Mentions légales du service

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

- Similarity can now been considered generically as a distance or similarity

parent 748f274b
No related branches found
No related tags found
No related merge requests found
...@@ -39,36 +39,26 @@ import fr.inrialpes.exmo.ontowrap.OntowrapException; ...@@ -39,36 +39,26 @@ import fr.inrialpes.exmo.ontowrap.OntowrapException;
import fr.inrialpes.exmo.ontosim.util.HungarianAlgorithm; import fr.inrialpes.exmo.ontosim.util.HungarianAlgorithm;
/** /**
* The mother class for distance or similarity-based alignments.
* It is abstract because it does not provide an implemented similarity measure
* Otherwise everything is fine.
*
* This class should work with similarity and distances, as soon as, the used
* similarity structure is defined as such.
* *
* @author Jrme Euzenat * @author Jrme Euzenat
* @version $Id$ * @version $Id$
*/ */
public class DistanceAlignment extends ObjectAlignment implements AlignmentProcess { public abstract class DistanceAlignment extends ObjectAlignment implements AlignmentProcess {
Similarity sim; Similarity sim;
/** Creation **/ /** Creation **/
public DistanceAlignment() {} public DistanceAlignment() {};
// JE: OntoRewr (LoadedOntology -> one step above)
//public DistanceAlignment( LoadedOntology onto1, LoadedOntology onto2 ){
// Init must now be triggered explicitely
// init( onto1, onto2 );
//};
public void setSimilarity( Similarity s ) { sim = s; } public void setSimilarity( Similarity s ) { sim = s; }
public Similarity getSimilarity() { return sim; } public Similarity getSimilarity() { return sim; }
public void addAlignDistanceCell( Object ob1, Object ob2, String relation, double measure) throws AlignmentException {
addAlignCell( ob1, ob2, relation, 1.-measure );
}
public double getAlignedDistance1( Object ob ) throws AlignmentException {
return (1. - getAlignedStrength1(ob));
};
public double getAlignedDistance2( Object ob ) throws AlignmentException {
return (1. - getAlignedStrength2(ob));
};
/** /**
* Process matching * Process matching
* - create distance data structures, * - create distance data structures,
...@@ -94,22 +84,26 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce ...@@ -94,22 +84,26 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce
* Prints the distance matrix * Prints the distance matrix
*/ */
public void printDistanceMatrix( Properties params ){ public void printDistanceMatrix( Properties params ){
String algName = params.getProperty("algName");
String metric = "distance";
if ( sim.getSimilarity() ) metric = "similarity";
if ( algName == null ) algName = getClass().toString();
System.out.println("\\documentclass{article}\n"); System.out.println("\\documentclass{article}\n");
System.out.println("\\usepackage{graphics}\n"); System.out.println("\\usepackage{graphics}\n");
System.out.println("\\begin{document}\n"); System.out.println("\\begin{document}\n");
System.out.println("\\begin{table}"); System.out.println("\\begin{table}");
sim.printClassSimilarityMatrix("tex"); sim.printClassSimilarityMatrix("tex");
System.out.println("\\caption{Class distance with measure "+params.getProperty("stringFunction")+"}"); System.out.println("\\caption{Class "+metric+" with measure "+algName+".}" );
System.out.println("\\end{table}"); System.out.println("\\end{table}");
System.out.println(); System.out.println();
System.out.println("\\begin{table}"); System.out.println("\\begin{table}");
sim.printPropertySimilarityMatrix("tex"); sim.printPropertySimilarityMatrix("tex");
System.out.println("\\caption{Property distance with measure "+params.getProperty("stringFunction")+"}"); System.out.println("\\caption{Property "+metric+" with measure "+algName+".}" );
System.out.println("\\end{table}"); System.out.println("\\end{table}");
System.out.println(); System.out.println();
System.out.println("\\begin{table}"); System.out.println("\\begin{table}");
sim.printIndividualSimilarityMatrix("tex"); sim.printIndividualSimilarityMatrix("tex");
System.out.println("\\caption{Individual distance with measure "+params.getProperty("stringFunction")+"}"); System.out.println("\\caption{Individual "+metric+" with measure "+algName+".}" );
System.out.println("\\end{table}"); System.out.println("\\end{table}");
System.out.println("\n\\end{document}"); System.out.println("\n\\end{document}");
} }
...@@ -160,7 +154,7 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce ...@@ -160,7 +154,7 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce
public Alignment extractqs( double threshold, Properties params) { public Alignment extractqs( double threshold, Properties params) {
double max = 0.; double max = 0.;
boolean found = false; boolean found = false;
double val = 0; double val = 0.;
try { try {
// Extract for properties // Extract for properties
...@@ -168,13 +162,14 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce ...@@ -168,13 +162,14 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce
ConcatenatedIterator(ontology1().getObjectProperties().iterator(), ConcatenatedIterator(ontology1().getObjectProperties().iterator(),
ontology1().getDataProperties().iterator()); ontology1().getDataProperties().iterator());
for( Object prop1 : pit1 ){ for( Object prop1 : pit1 ){
found = false; max = threshold; val = 0; found = false; max = threshold; val = 0.;
Object prop2 = null; Object prop2 = null;
ConcatenatedIterator pit2 = new ConcatenatedIterator pit2 = new
ConcatenatedIterator(ontology2().getObjectProperties().iterator(), ConcatenatedIterator(ontology2().getObjectProperties().iterator(),
ontology2().getDataProperties().iterator()); ontology2().getDataProperties().iterator());
for ( Object current : pit2 ){ for ( Object current : pit2 ){
val = 1 - sim.getPropertySimilarity(prop1,current); if ( sim.getSimilarity() ) val = sim.getPropertySimilarity(prop1,current);
else val = 1 - sim.getPropertySimilarity(prop1,current);
if ( val > max) { if ( val > max) {
found = true; max = val; prop2 = current; found = true; max = val; prop2 = current;
} }
...@@ -186,7 +181,8 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce ...@@ -186,7 +181,8 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce
found = false; max = threshold; val = 0; found = false; max = threshold; val = 0;
Object class2 = null; Object class2 = null;
for ( Object current : ontology2().getClasses() ) { for ( Object current : ontology2().getClasses() ) {
val = 1 - sim.getClassSimilarity(class1,current); if ( sim.getSimilarity() ) val = sim.getClassSimilarity(class1,current);
else val = 1 - sim.getClassSimilarity(class1,current);
if (val > max) { if (val > max) {
found = true; max = val; class2 = current; found = true; max = val; class2 = current;
} }
...@@ -201,7 +197,8 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce ...@@ -201,7 +197,8 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce
Object ind2 = null; Object ind2 = null;
for ( Object current : ontology2().getIndividuals() ) { for ( Object current : ontology2().getIndividuals() ) {
if ( ontology2().getEntityURI( current ) != null ) { if ( ontology2().getEntityURI( current ) != null ) {
val = 1 - sim.getIndividualSimilarity( ind1, current ); if ( sim.getSimilarity() ) val = sim.getIndividualSimilarity( ind1, current );
else val = 1 - sim.getIndividualSimilarity( ind1, current );
if (val > max) { if (val > max) {
found = true; max = val; ind2 = current; found = true; max = val; ind2 = current;
} }
...@@ -241,17 +238,23 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce ...@@ -241,17 +238,23 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce
for ( Object ob : ontology2().getClasses() ) { for ( Object ob : ontology2().getClasses() ) {
class2[j++] = ob; class2[j++] = ob;
} }
double ival = sim.getClassSimilarity(class1[0],class2[0]);
for( i = 0; i < nbclasses1; i++ ){ for( i = 0; i < nbclasses1; i++ ){
for( j = 0; j < nbclasses2; j++ ){ for( j = 0; j < nbclasses2; j++ ){
matrix[i][j] = 1 - sim.getClassSimilarity(class1[i],class2[j]); if ( ival != -1. && ival != sim.getClassSimilarity(class1[i],class2[j] ) ) ival = -1.;
if ( sim.getSimilarity() ) matrix[i][j] = sim.getClassSimilarity(class1[i],class2[j]);
else matrix[i][j] = 1 - sim.getClassSimilarity(class1[i],class2[j]);
} }
} }
// Pass it to the algorithm // Pass it to the algorithm
if ( ival == -1. ) {
int[][] result = HungarianAlgorithm.hgAlgorithm( matrix, "max" ); int[][] result = HungarianAlgorithm.hgAlgorithm( matrix, "max" );
// Extract the result // Extract the result
for( i=0; i < result.length ; i++ ){ for( i=0; i < result.length ; i++ ){
// The matrix has been destroyed // The matrix has been destroyed
double val = 1 - sim.getClassSimilarity(class1[result[i][0]],class2[result[i][1]]); double val;
if ( sim.getSimilarity() ) val = sim.getClassSimilarity(class1[result[i][0]],class2[result[i][1]]);
else val = 1 - sim.getClassSimilarity(class1[result[i][0]],class2[result[i][1]]);
// JE: here using strict-> is a very good idea. // JE: here using strict-> is a very good idea.
// it means that alignments with 0. similarity // it means that alignments with 0. similarity
// will be excluded from the best match. // will be excluded from the best match.
...@@ -259,6 +262,7 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce ...@@ -259,6 +262,7 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce
addCell( new ObjectCell( (String)null, class1[result[i][0]], class2[result[i][1]], BasicRelation.createRelation("="), val ) ); addCell( new ObjectCell( (String)null, class1[result[i][0]], class2[result[i][1]], BasicRelation.createRelation("="), val ) );
} }
} }
}
} catch (AlignmentException alex) { alex.printStackTrace(); } } catch (AlignmentException alex) { alex.printStackTrace(); }
catch (OntowrapException owex) { owex.printStackTrace(); } catch (OntowrapException owex) { owex.printStackTrace(); }
// For properties // For properties
...@@ -278,17 +282,24 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce ...@@ -278,17 +282,24 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce
ConcatenatedIterator(ontology2().getObjectProperties().iterator(), ConcatenatedIterator(ontology2().getObjectProperties().iterator(),
ontology2().getDataProperties().iterator()); ontology2().getDataProperties().iterator());
for ( Object ob: pit2 ) prop2[j++] = ob; for ( Object ob: pit2 ) prop2[j++] = ob;
double ival = sim.getPropertySimilarity(prop1[0],prop2[0]);
for( i = 0; i < nbprop1; i++ ){ for( i = 0; i < nbprop1; i++ ){
for( j = 0; j < nbprop2; j++ ){ for( j = 0; j < nbprop2; j++ ){
if ( ival != -1. && ival != sim.getPropertySimilarity(prop1[i],prop2[j] ) ) ival = -1.;
if ( sim.getSimilarity() ) matrix[i][j] = sim.getPropertySimilarity(prop1[i],prop2[j]);
else
matrix[i][j] = 1 - sim.getPropertySimilarity(prop1[i],prop2[j]); matrix[i][j] = 1 - sim.getPropertySimilarity(prop1[i],prop2[j]);
} }
} }
// Pass it to the algorithm // Pass it to the algorithm
if ( ival == -1. ) {
int[][] result = HungarianAlgorithm.hgAlgorithm( matrix, "max" ); int[][] result = HungarianAlgorithm.hgAlgorithm( matrix, "max" );
// Extract the result // Extract the result
for( i=0; i < result.length ; i++ ){ for( i=0; i < result.length ; i++ ){
// The matrix has been destroyed // The matrix has been destroyed
double val = 1 - sim.getPropertySimilarity(prop1[result[i][0]],prop2[result[i][1]]); double val;
if ( sim.getSimilarity() ) val = sim.getPropertySimilarity(prop1[result[i][0]],prop2[result[i][1]]);
else val = 1 - sim.getPropertySimilarity(prop1[result[i][0]],prop2[result[i][1]]);
// JE: here using strict-> is a very good idea. // JE: here using strict-> is a very good idea.
// it means that alignments with 0. similarity // it means that alignments with 0. similarity
// will be excluded from the best match. // will be excluded from the best match.
...@@ -296,6 +307,7 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce ...@@ -296,6 +307,7 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce
addCell( new ObjectCell( (String)null, prop1[result[i][0]], prop2[result[i][1]], BasicRelation.createRelation("="), val ) ); addCell( new ObjectCell( (String)null, prop1[result[i][0]], prop2[result[i][1]], BasicRelation.createRelation("="), val ) );
} }
} }
}
} catch (AlignmentException alex) { alex.printStackTrace(); } } catch (AlignmentException alex) { alex.printStackTrace(); }
catch (OntowrapException owex) { owex.printStackTrace(); } catch (OntowrapException owex) { owex.printStackTrace(); }
// For individuals // For individuals
...@@ -320,17 +332,24 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce ...@@ -320,17 +332,24 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce
} }
double[][] matrix = new double[nbind1][nbind2]; double[][] matrix = new double[nbind1][nbind2];
int i, j; int i, j;
double ival = sim.getIndividualSimilarity(ind1[0],ind2[0]);
for( i=0; i < nbind1; i++ ){ for( i=0; i < nbind1; i++ ){
for( j=0; j < nbind2; j++ ){ for( j=0; j < nbind2; j++ ){
if ( ival != -1. && ival != sim.getIndividualSimilarity(ind1[i],ind2[j] ) ) ival = -1.;
if ( sim.getSimilarity() ) matrix[i][j] = sim.getIndividualSimilarity(ind1[i],ind2[j]);
else
matrix[i][j] = 1 - sim.getIndividualSimilarity(ind1[i],ind2[j]); matrix[i][j] = 1 - sim.getIndividualSimilarity(ind1[i],ind2[j]);
} }
} }
// Pass it to the algorithm // Pass it to the algorithm
if ( ival == -1. ) {
int[][] result = HungarianAlgorithm.hgAlgorithm( matrix, "max" ); int[][] result = HungarianAlgorithm.hgAlgorithm( matrix, "max" );
// Extract the result // Extract the result
for( i=0; i < result.length ; i++ ){ for( i=0; i < result.length ; i++ ){
// The matrix has been destroyed // The matrix has been destroyed
double val = 1 - sim.getIndividualSimilarity(ind1[result[i][0]],ind2[result[i][1]]); double val;
if ( sim.getSimilarity() ) val = sim.getIndividualSimilarity(ind1[result[i][0]],ind2[result[i][1]]);
else val = 1 - sim.getIndividualSimilarity(ind1[result[i][0]],ind2[result[i][1]]);
// JE: here using strict-> is a very good idea. // JE: here using strict-> is a very good idea.
// it means that alignments with 0. similarity // it means that alignments with 0. similarity
// will be excluded from the best match. // will be excluded from the best match.
...@@ -338,6 +357,7 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce ...@@ -338,6 +357,7 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce
addCell( new ObjectCell( (String)null, ind1[result[i][0]], ind2[result[i][1]], BasicRelation.createRelation("="), val ) ); addCell( new ObjectCell( (String)null, ind1[result[i][0]], ind2[result[i][1]], BasicRelation.createRelation("="), val ) );
} }
} }
}
} catch (AlignmentException alex) { alex.printStackTrace(); //} } catch (AlignmentException alex) { alex.printStackTrace(); //}
} catch (OntowrapException owex) { owex.printStackTrace(); } } catch (OntowrapException owex) { owex.printStackTrace(); }
} }
...@@ -399,7 +419,8 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce ...@@ -399,7 +419,8 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce
// for classes // for classes
for ( Object ent1: ontology1().getClasses() ) { for ( Object ent1: ontology1().getClasses() ) {
for ( Object ent2: ontology2().getClasses() ) { for ( Object ent2: ontology2().getClasses() ) {
val = 1 - sim.getClassSimilarity( ent1, ent2 ); if ( sim.getSimilarity() ) val = sim.getClassSimilarity( ent1, ent2 );
else val = 1 - sim.getClassSimilarity( ent1, ent2 );
if ( val > threshold ){ if ( val > threshold ){
cellSet.add( new ObjectCell( (String)null, ent1, ent2, BasicRelation.createRelation("="), val ) ); cellSet.add( new ObjectCell( (String)null, ent1, ent2, BasicRelation.createRelation("="), val ) );
} }
...@@ -414,7 +435,8 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce ...@@ -414,7 +435,8 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce
ConcatenatedIterator(ontology2().getObjectProperties().iterator(), ConcatenatedIterator(ontology2().getObjectProperties().iterator(),
ontology2().getDataProperties().iterator()); ontology2().getDataProperties().iterator());
for ( Object ent2: pit2 ) { for ( Object ent2: pit2 ) {
val = 1 - sim.getPropertySimilarity( ent1, ent2 ); if ( sim.getSimilarity() ) val = sim.getPropertySimilarity( ent1, ent2 );
else val = 1 - sim.getPropertySimilarity( ent1, ent2 );
if ( val > threshold ){ if ( val > threshold ){
cellSet.add( new ObjectCell( (String)null, ent1, ent2, BasicRelation.createRelation("="), val ) ); cellSet.add( new ObjectCell( (String)null, ent1, ent2, BasicRelation.createRelation("="), val ) );
} }
...@@ -427,7 +449,8 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce ...@@ -427,7 +449,8 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce
for( Object ent2: ontology2().getIndividuals() ) { for( Object ent2: ontology2().getIndividuals() ) {
if ( ontology2().getEntityURI( ent2 ) != null ) { if ( ontology2().getEntityURI( ent2 ) != null ) {
val = 1 - sim.getIndividualSimilarity( ent1, ent2 ); if ( sim.getSimilarity() ) val = sim.getIndividualSimilarity( ent1, ent2 );
else val = 1 - sim.getIndividualSimilarity( ent1, ent2 );
if ( val > threshold ){ if ( val > threshold ){
cellSet.add( new ObjectCell( (String)null, ent1, ent2, BasicRelation.createRelation("="), val ) ); cellSet.add( new ObjectCell( (String)null, ent1, ent2, BasicRelation.createRelation("="), val ) );
} }
......
...@@ -48,6 +48,8 @@ import fr.inrialpes.exmo.align.impl.ObjectAlignment; ...@@ -48,6 +48,8 @@ import fr.inrialpes.exmo.align.impl.ObjectAlignment;
public abstract class MatrixMeasure implements Similarity { public abstract class MatrixMeasure implements Similarity {
public boolean similarity = true;
//Momentaneously public //Momentaneously public
public LoadedOntology onto1 = null; public LoadedOntology onto1 = null;
public LoadedOntology onto2 = null; public LoadedOntology onto2 = null;
...@@ -84,26 +86,31 @@ public abstract class MatrixMeasure implements Similarity { ...@@ -84,26 +86,31 @@ public abstract class MatrixMeasure implements Similarity {
} else { } else {
throw new AlignmentException(""); throw new AlignmentException("");
}; };
// Beware, I consider that confidence is similarity
for ( Cell c : oalign ){ for ( Cell c : oalign ){
Object o1 = c.getObject1(); Object o1 = c.getObject1();
if ( onto1.isClass( o1 ) ) { if ( onto1.isClass( o1 ) ) {
Integer i1 = classlist1.get( o1 ); Integer i1 = classlist1.get( o1 );
Integer i2 = classlist2.get( c.getObject2() ); Integer i2 = classlist2.get( c.getObject2() );
if ( i1 != null && i2 != null ) { if ( i1 != null && i2 != null ) {
clmatrix[i1.intValue()][i2.intValue()] = c.getStrength(); if ( similarity )
clmatrix[i1.intValue()][i2.intValue()] = c.getStrength();
else clmatrix[i1.intValue()][i2.intValue()] = 1.-c.getStrength();
} }
} else if ( onto1.isProperty( o1 ) ) { } else if ( onto1.isProperty( o1 ) ) {
Integer i1 = proplist1.get( o1 ); Integer i1 = proplist1.get( o1 );
Integer i2 = proplist2.get( c.getObject2() ); Integer i2 = proplist2.get( c.getObject2() );
if ( i1 != null && i2 != null ) { if ( i1 != null && i2 != null ) {
prmatrix[i1.intValue()][i2.intValue()] = c.getStrength(); if ( similarity )
prmatrix[i1.intValue()][i2.intValue()] = c.getStrength();
else prmatrix[i1.intValue()][i2.intValue()] = 1.-c.getStrength();
} }
} else { } else {
Integer i1 = indlist1.get( o1 ); Integer i1 = indlist1.get( o1 );
Integer i2 = indlist2.get( c.getObject2() ); Integer i2 = indlist2.get( c.getObject2() );
if ( i1 != null && i2 != null ) { if ( i1 != null && i2 != null ) {
indmatrix[i1.intValue()][i2.intValue()] = c.getStrength(); if ( similarity )
indmatrix[i1.intValue()][i2.intValue()] = c.getStrength();
else indmatrix[i1.intValue()][i2.intValue()] = 1.-c.getStrength();
} }
} }
} }
...@@ -238,6 +245,9 @@ public abstract class MatrixMeasure implements Similarity { ...@@ -238,6 +245,9 @@ public abstract class MatrixMeasure implements Similarity {
System.out.println("\n\\end{tabular}"); System.out.println("\n\\end{tabular}");
} }
public boolean getSimilarity() {
return similarity;
}
public void printClassSimilarityMatrix( String type ){ public void printClassSimilarityMatrix( String type ){
printMatrix( nbclass1, classlist1, classlist2, clmatrix ); printMatrix( nbclass1, classlist1, classlist2, clmatrix );
} }
......
...@@ -37,29 +37,41 @@ public interface Similarity ...@@ -37,29 +37,41 @@ public interface Similarity
{ {
// These parameters contains usually: // These parameters contains usually:
// ontology1 and ontology2 // ontology1 and ontology2
// It would be better if they where explicit... /**
// Apparently the initialize also compute the similarity * Is it a similarity or a distance?
*/
public boolean getSimilarity();
// JE: OntoRewr: This should not be in init // JE: OntoRewr: This should not be in init
/**
* Initialize the similarity value with various useful structures
*/
public void initialize( LoadedOntology<Object> onto1, LoadedOntology<Object> onto2 ); public void initialize( LoadedOntology<Object> onto1, LoadedOntology<Object> onto2 );
public void initialize( LoadedOntology<Object> onto1, LoadedOntology<Object> onto2, Alignment align ); public void initialize( LoadedOntology<Object> onto1, LoadedOntology<Object> onto2, Alignment align );
/**
* actually computes the similarity and store it in the adequate structures
*/
public void compute( Properties p ); public void compute( Properties p );
/**
* Accessors to the stored similarity values
*/
public double getClassSimilarity( Object c1, Object c2 ); public double getClassSimilarity( Object c1, Object c2 );
public double getPropertySimilarity( Object p1, Object p2); public double getPropertySimilarity( Object p1, Object p2);
public double getIndividualSimilarity( Object i1, Object i2 ); public double getIndividualSimilarity( Object i1, Object i2 );
/**
* Printers of the obtained similarity values
*/
public void printClassSimilarityMatrix( String type ); public void printClassSimilarityMatrix( String type );
public void printPropertySimilarityMatrix( String type ); public void printPropertySimilarityMatrix( String type );
public void printIndividualSimilarityMatrix( String type ); public void printIndividualSimilarityMatrix( String type );
// New implementation // JE2010: These are used by the generic MatrixMeasure implementation
// JE: this is better as a new implementation. // in which it is sufficient to implement them to solve everything
// however, currently the implementation does not follow it: // However, for more flexibility, it possible to just skip these
// the abstract matrix class provides the get- accessors and the // and implement the measure within compute(p) (see InstanceBasedMatrixMeasure).
// concrete classes implement measure as their computation function.
// This is not clean. What should be done is:
// JE: OntoRewr: to be suppressed
public double measure( Object c1, Object c2 ) throws Exception;
public double classMeasure( Object c1, Object c2 ) throws Exception; public double classMeasure( Object c1, Object c2 ) throws Exception;
public double propertyMeasure( Object p1, Object p2) throws Exception; public double propertyMeasure( Object p1, Object p2) throws Exception;
public double individualMeasure( Object i1, Object i2 ) throws Exception; public double individualMeasure( Object i1, Object i2 ) throws Exception;
......
...@@ -78,6 +78,7 @@ public class ClassStructAlignment extends DistanceAlignment implements Alignment ...@@ -78,6 +78,7 @@ public class ClassStructAlignment extends DistanceAlignment implements Alignment
} }
/** Processing **/ /** Processing **/
// Could better use similarity
public void align( Alignment alignment, Properties params ) throws AlignmentException { public void align( Alignment alignment, Properties params ) throws AlignmentException {
loadInit( alignment ); loadInit( alignment );
honto1 = (HeavyLoadedOntology<Object>)getOntologyObject1(); honto1 = (HeavyLoadedOntology<Object>)getOntologyObject1();
......
...@@ -76,6 +76,7 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align ...@@ -76,6 +76,7 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align
} }
/** Processing **/ /** Processing **/
// Could better use similarity
public void align( Alignment alignment, Properties params ) throws AlignmentException { public void align( Alignment alignment, Properties params ) throws AlignmentException {
loadInit( alignment ); loadInit( alignment );
honto1 = (HeavyLoadedOntology<Object>)getOntologyObject1(); honto1 = (HeavyLoadedOntology<Object>)getOntologyObject1();
...@@ -179,7 +180,7 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align ...@@ -179,7 +180,7 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align
max = propmatrix[i][j]; max = propmatrix[i][j];
} }
} }
if ( found && max < 0.5) { addAlignDistanceCell( proplist1.get(i), proplist2.get(best), "=", max ); } if ( found && max < 0.5) { addAlignCell( proplist1.get(i), proplist2.get(best), "=", 1.-max ); }
} }
if (debug > 0) System.err.print("Computing class distances\n"); if (debug > 0) System.err.print("Computing class distances\n");
// Compute classes distances // Compute classes distances
...@@ -242,7 +243,7 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align ...@@ -242,7 +243,7 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align
max = classmatrix[i][j]; max = classmatrix[i][j];
} }
} }
if ( found && max < 0.5) { addAlignDistanceCell( classlist1.get(i), classlist2.get(best), "=", max ); } if ( found && max < 0.5) { addAlignCell( classlist1.get(i), classlist2.get(best), "=", 1.-max ); }
} }
} }
......
...@@ -49,29 +49,34 @@ public class StringDistAlignment extends DistanceAlignment implements AlignmentP ...@@ -49,29 +49,34 @@ public class StringDistAlignment extends DistanceAlignment implements AlignmentP
Method dissimilarity = null; Method dissimilarity = null;
String methodName = "equalDistance"; String methodName = "equalDistance";
protected class StringDistMatrixMeasure extends MatrixMeasure {
public StringDistMatrixMeasure() {
similarity = false; // This is a distance matrix
}
public double measure( Object o1, Object o2 ) throws Exception {
String s1 = ontology1().getEntityName( o1 );
String s2 = ontology2().getEntityName( o2 );
// Unnamed entity = max distance
if ( s1 == null || s2 == null ) return 1.;
Object[] params = { s1.toLowerCase(), s2.toLowerCase() };
if ( debug > 4 )
System.err.println( "OB:"+s1+" ++ "+s2+" ==> "+dissimilarity.invoke( null, params ));
return ((Double)dissimilarity.invoke( null, params )).doubleValue();
}
public double classMeasure( Object cl1, Object cl2 ) throws Exception {
return measure( cl1, cl2 );
}
public double propertyMeasure( Object pr1, Object pr2 ) throws Exception{
return measure( pr1, pr2 );
}
public double individualMeasure( Object id1, Object id2 ) throws Exception{
return measure( id1, id2 );
}
}
/** Creation **/ /** Creation **/
public StringDistAlignment() { public StringDistAlignment() {
setSimilarity( new MatrixMeasure() { setSimilarity( new StringDistMatrixMeasure() );
public double measure( Object o1, Object o2 ) throws Exception {
String s1 = ontology1().getEntityName( o1 );
String s2 = ontology2().getEntityName( o2 );
// Unnamed entity = max distance
if ( s1 == null || s2 == null ) return 1.;
Object[] params = { s1.toLowerCase(), s2.toLowerCase() };
if ( debug > 4 )
System.err.println( "OB:"+s1+" ++ "+s2+" ==> "+dissimilarity.invoke( null, params ));
return ((Double)dissimilarity.invoke( null, params )).doubleValue();
}
public double classMeasure( Object cl1, Object cl2 ) throws Exception {
return measure( cl1, cl2 );
}
public double propertyMeasure( Object pr1, Object pr2 ) throws Exception{
return measure( pr1, pr2 );
}
public double individualMeasure( Object id1, Object id2 ) throws Exception{
return measure( id1, id2 );
}
} );
setType("**"); setType("**");
} }
...@@ -90,7 +95,7 @@ public class StringDistAlignment extends DistanceAlignment implements AlignmentP ...@@ -90,7 +95,7 @@ public class StringDistAlignment extends DistanceAlignment implements AlignmentP
throw new AlignmentException( "Unknown method for StringDistAlignment : "+params.getProperty("stringFunction"), e ); throw new AlignmentException( "Unknown method for StringDistAlignment : "+params.getProperty("stringFunction"), e );
} }
// JE2010: Strange: why does it is not equivalent to call // JE2010: Strange: why is it not equivalent to call
// super.align( alignment, params ) // super.align( alignment, params )
// Load initial alignment // Load initial alignment
loadInit( alignment ); loadInit( alignment );
...@@ -102,6 +107,7 @@ public class StringDistAlignment extends DistanceAlignment implements AlignmentP ...@@ -102,6 +107,7 @@ public class StringDistAlignment extends DistanceAlignment implements AlignmentP
getSimilarity().compute( params ); getSimilarity().compute( params );
// Print matrix if asked // Print matrix if asked
params.setProperty( "algName", getClass()+"/"+methodName );
if ( params.getProperty("printMatrix") != null ) printDistanceMatrix( params ); if ( params.getProperty("printMatrix") != null ) printDistanceMatrix( params );
// Extract alignment // Extract alignment
......
...@@ -77,6 +77,7 @@ public class StrucSubsDistAlignment extends DistanceAlignment implements Alignme ...@@ -77,6 +77,7 @@ public class StrucSubsDistAlignment extends DistanceAlignment implements Alignme
} }
/** Processing **/ /** Processing **/
// Could better use similarity
public void align( Alignment alignment, Properties params ) throws AlignmentException { public void align( Alignment alignment, Properties params ) throws AlignmentException {
loadInit( alignment ); loadInit( alignment );
honto1 = (HeavyLoadedOntology<Object>)getOntologyObject1(); honto1 = (HeavyLoadedOntology<Object>)getOntologyObject1();
...@@ -182,7 +183,7 @@ public class StrucSubsDistAlignment extends DistanceAlignment implements Alignme ...@@ -182,7 +183,7 @@ public class StrucSubsDistAlignment extends DistanceAlignment implements Alignme
max = propmatrix[i][j]; max = propmatrix[i][j];
} }
} }
if ( found ) { addAlignDistanceCell( proplist1.get(i), proplist2.get(best), "=", max ); } if ( found ) { addAlignCell( proplist1.get(i), proplist2.get(best), "=", 1.-max ); }
} }
if (debug > 0) System.err.print("Computing class distances\n"); if (debug > 0) System.err.print("Computing class distances\n");
...@@ -254,7 +255,7 @@ public class StrucSubsDistAlignment extends DistanceAlignment implements Alignme ...@@ -254,7 +255,7 @@ public class StrucSubsDistAlignment extends DistanceAlignment implements Alignme
max = classmatrix[i][j]; max = classmatrix[i][j];
} }
} }
if ( found ) { addAlignDistanceCell( classlist1.get(i), classlist2.get(best), "=", max ); } if ( found ) { addAlignCell( classlist1.get(i), classlist2.get(best), "=", 1.-max ); }
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment