|
TestDiffer |
|
1 /* 2 * 3 * Copyright (c) 1998-2001, The University of Sheffield. 4 * 5 * This file is part of GATE (see http://gate.ac.uk/), and is free 6 * software, licenced under the GNU Library General Public License, 7 * Version 2, June 1991 (in the distribution as file licence.html, 8 * and also available at http://gate.ac.uk/gate/licence.html). 9 * 10 * Valentin Tablan, 26/Feb/2002 11 * 12 * $Id: TestDiffer.java,v 1.2 2003/01/30 18:36:18 valyt Exp $ 13 */ 14 15 package gate.util; 16 17 import java.util.*; 18 import java.io.*; 19 import java.net.*; 20 21 import junit.framework.*; 22 import java.lang.reflect.*; 23 24 import gate.*; 25 import gate.util.*; 26 27 public class TestDiffer extends TestCase{ 28 /** Construction */ 29 public TestDiffer(String name) { super(name); } 30 31 /** Fixture set up */ 32 public void setUp() { 33 } // setUp 34 35 /** Put things back as they should be after running tests. 36 */ 37 public void tearDown() throws Exception { 38 } // tearDown 39 40 /** Test suite routine for the test runner */ 41 public static Test suite() { 42 return new TestSuite(TestDiffer.class); 43 } // suite 44 45 /** Jdk compiler */ 46 public void testDiffer() throws Exception { 47 Document doc = Factory.newDocument( 48 new URL(gate.corpora.TestDocument.getTestServerName() + 49 "tests/ft-bt-03-aug-2001.html"), 50 "windows-1252" 51 ); 52 AnnotationSet annSet = doc.getAnnotations(); 53 //create 100 annotations 54 FeatureMap features = Factory.newFeatureMap(); 55 features.put("type", "BAR"); 56 for (int i = 0; i < 100; i++) { 57 annSet.add(new Long(i * 10), new Long( (i + 1) * 10), "Foo", features); 58 } 59 List keySet = new ArrayList(annSet); 60 List responseSet = new ArrayList(annSet); 61 62 //check 100% Precision and recall 63 AnnotationDiffer differ = new AnnotationDiffer(); 64 differ.setSignificantFeaturesSet(null); 65 differ.calculateDiff(keySet, responseSet); 66 differ.sanityCheck(); 67 if(DEBUG) differ.printMissmatches(); 68 double value = differ.getPrecisionStrict(); 69 Assert.assertEquals("Precision Strict: " + value + " instead of 1!", 70 1, value, 0); 71 value = differ.getRecallStrict(); 72 Assert.assertEquals("Recall Strict: " + value + " instead of 1!", 73 1, value, 0); 74 value = differ.getPrecisionLenient(); 75 Assert.assertEquals("Precision Lenient: " + value + " instead of 1!", 76 1, value, 0); 77 value = differ.getRecallLenient(); 78 Assert.assertEquals("Recall Lenient: " + value + " instead of 1!", 79 1, value, 0); 80 81 //check low precision 82 Integer id = annSet.add(new Long(2), new Long(4), "Foo", features); 83 Annotation falsePositive = annSet.get(id); 84 responseSet.add(falsePositive); 85 differ.calculateDiff(keySet, responseSet); 86 differ.sanityCheck(); 87 if(DEBUG) differ.printMissmatches(); 88 value = differ.getPrecisionStrict(); 89 Assert.assertEquals("Precision Strict: " + value + " instead of .99!", 90 .99, value, .001); 91 //recall should still be 100% 92 value = differ.getRecallStrict(); 93 Assert.assertEquals("Recall Strict: " + value + " instead of 1!", 94 1, value, 0); 95 value = differ.getRecallLenient(); 96 Assert.assertEquals("Recall Lenient: " + value + " instead of 1!", 97 1, value, 0); 98 99 100 //check low recall 101 responseSet.remove(falsePositive); 102 keySet.add(falsePositive); 103 differ.calculateDiff(keySet, responseSet); 104 differ.sanityCheck(); 105 if(DEBUG) differ.printMissmatches(); 106 value = differ.getRecallStrict(); 107 Assert.assertEquals("Recall Strict: " + value + " instead of .99!", 108 .99, value, .001); 109 //precision should still be 100% 110 value = differ.getPrecisionStrict(); 111 Assert.assertEquals("Precision Strict: " + value + " instead of 1!", 112 1, value, 0); 113 value = differ.getPrecisionLenient(); 114 Assert.assertEquals("Precision Lenient: " + value + " instead of 1!", 115 1, value, 0); 116 } 117 118 /** Debug flag */ 119 private static final boolean DEBUG = false; 120 121 }
|
TestDiffer |
|