diff --git a/src/fr/inrialpes/exmo/align/onto/ConcreteOntology.java b/src/fr/inrialpes/exmo/align/onto/ConcreteOntology.java deleted file mode 100644 index db46594290359e26a19e7f886448ff71e7dba151..0000000000000000000000000000000000000000 --- a/src/fr/inrialpes/exmo/align/onto/ConcreteOntology.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) INRIA Rhône-Alpes, 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; - -import java.net.URI; -import java.util.Iterator; -import org.xml.sax.SAXException; - -import org.semanticweb.owl.align.AlignmentException; - -/** - * Store the information regarding ontologies in a specific structure - */ - -public abstract class ConcreteOntology<O> extends BasicOntology<O> implements LoadedOntology<O> { - - public abstract Iterator<Object> getObjectProperties() throws AlignmentException; - public abstract Iterator<URI> getClassNames() throws AlignmentException; - public abstract Iterator<URI> getObjectPropertyNames() throws AlignmentException; - public abstract Iterator<URI> getDataPropertyNames() throws AlignmentException; - public abstract Iterator<URI> getInstanceNames() throws AlignmentException; - public abstract int nbClasses() throws AlignmentException; - public abstract int nbDataProperties() throws AlignmentException; - public abstract int nbObjectProperties() throws AlignmentException; - public abstract int nbInstances() throws AlignmentException; - public abstract Object getEntity( URI uri ) throws AlignmentException; - //public abstract void loadOntology( URI ref, OntologyCache ontologies ) throws SAXException, AlignmentException; -} diff --git a/src/fr/inrialpes/exmo/align/onto/Entity.java b/src/fr/inrialpes/exmo/align/onto/Entity.java deleted file mode 100644 index e97073244605847eac2150978843dc90fff2a657..0000000000000000000000000000000000000000 --- a/src/fr/inrialpes/exmo/align/onto/Entity.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) INRIA Rhône-Alpes, 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; - -import java.net.URI; -import java.util.Set; - -public interface Entity<E> { - public URI getURI(); - public Set<String> getLabels(String lang); - public Set<String> getComments(String lang); - public Ontology getOntology(); - public Set<String> getAnnotations(String lang); - public E getObject(); - -} diff --git a/src/fr/inrialpes/exmo/align/onto/EntityAdapter.java b/src/fr/inrialpes/exmo/align/onto/EntityAdapter.java deleted file mode 100644 index f622db37e89f4f6a9c5fdd9ec58a9903aa67f051..0000000000000000000000000000000000000000 --- a/src/fr/inrialpes/exmo/align/onto/EntityAdapter.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) INRIA Rhône-Alpes, 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; - -import java.net.URI; -import java.util.Collections; -import java.util.EnumMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -public abstract class EntityAdapter<E> implements Entity<E>{ - - protected E entity; - protected Ontology ontology; - protected URI uri; - - public static enum LANGUAGES { en, fr }; - public static enum TYPE {comment, label}; - protected Map<LANGUAGES,Set<String>> langToAnnot; - protected Map<TYPE,Set<String>> typeToAnnot; - protected Set<String> annotations; - - public EntityAdapter(E e, Ontology o, URI u, boolean init) { - entity = e; - ontology = o; - uri = u; - if (init) init(); - } - - protected EntityAdapter(boolean init) { - if (init) init(); - } - - protected void init() { - annotations = new HashSet<String>(); - langToAnnot = new EnumMap<LANGUAGES, Set<String>>(LANGUAGES.class); - typeToAnnot = new EnumMap<TYPE,Set<String>>(TYPE.class); - for (LANGUAGES lang : LANGUAGES.values()) - langToAnnot.put(lang, new HashSet<String>()); - for (TYPE type : TYPE.values()) - typeToAnnot.put(type, new HashSet<String>()); - } - - public Set<String> getAnnotations(){ - return annotations; - } - public Set<String> getTypeToAnnot( TYPE type ){ - return typeToAnnot.get( type ); - } - - public Set<String> getLangToAnnot( LANGUAGES lang ){ - return langToAnnot.get( lang ); - } - - public Set<String> getAnnotations(String lang, TYPE type) { - Set<String> annots; - if (lang == null && type == null) - return Collections.unmodifiableSet(annotations); - else if (lang == null) - return Collections.unmodifiableSet(typeToAnnot.get(type)); - else if (type == null) - return Collections.unmodifiableSet(langToAnnot.get(LANGUAGES.valueOf(lang))); - - annots= new HashSet<String>(langToAnnot.get(lang)); - annots.retainAll(typeToAnnot.get(type)); - return Collections.unmodifiableSet(annots); - } - - public Set<String> getAnnotations(String lang) { - return getAnnotations(lang,null); - } - - public Set<String> getComments(String lang) { - return getAnnotations(lang,TYPE.comment); - } - - public Set<String> getLabels(String lang) { - return getAnnotations(lang,TYPE.label); - } - - public E getObject() { - return entity; - } - - public Ontology getOntology() { - return ontology; - } - - public URI getURI() { - return uri; - } - - public String toString() { - return uri.toString(); - } - -} diff --git a/src/fr/inrialpes/exmo/align/onto/LoadedOntology.java b/src/fr/inrialpes/exmo/align/onto/LoadedOntology.java index 3ba72b05a30a1ca5959e79fddd1efe6e999da8c8..748a55bf5ce2624f18e3be8a3c30886c2204e7f3 100644 --- a/src/fr/inrialpes/exmo/align/onto/LoadedOntology.java +++ b/src/fr/inrialpes/exmo/align/onto/LoadedOntology.java @@ -23,12 +23,33 @@ package fr.inrialpes.exmo.align.onto; import java.net.URI; import java.util.Set; +import org.semanticweb.owl.align.AlignmentException; public interface LoadedOntology<O> extends Ontology<O> { - public Set<Entity> getEntities(); - public Set<Entity> getClasses(); - public Set<Entity> getProperties(); - public boolean contains(Entity e); + public Object getEntity( URI u ) throws AlignmentException; + + public URI getEntityURI( Object o ) throws AlignmentException; + public String getEntityName( Object o ) throws AlignmentException; + + public boolean isEntity( Object o ); + public boolean isClass( Object o ); + public boolean isProperty( Object o ); + public boolean isDatatypeProperty( Object o ); + public boolean isObjectProperty( Object o ); + public boolean isIndividual( Object o ); + + public Set<Object> getEntities(); + public Set<Object> getClasses(); + public Set<Object> getProperties(); + public Set<Object> getObjectProperties(); + public Set<Object> getDatatypeProperties(); + public Set<Object> getIndividuals(); + + public int nbClasses(); + public int nbDataProperties(); + public int nbObjectProperties(); + public int nbInstances(); + public void unload(); } diff --git a/src/fr/inrialpes/exmo/align/onto/OntologyAdapter.java b/src/fr/inrialpes/exmo/align/onto/OntologyAdapter.java deleted file mode 100644 index 700409d8a8c710b828ca9796d7ef08f0446933a3..0000000000000000000000000000000000000000 --- a/src/fr/inrialpes/exmo/align/onto/OntologyAdapter.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) INRIA Rhône-Alpes, 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; - - -import java.net.URI; -import java.util.Collections; -import java.util.HashSet; -import java.util.IdentityHashMap; -import java.util.Map; -import java.util.Set; - -public abstract class OntologyAdapter<O> extends ConcreteOntology<O> { - - protected O ontology; - protected URI uri; - - protected Set<Entity> classes; - protected Set<Entity> properties; - protected Set<Entity> entities; - public Set<Entity> individuals; - - protected OntologyAdapter() {} - - public OntologyAdapter(O ont, Set<Entity> c, Set<Entity> p, URI uri) { - ontology=ont; - classes = c; - properties = p; - entities = new HashSet<Entity>(c); - entities.addAll(p); - this.uri = uri; - } - - public boolean contains(Entity e) { - return classes.contains(e) || properties.contains(e); - } - - public Set<Entity> getClasses() { - return Collections.unmodifiableSet(classes); - } - - public Set<Entity> getEntities() { - return Collections.unmodifiableSet(entities); - } - - public O getOntology() { - return ontology; - } - - public void setOntology( O o ) { - ontology = o; - } - - public Set<Entity> getProperties() { - return Collections.unmodifiableSet(properties); - } - - public URI getURI() { - return uri; - } - - public String toString() { - return uri.toString(); - } - -} diff --git a/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntology.java b/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntology.java index 1ebaa4a79dc01573cde8a383990b8a4745ef951d..903478cc68ba7680b9522a63810765d36353753e 100644 --- a/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntology.java +++ b/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntology.java @@ -28,9 +28,8 @@ import java.lang.UnsupportedOperationException; import org.semanticweb.owl.align.AlignmentException; -import fr.inrialpes.exmo.align.onto.ConcreteOntology; import fr.inrialpes.exmo.align.onto.LoadedOntology; -import fr.inrialpes.exmo.align.onto.Entity; +import fr.inrialpes.exmo.align.onto.BasicOntology; import org.semanticweb.owl.model.OWLOntology; import org.semanticweb.owl.model.OWLProperty; @@ -51,7 +50,8 @@ import org.semanticweb.owl.model.OWLException; //} -public class OWLAPIOntology extends ConcreteOntology<OWLOntology> implements LoadedOntology<OWLOntology> { +public class OWLAPIOntology extends BasicOntology<OWLOntology> implements LoadedOntology<OWLOntology> { + public OWLAPIOntology() { setFormalism( "OWL1.0" ); try { @@ -63,35 +63,75 @@ public class OWLAPIOntology extends ConcreteOntology<OWLOntology> implements Loa public void setOntology( OWLOntology o ) { this.onto = o; } - // Here it shoud be better to report exception - // JE: Onto this does not work at all, of course... - public Set<Entity> getEntities() { + public Object getEntity( URI uri ) throws AlignmentException { try { - return (Set<Entity>)((OWLOntology)onto).getClasses(); // [W:unchecked] + OWLEntity result = ((OWLOntology)onto).getClass( uri ); + if ( result == null ) result = ((OWLOntology)onto).getDataProperty( uri ); + if ( result == null ) result = ((OWLOntology)onto).getObjectProperty( uri ); + if ( result == null ) result = ((OWLOntology)onto).getIndividual( uri ); + return result; } catch (OWLException ex) { - return null; + throw new AlignmentException( "Cannot dereference URI : "+uri ); + } + } + + public URI getEntityURI( Object o ) throws AlignmentException { + try { + return ((OWLEntity)o).getURI(); + } catch (OWLException oex) { + throw new AlignmentException( "Cannot get URI ", oex ); } } + public String getEntityName( Object o ) throws AlignmentException { + return "Dummt"; + }; + + public boolean isEntity( Object o ){ + if ( o instanceof OWLEntity ) return true; + else return false; + }; + public boolean isClass( Object o ){ + if ( o instanceof OWLClass ) return true; + else return false; + }; + public boolean isProperty( Object o ){ + if ( o instanceof OWLProperty ) return true; + else return false; + }; + public boolean isDatatypeProperty( Object o ){ + if ( o instanceof OWLDataProperty ) return true; + else return false; + }; + public boolean isObjectProperty( Object o ){ + if ( o instanceof OWLObjectProperty ) return true; + else return false; + }; + public boolean isIndividual( Object o ){ + if ( o instanceof OWLIndividual ) return true; + else return false; + }; - public Set<Entity> getClasses() { + // Here it shoud be better to report exception + // JE: Onto this does not work at all, of course...!!!! + public Set<Object> getEntities() { try { - return (Set<Entity>)((OWLOntology)onto).getClasses(); // [W:unchecked] + return ((OWLOntology)onto).getClasses(); // [W:unchecked] } catch (OWLException ex) { return null; } } - public Set<Entity> getProperties() { + public Set<Object> getClasses() { try { - return (Set<Entity>)((OWLOntology)onto).getClasses(); // [W:unchecked] + return ((OWLOntology)onto).getClasses(); // [W:unchecked] } catch (OWLException ex) { return null; } } - public Set<Entity> getIndividuals() { + public Set<Object> getProperties() { try { - return (Set<Entity>)((OWLOntology)onto).getIndividuals(); // [W:unchecked] + return ((OWLOntology)onto).getClasses(); // [W:unchecked] } catch (OWLException ex) { return null; } @@ -100,134 +140,71 @@ public class OWLAPIOntology extends ConcreteOntology<OWLOntology> implements Loa // The only point is if I should return OWLProperties or names... // I guess that I will return names (ns+name) because otherwise I will need a full // Abstract ontology interface and this is not the rule... - public Iterator<Object> getObjectProperties() throws AlignmentException { + public Set<Object> getObjectProperties() { try { // [Warning:unchecked] due to OWL API not serving generic types - return ((OWLOntology)onto).getObjectProperties().iterator(); // [W:unchecked] - } catch (OWLException ex) { - throw new AlignmentException( "Cannot get object properties", ex ); - } - } - - // JE: these are really specific methods I guess - public Iterator<URI> getObjectPropertyNames() throws AlignmentException { - try { - return new URIIterator(((OWLOntology)onto).getObjectProperties().iterator()); + return ((OWLOntology)onto).getObjectProperties(); // [W:unchecked] } catch (OWLException ex) { - throw new AlignmentException( "Cannot get object properties", ex ); - } - } - - public Iterator<URI> getDataPropertyNames() throws AlignmentException { - try { - return new URIIterator(((OWLOntology)onto).getDataProperties().iterator()); - } catch (OWLException ex) { - throw new AlignmentException( "Cannot get object properties", ex ); + //throw new AlignmentException( "Cannot get object properties", ex ); + return null; } } - public Iterator<URI> getClassNames() throws AlignmentException { + public Set<Object> getDatatypeProperties() { try { - return new URIIterator(((OWLOntology)onto).getClasses().iterator()); + // [Warning:unchecked] due to OWL API not serving generic types + return ((OWLOntology)onto).getDataProperties(); // [W:unchecked] } catch (OWLException ex) { - throw new AlignmentException( "Cannot get object properties", ex ); + //throw new AlignmentException( "Cannot get object properties", ex ); + return null; } } - public Iterator<URI> getInstanceNames() throws AlignmentException { + public Set<Object> getIndividuals() { try { - return new URIIterator(((OWLOntology)onto).getIndividuals().iterator()); + return ((OWLOntology)onto).getIndividuals(); // [W:unchecked] } catch (OWLException ex) { - throw new AlignmentException( "Cannot get object properties", ex ); + return null; } } - public int nbClasses() throws AlignmentException { + // JE: particularly inefficient + public int nbClasses() { try { return ((OWLOntology)onto).getClasses().size(); - } catch (OWLException ex) { - throw new AlignmentException( "Cannot get class number" ); + } catch (OWLException oex) { + return 0; } } - public int nbObjectProperties() throws AlignmentException { + public int nbObjectProperties() { try { return ((OWLOntology)onto).getObjectProperties().size(); - } catch (OWLException ex) { - throw new AlignmentException( "Cannot get object property number" ); + } catch (OWLException oex) { + return 0; } } - public int nbDataProperties() throws AlignmentException { + public int nbDataProperties() { try { return ((OWLOntology)onto).getDataProperties().size(); - } catch (OWLException ex) { - throw new AlignmentException( "Cannot get data property number" ); + } catch (OWLException oex) { + return 0; } } - public int nbInstances() throws AlignmentException { + public int nbInstances() { try { return ((OWLOntology)onto).getIndividuals().size(); - } catch (OWLException ex) { - throw new AlignmentException( "Cannot get individual number" ); + } catch (OWLException oex) { + return 0; } } - public boolean contains(Entity e) { - if ( e instanceof OWLEntity ){ - if ( e instanceof OWLClass ) { - for ( Object o : getClasses() ){ - if ( o == e ) return true; - } - } else if ( e instanceof OWLDataProperty ) { - for ( Object o : getProperties() ){ - if ( o == e ) return true; - } - } else if ( e instanceof OWLIndividual ) { - for ( Object o : getIndividuals() ){ - if ( o == e ) return true; - } - } - }; - return false; - } - public void unload() { try { ((OWLOntology)onto).getOWLConnection().notifyOntologyDeleted( ((OWLOntology)onto) ); } catch (OWLException ex) { System.err.println(ex); }; } - public Object getEntity( URI uri ) throws AlignmentException { - try { - OWLEntity result = ((OWLOntology)onto).getClass( uri ); - if ( result == null ) result = ((OWLOntology)onto).getDataProperty( uri ); - if ( result == null ) result = ((OWLOntology)onto).getObjectProperty( uri ); - if ( result == null ) result = ((OWLOntology)onto).getIndividual( uri ); - return result; - } catch (OWLException ex) { - throw new AlignmentException( "Cannot dereference URI : "+uri ); - } - } - -} - -final class URIIterator implements Iterator<URI> { - private Iterator it = null; - - public URIIterator ( Iterator i ){ - it = i; - } - public boolean hasNext() { return it.hasNext(); } - public URI next() throws NoSuchElementException { - try{ - return ((OWLEntity)it.next()).getURI(); - } catch (OWLException ex) { - throw new NoSuchElementException(ex.toString()); // cannot encapsulate! - } - } - public void remove() throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } }