KickJava   Java API By Example, From Geeks To Geeks.

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


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: OWLLiteProfile.java,v $
10  * Revision $Revision: 1.15 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/04/11 16:22:49 $
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
24
25 // Imports
26
///////////////
27
import com.hp.hpl.jena.vocabulary.*;
28 import com.hp.hpl.jena.enhanced.*;
29 import com.hp.hpl.jena.graph.*;
30 import com.hp.hpl.jena.ontology.*;
31 import com.hp.hpl.jena.rdf.model.*;
32
33 import java.util.*;
34
35
36
37 /**
38  * <p>
39  * Ontology language profile implementation for the Lite 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: OWLLiteProfile.java,v 1.15 2005/04/11 16:22:49 ian_dickinson Exp $
45  */

46 public class OWLLiteProfile
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     public Resource DATARANGE() { return null; }
69     public Resource NOTHING() { return null; }
70     public Property COMPLEMENT_OF() { return null; }
71     public Property DISJOINT_WITH() { return null; }
72     public Property HAS_VALUE() { return null; }
73     public Property ONE_OF() { return null; }
74     public Property UNION_OF() { return null; }
75     public Property SAME_AS() { return null; }
76     public Property SAME_INDIVIDUAL_AS() { return null; }
77
78
79     /**
80      * <p>
81      * Answer a descriptive string for this profile, for use in debugging and other output.
82      * </p>
83      * @return "OWL Lite"
84      */

85     public String JavaDoc getLabel() {
86         return "OWL Lite";
87     }
88
89
90
91
92     // Internal implementation methods
93
//////////////////////////////////
94

95
96     //==============================================================================
97
// Inner class definitions
98
//==============================================================================
99

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

277     /** Map from resource to syntactic/semantic checks that a node can be seen as the given facet */
278     private static HashMap s_supportsChecks = new HashMap();
279
280     static {
281         // initialise the map of supports checks from a table of static data
282
for (int i = 0; i < s_supportsCheckData.length; i++) {
283             s_supportsChecks.put( s_supportsCheckData[i][0], s_supportsCheckData[i][1] );
284         }
285     }
286
287     protected Map getCheckTable() {
288         return s_supportsChecks;
289     }
290 }
291
292
293
294
295 /*
296     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
297     All rights reserved.
298
299     Redistribution and use in source and binary forms, with or without
300     modification, are permitted provided that the following conditions
301     are met:
302
303     1. Redistributions of source code must retain the above copyright
304        notice, this list of conditions and the following disclaimer.
305
306     2. Redistributions in binary form must reproduce the above copyright
307        notice, this list of conditions and the following disclaimer in the
308        documentation and/or other materials provided with the distribution.
309
310     3. The name of the author may not be used to endorse or promote products
311        derived from this software without specific prior written permission.
312
313     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
314     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
315     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
316     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
317     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
318     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
319     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
320     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
321     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
322     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
323 */

324
325
Popular Tags