KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > ontology > impl > OWLDLProfile


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 10 Feb 2003
9  * Filename $RCSfile: OWLDLProfile.java,v $
10  * Revision $Revision: 1.15 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/04/11 16:22:50 $
14  * by $Author: ian_dickinson $
15  *
16  * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
17  * (see footer for full conditions)
18  *****************************************************************************/

19
20 // Package
21
///////////////
22
package com.hp.hpl.jena.ontology.impl;
23 import com.hp.hpl.jena.rdf.model.*;
24
25
26 // Imports
27
///////////////
28
import com.hp.hpl.jena.vocabulary.*;
29 import com.hp.hpl.jena.enhanced.*;
30 import com.hp.hpl.jena.graph.*;
31 import com.hp.hpl.jena.ontology.*;
32
33 import java.util.*;
34
35
36
37 /**
38  * <p>
39  * Ontology language profile implementation for the DL variant of the OWL 2002/07 language.
40  * </p>
41  *
42  * @author Ian Dickinson, HP Labs
43  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
44  * @version CVS $Id: OWLDLProfile.java,v 1.15 2005/04/11 16:22:50 ian_dickinson Exp $
45  */

46 public class OWLDLProfile
47     extends OWLProfile
48 {
49     // Constants
50
//////////////////////////////////
51

52
53     // Static variables
54
//////////////////////////////////
55

56
57     // Instance variables
58
//////////////////////////////////
59

60
61     // Constructors
62
//////////////////////////////////
63

64
65     // External signature methods
66
//////////////////////////////////
67

68
69     /**
70      * <p>
71      * Answer a descriptive string for this profile, for use in debugging and other output.
72      * </p>
73      * @return "OWL DL"
74      */

75     public String JavaDoc getLabel() {
76         return "OWL DL";
77     }
78
79
80     // Internal implementation methods
81
//////////////////////////////////
82

83     protected static Object JavaDoc[][] s_supportsCheckData = new Object JavaDoc[][] {
84             // Resource (key), check method
85
{ AllDifferent.class, new SupportsCheck() {
86                 public boolean doCheck( Node n, EnhGraph g ) {
87                     return g.asGraph().contains( n, RDF.type.asNode(), OWL.AllDifferent.asNode() );
88                 }
89             }
90             },
91             { AnnotationProperty.class, new SupportsCheck() {
92                 public boolean doCheck( Node n, EnhGraph g ) {
93                     for (Iterator i = ((OntModel) g).getProfile().getAnnotationProperties(); i.hasNext(); ) {
94                         if (((Resource) i.next()).asNode().equals( n )) {
95                             // a built-in annotation property
96
return true;
97                         }
98                     }
99                     return g.asGraph().contains( n, RDF.type.asNode(), OWL.AnnotationProperty.asNode() );
100                 }
101             }
102             },
103             { OntClass.class, new SupportsCheck() {
104                 public boolean doCheck( Node n, EnhGraph g ) {
105                     return OWL.Thing.asNode().equals( n ) ||
106                             OWL.Nothing.asNode().equals( n ) ||
107                             g.asGraph().contains( n, RDF.type.asNode(), OWL.Class.asNode() ) ||
108                             g.asGraph().contains( n, RDF.type.asNode(), OWL.Restriction.asNode() ) ||
109                             g.asGraph().contains( n, RDF.type.asNode(), RDFS.Class.asNode() ) ||
110                             // These are common cases that we should support
111
n.equals( OWL.Thing.asNode() ) ||
112                             n.equals( OWL.Nothing.asNode() ) ||
113                             g.asGraph().contains( Node.ANY, RDFS.domain.asNode(), n ) ||
114                             g.asGraph().contains( Node.ANY, RDFS.range.asNode(), n )
115                             ;
116                 }
117             }
118             },
119             { DatatypeProperty.class, new SupportsCheck() {
120                 public boolean doCheck( Node n, EnhGraph g ) {
121                     return g.asGraph().contains( n, RDF.type.asNode(), OWL.DatatypeProperty.asNode() );
122                 }
123             }
124             },
125             { ObjectProperty.class, new SupportsCheck() {
126                 public boolean doCheck( Node n, EnhGraph g ) {
127                     return g.asGraph().contains( n, RDF.type.asNode(), OWL.ObjectProperty.asNode() ) ||
128                     g.asGraph().contains( n, RDF.type.asNode(), OWL.TransitiveProperty.asNode() ) ||
129                     g.asGraph().contains( n, RDF.type.asNode(), OWL.SymmetricProperty.asNode() ) ||
130                     g.asGraph().contains( n, RDF.type.asNode(), OWL.InverseFunctionalProperty.asNode() );
131                 }
132             }
133             },
134             { FunctionalProperty.class, new SupportsCheck() {
135                 public boolean doCheck( Node n, EnhGraph g ) {
136                     return g.asGraph().contains( n, RDF.type.asNode(), OWL.FunctionalProperty.asNode() );
137                 }
138             }
139             },
140             { InverseFunctionalProperty.class, new SupportsCheck() {
141                 public boolean doCheck( Node n, EnhGraph g ) {
142                     return g.asGraph().contains( n, RDF.type.asNode(), OWL.InverseFunctionalProperty.asNode() ) &&
143                     !g.asGraph().contains( n, RDF.type.asNode(), OWL.DatatypeProperty.asNode() );
144                 }
145             }
146             },
147             { RDFList.class, new SupportsCheck() {
148                 public boolean doCheck( Node n, EnhGraph g ) {
149                     return n.equals( RDF.nil.asNode() ) ||
150                     g.asGraph().contains( n, RDF.type.asNode(), RDF.List.asNode() );
151                 }
152             }
153             },
154             { OntProperty.class, new SupportsCheck() {
155                 public boolean doCheck( Node n, EnhGraph g ) {
156                     return g.asGraph().contains( n, RDF.type.asNode(), RDF.Property.asNode() ) ||
157                     g.asGraph().contains( n, RDF.type.asNode(), OWL.ObjectProperty.asNode() ) ||
158                     g.asGraph().contains( n, RDF.type.asNode(), OWL.DatatypeProperty.asNode() ) ||
159                     g.asGraph().contains( n, RDF.type.asNode(), OWL.AnnotationProperty.asNode() ) ||
160                     g.asGraph().contains( n, RDF.type.asNode(), OWL.TransitiveProperty.asNode() ) ||
161                     g.asGraph().contains( n, RDF.type.asNode(), OWL.SymmetricProperty.asNode() ) ||
162                     g.asGraph().contains( n, RDF.type.asNode(), OWL.FunctionalProperty.asNode() ) ||
163                     g.asGraph().contains( n, RDF.type.asNode(), OWL.InverseFunctionalProperty.asNode() );
164                 }
165             }
166             },
167             { Ontology.class, new SupportsCheck() {
168                 public boolean doCheck( Node n, EnhGraph g ) {
169                     return g.asGraph().contains( n, RDF.type.asNode(), OWL.Ontology.asNode() );
170                 }
171             }
172             },
173             { Restriction.class, new SupportsCheck() {
174                 public boolean doCheck( Node n, EnhGraph g ) {
175                     return g.asGraph().contains( n, RDF.type.asNode(), OWL.Restriction.asNode() );
176                 }
177             }
178             },
179             { AllValuesFromRestriction.class, new SupportsCheck() {
180                 public boolean doCheck( Node n, EnhGraph g ) {
181                     return g.asGraph().contains( n, RDF.type.asNode(), OWL.Restriction.asNode() ) &&
182                     containsSome( g, n, OWL.allValuesFrom ) &&
183                     containsSome( g, n, OWL.onProperty );
184                 }
185             }
186             },
187             { SomeValuesFromRestriction.class, new SupportsCheck() {
188                 public boolean doCheck( Node n, EnhGraph g ) {
189                     return g.asGraph().contains( n, RDF.type.asNode(), OWL.Restriction.asNode() ) &&
190                     containsSome( g,n, OWL.someValuesFrom ) &&
191                     containsSome( g,n, OWL.onProperty );
192                 }
193             }
194             },
195             { HasValueRestriction.class, new SupportsCheck() {
196                 public boolean doCheck( Node n, EnhGraph g ) {
197                     return g.asGraph().contains( n, RDF.type.asNode(), OWL.Restriction.asNode() ) &&
198                     containsSome( g, n, OWL.hasValue ) &&
199                     containsSome( g, n, OWL.onProperty );
200                 }
201             }
202             },
203             { CardinalityRestriction.class, new SupportsCheck() {
204                 public boolean doCheck( Node n, EnhGraph g ) {
205                     return g.asGraph().contains( n, RDF.type.asNode(), OWL.Restriction.asNode() ) &&
206                     containsSome( g, n, OWL.cardinality ) &&
207                     containsSome( g, n, OWL.onProperty );
208                 }
209             }
210             },
211             { MinCardinalityRestriction.class, new SupportsCheck() {
212                 public boolean doCheck( Node n, EnhGraph g ) {
213                     return g.asGraph().contains( n, RDF.type.asNode(), OWL.Restriction.asNode() ) &&
214                     containsSome( g, n, OWL.minCardinality ) &&
215                     containsSome( g, n, OWL.onProperty );
216                 }
217             }
218             },
219             { MaxCardinalityRestriction.class, new SupportsCheck() {
220                 public boolean doCheck( Node n, EnhGraph g ) {
221                     return g.asGraph().contains( n, RDF.type.asNode(), OWL.Restriction.asNode() ) &&
222                     containsSome( g, n, OWL.maxCardinality ) &&
223                     containsSome( g, n, OWL.onProperty );
224                 }
225             }
226             },
227             { SymmetricProperty.class, new SupportsCheck() {
228                 public boolean doCheck( Node n, EnhGraph g ) {
229                     return g.asGraph().contains( n, RDF.type.asNode(), OWL.SymmetricProperty.asNode() ) &&
230                     !g.asGraph().contains( n, RDF.type.asNode(), OWL.DatatypeProperty.asNode() );
231                 }
232             }
233             },
234             { TransitiveProperty.class, new SupportsCheck() {
235                 public boolean doCheck( Node n, EnhGraph g ) {
236                     return g.asGraph().contains( n, RDF.type.asNode(), OWL.TransitiveProperty.asNode() ) &&
237                     !g.asGraph().contains( n, RDF.type.asNode(), OWL.DatatypeProperty.asNode() );
238                 }
239             }
240             },
241             { Individual.class, new SupportsCheck() {
242                 public boolean doCheck( Node n, EnhGraph eg ) {
243                     if (n instanceof Node_URI || n instanceof Node_Blank) {
244                         // necessary to be a uri or bNode, but not sufficient
245
Graph g = eg.asGraph();
246
247                         // this check filters out OWL-full entailments from the OWL-rule reasoner
248
return !(g.contains( n, RDF.type.asNode(), RDFS.Class.asNode() ) ||
249                                 g.contains( n, RDF.type.asNode(), RDF.Property.asNode() ));
250                     }
251                     else {
252                         return false;
253                     }
254                 }
255             }
256             },
257             { DataRange.class, new SupportsCheck() {
258                 public boolean doCheck( Node n, EnhGraph g ) {
259                     return n instanceof Node_Blank &&
260                            g.asGraph().contains( n, RDF.type.asNode(), OWL.DataRange.asNode() );
261                 }
262             }
263             }
264             };
265
266
267     // to allow concise reference in the code above.
268
public static boolean containsSome( EnhGraph g, Node n, Property p ) {
269         return AbstractProfile.containsSome( g, n, p );
270     }
271
272     /** Map from resource to syntactic/semantic checks that a node can be seen as the given facet */
273     private static HashMap s_supportsChecks = new HashMap();
274
275     static {
276         // initialise the map of supports checks from a table of static data
277
for (int i = 0; i < s_supportsCheckData.length; i++) {
278             s_supportsChecks.put( s_supportsCheckData[i][0], s_supportsCheckData[i][1] );
279         }
280     }
281
282     protected Map getCheckTable() {
283         return s_supportsChecks;
284     }
285
286     //==============================================================================
287
// Inner class definitions
288
//==============================================================================
289

290
291 }
292
293
294
295
296 /*
297     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
298     All rights reserved.
299
300     Redistribution and use in source and binary forms, with or without
301     modification, are permitted provided that the following conditions
302     are met:
303
304     1. Redistributions of source code must retain the above copyright
305        notice, this list of conditions and the following disclaimer.
306
307     2. Redistributions in binary form must reproduce the above copyright
308        notice, this list of conditions and the following disclaimer in the
309        documentation and/or other materials provided with the distribution.
310
311     3. The name of the author may not be used to endorse or promote products
312        derived from this software without specific prior written permission.
313
314     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
315     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
316     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
317     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
318     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
319     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
320     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
321     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
322     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
323     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
324 */

325
326
Popular Tags