KickJava   Java API By Example, From Geeks To Geeks.

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


1 /******************************************************************
2  * File: TestOWLConsistency.java
3  * Created by: Dave Reynolds
4  * Created on: 24-Aug-2003
5  *
6  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
7  * [See end of file]
8  * $Id: TestOWLConsistency.java,v 1.5 2005/04/11 11:27:04 der Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.reasoner.rulesys.test;
11
12 import com.hp.hpl.jena.rdf.model.*;
13 import com.hp.hpl.jena.reasoner.*;
14 import com.hp.hpl.jena.util.FileManager;
15
16 //import java.util.*;
17

18 import junit.framework.TestCase;
19 import junit.framework.TestSuite;
20
21 /**
22  * Test the preliminary OWL validation rules.
23  *
24  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
25  * @version $Revision: 1.5 $ on $Date: 2005/04/11 11:27:04 $
26  */

27 public class TestOWLConsistency extends TestCase {
28      
29     /** The tbox/ontology file to test against sample data */
30     public static final String JavaDoc testTbox = "file:testing/reasoners/owl/tbox.owl";
31     
32     /** A cached copy of the bound reasoner */
33     public static Reasoner reasonerCache;
34      
35     /**
36      * Boilerplate for junit
37      */

38     public TestOWLConsistency( String JavaDoc name ) {
39         super( name );
40     }
41     
42     /**
43      * Boilerplate for junit.
44      * This is its own test suite
45      */

46     public static TestSuite suite() {
47         return new TestSuite( TestOWLConsistency.class );
48 // TestSuite suite = new TestSuite();
49
// suite.addTest(new TestOWLConsistency( "testInconsistent5" ));
50
// return suite;
51
}
52
53     /**
54      * Create, or retrieve from cache, an OWL reasoner already bound
55      * to the test tbox.
56      */

57     public Reasoner makeReasoner() {
58         if (reasonerCache == null) {
59             Model tbox = FileManager.get().loadModel(testTbox);
60             reasonerCache = ReasonerRegistry.getOWLReasoner().bindSchema(tbox.getGraph());
61         }
62         return reasonerCache;
63     }
64     
65     /**
66      * Should be consistent.
67      */

68     public void testConsistent() {
69         assertTrue(doTestOn("file:testing/reasoners/owl/consistentData.rdf"));
70     }
71     
72     /**
73      * Should find problem due to overlap of disjoint classes.
74      */

75     public void testInconsistent1() {
76         assertTrue( ! doTestOn("file:testing/reasoners/owl/inconsistent1.rdf"));
77     }
78     
79     /**
80      * Should find problem due to type violations
81      */

82     public void testInconsistent2() {
83         assertTrue( ! doTestOn("file:testing/reasoners/owl/inconsistent2.rdf"));
84     }
85     
86     /**
87      * Should find problem due to count violations
88      */

89     public void testInconsistent3() {
90         assertTrue( ! doTestOn("file:testing/reasoners/owl/inconsistent3.rdf"));
91     }
92     
93     /**
94      * Should find distinct values for a functional property
95      */

96     public void testInconsistent4() {
97         assertTrue( ! doTestOn("file:testing/reasoners/owl/inconsistent4.rdf"));
98     }
99     
100     /**
101      * Should find type clash due to allValuesFrom rdfs:Literal
102      */

103     public void testInconsistent5() {
104         assertTrue( ! doTestOn("file:testing/reasoners/owl/inconsistent5.rdf"));
105     }
106     
107     /**
108      * Run a single consistency test on the given data file.
109      */

110     private boolean doTestOn(String JavaDoc dataFile) {
111 // System.out.println("Test: " + dataFile);
112
Model data = FileManager.get().loadModel(dataFile);
113         InfModel infmodel = ModelFactory.createInfModel(makeReasoner(), data);
114         ValidityReport reportList = infmodel.validate();
115         /* Debug only
116         if (reportList.isValid()) {
117             System.out.println("No reported problems");
118         } else {
119             for (Iterator i = reportList.getReports(); i.hasNext(); ) {
120                 ValidityReport.Report report = (ValidityReport.Report)i.next();
121                 System.out.println("- " + report);
122             }
123         }
124         */

125         return reportList.isValid();
126     }
127 }
128
129
130
131 /*
132     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
133     All rights reserved.
134
135     Redistribution and use in source and binary forms, with or without
136     modification, are permitted provided that the following conditions
137     are met:
138
139     1. Redistributions of source code must retain the above copyright
140        notice, this list of conditions and the following disclaimer.
141
142     2. Redistributions in binary form must reproduce the above copyright
143        notice, this list of conditions and the following disclaimer in the
144        documentation and/or other materials provided with the distribution.
145
146     3. The name of the author may not be used to endorse or promote products
147        derived from this software without specific prior written permission.
148
149     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
150     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
151     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
152     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
153     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
154     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
155     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
156     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
157     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
158     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
159 */
Popular Tags