Search in sources :

Example 46 with InfGraph

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

the class TestFBRules method testMakeInstance.

/**
     * Test access to makeInstance machinery from a Brule.
     */
public void testMakeInstance() {
    Graph data = Factory.createGraphMem();
    data.add(new Triple(a, ty, C1));
    String rules = "[r1:  (?x p ?t) <- (?x rdf:type C1), makeInstance(?x, p, C2, ?t)]" + "[r2:  (?t rdf:type C2) <- (?x rdf:type C1), makeInstance(?x, p, C2, ?t)]";
    InfGraph infgraph = createInfGraph(rules, data);
    Node valueInstance = getValue(infgraph, a, p);
    assertNotNull(valueInstance);
    Node valueInstance2 = getValue(infgraph, a, p);
    assertEquals(valueInstance, valueInstance2);
    Node valueType = getValue(infgraph, valueInstance, RDF.type.asNode());
    assertEquals(valueType, C2);
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph)

Example 47 with InfGraph

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

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

the class TestFBRules method testBackchain3.

/**
     * Test restriction example
     */
public void testBackchain3() {
    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, ty, OWL.Restriction.asNode()));
    data.add(new Triple(C1, OWL.onProperty.asNode(), p));
    data.add(new Triple(C1, OWL.allValuesFrom.asNode(), c));
    String rules = "[rdfs9:   (?a rdf:type ?y) <- (?x rdfs:subClassOf ?y) (?a rdf:type ?x)]" + "[restriction2: (?C owl:equivalentClass all(?P, ?D)) <- (?C rdf:type owl:Restriction), (?C owl:onProperty ?P), (?C owl:allValuesFrom ?D)]" + "[rs2: (?X rdf:type all(?P,?C)) <- (?D owl:equivalentClass all(?P,?C)), (?X rdf:type ?D)]" + "[rp4: (?Y rdf:type ?C) <- (?X rdf:type all(?P, ?C)), (?X ?P ?Y)]";
    InfGraph infgraph = createInfGraph(rules, 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)

Example 49 with InfGraph

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

the class TestFBRules method testRebind.

/**
     * Test the rebind operation.
     */
public void testRebind() {
    String rules = "[rule1: (?x p ?y) -> (?x q ?y)]";
    Graph data = Factory.createGraphMem();
    data.add(new Triple(n1, p, n2));
    InfGraph infgraph = createInfGraph(rules, data);
    TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), new Triple[] { new Triple(n1, p, n2), new Triple(n1, q, n2) });
    Graph ndata = Factory.createGraphMem();
    ndata.add(new Triple(n1, p, n3));
    infgraph.rebind(ndata);
    TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), new Triple[] { new Triple(n1, p, n3), new Triple(n1, q, n3) });
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph)

Example 50 with InfGraph

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

the class TestFBRules method testHybridRDFS.

/**
     * Test example hybrid rules for rdfs.
     */
public void testHybridRDFS() {
    Graph data = Factory.createGraphMem();
    data.add(new Triple(a, p, b));
    data.add(new Triple(p, RDFS.range.asNode(), C1));
    String rules = "[rdfs2:  (?p rdfs:domain ?c) -> [(?x rdf:type ?c) <- (?x ?p ?y)] ]" + "[rdfs3:  (?p rdfs:range ?c)  -> [(?y rdf:type ?c) <- (?x ?p ?y)] ]" + "[rdfs5a: (?a rdfs:subPropertyOf ?b), (?b rdfs:subPropertyOf ?c) -> (?a rdfs:subPropertyOf ?c)]" + "[rdfs5b: (?a rdf:type rdf:Property) -> (?a rdfs:subPropertyOf ?a)]" + "[rdfs6:  (?p rdfs:subPropertyOf ?q) -> [ (?a ?q ?b) <- (?a ?p ?b)] ]" + "[rdfs7:  (?a rdf:type rdfs:Class) -> (?a rdfs:subClassOf ?a)]" + "[rdfs8:  (?a rdfs:subClassOf ?b), (?b rdfs:subClassOf ?c) -> (?a rdfs:subClassOf ?c)]" + "[rdfs9:  (?x rdfs:subClassOf ?y) -> [ (?a rdf:type ?y) <- (?a rdf:type ?x)] ]";
    InfGraph infgraph = createInfGraph(rules, data);
    //        ((FBRuleInfGraph)infgraph).setTraceOn(true);
    TestUtil.assertIteratorValues(this, infgraph.find(b, ty, null), new Object[] { new Triple(b, ty, C1) });
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) 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