| TestAnnotationDiff |

    1   /*
    2    *  TestAnnotationDiff.java
    3    *
    4    *  Copyright (c) 1998-2001, 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.19 2001/11/08 17:23:27 cursu Exp $
    16   */
    17
    18  package gate.annotation;
    19
    20  import java.util.*;
    21  import java.io.*;
    22  import java.net.*;
    23  import junit.framework.*;
    24  import javax.swing.*;
    25  import java.awt.*;
    26
    27  import gate.util.*;
    28  import gate.gui.*;
    29  import gate.creole.*;
    30  import gate.corpora.*;
    31  import gate.*;
    32
    33
    34  /**
    35    */
    36  public class TestAnnotationDiff extends TestCase
    37  {
    38    /** Debug flag */
    39    private static final boolean DEBUG = false;
    40
    41    /** The Precision value (see NLP Information Extraction)*/
    42    private Double precision = null;
    43
    44    /** The Recall value (see NLP Information Extraction)*/
    45    private Double recall = null;
    46
    47
    48    /** Construction */
    49    public TestAnnotationDiff(String name) { super(name); }
    50
    51    /** Fixture set up */
    52    public void setUp() {
    53
    54    } // setUp
    55
    56    /** A test */
    57    public void testDiff() throws Exception {
    58      // Create a AnnotationSchema object from URL.
    59      ResourceData resData = (ResourceData)
    60        Gate.getCreoleRegister().get("gate.creole.AnnotationSchema");
    61
    62      FeatureMap parameters = Factory.newFeatureMap();
    63      parameters.put("xmlFileUrl", Gate.getUrl("tests/xml/POSSchema.xml"));
    64
    65      AnnotationSchema annotationSchema = (AnnotationSchema)
    66        Factory.createResource("gate.creole.AnnotationSchema", parameters);
    67
    68
    69      // Load the xml Key Document and unpack it
    70      gate.Document keyDocument =
    71         gate.Factory.newDocument(
    72            Gate.getUrl("tests/annotDiff/KeyDocument.xml")
    73  //            new URL("file:///Z:/testAnnotDiff/key1.xml")
    74         );
    75
    76      // Load the xml Response Document and unpack it
    77      gate.Document responseDocument =
    78          gate.Factory.newDocument(
    79              Gate.getUrl("tests/annotDiff/ResponseDocument.xml")
    80  //            new URL("file:///Z:/testAnnotDiff/response1.xml")
    81          );
    82
    83      AnnotationSet keyAnnotSet = null;
    84      AnnotationSet responseAnnotSet = null;
    85      Set diffSet  = null;
    86      // Get the key AnnotationSet from the keyDocument
    87      keyAnnotSet = keyDocument.getAnnotations(
    88                              GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME).get(
    89                                annotationSchema.getAnnotationName());
    90      // Get the response AnnotationSet from the resonseDocument
    91      responseAnnotSet = responseDocument.getAnnotations(
    92                              GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME).get(
    93                                          annotationSchema.getAnnotationName());
    94
    95  //*
    96      // Create an AnnotationDiff object.
    97      // Creole.xml must contain a entry for AnnotationDiff.
    98      // If not, you will get an exception (couldn't configure resource metadata)
    99
    100     parameters = Factory.newFeatureMap();
    101     parameters.put("keyDocument",keyDocument);
    102     parameters.put("responseDocument",responseDocument);
    103     parameters.put("annotationSchema",annotationSchema);
    104     parameters.put("keyAnnotationSetName",
    105                                 GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME);
    106     parameters.put("responseAnnotationSetName",
    107                                 GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME);
    108
    109     // Create Annotation Diff visual resource
    110     AnnotationDiff annotDiff = (AnnotationDiff)
    111           Factory.createResource("gate.annotation.AnnotationDiff",parameters);
    112
    113 //*/
    114 //*
    115     assertTrue("Precision strict changed.That's because of the key/response" +
    116             " document or" + " code implementation!",
    117                         0.16666666666666666 == annotDiff.getPrecisionStrict());
    118     assertTrue("Recall strict changed.That's because of the key/response" +
    119     " document or" + " code implementation!",
    120                     0.18181818181818182 == annotDiff.getRecallStrict());
    121
    122
    123 //*/
    124     // Display the component
    125 /*
    126     JFrame jFrame = new JFrame("AnnotationDiff GUI");
    127     jFrame.getContentPane().add(annotDiff, BorderLayout.CENTER);
    128     jFrame.pack();
    129     jFrame.setVisible(true);
    130 */
    131
    132   } // testDiff()
    133
    134
    135
    136   /** Test suite routine for the test runner */
    137   public static Test suite() {
    138     return new TestSuite(TestAnnotationDiff.class);
    139   } // suite
    140
    141   public static void main(String[] args) {
    142     try{
    143       Gate.init();
    144       TestAnnotationDiff testAnnotDiff = new TestAnnotationDiff("");
    145
    146       testAnnotDiff.testDiff();
    147     }catch(Exception e){
    148       e.printStackTrace();
    149     }
    150   }// main
    151
    152 } // class TestAnnotationDiff
    153

| TestAnnotationDiff |