KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > ontology > OntModelSpec


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 13-May-2003
9  * Filename $RCSfile: OntModelSpec.java,v $
10  * Revision $Revision: 1.36 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/04/11 14:07:35 $
14  * by $Author: chris-dollin $
15  *
16  * (c) Copyright 2002, 2003, 204, Hewlett-Packard Development Company, LP
17  * (see footer for full conditions)
18  *****************************************************************************/

19
20 // Package
21
///////////////
22
package com.hp.hpl.jena.ontology;
23
24
25
26 // Imports
27
///////////////
28

29 import com.hp.hpl.jena.rdf.model.*;
30 import com.hp.hpl.jena.rdf.model.impl.*;
31 import com.hp.hpl.jena.reasoner.*;
32 import com.hp.hpl.jena.reasoner.rulesys.*;
33 import com.hp.hpl.jena.ontology.impl.*;
34 import com.hp.hpl.jena.vocabulary.*;
35 import com.hp.hpl.jena.reasoner.transitiveReasoner.TransitiveReasonerFactory;
36
37
38 /**
39  * <p>
40  * Encapsulates a description of the components of an ontology model, including the
41  * storage scheme, reasoner and language profile.
42  * </p>
43  *
44  * @author Ian Dickinson, HP Labs
45  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
46  * @version CVS $Id: OntModelSpec.java,v 1.36 2005/04/11 14:07:35 chris-dollin Exp $
47  */

