Search in sources :

Example 26 with InfGraph

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) });
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) Reasoner(org.apache.jena.reasoner.Reasoner)

Example 27 with InfGraph

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) });
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) Reasoner(org.apache.jena.reasoner.Reasoner)

Example 28 with InfGraph

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) });
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph)

Example 29 with InfGraph

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) });
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph)

Example 30 with InfGraph

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");
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) Reasoner(org.apache.jena.reasoner.Reasoner)

Aggregations

InfGraph (org.apache.jena.reasoner.InfGraph)70 Reasoner (org.apache.jena.reasoner.Reasoner)36 Graph (org.apache.jena.graph.Graph)11 Triple (org.apache.jena.graph.Triple)10 Node (org.apache.jena.graph.Node)7 RDFNode (org.apache.jena.rdf.model.RDFNode)5 TransitiveReasoner (org.apache.jena.reasoner.transitiveReasoner.TransitiveReasoner)5 FBRuleInfGraph (org.apache.jena.reasoner.rulesys.FBRuleInfGraph)3 JenaException (org.apache.jena.shared.JenaException)3 Derivation (org.apache.jena.reasoner.Derivation)2 ReasonerException (org.apache.jena.reasoner.ReasonerException)2 TriplePattern (org.apache.jena.reasoner.TriplePattern)2 XSDDatatype (org.apache.jena.datatypes.xsd.XSDDatatype)1 XSDDateTime (org.apache.jena.datatypes.xsd.XSDDateTime)1 InfModel (org.apache.jena.rdf.model.InfModel)1 InfModelImpl (org.apache.jena.rdf.model.impl.InfModelImpl)1 BasicForwardRuleReasoner (org.apache.jena.reasoner.rulesys.BasicForwardRuleReasoner)1 BuiltinException (org.apache.jena.reasoner.rulesys.BuiltinException)1 GenericRuleReasoner (org.apache.jena.reasoner.rulesys.GenericRuleReasoner)1 Rule (org.apache.jena.reasoner.rulesys.Rule)1