use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestBackchainer method testBug1.
/**
* Test problematic rdfs case
*/
public void testBug1() {
Graph data = Factory.createGraphMem();
Node p = NodeFactory.createURI("http://www.hpl.hp.com/semweb/2003/eg#p");
Node r = NodeFactory.createURI("http://www.hpl.hp.com/semweb/2003/eg#r");
Node C1 = NodeFactory.createURI("http://www.hpl.hp.com/semweb/2003/eg#C1");
data.add(new Triple(a, p, b));
List<Rule> rules = Rule.parseRules(Util.loadRuleParserFromResourceFile("testing/reasoners/bugs/rdfs-error1.brules"));
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(b, ty, C1), new Object[] { new Triple(b, ty, C1) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestBackchainer method testBaseRules3.
/**
* Test basic rule operations - simple AND rule check with tabling.
*/
public void testBaseRules3() {
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(p, sP, s));
data.add(new Triple(s, sP, t));
data.add(new Triple(a, p, b));
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(p, sP, s), new Triple(s, sP, t), new Triple(p, sP, t), new Triple(p, sP, r) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestFBRules method testBackchain2.
/**
* Test complex rule head unification
*/
public void testBackchain2() {
Graph data = Factory.createGraphMem();
data.add(new Triple(c, q, d));
String rules = "[r1: (c r ?x) <- (?x p f(?x b))]" + "[r2: (?y p f(a ?y)) <- (c q ?y)]";
InfGraph infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(c, r, null), new Object[] {});
data.add(new Triple(c, q, a));
rules = "[r1: (c r ?x) <- (?x p f(?x a))]" + "[r2: (?y p f(a ?y)) <- (c q ?y)]";
infgraph = createInfGraph(rules, 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 = "[r1: (c r ?x) <- (?x p ?x)]" + "[r2: (?x p ?y) <- (a q ?x), (b q ?y)]";
infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(c, r, null), new Object[] { new Triple(c, r, b) });
rules = "[r1: (c r ?x) <- (?x p ?x)]" + "[r2: (a p ?x) <- (a q ?x)]";
infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(c, r, null), new Object[] { new Triple(c, r, a) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestFBRules method testNumericFunctors.
/**
* Test numeric functors
*/
public void testNumericFunctors() {
String rules = "[r1: (?x p f(a, ?x)) -> (?x q f(?x)) ]" + "[r1: (?x p f(a, 0)) -> (?x s res) ]" + "";
Graph data = Factory.createGraphMem();
data.add(new Triple(n1, p, Util.makeIntNode(2)));
data.add(new Triple(n2, p, Functor.makeFunctorNode("f", new Node[] { a, Util.makeIntNode(0) })));
data.add(new Triple(n3, p, Functor.makeFunctorNode("f", new Node[] { a, NodeFactory.createLiteral("0", XSDDatatype.XSDnonNegativeInteger) })));
InfGraph infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(null, s, null), new Triple[] { new Triple(n2, s, res), new Triple(n3, s, res) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestFBRules method temp.
/**
* Check cost of creating an empty OWL closure.
*/
public void temp() {
Graph data = Factory.createGraphMem();
Graph data2 = Factory.createGraphMem();
Reasoner reasoner = new OWLFBRuleReasoner(OWLFBRuleReasonerFactory.theInstance());
FBRuleInfGraph infgraph = (FBRuleInfGraph) reasoner.bind(data);
FBRuleInfGraph infgraph2 = (FBRuleInfGraph) reasoner.bind(data2);
long t1 = System.currentTimeMillis();
infgraph.prepare();
long t2 = System.currentTimeMillis();
System.out.println("Prepare on empty graph = " + (t2 - t1) + "ms");
t1 = System.currentTimeMillis();
infgraph2.prepare();
t2 = System.currentTimeMillis();
System.out.println("Prepare on empty graph = " + (t2 - t1) + "ms");
}
Aggregations