Search in sources :

Example 16 with Reasoner

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

the class TestBackchainer method testBaseRules3.

/**
     * Test basic rule operations - simple AND rule check with tabling.
     */
public void testBaseRules3() {
    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(p, sP, s));
    data.add(new Triple(s, sP, t));
    data.add(new Triple(a, p, b));
    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(p, sP, s), new Triple(s, sP, t), new Triple(p, 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 17 with Reasoner

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

the class TestFBRules method temp.

/**
     * Check cost of creating an empty OWL closure.
     */
public void temp() {
    Graph data = Factory.createGraphMem();
    Graph data2 = Factory.createGraphMem();
    Reasoner reasoner = new OWLFBRuleReasoner(OWLFBRuleReasonerFactory.theInstance());
    FBRuleInfGraph infgraph = (FBRuleInfGraph) reasoner.bind(data);
    FBRuleInfGraph infgraph2 = (FBRuleInfGraph) reasoner.bind(data2);
    long t1 = System.currentTimeMillis();
    infgraph.prepare();
    long t2 = System.currentTimeMillis();
    System.out.println("Prepare on empty graph = " + (t2 - t1) + "ms");
    t1 = System.currentTimeMillis();
    infgraph2.prepare();
    t2 = System.currentTimeMillis();
    System.out.println("Prepare on empty graph = " + (t2 - t1) + "ms");
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) Reasoner(org.apache.jena.reasoner.Reasoner)

Example 18 with Reasoner

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

the class TestFBRules method testSchemaBinding.

/**
     * Test schmea partial binding machinery, forward subset.
     */
public void testSchemaBinding() {
    String rules = "[testRule1: (n1 p ?a) -> (n2, p, ?a)]" + "[testRule2: (n1 q ?a) -> (n2, q, ?a)]" + "[testRule3: (n2 p ?a), (n2 q ?a) -> (res p ?a)]" + "[testBRule4: (n3 p ?a) <- (n1, p, ?a)]";
    List<Rule> ruleList = Rule.parseRules(rules);
    Graph schema = Factory.createGraphMem();
    schema.add(new Triple(n1, p, n3));
    Graph data = Factory.createGraphMem();
    data.add(new Triple(n1, q, n4));
    data.add(new Triple(n1, q, n3));
    Reasoner reasoner = createReasoner(ruleList);
    Reasoner boundReasoner = reasoner.bindSchema(schema);
    InfGraph infgraph = boundReasoner.bind(data);
    TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), new Triple[] { new Triple(n1, p, n3), new Triple(n2, p, n3), new Triple(n3, p, n3), new Triple(n1, q, n4), new Triple(n2, q, n4), new Triple(n1, q, n3), new Triple(n2, q, n3), new Triple(res, p, n3) });
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) Reasoner(org.apache.jena.reasoner.Reasoner)

Example 19 with Reasoner

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

the class TestOWLMisc method testRangeBug.

/**
     * Test bug with leaking variables which results in an incorrect "range = Nothing" deduction.
     */
public void testRangeBug() {
    Model model = FileManager.get().loadModel("file:testing/reasoners/bugs/rangeBug.owl");
    //        Model m = ModelFactory.createDefaultModel();
    Reasoner r = ReasonerRegistry.getOWLReasoner();
    InfModel omodel = ModelFactory.createInfModel(r, model);
    String baseuri = "http://decsai.ugr.es/~ontoserver/bacarex2.owl#";
    //        Resource js = omodel.getResource(baseuri + "JS");
    Resource surname = omodel.getResource(baseuri + "surname");
    Statement s = omodel.createStatement(surname, RDFS.range, OWL.Nothing);
    assertTrue(!omodel.contains(s));
}
Also used : Reasoner(org.apache.jena.reasoner.Reasoner) OntModel(org.apache.jena.ontology.OntModel)

Example 20 with Reasoner

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

the class TestOWLMisc method testLiteralBug.

/**
     * Test change of RDF specs to allow plain literals w/o lang and XSD string to be the same.
     */
public void testLiteralBug() {
    Model model = FileManager.get().loadModel("file:testing/reasoners/bugs/dtValidation.owl");
    //        Model m = ModelFactory.createDefaultModel();
    Reasoner r = ReasonerRegistry.getOWLReasoner();
    InfModel infmodel = ModelFactory.createInfModel(r, model);
    ValidityReport validity = infmodel.validate();
    assertTrue(validity.isValid());
}
Also used : Reasoner(org.apache.jena.reasoner.Reasoner) ValidityReport(org.apache.jena.reasoner.ValidityReport) OntModel(org.apache.jena.ontology.OntModel)

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