diff --git a/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java index 2610f2af119cd64084afd06dbb3973970c719817..e7979c1f3592e29432d7f309e98a520e6cf926a3 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java @@ -144,7 +144,7 @@ public class ClassStructAlignment extends DistanceAlignment implements Alignment // Assess factor // -- FirstExp: nothing to be done: one pass } - selectBestMatch( nbclass1, classlist1, nbclass2, classlist2, classmatrix, threshold, null); + //selectBestMatch( nbclass1, classlist1, nbclass2, classlist2, classmatrix, threshold, null); } diff --git a/src/fr/inrialpes/exmo/align/impl/method/EditDistNameAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/EditDistNameAlignment.java index 704271851cc3f6504466b7841c14956dd17a103a..167904be40250652f471e4818ed5abb429db551e 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/EditDistNameAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/EditDistNameAlignment.java @@ -21,12 +21,11 @@ package fr.inrialpes.exmo.align.impl.method; import java.util.Iterator; -import java.util.Vector; -import java.net.URI; import org.semanticweb.owl.model.OWLOntology; import org.semanticweb.owl.model.OWLClass; import org.semanticweb.owl.model.OWLProperty; +import org.semanticweb.owl.model.OWLIndividual; import org.semanticweb.owl.model.OWLException; import org.semanticweb.owl.align.Alignment; @@ -37,7 +36,6 @@ import org.semanticweb.owl.align.Parameters; import fr.inrialpes.exmo.align.impl.DistanceAlignment; import fr.inrialpes.exmo.align.impl.MatrixMeasure; -import fr.inrialpes.exmo.align.impl.Similarity; /** * This class aligns ontology with regard to the editing distance between @@ -48,92 +46,37 @@ import fr.inrialpes.exmo.align.impl.Similarity; * @version $Id$ */ - public class EditDistNameAlignment extends DistanceAlignment implements AlignmentProcess { - protected final class EditDistName extends MatrixMeasure { - public EditDistName(){ - } - public void compute( Parameters params ){ - try { - // Compute distances on classes - for ( Iterator it2 = onto2.getClasses().iterator(); it2.hasNext(); ){ - OWLClass cl2 = (OWLClass)it2.next(); - int l2 = cl2.getURI().getFragment().length(); - for ( Iterator it1 = onto1.getClasses().iterator(); it1.hasNext(); ){ - OWLClass cl1 = (OWLClass)it1.next(); - int l1 = cl1.getURI().getFragment().length(); - clmatrix[((Integer)classlist1.get(cl1)).intValue()][((Integer)classlist2.get(cl2)).intValue()] = - StringDistances.levenshteinDistance( - cl1.getURI().getFragment().toLowerCase(), - cl2.getURI().getFragment().toLowerCase()) / max(l1,l2); - } - } - // Compute distances on properties - for ( Iterator it2 = onto2.getObjectProperties().iterator(); it2.hasNext(); ){ - OWLProperty pr2 = (OWLProperty)it2.next(); - int l2 = pr2.getURI().getFragment().length(); - for ( Iterator it1 = onto1.getObjectProperties().iterator(); it1.hasNext(); ){ - OWLProperty pr1 = (OWLProperty)it1.next(); - int l1 = pr1.getURI().getFragment().length(); - prmatrix[((Integer)proplist1.get(pr1)).intValue()][((Integer)proplist2.get(pr2)).intValue()] = - StringDistances.levenshteinDistance( - pr1.getURI().getFragment().toLowerCase(), - pr2.getURI().getFragment().toLowerCase()) / max(l1,l2); - } - for ( Iterator it1 = onto1.getDataProperties().iterator(); it1.hasNext(); ){ - OWLProperty pr1 = (OWLProperty)it1.next(); - int l1 = pr1.getURI().getFragment().length(); - prmatrix[((Integer)proplist1.get(pr1)).intValue()][((Integer)proplist2.get(pr2)).intValue()] = - StringDistances.levenshteinDistance( - pr1.getURI().getFragment().toLowerCase(), - pr2.getURI().getFragment().toLowerCase()) / max(l1,l2); - } - } - for ( Iterator it2 = onto2.getDataProperties().iterator(); it2.hasNext(); ){ - OWLProperty pr2 = (OWLProperty)it2.next(); - int l2 = pr2.getURI().getFragment().length(); - for ( Iterator it1 = onto1.getObjectProperties().iterator(); it1.hasNext(); ){ - OWLProperty pr1 = (OWLProperty)it1.next(); - int l1 = pr1.getURI().getFragment().length(); - prmatrix[((Integer)proplist1.get(pr1)).intValue()][((Integer)proplist2.get(pr2)).intValue()] = - StringDistances.levenshteinDistance( - pr1.getURI().getFragment().toLowerCase(), - pr2.getURI().getFragment().toLowerCase()) / max(l1,l2); - } - for ( Iterator it1 = onto1.getDataProperties().iterator(); it1.hasNext(); ){ - OWLProperty pr1 = (OWLProperty)it1.next(); - int l1 = pr1.getURI().getFragment().length(); - prmatrix[((Integer)proplist1.get(pr1)).intValue()][((Integer)proplist2.get(pr2)).intValue()] = - StringDistances.levenshteinDistance( - pr1.getURI().getFragment().toLowerCase(), - pr2.getURI().getFragment().toLowerCase()) / max(l1,l2); - } - } - - - } catch (OWLException e) { e.printStackTrace(); } - } - } - /** Creation **/ public EditDistNameAlignment( OWLOntology onto1, OWLOntology onto2 ){ super( onto1, onto2 ); - setSimilarity( new EditDistName() ); - setType("**"); + setSimilarity( new MatrixMeasure() { + public double measure( OWLClass cl1, OWLClass cl2 ) throws OWLException{ + String s1 = cl1.getURI().getFragment(); + String s2 = cl2.getURI().getFragment(); + 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( + 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( + s1.toLowerCase(), + s2.toLowerCase()) / max(s1.length(),s2.length()); + } + } ); }; private double max( double i, double j) { if ( i>j ) return i; else return j; } - /** Processing **/ - /** This is not exactly equal, this uses toLowerCase() */ - public void align( Alignment alignment, Parameters params ) throws AlignmentException, OWLException { - //ignore alignment; - double threshold = 1.; // threshold above which distances are to high - - getSimilarity().initialize( (OWLOntology)getOntology1(), (OWLOntology)getOntology2(), alignment ); - getSimilarity().compute( params ); - extract( type, params ); - } } diff --git a/src/fr/inrialpes/exmo/align/impl/method/NameAndPropertyAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/NameAndPropertyAlignment.java index 3397dad2ca446fd5d994ee0613330e272876a194..666e75cf1d1475cce3b7fc5cdede60caf18edd76 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/NameAndPropertyAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/NameAndPropertyAlignment.java @@ -97,9 +97,6 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align double pia2 = 0.; // relation weight for domain double pia3 = 0.; // relation weight for range double epsillon = 0.05; // stoping condition - - - if ( params.getParameter("debug") != null ) debug = ((Integer)params.getParameter("debug")).intValue(); @@ -127,7 +124,6 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align classlist1.add( it.next() ); } classmatrix = new double[nbclass1+1][nbclass2+1]; - if (debug > 0) System.err.println("Initializing property distances"); for ( i=0; i<nbprop1; i++ ){ @@ -322,10 +318,7 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align moy=moy+max; max=0.0; } - return moy; - - } } diff --git a/src/fr/inrialpes/exmo/align/impl/method/NameEqAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/NameEqAlignment.java index bef079432e0e6167633bdac37bf67f5f93841d9a..e9b169aa37cfc97f03a2edde736ed7d085c1731b 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/NameEqAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/NameEqAlignment.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2003-2004 + * Copyright (C) INRIA Rhône-Alpes, 2003-2005 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,22 +23,21 @@ package fr.inrialpes.exmo.align.impl.method; import java.util.Iterator; import java.util.Hashtable; -import org.semanticweb.owl.model.OWLEntity; import org.semanticweb.owl.model.OWLOntology; import org.semanticweb.owl.model.OWLClass; import org.semanticweb.owl.model.OWLProperty; import org.semanticweb.owl.model.OWLIndividual; import org.semanticweb.owl.model.OWLException; +import fr.inrialpes.exmo.align.impl.DistanceAlignment; +import fr.inrialpes.exmo.align.impl.MatrixMeasure; +import fr.inrialpes.exmo.align.impl.Similarity; + import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentProcess; -import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Parameters; -import fr.inrialpes.exmo.align.impl.BasicAlignment; - - /** * Represents an OWL ontology alignment. An ontology comprises a number of * collections. Each ontology has a number of classes, properties and @@ -52,71 +51,41 @@ import fr.inrialpes.exmo.align.impl.BasicAlignment; * @version $Id$ */ - -public class NameEqAlignment extends BasicAlignment implements AlignmentProcess -{ +public class NameEqAlignment extends DistanceAlignment implements AlignmentProcess { /** Creation **/ public NameEqAlignment( OWLOntology onto1, OWLOntology onto2 ){ - init( onto1, onto2 ); - setType("11"); + super( onto1, onto2 ); + setSimilarity( new MatrixMeasure() { + public double measure( OWLClass cl1, OWLClass cl2 ) throws OWLException{ + String s1 = cl1.getURI().getFragment(); + String s2 = cl2.getURI().getFragment(); + if ( s1 != null && s2 != null && s1.toLowerCase().equals(s2.toLowerCase()) ) return 0.; + else return 1.; + } + public double measure( OWLProperty pr1, OWLProperty pr2 ) throws OWLException{ + String s1 = pr1.getURI().getFragment(); + String s2 = pr2.getURI().getFragment(); + if ( s1 != null && s2 != null && s1.toLowerCase().equals(s2.toLowerCase()) ) return 0.; + else return 1.; + } + public double measure( OWLIndividual id1, OWLIndividual id2 ) throws OWLException{ + String s1 = id1.getURI().getFragment(); + String s2 = id2.getURI().getFragment(); + if ( s1 != null && s2 != null && s1.toLowerCase().equals(s2.toLowerCase()) ) return 0.; + else return 1.; + } + } ); + setType("**"); }; /** Processing **/ - /** This is not exactly equal, this uses toLowerCase() */ public void align( Alignment alignment, Parameters params ) throws AlignmentException, OWLException { - Hashtable table = new Hashtable(); - OWLEntity ob1 = null; - OWLEntity ob2 = null; //ignore alignment; - // This is a stupid O(2n) algorithm: - // Put each class of onto1 in a hashtable indexed by its name (not qualified) - // For each class of onto2 whose name is found in the hash table - for ( Iterator it = onto1.getClasses().iterator(); it.hasNext(); ){ - ob1 = (OWLEntity)it.next(); - if ( ob1.getURI().getFragment() != null ) - table.put((Object)ob1.getURI().getFragment().toLowerCase(), ob1); - } - for ( Iterator it = onto2.getClasses().iterator(); it.hasNext(); ){ - ob2 = (OWLEntity)it.next(); - if ( ob2.getURI().getFragment() != null ) { - ob1 = (OWLEntity)table.get((Object)ob2.getURI().getFragment().toLowerCase()); - if( ob1 != null ){ addAlignCell( ob1, ob2 ); } - } - } - for ( Iterator it = onto1.getObjectProperties().iterator(); it.hasNext(); ){ - ob1 = (OWLEntity)it.next(); - if ( ob1.getURI().getFragment() != null ) - table.put((Object)ob1.getURI().getFragment().toLowerCase(), ob1); - } - for ( Iterator it = onto2.getObjectProperties().iterator(); it.hasNext(); ){ - ob2 = (OWLEntity)it.next(); - if ( ob2.getURI().getFragment() != null ){ - ob1 = (OWLEntity)table.get((Object)ob2.getURI().getFragment().toLowerCase()); - if( ob1 != null ){ addAlignCell( ob1, ob2 ); } - } - } - for ( Iterator it = onto1.getDataProperties().iterator(); it.hasNext(); ){ - ob1 = (OWLEntity)it.next(); - if ( ob1.getURI().getFragment() != null ) - table.put((Object)ob1.getURI().getFragment().toLowerCase(), ob1); - } - for ( Iterator it = onto2.getDataProperties().iterator(); it.hasNext(); ){ - ob2 = (OWLEntity)it.next(); - if ( ob2.getURI().getFragment() != null ){ - ob1 = (OWLEntity)table.get((Object)ob2.getURI().getFragment().toLowerCase()); - if( ob1 != null ){ addAlignCell( ob1, ob2 ); } - } - } - //for ( Iterator it = onto1.getIndividuals().iterator(); it.hasNext(); ){ - // id = (OWLIndividual)it.next(); - // table.put((Object)pr.getURI().getFragment().toLowerCase(), id); - //} - //for ( Iterator it = onto2.getIndividuals().iterator(); it.hasNext(); ){ - // OWLIndividual id2 = (OWLIndividual)it.next(); - // id = (OWLIndividual)table.get((Object)id2.getURI().getFragment().toLowerCase()); - // if( id != null ){ addAlignCell( id, id2 ); } - // } - } + double threshold = 1.; // threshold above which distances are to high + getSimilarity().initialize( (OWLOntology)getOntology1(), (OWLOntology)getOntology2(), alignment ); + getSimilarity().compute( params ); + extract( type, params ); + } } diff --git a/src/fr/inrialpes/exmo/align/impl/method/SubsDistNameAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/SubsDistNameAlignment.java index 15777f1b1cf0e647ad76bb095c4619eca8078756..a77d9420e522eb2a513e3791af3cb048e1b5c65a 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/SubsDistNameAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/SubsDistNameAlignment.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2003-2004 + * Copyright (C) INRIA Rhône-Alpes, 2003-2005 * * 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 @@ -18,38 +18,30 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - package fr.inrialpes.exmo.align.impl.method; import java.util.Iterator; -import java.util.Vector; -import java.util.Set; -import java.util.HashSet; import org.semanticweb.owl.model.OWLOntology; import org.semanticweb.owl.model.OWLClass; import org.semanticweb.owl.model.OWLProperty; -import org.semanticweb.owl.model.OWLFrame; -import org.semanticweb.owl.model.OWLRestriction; -import org.semanticweb.owl.model.OWLDescription; -import org.semanticweb.owl.model.OWLNaryBooleanDescription; +import org.semanticweb.owl.model.OWLIndividual; import org.semanticweb.owl.model.OWLException; -import org.semanticweb.owl.model.OWLEntity; + +import fr.inrialpes.exmo.align.impl.DistanceAlignment; +import fr.inrialpes.exmo.align.impl.MatrixMeasure; +import fr.inrialpes.exmo.align.impl.Similarity; import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentProcess; -import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Parameters; import fr.inrialpes.exmo.align.impl.DistanceAlignment; -/** This class has been built for ISWC experiments with bibliography. - * It implements a non iterative (one step) OLA algorithms based on - * the name of classes and properties. It could be made iterative by - * just adding range/domain on properties... - * The parameters are: - * - threshold: above what do we select for the alignment; +/** + * This class implements alignment based on substring distance + * of class and property labels * * @author Jérôme Euzenat * @version $Id$ @@ -57,119 +49,37 @@ import fr.inrialpes.exmo.align.impl.DistanceAlignment; public class SubsDistNameAlignment extends DistanceAlignment implements AlignmentProcess { - /** Creation **/ public SubsDistNameAlignment( OWLOntology onto1, OWLOntology onto2 ){ - super( onto1, onto2 ); + super( onto1, onto2 ); + setSimilarity( new MatrixMeasure() { + public double measure( OWLClass cl1, OWLClass cl2 ) throws OWLException{ + String s1 = cl1.getURI().getFragment(); + String s2 = cl2.getURI().getFragment(); + return StringDistances.subStringDistance(s1.toLowerCase(),s2.toLowerCase()); + } + public double measure( OWLProperty pr1, OWLProperty pr2 ) throws OWLException{ + String s1 = pr1.getURI().getFragment(); + String s2 = pr2.getURI().getFragment(); + return StringDistances.subStringDistance(s1.toLowerCase(),s2.toLowerCase()); + } + public double measure( OWLIndividual id1, OWLIndividual id2 ) throws OWLException{ + String s1 = id1.getURI().getFragment(); + String s2 = id2.getURI().getFragment(); + return StringDistances.subStringDistance(s1.toLowerCase(),s2.toLowerCase()); + } + } ); setType("**"); }; - private double max( double i, double j) { if ( i>j ) return i; else return j; } - /** Processing **/ public void align( Alignment alignment, Parameters params ) throws AlignmentException, OWLException { - // The first parameter to get should be debug //ignore alignment; double threshold = 1.; // threshold above which distances are to high - int i, j = 0; // index for onto1 and onto2 classes - int l1, l2 = 0; // length of strings (for normalizing) - int nbclass1 = 0; // number of classes in onto1 - int nbclass2 = 0; // number of classes in onto2 - Vector classlist2 = new Vector(10); // onto2 classes - Vector classlist1 = new Vector(10); // onto1 classes - double classmatrix[][]; // class distance matrix - int nbprop1 = 0; // number of properties in onto1 - int nbprop2 = 0; // number of properties in onto2 - Vector proplist2 = new Vector(10); // onto2 properties - Vector proplist1 = new Vector(10); // onto1 properties - double propmatrix[][]; // properties distance matrix - - // Create property lists and matrix - for ( Iterator it = onto1.getObjectProperties().iterator(); it.hasNext(); nbprop1++ ){ - proplist1.add( it.next() ); - } - for ( Iterator it = onto1.getDataProperties().iterator(); it.hasNext(); nbprop1++ ){ - proplist1.add( it.next() ); - } - for ( Iterator it = onto2.getObjectProperties().iterator(); it.hasNext(); nbprop2++ ){ - proplist2.add( it.next() ); - } - for ( Iterator it = onto2.getDataProperties().iterator(); it.hasNext(); nbprop2++ ){ - proplist2.add( it.next() ); - } - propmatrix = new double[nbprop1+1][nbprop2+1]; - // Create class lists - for ( Iterator it = onto2.getClasses().iterator(); it.hasNext(); nbclass2++ ){ - classlist2.add( it.next() ); - } - for ( Iterator it = onto1.getClasses().iterator(); it.hasNext(); nbclass1++ ){ - classlist1.add( it.next() ); - } - classmatrix = new double[nbclass1+1][nbclass2+1]; - - if (debug > 0) System.err.println("Initializing property distances"); - for ( i=0; i<nbprop1; i++ ){ - OWLProperty cl = (OWLProperty)proplist1.get(i); - String s1 = cl.getURI().getFragment(); - if ( s1 != null ) s1 = s1.toLowerCase(); - for ( j=0; j<nbprop2; j++ ){ - cl = (OWLProperty)proplist2.get(j); - String s2 = cl.getURI().getFragment(); - if ( s2 != null ) s2 = s2.toLowerCase(); - if ( s1 == null || s2 == null ) { propmatrix[i][j] = 1.; } - else { propmatrix[i][j] = StringDistances.subStringDistance( s1, s2 ); } - } - } - - if (debug > 0) System.err.println("Initializing class distances"); - // Initialize class distances - for ( i=0; i<nbclass1; i++ ){ - OWLClass cl = (OWLClass)classlist1.get(i); - for ( j=0; j<nbclass2; j++ ){ - classmatrix[i][j] = StringDistances.subStringDistance( - cl.getURI().getFragment().toLowerCase(), - ((OWLClass)classlist2.get(j)).getURI().getFragment().toLowerCase()); - } - } - - // This mechanism should be parametric! - // Select the best match - // There can be many algorithm for these: - // n:m: get all of those above a threshold - // 1:1: get the best discard lines and columns and iterate - // Here we basically implement ?:* because the algorithm - // picks up the best matching object above threshold for i. - if (debug > 0) System.err.print("Storing property alignment\n"); - for ( i=0; i<nbprop1; i++ ){ - boolean found = false; - int best = 0; - double max = threshold; - for ( j=0; j<nbprop2; j++ ){ - if ( propmatrix[i][j] < max) { - found = true; - best = j; - max = propmatrix[i][j]; - } - } - if ( found ) { addAlignDistanceCell( (OWLProperty)proplist1.get(i), (OWLProperty)proplist2.get(best), "=", max ); } - } - - if (debug > 0) System.err.print("Storing class alignment\n"); - - for ( i=0; i<nbclass1; i++ ){ - boolean found = false; - int best = 0; - double max = threshold; - for ( j=0; j<nbclass2; j++ ){ - if ( classmatrix[i][j] < max) { - found = true; - best = j; - max = classmatrix[i][j]; - } - } - if ( found ) { addAlignDistanceCell( (OWLClass)classlist1.get(i), (OWLClass)classlist2.get(best), "=", max ); } - } + getSimilarity().initialize( (OWLOntology)getOntology1(), (OWLOntology)getOntology2(), alignment ); + getSimilarity().compute( params ); + extract( type, params ); } } diff --git a/src/fr/inrialpes/exmo/align/ling/JWNLAlignment.java b/src/fr/inrialpes/exmo/align/ling/JWNLAlignment.java index b946fecd2e96f38a58636863402dce7bd0282550..1a3e614309a7a0cffc09aba7dbc01b125ef09e82 100644 --- a/src/fr/inrialpes/exmo/align/ling/JWNLAlignment.java +++ b/src/fr/inrialpes/exmo/align/ling/JWNLAlignment.java @@ -21,16 +21,19 @@ package fr.inrialpes.exmo.align.ling; import java.util.Iterator; -import java.util.Vector; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLException; import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLClass; import org.semanticweb.owl.model.OWLProperty; +import org.semanticweb.owl.model.OWLIndividual; +import org.semanticweb.owl.model.OWLException; + +import fr.inrialpes.exmo.align.impl.DistanceAlignment; +import fr.inrialpes.exmo.align.impl.MatrixMeasure; +import fr.inrialpes.exmo.align.impl.Similarity; import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentProcess; -import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Parameters; @@ -42,132 +45,48 @@ import fr.inrialpes.exmo.align.impl.DistanceAlignment; * @version $Id: JWNLAlignment.java,v 1.0 2004/08/04 */ - public class JWNLAlignment extends DistanceAlignment implements AlignmentProcess { + protected class SynonymMatrixMeasure extends MatrixMeasure { + protected JWNLDistances Dist = null; + + public SynonymMatrixMeasure() { + Dist = new JWNLDistances(); + Dist.Initialize(); + } + public double measure( OWLClass cl1, OWLClass cl2 ) throws OWLException{ + String s1 = cl1.getURI().getFragment(); + String s2 = cl2.getURI().getFragment(); + return Dist.BasicSynonymDistance(s1.toLowerCase(),s2.toLowerCase()); + } + public double measure( OWLProperty pr1, OWLProperty pr2 ) throws OWLException{ + String s1 = pr1.getURI().getFragment(); + String s2 = pr2.getURI().getFragment(); + return Dist.BasicSynonymDistance(s1.toLowerCase(),s2.toLowerCase()); + } + public double measure( OWLIndividual id1, OWLIndividual id2 ) throws OWLException{ + String s1 = id1.getURI().getFragment(); + String s2 = id2.getURI().getFragment(); + return Dist.BasicSynonymDistance(s1.toLowerCase(),s2.toLowerCase()); + } + } + /** Creation **/ public JWNLAlignment( OWLOntology onto1, OWLOntology onto2 ){ super( onto1, onto2 ); + setSimilarity( new SynonymMatrixMeasure() ); setType("**"); }; - private double max( double i, double j) { if ( i>j ) return i; else return j; } - /** Processing **/ public void align( Alignment alignment, Parameters params ) throws AlignmentException, OWLException { //ignore alignment; - double threshold = 1.; // threshold above which distances are too high - int i, j, k = 0; // index for onto1 and onto2 classes - int l1, l2 = 0; // length of strings (for normalizing) - int nbclass1 = 0; // number of classes in onto1 - int nbclass2 = 0; // number of classes in onto2 - Vector classlist2 = new Vector(10); // onto2 classes - Vector classlist1 = new Vector(10); // onto1 classes - double classmatrix[][]; // class distance matrix - int nbprop1 = 0; // number of properties in onto1 - int nbprop2 = 0; // number of properties in onto2 - Vector proplist2 = new Vector(10); // onto2 properties - Vector proplist1 = new Vector(10); // onto1 properties - - double propmatrix[][]; // properties distance matrix - double pic1 = 0.5; // class weigth for name - double pic2 = 0.5; // class weight for properties - double pia1 = 1.; // relation weight for name - double pia2 = 0.; // relation weight for domain - double pia3 = 0.; // relation weight for range - double epsillon = 0.05; // stoping condition - // JE: changed within the tutorial Old to not-ald - JWNLDistances Dist = new JWNLDistances(); - //OldJWNLDistances Dist = new OldJWNLDistances(); - Dist.Initialize(); - if ( params.getParameter("debug") != null ) - debug = ((Integer)params.getParameter("debug")).intValue(); - // Create property lists and matrix - for ( Iterator it = onto1.getObjectProperties().iterator(); it.hasNext(); nbprop1++ ){ - proplist1.add( it.next() ); - } - for ( Iterator it = onto1.getDataProperties().iterator(); it.hasNext(); nbprop1++ ){ - proplist1.add( it.next() ); - } - for ( Iterator it = onto2.getObjectProperties().iterator(); it.hasNext(); nbprop2++ ){ - proplist2.add( it.next() ); - } - for ( Iterator it = onto2.getDataProperties().iterator(); it.hasNext(); nbprop2++ ){ - proplist2.add( it.next() ); - } - propmatrix = new double[nbprop1+1][nbprop2+1]; - - // Create class lists - for ( Iterator it = onto2.getClasses().iterator(); it.hasNext(); nbclass2++ ){ - classlist2.add( it.next() ); - } - for ( Iterator it = onto1.getClasses().iterator(); it.hasNext(); nbclass1++ ){ - classlist1.add( it.next() ); - } - classmatrix = new double[nbclass1+1][nbclass2+1]; - - - if (debug > 0) System.err.println("Initializing property distances"); - for ( i=0; i<nbprop1; i++ ){ - OWLProperty cl = (OWLProperty)proplist1.get(i); - String st1=new String(); - String st2=new String(); - if (cl.getURI().getFragment()!=null){ st1 = cl.getURI().getFragment().toLowerCase();} - for ( j=0; j<nbprop2; j++ ){ - cl = (OWLProperty)proplist2.get(j); - if(cl.getURI().getFragment()!=null){st2 = cl.getURI().getFragment().toLowerCase() ;} - propmatrix[i][j] = Dist.BasicSynonymDistance(st1,st2); - } - } - if (debug > 0) System.err.println("Initializing class distances"); - for ( i=0; i<nbclass1; i++ ){ - OWLClass cl = (OWLClass)classlist1.get(i); - for ( j=0; j<nbclass2; j++ ){ - classmatrix[i][j] = Dist.BasicSynonymDistance( - cl.getURI().getFragment().toLowerCase(), - ((OWLClass)classlist2.get(j)).getURI().getFragment().toLowerCase()); - } - } - - // This mechanism should be parametric! - // Select the best match - // There can be many algorithm for these: - // n:m: get all of those above a threshold - // 1:1: get the best discard lines and columns and iterate - // Here we basically implement ?:* because the algorithm - // picks up the best matching object above threshold for i. - if (debug > 0) System.err.print("Storing property alignment\n"); - for ( i=0; i<nbprop1; i++ ){ - boolean found = false; - int best = 0; - double max = threshold; - for ( j=0; j<nbprop2; j++ ){ - if ( propmatrix[i][j] < max) { - found = true; - best = j; - max = propmatrix[i][j]; - } - } - if ( found ) {addAlignDistanceCell( (OWLProperty)proplist1.get(i), (OWLProperty)proplist2.get(best), "=", max ); } - } - - if (debug > 0) System.err.print("Storing class alignment\n"); + double threshold = 1.; // threshold above which distances are to high - for ( i=0; i<nbclass1; i++ ){ - boolean found = false; - int best = 0; - double max = threshold; - for ( j=0; j<nbclass2; j++ ){ - if ( classmatrix[i][j] < max) { - found = true; - best = j; - max = classmatrix[i][j]; - } - } - if ( found ) { addAlignDistanceCell( (OWLClass)classlist1.get(i), (OWLClass)classlist2.get(best), "=", max ); } - } + getSimilarity().initialize( (OWLOntology)getOntology1(), (OWLOntology)getOntology2(), alignment ); + getSimilarity().compute( params ); + extract( type, params ); } - }