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 10 Feb 2003
009: * Filename $RCSfile: OWLDLProfile.java,v $
010: * Revision $Revision: 1.21 $
011: * Release status $State: Exp $
012: *
013: * Last modified on $Date: 2008/01/02 12:08:03 $
014: * by $Author: andy_seaborne $
015: *
016: * (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
017: * (see footer for full conditions)
018: *****************************************************************************/package com.hp.hpl.jena.ontology.impl;
019:
020: import com.hp.hpl.jena.rdf.model.*;
021:
022: // Imports
023: ///////////////
024: import com.hp.hpl.jena.vocabulary.*;
025: import com.hp.hpl.jena.enhanced.*;
026: import com.hp.hpl.jena.graph.*;
027: import com.hp.hpl.jena.ontology.*;
028:
029: import java.util.*;
030:
031: /**
032: * <p>
033: * Ontology language profile implementation for the DL variant of the OWL 2002/07 language.
034: * </p>
035: *
036: * @author Ian Dickinson, HP Labs
037: * (<a href="mailto:Ian.Dickinson@hp.com" >email</a>)
038: * @version CVS $Id: OWLDLProfile.java,v 1.21 2008/01/02 12:08:03 andy_seaborne Exp $
039: */
040: public class OWLDLProfile extends OWLProfile {
041: // Constants
042: //////////////////////////////////
043:
044: // Static variables
045: //////////////////////////////////
046:
047: // Instance variables
048: //////////////////////////////////
049:
050: // Constructors
051: //////////////////////////////////
052:
053: // External signature methods
054: //////////////////////////////////
055:
056: /**
057: * <p>
058: * Answer a descriptive string for this profile, for use in debugging and other output.
059: * </p>
060: * @return "OWL DL"
061: */
062: public String getLabel() {
063: return "OWL DL";
064: }
065:
066: // Internal implementation methods
067: //////////////////////////////////
068:
069: protected static Object[][] s_supportsCheckData = new Object[][] {
070: // Resource (key), check method
071: { AllDifferent.class, new SupportsCheck() {
072: public boolean doCheck(Node n, EnhGraph g) {
073: return g.asGraph().contains(n, RDF.type.asNode(),
074: OWL.AllDifferent.asNode());
075: }
076: } },
077: { AnnotationProperty.class, new SupportsCheck() {
078: public boolean doCheck(Node n, EnhGraph g) {
079: for (Iterator i = ((OntModel) g).getProfile()
080: .getAnnotationProperties(); i.hasNext();) {
081: if (((Resource) i.next()).asNode().equals(n)) {
082: // a built-in annotation property
083: return true;
084: }
085: }
086: return g.asGraph().contains(n, RDF.type.asNode(),
087: OWL.AnnotationProperty.asNode());
088: }
089: } },
090: { OntClass.class, new SupportsCheck() {
091: public boolean doCheck(Node n, EnhGraph eg) {
092: Graph g = eg.asGraph();
093: Node rdfTypeNode = RDF.type.asNode();
094: return g.contains(n, rdfTypeNode, OWL.Class
095: .asNode())
096: || g.contains(n, rdfTypeNode,
097: OWL.Restriction.asNode())
098: || g.contains(n, rdfTypeNode, RDFS.Class
099: .asNode())
100: || g.contains(n, rdfTypeNode, RDFS.Datatype
101: .asNode())
102: ||
103: // These are common cases that we should support
104: n.equals(OWL.Thing.asNode())
105: || n.equals(OWL.Nothing.asNode())
106: || g.contains(Node.ANY, RDFS.domain
107: .asNode(), n)
108: || g.contains(Node.ANY,
109: RDFS.range.asNode(), n)
110: || g.contains(n, OWL.intersectionOf
111: .asNode(), Node.ANY)
112: || g.contains(n, OWL.unionOf.asNode(),
113: Node.ANY)
114: || g.contains(n, OWL.complementOf.asNode(),
115: Node.ANY);
116: }
117: } },
118: { DatatypeProperty.class, new SupportsCheck() {
119: public boolean doCheck(Node n, EnhGraph g) {
120: return g.asGraph().contains(n, RDF.type.asNode(),
121: OWL.DatatypeProperty.asNode());
122: }
123: } },
124: { ObjectProperty.class, new SupportsCheck() {
125: public boolean doCheck(Node n, EnhGraph g) {
126: return g.asGraph().contains(n, RDF.type.asNode(),
127: OWL.ObjectProperty.asNode())
128: || g.asGraph().contains(n,
129: RDF.type.asNode(),
130: OWL.TransitiveProperty.asNode())
131: || g.asGraph().contains(n,
132: RDF.type.asNode(),
133: OWL.SymmetricProperty.asNode())
134: || g.asGraph().contains(
135: n,
136: RDF.type.asNode(),
137: OWL.InverseFunctionalProperty
138: .asNode());
139: }
140: } },
141: { FunctionalProperty.class, new SupportsCheck() {
142: public boolean doCheck(Node n, EnhGraph g) {
143: return g.asGraph().contains(n, RDF.type.asNode(),
144: OWL.FunctionalProperty.asNode());
145: }
146: } },
147: { InverseFunctionalProperty.class, new SupportsCheck() {
148: public boolean doCheck(Node n, EnhGraph g) {
149: return g.asGraph().contains(n, RDF.type.asNode(),
150: OWL.InverseFunctionalProperty.asNode())
151: && !g.asGraph().contains(n,
152: RDF.type.asNode(),
153: OWL.DatatypeProperty.asNode());
154: }
155: } },
156: { RDFList.class, new SupportsCheck() {
157: public boolean doCheck(Node n, EnhGraph g) {
158: return n.equals(RDF.nil.asNode())
159: || g.asGraph().contains(n,
160: RDF.type.asNode(),
161: RDF.List.asNode());
162: }
163: } },
164: { OntProperty.class, new SupportsCheck() {
165: public boolean doCheck(Node n, EnhGraph g) {
166: return g.asGraph().contains(n, RDF.type.asNode(),
167: RDF.Property.asNode())
168: || g.asGraph().contains(n,
169: RDF.type.asNode(),
170: OWL.ObjectProperty.asNode())
171: || g.asGraph().contains(n,
172: RDF.type.asNode(),
173: OWL.DatatypeProperty.asNode())
174: || g.asGraph().contains(n,
175: RDF.type.asNode(),
176: OWL.AnnotationProperty.asNode())
177: || g.asGraph().contains(n,
178: RDF.type.asNode(),
179: OWL.TransitiveProperty.asNode())
180: || g.asGraph().contains(n,
181: RDF.type.asNode(),
182: OWL.SymmetricProperty.asNode())
183: || g.asGraph().contains(n,
184: RDF.type.asNode(),
185: OWL.FunctionalProperty.asNode())
186: || g.asGraph().contains(
187: n,
188: RDF.type.asNode(),
189: OWL.InverseFunctionalProperty
190: .asNode());
191: }
192: } },
193: { Ontology.class, new SupportsCheck() {
194: public boolean doCheck(Node n, EnhGraph g) {
195: return g.asGraph().contains(n, RDF.type.asNode(),
196: OWL.Ontology.asNode());
197: }
198: } },
199: { Restriction.class, new SupportsCheck() {
200: public boolean doCheck(Node n, EnhGraph g) {
201: return g.asGraph().contains(n, RDF.type.asNode(),
202: OWL.Restriction.asNode());
203: }
204: } },
205: { AllValuesFromRestriction.class, new SupportsCheck() {
206: public boolean doCheck(Node n, EnhGraph g) {
207: return g.asGraph().contains(n, RDF.type.asNode(),
208: OWL.Restriction.asNode())
209: && containsSome(g, n, OWL.allValuesFrom)
210: && containsSome(g, n, OWL.onProperty);
211: }
212: } },
213: { SomeValuesFromRestriction.class, new SupportsCheck() {
214: public boolean doCheck(Node n, EnhGraph g) {
215: return g.asGraph().contains(n, RDF.type.asNode(),
216: OWL.Restriction.asNode())
217: && containsSome(g, n, OWL.someValuesFrom)
218: && containsSome(g, n, OWL.onProperty);
219: }
220: } },
221: { HasValueRestriction.class, new SupportsCheck() {
222: public boolean doCheck(Node n, EnhGraph g) {
223: return g.asGraph().contains(n, RDF.type.asNode(),
224: OWL.Restriction.asNode())
225: && containsSome(g, n, OWL.hasValue)
226: && containsSome(g, n, OWL.onProperty);
227: }
228: } },
229: { CardinalityRestriction.class, new SupportsCheck() {
230: public boolean doCheck(Node n, EnhGraph g) {
231: return g.asGraph().contains(n, RDF.type.asNode(),
232: OWL.Restriction.asNode())
233: && containsSome(g, n, OWL.cardinality)
234: && containsSome(g, n, OWL.onProperty);
235: }
236: } },
237: { MinCardinalityRestriction.class, new SupportsCheck() {
238: public boolean doCheck(Node n, EnhGraph g) {
239: return g.asGraph().contains(n, RDF.type.asNode(),
240: OWL.Restriction.asNode())
241: && containsSome(g, n, OWL.minCardinality)
242: && containsSome(g, n, OWL.onProperty);
243: }
244: } },
245: { MaxCardinalityRestriction.class, new SupportsCheck() {
246: public boolean doCheck(Node n, EnhGraph g) {
247: return g.asGraph().contains(n, RDF.type.asNode(),
248: OWL.Restriction.asNode())
249: && containsSome(g, n, OWL.maxCardinality)
250: && containsSome(g, n, OWL.onProperty);
251: }
252: } }, { SymmetricProperty.class, new SupportsCheck() {
253: public boolean doCheck(Node n, EnhGraph g) {
254: return g.asGraph().contains(n, RDF.type.asNode(),
255: OWL.SymmetricProperty.asNode())
256: && !g.asGraph().contains(n,
257: RDF.type.asNode(),
258: OWL.DatatypeProperty.asNode());
259: }
260: } }, { TransitiveProperty.class, new SupportsCheck() {
261: public boolean doCheck(Node n, EnhGraph g) {
262: return g.asGraph().contains(n, RDF.type.asNode(),
263: OWL.TransitiveProperty.asNode())
264: && !g.asGraph().contains(n,
265: RDF.type.asNode(),
266: OWL.DatatypeProperty.asNode());
267: }
268: } }, { Individual.class, new SupportsCheck() {
269: public boolean doCheck(Node n, EnhGraph eg) {
270: if (n instanceof Node_URI
271: || n instanceof Node_Blank) {
272: // necessary to be a uri or bNode, but not sufficient
273: Graph g = eg.asGraph();
274:
275: // this check filters out OWL-full entailments from the OWL-rule reasoner
276: return !(g.contains(n, RDF.type.asNode(),
277: RDFS.Class.asNode()) || g.contains(n,
278: RDF.type.asNode(), RDF.Property
279: .asNode()));
280: } else {
281: return false;
282: }
283: }
284: } }, { DataRange.class, new SupportsCheck() {
285: public boolean doCheck(Node n, EnhGraph g) {
286: return n instanceof Node_Blank
287: && g.asGraph().contains(n,
288: RDF.type.asNode(),
289: OWL.DataRange.asNode());
290: }
291: } } };
292:
293: // to allow concise reference in the code above.
294: public static boolean containsSome(EnhGraph g, Node n, Property p) {
295: return AbstractProfile.containsSome(g, n, p);
296: }
297:
298: /** Map from resource to syntactic/semantic checks that a node can be seen as the given facet */
299: private static HashMap s_supportsChecks = new HashMap();
300:
301: static {
302: // initialise the map of supports checks from a table of static data
303: for (int i = 0; i < s_supportsCheckData.length; i++) {
304: s_supportsChecks.put(s_supportsCheckData[i][0],
305: s_supportsCheckData[i][1]);
306: }
307: }
308:
309: protected Map getCheckTable() {
310: return s_supportsChecks;
311: }
312:
313: //==============================================================================
314: // Inner class definitions
315: //==============================================================================
316:
317: }
318:
319: /*
320: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
321: All rights reserved.
322:
323: Redistribution and use in source and binary forms, with or without
324: modification, are permitted provided that the following conditions
325: are met:
326:
327: 1. Redistributions of source code must retain the above copyright
328: notice, this list of conditions and the following disclaimer.
329:
330: 2. Redistributions in binary form must reproduce the above copyright
331: notice, this list of conditions and the following disclaimer in the
332: documentation and/or other materials provided with the distribution.
333:
334: 3. The name of the author may not be used to endorse or promote products
335: derived from this software without specific prior written permission.
336:
337: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
338: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
339: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
340: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
341: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
342: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
343: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
344: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
345: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
346: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
347: */
|