KickJava   Java API By Example, From Geeks To Geeks.

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


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: OWLProfile.java,v $
10  * Revision $Revision: 1.30 $
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
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 Full 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: OWLProfile.java,v 1.30 2005/04/11 16:22:50 ian_dickinson Exp $
45  */

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

52
53     // Instance variables
54
//////////////////////////////////
55

56
57     // Constructors
58
//////////////////////////////////
59

60
61     // External signature methods
62
//////////////////////////////////
63

64     public String JavaDoc NAMESPACE() { return OWL.getURI(); }
65
66     public Resource CLASS() { return OWL.Class; }
67     public Resource RESTRICTION() { return OWL.Restriction; }
68     public Resource THING() { return OWL.Thing; }
69     public Resource NOTHING() { return OWL.Nothing; }
70     public Resource PROPERTY() { return RDF.Property; }
71     public Resource OBJECT_PROPERTY() { return OWL.ObjectProperty; }
72     public Resource DATATYPE_PROPERTY() { return OWL.DatatypeProperty; }
73     public Resource TRANSITIVE_PROPERTY() { return OWL.TransitiveProperty; }
74     public Resource SYMMETRIC_PROPERTY() { return OWL.SymmetricProperty; }
75     public Resource FUNCTIONAL_PROPERTY() { return OWL.FunctionalProperty; }
76     public Resource INVERSE_FUNCTIONAL_PROPERTY() { return OWL.InverseFunctionalProperty; }
77     public Resource ALL_DIFFERENT() { return OWL.AllDifferent; }
78     public Resource ONTOLOGY() { return OWL.Ontology; }
79     public Resource DEPRECATED_CLASS() { return OWL.DeprecatedClass; }
80     public Resource DEPRECATED_PROPERTY() { return OWL.DeprecatedProperty; }
81     public Resource ANNOTATION_PROPERTY() { return OWL.AnnotationProperty; }
82     public Resource ONTOLOGY_PROPERTY() { return OWL.OntologyProperty; }
83     public Resource LIST() { return RDF.List; }
84     public Resource NIL() { return RDF.nil; }
85     public Resource DATARANGE() { return OWL.DataRange; }
86
87
88     public Property EQUIVALENT_PROPERTY() { return OWL.equivalentProperty; }
89     public Property EQUIVALENT_CLASS() { return OWL.equivalentClass; }
90     public Property DISJOINT_WITH() { return OWL.disjointWith; }
91     public Property SAME_INDIVIDUAL_AS() { return null; }
92     public Property SAME_AS() { return OWL.sameAs; }
93     public Property DIFFERENT_FROM() { return OWL.differentFrom; }
94     public Property DISTINCT_MEMBERS() { return OWL.distinctMembers; }
95     public Property UNION_OF() { return OWL.unionOf; }
96     public Property INTERSECTION_OF() { return OWL.intersectionOf; }
97     public Property COMPLEMENT_OF() { return OWL.complementOf; }
98     public Property ONE_OF() { return OWL.oneOf; }
99     public Property ON_PROPERTY() { return OWL.onProperty; }
100     public Property ALL_VALUES_FROM() { return OWL.allValuesFrom; }
101     public Property HAS_VALUE() { return OWL.hasValue; }
102     public Property SOME_VALUES_FROM() { return OWL.someValuesFrom; }
103     public Property MIN_CARDINALITY() { return OWL.minCardinality; }
104     public Property MAX_CARDINALITY() { return OWL.maxCardinality; }
105     public Property CARDINALITY() { return OWL.cardinality; }
106     public Property INVERSE_OF() { return OWL.inverseOf; }
107     public Property IMPORTS() { return OWL.imports; }
108     public Property PRIOR_VERSION() { return OWL.priorVersion; }
109     public Property BACKWARD_COMPATIBLE_WITH() { return OWL.backwardCompatibleWith; }
110     public Property INCOMPATIBLE_WITH() { return OWL.incompatibleWith; }
111     public Property SUB_PROPERTY_OF() { return RDFS.subPropertyOf; }
112     public Property SUB_CLASS_OF() { return RDFS.subClassOf; }
113     public Property DOMAIN() { return RDFS.domain; }
114     public Property RANGE() { return RDFS.range; }
115     public Property FIRST() { return RDF.first; }
116     public Property REST() { return RDF.rest; }
117     public Property MIN_CARDINALITY_Q() { return null; } // qualified restrictions are not in the first version of OWL
118
public Property MAX_CARDINALITY_Q() { return null; }
119     public Property CARDINALITY_Q() { return null; }
120     public Property HAS_CLASS_Q() { return null; }
121
122     // Annotations
123
public Property VERSION_INFO() { return OWL.versionInfo; }
124     public Property LABEL() { return RDFS.label; }
125     public Property COMMENT() { return RDFS.comment; }
126     public Property SEE_ALSO() { return RDFS.seeAlso; }
127     public Property IS_DEFINED_BY() { return RDFS.isDefinedBy; }
128
129
130     protected Resource[][] aliasTable() {
131         return new Resource[][] {
132         };
133     }
134
135     /** The only first-class axiom type in OWL is AllDifferent */
136     public Iterator getAxiomTypes() {
137         return Arrays.asList(
138             new Resource[] {
139                 OWL.AllDifferent
140             }
141         ).iterator();
142     }
143
144     /** The annotation properties of OWL */
145     public Iterator getAnnotationProperties() {
146         return Arrays.asList(
147             new Resource[] {
148                 OWL.versionInfo,
149                 RDFS.label,
150                 RDFS.seeAlso,
151                 RDFS.comment,
152                 RDFS.isDefinedBy
153             }
154         ).iterator();
155     }
156
157     public Iterator getClassDescriptionTypes() {
158         return Arrays.asList(
159             new Resource[] {
160                 OWL.Class,
161                 OWL.Restriction
162             }
163         ).iterator();
164     }
165
166
167     /**
168      * <p>
169      * Answer true if the given graph supports a view of this node as the given
170      * language element, according to the semantic constraints of the profile.
171      * If strict checking on the ontology model is turned off, this check is
172      * skipped.
173      * </p>
174      *
175      * @param n A node to test
176      * @param g The enhanced graph containing <code>n</code>, which is assumed to
177      * be an {@link OntModel}.
178      * @param type A class indicating the facet that we are testing against.
179      * @return True if strict checking is off, or if <code>n</code> can be
180      * viewed according to the facet resource <code>res</code>
181      */

