MCPcopy Create free account
hub / github.com/GateNLP/gate-core / testDiffer

Method testDiffer

src/test/java/gate/util/TestDiffer.java:49–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

47 } // tearDown
48
49 public void testDiffer() throws Exception {
50 Document doc = Factory.newDocument(
51 new URL(gate.corpora.TestDocument.getTestServerName() +
52 "tests/ft-bt-03-aug-2001.html"),
53 "windows-1252"
54 );
55 AnnotationSet annSet = doc.getAnnotations();
56 //create 100 annotations
57 FeatureMap features = Factory.newFeatureMap();
58 features.put("type", "BAR");
59 for (int i = 0; i < 100; i++) {
60 annSet.add(new Long(i * 10), new Long( (i + 1) * 10), "Foo", features);
61 }
62 List<Annotation> keySet = new ArrayList<Annotation>(annSet);
63 List<Annotation> responseSet = new ArrayList<Annotation>(annSet);
64
65 //check 100% Precision and recall
66 AnnotationDiffer differ = new AnnotationDiffer();
67 differ.setSignificantFeaturesSet(null);
68 differ.calculateDiff(keySet, responseSet);
69 differ.sanityCheck();
70 if(DEBUG) differ.printMissmatches();
71 double value = differ.getPrecisionStrict();
72 Assert.assertEquals("Precision Strict: " + value + " instead of 1!",
73 1, value, 0);
74 value = differ.getRecallStrict();
75 Assert.assertEquals("Recall Strict: " + value + " instead of 1!",
76 1, value, 0);
77 value = differ.getPrecisionLenient();
78 Assert.assertEquals("Precision Lenient: " + value + " instead of 1!",
79 1, value, 0);
80 value = differ.getRecallLenient();
81 Assert.assertEquals("Recall Lenient: " + value + " instead of 1!",
82 1, value, 0);
83
84 //check low precision
85 Integer id = annSet.add(new Long(2), new Long(4), "Foo", features);
86 Annotation falsePositive = annSet.get(id);
87 responseSet.add(falsePositive);
88 differ.calculateDiff(keySet, responseSet);
89 differ.sanityCheck();
90 if(DEBUG) differ.printMissmatches();
91 value = differ.getPrecisionStrict();
92 Assert.assertEquals("Precision Strict: " + value + " instead of .99!",
93 .99, value, .001);
94 //recall should still be 100%
95 value = differ.getRecallStrict();
96 Assert.assertEquals("Recall Strict: " + value + " instead of 1!",
97 1, value, 0);
98 value = differ.getRecallLenient();
99 Assert.assertEquals("Recall Lenient: " + value + " instead of 1!",
100 1, value, 0);
101
102
103 //check low recall
104 responseSet.remove(falsePositive);
105 keySet.add(falsePositive);
106 differ.calculateDiff(keySet, responseSet);

Callers

nothing calls this directly

Calls 15

newDocumentMethod · 0.95
newFeatureMapMethod · 0.95
addMethod · 0.95
calculateDiffMethod · 0.95
sanityCheckMethod · 0.95
printMissmatchesMethod · 0.95
getPrecisionStrictMethod · 0.95
getRecallStrictMethod · 0.95
getPrecisionLenientMethod · 0.95
getRecallLenientMethod · 0.95
getMethod · 0.95

Tested by

no test coverage detected