001: /******************************************************************
002: * File: TestOWLConsistency.java
003: * Created by: Dave Reynolds
004: * Created on: 24-Aug-2003
005: *
006: * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
007: * [See end of file]
008: * $Id: TestOWLConsistency.java,v 1.9 2008/01/02 12:08:19 andy_seaborne Exp $
009: *****************************************************************/package com.hp.hpl.jena.reasoner.rulesys.test;
010:
011: import com.hp.hpl.jena.rdf.model.*;
012: import com.hp.hpl.jena.reasoner.*;
013: import com.hp.hpl.jena.util.FileManager;
014:
015: //import java.util.*;
016:
017: import junit.framework.TestCase;
018: import junit.framework.TestSuite;
019:
020: /**
021: * Test the preliminary OWL validation rules.
022: *
023: * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
024: * @version $Revision: 1.9 $ on $Date: 2008/01/02 12:08:19 $
025: */
026: public class TestOWLConsistency extends TestCase {
027:
028: /** The tbox/ontology file to test against sample data */
029: public static final String testTbox = "file:testing/reasoners/owl/tbox.owl";
030:
031: /** A cached copy of the bound reasoner */
032: public static Reasoner reasonerCache;
033:
034: /**
035: * Boilerplate for junit
036: */
037: public TestOWLConsistency(String name) {
038: super (name);
039: }
040:
041: /**
042: * Boilerplate for junit.
043: * This is its own test suite
044: */
045: public static TestSuite suite() {
046: return new TestSuite(TestOWLConsistency.class);
047: // TestSuite suite = new TestSuite();
048: // suite.addTest(new TestOWLConsistency( "testInconsistent5" ));
049: // return suite;
050: }
051:
052: /**
053: * Create, or retrieve from cache, an OWL reasoner already bound
054: * to the test tbox.
055: */
056: public Reasoner makeReasoner() {
057: if (reasonerCache == null) {
058: Model tbox = FileManager.get().loadModel(testTbox);
059: reasonerCache = ReasonerRegistry.getOWLReasoner()
060: .bindSchema(tbox.getGraph());
061: }
062: return reasonerCache;
063: }
064:
065: /**
066: * Should be consistent.
067: */
068: public void testConsistent() {
069: assertTrue(doTestOn("file:testing/reasoners/owl/consistentData.rdf"));
070: }
071:
072: /**
073: * Should find problem due to overlap of disjoint classes.
074: */
075: public void testInconsistent1() {
076: assertTrue(!doTestOn("file:testing/reasoners/owl/inconsistent1.rdf"));
077: }
078:
079: /**
080: * Should find problem due to type violations
081: */
082: public void testInconsistent2() {
083: assertTrue(!doTestOn("file:testing/reasoners/owl/inconsistent2.rdf"));
084: }
085:
086: /**
087: * Should find problem due to count violations
088: */
089: public void testInconsistent3() {
090: assertTrue(!doTestOn("file:testing/reasoners/owl/inconsistent3.rdf"));
091: }
092:
093: /**
094: * Should find distinct values for a functional property
095: */
096: public void testInconsistent4() {
097: assertTrue(!doTestOn("file:testing/reasoners/owl/inconsistent4.rdf"));
098: }
099:
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: * Should find distinct literal values for a functional property
109: * via an indirect sameAs
110: */
111: public void testInconsistent7() {
112: assertTrue(!doTestOn("file:testing/reasoners/owl/inconsistent7.rdf"));
113: }
114:
115: /**
116: * Run a single consistency test on the given data file.
117: */
118: private boolean doTestOn(String dataFile) {
119: // System.out.println("Test: " + dataFile);
120: Model data = FileManager.get().loadModel(dataFile);
121: InfModel infmodel = ModelFactory.createInfModel(makeReasoner(),
122: data);
123: ValidityReport reportList = infmodel.validate();
124: /* Debug only
125: if (reportList.isValid()) {
126: System.out.println("No reported problems");
127: } else {
128: for (Iterator i = reportList.getReports(); i.hasNext(); ) {
129: ValidityReport.Report report = (ValidityReport.Report)i.next();
130: System.out.println("- " + report);
131: }
132: }
133: */
134: return reportList.isValid();
135: }
136: }
137:
138: /*
139: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
140: All rights reserved.
141:
142: Redistribution and use in source and binary forms, with or without
143: modification, are permitted provided that the following conditions
144: are met:
145:
146: 1. Redistributions of source code must retain the above copyright
147: notice, this list of conditions and the following disclaimer.
148:
149: 2. Redistributions in binary form must reproduce the above copyright
150: notice, this list of conditions and the following disclaimer in the
151: documentation and/or other materials provided with the distribution.
152:
153: 3. The name of the author may not be used to endorse or promote products
154: derived from this software without specific prior written permission.
155:
156: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
157: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
158: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
159: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
160: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
161: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
162: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
163: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
164: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
165: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
166: */
|