Search in sources :

Example 31 with Reasoner

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

the class TestBackchainer method testRestriction3.

/**
     * Test restriction example
     */
public void testRestriction3() {
    Graph data = Factory.createGraphMem();
    data.add(new Triple(a, ty, r));
    data.add(new Triple(r, sC, 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.allValuesFrom.asNode(), c));
    List<Rule> rules = Rule.parseRules("[-> (rdfs:subClassOf rdfs:range rdfs:Class)]" + //        "[-> (owl:Class rdfs:subClassOf rdfs:Class)]" +
    "[rdfs3:  bound(?c)   (?p rdfs:range ?c) (?x ?p ?y) -> (?y rdf:type ?c)]" + "[rdfs3:  unbound(?c) (?x ?p ?y), (?p rdfs:range ?c) -> (?y rdf:type ?c)]" + "[rdfs7:  (?a rdf:type rdfs:Class) -> (?a rdfs:subClassOf ?a)]" + "[rdfs8:  (?a rdfs:subClassOf ?b) (?b rdfs:subClassOf ?c) -> (?a rdfs:subClassOf ?c)]" + "[restrictionProc4b: bound(?Y) (?X ?P ?Y), notEqual(?P, rdf:type), (?X rdf:type all(?P, ?C)),-> (?Y rdf:type ?C)]" + "[restrictionProc4b: unbound(?Y), (?X rdf:type all(?P, ?C)), (?X ?P ?Y), notEqual(?P, rdf:type),-> (?Y rdf:type ?C)]" + "");
    Reasoner reasoner = createReasoner(rules);
    InfGraph infgraph = reasoner.bind(data);
    TestUtil.assertIteratorValues(this, infgraph.find(null, ty, c), new Object[] {});
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) Reasoner(org.apache.jena.reasoner.Reasoner)

Example 32 with Reasoner

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

the class TestBackchainer method testBuiltin2.

/**
     * Test basic builtin usage.
     */
public void testBuiltin2() {
    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 ?y ) <- bound(?x), (?x p ?y) ]" + "[r2: (?x r ?y) <- unbound(?x), (?x q ?y)]");
    Reasoner reasoner = createReasoner(rules);
    InfGraph infgraph = reasoner.bind(data);
    TestUtil.assertIteratorValues(this, infgraph.find(a, r, null), new Object[] { new Triple(a, r, b) });
    TestUtil.assertIteratorValues(this, infgraph.find(null, 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 33 with Reasoner

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

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

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

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