|
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.20 2002/03/05 16:10:27 kalina 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 101 // Create Annotation Diff visual resource 102 AnnotationDiff annotDiff = new AnnotationDiff(); 103 annotDiff.setKeyDocument(keyDocument); 104 annotDiff.setResponseDocument(responseDocument); 105 annotDiff.setAnnotationSchema(annotationSchema); 106 annotDiff.setKeyAnnotationSetName( 107 GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME); 108 annotDiff.setResponseAnnotationSetName( 109 GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME); 110 annotDiff.init(); 111 112 //*/ 113 //* 114 assertTrue("Precision strict changed.That's because of the key/response" + 115 " document or" + " code implementation!", 116 0.16666666666666666 == annotDiff.getPrecisionStrict()); 117 assertTrue("Recall strict changed.That's because of the key/response" + 118 " document or" + " code implementation!", 119 0.18181818181818182 == annotDiff.getRecallStrict()); 120 121 122 //*/ 123 // Display the component 124 /* 125 JFrame jFrame = new JFrame("AnnotationDiff GUI"); 126 jFrame.getContentPane().add(annotDiff, BorderLayout.CENTER); 127 jFrame.pack(); 128 jFrame.setVisible(true); 129 */ 130 131 } // testDiff() 132 133 134 135 /** Test suite routine for the test runner */ 136 public static Test suite() { 137 return new TestSuite(TestAnnotationDiff.class); 138 } // suite 139 140 public static void main(String[] args) { 141 try{ 142 Gate.init(); 143 TestAnnotationDiff testAnnotDiff = new TestAnnotationDiff(""); 144 145 testAnnotDiff.testDiff(); 146 }catch(Exception e){ 147 e.printStackTrace(); 148 } 149 }// main 150 151 } // class TestAnnotationDiff 152
|
TestAnnotationDiff |
|