Search in sources :

Example 86 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TestGenericRuleReasonerConfig method testLoadsSingleRuleViaURL.

private void testLoadsSingleRuleViaURL(String ns) {
    String where = "file:testing/modelspecs/example.rules";
    Resource r = resourceInModel("x <ns>:ruleSetURL <where>".replaceAll("<ns>", ns).replaceAll("<where>", where));
    List<Rule> rules = Rule.rulesFromURL(where);
    GenericRuleReasoner grr = new GenericRuleReasoner(null, r);
    assertEquals(rules, grr.getRules());
}
Also used : Resource(org.apache.jena.rdf.model.Resource) Rule.parseRule(org.apache.jena.reasoner.rulesys.Rule.parseRule)

Example 87 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TestGenericRuleReasonerConfig method testLoadsSingleRuleFromString.

private void testLoadsSingleRuleFromString(String ns) {
    String rule = "[R: (?x rdf:type eg:Thing) -> (?x eg:thing true)]";
    List<Rule> rules = Rule.parseRules(rule);
    Resource r = resourceInModel("x <ns>:hasRule '<it>'".replaceAll("<ns>", ns).replaceAll("<it>", rule.replaceAll(" ", "\\\\\\\\s")));
    GenericRuleReasoner grr = new GenericRuleReasoner(null, r);
    assertEquals(rules, grr.getRules());
}
Also used : Resource(org.apache.jena.rdf.model.Resource) Rule.parseRule(org.apache.jena.reasoner.rulesys.Rule.parseRule)

Example 88 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TestGenericRuleReasonerConfig method testLoadsMultipleRuleSetsViaRuleSetNode.

private void testLoadsMultipleRuleSetsViaRuleSetNode(String ns) {
    String whereA = "file:testing/modelspecs/example.rules";
    String whereB = "file:testing/modelspecs/extra.rules";
    Resource r = resourceInModel("x <ns>:ruleSet _a; _a <ns>:ruleSetURL <whereA>; _a <ns>:ruleSetURL <whereB>".replaceAll("<ns>", ns).replaceAll("<whereA>", whereA).replaceAll("<whereB>", whereB));
    GenericRuleReasoner grr = new GenericRuleReasoner(null, r);
    assertEquals(rulesFromTwoPlaces(whereA, whereB), new HashSet<>(grr.getRules()));
}
Also used : Resource(org.apache.jena.rdf.model.Resource)

Example 89 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TestReasoners method testTransitiveSpecReuse.

/**
     * The reasoner contract for bind(data) is not quite precise. It allows for
     * reasoners which have state so that reusing the same reasoner on a second data
     * model might lead to interference. This in fact used to happen with the transitive
     * reasoner. This is a test to check the top level symptoms of this which can be
     * solved just be not reusing reasoners.
     * @todo this test might be better moved to OntModel tests somewhere
     */
public void testTransitiveSpecReuse() {
    OntModel om1 = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_TRANS_INF);
    Resource c1 = om1.createResource(PrintUtil.egNS + "Class1");
    Resource c2 = om1.createResource(PrintUtil.egNS + "Class2");
    Resource c3 = om1.createResource(PrintUtil.egNS + "Class3");
    om1.add(c1, RDFS.subClassOf, c2);
    om1.add(c2, RDFS.subClassOf, c3);
    om1.prepare();
    assertFalse(om1.isEmpty());
    OntModel om2 = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_TRANS_INF);
    StmtIterator si = om2.listStatements();
    boolean ok = !si.hasNext();
    si.close();
    assertTrue("Transitive reasoner state leak", ok);
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Resource(org.apache.jena.rdf.model.Resource) OntModel(org.apache.jena.ontology.OntModel)

Example 90 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TestReasoners method testRDFSRemove.

/**
     * Test remove operations on an RDFS reasoner instance.
     * This is an example to test that rebing is invoked correctly rather
     * than an RDFS-specific test.
     */
public void testRDFSRemove() {
    InfModel m = ModelFactory.createRDFSModel(ModelFactory.createDefaultModel());
    String NS = PrintUtil.egNS;
    Property p = m.createProperty(NS, "p");
    Resource D = m.createResource(NS + "D");
    Resource i = m.createResource(NS + "i");
    Resource c = m.createResource(NS + "c");
    Resource d = m.createResource(NS + "d");
    p.addProperty(RDFS.domain, D);
    i.addProperty(p, c);
    i.addProperty(p, d);
    TestUtil.assertIteratorValues(this, i.listProperties(), new Object[] { m.createStatement(i, p, c), m.createStatement(i, p, d), m.createStatement(i, RDF.type, D), m.createStatement(i, RDF.type, RDFS.Resource) });
    i.removeAll(p);
    TestUtil.assertIteratorValues(this, i.listProperties(), new Object[] {});
}
Also used : Resource(org.apache.jena.rdf.model.Resource) InfModel(org.apache.jena.rdf.model.InfModel) Property(org.apache.jena.rdf.model.Property)

Aggregations

Resource (org.apache.jena.rdf.model.Resource)178 Model (org.apache.jena.rdf.model.Model)86 Test (org.junit.Test)55 Property (org.apache.jena.rdf.model.Property)34 RDFNode (org.apache.jena.rdf.model.RDFNode)24 Dataset (org.apache.jena.query.Dataset)20 Literal (org.apache.jena.rdf.model.Literal)17 BaseTest (org.apache.jena.atlas.junit.BaseTest)16 Node (org.apache.jena.graph.Node)16 Statement (org.apache.jena.rdf.model.Statement)14 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)13 StringReader (java.io.StringReader)9 InfModel (org.apache.jena.rdf.model.InfModel)9 Reader (java.io.Reader)8 ArrayList (java.util.ArrayList)8 JsonString (org.apache.jena.atlas.json.JsonString)8 Triple (org.apache.jena.graph.Triple)8 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)6 PrefixMapping (org.apache.jena.shared.PrefixMapping)6 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)5