use of org.apache.jena.reasoner.Reasoner 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.Reasoner in project jena by apache.
the class OWLConsistencyTest method testResults.
/**
* Run the consistency check, returning a ValidityReport.
*/
public ValidityReport testResults() {
Model t = FileManager.get().loadModel(BASE_DIR + tbox);
Model a = FileManager.get().loadModel(BASE_DIR + abox);
// Work around non-deterministic bug in bindSchema
// Reasoner r = rf.create(null).bindSchema(t);
Reasoner r = rf.create(null);
a.add(t);
InfModel im = ModelFactory.createInfModel(r, a);
return im.validate();
}
use of org.apache.jena.reasoner.Reasoner in project jena by apache.
the class TestFBRules method testDuplicatesEC4.
/**
* Investigate a suspicious case in the OWL ruleset, is the backchainer
* returning duplicate values?
*/
public void testDuplicatesEC4() {
boolean prior = JenaParameters.enableFilteringOfHiddenInfNodes;
try {
JenaParameters.enableFilteringOfHiddenInfNodes = false;
Model premisesM = FileManager.get().loadModel("file:testing/wg/equivalentClass/premises004.rdf");
Graph data = premisesM.getGraph();
Reasoner reasoner = new OWLFBRuleReasoner(OWLFBRuleReasonerFactory.theInstance());
InfGraph infgraph = reasoner.bind(data);
Node rbPrototypeProp = NodeFactory.createURI(ReasonerVocabulary.RBNamespace + "prototype");
int count = 0;
for (Iterator<Triple> i = infgraph.find(null, rbPrototypeProp, null); i.hasNext(); ) {
Object t = i.next();
// System.out.println(" - " + PrintUtil.print(t));
count++;
}
// listFBGraph("direct databind case", (FBRuleInfGraph)infgraph);
assertEquals(5, count);
infgraph = reasoner.bindSchema(data).bind(Factory.createGraphMem());
count = 0;
for (Iterator<Triple> i = infgraph.find(null, rbPrototypeProp, null); i.hasNext(); ) {
Triple t = i.next();
// System.out.println(" - " + PrintUtil.print(t));
count++;
}
// listFBGraph("bindSchema case", (FBRuleInfGraph)infgraph);
assertEquals(5, count);
} finally {
JenaParameters.enableFilteringOfHiddenInfNodes = prior;
}
}
use of org.apache.jena.reasoner.Reasoner in project jena by apache.
the class TestBackchainer method testRebind.
// /**
// * Test multiheaded rule.
// */
// public void testMutliHead() {
// Graph data = new GraphMem();
// data.add(new Triple(a, p, b));
// data.add(new Triple(b, r, c));
// List<Rule> rules = Rule.parseRules(
// "[r1: (?x s ?z), (?z s ?x) <- (?x p ?y) (?y r ?z) ]"
// );
// Reasoner reasoner = createReasoner(rules);
// InfGraph infgraph = reasoner.bind(data);
// TestUtil.assertIteratorValues(this,
// infgraph.find(null, s, null),
// new Object[] {
// new Triple(a, s, c),
// new Triple(c, s, a)
// } );
// }
/**
* Test rebind operation
*/
public void testRebind() {
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) });
Graph ndata = Factory.createGraphMem();
ndata.add(new Triple(a, p, d));
ndata.add(new Triple(d, p, b));
infgraph.rebind(ndata);
TestUtil.assertIteratorValues(this, infgraph.find(null, r, null), new Object[] { new Triple(a, r, b) });
}
use of org.apache.jena.reasoner.Reasoner in project jena by apache.
the class TestBackchainer method testBaseRules2b.
/**
* Test basic rule operations - simple OR rule with chaining
*/
public void testBaseRules2b() {
List<Rule> rules = Rule.parseRules("[r1: (?a r ?b) <- (?a p ?b)]" + "[r2: (?a r ?b) <- (?a q ?b)]" + "[r3: (?a r ?b) <- (?a t ?c), (?c t ?b)]" + "[r4: (?a t ?b) <- (?a 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) });
}
Aggregations