1   /*
2    *  TestAnnotationDiff.java
3    *
4    *  Copyright (c) 1998-2005, The University of Sheffield.
5    *
6    *  This file is part of GATE (see http://gate.ac.uk/), and is free
7    *  software, licenced under the GNU Library General Public License,
8    *  Version 2, June 1991 (in the distribution as file licence.html,
9    *  and also available at http://gate.ac.uk/gate/licence.html).
10   *
11   *  Hamish Cunningham, 11/Feb/2000
12   *
13   *  Cristian URSU, 06/Nov/2000
14   *
15   *  $Id: TestAnnotationDiff.java,v 1.25 2005/01/11 13:51:30 ian Exp $
16   */
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  /**
30    */
31  public class TestAnnotationDiff extends TestCase
32  {
33    /** Debug flag */
34    private static final boolean DEBUG = false;
35  
36    /** The Precision value (see NLP Information Extraction)*/
37    private Double precision = null;
38  
39    /** The Recall value (see NLP Information Extraction)*/
40    private Double recall = null;
41  
42  
43    /** Construction */
44    public TestAnnotationDiff(String name) { super(name); }
45  
46    /** Fixture set up */
47    public void setUp() {
48  
49    } // setUp
50  
51    /** A test */
52    public void testDiff() throws Exception {
53      // Create a AnnotationSchema object from URL.
54      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      // Load the xml Key Document and unpack it
65      gate.Document keyDocument =
66         gate.Factory.newDocument(
67            Gate.getUrl("tests/annotDiff/KeyDocument.xml")
68  //            new URL("file:///Z:/testAnnotDiff/key1.xml")
69         );
70  
71      // Load the xml Response Document and unpack it
72      gate.Document responseDocument =
73          gate.Factory.newDocument(
74              Gate.getUrl("tests/annotDiff/ResponseDocument.xml")
75  //            new URL("file:///Z:/testAnnotDiff/response1.xml")
76          );
77  
78      AnnotationSet keyAnnotSet = null;
79      AnnotationSet responseAnnotSet = null;
80      Set diffSet  = null;
81      // Get the key AnnotationSet from the keyDocument
82      keyAnnotSet = keyDocument.getAnnotations(
83                              GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME).get(
84                                annotationSchema.getAnnotationName());
85      // Get the response AnnotationSet from the resonseDocument
86      responseAnnotSet = responseDocument.getAnnotations(
87                              GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME).get(
88                                          annotationSchema.getAnnotationName());
89  
90  //*
91      // Create an AnnotationDiff object.
92      // Creole.xml must contain a entry for AnnotationDiff.
93      // If not, you will get an exception (couldn't configure resource metadata)
94  
95  
96      // Create Annotation Diff visual resource
97      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 //*/
108 //*
109     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 //*/
118     // Display the component
119 /*
120     JFrame jFrame = new JFrame("AnnotationDiff GUI");
121     jFrame.getContentPane().add(annotDiff, BorderLayout.CENTER);
122     jFrame.pack();
123     jFrame.setVisible(true);
124 */
125 
126   } // testDiff()
127 
128 
129 
130   /** Test suite routine for the test runner */
131   public static Test suite() {
132     return new TestSuite(TestAnnotationDiff.class);
133   } // suite
134 
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   }// main
145 
146 } // class TestAnnotationDiff
147