1
15
16 package gate.creole.gazetteer;
17
18 import junit.framework.*;
19 import gate.*;
20 import gate.corpora.*;
21 import java.net.*;
22 import gate.gui.MainFrame;
23
24 public class TestFlexibleGazetteer extends TestCase {
25
26 private static final boolean DEBUG=false;
27
28 public TestFlexibleGazetteer(String name) {
29 super(name);
30 }
31
32
33 public void setUp() throws Exception {
34 }
35
36
37 public void tearDown() throws Exception {
38 }
40
41 public void testFlexibleGazetteer() throws Exception {
42
43 if (DEBUG) {
45 MainFrame mainFrame = new MainFrame();
46 mainFrame.setVisible(true);
47 }
48
49 Document doc = Factory.newDocument(
52 new URL(TestDocument.getTestServerName() + "tests/doc0.html")
53 );
54
55 gate.creole.tokeniser.DefaultTokeniser tokeniser=
57 (gate.creole.tokeniser.DefaultTokeniser) Factory.createResource(
58 "gate.creole.tokeniser.DefaultTokeniser");
59
60 gate.creole.splitter.SentenceSplitter splitter =
61 (gate.creole.splitter.SentenceSplitter) Factory.createResource(
62 "gate.creole.splitter.SentenceSplitter");
63
64 gate.creole.POSTagger tagger = (gate.creole.POSTagger) Factory.createResource(
65 "gate.creole.POSTagger");
66
67 gate.creole.morph.Morph morphologicalAnalyser=
69 (gate.creole.morph.Morph) Factory.createResource(
70 "gate.creole.morph.Morph");
71
72 gate.creole.gazetteer.Gazetteer gazetteerInst =
74 (gate.creole.gazetteer.DefaultGazetteer) Factory.createResource(
75 "gate.creole.gazetteer.DefaultGazetteer");
76
77 FeatureMap params = Factory.newFeatureMap();
80 java.util.ArrayList testInputFeatures=new java.util.ArrayList();
83 testInputFeatures.add("Token.root");
84 params.put("inputFeatureNames", testInputFeatures);
85 params.put("gazetteerInst",gazetteerInst);
86
87 FlexibleGazetteer flexGaz = (FlexibleGazetteer) Factory.createResource(
89 "gate.creole.gazetteer.FlexibleGazetteer", params);
90
91 tokeniser.setDocument(doc);
94 tokeniser.execute();
95 splitter.setDocument(doc);
96 splitter.execute();
97 tagger.setDocument(doc);
98 tagger.execute();
99 morphologicalAnalyser.setDocument(doc);
100 morphologicalAnalyser.execute();
101 flexGaz.setDocument(doc);
102 flexGaz.execute();
103
104 AnnotationSet defaultAnnotations=doc.getAnnotations();
107
108 AnnotationSet lookups=defaultAnnotations.get("Lookup");
110
111
115 if (DEBUG) {
116 System.out.println("There are this many lookup annotations: "+
117 lookups.size());
118 }
119 assertTrue(lookups.size()== 40);
120
121 Factory.deleteResource(doc);
123 Factory.deleteResource(tokeniser);
124 Factory.deleteResource(morphologicalAnalyser);
125 Factory.deleteResource(flexGaz);
126 }
127
128
129 public static Test suite() {
130 return new TestSuite(TestFlexibleGazetteer.class);
131 }
133 public static void main(String[] args) {
136 try{
137 Gate.init();
138 TestFlexibleGazetteer testGaz = new TestFlexibleGazetteer("");
139 testGaz.setUp();
140 testGaz.testFlexibleGazetteer();
141 testGaz.tearDown();
142 } catch(Exception e) {
143 e.printStackTrace();
144 }
145 }
147 }