⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webonttestharness.java

📁 Jena推理机
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/******************************************************************
 * File:        WebOntTestHarness.java
 * Created by:  Dave Reynolds
 * Created on:  12-Sep-2003
 * 
 * (c) Copyright 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP, all rights reserved.
 * [See end of file]
 * $Id: WebOntTestHarness.java,v 1.26 2007/01/02 11:50:31 andy_seaborne Exp $
 *****************************************************************/
package com.hp.hpl.jena.reasoner.rulesys.test;

import com.hp.hpl.jena.graph.query.*;
import com.hp.hpl.jena.graph.*;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.reasoner.*;
import com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph;
import com.hp.hpl.jena.reasoner.test.WGReasonerTester;
import com.hp.hpl.jena.vocabulary.*;

import java.io.*;
import java.util.*;

/**
 * Test harness for running the WebOnt working group tests relevant 
 * to the OWL rule reasoner. See also TestOWLRules which runs the
 * core WG tests as part of the routine unit tests.
 * 
 * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
 * @version $Revision: 1.26 $ on $Date: 2007/01/02 11:50:31 $
 */
public class WebOntTestHarness {

//  =======================================================================
//  Variables to control the test operations

    /** Set to true to include modified test versions */
    public static boolean includeModified = false;
    
    /** Set to true to use approved tests only */
    public static boolean approvedOnly = true;
    
    /** Set to true to print LP engine profile information */
    public static boolean printProfile = false;
    
//  =======================================================================
//  Internal state

    /** The reasoner being tested */
    Reasoner reasoner;
    
    /** The total set of known tests */
    Model testDefinitions;
    
    /** The number of tests run */
    int testCount = 0;
    
    /** The time cost in ms of the last test to be run */
    long lastTestDuration = 0;
    
    /** Number of tests passed */
    int passCount = 0;
    
    /** The model describing the results of the run */
    Model testResults;
    
    /** The resource which acts as a description for the Jena2 instance being tested */
    Resource jena2;
    
//  =======================================================================
//  Internal constants

    /** The base directory for the working group test files to use */
    public static final String BASE_TESTDIR = "testing/wg/";
    
    /** The base URI in which the files are purported to reside */
    public static String BASE_URI = "http://www.w3.org/2002/03owlt/";
    
    /** The base URI for the results file */
    public static String BASE_RESULTS_URI = "http://jena.sourceforge.net/data/owl-results.rdf";
    
    /** The list of subdirectories to process (omits the rdf/rdfs dirs) */
    public static final String[] TEST_DIRS= {"AllDifferent", "AllDistinct", 
            "AnnotationProperty", "DatatypeProperty", "FunctionalProperty",
            "I3.2", "I3.4", "I4.1", "I4.5", "I4.6", "I5.1", "I5.2", "I5.21", "I5.24",
            "I5.26", "I5.3", "I5.5", "I5.8", "InverseFunctionalProperty", "Nothing", 
            "Restriction", "SymmetricProperty", "Thing", "TransitiveProperty", 
            "allValuesFrom", "amp-in-url", "cardinality", "complementOf", "datatypes", 
            "differentFrom", "disjointWith", "distinctMembers", 
            "equivalentClass", "equivalentProperty", "imports", 
            "intersectionOf", "inverseOf", "localtests", "maxCardinality", "miscellaneous",
            "oneOf", "oneOfDistinct", "sameAs", "sameClassAs", "sameIndividualAs", 
            "samePropertyAs", "someValuesFrom", "statement-entailment", "unionOf", 
            "xmlbase",
            "description-logic", 
//            "extra-credit", 
        };
    
