Search in sources :

Example 36 with Reasoner

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

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

the class OWLConsistencyTest method testResults.

/**
     * Run the consistency check, returning a ValidityReport.
     */
public ValidityReport testResults() {
    Model t = FileManager.get().loadModel(BASE_DIR + tbox);
    Model a = FileManager.get().loadModel(BASE_DIR + abox);
    // Work around non-deterministic bug in bindSchema
    //        Reasoner r = rf.create(null).bindSchema(t);
    Reasoner r = rf.create(null);
    a.add(t);
    InfModel im = ModelFactory.createInfModel(r, a);
    return im.validate();
}
Also used : Reasoner(org.apache.jena.reasoner.Reasoner) Model(org.apache.jena.rdf.model.Model) InfModel(org.apache.jena.rdf.model.InfModel) InfModel(org.apache.jena.rdf.model.InfModel)

Example 38 with Reasoner

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

the class TestFBRules method testDuplicatesEC4.

/**
     * Investigate a suspicious case in the OWL ruleset, is the backchainer 
     * returning duplicate values?
     */
public void testDuplicatesEC4() {
    boolean prior = JenaParameters.enableFilteringOfHiddenInfNodes;
    try {
        JenaParameters.enableFilteringOfHiddenInfNodes = false;
        Model premisesM = FileManager.get().loadModel("file:testing/wg/equivalentClass/premises004.rdf");
        Graph data = premisesM.getGraph();
        Reasoner reasoner = new OWLFBRuleReasoner(OWLFBRuleReasonerFactory.theInstance());
        InfGraph infgraph = reasoner.bind(data);
        Node rbPrototypeProp = NodeFactory.createURI(ReasonerVocabulary.RBNamespace + "prototype");
        int count = 0;
        for (Iterator<Triple> i = infgraph.find(null, rbPrototypeProp, null); i.hasNext(); ) {
            Object t = i.next();
            //                System.out.println(" - " + PrintUtil.print(t));
            count++;
        }
        //            listFBGraph("direct databind case", (FBRuleInfGraph)infgraph);
        assertEquals(5, count);
        infgraph = reasoner.bindSchema(data).bind(Factory.createGraphMem());
        count = 0;
        for (Iterator<Triple> i = infgraph.find(null, rbPrototypeProp, null); i.hasNext(); ) {
            Triple t = i.next();
            //                System.out.println(" - " + PrintUtil.print(t));
            count++;
        }
        //            listFBGraph("bindSchema case", (FBRuleInfGraph)infgraph);
        assertEquals(5, count);
    } finally {
        JenaParameters.enableFilteringOfHiddenInfNodes = prior;
    }
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) Reasoner(org.apache.jena.reasoner.Reasoner)

Example 39 with Reasoner

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

the class TestBackchainer method testRebind.

//    /**
//     * Test multiheaded rule.
//     */
//    public void testMutliHead() {
//        Graph data = new GraphMem();
//        data.add(new Triple(a, p, b));
//        data.add(new Triple(b, r, c));
//        List<Rule> rules = Rule.parseRules(
//            "[r1: (?x s ?z), (?z s ?x) <- (?x p ?y) (?y r ?z) ]"
//        );
//        Reasoner reasoner =  createReasoner(rules);
//        InfGraph infgraph = reasoner.bind(data);
//        TestUtil.assertIteratorValues(this, 
//            infgraph.find(null, s, null), 
//            new Object[] {
//                new Triple(a, s, c),
//                new Triple(c, s, a)
//            } );
//    }
/**
     * Test rebind operation
     */
public void testRebind() {
    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) });
    Graph ndata = Factory.createGraphMem();
    ndata.add(new Triple(a, p, d));
    ndata.add(new Triple(d, p, b));
    infgraph.rebind(ndata);
    TestUtil.assertIteratorValues(this, infgraph.find(null, r, null), new Object[] { 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 40 with Reasoner

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

the class TestBackchainer method testBaseRules2b.

/**
     * Test basic rule operations - simple OR rule with chaining 
     */
public void testBaseRules2b() {
    List<Rule> rules = Rule.parseRules("[r1: (?a r ?b) <- (?a p ?b)]" + "[r2: (?a r ?b) <- (?a q ?b)]" + "[r3: (?a r ?b) <- (?a t ?c), (?c t ?b)]" + "[r4: (?a t ?b) <- (?a 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)

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