KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > dig > test > TestConsistency


1 /*****************************************************************************
2  * Source code information
3  * -----------------------
4  * Original author Ian Dickinson, HP Labs Bristol
5  * Author email ian.dickinson@hp.com
6  * Package Jena 2
7  * Web http://sourceforge.net/projects/jena/
8  * Created 11-Sep-2003
9  * Filename $RCSfile: TestConsistency.java,v $
10  * Revision $Revision: 1.3 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:16:33 $
14  * by $Author: andy_seaborne $
15  *
16  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
17  * [See end of file]
18  *****************************************************************************/

19
20 // Package
21
///////////////
22
package com.hp.hpl.jena.reasoner.dig.test;
23
24
25
26 // Imports
27
///////////////
28
import java.util.Iterator JavaDoc;
29
30 import org.apache.commons.logging.LogFactory;
31
32 import com.hp.hpl.jena.ontology.*;
33 import com.hp.hpl.jena.rdf.model.*;
34 import com.hp.hpl.jena.reasoner.ReasonerRegistry;
35 import com.hp.hpl.jena.reasoner.ValidityReport;
36 import com.hp.hpl.jena.reasoner.dig.*;
37 import com.hp.hpl.jena.vocabulary.OWL;
38
39 import junit.framework.*;
40
41
42
43 /**
44  * <p>
45  * Abstract test harness for DIG reasoners
46  * </p>
47  *
48  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com">email</a>)
49  * @version Release @release@ ($Id: TestConsistency.java,v 1.3 2005/02/21 12:16:33 andy_seaborne Exp $)
50  */

51 public class TestConsistency
52     extends TestCase
53 {
54     // Constants
55
//////////////////////////////////
56

57     // Static variables
58
//////////////////////////////////
59

60     // Instance variables
61
//////////////////////////////////
62

63     // Constructors
64
//////////////////////////////////
65

66     // External signature methods
67
//////////////////////////////////
68

69     public void testConsistent0() {
70         String JavaDoc NS = "http://example.org/foo#";
71         
72         OntModel base = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM, null );
73         OntClass F0 = base.createClass( NS + "F0" );
74         OntClass F1 = base.createClass( NS + "F1" );
75         F0.addDisjointWith( F1 );
76         Individual i0 = base.createIndividual( NS + "i0", OWL.Thing );
77         i0.setRDFType( F0 );
78         
79         DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry().create( DIGReasonerFactory.URI, null );
80         
81         OntModelSpec spec = new OntModelSpec( OntModelSpec.OWL_DL_MEM );
82         spec.setReasoner( r );
83         OntModel m = ModelFactory.createOntologyModel( spec, base );
84         assertTrue( "KB should be consistent", m.validate().isValid() );
85     }
86
87     public void testConsistent1() {
88         String JavaDoc NS = "http://example.org/foo#";
89         
90         OntModel base = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM, null );
91         OntClass F0 = base.createClass( NS + "F0" );
92         OntClass F1 = base.createClass( NS + "F1" );
93         F0.addDisjointWith( F1 );
94         Individual i0 = base.createIndividual( NS + "i0", OWL.Thing );
95         i0.setRDFType( F0 );
96         i0.addRDFType( F1 );
97         
98         DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry().create( DIGReasonerFactory.URI, null );
99         
100         OntModelSpec spec = new OntModelSpec( OntModelSpec.OWL_DL_MEM );
101         spec.setReasoner( r );
102         OntModel m = ModelFactory.createOntologyModel( spec, base );
103         ValidityReport report = m.validate();
104         
105         if (!report.isValid()) {
106             for (Iterator JavaDoc i = report.getReports(); i.hasNext(); ) {
107                 ValidityReport.Report rp = (ValidityReport.Report) i.next();
108                 LogFactory.getLog( getClass() ).debug( "Problem report: " + rp.type + " - " + rp.description );
109             }
110         }
111         assertFalse( "KB should not be consistent", m.validate().isValid() );
112     }
113
114     public void testConsistent2() {
115         String JavaDoc NS = "http://example.org/foo#";
116         
117         OntModel base = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM, null );
118         OntClass F0 = base.createClass( NS + "F0" );
119         OntClass F1 = base.createClass( NS + "F1" );
120         OntClass F2 = base.createClass( NS + "F2" );
121         
122         F0.addDisjointWith( F1 );
123         F2.addSuperClass( F0 );
124         F2.addSuperClass( F1 );
125         
126         DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry().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 JavaDoc i = report.getReports(); i.hasNext(); ) {
135                 ValidityReport.Report rp = (ValidityReport.Report) i.next();
136                 LogFactory.getLog( getClass() ).debug( "Problem report: " + rp.type + " - " + rp.description );
137             }
138         }
139         assertFalse( "KB should not be consistent", m.validate().isValid() );
140     }
141
142     // Internal implementation methods
143
//////////////////////////////////
144

145     //==============================================================================
146
// Inner class definitions
147
//==============================================================================
148

149 }
150
151
152 /*
153  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
154  * All rights reserved.
155  *
156  * Redistribution and use in source and binary forms, with or without
157  * modification, are permitted provided that the following conditions
158  * are met:
159  * 1. Redistributions of source code must retain the above copyright
160  * notice, this list of conditions and the following disclaimer.
161  * 2. Redistributions in binary form must reproduce the above copyright
162  * notice, this list of conditions and the following disclaimer in the
163  * documentation and/or other materials provided with the distribution.
164  * 3. The name of the author may not be used to endorse or promote products
165  * derived from this software without specific prior written permission.
166  *
167  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
168  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
169  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
170  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
171  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
172  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
173  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
174  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
175  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
176  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
177  */

178
Popular Tags