48 public class OntModelSpec extends ModelSpecImpl implements ModelSpec {
49     // Constants
50
//////////////////////////////////
51
// Static variables
52
//////////////////////////////////
53

54     /** A specification for OWL models that are stored in memory and do no additional entailment reasoning */
55     public static final OntModelSpec OWL_MEM = new OntModelSpec( ModelFactory.createMemModelMaker(), null, null, ProfileRegistry.OWL_LANG );
56     
57     /** A specification for OWL models that are stored in memory and use the RDFS inferencer for additional entailments */
58     public static final OntModelSpec OWL_MEM_RDFS_INF = new OntModelSpec( ModelFactory.createMemModelMaker(), null, RDFSRuleReasonerFactory.theInstance(), ProfileRegistry.OWL_LANG );
59     
60     /** A specification for OWL models that are stored in memory and use the transitive inferencer for additional entailments */
61     public static final OntModelSpec OWL_MEM_TRANS_INF = new OntModelSpec( ModelFactory.createMemModelMaker(), null, TransitiveReasonerFactory.theInstance(), ProfileRegistry.OWL_LANG );
62     
63     /** A specification for OWL models that are stored in memory and use the OWL rules inference engine for additional entailments */
64     public static final OntModelSpec OWL_MEM_RULE_INF = new OntModelSpec( ModelFactory.createMemModelMaker(), null, OWLFBRuleReasonerFactory.theInstance(), ProfileRegistry.OWL_LANG );
65     
66     /** A specification for OWL models that are stored in memory and use the micro OWL rules inference engine for additional entailments */
67     public static final OntModelSpec OWL_MEM_MICRO_RULE_INF = new OntModelSpec( ModelFactory.createMemModelMaker(), null, OWLMicroReasonerFactory.theInstance(), ProfileRegistry.OWL_LANG );
68     
69     /** A specification for OWL models that are stored in memory and use the mini OWL rules inference engine for additional entailments */
70     public static final OntModelSpec OWL_MEM_MINI_RULE_INF = new OntModelSpec( ModelFactory.createMemModelMaker(), null, OWLMiniReasonerFactory.theInstance(), ProfileRegistry.OWL_LANG );
71     
72     /** A specification for OWL DL models that are stored in memory and do no additional entailment reasoning */
73     public static final OntModelSpec OWL_DL_MEM = new OntModelSpec( ModelFactory.createMemModelMaker(), null, null, ProfileRegistry.OWL_DL_LANG );
74     
75     /** A specification for OWL DL models that are stored in memory and use the RDFS inferencer for additional entailments */
76     public static final OntModelSpec OWL_DL_MEM_RDFS_INF = new OntModelSpec( ModelFactory.createMemModelMaker(), null, RDFSRuleReasonerFactory.theInstance(), ProfileRegistry.OWL_DL_LANG );
77     
78     /** A specification for OWL DL models that are stored in memory and use the transitive inferencer for additional entailments */
79     public static final OntModelSpec OWL_DL_MEM_TRANS_INF = new OntModelSpec( ModelFactory.createMemModelMaker(), null, TransitiveReasonerFactory.theInstance(), ProfileRegistry.OWL_DL_LANG );
80     
81     /** A specification for OWL DL models that are stored in memory and use the OWL rules inference engine for additional entailments */
82     public static final OntModelSpec OWL_DL_MEM_RULE_INF = new OntModelSpec( ModelFactory.createMemModelMaker(), null, OWLFBRuleReasonerFactory.theInstance(), ProfileRegistry.OWL_DL_LANG );
83     
84     /** A specification for OWL Lite models that are stored in memory and do no entailment additional reasoning */
85     public static final OntModelSpec OWL_LITE_MEM = new OntModelSpec( ModelFactory.createMemModelMaker(), null, null, ProfileRegistry.OWL_LITE_LANG );
86     
87     /** A specification for OWL Lite models that are stored in memory and use the transitive inferencer for additional entailments */
88     public static final OntModelSpec OWL_LITE_MEM_TRANS_INF = new OntModelSpec( ModelFactory.createMemModelMaker(), null, TransitiveReasonerFactory.theInstance(), ProfileRegistry.OWL_LITE_LANG );
89     
90     /** A specification for OWL Lite models that are stored in memory and use the RDFS inferencer for additional entailments */
91     public static final OntModelSpec OWL_LITE_MEM_RDFS_INF = new OntModelSpec( ModelFactory.createMemModelMaker(), null, RDFSRuleReasonerFactory.theInstance(), ProfileRegistry.OWL_LITE_LANG );
92     
93     /** A specification for OWL Lite models that are stored in memory and use the OWL rules inference engine for additional entailments */
94     public static final OntModelSpec OWL_LITE_MEM_RULES_INF = new OntModelSpec( ModelFactory.createMemModelMaker(), null, OWLFBRuleReasonerFactory.theInstance(), ProfileRegistry.OWL_LITE_LANG );
95     
96     /** A specification for DAML models that are stored in memory and do no additional entailment reasoning */
97     public static final OntModelSpec DAML_MEM = new OntModelSpec( ModelFactory.createMemModelMaker(), null, null, ProfileRegistry.DAML_LANG );
98     
99     /** A specification for DAML models that are stored in memory and use the transitive reasoner for entailments */
100     public static final OntModelSpec DAML_MEM_TRANS_INF = new OntModelSpec( ModelFactory.createMemModelMaker(), null, TransitiveReasonerFactory.theInstance(), ProfileRegistry.DAML_LANG );
101     
102     /** A specification for DAML models that are stored in memory and use the RDFS inferencer for additional entailments */
103     public static final OntModelSpec DAML_MEM_RDFS_INF = new OntModelSpec( ModelFactory.createMemModelMaker(), null, RDFSRuleReasonerFactory.theInstance(), ProfileRegistry.DAML_LANG );
104     
105     /** A specification for DAML models that are stored in memory and use a subset of the DAML semantic model additional entailments */
106     public static final OntModelSpec DAML_MEM_RULE_INF = new OntModelSpec( ModelFactory.createMemModelMaker(), null, DAMLMicroReasonerFactory.theInstance(), ProfileRegistry.DAML_LANG );
107     
108     /** A specification for RDFS ontology models that are stored in memory and do no additional entailment reasoning */
109     public static final OntModelSpec RDFS_MEM = new OntModelSpec( ModelFactory.createMemModelMaker(), null, null, ProfileRegistry.RDFS_LANG );
110     
111     /** A specification for RDFS ontology models that are stored in memory and use the transitive reasoner for entailments */
112     public static final OntModelSpec RDFS_MEM_TRANS_INF = new OntModelSpec( ModelFactory.createMemModelMaker(), null, TransitiveReasonerFactory.theInstance(), ProfileRegistry.RDFS_LANG );
113     
114     /** A specification for RDFS ontology models that are stored in memory and use the RDFS inferencer for additional entailments */
115     public static final OntModelSpec RDFS_MEM_RDFS_INF = new OntModelSpec( ModelFactory.createMemModelMaker(), null, RDFSRuleReasonerFactory.theInstance(), ProfileRegistry.RDFS_LANG );
116     
117     
118     // Instance variables
119
//////////////////////////////////
120

121     /** The specification document manager */
122     protected OntDocumentManager m_docManager = null;
123     
124     /** The specification reasoner */
125     protected Reasoner m_reasoner = null;
126     
127     /** The language URI for the ontology */
128     protected String JavaDoc m_languageURI;
129     
130     /** The ontology language profile */
131     protected Profile m_profile = null;
132     
133     /** The reasoner factory for creating the reasoner on demand */
134     protected ReasonerFactory m_rFactory = null;
135     
136     /** The ModelMaker used for creating imported models */
137     protected ModelMaker importsMaker;
138     
139     /** the name of the base model in the baseModelMaker, if specified */
140     protected String JavaDoc baseModelName;
141     
142     // Constructors
143
//////////////////////////////////
144

145     /**
146      * <p>Construct a new ontology model specification with the given specification parameters</p>
147      * @param importsMaker The model maker, which will be used to construct stores for statements in the
148      * imported ontologies and the base ontology. Use null to get a default (memory) model maker.
149      * @param docMgr The document manager, or null for the default document manager.
150      * @param rFactory The factory for the reasoner to use to infer additional triples in the model, or null for no reasoner
151      * @param languageURI The URI of the ontology language. Required.
152      */

153     public OntModelSpec( ModelMaker importsMaker, OntDocumentManager docMgr, ReasonerFactory rFactory, String JavaDoc languageURI ) {
154         this( ModelFactory.createMemModelMaker(), importsMaker, docMgr, rFactory, languageURI );
155     }
156     
157     /**
158      * Construct a new ontology model specification from the supplied components.
159      * @param baseMaker the model-maker to use for the base model
160      * @param importsMaker the model-maker to use for imported models
161      * @param docMgr the document manager (null for the default manager)
162      * @param rFactory the reasoner (null for no reasoner)
163      * @param languageURI the ontology language URI (must not be null)
164     */

165     public OntModelSpec( ModelMaker baseMaker, ModelMaker importsMaker, OntDocumentManager docMgr,
166             ReasonerFactory rFactory, String JavaDoc languageURI )
167         { this( null, baseMaker, importsMaker, docMgr, rFactory, languageURI ); }
168     
169     
170     /**
171      * Construct a new ontology model specification from the supplied components.
172      * @param baseModelName the name of the model in the baseModelMaker
173      * @param baseMaker the model-maker to use for the base model
174      * @param importsMaker the model-maker to use for imported models
175      * @param docMgr the document manager (null for the default manager)
176      * @param rFactory the reasoner (null for no reasoner)
177      * @param languageURI the ontology language URI (must not be null)
178     */

179     public OntModelSpec( String JavaDoc baseModelName, ModelMaker baseMaker,
180             ModelMaker importsMaker, OntDocumentManager docMgr,
181             ReasonerFactory rFactory, String JavaDoc languageURI ) {
182         super( baseMaker );
183         this.baseModelName = baseModelName;
184         this.importsMaker = importsMaker == null ? ModelFactory.createMemModelMaker(): importsMaker;
185         setDocumentManager( docMgr );
186         setReasonerFactory( rFactory );
187         
188         if (languageURI == null) {
189             throw new IllegalArgumentException JavaDoc( "Cannot create OntModelSpec with a null ontology language" );
190         }
191         setLanguage( languageURI );
192     }
193     
194     
195     /**
196      * <p>Create one model spec as a copy of another. This is useful when what is required is similar to
197      * an existing spec, but with some changes. <strong>Note:</strong> this is only a shallow copy, so the
198      * structured objects (reasoners, document managers, etc) are not themselves copied. Thus, even after
199      * calling this copy constructor, making a change to the document manager in the copy specification
200      * will also affect the one that the copy was made from. The correct idiom is to replace the object
201      * before side-effecting it, e.g:
202      * <code><pre>
203      * OntModelSpec newSpec = new OntModelSpec( existingSpec );
204      * newSpec.setDocumentManager( new OntDocumentManager() );
205      * newSpec.getDocumentManager().setMetaDataSearchPath( "..." );
206      * </pre></code>
207      * @param spec
208      */

209     public OntModelSpec( OntModelSpec spec ) {
210         this( spec.getBaseModelMaker(), spec.getImportModelMaker(), spec.getDocumentManager(),
211             spec.getReasonerFactory(), spec.getLanguage() );
212     }
213     
214     /**
215      * Answer the model maker used for creating imported models.
216      * @deprecated use getImportModelMaker
217     */

218     public ModelMaker getModelMaker() {
219         if (false) throw new RuntimeException JavaDoc( "get rid of calls to this method" );
220         return getImportModelMaker();
221     }
222     
223     /**
224      * Answer the model maker used for creating imported models.
225     */

226     public ModelMaker getImportModelMaker() {
227         return importsMaker;
228     }
229     
230     /**
231      * Answer the model maker used for creating base models.
232     */

233     public ModelMaker getBaseModelMaker() {
234         return super.getModelMaker();
235     }
236     
237     /**
238         Initialise an OntModelSpec from an RDF description using the JenaModelSpec vocabulary. See
239         (insert reference here) for the description of the OntModel used. The root of the
240         description is the unique resource with type JenaModelSpec:OntMakerClass.
241         
242         @param description an RDF model using the JenaModelSpec vocabulary
243     */

244     public OntModelSpec( Model description ) {
245         this( findRootByType( description, JenaModelSpec.OntModelSpec ), description );
246     }
247
248     /**
249         Initialise an OntModelSpec from an RDF description using the JenaModelSpec vocabulary. See
250         (insert reference here) for the description of the OntModel used. The root of the
251         description is supplied as a parameter (so the description may describe several
252         different OntModels).
253         
254         @param description an RDF model using the JenaModelSpec vocabulary
255         @param root the root of the sub-graph to use for the specification
256     */

257     public OntModelSpec( Resource root, Model description ) {
258         this( getBaseModelName( description, root ),
259             getBaseMaker( description, root ),
260             getImportMaker( description, root ),
261             getDocumentManager( description, root ),
262             getReasonerFactory( description, root ),
263             getLanguage( description, root ) );
264         
265     }
266
267     /**
268      * <p>Answer a default specification for the given language URI. This default
269      * will typically use a memory model and have minimal inferencing capabilities.
270      * Specifically, OWL and RDFS languages will have RDFS level inferencing
271      * capability (chosen to give a reasonable balance between power and efficiency
272      * of computation), and DAML language will have the minimal DAML rule reasoner.
273      * To get other (more powerful or less powerful) reasoning capabilities, users
274      * should create ontology models by passing an explicit <code>OntModelSpec</code>
275      * parameter to the
276      * {@link ModelFactory#createOntologyModel( OntModelSpec, Model ) model factory}.
277      * </p>
278      * @param languageURI The ontology language we want a default model spec for
279      * @return The default model spec for that language
280      * @exception OntologyException if the URI is not a recognised name of an ontology language
281      */

282     public static OntModelSpec getDefaultSpec( String JavaDoc languageURI ) {
283         if (languageURI.equals( ProfileRegistry.OWL_LANG )) {
284             return OWL_MEM_RDFS_INF;
285         }
286         else if (languageURI.equals( ProfileRegistry.OWL_DL_LANG )) {
287             return OWL_DL_MEM_RDFS_INF;
288         }
289         else if (languageURI.equals( ProfileRegistry.OWL_LITE_LANG )) {
290             return OWL_LITE_MEM_RDFS_INF;
291         }
292         else if (languageURI.equals( ProfileRegistry.DAML_LANG )) {
293             return DAML_MEM_RULE_INF;
294         }
295         else if (languageURI.equals( ProfileRegistry.RDFS_LANG )) {
296             return RDFS_MEM_RDFS_INF;
297         }
298         else {
299             throw new OntologyException( "Did not recognise this language URI, so cannot determine default model spec: " + languageURI );
300         }
301     }
302     
303     
304     /**
305      * <p>Answer the document manager for this model specification. Defaults to
306      * a standard instance of {@link OntDocumentManager}</p>
307      * @return The document manager to be used by models matching this specification
308      */

309     public OntDocumentManager getDocumentManager() {
310         if (m_docManager == null) {
311             // need to set the default document manager
312
m_docManager = OntDocumentManager.getInstance();
313         }
314         
315         return m_docManager;
316     }
317     
318     
319     /**
320      * <p>Set the document manager in this specification</p>
321      * @param docMgr The new document manager
322      */

323     public void setDocumentManager( OntDocumentManager docMgr ) {
324         m_docManager = docMgr;
325     }
326     
327     /**
328      * <p>Set the model maker that will be used when the ontology model needs to create
329      * an additional container for an imported ontology</p>
330      * @param maker The new model maker to use
331      */

332     public void setImportModelMaker( ModelMaker maker ) {
333         this.maker = maker;
334     }
335     
336     /**
337         Set the model maker used for imported models. OntModelSpecs now have
338         separate model makers for imported vs base models - use the correct
339         one. (Originally they shared the same maker; this was a mistake.)
340         
341         @deprecated use setImportModelMaker or setBaseModelMaker
342      */

343     public void setModelMaker( ModelMaker m ) {
344         setImportModelMaker( m );
345     }
346     
347     /**
348        Set the model maker used for base models.
349    */

350     public void setBaseModelMaker( ModelMaker m ) {
351         this.maker = m;
352     }
353     
354     /**
355      * <p>Answer the reasoner that will be used to infer additional entailed
356      * triples in the ontology model.</p>
357      * @return The reasoner for this specification
358      */

359     public Reasoner getReasoner() {
360         if (m_reasoner == null && m_rFactory != null) {
361             // we need to create the reasoner for the first time
362
m_reasoner = m_rFactory.create( null );
363         }
364         
365         return m_reasoner;
366     }
367     
368     
369     /**
370      * <p>Set the reasoner that will be used by ontology models that conform
371      * to this specification to compute entailments.
372      * <strong>Note:</strong> The reasoner is generated on demand by the reasoner
373      * factory. To prevent this spec from having a reasoner, set the reasoner factory
374      * to null, see {@link #setReasonerFactory}.
375      * </p>
376      * @param reasoner The new reasoner
377      */

378     public void setReasoner( Reasoner reasoner ) {
379         m_reasoner = reasoner;
380     }
381     
382     
383     /**
384      * <p>Set the factory object that will be used to generate the reasoner object
385      * for this model specification. <strong>Note</strong> that the reasoner itself is cached, so setting
386      * the factory after a call to {@link #getReasoner()} will have no effect.</p>
387      * @param rFactory The new reasoner factory, or null to prevent any reasoner being used
388      */

389     public void setReasonerFactory( ReasonerFactory rFactory ) {
390         m_rFactory = rFactory;
391     }
392     
393     /**
394      * <p>Answer the current reasoner factory</p>
395      * @return The reasoner factory, or null.
396      */

397     public ReasonerFactory getReasonerFactory() {
398         return m_rFactory;
399     }
400     
401     
402     /**
403      * <p>Answer the URI of the ontology lanuage to use when constructing
404      * models from this specification. Well known language URI's are
405      * available from the {@link ProfileRegistry}</p>
406      * @return The ontology language URI
407      */

408     public String JavaDoc getLanguage() {
409         return m_languageURI;
410     }
411     
412     
413     /**
414      * <p>Set the URI of the ontology to use for models that conform to
415      * this specification.</p>
416      * @param languageURI The new language URI
417      * @exception OntologyException if the URI does not map to a known language profile
418      */

419     public void setLanguage( String JavaDoc languageURI ) {
420         m_languageURI = languageURI;
421         m_profile = ProfileRegistry.getInstance().getProfile( m_languageURI );
422         
423         if (m_profile == null) {
424             throw new OntologyException( "Could not determine an ontology language profile for URI " + m_languageURI );
425         }
426     }
427     
428     
429     /**
430      * <p>Answer the language profile for this ontology specification</p>
431      * @return An ontology langauge profile object
432      */

433     public Profile getProfile() {
434         return m_profile;
435     }
436     
437     /**
438         Satisfy the ModelSpec interface: create an [Ont]Model according to the specification.
439         The base model comes from the underlying ModelMaker.
440         @return an OntModel satisfying this specification
441     */

442     public Model createModel() {
443         Model m = baseModelName == null ? maker.createModel() : maker.createModel( baseModelName );
444         return new OntModelImpl( this, m );
445     }
446     
447     /**
448         Satisfy the ModelSpec interface: create an [Ont]Model according to the specification.
449         The base model comes from the underlying ModelMaker and is named by the
450         give name.
451         @see com.hp.hpl.jena.rdf.model.ModelSpec#createModelOver(java.lang.String)
452      */

453     public Model createModelOver( String JavaDoc name ) {
454         return new OntModelImpl( this, maker.createModel( name, false ) );
455     }
456     
457     /**
458         Answer the ModelMaker to be used to construct models that are used for
459         the imports of an OntModel. The ModelMaker is specified by the properties of
460         the resource which is the object of the root's JenaModelSpec.importMaker property.
461         If no importMaker is specified, a MemModelMaker is constructed and used.
462         
463         @param description the description model for [at least] this OntModel
464         @param root the root of the description for the OntModel
465         @return a ModelMaker fitting the importMaker description
466      */

467     public static ModelMaker getImportMaker( Model description, Resource root ) {
468         return getMaker( description, root, JenaModelSpec.importMaker );
469     }
470     
471     /**
472         Answer the ModelMaker to be used to construct base models of an
473         OntModel. The ModelMaker is specified by the properties of
474         the resource which is the object of the root's JenaModelSpec.maker property.
475         If no maker is specified, a MemModelMaker is constructed and used.
476         
477         @param description the description model for [at least] this OntModel
478         @param root the root of the description for the OntModel
479         @return a ModelMaker fitting the maker description
480      */

481     public static ModelMaker getBaseMaker( Model description, Resource root ) {
482             return getMaker( description, root, JenaModelSpec.maker );
483         }
484
485     /**
486         Answer the value of the jms:modelName property of <code>root</code>,
487         or <code>null</code> id there isn't one.
488     */

489     protected static String JavaDoc getBaseModelName( Model description, Resource root ) {
490         Statement s = description.getProperty( root, JenaModelSpec.modelName );
491         return s == null ? null : s.getString();
492         }
493     
494     /**
495         Answer a ModelMaker described by the <code>makerProperty</code> of
496         <code>root</code> in <code>description</code>; if there is no such statement,
497         answer a memory-model maker.
498     */

499     protected static ModelMaker getMaker( Model description, Resource root, Property makerProperty ) {
500         Statement mStatement = description.getProperty( root, makerProperty );
501         return mStatement == null
502             ? ModelFactory.createMemModelMaker()
503             : createMaker( mStatement.getResource(), description );
504     }
505         
506     /**
507         Answer the URI string of the ontology language in this description.
508      
509         @param description the Model from which to extract the description
510         @return the language string
511         @exception something if the value isn't a URI resource
512     */

513     public static String JavaDoc getLanguage( Model description, Resource root ) {
514         Statement langStatement = description.getRequiredProperty( root, JenaModelSpec.ontLanguage );
515         return langStatement.getResource().getURI();
516     }
517     
518     /**
519         Answer an OntDocumentManager satisfying the docManager part of this description.
520         Currently restricted to one where the object of JenaModelSpec.docManager is registered with
521         the value table held in ModelSpecImpl. If there's no such property, or if its bnode
522         has no associated value, returns null.
523         
524          @param description the description of the OntModel
525          @param root the root of the description
526          @return the OntDocumentManager of root's JenaModelSpec.docManager
527     */

528     public static OntDocumentManager getDocumentManager( Model description,
529         Resource root ) {
530         Statement docStatement = description.getProperty( root, JenaModelSpec.docManager );
531         if (docStatement == null) return null;
532         Resource manager = docStatement.getResource();
533         Statement policy = description.getProperty( manager, JenaModelSpec.policyPath );
534         if (policy == null)
535             return (OntDocumentManager) getValue( manager );
536         else
537             return new OntDocumentManager( policy.getString() );
538     }
539
540     /**
541         Answer a ReasonerFactory as described by the reasonsWith part of this discription,
542         or null if no reasoner specification has been supplied.
543         
544         @param description the description of this OntModel
545         @param root the root of this OntModel's description
546         @return a ReasonerFactory with URI given by root's reasonsWith's reasoner.
547     */

548     public static ReasonerFactory getReasonerFactory( Model description, Resource root ) {
549         Statement factStatement = description.getProperty( root, JenaModelSpec.reasonsWith );
550         if (factStatement == null) return null;
551         return InfModelSpec.getReasonerFactory( factStatement.getResource(), description );
552     }
553
554     /**
555         Add the description of this OntModelSpec to the given model under the given
556         resource. This same description can be used to create an equivalent OntModelSpec.
557         Serialising the description will lose the DocumentManager description.
558         
559         TODO allow the DocumentManager to be [de]serialised
560     */

561     public Model addDescription( Model d, Resource self ) {
562         super.addDescription( d, self );
563         addImportsDescription( d, self, importsMaker );
564         addLanguageDescription( d, self, m_languageURI );
565         addManagerDescription( d, self, getDocumentManager() );
566         addReasonerDescription( d, self, getReasonerFactory() );
567         return d;
568     }
569     
570     /**
571         Answer the RDFS property used to attach this ModelSpec to its ModelMaker; used
572         by the parent classes when constructing the RDF description for this Spec.
573         
574         @return JenaModelSpec.importMaker
575     */

576     public Property getMakerProperty() {
577         return JenaModelSpec.importMaker;
578     }
579         
580     /**
581         Augment the description with that of our language
582         @param d the description to augment
583         @param me the resource to use to represent this OntModelSpec
584         @param langURI the language URI
585     */

586     protected void addLanguageDescription( Model d, Resource me, String JavaDoc langURI ) {
587         d.add( me, JenaModelSpec.ontLanguage, d.createResource( langURI ) );
588     }
589     
590     protected void addImportsDescription( Model d, Resource me, ModelMaker m ) {
591         Resource importSelf = d.createResource();
592         d.add( me, JenaModelSpec.importMaker, importSelf );
593         m.addDescription( d, importSelf );
594     }
595     
596     /**
597         Augment the description with that of our document manager [as a Java value]
598         @param d the description to augment
599         @param me the resource to use to represent this OntModelSpec
600         @param man the document manager
601     */

602     protected void addManagerDescription( Model d, Resource me,
603         OntDocumentManager man ) {
604         d.add( me, JenaModelSpec.docManager, createValue( man ) );
605     }
606     
607     /**
608         Augment the description with that of our reasoner factory
609         @param d the description to augment
610         @param me the resource to use to represent this OntModelSpec
611         @param rf the reasoner factory to describe
612     */

613     protected void addReasonerDescription( Model d, Resource me, ReasonerFactory rf ) {
614         Resource reasonerSelf = d.createResource();
615         d.add( me, JenaModelSpec.reasonsWith, reasonerSelf );
616         if (rf != null) {
617             d.add( reasonerSelf, JenaModelSpec.reasoner, d.createResource( rf.getURI() ) );
618         }
619     }
620
621     /**
622         Answer a base model constructed according to this specificiation. This is used for the
623         "base" (ie non-imported) model for an OntModel.
624     */

625     public Model createBaseModel() {
626         return ModelFactory.createDefaultModel();
627     }
628     
629 }
630
631
632 /*
633     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
634     All rights reserved.
635
636     Redistribution and use in source and binary forms, with or without
637     modification, are permitted provided that the following conditions
638     are met:
639
640     1. Redistributions of source code must retain the above copyright
641        notice, this list of conditions and the following disclaimer.
642
643     2. Redistributions in binary form must reproduce the above copyright
644        notice, this list of conditions and the following disclaimer in the
645        documentation and/or other materials provided with the distribution.
646
647     3. The name of the author may not be used to endorse or promote products
648        derived from this software without specific prior written permission.
649
650     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
651     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
652     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
653     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
654     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
655     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
656     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
657     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
658     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
659     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
660 */

661
662
Popular Tags