diff --git a/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java b/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java index 0f7c914f9f914c7709aba14ae6af93a7912c7b67..da6e01178ec8af3627783182ef4648744fc46be3 100644 --- a/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java @@ -18,11 +18,17 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +//Raph: are things to change for dealing with multiple cell +// for one objects + package fr.inrialpes.exmo.align.impl; import java.lang.ClassNotFoundException; import java.util.Hashtable; +//Raph: +import java.util.HashSet; import java.util.Enumeration; +import java.util.Iterator; import java.util.Collections; import java.util.List; import java.util.ArrayList; @@ -96,6 +102,7 @@ public class BasicAlignment implements Alignment { } public int nbCells() { + // Raph: this is now wrong: I need multi-enumeration return hash1.size(); } @@ -109,22 +116,16 @@ public class BasicAlignment implements Alignment { }; public void setOntology1(Object ontology) throws AlignmentException { - try { - if (!Class.forName("org.semanticweb.owl.model.OWLOntology").isInstance(ontology)) - throw new AlignmentException("setOntollogy1: arguments must be OWLEntities"); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } + throw new AlignmentException("setOntollogy1: arguments must be OWLEntities"); + }; + public void setOntology1(OWLOntology ontology) throws AlignmentException { onto1 = (OWLOntology) ontology; }; public void setOntology2(Object ontology) throws AlignmentException { - try { - if (!Class.forName("org.semanticweb.owl.model.OWLOntology").isInstance(ontology)) - throw new AlignmentException("setOntollogy2: arguments must be OWLEntities"); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } + throw new AlignmentException("setOntollogy2: arguments must be OWLEntities"); + }; + public void setOntology2(OWLOntology ontology) throws AlignmentException { onto2 = (OWLOntology) ontology; }; @@ -144,11 +145,15 @@ public class BasicAlignment implements Alignment { public void setFile2(URI u) { uri2 = u; }; - public Enumeration getElements() { return hash1.elements(); } + public Enumeration getElements() { + //Raph: This should be a multi Enumeration: + return hash1.elements(); + } /* * Please note that all the following methods must be changed because they * consider that only ONE Entity can be aligned with another !! + * A number of modifications are considered in the //Raph: */ /** Cell methods * */ public Cell addAlignCell(Object ob1, Object ob2, String relation, @@ -161,8 +166,22 @@ public class BasicAlignment implements Alignment { try { Cell cell = (Cell) new BasicCell((OWLEntity) ob1, (OWLEntity) ob2, relation, measure); - hash1.put((Object) (((OWLEntity) ob1).getURI()), cell); - hash2.put((Object) (((OWLEntity) ob2).getURI()), cell); + //Raph: + //HashSet s1 = hash1.get((Object)(((OWLEntity)ob1).getURI())); + //if ( s1 == null ){ + // s1 = new HashSet(); + // hash1.put((Object)(((OWLEntity)ob1).getURI()),s1); + //} + //s1.add(cell); + hash1.put((Object)(((OWLEntity)ob1).getURI()), cell); + //Raph: + //HashSet s1 = hash1.get((Object)(((OWLEntity)ob1).getURI())); + //if ( s2 == null ){ + // s2 = new HashSet(); + // hash2.put((Object)(((OWLEntity)ob2).getURI()),s2); + //} + //s2.add(cell); + hash2.put((Object)(((OWLEntity)ob2).getURI()), cell); return cell; } catch (OWLException e) { throw new AlignmentException("getURI problem", e); @@ -173,86 +192,83 @@ public class BasicAlignment implements Alignment { return addAlignCell( ob1, ob2, "=", 1. ); } + // Raph: + public Iterator getAlignCells1(Object ob) throws AlignmentException { + throw new AlignmentException("getAlignCell1: arguments must be OWLEntities"); + } + // Raph: + public Iterator getAlignCells1(OWLEntity ob) throws AlignmentException { + HashSet s = null; + try { s = (HashSet)hash1.get(((OWLEntity)ob).getURI()); } + catch (OWLException e) { throw new AlignmentException("getURI problem", e); } + if ( s == null ) { return null; } + else { return s.iterator(); } + } + public Cell getAlignCell1(Object ob) throws AlignmentException { - try { - if (!Class.forName("org.semanticweb.owl.model.OWLEntity").isInstance(ob)) - throw new AlignmentException("getAlignCell1: arguments must be OWLEntities"); - } catch (ClassNotFoundException e) { e.printStackTrace(); } - try { - return (Cell) hash1.get(((OWLEntity) ob).getURI()); - } catch (OWLException e) { throw new AlignmentException("getURI problem", e); } + throw new AlignmentException("getAlignCell1: arguments must be OWLEntities"); + } + public Cell getAlignCell1(OWLEntity ob) throws AlignmentException { + try { return (Cell) hash1.get(((OWLEntity) ob).getURI()); } + catch (OWLException e) { throw new AlignmentException("getURI problem", e); } } public Cell getAlignCell2(Object ob) throws AlignmentException { - try { - if (!Class.forName("org.semanticweb.owl.model.OWLEntity").isInstance(ob)) - throw new AlignmentException("getAlignCell2: arguments must be OWLEntities"); - } catch (ClassNotFoundException e) { e.printStackTrace(); } - try { - return (Cell) hash2.get(((OWLEntity) ob).getURI()); - } catch (OWLException e) { throw new AlignmentException("getURI problem", e); } + throw new AlignmentException("getAlignCell2: arguments must be OWLEntities"); + } + public Cell getAlignCell2(OWLEntity ob) throws AlignmentException { + try { return (Cell) hash2.get(((OWLEntity) ob).getURI()); } + catch (OWLException e) { throw new AlignmentException("getURI problem", e); } } public Object getAlignedObject1(Object ob) throws AlignmentException { - try { - if (!Class.forName("org.semanticweb.owl.model.OWLEntity").isInstance(ob)) - throw new AlignmentException("getAlignedObject1: arguments must be OWLEntities"); - } catch (ClassNotFoundException e) { e.printStackTrace(); } Cell c = getAlignCell1(ob); if (c != null) return c.getObject2(); else return null; }; public Object getAlignedObject2(Object ob) throws AlignmentException { - try { - if (!Class.forName("org.semanticweb.owl.model.OWLEntity").isInstance(ob)) - throw new AlignmentException("getAlignedObject2: arguments must be OWLEntities"); - } catch (ClassNotFoundException e) { e.printStackTrace(); } Cell c = getAlignCell2(ob); if (c != null) return c.getObject1(); else return null; }; public Relation getAlignedRelation1(Object ob) throws AlignmentException { - try { - if (!Class.forName("org.semanticweb.owl.model.OWLEntity").isInstance(ob)) - throw new AlignmentException("getAlignedRelation1: argument must be OWLEntity"); - } catch (ClassNotFoundException e) { e.printStackTrace(); } Cell c = getAlignCell1(ob); if (c != null) return c.getRelation(); else return (Relation) null; }; public Relation getAlignedRelation2(Object ob) throws AlignmentException { - try { - if (!Class.forName("org.semanticweb.owl.model.OWLEntity").isInstance(ob)) - throw new AlignmentException("getAlignedRelation2: argument must be OWLEntity"); - } catch (ClassNotFoundException e) { e.printStackTrace(); } Cell c = getAlignCell2(ob); if (c != null) return c.getRelation(); else return (Relation) null; }; public double getAlignedStrength1(Object ob) throws AlignmentException { - try { - if (!Class.forName("org.semanticweb.owl.model.OWLEntity").isInstance(ob)) - throw new AlignmentException("getAlignedStrength1: arguments must be OWLEntities"); - } catch (ClassNotFoundException e) { e.printStackTrace(); } Cell c = getAlignCell1(ob); if (c != null) return c.getStrength(); else return 0; }; public double getAlignedStrength2(Object ob) throws AlignmentException { - try { - if (!Class.forName("org.semanticweb.owl.model.OWLEntity").isInstance(ob)) - throw new AlignmentException("getAlignedStrength2: arguments must be OWLEntities"); - } catch (ClassNotFoundException e) { e.printStackTrace(); } Cell c = getAlignCell2(ob); if (c != null) return c.getStrength(); else return 0; }; + //Raph: + public void removeAlignCell(Cell c) throws AlignmentException { + try { + HashSet s1 = (HashSet)hash1.get(((OWLEntity)c.getObject1()).getURI()); + HashSet s2 = (HashSet)hash2.get(((OWLEntity)c.getObject2()).getURI()); + s1.remove(c); + s2.remove(c); + } catch (OWLException ex) { + throw new AlignmentException("getURI problem", ex); + } + } + /*************************************************************************** * The cut function suppresses from an alignment all the cell over a * particulat threshold @@ -264,6 +280,8 @@ public class BasicAlignment implements Alignment { // Beware, this suppresses all cells with these keys // There is only one of them try { + //Raph: + //removeAlignCell( c ); hash1.remove(((OWLEntity) c.getObject1()).getURI()); hash2.remove(((OWLEntity) c.getObject2()).getURI()); } catch (OWLException ex) { @@ -295,6 +313,7 @@ public class BasicAlignment implements Alignment { if ( threshold > 1. || threshold < 0. ) throw new AlignmentException( "Not a percentage or threshold : "+threshold ); // Create a sorted list of cells + // Raph: this will not work anymore List buffer = new ArrayList( hash1.values() ); Collections.sort( buffer ); int size = buffer.size(); diff --git a/src/fr/inrialpes/exmo/align/impl/BasicCell.java b/src/fr/inrialpes/exmo/align/impl/BasicCell.java index af9df66a185b5d950cc441eb9d2890769a6a361f..c6e8494da7901cd3892c719751fafc2b12423a19 100644 --- a/src/fr/inrialpes/exmo/align/impl/BasicCell.java +++ b/src/fr/inrialpes/exmo/align/impl/BasicCell.java @@ -72,19 +72,19 @@ public class BasicCell implements Cell, Comparable { } public BasicCell( Object ob1, Object ob2, String rel, double m ) throws AlignmentException { - try { - if ( !Class.forName("org.semanticweb.owl.model.OWLEntity").isInstance(ob1) || - !Class.forName("org.semanticweb.owl.model.OWLEntity").isInstance(ob2) ) - throw new AlignmentException("BasicCell: must take two OWLEntity as argument"); - } catch (ClassNotFoundException e) { e.printStackTrace(); } - object1 = (OWLEntity)ob1; - object2 = (OWLEntity)ob2; + throw new AlignmentException("BasicCell: must take two OWLEntity as argument"); + } + public BasicCell( OWLEntity ob1, OWLEntity ob2, String rel, double m ) throws AlignmentException { + object1 = ob1; + object2 = ob2; if ( rel.equals("=") ) { relation = new EquivRelation(); } else if ( rel.equals("<") ) { relation = new SubsumeRelation(); } else if ( rel.equals("%") ) { relation = new IncompatRelation(); + } else if ( rel.equals("~>") ) { + relation = new NonTransitiveImplicationRelation(); } else { // I could use the class name for relation, // this would be more extensible... diff --git a/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java b/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java index 5076c17f770b5d181ab6ea00f3d60e1d51b78b82..e600c97d161d7e32b2df169d6af02a95234d0f58 100644 --- a/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java @@ -40,6 +40,7 @@ import org.semanticweb.owl.model.OWLIndividual; import org.semanticweb.owl.model.OWLException; import org.semanticweb.owl.align.Alignment; +import org.semanticweb.owl.align.AlignmentProcess; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.Cell; @@ -60,7 +61,7 @@ import fr.inrialpes.exmo.align.impl.ConcatenatedIterator; */ -public class DistanceAlignment extends BasicAlignment +public class DistanceAlignment extends BasicAlignment implements AlignmentProcess { Similarity sim; @@ -171,8 +172,9 @@ public class DistanceAlignment extends BasicAlignment addAlignCell(class1,class2, "=", max); } } - // Extract for properties - for (Iterator it1 = onto1.getIndividuals().iterator(); it1.hasNext();) { + // Extract for individuals + // This does not work, at least for the OAEI 2005 tests + /* for (Iterator it1 = onto1.getIndividuals().iterator(); it1.hasNext();) { OWLIndividual ind1 = (OWLIndividual)it1.next(); found = false; max = threshold; val = 0; OWLIndividual ind2 = null; @@ -183,8 +185,9 @@ public class DistanceAlignment extends BasicAlignment found = true; max = val; ind2 = current; } } + System.err.println(ind1+" -- "+ind2+" = "+max); if ( found ) addAlignCell(ind1,ind2, "=", max); - } + }*/ } catch (Exception e2) {e2.printStackTrace();} return((Alignment)this); } diff --git a/src/fr/inrialpes/exmo/align/impl/method/EditDistNameAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/EditDistNameAlignment.java index 167904be40250652f471e4818ed5abb429db551e..f5a3f492991e6cabaa5c5b119945f8bba1a050d2 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/EditDistNameAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/EditDistNameAlignment.java @@ -55,21 +55,24 @@ public class EditDistNameAlignment extends DistanceAlignment implements Alignmen public double measure( OWLClass cl1, OWLClass cl2 ) throws OWLException{ String s1 = cl1.getURI().getFragment(); String s2 = cl2.getURI().getFragment(); - return StringDistances.levenshteinDistance( + if ( s1 == null || s2 == null ) return 1.; + else return StringDistances.levenshteinDistance( s1.toLowerCase(), s2.toLowerCase()) / max(s1.length(),s2.length()); } public double measure( OWLProperty pr1, OWLProperty pr2 ) throws OWLException{ String s1 = pr1.getURI().getFragment(); String s2 = pr2.getURI().getFragment(); - return StringDistances.levenshteinDistance( + if ( s1 == null || s2 == null ) return 1.; + else return StringDistances.levenshteinDistance( s1.toLowerCase(), s2.toLowerCase()) / max(s1.length(),s2.length()); } public double measure( OWLIndividual id1, OWLIndividual id2 ) throws OWLException{ String s1 = id1.getURI().getFragment(); String s2 = id2.getURI().getFragment(); - return StringDistances.levenshteinDistance( + if ( s1 == null || s2 == null ) return 1.; + else return StringDistances.levenshteinDistance( s1.toLowerCase(), s2.toLowerCase()) / max(s1.length(),s2.length()); } diff --git a/src/fr/inrialpes/exmo/align/impl/method/StringDistances.java b/src/fr/inrialpes/exmo/align/impl/method/StringDistances.java index 60eca48ba41b1252e7bdb7d0e971d7d33b06ad08..26004eff3f765e5fbf42c2d790fce2dcdb673673 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/StringDistances.java +++ b/src/fr/inrialpes/exmo/align/impl/method/StringDistances.java @@ -25,10 +25,11 @@ * various kind of strings. * * This includes: - * - subStringDistance * - equality + * - subStringDistance + * - pSubStringDistance [not implemented yet] * - lowenhein (edit) distance - * - n-gram distance + * - n-gram distance [not implemented yet] * * @author Jérôme Euzenat * @version $Id$ @@ -77,6 +78,10 @@ public class StringDistances { return (1.0 - ((double)2*best / (l1+l2))); } + /* pSubStringDistance: + * find all the common substrings (up to length 3) + * sum their size / s1+s2 + */ public static int equalDistance (String s, String t) { if (s == null || t == null) {