Search in sources :

Example 6 with FBRuleInfGraph

use of org.apache.jena.reasoner.rulesys.FBRuleInfGraph in project jena by apache.

the class OWLWGTester method runTest.

/**
     * Run a single designated test.
     * @param test the root node descibing the test
     * @param log set to true to enable derivation logging
     * @param stats set to true to log performance statistics
     * @return true if the test passes
     * @throws IOException if one of the test files can't be found
     */
public boolean runTest(Resource test, boolean log, boolean stats) throws IOException {
    // Find the specification for the named test
    RDFNode testType = test.getRequiredProperty(RDF.type).getObject();
    if (!(testType.equals(NegativeEntailmentTest) || testType.equals(PositiveEntailmentTest))) {
        throw new JenaException("Can't find test: " + test);
    }
    String description = test.getRequiredProperty(descriptionP).getObject().toString();
    String status = test.getRequiredProperty(statusP).getObject().toString();
    logger.debug("WG test " + test.getURI() + " - " + status);
    // Load up the premise documents
    Model premises = ModelFactory.createDefaultModel();
    for (StmtIterator premisesI = test.listProperties(premiseDocumentP); premisesI.hasNext(); ) {
        premises.add(loadFile(premisesI.nextStatement().getObject().toString() + ".rdf"));
    }
    // Load up the conclusions document
    Resource conclusionsRes = (Resource) test.getRequiredProperty(conclusionDocumentP).getObject();
    Model conclusions = loadFile(conclusionsRes.toString() + ".rdf");
    // Optional logging
    if (log) {
        if (configuration == null) {
            Model m = ModelFactory.createDefaultModel();
            configuration = m.createResource();
        }
        configuration.addProperty(ReasonerVocabulary.PROPtraceOn, "true").addProperty(ReasonerVocabulary.PROPderivationLogging, "true");
    }
    Reasoner reasoner = reasonerF.create(configuration);
    long t1 = System.currentTimeMillis();
    InfGraph graph = reasoner.bind(premises.getGraph());
    Model result = ModelFactory.createModelForGraph(graph);
    if (stats && graph instanceof FBRuleInfGraph) {
    //            ((FBRuleInfGraph)graph).resetLPProfile(true);
    }
    // Check the results against the official conclusions
    boolean correct = true;
    if (testType.equals(PositiveEntailmentTest)) {
        correct = WGReasonerTester.testConclusions(conclusions.getGraph(), result.getGraph());
    } else {
        // A negative entailment check
        correct = !WGReasonerTester.testConclusions(conclusions.getGraph(), result.getGraph());
    }
    long t2 = System.currentTimeMillis();
    timeCost += (t2 - t1);
    numTests++;
    if (stats) {
        logger.info("Time=" + (t2 - t1) + "ms for " + test.getURI());
        printStats();
        if (graph instanceof FBRuleInfGraph) {
            ((FBRuleInfGraph) graph).printLPProfile();
        }
    }
    if (!correct) {
    // List all the forward deductions for debugging
    //            if (graph instanceof FBRuleInfGraph) {
    //                System.out.println("Error: deductions graph was ...");
    //                FBRuleInfGraph fbGraph = (FBRuleInfGraph)graph;
    //                Graph deductions = fbGraph.getDeductionsGraph();
    //                org.apache.jena.PrintUtil.printOut(deductions.find(null,null,null));
    //            }
    }
    // Signal the results        
    if (testcase != null) {
        Assert.assertTrue("Test: " + test + "\n" + reasonerF.getURI() + "\n" + description, correct);
    }
    return correct;
}
Also used : JenaException(org.apache.jena.shared.JenaException) FBRuleInfGraph(org.apache.jena.reasoner.rulesys.FBRuleInfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) FBRuleInfGraph(org.apache.jena.reasoner.rulesys.FBRuleInfGraph) Reasoner(org.apache.jena.reasoner.Reasoner)

Example 7 with FBRuleInfGraph

use of org.apache.jena.reasoner.rulesys.FBRuleInfGraph in project jena by apache.

the class TestLPDerivation method makeInfGraph.

/**
     * Return an inference graph working over the given rule set and raw data.
     * Can be overridden by subclasses of this test class.
     * @param rules the rule set to use
     * @param data the graph of triples to process
     * @param tabled an array of predicates that should be tabled
     */
public static InfGraph makeInfGraph(List<Rule> rules, Graph data, Node[] tabled) {
    FBRuleReasoner reasoner = new FBRuleReasoner(rules);
    FBRuleInfGraph infgraph = (FBRuleInfGraph) reasoner.bind(data);
    for (Node aTabled : tabled) {
        infgraph.setTabled(aTabled);
    }
    //        infgraph.setTraceOn(true);
    infgraph.setDerivationLogging(true);
    return infgraph;
}
Also used : FBRuleReasoner(org.apache.jena.reasoner.rulesys.FBRuleReasoner) FBRuleInfGraph(org.apache.jena.reasoner.rulesys.FBRuleInfGraph)

Example 8 with FBRuleInfGraph

use of org.apache.jena.reasoner.rulesys.FBRuleInfGraph in project jena by apache.

the class TestOWLMisc method hiddenTestOWLLoop.

/**
     * Test looping on recursive someValuesFrom.
     */
