use of org.apache.jena.reasoner.Reasoner in project jena by apache.
the class OntModelImpl method generateGraph.
/**
* <p>Helper method to the constructor, which interprets the spec and generates an appropriate
* graph for this model</p>
* @param spec The model spec to interpret
* @param base The base model, or null
*/
private static Graph generateGraph(OntModelSpec spec, Graph base) {
// create a empty union graph
MultiUnion u = new MultiUnion();
u.addGraph(base);
u.setBaseGraph(base);
Reasoner r = spec.getReasoner();
// if we have a reasoner in the spec, bind to the union graph and return
return r == null ? (Graph) u : r.bind(u);
}
use of org.apache.jena.reasoner.Reasoner in project jena by apache.
the class TestBackchainer method testBaseRulesXSB1.
/**
* Test basic rule operations - simple AND/OR with tabling.
*/
public void testBaseRulesXSB1() {
Graph data = Factory.createGraphMem();
data.add(new Triple(p, c, q));
data.add(new Triple(q, c, r));
data.add(new Triple(p, d, q));
data.add(new Triple(q, d, r));
List<Rule> rules = Rule.parseRules("[r1: (?x a ?y) <- (?x c ?y)]" + "[r2: (?x a ?y) <- (?x b ?z), (?z c ?y)]" + "[r3: (?x b ?y) <- (?x d ?y)]" + "[r4: (?x b ?y) <- (?x a ?z), (?z d ?y)]");
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(p, a, null), new Object[] { new Triple(p, a, q), new Triple(p, a, r) });
}
use of org.apache.jena.reasoner.Reasoner in project jena by apache.
the class TestBackchainer method testBaseRules4.
/**
* Test basic rule operations - simple AND/OR with tabling.
*/
public void testBaseRules4() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, r, b));
data.add(new Triple(b, r, c));
data.add(new Triple(b, r, b));
data.add(new Triple(b, r, d));
List<Rule> rules = Rule.parseRules("[r1: (?x p ?y) <- (?x r ?y)]" + "[r2: (?x p ?z) <- (?x p ?y), (?y r ?z)]");
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(a, p, null), new Object[] { new Triple(a, p, b), new Triple(a, p, d), new Triple(a, p, c) });
}
use of org.apache.jena.reasoner.Reasoner in project jena by apache.
the class TestBackchainer method testClose.
/**
* Test close and halt operation.
*/
public void testClose() {
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));
data.add(new Triple(ty, RDFS.range.asNode(), RDFS.Class.asNode()));
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);
// Get just one result
ExtendedIterator<Triple> it = infgraph.find(a, ty, null);
Triple result = it.next();
assertEquals(result.getSubject(), a);
assertEquals(result.getPredicate(), ty);
it.close();
// Make sure if we start again we get the full listing.
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) });
}
use of org.apache.jena.reasoner.Reasoner in project jena by apache.
the class TestBackchainer method testHeadUnify.
/**
* Test complex rule head unification
*/
public void testHeadUnify() {
Graph data = Factory.createGraphMem();
data.add(new Triple(c, q, d));
List<Rule> rules = Rule.parseRules("[r1: (c r ?x) <- (?x p f(?x b))]" + "[r2: (?y p f(a ?y)) <- (c q ?y)]");
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(c, r, null), new Object[] {});
data.add(new Triple(c, q, a));
rules = Rule.parseRules("[r1: (c r ?x) <- (?x p f(?x a))]" + "[r2: (?y p f(a ?y)) <- (c q ?y)]");
reasoner = createReasoner(rules);
infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(c, r, null), new Object[] { new Triple(c, r, a) });
data = Factory.createGraphMem();
data.add(new Triple(a, q, a));
data.add(new Triple(a, q, b));
data.add(new Triple(a, q, c));
data.add(new Triple(b, q, d));
data.add(new Triple(b, q, b));
rules = Rule.parseRules("[r1: (c r ?x) <- (?x p ?x)]" + "[r2: (?x p ?y) <- (a q ?x), (b q ?y)]");
reasoner = createReasoner(rules);
infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(c, r, null), new Object[] { new Triple(c, r, b) });
rules = Rule.parseRules("[r1: (c r ?x) <- (?x p ?x)]" + "[r2: (a p ?x) <- (a q ?x)]");
reasoner = createReasoner(rules);
infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(c, r, null), new Object[] { new Triple(c, r, a) });
}
Aggregations