use of org.apache.jena.reasoner.Reasoner in project jena by apache.
the class TestBackchainer method testRestriction3.
/**
* Test restriction example
*/
public void testRestriction3() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, ty, r));
data.add(new Triple(r, sC, C1));
data.add(new Triple(C1, ty, OWL.Restriction.asNode()));
data.add(new Triple(C1, OWL.onProperty.asNode(), p));
data.add(new Triple(C1, OWL.allValuesFrom.asNode(), c));
List<Rule> rules = Rule.parseRules("[-> (rdfs:subClassOf rdfs:range rdfs:Class)]" + // "[-> (owl:Class rdfs:subClassOf rdfs:Class)]" +
"[rdfs3: bound(?c) (?p rdfs:range ?c) (?x ?p ?y) -> (?y rdf:type ?c)]" + "[rdfs3: unbound(?c) (?x ?p ?y), (?p rdfs:range ?c) -> (?y rdf:type ?c)]" + "[rdfs7: (?a rdf:type rdfs:Class) -> (?a rdfs:subClassOf ?a)]" + "[rdfs8: (?a rdfs:subClassOf ?b) (?b rdfs:subClassOf ?c) -> (?a rdfs:subClassOf ?c)]" + "[restrictionProc4b: bound(?Y) (?X ?P ?Y), notEqual(?P, rdf:type), (?X rdf:type all(?P, ?C)),-> (?Y rdf:type ?C)]" + "[restrictionProc4b: unbound(?Y), (?X rdf:type all(?P, ?C)), (?X ?P ?Y), notEqual(?P, rdf:type),-> (?Y rdf:type ?C)]" + "");
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(null, ty, c), new Object[] {});
}
use of org.apache.jena.reasoner.Reasoner in project jena by apache.
the class TestBackchainer method testBuiltin2.
/**
* Test basic builtin usage.
*/
public void testBuiltin2() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, p, b));
data.add(new Triple(a, q, c));
List<Rule> rules = Rule.parseRules("[r1: (?x r ?y ) <- bound(?x), (?x p ?y) ]" + "[r2: (?x r ?y) <- unbound(?x), (?x q ?y)]");
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(a, r, null), new Object[] { new Triple(a, r, b) });
TestUtil.assertIteratorValues(this, infgraph.find(null, r, null), new Object[] { new Triple(a, r, c) });
}
use of org.apache.jena.reasoner.Reasoner 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.Reasoner 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.Reasoner 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) });
}
Aggregations