Search in sources :

Example 16 with InfGraph

use of org.apache.jena.reasoner.InfGraph in project jena by apache.

the class TestBackchainer method testBaseRules1.

/**
     * Test basic rule operations - simple AND rule 
     */
public void testBaseRules1() {
    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) });
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) Reasoner(org.apache.jena.reasoner.Reasoner)

Example 17 with InfGraph

use of org.apache.jena.reasoner.InfGraph in project jena by apache.

the class TestBackchainer method testFunctors3.

/**
     * Test basic functor usage.
     */
public void testFunctors3() {
    Graph data = Factory.createGraphMem();
    data.add(new Triple(a, s, b));
    data.add(new Triple(a, t, c));
    List<Rule> rules = Rule.parseRules("[r1: (a q f(?x,?y)) <- (a s ?x), (a t ?y)]" + "[r2: (a p ?x) <- (a q ?x)]" + "[r3: (a r ?y) <- (a p f(?x, ?y))]");
    Reasoner reasoner = createReasoner(rules);
    InfGraph infgraph = reasoner.bind(data);
    TestUtil.assertIteratorValues(this, infgraph.find(a, r, null), new Object[] { new Triple(a, r, c) });
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) Reasoner(org.apache.jena.reasoner.Reasoner)

Example 18 with InfGraph

use of org.apache.jena.reasoner.InfGraph in project jena by apache.

the class TestBackchainer method testRDFSProblems.

/**
     * Test troublesome rdfs rules
     */
public void testRDFSProblems() {
    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));
    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);
    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) });
    TestUtil.assertIteratorValues(this, infgraph.find(C1, sC, a), new Object[] {});
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) Reasoner(org.apache.jena.reasoner.Reasoner)

Example 19 with InfGraph

use of org.apache.jena.reasoner.InfGraph in project jena by apache.

the class TestBackchainer method testBaseRules3b.

/**
     * Test basic rule operations - simple AND rule check with tabling.
     */
public void testBaseRules3b() {
    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(r, sP, t));
    data.add(new Triple(q, sP, s));
    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(r, sP, t), new Triple(q, sP, s), new Triple(p, sP, s), new Triple(p, sP, r), new Triple(p, sP, t), new Triple(q, 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 20 with InfGraph

use of org.apache.jena.reasoner.InfGraph in project jena by apache.

the class TestBackchainer method testRDFSProblemsb.

/**
     * Test troublesome rdfs rules
     */
public void testRDFSProblemsb() {
    Graph data = Factory.createGraphMem();
    data.add(new Triple(C1, sC, C2));
    data.add(new Triple(C2, sC, C3));
    data.add(new Triple(C1, ty, RDFS.Class.asNode()));
    data.add(new Triple(C2, ty, RDFS.Class.asNode()));
    data.add(new Triple(C3, ty, RDFS.Class.asNode()));
    List<Rule> rules = Rule.parseRules("[rdfs8:  (?a rdfs:subClassOf ?b), (?b rdfs:subClassOf ?c) -> (?a rdfs:subClassOf ?c)]" + "[rdfs7:  (?a rdf:type rdfs:Class) -> (?a rdfs:subClassOf ?a)]");
    Reasoner reasoner = createReasoner(rules);
    InfGraph infgraph = reasoner.bind(data);
    TestUtil.assertIteratorValues(this, infgraph.find(null, sC, null), new Object[] { new Triple(C1, sC, C2), new Triple(C1, sC, C3), new Triple(C1, sC, C1), new Triple(C2, sC, C3), new Triple(C2, sC, C2), new Triple(C3, sC, C3) });
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) 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