diff --git a/src/fr/inrialpes/exmo/align/onto/Ontology.java b/src/fr/inrialpes/exmo/align/onto/Ontology.java index 98dc25a9b63664dc1424a52979d99022ab292964..b6faee037d26603ae1b7f4951c9dcd7c2f208180 100644 --- a/src/fr/inrialpes/exmo/align/onto/Ontology.java +++ b/src/fr/inrialpes/exmo/align/onto/Ontology.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2008 + * Copyright (C) INRIA, 2008 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by diff --git a/src/fr/inrialpes/exmo/align/onto/OntologyFactory.java b/src/fr/inrialpes/exmo/align/onto/OntologyFactory.java index ed2e4ca93d22fd1ed14070b991972d45c1ddf5af..b0528556d358522c296b4a5bea1fbc144310f2cf 100644 --- a/src/fr/inrialpes/exmo/align/onto/OntologyFactory.java +++ b/src/fr/inrialpes/exmo/align/onto/OntologyFactory.java @@ -46,8 +46,6 @@ public abstract class OntologyFactory { return newInstance(API_NAME); } - // JE: The true question here is that instance being static, - // I assume that it is shared by all subclasses! private static OntologyFactory newInstance( String apiName ) { if ( instances == null ) instances = new Hashtable<String,OntologyFactory>(); OntologyFactory of = instances.get( apiName ); @@ -82,16 +80,27 @@ public abstract class OntologyFactory { } } + /** + * All Ontologies must implement clearCache() + * which unload their ontologies if any cache is enabled. + */ public abstract void clearCache(); + /** + * Encapsulate an ontology already in the environment + * These methods should rather be in a LoadableOntologyFactory + */ + public abstract LoadedOntology newOntology( Object onto ) throws AlignmentException; + /** * Load an ontology, cache enabled + * These methods should rather be in a LoadableOntologyFactory */ public abstract LoadedOntology loadOntology( URI uri ) throws AlignmentException; + /** * Load an ontology, cache enabled if true, disabled otherwise * This will disappear: cache will be dispatched in implementations - */ public LoadedOntology loadOntology( URI uri, OntologyCache<LoadedOntology> ontologies ) throws AlignmentException { LoadedOntology onto = null; if ( ontologies != null ) { @@ -104,4 +113,5 @@ public abstract class OntologyFactory { if ( ontologies != null ) ontologies.recordOntology( uri, onto ); return onto; }; + */ } diff --git a/src/fr/inrialpes/exmo/align/onto/jena25/JENAOntology.java b/src/fr/inrialpes/exmo/align/onto/jena25/JENAOntology.java index 76b16c53367296038e1000b5cf7e59c366654141..6973e1112b57b2afc6ff4579e4c5a7cff0d4f9e5 100644 --- a/src/fr/inrialpes/exmo/align/onto/jena25/JENAOntology.java +++ b/src/fr/inrialpes/exmo/align/onto/jena25/JENAOntology.java @@ -1,3 +1,23 @@ +/* + * $Id$ + * + * Copyright (C) INRIA, 2003-2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + package fr.inrialpes.exmo.align.onto.jena25; import java.net.URI; diff --git a/src/fr/inrialpes/exmo/align/onto/jena25/JENAOntologyFactory.java b/src/fr/inrialpes/exmo/align/onto/jena25/JENAOntologyFactory.java index 68b961344be4bfe67e465353ebda1af208c9ce9c..1d923c23935aa4a24a76e2b313389b83bcb55798 100644 --- a/src/fr/inrialpes/exmo/align/onto/jena25/JENAOntologyFactory.java +++ b/src/fr/inrialpes/exmo/align/onto/jena25/JENAOntologyFactory.java @@ -1,6 +1,27 @@ +/* + * $Id$ + * + * Copyright (C) INRIA, 2003-2008 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + package fr.inrialpes.exmo.align.onto.jena25; import java.net.URI; +import java.net.URISyntaxException; import java.util.NoSuchElementException; import org.semanticweb.owl.align.AlignmentException; @@ -15,12 +36,45 @@ import fr.inrialpes.exmo.align.onto.OntologyFactory; public class JENAOntologyFactory extends OntologyFactory{ + private static URI formalismUri = null; + private static String formalismId = "OWL1.0"; + + public JENAOntologyFactory() { + try { + formalismUri = new URI("http://www.w3.org/2002/07/owl#"); + } catch (URISyntaxException ex) { ex.printStackTrace(); } // should not happen + } + // No cache management so far - public void clearCache() { + public void clearCache() {}; + + public JENAOntology newOntology( Object ontology ) throws AlignmentException { + if ( ontology instanceof OntModel ) { + JENAOntology onto = new JENAOntology(); + onto.setFormalism( formalismId ); + onto.setFormURI( formalismUri ); + onto.setOntology( (OntModel)ontology ); + //onto.setFile( uri );// unknown + // to be checked : why several ontologies in a model ??? + // If no URI can be extracted from ontology, then we use the physical URI + try { + try { + onto.setURI(new URI(((Ontology)((OntModel)ontology).listOntologies().next()).getURI())); + } catch (NoSuchElementException nse) { + // JE: not verysafe + onto.setURI(new URI(((OntModel)ontology).getNsPrefixURI(""))); + } + } catch ( URISyntaxException usex ){ + // Better put in the AlignmentException of loaded + throw new AlignmentException( "URI Error ", usex ); + } + return onto; + } else { + throw new AlignmentException( "Argument is not an OntModel: "+ontology ); + } } - @Override - public LoadedOntology loadOntology(URI uri) throws AlignmentException { + public JENAOntology loadOntology( URI uri ) throws AlignmentException { try { OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null ); m.read(uri.toString()); @@ -30,16 +84,14 @@ public class JENAOntologyFactory extends OntologyFactory{ // If no URI can be extracted from ontology, then we use the physical URI try { onto.setURI(new URI(((Ontology)m.listOntologies().next()).getURI())); - } - catch (NoSuchElementException nse) { + } catch (NoSuchElementException nse) { onto.setURI(new URI(m.getNsPrefixURI(""))); //onto.setFile(uri); } //onto.setURI(new URI(m.listOntologies()getOntology(null).getURI())); onto.setOntology(m); return onto; - } - catch (Exception e) { + } catch (Exception e) { throw new AlignmentException("Cannot load "+uri, e ); } } diff --git a/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntologyFactory.java b/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntologyFactory.java index 7e00456c1d8fb4456cfb2207d8474c2fc95830eb..0daf0cb067428875e3023b6ae01f098694e58598 100644 --- a/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntologyFactory.java +++ b/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntologyFactory.java @@ -60,6 +60,26 @@ public class OWLAPIOntologyFactory extends OntologyFactory { cache.clear(); } + public OWLAPIOntology newOntology( Object ontology ) throws AlignmentException { + if ( ontology instanceof OWLOntology ) { + OWLAPIOntology onto = new OWLAPIOntology(); + onto.setFormalism( formalismId ); + onto.setFormURI( formalismUri ); + onto.setOntology( (OWLOntology)ontology ); + //onto.setFile( uri );// unknown + try { + onto.setURI( ((OWLOntology)ontology).getLogicalURI() ); + } catch (OWLException e) { + // Better put in the AlignmentException of loaded + e.printStackTrace(); + } + //cache.recordOntology( uri, onto ); + return onto; + } else { + throw new AlignmentException( "Argument is not an OWLOntology: "+ontology ); + } + } + public OWLAPIOntology loadOntology( URI uri ) throws AlignmentException { OWLAPIOntology onto = null; onto = cache.getOntologyFromURI( uri ); @@ -95,3 +115,4 @@ public class OWLAPIOntologyFactory extends OntologyFactory { } } } +