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());
}
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());
}
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()));
}
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);
}
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[] {});
}
Aggregations