    /** List of tests that are blocked because they test language features beyond Lite */
    public static final String[] BLOCKED_TESTS = {
        // Explicitly testing non-lite features
        "http://www.w3.org/2002/03owlt/complementOf/Manifest001#test", 
        "http://www.w3.org/2002/03owlt/description-logic/Manifest901#test", 
        "http://www.w3.org/2002/03owlt/description-logic/Manifest903#test", 
        "http://www.w3.org/2002/03owlt/description-logic/Manifest902#test", 
        "http://www.w3.org/2002/03owlt/description-logic/Manifest904#test", 
//        "http://www.w3.org/2002/03owlt/oneOf/Manifest002#test", 
//        "http://www.w3.org/2002/03owlt/oneOf/Manifest003#test", 
        "http://www.w3.org/2002/03owlt/oneOf/Manifest004#test", 
        "http://www.w3.org/2002/03owlt/unionOf/Manifest001#test", 
        "http://www.w3.org/2002/03owlt/unionOf/Manifest002#test",
        "http://www.w3.org/2002/03owlt/unionOf/Manifest003#test",
        "http://www.w3.org/2002/03owlt/unionOf/Manifest004#test",
        "http://www.w3.org/2002/03owlt/equivalentClass/Manifest006#test",
        "http://www.w3.org/2002/03owlt/equivalentClass/Manifest007#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest201#test",
        "http://www.w3.org/2002/03owlt/I5.8/Manifest004#test",
        "http://www.w3.org/2002/03owlt/I5.2/Manifest004#test",
        
        "http://www.w3.org/2002/03owlt/description-logic/Manifest008#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest011#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest015#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest019#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest023#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest026#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest027#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest029#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest030#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest032#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest033#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest035#test",

        "http://www.w3.org/2002/03owlt/description-logic/Manifest101#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest102#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest103#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest104#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest105#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest106#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest107#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest108#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest109#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest110#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest111#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest502#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest504#test",
        
        "http://www.w3.org/2002/03owlt/description-logic/Manifest202#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest203#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest204#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest205#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest206#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest207#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest208#test",

        "http://www.w3.org/2002/03owlt/description-logic/Manifest209#test",
        
        "http://www.w3.org/2002/03owlt/miscellaneous/Manifest010#test",
        "http://www.w3.org/2002/03owlt/miscellaneous/Manifest011#test",
        "http://www.w3.org/2002/03owlt/SymmetricProperty/Manifest002#test",
        
        "http://www.w3.org/2002/03owlt/Thing/Manifest005#test",
        
        // Temporary block - incomplete (OOM eventually in some cases)
        "http://www.w3.org/2002/03owlt/TransitiveProperty/Manifest002#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest661#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest662#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest663#test",
        
        "http://www.w3.org/2002/03owlt/description-logic/Manifest608#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest611#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest615#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest623#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest626#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest627#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest630#test",        
        "http://www.w3.org/2002/03owlt/description-logic/Manifest668#test",
        "http://www.w3.org/2002/03owlt/description-logic/Manifest668#test",

    };
            
    /** The list of status values to include. If approvedOnly then only the first
     *  entry is allowed */
    public static final String[] STATUS_FLAGS = { "APPROVED", "PROPOSED" };
    
//  =======================================================================
//  Constructor and associated support
    
    public WebOntTestHarness() {
        testDefinitions = loadAllTestDefinitions();
        reasoner = ReasonerRegistry.getOWLReasoner();
        initResults();
    }

    /** Load all of the known manifest files into a single model */
    public static Model loadAllTestDefinitions() {
        System.out.print("Loading manifests "); System.out.flush();
        Model testDefs = ModelFactory.createDefaultModel();
        int count = 0;
        for (int idir = 0; idir < TEST_DIRS.length; idir++) {
            File dir = new File(BASE_TESTDIR + TEST_DIRS[idir]);
            String[] manifests = dir.list(new FilenameFilter() {
                    public boolean accept(File df, String name) {
                        if (name.startsWith("Manifest") && name.endsWith(".rdf")) {
                            return includeModified || ! name.endsWith("-mod.rdf");
                        } else {
                            return false;
                        }
                    }
                });
            for (int im = 0; im < manifests.length; im++) {
                String manifest = manifests[im];
                File mf = new File(dir, manifest);
                try {
                    testDefs.read(new FileInputStream(mf), "file:" + mf);
                    count ++;
                    if (count % 8 == 0) {
                        System.out.print("."); System.out.flush();
                    }
                } catch (FileNotFoundException e) {
                    System.out.println("File not readable - " + e);
                }
            }
        }
        System.out.println("loaded");
        return testDefs;
    }
    
