KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > rulesys > test > WebOntTestHarness


1 /******************************************************************
2  * File: WebOntTestHarness.java
3  * Created by: Dave Reynolds
4  * Created on: 12-Sep-2003
5  *
6  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
7  * [See end of file]
8  * $Id: WebOntTestHarness.java,v 1.24 2005/02/21 12:18:14 andy_seaborne Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.reasoner.rulesys.test;
11
12 import com.hp.hpl.jena.graph.query.*;
13 import com.hp.hpl.jena.graph.*;
14 import com.hp.hpl.jena.ontology.OntModelSpec;
15 import com.hp.hpl.jena.rdf.model.*;
16 import com.hp.hpl.jena.reasoner.*;
17 import com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph;
18 import com.hp.hpl.jena.reasoner.test.WGReasonerTester;
19 import com.hp.hpl.jena.vocabulary.*;
20
21 import java.io.*;
22 import java.util.*;
23
24 /**
25  * Test harness for running the WebOnt working group tests relevant
26  * to the OWL rule reasoner. See also TestOWLRules which runs the
27  * core WG tests as part of the routine unit tests.
28  *
29  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
30  * @version $Revision: 1.24 $ on $Date: 2005/02/21 12:18:14 $
31  */

32 public class WebOntTestHarness {
33
34 // =======================================================================
35
// Variables to control the test operations
36

37     /** Set to true to include modified test versions */
38     public static boolean includeModified = false;
39     
40     /** Set to true to use approved tests only */
41     public static boolean approvedOnly = true;
42     
43     /** Set to true to print LP engine profile information */
44     public static boolean printProfile = false;
45     
46 // =======================================================================
47
// Internal state
48

49     /** The reasoner being tested */
50     Reasoner reasoner;
51     
52     /** The total set of known tests */
53     Model testDefinitions;
54     
55     /** The number of tests run */
56     int testCount = 0;
57     
58     /** The time cost in ms of the last test to be run */
59     long lastTestDuration = 0;
60     
61     /** Number of tests passed */
62     int passCount = 0;
63     
64     /** The model describing the results of the run */
65     Model testResults;
66     
67     /** The resource which acts as a description for the Jena2 instance being tested */
68     Resource jena2;
69     
70 // =======================================================================
71
// Internal constants
72

73     /** The base directory for the working group test files to use */
74     public static final String JavaDoc BASE_TESTDIR = "testing/wg/";
75     
76     /** The base URI in which the files are purported to reside */
77     public static String JavaDoc BASE_URI = "http://www.w3.org/2002/03owlt/";
78     
79     /** The base URI for the results file */
80     public static String JavaDoc BASE_RESULTS_URI = "http://jena.sourceforge.net/data/owl-results.rdf";
81     
82     /** The list of subdirectories to process (omits the rdf/rdfs dirs) */
83     public static final String JavaDoc[] TEST_DIRS= {"AllDifferent", "AllDistinct",
84             "AnnotationProperty", "DatatypeProperty", "FunctionalProperty",
85             "I3.2", "I3.4", "I4.1", "I4.5", "I4.6", "I5.1", "I5.2", "I5.21", "I5.24",
86             "I5.26", "I5.3", "I5.5", "I5.8", "InverseFunctionalProperty", "Nothing",
87             "Restriction", "SymmetricProperty", "Thing", "TransitiveProperty",
88             "allValuesFrom", "amp-in-url", "cardinality", "complementOf", "datatypes",
89             "differentFrom", "disjointWith", "distinctMembers",
90             "equivalentClass", "equivalentProperty", "imports",
91             "intersectionOf", "inverseOf", "localtests", "maxCardinality", "miscellaneous",
92             "oneOf", "oneOfDistinct", "sameAs", "sameClassAs", "sameIndividualAs",
93             "samePropertyAs", "someValuesFrom", "statement-entailment", "unionOf",
94             "xmlbase",
95             "description-logic",
96 // "extra-credit",
97
};
98     
99     /** List of tests that are blocked because they test language features beyond Lite */
100     public static final String JavaDoc[] BLOCKED_TESTS = {
101         // Explicitly testing non-lite features
102
"http://www.w3.org/2002/03owlt/complementOf/Manifest001#test",
103         "http://www.w3.org/2002/03owlt/description-logic/Manifest901#test",
104         "http://www.w3.org/2002/03owlt/description-logic/Manifest903#test",
105         "http://www.w3.org/2002/03owlt/description-logic/Manifest902#test",
106         "http://www.w3.org/2002/03owlt/description-logic/Manifest904#test",
107 // "http://www.w3.org/2002/03owlt/oneOf/Manifest002#test",
108
// "http://www.w3.org/2002/03owlt/oneOf/Manifest003#test",
109
"http://www.w3.org/2002/03owlt/oneOf/Manifest004#test",
110         "http://www.w3.org/2002/03owlt/unionOf/Manifest001#test",
111         "http://www.w3.org/2002/03owlt/unionOf/Manifest002#test",
112         "http://www.w3.org/2002/03owlt/unionOf/Manifest003#test",
113         "http://www.w3.org/2002/03owlt/unionOf/Manifest004#test",
114         "http://www.w3.org/2002/03owlt/equivalentClass/Manifest006#test",
115         "http://www.w3.org/2002/03owlt/equivalentClass/Manifest007#test",
116         "http://www.w3.org/2002/03owlt/description-logic/Manifest201#test",
117         "http://www.w3.org/2002/03owlt/I5.8/Manifest004#test",
118         "http://www.w3.org/2002/03owlt/I5.2/Manifest004#test",
119         
120         "http://www.w3.org/2002/03owlt/description-logic/Manifest008#test",
121         "http://www.w3.org/2002/03owlt/description-logic/Manifest011#test",
122         "http://www.w3.org/2002/03owlt/description-logic/Manifest015#test",
123         "http://www.w3.org/2002/03owlt/description-logic/Manifest019#test",
124         "http://www.w3.org/2002/03owlt/description-logic/Manifest023#test",
125         "http://www.w3.org/2002/03owlt/description-logic/Manifest026#test",
126         "http://www.w3.org/2002/03owlt/description-logic/Manifest027#test",
127         "http://www.w3.org/2002/03owlt/description-logic/Manifest029#test",
128         "http://www.w3.org/2002/03owlt/description-logic/Manifest030#test",
129         "http://www.w3.org/2002/03owlt/description-logic/Manifest032#test",
130         "http://www.w3.org/2002/03owlt/description-logic/Manifest033#test",
131         "http://www.w3.org/2002/03owlt/description-logic/Manifest035#test",
132
133         "http://www.w3.org/2002/03owlt/description-logic/Manifest101#test",
134         "http://www.w3.org/2002/03owlt/description-logic/Manifest102#test",
135         "http://www.w3.org/2002/03owlt/description-logic/Manifest103#test",
136         "http://www.w3.org/2002/03owlt/description-logic/Manifest104#test",
137         "http://www.w3.org/2002/03owlt/description-logic/Manifest105#test",
138         "http://www.w3.org/2002/03owlt/description-logic/Manifest106#test",
139         "http://www.w3.org/2002/03owlt/description-logic/Manifest107#test",
140         "http://www.w3.org/2002/03owlt/description-logic/Manifest108#test",
141         "http://www.w3.org/2002/03owlt/description-logic/Manifest109#test",
142         "http://www.w3.org/2002/03owlt/description-logic/Manifest110#test",
143         "http://www.w3.org/2002/03owlt/description-logic/Manifest111#test",
144         "http://www.w3.org/2002/03owlt/description-logic/Manifest502#test",
145         "http://www.w3.org/2002/03owlt/description-logic/Manifest504#test",
146         
147         "http://www.w3.org/2002/03owlt/description-logic/Manifest202#test",
148         "http://www.w3.org/2002/03owlt/description-logic/Manifest203#test",
149         "http://www.w3.org/2002/03owlt/description-logic/Manifest204#test",
150         "http://www.w3.org/2002/03owlt/description-logic/Manifest205#test",
151         "http://www.w3.org/2002/03owlt/description-logic/Manifest206#test",
152         "http://www.w3.org/2002/03owlt/description-logic/Manifest207#test",
153         "http://www.w3.org/2002/03owlt/description-logic/Manifest208#test",
154
155         "http://www.w3.org/2002/03owlt/description-logic/Manifest209#test",
156         
157         "http://www.w3.org/2002/03owlt/miscellaneous/Manifest010#test",
158         "http://www.w3.org/2002/03owlt/miscellaneous/Manifest011#test",
159         "http://www.w3.org/2002/03owlt/SymmetricProperty/Manifest002#test",
160         
161         "http://www.w3.org/2002/03owlt/Thing/Manifest005#test",
162         
163         // Temporary block - incomplete (OOM eventually in some cases)
164
"http://www.w3.org/2002/03owlt/TransitiveProperty/Manifest002#test",
165         "http://www.w3.org/2002/03owlt/description-logic/Manifest661#test",
166         "http://www.w3.org/2002/03owlt/description-logic/Manifest662#test",
167         "http://www.w3.org/2002/03owlt/description-logic/Manifest663#test",
168         
169         "http://www.w3.org/2002/03owlt/description-logic/Manifest608#test",
170         "http://www.w3.org/2002/03owlt/description-logic/Manifest611#test",
171         "http://www.w3.org/2002/03owlt/description-logic/Manifest615#test",
172         "http://www.w3.org/2002/03owlt/description-logic/Manifest623#test",
173         "http://www.w3.org/2002/03owlt/description-logic/Manifest626#test",
174         "http://www.w3.org/2002/03owlt/description-logic/Manifest627#test",
175         "http://www.w3.org/2002/03owlt/description-logic/Manifest630#test",
176         "http://www.w3.org/2002/03owlt/description-logic/Manifest668#test",
177         "http://www.w3.org/2002/03owlt/description-logic/Manifest668#test",
178
179     };
180             
181     /** The list of status values to include. If approvedOnly then only the first
182      * entry is allowed */

183     public static final String JavaDoc[] STATUS_FLAGS = { "APPROVED", "PROPOSED" };
184     
185 // =======================================================================
186
// Constructor and associated support
187

188     public WebOntTestHarness() {
189         testDefinitions = loadAllTestDefinitions();
190         reasoner = ReasonerRegistry.getOWLReasoner();
191         initResults();
192     }
193
194     /** Load all of the known manifest files into a single model */
195     public static Model loadAllTestDefinitions() {
196         System.out.print("Loading manifests "); System.out.flush();
197         Model testDefs = ModelFactory.createDefaultModel();
198         int count = 0;
199         for (int idir = 0; idir < TEST_DIRS.length; idir++) {
200             File dir = new File(BASE_TESTDIR + TEST_DIRS[idir]);
201             String JavaDoc[] manifests = dir.list(new FilenameFilter() {
202                     public boolean accept(File df, String JavaDoc name) {
203                         if (name.startsWith("Manifest") && name.endsWith(".rdf")) {
204                             return includeModified || ! name.endsWith("-mod.rdf");
205                         } else {
206                             return false;
207                         }
208                     }
209                 });
210             for (int im = 0; im < manifests.length; im++) {
211                 String JavaDoc manifest = manifests[im];
212                 File mf = new File(dir, manifest);
213                 try {
214                     testDefs.read(new FileInputStream(mf), "file:" + mf);
215                     count ++;
216                     if (count % 8 == 0) {
217                         System.out.print("."); System.out.flush();
218                     }
219                 } catch (FileNotFoundException e) {
220                     System.out.println("File not readable - " + e);
221                 }
222             }
223         }
224         System.out.println("loaded");
225         return testDefs;
226     }
227     
228     /**
229      * Initialize the result model.
230      */

231     public void initResults() {
232         testResults = ModelFactory.createDefaultModel();
233         jena2 = testResults.createResource(BASE_RESULTS_URI + "#jena2");
234         jena2.addProperty(RDFS.comment,
235             testResults.createLiteral(
236                 "<a xmlns=\"http://www.w3.org/1999/xhtml\" HREF=\"http://jena.sourceforce.net/\">Jena2</a> includes a rule-based inference engine for RDF processing, " +
237                 "supporting both forward and backward chaining rules. Its OWL rule set is designed to provide sound " +
238                 "but not complete instance resasoning for that fragment of OWL/Full limited to the OWL/lite vocabulary. In" +
239                 "particular it does not support unionOf/complementOf.",
240                 true)
241         );
242         jena2.addProperty(RDFS.label, "Jena2");
243         testResults.setNsPrefix("results", OWLResults.NS);
244     }
245     
246 // =======================================================================
247
// Main control methods
248

249     public static void main(String JavaDoc[] args) throws IOException {
250         String JavaDoc resultFile = "owl-results.rdf";
251         if (args.length >= 1) {
252             resultFile = args[0];
253         }
254         WebOntTestHarness harness = new WebOntTestHarness();
255         harness.runTests();
256 // harness.runTest("http://www.w3.org/2002/03owlt/AnnotationProperty/Manifest004#test");
257
// harness.runTest("http://www.w3.org/2002/03owlt/AnnotationProperty/Manifest003#test");
258
// harness.runTest("http://www.w3.org/2002/03owlt/Thing/Manifest001#test");
259
// harness.runTest("http://www.w3.org/2002/03owlt/Thing/Manifest002#test");
260
// harness.runTest("http://www.w3.org/2002/03owlt/Thing/Manifest003#test");
261
// harness.runTest("http://www.w3.org/2002/03owlt/Thing/Manifest004#test");
262
// harness.runTest("http://www.w3.org/2002/03owlt/Thing/Manifest005#test");
263
RDFWriter writer = harness.testResults.getWriter("RDF/XML-ABBREV");
264         OutputStream stream = new FileOutputStream(resultFile);
265         writer.setProperty("showXmlDeclaration", "true");
266         harness.testResults.setNsPrefix("", "http://www.w3.org/1999/xhtml");
267         writer.write(harness.testResults, stream, BASE_RESULTS_URI);
268     }
269     
270     /**
271      * Run all relevant tests.
272      */

273     public void runTests() {
274         System.out.println("Testing " + (approvedOnly ? "only APPROVED" : "APPROVED and PROPOSED") );
275         System.out.println("Positive entailment: ");
276         runTests(findTestsOfType(OWLTest.PositiveEntailmentTest));
277 // System.out.println("\nNegative entailment: ");
278
// runTests(findTestsOfType(OWLTest.NegativeEntailmentTest));
279
System.out.println("\nTrue tests: ");
280         runTests(findTestsOfType(OWLTest.TrueTest));
281         System.out.println("\nOWL for OWL tests: ");
282         runTests(findTestsOfType(OWLTest.OWLforOWLTest));
283         System.out.println("\nImport entailment tests: ");
284         runTests(findTestsOfType(OWLTest.ImportEntailmentTest));
285         System.out.println("\nInconsistency tests: ");
286         runTests(findTestsOfType(OWLTest.InconsistencyTest));
287         System.out.println("\nPassed " + passCount + " out of " + testCount);
288     }
289     
290     /**
291      * Run all tests in the given list.
292      */

293     public void runTests(List tests) {
294         for (Iterator i = tests.iterator(); i.hasNext(); ) {
295             runTest( (Resource) i.next() );
296         }
297     }
298     
299     /**
300      * Run a single test of any sort, performing any appropriate logging
301      * and error reporting.
302      */

303     public void runTest(String JavaDoc test) {
304         runTest(testDefinitions.getResource(test));
305     }
306      
307     /**
308      * Run a single test of any sort, performing any appropriate logging
309      * and error reporting.
310      */

311     public void runTest(Resource test) {
312         System.out.println("Running " + test);
313         boolean success = false;
314         boolean fail = false;
315         try {
316             success = doRunTest(test);
317         } catch (Exception JavaDoc e) {
318             fail = true;
319             System.out.print("\nException: " + e);
320             e.printStackTrace();
321         }
322         testCount++;
323         if (success) {
324             System.out.print( (testCount % 40 == 0) ? ".\n" : ".");
325             System.out.flush();
326             passCount++;
327         } else {
328             System.out.println("\nFAIL: " + test);
329         }
330         Resource resultType = null;
331         if (fail) {
332             resultType = OWLResults.FailingRun;
333         } else {
334             if (test.hasProperty(RDF.type, OWLTest.NegativeEntailmentTest)
335             || test.hasProperty(RDF.type, OWLTest.ConsistencyTest)) {
336                 resultType = success ? OWLResults.PassingRun : OWLResults.FailingRun;
337             } else {
338                 resultType = success ? OWLResults.PassingRun : OWLResults.IncompleteRun;
339             }
340         }
341         // log to the rdf result format
342
Resource result = testResults.createResource()
343             .addProperty(RDF.type, OWLResults.TestRun)
344             .addProperty(RDF.type, resultType)
345             .addProperty(OWLResults.test, test)
346             .addProperty(OWLResults.system, jena2);
347     }
348     
349     /**
350      * Run a single test of any sort, return true if the test succeeds.
351      */

352     public boolean doRunTest(Resource test) throws IOException {
353         if (test.hasProperty(RDF.type, OWLTest.PositiveEntailmentTest)
354         || test.hasProperty(RDF.type, OWLTest.NegativeEntailmentTest)
355         || test.hasProperty(RDF.type, OWLTest.OWLforOWLTest)
356         || test.hasProperty(RDF.type, OWLTest.ImportEntailmentTest)
357         || test.hasProperty(RDF.type, OWLTest.TrueTest) ) {
358             // Entailment tests
359
boolean processImports = test.hasProperty(RDF.type, OWLTest.ImportEntailmentTest);
360             Model premises = getDoc(test, RDFTest.premiseDocument, processImports);
361             Model conclusions = getDoc(test, RDFTest.conclusionDocument);
362             comprehensionAxioms(premises, conclusions);
363             long t1 = System.currentTimeMillis();
364             InfGraph graph = reasoner.bind(premises.getGraph());
365             if (printProfile) {
366                 ((FBRuleInfGraph)graph).resetLPProfile(true);
367             }
368             Model result = ModelFactory.createModelForGraph(graph);
369             boolean correct = testEntailment(conclusions.getGraph(), result.getGraph());
370             long t2 = System.currentTimeMillis();
371             lastTestDuration = t2 - t1;
372             if (printProfile) {
373                 ((FBRuleInfGraph)graph).printLPProfile();
374             }
375             if (test.hasProperty(RDF.type, OWLTest.NegativeEntailmentTest)) {
376                 correct = !correct;
377             }
378             return correct;
379         } else if (test.hasProperty(RDF.type, OWLTest.InconsistencyTest)) {
380 // System.out.println("Starting: " + test);
381
Model input = getDoc(test, RDFTest.inputDocument);
382             long t1 = System.currentTimeMillis();
383             InfGraph graph = reasoner.bind(input.getGraph());
384             boolean correct = ! graph.validate().isValid();
385             long t2 = System.currentTimeMillis();
386             lastTestDuration = t2 - t1;
387             return correct;
388         } else if (test.hasProperty(RDF.type, OWLTest.ConsistencyTest)) {
389             // Not used normally becase we are not complete enough to prove consistency
390
// System.out.println("Starting: " + test);
391
Model input = getDoc(test, RDFTest.inputDocument);
392             long t1 = System.currentTimeMillis();
393             InfGraph graph = reasoner.bind(input.getGraph());
394             boolean correct = graph.validate().isValid();
395             long t2 = System.currentTimeMillis();
396             lastTestDuration = t2 - t1;
397             return correct;
398         } else {
399             for (StmtIterator i = test.listProperties(RDF.type); i.hasNext(); ) {
400                 System.out.println("Test type = " + i.nextStatement().getObject());
401             }
402             throw new ReasonerException("Unknown test type");
403         }
404     }
405    
406     /**
407      * Load the premises or conclusions for the test, optional performing
408      * import processing.
409      */

410     public Model getDoc(Resource test, Property docType, boolean processImports) throws IOException {
411         if (processImports) {
412             Model result = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
413             StmtIterator si = test.listProperties(docType);
414             while ( si.hasNext() ) {
415                 String JavaDoc fname = si.nextStatement().getObject().toString() + ".rdf";
416                 loadFile(fname, result);
417             }
418             return result;
419         } else {
420             return getDoc(test, docType);
421         }
422     }
423    
424     /**
425      * Load the premises or conclusions for the test.
426      */

427     public Model getDoc(Resource test, Property docType) throws IOException {
428         Model result = ModelFactory.createDefaultModel();
429         StmtIterator si = test.listProperties(docType);
430         while ( si.hasNext() ) {
431             String JavaDoc fname = si.nextStatement().getObject().toString() + ".rdf";
432             loadFile(fname, result);
433         }
434         return result;
435     }
436
437     /**
438      * Utility to load a file into a model a Model.
439      * Files are assumed to be relative to the BASE_URI.
440      * @param file the file name, relative to baseDir
441      * @return the loaded Model
442      */

443     public static Model loadFile(String JavaDoc file, Model model) throws IOException {
444         String JavaDoc langType = "RDF/XML";
445         if (file.endsWith(".nt")) {
446             langType = "N-TRIPLE";
447         } else if (file.endsWith("n3")) {
448             langType = "N3";
449         }
450         String JavaDoc fname = file;
451         if (fname.startsWith(BASE_URI)) {
452             fname = fname.substring(BASE_URI.length());
453         }
454         Reader reader = new BufferedReader(new FileReader(BASE_TESTDIR + fname));
455         model.read(reader, BASE_URI + fname, langType);
456         return model;
457     }
458     
459     /**
460      * Test a conclusions graph against a result graph. This works by
461      * translating the conclusions graph into a find query which contains one
462      * variable for each distinct bNode in the conclusions graph.
463      */

464     public boolean testEntailment(Graph conclusions, Graph result) {
465         QueryHandler qh = result.queryHandler();
466         Query query = WGReasonerTester.graphToQuery(conclusions);
467         Iterator i = qh.prepareBindings(query, new Node[] {}).executeBindings();
468         return i.hasNext();
469     }
470     
471     /**
472      * Example the conclusions graph for introduction of restrictions which
473      * require a comprehension rewrite and declare new (anon) classes
474      * for those restrictions.
475      */

476     public void comprehensionAxioms(Model premises, Model conclusions) {
477         // Comprehend all restriction declarations and note them in a map
478
Map comprehension = new HashMap();
479         StmtIterator ri = conclusions.listStatements(null, RDF.type, OWL.Restriction);
480         while (ri.hasNext()) {
481             Resource restriction = ri.nextStatement().getSubject();
482             StmtIterator pi = restriction.listProperties(OWL.onProperty);
483             while (pi.hasNext()) {
484                 Resource prop = (Resource)pi.nextStatement().getObject();
485                 StmtIterator vi = restriction.listProperties();
486                 while (vi.hasNext()) {
487                     Statement rs = vi.nextStatement();
488                     if ( ! rs.getPredicate().equals(OWL.onProperty)) {
489                         // Have a restriction on(prop) of type rs in the conclusions
490
// So assert a premise that such a restriction could exisit
491
Resource comp = premises.createResource()
492                             .addProperty(RDF.type, OWL.Restriction)
493                             .addProperty(OWL.onProperty, prop)
494                             .addProperty(rs.getPredicate(), rs.getObject());
495                         comprehension.put(restriction, comp);
496                     }
497                 }
498             }
499         }
500         // Comprehend any intersectionOf lists. Introduce anon class which has the form
501
// of the intersection expression.
502
// Rewrite queries of the form (X intersectionOf Y) to the form
503
// (X equivalentClass ?CC) (?CC intersectionOf Y)
504
StmtIterator ii = conclusions.listStatements(null, OWL.intersectionOf, (RDFNode)null);
505         List intersections = new ArrayList();
506         while (ii.hasNext()) {
507             intersections.add(ii.next());
508         }
509         for (Iterator i = intersections.iterator(); i.hasNext(); ) {
510             Statement is = (Statement)i.next();
511             // Declare in the premises that such an intersection exists
512
Resource comp = premises.createResource()
513                    .addProperty(RDF.type, OWL.Class)
514                    .addProperty(OWL.intersectionOf, mapList(premises, (Resource)is.getObject(), comprehension));
515             // Rewrite the conclusions to be a test for equivalence between the class being
516
// queried and the comprehended interesection
517
conclusions.remove(is);
518             conclusions.add(is.getSubject(), OWL.equivalentClass, comp);
519         }
520         // Comprehend any oneOf lists
521
StmtIterator io = conclusions.listStatements(null, OWL.oneOf, (RDFNode)null);
522         while (io.hasNext()) {
523             Statement s = io.nextStatement();
524             Resource comp = premises.createResource()
525                         .addProperty(OWL.oneOf, s.getObject());
526         }
527     }
528
529     /**
530      * Helper. Adds to the target model a translation of the given RDF list
531      * with each element replaced according to the map.
532      */

533     private Resource mapList(Model target, Resource list, Map map) {
534         if (list.equals(RDF.nil)) {
535             return RDF.nil;
536         } else {
537             Resource head = (Resource) list.getRequiredProperty(RDF.first).getObject();
538             Resource rest = (Resource) list.getRequiredProperty(RDF.rest).getObject();
539             Resource mapElt = target.createResource();
540             Resource mapHead = (Resource) map.get(head);
541             if (mapHead == null) mapHead = head;
542             mapElt.addProperty(RDF.first, mapHead);
543             mapElt.addProperty(RDF.rest, mapList(target, rest, map));
544             return mapElt;
545         }
546     }
547     
548 // =======================================================================
549
// Internal helper functions
550

551     /** Return a list of all tests of the given type, according to the current filters */
552     public List findTestsOfType(Resource testType) {
553         ArrayList result = new ArrayList();
554         StmtIterator si = testDefinitions.listStatements(null, RDF.type, testType);
555         while (si.hasNext()) {
556             Resource test = si.nextStatement().getSubject();
557             boolean accept = true;
558             // Check test status
559
Literal status = (Literal) test.getProperty(RDFTest.status).getObject();
560             if (approvedOnly) {
561                 accept = status.getString().equals(STATUS_FLAGS[0]);
562             } else {
563                 accept = false;
564                 for (int i = 0; i < STATUS_FLAGS.length; i++) {
565                     if (status.getString().equals(STATUS_FLAGS[i])) {
566                         accept = true;
567                         break;
568                     }
569                 }
570             }
571             // Check for blocked tests
572
for (int i = 0; i < BLOCKED_TESTS.length; i++) {
573                 if (BLOCKED_TESTS[i].equals(test.toString())) {
574                     accept = false;
575                 }
576             }
577             // End of filter tests
578
if (accept) {
579                 result.add(test);
580             }
581         }
582         return result;
583     }
584 }
585
586
587 /*
588     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
589     All rights reserved.
590
591     Redistribution and use in source and binary forms, with or without
592     modification, are permitted provided that the following conditions
593     are met:
594
595     1. Redistributions of source code must retain the above copyright
596        notice, this list of conditions and the following disclaimer.
597
598     2. Redistributions in binary form must reproduce the above copyright
599        notice, this list of conditions and the following disclaimer in the
600        documentation and/or other materials provided with the distribution.
601
602     3. The name of the author may not be used to endorse or promote products
603        derived from this software without specific prior written permission.
604
605     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
606     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
607     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
608     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
609     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
610     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
611     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
612     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
613     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
614     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
615 */
Popular Tags