1
14
15 package gate.util;
16
17 import java.net.URL;
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import junit.framework.*;
22
23 import gate.*;
24
25 public class TestDiffer extends TestCase{
26
27 public TestDiffer(String name) { super(name); }
28
29
30 public void setUp() {
31 }
33
35 public void tearDown() throws Exception {
36 }
38
39 public static Test suite() {
40 return new TestSuite(TestDiffer.class);
41 }
43
44 public void testDiffer() throws Exception {
45 Document doc = Factory.newDocument(
46 new URL(gate.corpora.TestDocument.getTestServerName() +
47 "tests/ft-bt-03-aug-2001.html"),
48 "windows-1252"
49 );
50 AnnotationSet annSet = doc.getAnnotations();
51 FeatureMap features = Factory.newFeatureMap();
53 features.put("type", "BAR");
54 for (int i = 0; i < 100; i++) {
55 annSet.add(new Long(i * 10), new Long( (i + 1) * 10), "Foo", features);
56 }
57 List keySet = new ArrayList(annSet);
58 List responseSet = new ArrayList(annSet);
59
60 AnnotationDiffer differ = new AnnotationDiffer();
62 differ.setSignificantFeaturesSet(null);
63 differ.calculateDiff(keySet, responseSet);
64 differ.sanityCheck();
65 if(DEBUG) differ.printMissmatches();
66 double value = differ.getPrecisionStrict();
67 Assert.assertEquals("Precision Strict: " + value + " instead of 1!",
68 1, value, 0);
69 value = differ.getRecallStrict();
70 Assert.assertEquals("Recall Strict: " + value + " instead of 1!",
71 1, value, 0);
72 value = differ.getPrecisionLenient();
73 Assert.assertEquals("Precision Lenient: " + value + " instead of 1!",
74 1, value, 0);
75 value = differ.getRecallLenient();
76 Assert.assertEquals("Recall Lenient: " + value + " instead of 1!",
77 1, value, 0);
78
79 Integer id = annSet.add(new Long(2), new Long(4), "Foo", features);
81 Annotation falsePositive = annSet.get(id);
82 responseSet.add(falsePositive);
83 differ.calculateDiff(keySet, responseSet);
84 differ.sanityCheck();
85 if(DEBUG) differ.printMissmatches();
86 value = differ.getPrecisionStrict();
87 Assert.assertEquals("Precision Strict: " + value + " instead of .99!",
88 .99, value, .001);
89 value = differ.getRecallStrict();
91 Assert.assertEquals("Recall Strict: " + value + " instead of 1!",
92 1, value, 0);
93 value = differ.getRecallLenient();
94 Assert.assertEquals("Recall Lenient: " + value + " instead of 1!",
95 1, value, 0);
96
97
98 responseSet.remove(falsePositive);
100 keySet.add(falsePositive);
101 differ.calculateDiff(keySet, responseSet);
102 differ.sanityCheck();
103 if(DEBUG) differ.printMissmatches();
104 value = differ.getRecallStrict();
105 Assert.assertEquals("Recall Strict: " + value + " instead of .99!",
106 .99, value, .001);
107 value = differ.getPrecisionStrict();
109 Assert.assertEquals("Precision Strict: " + value + " instead of 1!",
110 1, value, 0);
111 value = differ.getPrecisionLenient();
112 Assert.assertEquals("Precision Lenient: " + value + " instead of 1!",
113 1, value, 0);
114 }
115
116
117 private static final boolean DEBUG = false;
118
119 }