Search in sources :

Example 41 with InfGraph

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

the class TestBackchainer method testBaseRules2.

/**
     * Test basic rule operations - simple OR rule 
     */
public void testBaseRules2() {
    List<Rule> rules = Rule.parseRules("[r1: (?a r ?b) <- (?a p ?b)]" + "[r2: (?a r ?b) <- (?a q ?b)]" + "[r3: (?a r ?b) <- (?a s ?c), (?c 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) });
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) Reasoner(org.apache.jena.reasoner.Reasoner)

Example 42 with InfGraph

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

the class TestBackchainer method testGroundHead.

/**
     * Test basic ground head patterns.
     */
public void testGroundHead() {
    Graph data = Factory.createGraphMem();
    data.add(new Triple(a, r, b));
    List<Rule> rules = Rule.parseRules("[r1: (a p b ) <- (a r b) ]");
    Reasoner reasoner = createReasoner(rules);
    InfGraph infgraph = reasoner.bind(data);
    TestUtil.assertIteratorValues(this, infgraph.find(a, null, null), new Object[] { new Triple(a, p, b), new Triple(a, r, b) });
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) Reasoner(org.apache.jena.reasoner.Reasoner)

Example 43 with InfGraph

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

the class TestBackchainer method testRestriction1.

/**
     * Test restriction example
     */
public void testRestriction1() {
    Graph data = Factory.createGraphMem();
    data.add(new Triple(a, ty, r));
    data.add(new Triple(a, p, b));
    data.add(new Triple(r, sC, C1));
    data.add(new Triple(C1, OWL.onProperty.asNode(), p));
    data.add(new Triple(C1, OWL.allValuesFrom.asNode(), c));
    List<Rule> rules = Rule.parseRules("[rdfs9:  (?x rdfs:subClassOf ?y) (?a rdf:type ?x) -> (?a rdf:type ?y)]" + "[restriction2: (?C owl:onProperty ?P), (?C owl:allValuesFrom ?D) -> (?C owl:equivalentClass all(?P, ?D))]" + "[rs2: (?D owl:equivalentClass all(?P,?C)), (?X rdf:type ?D) -> (?X rdf:type all(?P,?C))]" + "[rp4: (?X rdf:type all(?P, ?C)), (?X ?P ?Y) -> (?Y rdf:type ?C)]");
    Reasoner reasoner = createReasoner(rules);
    InfGraph infgraph = reasoner.bind(data);
    TestUtil.assertIteratorValues(this, infgraph.find(b, ty, c), new Object[] { new Triple(b, ty, c) });
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) Reasoner(org.apache.jena.reasoner.Reasoner)

Example 44 with InfGraph

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

Example 45 with InfGraph

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

the class DebugRules method run.

/** Run a single test */
public void run() {
    BasicForwardRuleReasoner reasoner = new BasicForwardRuleReasoner(ruleset);
    InfGraph result = reasoner.bind(Factory.createGraphMem());
    System.out.println("Final graph state");
    for (Iterator<Triple> i = result.find(null, null, null); i.hasNext(); ) {
        System.out.println(PrintUtil.print(i.next()));
    }
}
Also used : BasicForwardRuleReasoner(org.apache.jena.reasoner.rulesys.BasicForwardRuleReasoner) Triple(org.apache.jena.graph.Triple) InfGraph(org.apache.jena.reasoner.InfGraph)

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