diff --git a/lib/owlapi1/api.jar b/lib/owlapi1/api.jar deleted file mode 100644 index 9ab29858a206d3163f591e86b91eaad221786df1..0000000000000000000000000000000000000000 Binary files a/lib/owlapi1/api.jar and /dev/null differ diff --git a/lib/owlapi1/impl.jar b/lib/owlapi1/impl.jar deleted file mode 100644 index cbdd34c82727d1ecd0088ce89af7a7ebf494dc23..0000000000000000000000000000000000000000 Binary files a/lib/owlapi1/impl.jar and /dev/null differ diff --git a/lib/owlapi1/io.jar b/lib/owlapi1/io.jar deleted file mode 100644 index 4d57e6c1da69761c2f052e3a745eea254d755bd1..0000000000000000000000000000000000000000 Binary files a/lib/owlapi1/io.jar and /dev/null differ diff --git a/lib/owlapi1/rdfapi.jar b/lib/owlapi1/rdfapi.jar deleted file mode 100644 index 5499252ac2499e6c20ed89a6e32f294eecc6ef35..0000000000000000000000000000000000000000 Binary files a/lib/owlapi1/rdfapi.jar and /dev/null differ diff --git a/lib/owlapi1/rdfparser.jar b/lib/owlapi1/rdfparser.jar deleted file mode 100644 index e967dd537c59dce44639026a8f4a10a2c9a4da83..0000000000000000000000000000000000000000 Binary files a/lib/owlapi1/rdfparser.jar and /dev/null differ diff --git a/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIAnnotIt.java b/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIAnnotIt.java deleted file mode 100644 index ad0dc82502f126159a463ac7495efa586e04c3ce..0000000000000000000000000000000000000000 --- a/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIAnnotIt.java +++ /dev/null @@ -1,77 +0,0 @@ -package fr.inrialpes.exmo.align.onto.owlapi10; - -import java.util.Iterator; -import java.util.NoSuchElementException; - - -import org.semanticweb.owl.model.OWLAnnotationInstance; -import org.semanticweb.owl.model.OWLDataValue; -import org.semanticweb.owl.model.OWLEntity; -import org.semanticweb.owl.model.OWLException; -import org.semanticweb.owl.model.OWLOntology; - - -/** - * An iterator over annotations of an OWLEntity. This class permits to avoid the instantiation of HashSet for - * each call of a getAnnotation method. - * @author JD - * - */ -public class OWLAPIAnnotIt implements Iterator<String> { - - /*private OWLOntology o; - private OWLEntity e;*/ - private String lang; - private String typeAnnot; - - private Iterator it; - - private String currentElem=null; - - public OWLAPIAnnotIt(OWLOntology o, OWLEntity e , String lang , String typeAnnot) throws OWLException { - /*this.o=o; this.e=e; */ this.lang=lang; this.typeAnnot=typeAnnot; - it = e.getAnnotations(o).iterator(); - } - - public boolean hasNext() { - try { - setNext(); - return currentElem != null; - } - catch (NoSuchElementException e) { - return false; - } - } - - public String next() { - setNext(); - String returnVal = currentElem; - currentElem=null; - return returnVal; - } - - private void setNext() throws NoSuchElementException { - while (currentElem==null) { - OWLAnnotationInstance annot = (OWLAnnotationInstance) it.next(); - try { - String annotUri = annot.getProperty().getURI().toString(); - if (annotUri.equals(typeAnnot) || typeAnnot==null) { - if ( annot.getContent() instanceof OWLDataValue && - ( lang==null || ((OWLDataValue) annot.getContent()).getLang().equals(lang)) ) { - currentElem = ((OWLDataValue) annot.getContent()).getValue().toString(); - } - } - } catch (OWLException e) { - e.printStackTrace(); - currentElem=null; - } - } - - } - - public void remove() { - throw new UnsupportedOperationException(); - } - - } - diff --git a/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntology.java b/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntology.java deleted file mode 100644 index 8eee9c6ac81fcbf0ee1774be42c11bcaf2dc2f0d..0000000000000000000000000000000000000000 --- a/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntology.java +++ /dev/null @@ -1,578 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) INRIA, 2007-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 - */ - -/* - * This should be turned into an HeavyLoadedOntology. - * Some primitives are already avalible below - * - * The point is that these primitives may concern: - * - Named entities / All entities - * - Asserted information / Deduced information - * - Inherited information... () - * In fact the OWL API does only provide asserted. - * - * This is not very well implemented: the OWL API mandates to implement this as visitors... - */ - -package fr.inrialpes.exmo.align.onto.owlapi10; - -import java.net.URI; -import java.util.AbstractSet; -import java.util.Iterator; -import java.util.Set; -import java.util.HashSet; - -import org.semanticweb.owl.align.AlignmentException; - -import fr.inrialpes.exmo.align.onto.OntologyFactory; -import fr.inrialpes.exmo.align.onto.HeavyLoadedOntology; -import fr.inrialpes.exmo.align.onto.BasicOntology; - -import org.semanticweb.owl.io.vocabulary.RDFSVocabularyAdapter; -import org.semanticweb.owl.model.OWLAnnotationInstance; -import org.semanticweb.owl.model.OWLDataType; -import org.semanticweb.owl.model.OWLDataValue; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLProperty; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLObjectProperty; -import org.semanticweb.owl.model.OWLDataProperty; -import org.semanticweb.owl.model.OWLIndividual; -import org.semanticweb.owl.model.OWLEntity; -import org.semanticweb.owl.model.OWLRestriction; -import org.semanticweb.owl.model.OWLDescription; -import org.semanticweb.owl.model.OWLNaryBooleanDescription; -import org.semanticweb.owl.model.OWLCardinalityRestriction; -import org.semanticweb.owl.model.OWLDataAllRestriction; -import org.semanticweb.owl.model.OWLObjectAllRestriction; -import org.semanticweb.owl.model.OWLException; -import org.semanticweb.owl.model.helper.OWLEntityCollector; - -/** - * Store the information regarding ontologies in a specific structure - * Acts as an interface with regard to an ontology APY - */ - -public class OWLAPIOntology extends BasicOntology<OWLOntology> implements HeavyLoadedOntology<OWLOntology> { - - /* For caching sizes */ - private int nbentities = -1; - private int nbclasses = -1; - private int nbproperties = -1; - private int nbobjectproperties = -1; - private int nbdataproperties = -1; - private int nbindividuals = -1; - - public OWLAPIOntology() { - setFormalism( "OWL1.0" ); - try { - setFormURI( new URI("http://www.w3.org/2002/07/owl#") ); - } catch (Exception e) {}; // does not happen - }; - - // ----------------------------------------------------------------- - // Ontology interface [//DONE] - - public OWLOntology getOntology() { return onto; } - - public void setOntology( OWLOntology o ) { this.onto = o; } - - // ----------------------------------------------------------------- - // LoadedOntology interface [//DONE] - - 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 ); - } - } - - 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 { - try { - // Try to get labels first... - URI u = ((OWLEntity)o).getURI(); - if ( u != null ) return u.getFragment(); - else return ""; - } catch (OWLException oex) { - return null; - } - }; - - public Set<String> getEntityNames( Object o , String lang ) throws AlignmentException { - try { - OWLEntity e = ((OWLEntity) o); - return getAnnotations(e,lang,RDFSVocabularyAdapter.INSTANCE.getLabel()); - } catch (OWLException oex) { - return null; - } - } - public Set<String> getEntityNames( Object o ) throws AlignmentException { - try { - OWLEntity e = ((OWLEntity) o); - return getAnnotations(e,null,RDFSVocabularyAdapter.INSTANCE.getLabel()); - } catch (OWLException oex) { - return null; - } - }; - - - public Set<String> getEntityComments( Object o , String lang ) throws AlignmentException { - try { - OWLEntity e = ((OWLEntity) o); - return getAnnotations(e,lang,RDFSVocabularyAdapter.INSTANCE.getComment()); - } catch (OWLException oex) { - return null; - } - }; - - public Set<String> getEntityComments( Object o ) throws AlignmentException { - try { - OWLEntity e = ((OWLEntity) o); - return getAnnotations(e,null,RDFSVocabularyAdapter.INSTANCE.getComment()); - } catch (OWLException oex) { - return null; - } - }; - - protected Set<String> getAnnotations(final OWLEntity e , final String lang , final String typeAnnot ) throws OWLException { - final OWLOntology o = this.onto; - return new AbstractSet<String>() { - int size=-1; - public Iterator<String> iterator() { - try { - return new OWLAPIAnnotIt(o,e,lang,typeAnnot); - } catch (OWLException e) { - e.printStackTrace(); - return null; - } - } - public int size() { - if (size==-1) { - for (String s : this) { - size++; - } - size++; - } - return size; - } - - }; - // OLD IMPLEMENTATION - /*Set<String> annots = new HashSet<String>(); - for (Object objAnnot : e.getAnnotations(onto)) { - OWLAnnotationInstance annot = (OWLAnnotationInstance) objAnnot; - String annotUri = annot.getProperty().getURI().toString(); - if (annotUri.equals(typeAnnot) || typeAnnot==null) { - if ( annot.getContent() instanceof OWLDataValue && - ( lang==null || ((OWLDataValue) annot.getContent()).getLang().equals(lang)) ) { - annots.add(((OWLDataValue) annot.getContent()).getValue().toString()); - } - } - } - return annots;*/ - } - - public Set<String> getEntityAnnotations( Object o ) throws AlignmentException { - try { - return getAnnotations(((OWLEntity) o),null,null); - } catch (OWLException oex) { - return null; - } - }; - - public boolean isEntity( Object o ){ - return ( o instanceof OWLEntity ); - }; - public boolean isClass( Object o ){ - return ( o instanceof OWLClass ); - }; - public boolean isProperty( Object o ){ - return ( o instanceof OWLProperty ); - }; - public boolean isDataProperty( Object o ){ - return ( o instanceof OWLDataProperty ); - }; - public boolean isObjectProperty( Object o ){ - return ( o instanceof OWLObjectProperty ); - }; - public boolean isIndividual( Object o ){ - return ( o instanceof OWLIndividual ); - }; - - // ***JE: - // We should solve this issue, is it better to go this way or tu use the OWL API? - // JD: allows to retrieve some specific entities by giving their class - // This is not part of the interface... - protected Set<?> getEntities(Class<? extends OWLEntity> c) throws OWLException{ - OWLEntityCollector ec = new OWLEntityCollector(); - onto.accept(ec); - Set<Object> entities = new HashSet<Object>(); - for (Object obj : ec.entities()) { - // JD: OWLEntitytCollector seems to return anonymous entities :&& ((OWLEntity)obj).getURI()!=null - if (c.isInstance(obj) && ((OWLEntity) obj).getURI()!=null) { // &&((OWLEntity) obj).getURI().toString().startsWith(onto.getURI().toString()) ){ - entities.add(obj); - } - } - return entities; - } - - // Here it shoud be better to report exception - // JE: Onto this does not work at all, of course...!!!! - public Set<?> getEntities() { - try { - return getEntities(OWLEntity.class); - } catch (OWLException ex) { - return null; - } - } - - public Set<?> getClasses() { - try { - return ((OWLOntology)onto).getClasses(); // [W:unchecked] - //return getEntities(OWLClass.class); - } catch (OWLException ex) { - return null; - } - } - - public Set<?> getProperties() { - try { - //return ((OWLOntology)onto).getProperties(); // [W:unchecked] - return getEntities(OWLProperty.class); - } catch (OWLException ex) { - return null; - } - } - - public Set<?> getDataProperties() { - try { - // This first method returns also Properties not defined in the Onto - // i.e. properties having an namespace different from the ontology uri - return ((OWLOntology)onto).getDataProperties(); // [W:unchecked] - //return getEntities(OWLDataProperty.class); - } catch (OWLException ex) { - return null; - } - } - - public Set<?> getObjectProperties() { - try { - // [Warning:unchecked] due to OWL API not serving generic types - // This first method returns also Properties not defined in the Onto - // i.e. properties having an namespace different from the ontology uri - return ((OWLOntology)onto).getObjectProperties(); // [W:unchecked] - // This method works better (??) - //return getEntities(OWLObjectProperty.class); - } catch (OWLException ex) { - return null; - } - } - - public Set<?> getIndividuals() { - try { - return ((OWLOntology)onto).getIndividuals(); // [W:unchecked] - //return getEntities(OWLIndividual.class); - } catch (OWLException ex) { - return null; - } - } - - public int nbEntities() { - if ( nbentities != -1 ) return nbentities; - nbentities = nbClasses()+nbProperties()+nbIndividuals(); - return nbentities; - } - - public int nbClasses() { - if ( nbclasses != -1 ) return nbclasses; - try { - nbclasses = ((OWLOntology)onto).getClasses().size(); - return nbclasses; - } catch (OWLException oex) { - return 0; - } - } - - public int nbProperties() { - if ( nbproperties != -1 ) return nbproperties; - nbproperties = nbObjectProperties()+nbDataProperties(); - return nbproperties; - } - - public int nbObjectProperties() { - if ( nbobjectproperties != -1 ) return nbobjectproperties; - try { - nbobjectproperties = ((OWLOntology)onto).getObjectProperties().size(); - return nbobjectproperties; - } catch (OWLException oex) { - return 0; - } - } - - public int nbDataProperties() { - if ( nbdataproperties != -1 ) return nbdataproperties; - try { - nbdataproperties = ((OWLOntology)onto).getDataProperties().size(); - return nbdataproperties; - } catch (OWLException oex) { - return 0; - } - } - - public int nbIndividuals() { - if ( nbindividuals != -1 ) return nbindividuals; - try { - nbindividuals = ((OWLOntology)onto).getIndividuals().size(); - return nbindividuals; - } catch (OWLException oex) { - return 0; - } - } - - public void unload() { - try { - ((OWLOntology)onto).getOWLConnection().notifyOntologyDeleted( ((OWLOntology)onto) ); - } catch (OWLException ex) { System.err.println(ex); }; - } - - // ----------------------------------------------------------------- - // HeavyLoadedOntology interface [//TOCHECK] - - // [//TODO] - public boolean getCapabilities( int Direct, int Asserted, int Named ){ - return true; - } - - // Pretty inefficient but nothing seems to be stored - public Set<Object> getSubClasses( Object cl, int local, int asserted, int named ){ - Set<Object> sbcl = new HashSet<Object>(); - for( Object c : getClasses() ) { - if ( getSuperClasses( (OWLClass)c, local, asserted, named ).contains( cl ) ) sbcl.add( c ); - } - return sbcl; - } - public Set<Object> getSuperClasses( Object cl, int local, int asserted, int named ){ - Set<Object> spcl = new HashSet<Object>(); - if ( asserted == OntologyFactory.ASSERTED ){ - try { - for( Object rest : ((OWLClass)cl).getSuperClasses( getOntology() ) ){ - if (rest instanceof OWLClass) spcl.add( rest ); - } - } catch (OWLException ex) { - } - } else { - try { - // JE: I do not feel that this is really correct - Set<Object> sup = new HashSet<Object>(); - for( Object rest : ((OWLClass)cl).getSuperClasses( getOntology() ) ){ - if (rest instanceof OWLClass) { - spcl.add( rest ); - sup.add( rest ); - } - } - } catch (OWLException ex) { - }; - } - return spcl; - } - - /* - * In the OWL API, there is no properties: there are SuperClasses which are restrictions - */ - public Set<Object> getProperties( Object cl, int local, int asserted, int named ){ - Set<Object> prop = new HashSet<Object>(); - if ( asserted == OntologyFactory.ASSERTED && local == OntologyFactory.LOCAL ) { - try { - for ( Object ent : ((OWLClass)cl).getSuperClasses( getOntology() ) ){ - if ( ent instanceof OWLRestriction ) - prop.add( ((OWLRestriction)ent).getProperty() ); - } - } catch (OWLException e) { e.printStackTrace(); } - } else { - prop = getInheritedProperties( (OWLClass)cl ); - } - return prop; - } - // Not very efficient: 2n instead of n - public Set<Object> getDataProperties( Object c, int local, int asserted, int named ){ - Set<Object> props = new HashSet<Object>(); - for ( Object p : getProperties( c, local, asserted, named ) ){ - if ( p instanceof OWLDataProperty ) props.add( p ); - } - return props; - } - // Not very efficient: 2n instead of n - public Set<Object> getObjectProperties( Object c, int local, int asserted, int named ){ - Set<Object> props = new HashSet<Object>(); - for ( Object p : getProperties( c, local, asserted, named ) ){ - if ( p instanceof OWLObjectProperty ) props.add( p ); - } - return props; - } - // Pretty inefficient but nothing seems to be stored - public Set<Object> getInstances( Object cl, int local, int asserted, int named ){ - Set<Object> sbcl = new HashSet<Object>(); - try { - for( Object i : getIndividuals() ) { - //if ( getClasses( (OWLIndividual)i, local, asserted, named ).contains( cl ) ) sbcl.add( i ); - if ( ((OWLIndividual)i).getTypes( getOntology() ).contains( cl ) ) sbcl.add( i ); - } - } catch (OWLException ex) {}; - return sbcl; - } - // Pretty inefficient but nothing seems to be stored - public Set<Object> getSubProperties( Object pr, int local, int asserted, int named ){ - Set<Object> sbpr = new HashSet<Object>(); - for( Object p : getProperties() ) { - if ( getSuperProperties( (OWLProperty)p, local, asserted, named ).contains( pr ) ) sbpr.add( p ); - } - return sbpr; - } - public Set<Object> getSuperProperties( Object pr, int local, int asserted, int named ){ - Set<Object> supers = new HashSet<Object>(); - if ( asserted == OntologyFactory.ASSERTED ){ - try { - for( Object rest : ((OWLProperty)pr).getSuperProperties( getOntology() ) ){ - if (rest instanceof OWLProperty) supers.add( rest ); - } - } catch (OWLException ex) { - } - } else { - try { - Set<Object> sup = new HashSet<Object>(); - for( Object rest : ((OWLProperty)pr).getSuperProperties( getOntology() ) ){ - if (rest instanceof OWLProperty) { - sup.add( rest ); - supers.add( rest ); - } - } - } catch (OWLException ex) { - }; - } - return supers; - } - public Set<Object> getRange( Object p, int asserted ){ - Set resultSet = new HashSet(); - try { - for ( Object ent : ((OWLProperty)p).getRanges( getOntology() ) ){ - // Not correct - // Could be something else than class - if ( ent instanceof OWLClass || ent instanceof OWLDataType ) { - resultSet.add( ent ); - } - } - } catch (OWLException ex) {}; - return resultSet; - } - public Set<Object> getDomain( Object p, int asserted ){ - Set resultSet = new HashSet(); - try { - for ( Object ent : ((OWLProperty)p).getDomains( getOntology() ) ){ - // Not correct - // Could be something else than class - if ( ent instanceof OWLClass ) { - resultSet.add( ent ); - } - } - } catch (OWLException ex) {}; - return resultSet; - } - public Set<Object> getClasses( Object i, int local, int asserted, int named ){ - Set<Object> supers = null; - try { - supers = ((OWLIndividual)i).getTypes( getOntology() ); - } catch (OWLException ex) {}; - if ( local == OntologyFactory.LOCAL ) { - return supers; - } else { - // inherits the superclasses (unless we have to reduce them...) - return supers; - } - } - - // JE: note this may be wrong if p is a property - public Set<Object> getCardinalityRestrictions( Object p ){//JFDK - Set<Object> spcl = new HashSet<Object>(); - try { - Set<Object> sup = ((OWLClass)p).getSuperClasses( getOntology() ); - for( Object rest : sup ){ - // This should be filtered - if (rest instanceof OWLCardinalityRestriction) spcl.add( rest ); - } - } catch (OWLException ex) { - }; - return spcl; - } - - /* - * Inherits all properties of a class - */ - private Set<Object> getInheritedProperties( OWLClass cl ) { - Set resultSet = new HashSet(); - try { getProperties( cl, resultSet ); } - catch (OWLException ex) {}; - return resultSet; - } - - /* This traverse properties */ - public void getProperties( OWLDescription desc, Set<Object> list) throws OWLException { - if ( desc instanceof OWLRestriction ){ - //getProperties( (OWLRestriction)desc, list ); - list.add( ((OWLRestriction)desc).getProperty() ); - } else if ( desc instanceof OWLClass ) { - getProperties( (OWLClass)desc, list ); - } else if ( desc instanceof OWLNaryBooleanDescription ) { - for ( Object d : ((OWLNaryBooleanDescription)desc).getOperands() ){ - getProperties( (OWLDescription)d, list ); - } - //getProperties( (OWLNaryBooleanDescription)desc, list ); - } - } - public void getProperties( OWLRestriction rest, Set<Object> list) throws OWLException { - list.add( (Object)rest.getProperty() ); - } - public void getProperties( OWLNaryBooleanDescription d, Set<Object> list) throws OWLException { - for ( Iterator it = d.getOperands().iterator(); it.hasNext() ;){ - getProperties( (OWLDescription)it.next(), list ); - } - } - public void getProperties( OWLClass cl, Set<Object> list) throws OWLException { - for ( Object desc : cl.getSuperClasses( getOntology() ) ){ - getProperties( (OWLDescription)desc, list ); - } - // JE: I suspect that this can be a cause for looping!! - for ( Object desc : cl.getEquivalentClasses( getOntology() ) ){ - getProperties( (OWLDescription)desc, list ); - } - } - -} diff --git a/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntologyFactory.java b/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntologyFactory.java deleted file mode 100644 index 0daf0cb067428875e3023b6ae01f098694e58598..0000000000000000000000000000000000000000 --- a/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntologyFactory.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * $Id$ - * - * 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 - * 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.owlapi10; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.apache.log4j.Logger; -import org.apache.log4j.Level; - -import org.semanticweb.owl.align.AlignmentException; - -import fr.inrialpes.exmo.align.onto.OntologyCache; -import fr.inrialpes.exmo.align.onto.OntologyFactory; -import fr.inrialpes.exmo.align.onto.Ontology; -import fr.inrialpes.exmo.align.onto.LoadedOntology; - -import org.semanticweb.owl.model.OWLException; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.util.OWLConnection; -import org.semanticweb.owl.util.OWLManager; - -public class OWLAPIOntologyFactory extends OntologyFactory { - - private static URI formalismUri = null; - private static String formalismId = "OWL1.0"; - private static OntologyCache<OWLAPIOntology> cache = null; - - public OWLAPIOntologyFactory() { - cache = new OntologyCache<OWLAPIOntology>(); - try { - formalismUri = new URI("http://www.w3.org/2002/07/owl#"); - } catch (URISyntaxException ex) { ex.printStackTrace(); } // should not happen - }; - - public void clearCache() { - 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 ); - if ( onto != null ) return onto; - onto = cache.getOntology( uri ); - if ( onto != null ) return onto; - OWLConnection connection = null; - Map<Object,Object> parameters = new HashMap<Object, Object>(); - parameters.put(OWLManager.OWL_CONNECTION, - "org.semanticweb.owl.impl.model.OWLConnectionImpl"); - try { - connection = OWLManager.getOWLConnection(parameters); - Level lev = Logger.getLogger("org.semanticweb.owl").getLevel(); - Logger.getLogger("org.semanticweb.owl").setLevel(Level.ERROR); - OWLOntology ontology = connection.loadOntologyPhysical(uri); - Logger.getLogger("org.semanticweb.owl").setLevel(lev); - onto = new OWLAPIOntology(); - // It may be possible to fill this as final in OWLAPIOntology... - onto.setFormalism( formalismId ); - onto.setFormURI( formalismUri ); - onto.setOntology( ontology ); - onto.setFile( uri ); - try { - onto.setURI( ontology.getLogicalURI() ); - } catch (OWLException e) { - // Better put in the AlignmentException of loaded - e.printStackTrace(); - } - cache.recordOntology( uri, onto ); - return onto; - } catch (OWLException e) { - throw new AlignmentException("Cannot load "+uri, e ); - } - } -} - diff --git a/test/src/OWLAPIAlignmentTest.java b/test/src/OWLAPIAlignmentTest.java deleted file mode 100644 index 056986209e29f3cf5b1ac00d815a419e6b3b7ecc..0000000000000000000000000000000000000000 --- a/test/src/OWLAPIAlignmentTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * $Id$ - * - * 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 - * 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 test.com.acme.dona.dep; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Configuration; -import org.testng.annotations.Test; -//import org.testng.annotations.*; - -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLEntity; - -import org.semanticweb.owl.align.AlignmentVisitor; -import org.semanticweb.owl.align.Cell; - -import fr.inrialpes.exmo.align.impl.OWLAPIAlignment; -import fr.inrialpes.exmo.align.impl.OWLAPICell; -import fr.inrialpes.exmo.align.impl.rel.EquivRelation; -import fr.inrialpes.exmo.align.impl.URIAlignment; -import fr.inrialpes.exmo.align.impl.Annotations; -import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor; -import fr.inrialpes.exmo.align.onto.LoadedOntology; -import fr.inrialpes.exmo.align.onto.Ontology; -import fr.inrialpes.exmo.align.parser.AlignmentParser; - -import java.io.ByteArrayOutputStream; -import java.io.PrintWriter; -import java.io.BufferedWriter; -import java.io.OutputStreamWriter; -import java.io.FileOutputStream; -import java.net.URI; -import java.util.Set; - -public class OWLAPIAlignmentTest { - - private String localURIPrefix = "file://" + System.getProperty("user.dir"); - - private OWLAPIAlignment alignment = null; - private Ontology onto1 = null; - private Ontology onto2 = null; - - @BeforeClass(groups = { "full", "noling" }) - private void init(){ - alignment = new OWLAPIAlignment(); - } - - @Test(groups = { "full", "noling" }) - public void loadingAndConvertingTest() throws Exception { - assertNotNull( alignment, "Alignment was null" ); - AlignmentParser aparser = new AlignmentParser( 0 ); - assertNotNull( aparser, "AlignmentParser was null" ); - URIAlignment result = (URIAlignment)aparser.parse( "file:examples/rdf/newsample.rdf" ); - assertNotNull( result, "URIAlignment(result) was null" ); - alignment = OWLAPIAlignment.toOWLAPIAlignment( result ); - assertNotNull( alignment, "toOWLAPIAlignment(result) was null" ); - result = alignment.toURIAlignment(); - assertNotNull( result, "toURIAlignment() was null" ); - assertTrue( result instanceof URIAlignment ); - } - - @Test(groups = { "full", "noling" }, dependsOnMethods = {"loadingAndConvertingTest"}) - public void basicAttributeTest() throws Exception { - assertEquals( alignment.getLevel(), "0" ); - assertEquals( alignment.getType(), "**" ); - assertEquals( alignment.getExtension( Annotations.ALIGNNS, Annotations.METHOD), "fr.inrialpes.exmo.align.impl.method.StringDistAlignment" ); - assertEquals( alignment.getExtension( Annotations.ALIGNNS, Annotations.TIME), "7" ); - } - - @Test(groups = { "full", "noling" }, dependsOnMethods = {"loadingAndConvertingTest"}) - public void ontologyTest() throws Exception { - onto1 = alignment.getOntologyObject1(); - onto2 = alignment.getOntologyObject2(); - assertTrue( onto1 instanceof LoadedOntology ); - assertTrue( onto2 instanceof LoadedOntology ); - assertTrue( alignment.getOntology1() instanceof OWLOntology ); - assertTrue( alignment.getOntology2() instanceof OWLOntology ); - assertEquals( alignment.getOntology1URI().toString(), "http://www.example.org/ontology1" ); - assertEquals( alignment.getOntology2URI().toString(), "http://www.example.org/ontology2" ); - assertEquals( onto1.getURI().toString(), "http://www.example.org/ontology1" ); - assertEquals( onto2.getURI().toString(), "http://www.example.org/ontology2" ); - assertEquals( onto1.getFile().toString(), "file:examples/rdf/onto1.owl" ); - assertEquals( onto2.getFile().toString(), "file:examples/rdf/onto2.owl" ); - assertEquals( onto1.getFormalism(), "OWL1.0" ); - assertEquals( onto2.getFormalism(), "OWL1.0" ); - assertEquals( onto1.getFormURI().toString(), "http://www.w3.org/2002/07/owl#" ); - assertEquals( onto2.getFormURI().toString(), "http://www.w3.org/2002/07/owl#" ); - } - - @Test(groups = { "full", "noling" }, dependsOnMethods = {"ontologyTest"}) - public void basicCellTest() throws Exception { - assertEquals( alignment.nbCells(), 2 ); - Object ob2 = ((LoadedOntology)onto2).getEntity( new URI("http://www.example.org/ontology2#journalarticle") ); - assertTrue( ob2 instanceof OWLEntity ); - Set<Cell> s2 = alignment.getAlignCells2( ob2 ); - assertEquals( s2.size(), 2 ); - for( Cell c2 : s2 ){ - assertTrue( c2 instanceof OWLAPICell ); - assertTrue( c2.getRelation() instanceof EquivRelation ); - assertTrue( c2.getObject1() instanceof OWLEntity ); - } - Object ob1 = ((LoadedOntology)onto1).getEntity( new URI("http://www.example.org/ontology1#journalarticle") ); - assertTrue( ob1 instanceof OWLEntity ); - Set<Cell> s1 = alignment.getAlignCells1( ob1 ); - assertEquals( s1.size(), 1 ); - for( Cell c1 : s1 ){ - assertTrue( c1 instanceof OWLAPICell ); - assertTrue( c1.getRelation() instanceof EquivRelation ); - assertEquals( c1.getStrength(), 1. ); - assertTrue( c1.getObject2() instanceof OWLEntity ); - assertEquals( ((LoadedOntology)onto2).getEntityURI( c1.getObject2() ).toString(), "http://www.example.org/ontology2#journalarticle" ); - } - ob1 = ((LoadedOntology)onto1).getEntity( new URI("http://www.example.org/ontology1#reviewedarticle") ); - assertTrue( ob1 instanceof OWLEntity ); - s1 = alignment.getAlignCells1( ob1 ); - assertEquals( s1.size(), 1 ); - for( Cell c1 : s1 ){ - assertTrue( c1 instanceof OWLAPICell ); - assertTrue( c1.getRelation() instanceof EquivRelation ); - assertEquals( c1.getStrength(), .4666666666666667 ); - assertTrue( c1.getObject2() instanceof OWLEntity ); - assertEquals( ((LoadedOntology)onto2).getEntityURI( c1.getObject2() ).toString(), "http://www.example.org/ontology2#journalarticle" ); - } - } - - @Test(groups = { "full", "noling" }, dependsOnMethods = {"loadingAndConvertingTest"}) - public void rendererTest() throws Exception { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - //FileOutputStream stream = new FileOutputStream("result.rdf"); - PrintWriter writer = new PrintWriter ( - new BufferedWriter( - new OutputStreamWriter( stream, "UTF-8" )), true); - - AlignmentVisitor renderer = new RDFRendererVisitor( writer ); - alignment.render( renderer ); - writer.flush(); - writer.close(); - assertEquals( stream.toString().length(), 1706, "Rendered differently" ); - } - -}