diff --git a/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java b/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java index 116b18234e5164e71bc1a802138519868bdbaba2..14930a0a3f28aeb155cda52d3a12063bd322b8c2 100644 --- a/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java @@ -84,7 +84,7 @@ public class DistanceAlignment extends BasicAlignment implements AlignmentProces return (1 - getAlignedStrength1(ob)); }; public double getAlignedDistance2( Object ob ) throws AlignmentException{ - return (1 - getAlignedStrength1(ob)); + return (1 - getAlignedStrength2(ob)); }; /** @@ -96,7 +96,8 @@ public class DistanceAlignment extends BasicAlignment implements AlignmentProces public void align( Alignment alignment, Parameters params ) throws AlignmentException, OWLException { if ( params.getParameter("type") != null ) setType((String)params.getParameter("type")); - else setType("**"); + // This is a 1:1 alignment in fact + else setType("11"); getSimilarity().initialize( (OWLOntology)getOntology1(), (OWLOntology)getOntology2(), alignment ); getSimilarity().compute( params ); @@ -219,18 +220,52 @@ public class DistanceAlignment extends BasicAlignment implements AlignmentProces double val = 0; //TreeSet could be replaced by something else //The comparator must always tell that things are different! + /*SortedSet cellSet = new TreeSet( + new Comparator() { + public int compare( Object o1, Object o2 ) + throws ClassCastException{ + if ( o1 instanceof Cell + && o2 instanceof Cell ) { + if ( ((Cell)o1).getStrength() > ((Cell)o2).getStrength() ){ + return -1; + } else { return 1; } + } else { + throw new ClassCastException(); + }}});*/ SortedSet cellSet = new TreeSet( new Comparator() { public int compare( Object o1, Object o2 ) throws ClassCastException{ + try { + //System.err.println(((Cell)o1).getObject1()+" -- "+((Cell)o1).getObject2()+" // "+((Cell)o2).getObject1()+" -- "+((Cell)o2).getObject2()); if ( o1 instanceof Cell && o2 instanceof Cell ) { if ( ((Cell)o1).getStrength() > ((Cell)o2).getStrength() ){ return -1; + } else if ( ((Cell)o1).getStrength() < ((Cell)o2).getStrength() ){ + return 1; + } else if ( (((OWLEntity)((Cell)o1).getObject1()).getURI().getFragment() == null) + || (((OWLEntity)((Cell)o2).getObject1()).getURI().getFragment() == null) ) { + return -1; + } else if ( ((OWLEntity)((Cell)o1).getObject1()).getURI().getFragment().compareTo(((OWLEntity)((Cell)o2).getObject1()).getURI().getFragment()) > 0) { + return -1; + } else if ( ((OWLEntity)((Cell)o1).getObject1()).getURI().getFragment().compareTo(((OWLEntity)((Cell)o2).getObject1()).getURI().getFragment()) < 0 ) { + return 1; + } else if ( (((OWLEntity)((Cell)o1).getObject2()).getURI().getFragment() == null) + || (((OWLEntity)((Cell)o2).getObject2()).getURI().getFragment() == null) ) { + return -1; + } else if ( ((OWLEntity)((Cell)o1).getObject2()).getURI().getFragment().compareTo(((OWLEntity)((Cell)o2).getObject2()).getURI().getFragment()) > 0) { + return -1; + // On va supposer qu'ils n'ont pas le meme nom } else { return 1; } } else { throw new ClassCastException(); - }}}); + } + } catch ( OWLException e) { + e.printStackTrace(); return 0;} + } + } + ); try { // Get all the matrix above threshold in the SortedSet @@ -284,9 +319,9 @@ public class DistanceAlignment extends BasicAlignment implements AlignmentProces Cell cell = (Cell)it.next(); ent1 = (OWLEntity)cell.getObject1(); ent2 = (OWLEntity)cell.getObject2(); - if ( (getAlignCell1( ent1 ) == null) && (getAlignCell2( ent2 ) == null) ){ + if ( (getAlignCells1( ent1 ) == null) && (getAlignCells2( ent2 ) == null) ){ // The cell is directly added! - addCell( ent1, ent2, cell ); + addCell( cell ); } }; diff --git a/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java index e7979c1f3592e29432d7f309e98a520e6cf926a3..56a711d575aeb8db382efc24cc280e507c69b6ef 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java @@ -130,12 +130,19 @@ public class ClassStructAlignment extends DistanceAlignment implements Alignment // check that there is a correspondance // in list of class2 atts and add their weights for ( Iterator prp = properties1.iterator(); prp.hasNext(); ){ - Cell cell = getAlignCell1( (OWLEntity)prp.next() ); - if ( cell != null ) { - if ( properties2.contains((Object)cell.getObject2() ) ) { - attsum = attsum + 1 - cell.getStrength(); + Set s2 = getAlignCells1( (OWLEntity)prp.next() ); + // Find the property with the higest similarity + // that is matched here + double currentValue = 0.; + for( Iterator it2 = s2.iterator(); it2.hasNext(); ){ + Cell c2 = (Cell)it2.next(); + if ( properties2.contains((Object)c2.getObject2() ) ) { + double val = c2.getStrength(); + if ( val > currentValue ) + currentValue = val; } } + attsum = attsum + 1 - currentValue; } classmatrix[i][j] = classmatrix[i][j] + pic2 * (2 * attsum / (nba1 + nba2)); diff --git a/src/fr/inrialpes/exmo/align/impl/method/StrucSubsDistAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/StrucSubsDistAlignment.java index 5e09a350901423d39f132c4d0f9221fa62d96c98..6008219f377f58bb2771c940c05168518f27c955 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/StrucSubsDistAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/StrucSubsDistAlignment.java @@ -195,12 +195,19 @@ public class StrucSubsDistAlignment extends DistanceAlignment implements Alignme // check that there is a correspondance // in list of class2 atts and add their weights for ( Iterator prp = properties1.iterator(); prp.hasNext(); ){ - Cell cell = getAlignCell1( (OWLEntity)prp.next() ); - if ( cell != null ) { - if ( properties2.contains((Object)cell.getObject2() ) ) { - attsum = attsum + 1 - cell.getStrength(); + Set s2 = getAlignCells1( (OWLEntity)prp.next() ); + // Find the property with the higest similarity + // that is matched here + double currentValue = 0.; + for( Iterator it2 = s2.iterator(); it2.hasNext(); ){ + Cell c2 = (Cell)it2.next(); + if ( properties2.contains((Object)c2.getObject2() ) ) { + double val = c2.getStrength(); + if ( val > currentValue ) + currentValue = val; } } + attsum = attsum + 1 - currentValue; } classmatrix[i][j] = classmatrix[i][j] + pic2 * (2 * attsum / (nba1 + nba2)); diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java index bc016c064e917c3a5da5576e4d6374e53ed308f9..ffc2bb0d4dc058d6165ee8492e2c29fa055fde10 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java @@ -89,7 +89,7 @@ public class OWLAxiomsRendererVisitor implements AlignmentVisitor URI entity1URI = null; try { // Not very good but we failed to think subsumed from the first shot. - if ( Class.forName("fr.inrialpes.exmo.align.impl.rel.SubsumedRelation").isInstance(cell.getRelation()) ) { + if ( cell.getRelation() instanceof SubsumedRelation ){ onto1 = (OWLOntology)alignment.getOntology2(); entity1URI = ((OWLEntity)cell.getObject2()).getURI(); } else { @@ -116,7 +116,6 @@ public class OWLAxiomsRendererVisitor implements AlignmentVisitor writer.print("\n"); } catch (OWLException e) { throw new AlignmentException("getURI problem", e); } - catch (ClassNotFoundException e) { throw new AlignmentException("Class no found", e); }; } public void visit( EquivRelation rel ) throws AlignmentException { OWLOntology onto2 = (OWLOntology)alignment.getOntology2(); diff --git a/src/fr/inrialpes/exmo/align/parser/AlignmentParser.java b/src/fr/inrialpes/exmo/align/parser/AlignmentParser.java index a79c67abb96850949da163054fbccd9f03ca637e..26f7deb2a0a037830c755f97fc96a3c71c99e4a0 100644 --- a/src/fr/inrialpes/exmo/align/parser/AlignmentParser.java +++ b/src/fr/inrialpes/exmo/align/parser/AlignmentParser.java @@ -1,5 +1,6 @@ /* * $Id$ + * MULT * * Copyright (C) 2003-2005 INRIA Rhône-Alpes. * @@ -62,6 +63,7 @@ import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.AlignmentException; import fr.inrialpes.exmo.align.impl.BasicAlignment; +import fr.inrialpes.exmo.align.impl.MultipleAlignment; /** * This class allows the creation of a parser for an Alignment file. @@ -105,7 +107,9 @@ public class AlignmentParser extends DefaultHandler { * This is a pitty but the idea of creating a particular alignment * is not in accordance with using an interface. */ - protected Alignment alignment = null; + //JE: mult + //protected Alignment alignment = null; + protected MultipleAlignment alignment = null; /** * the content found as text... @@ -248,7 +252,9 @@ public class AlignmentParser extends DefaultHandler { } else if (pName.equals("level")) { } else if (pName.equals("xml")) { } else if (pName.equals("Alignment")) { - alignment = new BasicAlignment(); + //JE: multiple + //alignment = new BasicAlignment(); + alignment = new MultipleAlignment(); } else { if ( debugMode > 0 ) System.err.println("[AlignmentParser] Unknown element name : "+pName); //throw new SAXException("[AlignmentParser] Unknown element name : "+pName); @@ -313,8 +319,10 @@ public class AlignmentParser extends DefaultHandler { } if ( cl1 == null || cl2 == null ) { // Maybe we could just print this out and fail in the end. - throw new SAXException( "Missing entity "+cl1+" "+cl2 ); } - if ( measure == null || relation == null ){ + //throw new SAXException( "Missing entity "+cl1+" "+cl2 ); + // The cell is void + System.err.println("Warning (cell voided), missing entity "+cl1+" "+cl2 ); + } else if ( measure == null || relation == null ){ cell = alignment.addAlignCell( cl1, cl2); } else { cell = alignment.addAlignCell( cl1, cl2, relation, Double.parseDouble(measure) );} diff --git a/src/fr/inrialpes/exmo/align/util/GroupEval.java b/src/fr/inrialpes/exmo/align/util/GroupEval.java index c27bddd9e429f7d1d4bae9f7313ccde8c620f49f..f439cc89581759b62f44c2a62a5b34f31efb6dce 100644 --- a/src/fr/inrialpes/exmo/align/util/GroupEval.java +++ b/src/fr/inrialpes/exmo/align/util/GroupEval.java @@ -61,9 +61,9 @@ import gnu.getopt.Getopt; import fr.inrialpes.exmo.align.parser.AlignmentParser; -/** A basic class for an OWL ontology alignment processing. The processor - will parse ontologies, align them and renderings the resulting alignment. - Command synopsis is as follows: +/** A basic class for synthesizing the results of a set of alignments provided by + different algorithms. The output is a table showing various classical measures + for each test and for each algorithm. Average is also computed. <pre> java -cp procalign.jar fr.inrialpes.exmo.align.util.GroupEval [options] @@ -79,8 +79,11 @@ import fr.inrialpes.exmo.align.parser.AlignmentParser; -t output --type=output: xml/tex/html/ascii </pre> - If output is - requested (<CODE>-o</CODE> flags), then output will be written to + The input is taken in the current directory in a set of subdirectories (one per + test which will be rendered by a line) each directory contains a number of + alignment files (one per algorithms which will be renderer as a column). + + If output is requested (<CODE>-o</CODE> flags), then output will be written to <CODE>output</CODE> if present, stdout by default. <pre> @@ -110,7 +113,7 @@ public class GroupEval { } public static void run(String[] args) throws Exception { - String listFile = "std,ssda5,nea,edna5,sdna5,karlsruhe,karlsruhe2,fujitsu,umontreal,stanford"; + String listFile = ""; LongOpt[] longopts = new LongOpt[8]; loaded = new Hashtable(); @@ -166,6 +169,7 @@ public class GroupEval { } } + // JE: StringTokenizer is obsoleted in Java 1.4 in favor of split: to change listAlgo = new Vector(); StringTokenizer st = new StringTokenizer(listFile,","); while (st.hasMoreTokens()) { @@ -337,12 +341,9 @@ public class GroupEval { // For each record print the values <td>bla</td> Enumeration f = test.elements(); f.nextElement(); - System.err.println(" Test#"+test); for( int k = 0 ; f.hasMoreElements() ; k++) { PRecEvaluator eval = (PRecEvaluator)f.nextElement(); if ( eval != null ){ - // JE: It might seem that the analogy with kilometers is not correct? This is because of when we have found=0 then the rate is 0, then the value must worsen... which is not the case with our new stuff: - // I must reconstuct P & R: this is doable. // iterative H-means computation if ( nexpected == -1 ){ nexpected = eval.getExpected(); @@ -356,20 +357,6 @@ public class GroupEval { int ocorrect = correctVect[k]; correctVect[k] = ocorrect + ncorrect; - //System.err.println(" Algo "+k+" hprec[k-1]="+hMeansPrec[k]+" exp[k-1]="+oexpected+" Prec[k]="+eval.getPrecision()+" exp[k]="+nexpected); - // JE: not sure it is precision or recall - //if ( eval.getRecall() == 0 ) { - // hMeansRec[k] = (expected)/((oexpected/hMeansRec[k])); - //} else { - // hMeansRec[k] = (expected)/((nexpected/eval.getRecall())+(oexpected/hMeansRec[k])); - //}; - //if ( eval.getPrecision() == 0 ){ - // hMeansPrec[k] = (foundVect[k])/((ofound/hMeansPrec[k])); - //} else { - // hMeansPrec[k] = (foundVect[k])/((nfound/eval.getPrecision())+(ofound/hMeansPrec[k])); - //}; - // Update data structures - //System.err.println(" hprec[k]="+hMeansPrec[k]+" exp[k]="+expected); for ( int i = 0 ; i < fsize; i++){ writer.print("<td>"); if ( format.charAt(i) == 'p' ) { @@ -443,7 +430,6 @@ public class GroupEval { public static void usage() { System.out.println("usage: GroupEval [options]"); System.out.println("options are:"); - System.out.println("\t--impl=className -i classname\t\tUse the given alignment implementation."); System.out.println("\t--format=prfmo -r prfmo\tSpecifies the output order (precision/recall/fallout/f-measure/overall)"); System.out.println("\t--dominant=algo -s algo\tSpecifies if dominant columns are algorithms or measure"); System.out.println("\t--type=html|xml|tex|ascii -t html|xml|tex|ascii\tSpecifies the output format"); diff --git a/src/fr/inrialpes/exmo/align/util/Procalign.java b/src/fr/inrialpes/exmo/align/util/Procalign.java index 2de765efecd0b7cfc33c8bcfb8c04c3228f900bf..a9da4b18199c11bb7df8cadf5215076cf3383b07 100644 --- a/src/fr/inrialpes/exmo/align/util/Procalign.java +++ b/src/fr/inrialpes/exmo/align/util/Procalign.java @@ -1,5 +1,6 @@ /* * $Id$ + * MULT * * Copyright (C) 2003 The University of Manchester * Copyright (C) 2003 The University of Karlsruhe