use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestBackchainer method testBaseRules2.
/**
* Test basic rule operations - simple OR rule
*/
public void testBaseRules2() {
List<Rule> rules = Rule.parseRules("[r1: (?a r ?b) <- (?a p ?b)]" + "[r2: (?a r ?b) <- (?a q ?b)]" + "[r3: (?a r ?b) <- (?a s ?c), (?c s ?b)]");
Graph data = Factory.createGraphMem();
data.add(new Triple(a, p, b));
data.add(new Triple(b, q, c));
data.add(new Triple(a, s, b));
data.add(new Triple(b, s, d));
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(null, r, null), new Object[] { new Triple(a, r, b), new Triple(b, r, c), new Triple(a, r, d) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestBackchainer method testGroundHead.
/**
* Test basic ground head patterns.
*/
public void testGroundHead() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, r, b));
List<Rule> rules = Rule.parseRules("[r1: (a p b ) <- (a r b) ]");
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(a, null, null), new Object[] { new Triple(a, p, b), new Triple(a, r, b) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestBackchainer method testRestriction1.
/**
* Test restriction example
*/
public void testRestriction1() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, ty, r));
data.add(new Triple(a, p, b));
data.add(new Triple(r, sC, C1));
data.add(new Triple(C1, OWL.onProperty.asNode(), p));
data.add(new Triple(C1, OWL.allValuesFrom.asNode(), c));
List<Rule> rules = Rule.parseRules("[rdfs9: (?x rdfs:subClassOf ?y) (?a rdf:type ?x) -> (?a rdf:type ?y)]" + "[restriction2: (?C owl:onProperty ?P), (?C owl:allValuesFrom ?D) -> (?C owl:equivalentClass all(?P, ?D))]" + "[rs2: (?D owl:equivalentClass all(?P,?C)), (?X rdf:type ?D) -> (?X rdf:type all(?P,?C))]" + "[rp4: (?X rdf:type all(?P, ?C)), (?X ?P ?Y) -> (?Y rdf:type ?C)]");
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(b, ty, c), new Object[] { new Triple(b, ty, c) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestBackchainer method testBuiltin1.
/**
* Test basic builtin usage.
*/
public void testBuiltin1() {
Graph data = Factory.createGraphMem();
List<Rule> rules = Rule.parseRules("[a1: -> (a p 2) ]" + "[a2: -> (a q 3) ]" + "[r1: (?x r ?s) <- (?x p ?y), (?x q ?z), sum(?y, ?z, ?s)]");
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(a, r, null), new Object[] { new Triple(a, r, Util.makeIntNode(5)) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class DebugRules method run.
/** Run a single test */
public void run() {
BasicForwardRuleReasoner reasoner = new BasicForwardRuleReasoner(ruleset);
InfGraph result = reasoner.bind(Factory.createGraphMem());
System.out.println("Final graph state");
for (Iterator<Triple> i = result.find(null, null, null); i.hasNext(); ) {
System.out.println(PrintUtil.print(i.next()));
}
}
Aggregations