Search in sources :

Example 71 with InfGraph

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

InfGraph (org.apache.jena.reasoner.InfGraph)71 Reasoner (org.apache.jena.reasoner.Reasoner)36 Graph (org.apache.jena.graph.Graph)12 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