Search in sources :

Example 6 with Reasoner

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

the class TestBackchainer method testFunctors1.

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

Example 7 with Reasoner

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

the class TestBackchainer method testBuiltin3.

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

Example 8 with Reasoner

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

the class TestBackchainer method testRestriction2.

/**
     * Test restriction example. The rules are more than the minimum required
     * to solve the query and they interact to given run away seaches if there
     * is a problem. 
     */
public void testRestriction2() {
    Graph data = Factory.createGraphMem();
    data.add(new Triple(a, ty, OWL.Thing.asNode()));
    data.add(new Triple(p, ty, OWL.FunctionalProperty.asNode()));
    data.add(new Triple(c, OWL.equivalentClass.asNode(), C1));
    data.add(new Triple(C1, ty, OWL.Restriction.asNode()));
    data.add(new Triple(C1, OWL.onProperty.asNode(), p));
    data.add(new Triple(C1, OWL.maxCardinality.asNode(), Util.makeIntNode(1)));
    List<Rule> rules = Rule.parseRules(// these ones are required for the inference.
    "[rdfs9:  bound(?y)   (?x rdfs:subClassOf ?y) (?a rdf:type ?x) -> (?a rdf:type ?y)]" + "[restriction4: (?C rdf:type owl:Restriction), (?C owl:onProperty ?P), (?C owl:maxCardinality ?X) -> (?C owl:equivalentClass max(?P, ?X))]" + "[restrictionProc11: (?P rdf:type owl:FunctionalProperty), (?X rdf:type owl:Thing) -> (?X rdf:type max(?P, 1))]" + //        "[equivalentClass1: (?P owl:equivalentClass ?Q) -> (?P rdfs:subClassOf ?Q), (?Q rdfs:subClassOf ?P) ]" +
    "[equivalentClass1: (?P owl:equivalentClass ?Q) -> (?P rdfs:subClassOf ?Q) ]" + "[equivalentClass1: (?P owl:equivalentClass ?Q) -> (?Q rdfs:subClassOf ?P) ]" + "[restrictionSubclass1: bound(?D) (?D owl:equivalentClass ?R), isFunctor(?R) (?X rdf:type ?R)-> (?X rdf:type ?D)]" + // these ones are noise which can cause run aways or failures if there are bugs        
    "[rdfs8:  unbound(?c) (?a rdfs:subClassOf ?b) (?b rdfs:subClassOf ?c) -> (?a rdfs:subClassOf ?c)]" + "[rdfs8:  bound(?c)   (?b rdfs:subClassOf ?c) (?a rdfs:subClassOf ?b) -> (?a rdfs:subClassOf ?c)]" + "[rdfs9:  unbound(?y) (?a rdf:type ?x) (?x rdfs:subClassOf ?y) -> (?a rdf:type ?y)]" + "[-> (rdf:type      rdfs:range rdfs:Class)]" + "[rdfs3:  bound(?c)   (?p rdfs:range ?c) (?x ?p ?y) -> (?y rdf:type ?c)]" + "[rdfs7:  (?a rdf:type rdfs:Class) -> (?a rdfs:subClassOf ?a)]" + "[restrictionProc13: (owl:Thing rdfs:subClassOf all(?P, ?C)) -> (?P rdfs:range ?C)]" + "[restrictionSubclass1: unbound(?D) (?X rdf:type ?R), isFunctor(?R) (?D owl:equivalentClass ?R) -> (?X rdf:type ?D)]" + "[restrictionSubclass2: bound(?R), isFunctor(?R), (?D owl:equivalentClass ?R),(?X rdf:type ?D) -> (?X rdf:type ?R)]" + "[restrictionSubclass2: unbound(?R), (?X rdf:type ?D), (?D owl:equivalentClass ?R) isFunctor(?R) -> (?X rdf:type ?R)]" + "");
    Reasoner reasoner = createReasoner(rules);
    InfGraph infgraph = reasoner.bind(data);
    TestUtil.assertIteratorValues(this, infgraph.find(a, ty, C1), new Object[] { new Triple(a, ty, C1) });
    TestUtil.assertIteratorValues(this, infgraph.find(a, ty, c), new Object[] { new Triple(a, ty, c) });
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) Reasoner(org.apache.jena.reasoner.Reasoner)

Example 9 with Reasoner

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

the class TestBackchainer method testFunctors2.

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

Example 10 with Reasoner

use of org.apache.jena.reasoner.Reasoner 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)

Aggregations

Reasoner (org.apache.jena.reasoner.Reasoner)45 InfGraph (org.apache.jena.reasoner.InfGraph)36 TransitiveReasoner (org.apache.jena.reasoner.transitiveReasoner.TransitiveReasoner)7 Graph (org.apache.jena.graph.Graph)5 Node (org.apache.jena.graph.Node)5 Triple (org.apache.jena.graph.Triple)5 InfModel (org.apache.jena.rdf.model.InfModel)5 RDFNode (org.apache.jena.rdf.model.RDFNode)5 ByteArrayInputStream (java.io.ByteArrayInputStream)2 OntModel (org.apache.jena.ontology.OntModel)2 Model (org.apache.jena.rdf.model.Model)2 Resource (org.apache.jena.rdf.model.Resource)2 JenaException (org.apache.jena.shared.JenaException)2 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 Options (org.apache.commons.cli.Options)1 MultiUnion (org.apache.jena.graph.compose.MultiUnion)1 Property (org.apache.jena.rdf.model.Property)1 StmtIterator (org.apache.jena.rdf.model.StmtIterator)1