OWLFactory.java revision 2
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// The MIT License
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen//
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// Copyright (c) 2004 Evren Sirin
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen//
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// Permission is hereby granted, free of charge, to any person obtaining a copy
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// of this software and associated documentation files (the "Software"), to
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// deal in the Software without restriction, including without limitation the
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// sell copies of the Software, and to permit persons to whom the Software is
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// furnished to do so, subject to the following conditions:
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen//
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// The above copyright notice and this permission notice shall be included in
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// all copies or substantial portions of the Software.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen//
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen// IN THE SOFTWARE.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen/*
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * Created on Dec 29, 2003
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenpackage org.mindswap.owl;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenimport java.net.URI;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenimport java.util.Map;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenimport org.mindswap.owls.vocabulary.OWLS;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenimport org.mindswap.query.ABoxQueryParser;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen/**
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * @author Evren Sirin
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenpublic class OWLFactory {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen private static OWLKnowledgeBase kb;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen private static OWLOntology owlsService;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen private static OWLOntology owlsProfile;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen private static OWLOntology owlsGrounding;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen private static OWLOntology owlsProcess;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public interface Interface {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public Map getReasoners();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public Object getReasoner(String reasonerName);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public OWLKnowledgeBase createKB();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public OWLOntology createOntology();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public OWLOntology createOntology(URI uri);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public OWLReader createReader();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public OWLWriter createWriter();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public OWLDataValueList createDataValueList();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public OWLIndividualList createIndividualList();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public ABoxQueryParser createRDQLParser(OWLModel model);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public Map getDefaultConverters();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen private static String[] implementations = {"impl.jena.JenaOWLFactory"};
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen private static OWLFactory.Interface factory = createFactory();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen private static OWLFactory.Interface createFactory() {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen for(int i = 0; (factory == null) && (i < implementations.length); i++) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen try {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen Class impl = Class.forName(implementations[i]);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen factory = (OWLFactory.Interface) impl.newInstance();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen } catch(Exception e) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen System.err.println("Cannot create OWLFactory!");
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen e.printStackTrace();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return factory;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public static OWLKnowledgeBase createKB() {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return factory.createKB();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public static OWLOntology createOntology() {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return createOntology(false);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public static OWLOntology createOntology(URI uri) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return createOntology(uri, false);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /**
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * Create an empty OWL ontology and optionally import the
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * OWL-S ontologies (Service, Profile, Process and Grounding
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * ontologies).
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * @param importOWLS
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * @return
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public static OWLOntology createOntology( boolean importOWLS ) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen OWLOntology ont = factory.createOntology();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen if( importOWLS )
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen addOWLSImports( ont );
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return ont;
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /**
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * Create an empty OWL ontology with the given logical URI
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen * and optionally import the OWL-S ontologies (Service, Profile, Process
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen * and Grounding ontologies)
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen *
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen * @param importOWLS
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen * @return
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen */
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen public static OWLOntology createOntology( URI uri, boolean importOWLS ) {
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen OWLOntology ont = factory.createOntology(uri);
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen if( importOWLS )
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen addOWLSImports( ont );
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen return ont;
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen }
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen /**
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen * Import the OWL-S ontologies (Service, Profile, Process
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen * and Grounding ontologies) in the given ontology
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen *
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * @param ont
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen * @return
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public static void addOWLSImports( OWLOntology ont ) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen loadOWLSOntologies();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen ont.addImport( owlsService );
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen ont.addImport( owlsProfile );
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen ont.addImport( owlsProcess );
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen ont.addImport( owlsGrounding );
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen private static void loadOWLSOntologies() {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen if( kb == null ) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen kb = createKB();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen try {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen owlsService = kb.read( OWLS.Service.URI );
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen owlsProfile = kb.read( OWLS.Profile.URI );
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen owlsProcess = kb.read( OWLS.Process.URI );
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen owlsGrounding = kb.read( OWLS.Grounding.URI );
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen catch( Exception e ) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen owlsService = kb.createOntology( URI.create( OWLS.Service.URI ) );
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen owlsProfile = kb.createOntology( URI.create( OWLS.Profile.URI ) );
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen owlsProcess = kb.createOntology( URI.create( OWLS.Process.URI ) );
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen owlsGrounding = kb.createOntology( URI.create( OWLS.Grounding.URI ) );
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen }
b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011Timo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public static OWLReader createReader() {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return factory.createReader();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public static OWLWriter createWriter() {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return factory.createWriter();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public static OWLDataValueList createDataValueList() {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return factory.createDataValueList();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public static OWLIndividualList createIndividualList() {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return factory.createIndividualList();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public static Map getReasoners() {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return factory.getReasoners();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public static Object getReasoner(String reasonerName) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return factory.getReasoner(reasonerName);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public static ABoxQueryParser createRDQLParser(OWLModel model) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return factory.createRDQLParser(model);
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen public static Map getDefaultConverters() {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return factory.getDefaultConverters();
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen }
bcbca4b66800f0fbfe2643a86d5a6b63d752454dTimo Sirainen}
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen