From 5cb108a253c432c91c6096f29d7f2717734f998d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr>
Date: Mon, 12 Jul 2010 19:47:11 +0000
Subject: [PATCH] - implemented alignment checking when creating an evaluator -
 improved DiffEvaluator layout

---
 .../exmo/align/impl/BasicEvaluator.java       |  11 +-
 .../exmo/align/impl/eval/DiffEvaluator.java   | 151 +++++++++---------
 .../exmo/align/impl/eval/ExtPREvaluator.java  |   2 +-
 3 files changed, 81 insertions(+), 83 deletions(-)

diff --git a/src/fr/inrialpes/exmo/align/impl/BasicEvaluator.java b/src/fr/inrialpes/exmo/align/impl/BasicEvaluator.java
index d14ca846..75254980 100644
--- a/src/fr/inrialpes/exmo/align/impl/BasicEvaluator.java
+++ b/src/fr/inrialpes/exmo/align/impl/BasicEvaluator.java
@@ -1,7 +1,7 @@
 /*
  * $Id$
  *
- * Copyright (C) INRIA, 2004, 2007
+ * Copyright (C) INRIA, 2004, 2007-2008, 2010
  *
  * 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
@@ -21,6 +21,7 @@
 package fr.inrialpes.exmo.align.impl; 
 
 import org.semanticweb.owl.align.Alignment;
+import org.semanticweb.owl.align.AlignmentException;
 import org.semanticweb.owl.align.Evaluator;
 
 import java.io.PrintWriter;
@@ -30,9 +31,6 @@ import java.io.PrintWriter;
  * This function implements a simple weighted symetric difference.
  * There are many different things to compute in such a function...
  * Add classification per type of objects (Ind, Class, Prop...)
- *
- * @author Jerome Euzenat
- * @version $Id$ 
  */
 
 public abstract class BasicEvaluator implements Evaluator {
@@ -41,7 +39,10 @@ public abstract class BasicEvaluator implements Evaluator {
     protected Alignment align2;
 
     /** Creation **/
-    public BasicEvaluator( Alignment align1, Alignment align2 ){
+    public BasicEvaluator( Alignment align1, Alignment align2 ) throws AlignmentException {
+	if ( !align1.getOntology1URI().equals( align2.getOntology1URI() )
+	     || !align1.getOntology2URI().equals( align2.getOntology2URI() ) )
+	    throw new AlignmentException( "The alignments must align the same ontologies\n" );
 	this.align1 = align1;
 	this.align2 = align2;
     }
diff --git a/src/fr/inrialpes/exmo/align/impl/eval/DiffEvaluator.java b/src/fr/inrialpes/exmo/align/impl/eval/DiffEvaluator.java
index 58eea7bb..37a526b5 100644
--- a/src/fr/inrialpes/exmo/align/impl/eval/DiffEvaluator.java
+++ b/src/fr/inrialpes/exmo/align/impl/eval/DiffEvaluator.java
@@ -45,7 +45,6 @@ import java.net.URI;
  * This function implements Precision/Recall/Fallout. The first alignment
  * is thus the expected one.
  *
- * @author Jerome Euzenat
  * @version $Id$ 
  */
 
@@ -76,67 +75,66 @@ public class DiffEvaluator extends BasicEvaluator implements Evaluator {
     }
 
     public void diff(){
-	  
-            // True and false positives
-	    try {
-                   boolean has = false;
-                   // Alignment
-		   for ( Cell c1 : this.align2 ) {
-		              URI uri1_1 = c1.getObject1AsURI();
-		   	      URI uri1_2 = c1.getObject2AsURI();
-                              String rel1 = c1.getRelation().getRelation().toString();
-                              has = false; 
-                              // Reference alignment
-		   	      for( Cell c2 : this.align1) {
-		   	        	URI uri2_1 = c2.getObject1AsURI();
-		   	        	URI uri2_2 = c2.getObject2AsURI();
-                                        String rel2 = c2.getRelation().getRelation().toString();
-		   		        if ( (uri1_1.toString().equals(uri2_1.toString())) && 
-		   		             (uri1_2.toString().equals(uri2_2.toString())) && 
-                                             (rel1.equals(rel2))
-                                           ) {
-		   		             this.truepositive.add(c1);
-                                             has = true;
-                                             break;
-		   		        }
-		   	     }
-                             if (!has) {
-			          this.falsepositive.add(c1);  
-			     }
-		   }
-	    } catch (Exception e) {
-		     e.printStackTrace(); 
-            }
-   
-    	    // False negative
- 	    try {
-                   boolean has;
-	           // Reference alignment
-                   for ( Cell c1 : this.align1 ) {
-	   	              URI uri1_1 = c1.getObject1AsURI();
-	   	              URI uri1_2 = c1.getObject2AsURI();
-                              String rel1 = c1.getRelation().getRelation().toString();
-	   	              has = false;
-                              // Alignment
-	   	              for( Cell c2 : this.align2) {
-	   	        	        URI uri2_1 = c2.getObject1AsURI();
-	   	        	        URI uri2_2 = c2.getObject2AsURI();
-                                        String rel2 = c2.getRelation().getRelation().toString();
-	   		                if ( (uri1_1.toString().equals(uri2_1.toString())) && 
-	   		        	     (uri1_2.toString().equals(uri2_2.toString())) &&
-                                             (rel1.equals(rel2))    
-                                            ) {
-	   		        	       has = true;
-	   		        	       break;
-	   		                }
-	   		     }
-	   	             if (!has) {
-	   	        	 this.falsenegative.add(c1); 
-	   	             }
-	   	   }
-	       } catch (Exception e) {
-	    	       e.printStackTrace(); 
-	       }
+	// True and false positives
+	try {
+	    boolean has = false;
+	    // Alignment
+	    for ( Cell c1 : this.align2 ) {
+		URI uri1_1 = c1.getObject1AsURI();
+		URI uri1_2 = c1.getObject2AsURI();
+		String rel1 = c1.getRelation().getRelation().toString();
+		has = false; 
+		// Reference alignment
+		for( Cell c2 : this.align1) {
+		    URI uri2_1 = c2.getObject1AsURI();
+		    URI uri2_2 = c2.getObject2AsURI();
+		    String rel2 = c2.getRelation().getRelation().toString();
+		    if ( (uri1_1.toString().equals(uri2_1.toString())) && 
+			 (uri1_2.toString().equals(uri2_2.toString())) && 
+			 (rel1.equals(rel2))
+			 ) {
+			truepositive.add(c1);
+			has = true;
+			break;
+		    }
+		}
+		if (!has) {
+		    falsepositive.add(c1);  
+		}
+	    }
+	} catch (Exception e) {
+	    e.printStackTrace(); 
+	}
+	
+	// False negative
+	try {
+	    boolean has;
+	    // Reference alignment
+	    for ( Cell c1 : this.align1 ) {
+		URI uri1_1 = c1.getObject1AsURI();
+		URI uri1_2 = c1.getObject2AsURI();
+		String rel1 = c1.getRelation().getRelation().toString();
+		has = false;
+		// Alignment
+		for( Cell c2 : this.align2) {
+		    URI uri2_1 = c2.getObject1AsURI();
+		    URI uri2_2 = c2.getObject2AsURI();
+		    String rel2 = c2.getRelation().getRelation().toString();
+		    if ( (uri1_1.toString().equals(uri2_1.toString())) && 
+			 (uri1_2.toString().equals(uri2_2.toString())) &&
+			 (rel1.equals(rel2))    
+			 ) {
+			has = true;
+			break;
+		    }
+		}
+		if (!has) {
+		    falsenegative.add(c1); 
+		}
+	    }
+	} catch (Exception e) {
+	    e.printStackTrace(); 
+	}
     }
 
    public double eval( Properties params ) throws AlignmentException {
@@ -153,27 +151,26 @@ public class DiffEvaluator extends BasicEvaluator implements Evaluator {
 	String result = "";
 	result += "  <div  xmlns:"+Namespace.ATLMAP.shortCut+"='"+Namespace.ATLMAP.prefix+"' typeof=\""+Namespace.ATLMAP.shortCut+":output\" href=''>";
         result += "     <dl>";
-        result += writeCellsHTML(this.truepositive,  "Correct correspondences");
-        result += writeCellsHTML(this.falsepositive, "Incorrect correspondences");
-        result += writeCellsHTML(this.falsenegative, "Missing correspondences");
+        result += writeCellsHTML( truepositive,  "Correct correspondences");
+        result += writeCellsHTML( falsepositive, "Incorrect correspondences");
+        result += writeCellsHTML( falsenegative, "Missing correspondences");
         result += "     </dl>\n  </div>\n";
         return result;
     }
 
 
     private String writeCellsHTML(Set<Cell> set, String what) { 
-            String result = ""; 
-            try {
-            	Iterator<Cell> i = set.iterator();
-            	result += "              <dt> " + what + "</dt>\n";
-            	while (i.hasNext()) {
-                	   Cell c = i.next();
-	              	   result +=  "                        <dd>" + c.getObject1AsURI() + " " + c.getRelation().getRelation() + " " +  c.getObject2AsURI() + "</dd>\n"; 
-                }
-            } catch (AlignmentException e) {
-                      e.printStackTrace(); 
-            }
-            return result;  
+	String result = ""; 
+	try {
+	    result += "              <dt> " + what + "</dt><dd>\n";
+	    for ( Cell c : set ){
+		result +=  "                        " + c.getObject1AsURI() + " " + c.getRelation().getRelation() + " " +  c.getObject2AsURI() + "<br />\n"; 
+	    }
+	    result += "</dd>\n";
+	} catch (AlignmentException e) {
+	    e.printStackTrace(); 
+	}
+	return result;  
     }
 
 
diff --git a/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java b/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java
index a15ab83d..13f892ce 100644
--- a/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java
+++ b/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java
@@ -77,7 +77,7 @@ public class ExtPREvaluator extends BasicEvaluator implements Evaluator {
     private double orientsimilarity = 0;
 
     /** Creation **/
-    public ExtPREvaluator(Alignment align1, Alignment align2) {
+    public ExtPREvaluator(Alignment align1, Alignment align2) throws AlignmentException {
 	super(align1, align2);
     }
 
-- 
GitLab