001: /*****************************************************************************
002: * Source code information
003: * -----------------------
004: * Original author Ian Dickinson, HP Labs Bristol
005: * Author email Ian.Dickinson@hp.com
006: * Package Jena 2
007: * Web http://sourceforge.net/projects/jena/
008: * Created July 19th 2003
009: * Filename $RCSfile: DIGReasonerFactory.java,v $
010: * Revision $Revision: 1.11 $
011: * Release status $State: Exp $
012: *
013: * Last modified on $Date: 2008/01/02 12:07:11 $
014: * by $Author: andy_seaborne $
015: *
016: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
017: * [See end of file]
018: * ****************************************************************************/package com.hp.hpl.jena.reasoner.dig;
019:
020: // Imports
021: ///////////////
022: import com.hp.hpl.jena.rdf.model.*;
023: import com.hp.hpl.jena.reasoner.*;
024: import com.hp.hpl.jena.util.ResourceUtils;
025: import com.hp.hpl.jena.vocabulary.*;
026: import com.hp.hpl.jena.vocabulary.ReasonerVocabulary;
027:
028: /**
029: * <p>
030: * Factory class for generating instances of DIG reasoners. Implements singleton pattern.
031: * </p>
032: *
033: * @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com">email</a>)
034: * @version Release @release@ ($Id: DIGReasonerFactory.java,v 1.11 2008/01/02 12:07:11 andy_seaborne Exp $)
035: */
036: public class DIGReasonerFactory implements ReasonerFactory {
037:
038: // Constants
039: //////////////////////////////////
040:
041: /** Static URI for this reasoner type */
042: public static final String URI = "http://jena.hpl.hp.com/2003/DIGReasoner";
043:
044: /** Default axioms location for the OWL variant DIG reasoner */
045: public static final String DEFAULT_OWL_AXIOMS = "file:etc/dig-owl-axioms.rdf";
046:
047: /** Default axioms location for the DAML variant DIG reasoner */
048: public static final String DEFAULT_DAML_AXIOMS = "file:etc/dig-daml-axioms.rdf";
049:
050: // Static variables
051: //////////////////////////////////
052:
053: /** The singleton instance */
054: private static DIGReasonerFactory s_instance = new DIGReasonerFactory();
055:
056: // Instance variables
057: //////////////////////////////////
058:
059: /** A model denoting the standard capabilities of a DIG reasoner */
060: private Model m_capabilities = null;
061:
062: // Constructors
063: //////////////////////////////////
064:
065: /** Private constructor to enforce singleton pattern */
066: private DIGReasonerFactory() {
067: }
068:
069: // External signature methods
070: //////////////////////////////////
071:
072: /**
073: * <p>Answer the singleton instance of the factory.</p>
074: */
075: public static DIGReasonerFactory theInstance() {
076: return s_instance;
077: }
078:
079: /**
080: * <p>Answer a new DIG reasoner instance, optionally configured with the given
081: * configuration resource.</p>
082: * @param configuration A resource whose properties denote the configuration of
083: * the reasoner instance, or null to rely on the default configuration.
084: */
085: public Reasoner create(Resource configuration) {
086: return new DIGReasoner(null, this , configuration);
087: }
088:
089: /**
090: * <p>Answer a new DIG reasoner instance (optionally configured with the given
091: * configuration resource) that is pre-loaded with the axioms pertaining to
092: * the DAML language.</p>
093: * @param configuration A resource whose properties denote the configuration of
094: * the reasoner instance, or null to rely on the default configuration.
095: */
096: public Reasoner createWithDAMLAxioms(Resource configuration) {
097: return create(OWL.NAMESPACE, DEFAULT_DAML_AXIOMS, configuration);
098: }
099:
100: /**
101: * <p>Answer a new DIG reasoner instance (optionally configured with the given
102: * configuration resource) that is pre-loaded with the axioms pertaining to
103: * the OWL language.</p>
104: * @param configuration A resource whose properties denote the configuration of
105: * the reasoner instance, or null to rely on the default configuration.
106: */
107: public Reasoner createWithOWLAxioms(Resource configuration) {
108: return create(OWL.NAMESPACE, DEFAULT_OWL_AXIOMS, configuration);
109: }
110:
111: /**
112: * <p>Create a DIG reasoner with the given ontology language, axioms and configuration.</p>
113: * @param language The URI of the ontology lanuage (owl or daml), or null
114: * @param axiomsURL The URL of the axioms to load, or null
115: * @param configuration The root of the configuration options for the model, or null
116: * @return A new DIG reasoner object
117: */
118: public DIGReasoner create(Resource language, String axiomsURL,
119: Resource configuration) {
120: Model config = ModelFactory.createDefaultModel();
121: Resource root;
122:
123: if (configuration != null) {
124: config.add(ResourceUtils.reachableClosure(configuration));
125: root = (Resource) config.getRDFNode(configuration.asNode());
126: } else {
127: root = config.createResource();
128: }
129:
130: if (axiomsURL != null
131: && !root
132: .hasProperty(ReasonerVocabulary.EXT_REASONER_AXIOMS)) {
133: config.add(root, ReasonerVocabulary.EXT_REASONER_AXIOMS,
134: config.getResource(axiomsURL));
135: }
136: if (language != null
137: && !root
138: .hasProperty(ReasonerVocabulary.EXT_REASONER_ONT_LANG)) {
139: config.add(root, ReasonerVocabulary.EXT_REASONER_ONT_LANG,
140: language);
141: }
142:
143: return (DIGReasoner) create(root);
144: }
145:
146: /* (non-Javadoc)
147: * @see com.hp.hpl.jena.reasoner.ReasonerFactory#getCapabilities()
148: */
149: public Model getCapabilities() {
150: if (m_capabilities == null) {
151: m_capabilities = ModelFactory.createDefaultModel();
152: Resource base = m_capabilities.createResource(getURI());
153: base
154: .addProperty(ReasonerVocabulary.nameP,
155: "DIG external Reasoner")
156: .addProperty(ReasonerVocabulary.descriptionP,
157: "Adapter for external (i.e. non-Jena) DIG reasoner.")
158: .addProperty(ReasonerVocabulary.supportsP,
159: RDFS.subClassOf).addProperty(
160: ReasonerVocabulary.supportsP,
161: RDFS.subPropertyOf).addProperty(
162: ReasonerVocabulary.supportsP, RDFS.member)
163: .addProperty(ReasonerVocabulary.supportsP,
164: RDFS.range).addProperty(
165: ReasonerVocabulary.supportsP, RDFS.domain)
166:
167: .addProperty(ReasonerVocabulary.supportsP,
168: ReasonerVocabulary.directSubClassOf)
169: .addProperty(ReasonerVocabulary.supportsP,
170: ReasonerVocabulary.directSubPropertyOf)
171:
172: .addProperty(ReasonerVocabulary.supportsP,
173: ReasonerVocabulary.individualAsThingP)
174:
175: // TODO - add OWL elements supported
176: .addProperty(ReasonerVocabulary.versionP, "0.1");
177: }
178:
179: return m_capabilities;
180: }
181:
182: /**
183: * <p>Answer the URI of this reasoner factory</p>
184: */
185: public String getURI() {
186: return URI;
187: }
188:
189: // Internal implementation methods
190: //////////////////////////////////
191:
192: //==============================================================================
193: // Inner class definitions
194: //==============================================================================
195:
196: }
197:
198: /*
199: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
200: * All rights reserved.
201: *
202: * Redistribution and use in source and binary forms, with or without
203: * modification, are permitted provided that the following conditions
204: * are met:
205: * 1. Redistributions of source code must retain the above copyright
206: * notice, this list of conditions and the following disclaimer.
207: * 2. Redistributions in binary form must reproduce the above copyright
208: * notice, this list of conditions and the following disclaimer in the
209: * documentation and/or other materials provided with the distribution.
210: * 3. The name of the author may not be used to endorse or promote products
211: * derived from this software without specific prior written permission.
212: *
213: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
214: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
215: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
216: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
217: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
218: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
219: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
220: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
221: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
222: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
223: */
|