Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 0ff6d267 authored by Jérôme Euzenat's avatar Jérôme Euzenat
Browse files

- Added the oportunity to encapsulate and already loaded ontology

- fixed copyright notices
parent af6efcd2
Branches
Tags
No related merge requests found
/*
* $Id$
*
* Copyright (C) INRIA Rhne-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
......
......@@ -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;
};
*/
}
/*
* $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;
......
/*
* $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 );
}
}
......
......@@ -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 {
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment