1
17
18 package gate.annotation;
19
20 import java.util.Set;
21
22 import junit.framework.*;
23
24 import gate.*;
25 import gate.creole.AnnotationSchema;
26 import gate.creole.ResourceData;
27
28
29
31 public class TestAnnotationDiff extends TestCase
32 {
33
34 private static final boolean DEBUG = false;
35
36
37 private Double precision = null;
38
39
40 private Double recall = null;
41
42
43
44 public TestAnnotationDiff(String name) { super(name); }
45
46
47 public void setUp() {
48
49 }
51
52 public void testDiff() throws Exception {
53 ResourceData resData = (ResourceData)
55 Gate.getCreoleRegister().get("gate.creole.AnnotationSchema");
56
57 FeatureMap parameters = Factory.newFeatureMap();
58 parameters.put("xmlFileUrl", Gate.getUrl("tests/xml/POSSchema.xml"));
59
60 AnnotationSchema annotationSchema = (AnnotationSchema)
61 Factory.createResource("gate.creole.AnnotationSchema", parameters);
62
63
64 gate.Document keyDocument =
66 gate.Factory.newDocument(
67 Gate.getUrl("tests/annotDiff/KeyDocument.xml")
68 );
70
71 gate.Document responseDocument =
73 gate.Factory.newDocument(
74 Gate.getUrl("tests/annotDiff/ResponseDocument.xml")
75 );
77
78 AnnotationSet keyAnnotSet = null;
79 AnnotationSet responseAnnotSet = null;
80 Set diffSet = null;
81 keyAnnotSet = keyDocument.getAnnotations(
83 GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME).get(
84 annotationSchema.getAnnotationName());
85 responseAnnotSet = responseDocument.getAnnotations(
87 GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME).get(
88 annotationSchema.getAnnotationName());
89
90
95
96 AnnotationDiff annotDiff = new AnnotationDiff();
98 annotDiff.setKeyDocument(keyDocument);
99 annotDiff.setResponseDocument(responseDocument);
100 annotDiff.setAnnotationSchema(annotationSchema);
101 annotDiff.setKeyAnnotationSetName(
102 GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME);
103 annotDiff.setResponseAnnotationSetName(
104 GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME);
105 annotDiff.init();
106
107 assertTrue("Precision strict changed.That's because of the key/response" +
110 " document or" + " code implementation!",
111 0.16666666666666666 == annotDiff.getPrecisionStrict());
112 assertTrue("Recall strict changed.That's because of the key/response" +
113 " document or" + " code implementation!",
114 0.18181818181818182 == annotDiff.getRecallStrict());
115
116
117
125
126 }
128
129
130
131 public static Test suite() {
132 return new TestSuite(TestAnnotationDiff.class);
133 }
135 public static void main(String[] args) {
136 try{
137 Gate.init();
138 TestAnnotationDiff testAnnotDiff = new TestAnnotationDiff("");
139
140 testAnnotDiff.testDiff();
141 }catch(Exception e){
142 e.printStackTrace();
143 }
144 }
146 }