182     public boolean isSupported( Node n, EnhGraph g, Class JavaDoc type ) {
183         if (g instanceof OntModel) {
184             OntModel m = (OntModel) g;
185
186             if (!m.strictMode()) {
187                 // checking turned off
188
return true;
189             }
190             else {
191                 // lookup the profile check for this resource
192
SupportsCheck check = (SupportsCheck) getCheckTable().get( type );
193
194                 // a check must be defined for the test to succeed
195
return (check != null) && check.doCheck( n, g );
196             }
197         }
198         else {
199             return false;
200         }
201     }
202
203     /**
204      * <p>
205      * Answer a descriptive string for this profile, for use in debugging and other output.
206      * </p>
207      * @return "OWL Full"
208      */

209     public String JavaDoc getLabel() {
210         return "OWL Full";
211     }
212
213     // Internal implementation methods
214
//////////////////////////////////
215

216
217     //==============================================================================
218
// Inner class definitions
219
//==============================================================================
220

221     /** Helper class for doing syntactic/semantic checks on a node */
222     protected static class SupportsCheck
223     {
224         public boolean doCheck( Node n, EnhGraph g ) {
225             return true;
226         }
227     }
228
229
230     // Table of check data
231
//////////////////////
232

233     private static Object JavaDoc[][] s_supportsCheckData = new Object JavaDoc[][] {
234         // Resource (key), check method
235
{ AllDifferent.class, new SupportsCheck() {
236                                             public boolean doCheck( Node n, EnhGraph g ) {
237                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.AllDifferent.asNode() );
238                                             }
239                                         }
240         },
241         { AnnotationProperty.class, new SupportsCheck() {
242                                             public boolean doCheck( Node n, EnhGraph g ) {
243                                                 for (Iterator i = ((OntModel) g).getProfile().getAnnotationProperties(); i.hasNext(); ) {
244                                                     if (((Resource) i.next()).asNode().equals( n )) {
245                                                         // a built-in annotation property
246
return true;
247                                                     }
248                                                 }
249                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.AnnotationProperty.asNode() );
250                                             }
251                                         }
252         },
253         { OntClass.class, new SupportsCheck() {
254                                             public boolean doCheck( Node n, EnhGraph g ) {
255                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.Class.asNode() ) ||
256                                                        g.asGraph().contains( n, RDF.type.asNode(), OWL.Restriction.asNode() ) ||
257                                                        g.asGraph().contains( n, RDF.type.asNode(), RDFS.Class.asNode() ) ||
258                                                        // These are common cases that we should support
259
n.equals( OWL.Thing.asNode() ) ||
260                                                        n.equals( OWL.Nothing.asNode() ) ||
261                                                        g.asGraph().contains( Node.ANY, RDFS.domain.asNode(), n ) ||
262                                                        g.asGraph().contains( Node.ANY, RDFS.range.asNode(), n )
263                                                        ;
264                                             }
265                                         }
266         },
267         { DatatypeProperty.class, new SupportsCheck() {
268                                             public boolean doCheck( Node n, EnhGraph g ) {
269                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.DatatypeProperty.asNode() );
270                                             }
271                                         }
272         },
273         { ObjectProperty.class, new SupportsCheck() {
274                                             public boolean doCheck( Node n, EnhGraph g ) {
275                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.ObjectProperty.asNode() ) ||
276                                                         g.asGraph().contains( n, RDF.type.asNode(), OWL.TransitiveProperty.asNode() ) ||
277                                                         g.asGraph().contains( n, RDF.type.asNode(), OWL.SymmetricProperty.asNode() ) ||
278                                                         g.asGraph().contains( n, RDF.type.asNode(), OWL.InverseFunctionalProperty.asNode() )
279                                                 ;
280                                             }
281                                         }
282         },
283         { FunctionalProperty.class, new SupportsCheck() {
284                                             public boolean doCheck( Node n, EnhGraph g ) {
285                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.FunctionalProperty.asNode() );
286                                             }
287                                         }
288         },
289         { InverseFunctionalProperty.class, new SupportsCheck() {
290                                             public boolean doCheck( Node n, EnhGraph g ) {
291                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.InverseFunctionalProperty.asNode() );
292                                             }
293                                         }
294         },
295         { RDFList.class, new SupportsCheck() {
296                                             public boolean doCheck( Node n, EnhGraph g ) {
297                                                 return n.equals( RDF.nil.asNode() ) ||
298                                                        g.asGraph().contains( n, RDF.type.asNode(), RDF.List.asNode() );
299                                             }
300                                         }
301         },
302         { OntProperty.class, new SupportsCheck() {
303                                             public boolean doCheck( Node n, EnhGraph g ) {
304                                                 return g.asGraph().contains( n, RDF.type.asNode(), RDF.Property.asNode() ) ||
305                                                        g.asGraph().contains( n, RDF.type.asNode(), OWL.ObjectProperty.asNode() ) ||
306                                                        g.asGraph().contains( n, RDF.type.asNode(), OWL.DatatypeProperty.asNode() ) ||
307                                                        g.asGraph().contains( n, RDF.type.asNode(), OWL.AnnotationProperty.asNode() ) ||
308                                                        g.asGraph().contains( n, RDF.type.asNode(), OWL.TransitiveProperty.asNode() ) ||
309                                                        g.asGraph().contains( n, RDF.type.asNode(), OWL.SymmetricProperty.asNode() ) ||
310                                                        g.asGraph().contains( n, RDF.type.asNode(), OWL.FunctionalProperty.asNode() ) ||
311                                                        g.asGraph().contains( n, RDF.type.asNode(), OWL.InverseFunctionalProperty.asNode() );
312                                             }
313                                         }
314         },
315         { Ontology.class, new SupportsCheck() {
316                                             public boolean doCheck( Node n, EnhGraph g ) {
317                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.Ontology.asNode() );
318                                             }
319                                         }
320         },
321         { Restriction.class, new SupportsCheck() {
322                                             public boolean doCheck( Node n, EnhGraph g ) {
323                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.Restriction.asNode() );
324                                             }
325                                         }
326         },
327         { HasValueRestriction.class, new SupportsCheck() {
328                                             public boolean doCheck( Node n, EnhGraph g ) {
329                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.Restriction.asNode() ) &&
330                                                        containsSome( g,n, OWL.hasValue ) &&
331                                                        containsSome( g,n, OWL.onProperty );
332                                             }
333                                         }
334         },
335         { AllValuesFromRestriction.class, new SupportsCheck() {
336                                             public boolean doCheck( Node n, EnhGraph g ) {
337                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.Restriction.asNode() ) &&
338                                                        containsSome( g, n, OWL.allValuesFrom ) &&
339                                                        containsSome( g, n, OWL.onProperty );
340                                             }
341                                         }
342         },
343         { SomeValuesFromRestriction.class, new SupportsCheck() {
344                                             public boolean doCheck( Node n, EnhGraph g ) {
345                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.Restriction.asNode() ) &&
346                                                        containsSome( g,n, OWL.someValuesFrom ) &&
347                                                        containsSome( g,n, OWL.onProperty );
348                                             }
349                                         }
350         },
351         { CardinalityRestriction.class, new SupportsCheck() {
352                                             public boolean doCheck( Node n, EnhGraph g ) {
353                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.Restriction.asNode() ) &&
354                                                       containsSome( g, n, OWL.cardinality ) &&
355                                                        containsSome( g, n, OWL.onProperty );
356                                             }
357                                         }
358         },
359         { MinCardinalityRestriction.class, new SupportsCheck() {
360                                             public boolean doCheck( Node n, EnhGraph g ) {
361                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.Restriction.asNode() ) &&
362                                                        containsSome( g, n, OWL.minCardinality ) &&
363                                                        containsSome( g, n, OWL.onProperty );
364                                             }
365                                         }
366         },
367         { MaxCardinalityRestriction.class, new SupportsCheck() {
368                                             public boolean doCheck( Node n, EnhGraph g ) {
369                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.Restriction.asNode() ) &&
370                                                        containsSome( g, n, OWL.maxCardinality ) &&
371                                                        containsSome( g, n, OWL.onProperty );
372                                             }
373                                         }
374         },
375         { SymmetricProperty.class, new SupportsCheck() {
376                                             public boolean doCheck( Node n, EnhGraph g ) {
377                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.SymmetricProperty.asNode() ) &&
378                                                        !g.asGraph().contains( n, RDF.type.asNode(), OWL.DatatypeProperty.asNode() );
379                                             }
380                                         }
381         },
382         { TransitiveProperty.class, new SupportsCheck() {
383                                             public boolean doCheck( Node n, EnhGraph g ) {
384                                                 return g.asGraph().contains( n, RDF.type.asNode(), OWL.TransitiveProperty.asNode() ) &&
385                                                        !g.asGraph().contains( n, RDF.type.asNode(), OWL.DatatypeProperty.asNode() );
386                                             }
387                                         }
388         },
389         { Individual.class, new SupportsCheck() {
390                                             public boolean doCheck( Node n, EnhGraph g ) {
391                                                 return n instanceof Node_URI || n instanceof Node_Blank;
392                                             }
393                                         }
394         },
395         { DataRange.class, new SupportsCheck() {
396                                             public boolean doCheck( Node n, EnhGraph g ) {
397                                                 return n instanceof Node_Blank &&
398                                                        g.asGraph().contains( n, RDF.type.asNode(), OWL.DataRange.asNode() );
399                                             }
400                                         }
401         }};
402
403     // to allow concise reference in the code above.
404
public static boolean containsSome( EnhGraph g, Node n, Property p ) {
405         return AbstractProfile.containsSome( g, n, p );
406     }
407
408
409     // Static variables
410
//////////////////////////////////
411

412     /** Map from resource to syntactic/semantic checks that a node can be seen as the given facet */
413     private static HashMap s_supportsChecks = new HashMap();
414
415     static {
416         // initialise the map of supports checks from a table of static data
417
for (int i = 0; i < s_supportsCheckData.length; i++) {
418             s_supportsChecks.put( s_supportsCheckData[i][0], s_supportsCheckData[i][1] );
419         }
420     }
421
422     protected Map getCheckTable() {
423         return s_supportsChecks;
424     }
425 }
426
427
428
429
430 /*
431     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
432     All rights reserved.
433
434     Redistribution and use in source and binary forms, with or without
435     modification, are permitted provided that the following conditions
436     are met:
437
438     1. Redistributions of source code must retain the above copyright
439        notice, this list of conditions and the following disclaimer.
440
441     2. Redistributions in binary form must reproduce the above copyright
442        notice, this list of conditions and the following disclaimer in the
443        documentation and/or other materials provided with the distribution.
444
445     3. The name of the author may not be used to endorse or promote products
446        derived from this software without specific prior written permission.
447
448     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
449     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
450     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
451     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
452     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
453     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
454     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
455     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
456     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
457     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
458 */

459
460
Popular Tags