1
15
16 package gate.creole.gazetteer;
17
18 import junit.framework.*;
19 import gate.*;
20 import gate.corpora.*;
21 import java.io.File;
22 import java.net.*;
23 import gate.gui.MainFrame;
24 import gate.util.GateRuntimeException;
25
26 public class TestFlexibleGazetteer extends TestCase {
27
28 private static final boolean DEBUG=false;
29
30 public TestFlexibleGazetteer(String name) {
31 super(name);
32 }
33
34
35 public void setUp() throws Exception {
36 File pluginsHome = new File(System.getProperty(
38 GateConstants.GATE_HOME_PROPERTY_NAME),
39 "plugins");
40 try{
41 Gate.getCreoleRegister().registerDirectories(
42 new File(pluginsHome, "Tools").toURL());
43 }catch(Exception e){
44 throw new GateRuntimeException(e);
45 }
46 }
47
48
49 public void tearDown() throws Exception {
50 }
52
53 public void testFlexibleGazetteer() throws Exception {
54
55 if (DEBUG) {
57 MainFrame mainFrame = new MainFrame();
58 mainFrame.setVisible(true);
59 }
60
61 Document doc = Factory.newDocument(
64 new URL(TestDocument.getTestServerName() + "tests/doc0.html")
65 );
66
67 gate.creole.tokeniser.DefaultTokeniser tokeniser=
69 (gate.creole.tokeniser.DefaultTokeniser) Factory.createResource(
70 "gate.creole.tokeniser.DefaultTokeniser");
71
72 gate.creole.splitter.SentenceSplitter splitter =
73 (gate.creole.splitter.SentenceSplitter) Factory.createResource(
74 "gate.creole.splitter.SentenceSplitter");
75
76 gate.creole.POSTagger tagger = (gate.creole.POSTagger) Factory.createResource(
77 "gate.creole.POSTagger");
78
79 gate.creole.morph.Morph morphologicalAnalyser=
81 (gate.creole.morph.Morph) Factory.createResource(
82 "gate.creole.morph.Morph");
83
84 gate.creole.gazetteer.Gazetteer gazetteerInst =
86 (gate.creole.gazetteer.DefaultGazetteer) Factory.createResource(
87 "gate.creole.gazetteer.DefaultGazetteer");
88
89 FeatureMap params = Factory.newFeatureMap();
92 java.util.ArrayList testInputFeatures=new java.util.ArrayList();
95 testInputFeatures.add("Token.root");
96 params.put("inputFeatureNames", testInputFeatures);
97 params.put("gazetteerInst",gazetteerInst);
98
99 FlexibleGazetteer flexGaz = (FlexibleGazetteer) Factory.createResource(
101 "gate.creole.gazetteer.FlexibleGazetteer", params);
102
103 tokeniser.setDocument(doc);
106 tokeniser.execute();
107 splitter.setDocument(doc);
108 splitter.execute();
109 tagger.setDocument(doc);
110 tagger.execute();
111 morphologicalAnalyser.setDocument(doc);
112 morphologicalAnalyser.execute();
113 flexGaz.setDocument(doc);
114 flexGaz.execute();
115
116 AnnotationSet defaultAnnotations=doc.getAnnotations();
119
120 AnnotationSet lookups=defaultAnnotations.get("Lookup");
122
123
127 if (DEBUG) {
128 System.out.println("There are this many lookup annotations: "+
129 lookups.size());
130 }
131 assertTrue(lookups.size()== 40);
132
133 Factory.deleteResource(doc);
135 Factory.deleteResource(tokeniser);
136 Factory.deleteResource(morphologicalAnalyser);
137 Factory.deleteResource(flexGaz);
138 }
139
140
141 public static Test suite() {
142 return new TestSuite(TestFlexibleGazetteer.class);
143 }
145 public static void main(String[] args) {
148 try{
149 Gate.init();
150 TestFlexibleGazetteer testGaz = new TestFlexibleGazetteer("");
151 testGaz.setUp();
152 testGaz.testFlexibleGazetteer();
153 testGaz.tearDown();
154 } catch(Exception e) {
155 e.printStackTrace();
156 }
157 }
159 }