001: /*****************************************************************************
002: * Source code information
003: * -----------------------
004: * Original author Ian Dickinson, HP Labs Bristol
005: * Author email ian.dickinson@hp.com
006: * Package Jena 2
007: * Web http://sourceforge.net/projects/jena/
008: * Created 11-Sep-2003
009: * Filename $RCSfile: TestConsistency.java,v $
010: * Revision $Revision: 1.6 $
011: * Release status $State: Exp $
012: *
013: * Last modified on $Date: 2008/01/02 12:10:28 $
014: * by $Author: andy_seaborne $
015: *
016: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
017: * [See end of file]
018: *****************************************************************************/package com.hp.hpl.jena.reasoner.dig.test;
019:
020: // Imports
021: ///////////////
022: import java.util.Iterator;
023:
024: import org.apache.commons.logging.LogFactory;
025:
026: import com.hp.hpl.jena.ontology.*;
027: import com.hp.hpl.jena.rdf.model.*;
028: import com.hp.hpl.jena.reasoner.ReasonerRegistry;
029: import com.hp.hpl.jena.reasoner.ValidityReport;
030: import com.hp.hpl.jena.reasoner.dig.*;
031: import com.hp.hpl.jena.vocabulary.OWL;
032:
033: import junit.framework.*;
034:
035: /**
036: * <p>
037: * Abstract test harness for DIG reasoners
038: * </p>
039: *
040: * @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com">email</a>)
041: * @version Release @release@ ($Id: TestConsistency.java,v 1.6 2008/01/02 12:10:28 andy_seaborne Exp $)
042: */
043: public class TestConsistency extends TestCase {
044: // Constants
045: //////////////////////////////////
046:
047: // Static variables
048: //////////////////////////////////
049:
050: // Instance variables
051: //////////////////////////////////
052:
053: // Constructors
054: //////////////////////////////////
055:
056: // External signature methods
057: //////////////////////////////////
058:
059: public void testConsistent0() {
060: String NS = "http://example.org/foo#";
061:
062: OntModel base = ModelFactory.createOntologyModel(
063: OntModelSpec.OWL_DL_MEM, null);
064: OntClass F0 = base.createClass(NS + "F0");
065: OntClass F1 = base.createClass(NS + "F1");
066: F0.addDisjointWith(F1);
067: Individual i0 = base.createIndividual(NS + "i0", OWL.Thing);
068: i0.setRDFType(F0);
069:
070: DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
071: .create(DIGReasonerFactory.URI, null);
072:
073: OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
074: spec.setReasoner(r);
075: OntModel m = ModelFactory.createOntologyModel(spec, base);
076: assertTrue("KB should be consistent", m.validate().isValid());
077: }
078:
079: public void testConsistent1() {
080: String NS = "http://example.org/foo#";
081:
082: OntModel base = ModelFactory.createOntologyModel(
083: OntModelSpec.OWL_DL_MEM, null);
084: OntClass F0 = base.createClass(NS + "F0");
085: OntClass F1 = base.createClass(NS + "F1");
086: F0.addDisjointWith(F1);
087: Individual i0 = base.createIndividual(NS + "i0", OWL.Thing);
088: i0.setRDFType(F0);
089: i0.addRDFType(F1);
090:
091: DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
092: .create(DIGReasonerFactory.URI, null);
093:
094: OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
095: spec.setReasoner(r);
096: OntModel m = ModelFactory.createOntologyModel(spec, base);
097: ValidityReport report = m.validate();
098:
099: if (!report.isValid()) {
100: for (Iterator i = report.getReports(); i.hasNext();) {
101: ValidityReport.Report rp = (ValidityReport.Report) i
102: .next();
103: LogFactory.getLog(getClass()).debug(
104: "Problem report: " + rp.type + " - "
105: + rp.description);
106: }
107: }
108: assertFalse("KB should not be consistent", m.validate()
109: .isValid());
110: }
111:
112: public void testConsistent2() {
113: String NS = "http://example.org/foo#";
114:
115: OntModel base = ModelFactory.createOntologyModel(
116: OntModelSpec.OWL_DL_MEM, null);
117: OntClass F0 = base.createClass(NS + "F0");
118: OntClass F1 = base.createClass(NS + "F1");
119: OntClass F2 = base.createClass(NS + "F2");
120:
121: F0.addDisjointWith(F1);
122: F2.addSuperClass(F0);
123: F2.addSuperClass(F1);
124:
125: DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
126: .create(DIGReasonerFactory.URI, null);
127:
128: OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
129: spec.setReasoner(r);
130: OntModel m = ModelFactory.createOntologyModel(spec, base);
131: ValidityReport report = m.validate();
132:
133: if (!report.isValid()) {
134: for (Iterator i = report.getReports(); i.hasNext();) {
135: ValidityReport.Report rp = (ValidityReport.Report) i
136: .next();
137: LogFactory.getLog(getClass()).debug(
138: "Problem report: " + rp.type + " - "
139: + rp.description);
140: }
141: }
142: assertFalse("KB should not be consistent", m.validate()
143: .isValid());
144: }
145:
146: // Internal implementation methods
147: //////////////////////////////////
148:
149: //==============================================================================
150: // Inner class definitions
151: //==============================================================================
152:
153: }
154:
155: /*
156: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
157: * All rights reserved.
158: *
159: * Redistribution and use in source and binary forms, with or without
160: * modification, are permitted provided that the following conditions
161: * are met:
162: * 1. Redistributions of source code must retain the above copyright
163: * notice, this list of conditions and the following disclaimer.
164: * 2. Redistributions in binary form must reproduce the above copyright
165: * notice, this list of conditions and the following disclaimer in the
166: * documentation and/or other materials provided with the distribution.
167: * 3. The name of the author may not be used to endorse or promote products
168: * derived from this software without specific prior written permission.
169: *
170: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
171: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
172: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
173: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
174: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
175: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
176: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
177: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
178: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
179: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
180: */
|