    /** 
     * Initialize the result model.
     */
    public void initResults() {
        testResults = ModelFactory.createDefaultModel();
        jena2 = testResults.createResource(BASE_RESULTS_URI + "#jena2");
        jena2.addProperty(RDFS.comment, 
            testResults.createLiteral(
                "<a xmlns=\"http://www.w3.org/1999/xhtml\" href=\"http://jena.sourceforce.net/\">Jena2</a> includes a rule-based inference engine for RDF processing, " +
                "supporting both forward and backward chaining rules. Its OWL rule set is designed to provide sound " +
                "but not complete instance resasoning for that fragment of OWL/Full limited to the OWL/lite vocabulary. In" +
                "particular it does not support unionOf/complementOf.",
                true)
        );
        jena2.addProperty(RDFS.label, "Jena2");
        testResults.setNsPrefix("results", OWLResults.NS);
    }
    
//  =======================================================================
//  Main control methods
    
    public static void main(String[] args) throws IOException {
        String resultFile = "owl-results.rdf";
        if (args.length >= 1) {
            resultFile = args[0];
        }
        WebOntTestHarness harness = new WebOntTestHarness();
        harness.runTests();
//        harness.runTest("http://www.w3.org/2002/03owlt/AnnotationProperty/Manifest004#test");
//        harness.runTest("http://www.w3.org/2002/03owlt/AnnotationProperty/Manifest003#test");
//        harness.runTest("http://www.w3.org/2002/03owlt/Thing/Manifest001#test");
//        harness.runTest("http://www.w3.org/2002/03owlt/Thing/Manifest002#test");
//        harness.runTest("http://www.w3.org/2002/03owlt/Thing/Manifest003#test");
//        harness.runTest("http://www.w3.org/2002/03owlt/Thing/Manifest004#test");
//        harness.runTest("http://www.w3.org/2002/03owlt/Thing/Manifest005#test");
        RDFWriter writer = harness.testResults.getWriter("RDF/XML-ABBREV");
        OutputStream stream = new FileOutputStream(resultFile);
        writer.setProperty("showXmlDeclaration", "true");
        harness.testResults.setNsPrefix("", "http://www.w3.org/1999/xhtml");
        writer.write(harness.testResults, stream, BASE_RESULTS_URI);
    }
    
    /**
     * Run all relevant tests.
     */
    public void runTests() {
        System.out.println("Testing " + (approvedOnly ? "only APPROVED" : "APPROVED and PROPOSED") );
        System.out.println("Positive entailment: ");
        runTests(findTestsOfType(OWLTest.PositiveEntailmentTest));
//        System.out.println("\nNegative entailment: ");
//        runTests(findTestsOfType(OWLTest.NegativeEntailmentTest));
        System.out.println("\nTrue tests: ");
        runTests(findTestsOfType(OWLTest.TrueTest));
        System.out.println("\nOWL for OWL tests: ");
        runTests(findTestsOfType(OWLTest.OWLforOWLTest));
        System.out.println("\nImport entailment tests: ");
        runTests(findTestsOfType(OWLTest.ImportEntailmentTest));
        System.out.println("\nInconsistency tests: ");
        runTests(findTestsOfType(OWLTest.InconsistencyTest));
        System.out.println("\nPassed " + passCount + " out of " + testCount);
    }
    
    /**
     * Run all tests in the given list.
     */
    public void runTests(List tests) {
        for (Iterator i = tests.iterator(); i.hasNext(); ) {
            runTest( (Resource) i.next() );
        }
    }
    
    /**
     * Run a single test of any sort, performing any appropriate logging
     * and error reporting.
     */
    public void runTest(String test) {
        runTest(testDefinitions.getResource(test));
    }
     
    /**
     * Run a single test of any sort, performing any appropriate logging

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -