KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > dig > DIGReasonerFactory


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 July 19th 2003
9  * Filename $RCSfile: DIGReasonerFactory.java,v $
10  * Revision $Revision: 1.7 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:16:24 $
14  * by $Author: andy_seaborne $
15  *
16  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
17  * [See end of file]
18  * ****************************************************************************/

19
20 // Package
21
///////////////
22
package com.hp.hpl.jena.reasoner.dig;
23
24
25
26 // Imports
27
///////////////
28
import com.hp.hpl.jena.rdf.model.*;
29 import com.hp.hpl.jena.reasoner.*;
30 import com.hp.hpl.jena.util.ResourceUtils;
31 import com.hp.hpl.jena.vocabulary.*;
32 import com.hp.hpl.jena.vocabulary.ReasonerVocabulary;
33
34
35
36 /**
37  * <p>
38  * Factory class for generating instances of DIG reasoners. Implements singleton pattern.
39  * </p>
40  *
41  * @author Ian Dickinson, HP Labs (<a HREF="mailto:Ian.Dickinson@hp.com">email</a>)
42  * @version Release @release@ ($Id: DIGReasonerFactory.java,v 1.7 2005/02/21 12:16:24 andy_seaborne Exp $)
43  */

44 public class DIGReasonerFactory
45     implements ReasonerFactory
46 {
47
48     // Constants
49
//////////////////////////////////
50

51     /** Static URI for this reasoner type */
52     public static final String JavaDoc URI = "http://jena.hpl.hp.com/2003/DIGReasoner";
53     
54     /** Default axioms location for the OWL variant DIG reasoner */
55     public static final String JavaDoc DEFAULT_OWL_AXIOMS = "file:etc/dig-owl-axioms.rdf";
56     
57     /** Default axioms location for the DAML variant DIG reasoner */
58     public static final String JavaDoc DEFAULT_DAML_AXIOMS = "file:etc/dig-daml-axioms.rdf";
59     
60     
61     // Static variables
62
//////////////////////////////////
63

64     /** The singleton instance */
65     private static DIGReasonerFactory s_instance = new DIGReasonerFactory();
66     
67     
68     // Instance variables
69
//////////////////////////////////
70

71     /** A model denoting the standard capabilities of a DIG reasoner */
72     private Model m_capabilities = null;
73     
74     
75     // Constructors
76
//////////////////////////////////
77

78     /** Private constructor to enforce singleton pattern */
79     private DIGReasonerFactory() {}
80     
81     
82     // External signature methods
83
//////////////////////////////////
84

85     /**
86      * <p>Answer the singleton instance of the factory.</p>
87      */

88     public static DIGReasonerFactory theInstance() {
89         return s_instance;
90     }
91     
92     
93     /**
94      * <p>Answer a new DIG reasoner instance, optionally configured with the given
95      * configuration resource.</p>
96      * @param configuration A resource whose properties denote the configuration of
97      * the reasoner instance, or null to rely on the default configuration.
98      */

99     public Reasoner create( Resource configuration ) {
100         return new DIGReasoner( null, this, configuration );
101     }
102     
103
104     /**
105      * <p>Answer a new DIG reasoner instance (optionally configured with the given
106      * configuration resource) that is pre-loaded with the axioms pertaining to
107      * the DAML language.</p>
108      * @param configuration A resource whose properties denote the configuration of
109      * the reasoner instance, or null to rely on the default configuration.
110      */

111     public Reasoner createWithDAMLAxioms( Resource configuration ) {
112         return create( OWL.NAMESPACE, DEFAULT_DAML_AXIOMS, configuration );
113     }
114     
115
116     /**
117      * <p>Answer a new DIG reasoner instance (optionally configured with the given
118      * configuration resource) that is pre-loaded with the axioms pertaining to
119      * the OWL language.</p>
120      * @param configuration A resource whose properties denote the configuration of
121      * the reasoner instance, or null to rely on the default configuration.
122      */

123     public Reasoner createWithOWLAxioms( Resource configuration ) {
124         return create( OWL.NAMESPACE, DEFAULT_OWL_AXIOMS, configuration );
125     }
126     
127
128     /**
129      * <p>Create a DIG reasoner with the given ontology language, axioms and configuration.</p>
130      * @param language The URI of the ontology lanuage (owl or daml), or null
131      * @param axiomsURL The URL of the axioms to load, or null
132      * @param configuration The root of the configuration options for the model, or null
133      * @return A new DIG reasoner object
134      */

135     public DIGReasoner create( Resource language, String JavaDoc axiomsURL, Resource configuration ) {
136         Model config = ModelFactory.createDefaultModel();
137         Resource root;
138         
139         if (configuration != null) {
140             config.add( ResourceUtils.reachableClosure( configuration ) );
141             root = (Resource) config.getRDFNode( configuration.getNode() );
142         }
143         else {
144             root = config.createResource();
145         }
146         
147         if (axiomsURL != null && !root.hasProperty( ReasonerVocabulary.EXT_REASONER_AXIOMS )) {
148             config.add( root, ReasonerVocabulary.EXT_REASONER_AXIOMS, config.getResource( axiomsURL ) );
149         }
150         if (language != null && !root.hasProperty( ReasonerVocabulary.EXT_REASONER_ONT_LANG )) {
151             config.add( root, ReasonerVocabulary.EXT_REASONER_ONT_LANG, language );
152         }
153         
154         return (DIGReasoner) create( root );
155     }
156     
157
158     /* (non-Javadoc)
159      * @see com.hp.hpl.jena.reasoner.ReasonerFactory#getCapabilities()
160      */

161     public Model getCapabilities() {
162         if (m_capabilities == null) {
163             m_capabilities = ModelFactory.createDefaultModel();
164             Resource base = m_capabilities.createResource(getURI());
165             base.addProperty(ReasonerVocabulary.nameP, "DIG external Reasoner")
166                 .addProperty(ReasonerVocabulary.descriptionP, "Adapter for external (i.e. non-Jena) DIG reasoner." )
167                 .addProperty(ReasonerVocabulary.supportsP, RDFS.subClassOf)
168                 .addProperty(ReasonerVocabulary.supportsP, RDFS.subPropertyOf)
169                 .addProperty(ReasonerVocabulary.supportsP, RDFS.member)
170                 .addProperty(ReasonerVocabulary.supportsP, RDFS.range)
171                 .addProperty(ReasonerVocabulary.supportsP, RDFS.domain)
172                 
173                 .addProperty( ReasonerVocabulary.supportsP, ReasonerVocabulary.directSubClassOf )
174                 .addProperty( ReasonerVocabulary.supportsP, ReasonerVocabulary.directSubPropertyOf )
175                 
176                 .addProperty( ReasonerVocabulary.supportsP, ReasonerVocabulary.individualAsThingP )
177                 
178                 // TODO - add OWL elements supported
179
.addProperty(ReasonerVocabulary.versionP, "0.1");
180         }
181         
182         return m_capabilities;
183     }
184
185     /**
186      * <p>Answer the URI of this reasoner factory</p>
187      */

188     public String JavaDoc getURI() {
189         return URI;
190     }
191
192
193     // Internal implementation methods
194
//////////////////////////////////
195

196     //==============================================================================
197
// Inner class definitions
198
//==============================================================================
199

200 }
201
202 /*
203  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
204  * All rights reserved.
205  *
206  * Redistribution and use in source and binary forms, with or without
207  * modification, are permitted provided that the following conditions
208  * are met:
209  * 1. Redistributions of source code must retain the above copyright
210  * notice, this list of conditions and the following disclaimer.
211  * 2. Redistributions in binary form must reproduce the above copyright
212  * notice, this list of conditions and the following disclaimer in the
213  * documentation and/or other materials provided with the distribution.
214  * 3. The name of the author may not be used to endorse or promote products
215  * derived from this software without specific prior written permission.
216  *
217  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
218  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
219  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
220  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
221  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
222  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
224  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
225  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
226  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
227  */

228
Popular Tags