public void hiddenTestOWLLoop() {
    Model data = FileManager.get().loadModel("file:testing/reasoners/bugs/loop.owl");
    InfModel infmodel = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), data);
    ((FBRuleInfGraph) infmodel.getGraph()).setTraceOn(true);
    String baseURI = "http://jena.hpl.hp.com/eg#";
    Resource C = infmodel.getResource(baseURI + "C");
    Resource I = infmodel.getResource(baseURI + "i");
    Property R = infmodel.getProperty(baseURI, "R");
    //        ((FBRuleInfGraph)infmodel.getGraph()).setTraceOn(true);
    System.out.println("Check that the instance does have an R property");
    Statement s = I.getProperty(R);
    System.out.println(" - " + s);
    System.out.println("And that the type of the R property is C");
    Statement s2 = ((Resource) s.getObject()).getProperty(RDF.type);
    System.out.println(" - " + s2);
    System.out.println("But does that have an R property?");
    Statement s3 = ((Resource) s.getObject()).getProperty(R);
    System.out.println(" - " + s3);
    System.out.println("List all instances of C");
    int count = 0;
    for (Iterator<Statement> i = infmodel.listStatements(null, RDF.type, C); i.hasNext(); ) {
        Statement st = i.next();
        System.out.println(" - " + st);
        count++;
    }
    System.out.println("OK");
//        infmodel.write(System.out);
//        System.out.flush();
}
Also used : FBRuleInfGraph(org.apache.jena.reasoner.rulesys.FBRuleInfGraph) OntModel(org.apache.jena.ontology.OntModel) DatatypeProperty(org.apache.jena.ontology.DatatypeProperty)

Example 9 with FBRuleInfGraph

use of org.apache.jena.reasoner.rulesys.FBRuleInfGraph in project jena by apache.

the class WebOntTestHarness method doRunTest.

/**
     * Run a single test of any sort, return true if the test succeeds.
     */
public boolean doRunTest(Resource test) throws IOException {
    if (test.hasProperty(RDF.type, OWLTest.PositiveEntailmentTest) || test.hasProperty(RDF.type, OWLTest.NegativeEntailmentTest) || test.hasProperty(RDF.type, OWLTest.OWLforOWLTest) || test.hasProperty(RDF.type, OWLTest.ImportEntailmentTest) || test.hasProperty(RDF.type, OWLTest.TrueTest)) {
        // Entailment tests
        boolean processImports = test.hasProperty(RDF.type, OWLTest.ImportEntailmentTest);
        Model premises = getDoc(test, RDFTest.premiseDocument, processImports);
        Model conclusions = getDoc(test, RDFTest.conclusionDocument);
        comprehensionAxioms(premises, conclusions);
        long t1 = System.currentTimeMillis();
        InfGraph graph = reasoner.bind(premises.getGraph());
        if (printProfile) {
            ((FBRuleInfGraph) graph).resetLPProfile(true);
        }
        Model result = ModelFactory.createModelForGraph(graph);
        boolean correct = WGReasonerTester.testConclusions(conclusions.getGraph(), result.getGraph());
        long t2 = System.currentTimeMillis();
        lastTestDuration = t2 - t1;
        if (printProfile) {
            ((FBRuleInfGraph) graph).printLPProfile();
        }
        if (test.hasProperty(RDF.type, OWLTest.NegativeEntailmentTest)) {
            correct = !correct;
        }
        return correct;
    } else if (test.hasProperty(RDF.type, OWLTest.InconsistencyTest)) {
        //            System.out.println("Starting: " + test);
        Model input = getDoc(test, RDFTest.inputDocument);
        long t1 = System.currentTimeMillis();
        InfGraph graph = reasoner.bind(input.getGraph());
        boolean correct = !graph.validate().isValid();
        long t2 = System.currentTimeMillis();
        lastTestDuration = t2 - t1;
        return correct;
    } else if (test.hasProperty(RDF.type, OWLTest.ConsistencyTest)) {
        // Not used normally becase we are not complete enough to prove consistency
        //            System.out.println("Starting: " + test);
        Model input = getDoc(test, RDFTest.inputDocument);
        long t1 = System.currentTimeMillis();
        InfGraph graph = reasoner.bind(input.getGraph());
        boolean correct = graph.validate().isValid();
        long t2 = System.currentTimeMillis();
        lastTestDuration = t2 - t1;
        return correct;
    } else {
        for (StmtIterator i = test.listProperties(RDF.type); i.hasNext(); ) {
            System.out.println("Test type = " + i.nextStatement().getObject());
        }
        throw new ReasonerException("Unknown test type");
    }
}
Also used : FBRuleInfGraph(org.apache.jena.reasoner.rulesys.FBRuleInfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) FBRuleInfGraph(org.apache.jena.reasoner.rulesys.FBRuleInfGraph) ReasonerException(org.apache.jena.reasoner.ReasonerException)

Aggregations

FBRuleInfGraph (org.apache.jena.reasoner.rulesys.FBRuleInfGraph)9 Graph (org.apache.jena.graph.Graph)5 Triple (org.apache.jena.graph.Triple)5 Rule (org.apache.jena.reasoner.rulesys.Rule)5 Test (org.junit.Test)5 InfGraph (org.apache.jena.reasoner.InfGraph)2 Node (org.apache.jena.graph.Node)1 DatatypeProperty (org.apache.jena.ontology.DatatypeProperty)1 OntModel (org.apache.jena.ontology.OntModel)1 Reasoner (org.apache.jena.reasoner.Reasoner)1 ReasonerException (org.apache.jena.reasoner.ReasonerException)1 FBRuleReasoner (org.apache.jena.reasoner.rulesys.FBRuleReasoner)1 JenaException (org.apache.jena.shared.JenaException)1