KickJava   Java API By Example, From Geeks To Geeks.

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


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 22-Jun-2003
9  * Filename $RCSfile: RDFSProfile.java,v $
10  * Revision $Revision: 1.10 $
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
26 // Imports
27
///////////////
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 import com.hp.hpl.jena.vocabulary.*;
33
34 import java.util.*;
35
36
37 /**
38  * <p>
39  * Ontology language profile for working with RDFS ontologies. RDFS is a (small)
40  * sub-set of OWL, mostly.
41  * </p>
42  *
43  * @author Ian Dickinson, HP Labs
44  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
45  * @version CVS $Id: RDFSProfile.java,v 1.10 2005/04/11 16:22:49 ian_dickinson Exp $
46  */

47 public class RDFSProfile
48     extends AbstractProfile
49 {
50     // Constants
51
//////////////////////////////////
52

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

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

59     // Constructors
60
//////////////////////////////////
61

62     // External signature methods
63
//////////////////////////////////
64

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

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

207     public String JavaDoc getLabel() {
208         return "RDFS";
209     }
210
211     // Internal implementation methods
212
//////////////////////////////////
213

214
215     //==============================================================================
216
// Inner class definitions
217
//==============================================================================
218

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

231     private static Object JavaDoc[][] s_supportsCheckTable = new Object JavaDoc[][] {
232         // Resource (key), check method
233
{ OntClass.class, new SupportsCheck() {
234                                             public boolean doCheck( Node n, EnhGraph g ) {
235                                                 return g.asGraph().contains( n, RDF.type.asNode(), RDFS.Class.asNode() ) ||
236                                                        // These are common cases that we should support
237
n.equals( RDFS.Resource.asNode() ) ||
238                                                        g.asGraph().contains( Node.ANY, RDFS.domain.asNode(), n ) ||
239                                                        g.asGraph().contains( Node.ANY, RDFS.range.asNode(), n )
240                                                        ;
241                                             }
242                                         }
243         },
244         { RDFList.class, new SupportsCheck() {
245                                             public boolean doCheck( Node n, EnhGraph g ) {
246                                                 return n.equals( RDF.nil.asNode() ) ||
247                                                        g.asGraph().contains( n, RDF.type.asNode(), RDF.List.asNode() );
248                                             }
249                                         }
250         },
251         { OntProperty.class, new SupportsCheck() {
252                                             public boolean doCheck( Node n, EnhGraph g ) {
253                                                 return g.asGraph().contains( n, RDF.type.asNode(), RDF.Property.asNode() );
254                                             }
255                                         }
256         },
257     };
258
259
260     // Static variables
261
//////////////////////////////////
262

263     /** Map from resource to syntactic/semantic checks that a node can be seen as the given facet */
264     protected static HashMap s_supportsChecks = new HashMap();
265
266     static {
267         // initialise the map of supports checks from a table of static data
268
for (int i = 0; i < s_supportsCheckTable.length; i++) {
269             s_supportsChecks.put( s_supportsCheckTable[i][0], s_supportsCheckTable[i][1] );
270         }
271     }
272
273     //==============================================================================
274
// Inner class definitions
275
//==============================================================================
276

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

309
Popular Tags