Search in sources :

Example 11 with Reasoner

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

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

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

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

Example 15 with Reasoner

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

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