use of org.apache.jena.rdf.model.InfModel in project jena by apache.
the class TestGenericRuleReasonerConfig method testRuleLoadingWithOverridenBuiltins.
public void testRuleLoadingWithOverridenBuiltins() {
List<Node> savedNode = new ArrayList<>();
Builtin b = new BaseBuiltin() {
@Override
public String getName() {
return "groo";
}
@Override
public int getArgLength() {
return 1;
}
@Override
public void headAction(Node[] args, int length, RuleContext context) {
savedNode.add(getArg(0, args, context));
}
};
BuiltinRegistry r = new OverrideBuiltinRegistry(BuiltinRegistry.theRegistry);
r.register(b);
assertEquals(b, r.getImplementation("groo"));
List<Rule> rules = new ArrayList<>();
//
// note that the head action does not appear to fire unless we put a triple in the head as well.. is
// this expected?
//
rules.add(parseRule("[ (?instance rdf:type ?type) -> groo(?type) ]", r));
GenericRuleReasoner article = new GenericRuleReasoner(rules);
article.setMode(GenericRuleReasoner.FORWARD_RETE);
Model input = ModelFactory.createDefaultModel();
input.add(input.createResource(), RDF.type, input.createResource("http://example.com/Renegade"));
InfModel output = ModelFactory.createInfModel(article, input);
// not optional, inferences are not run if we don't trigger them
output.size();
assertEquals(1, savedNode.size());
assertEquals("http://example.com/Renegade", savedNode.get(0).getURI());
}
use of org.apache.jena.rdf.model.InfModel in project jena by apache.
the class TestReasoners method testTransitiveBindReuse.
/**
* 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 that the transitive reasoner state reuse has been fixed at source.
*/
public void testTransitiveBindReuse() {
Reasoner r = ReasonerRegistry.getTransitiveReasoner();
InfModel om1 = ModelFactory.createInfModel(r, ModelFactory.createDefaultModel());
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());
InfModel om2 = ModelFactory.createInfModel(r, ModelFactory.createDefaultModel());
StmtIterator si = om2.listStatements();
boolean ok = !si.hasNext();
si.close();
assertTrue("Transitive reasoner state leak", ok);
}
use of org.apache.jena.rdf.model.InfModel in project jena by apache.
the class TestReasoners method testTransitiveEngineSeparation.
/**
* Test that two transitive engines are independent.
* See JENA-1260
*/
public void testTransitiveEngineSeparation() throws InterruptedException {
String NS = "http://example.com/test#";
Property sp = ResourceFactory.createProperty(NS, "sp");
Property p = ResourceFactory.createProperty(NS, "p");
Property s = ResourceFactory.createProperty(NS, "s");
Resource q = ResourceFactory.createProperty(NS, "q");
Reasoner reasoner = ReasonerRegistry.getTransitiveReasoner();
InfModel simple = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
simple.add(s, sp, p);
assertFalse(simple.contains(s, RDFS.subPropertyOf, p));
InfModel withSP = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
withSP.add(sp, RDFS.subPropertyOf, RDFS.subPropertyOf);
withSP.add(s, sp, p);
assertTrue(withSP.contains(s, RDFS.subPropertyOf, p));
simple.add(q, sp, p);
assertFalse(simple.contains(q, RDFS.subPropertyOf, p));
}
use of org.apache.jena.rdf.model.InfModel in project jena by apache.
the class TestQueryEngineMultiThreaded method createForwardChainingModel.
private Model createForwardChainingModel() {
Model baseModel = ModelFactory.createDefaultModel();
Model schemaModel = ModelFactory.createDefaultModel();
Model configurationRuleReasoner = ModelFactory.createDefaultModel();
org.apache.jena.rdf.model.Resource configuration = configurationRuleReasoner.createResource();
configuration.addProperty(ReasonerVocabulary.PROPruleMode, "forward");
configuration.addProperty(ReasonerVocabulary.PROPsetRDFSLevel, ReasonerVocabulary.RDFS_SIMPLE);
Reasoner ruleReasoner = RDFSRuleReasonerFactory.theInstance().create(configuration);
InfModel inf = ModelFactory.createInfModel(ruleReasoner, schemaModel, baseModel);
inf.read(new ByteArrayInputStream(TURTLE_RDF.getBytes()), "", "TURTLE");
return inf;
}
use of org.apache.jena.rdf.model.InfModel 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