use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestBackchainer method testBaseRules1.
/**
* Test basic rule operations - simple AND rule
*/
public void testBaseRules1() {
List<Rule> rules = Rule.parseRules("[r1: (?a r ?c) <- (?a p ?b),(?b p ?c)]");
Graph data = Factory.createGraphMem();
data.add(new Triple(a, p, b));
data.add(new Triple(b, p, c));
data.add(new Triple(b, p, d));
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(null, r, null), new Object[] { new Triple(a, r, c), new Triple(a, r, d) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestBackchainer method testFunctors3.
/**
* Test basic functor usage.
*/
public void testFunctors3() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, s, b));
data.add(new Triple(a, t, c));
List<Rule> rules = Rule.parseRules("[r1: (a q f(?x,?y)) <- (a s ?x), (a t ?y)]" + "[r2: (a p ?x) <- (a q ?x)]" + "[r3: (a r ?y) <- (a p f(?x, ?y))]");
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(a, r, null), new Object[] { new Triple(a, r, c) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestBackchainer method testRDFSProblems.
/**
* Test troublesome rdfs rules
*/
public void testRDFSProblems() {
Graph data = Factory.createGraphMem();
data.add(new Triple(p, sP, q));
data.add(new Triple(q, sP, r));
data.add(new Triple(C1, sC, C2));
data.add(new Triple(C2, sC, C3));
data.add(new Triple(a, ty, C1));
List<Rule> rules = Rule.parseRules("[rdfs8: (?a rdfs:subClassOf ?b), (?b rdfs:subClassOf ?c) -> (?a rdfs:subClassOf ?c)]" + "[rdfs9: (?x rdfs:subClassOf ?y), (?a rdf:type ?x) -> (?a rdf:type ?y)]" + // "[-> (rdf:type rdfs:range rdfs:Class)]" +
"[rdfs3: (?x ?p ?y), (?p rdfs:range ?c) -> (?y rdf:type ?c)]" + "[rdfs7: (?a rdf:type rdfs:Class) -> (?a rdfs:subClassOf ?a)]");
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(a, ty, null), new Object[] { new Triple(a, ty, C1), new Triple(a, ty, C2), new Triple(a, ty, C3) });
TestUtil.assertIteratorValues(this, infgraph.find(C1, sC, a), new Object[] {});
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestBackchainer method testBaseRules3b.
/**
* Test basic rule operations - simple AND rule check with tabling.
*/
public void testBaseRules3b() {
List<Rule> rules = Rule.parseRules("[rule: (?a rdfs:subPropertyOf ?c) <- (?a rdfs:subPropertyOf ?b),(?b rdfs:subPropertyOf ?c)]");
Reasoner reasoner = createReasoner(rules);
Graph data = Factory.createGraphMem();
data.add(new Triple(p, sP, q));
data.add(new Triple(q, sP, r));
data.add(new Triple(r, sP, t));
data.add(new Triple(q, sP, s));
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(null, RDFS.subPropertyOf.asNode(), null), new Object[] { new Triple(p, sP, q), new Triple(q, sP, r), new Triple(r, sP, t), new Triple(q, sP, s), new Triple(p, sP, s), new Triple(p, sP, r), new Triple(p, sP, t), new Triple(q, sP, t), new Triple(p, sP, r) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestBackchainer method testRDFSProblemsb.
/**
* Test troublesome rdfs rules
*/
public void testRDFSProblemsb() {
Graph data = Factory.createGraphMem();
data.add(new Triple(C1, sC, C2));
data.add(new Triple(C2, sC, C3));
data.add(new Triple(C1, ty, RDFS.Class.asNode()));
data.add(new Triple(C2, ty, RDFS.Class.asNode()));
data.add(new Triple(C3, ty, RDFS.Class.asNode()));
List<Rule> rules = Rule.parseRules("[rdfs8: (?a rdfs:subClassOf ?b), (?b rdfs:subClassOf ?c) -> (?a rdfs:subClassOf ?c)]" + "[rdfs7: (?a rdf:type rdfs:Class) -> (?a rdfs:subClassOf ?a)]");
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(null, sC, null), new Object[] { new Triple(C1, sC, C2), new Triple(C1, sC, C3), new Triple(C1, sC, C1), new Triple(C2, sC, C3), new Triple(C2, sC, C2), new Triple(C3, sC, C3) });
}
Aggregations