1
13 package gate.creole;
14
15 import java.net.URL;
16 import java.util.Iterator;
17
18 import junit.framework.*;
19
20 import gate.*;
21 import gate.corpora.TestDocument;
22 import gate.creole.splitter.SentenceSplitter;
23 import gate.creole.tokeniser.DefaultTokeniser;
24 import gate.util.GateException;
25
26
29 public class TestSplitterTagger extends TestCase{
30
31
32 public TestSplitterTagger(String name) { super(name); }
33
34
35 public void setUp() throws GateException {
36 }
38
41 public void tearDown() throws Exception {
42 }
44
45 public static Test suite() {
46 return new TestSuite(TestSplitterTagger.class);
47 }
49
50
51 public void testSplitterTagger() throws Exception{
52 Document doc = Factory.newDocument(
54 new URL(TestDocument.getTestServerName() + "tests/doc0.html")
55 );
56
57 FeatureMap params = Factory.newFeatureMap();
60 DefaultTokeniser tokeniser = (DefaultTokeniser) Factory.createResource(
61 "gate.creole.tokeniser.DefaultTokeniser", params);
62 tokeniser.setDocument(doc);
64 tokeniser.setAnnotationSetName("testAS");
65 tokeniser.execute();
66
67
68 params = Factory.newFeatureMap();
70 SentenceSplitter splitter = (SentenceSplitter) Factory.createResource(
71 "gate.creole.splitter.SentenceSplitter", params);
72
73 splitter.setDocument(doc);
75 splitter.setOutputASName("testAS");
76 splitter.setInputASName("testAS");
77 splitter.execute();
78 assertTrue(!doc.getAnnotations("testAS").
79 get(ANNIEConstants.SENTENCE_ANNOTATION_TYPE).isEmpty());
80
81 params = Factory.newFeatureMap();
84 POSTagger tagger = (POSTagger) Factory.createResource(
85 "gate.creole.POSTagger", params);
86
87 tagger.setDocument(doc);
89 tagger.setInputASName("testAS");
90 tagger.execute();
91 Iterator tokIter =doc.getAnnotations("testAS").
92 get(ANNIEConstants.TOKEN_ANNOTATION_TYPE).iterator();
93 while(tokIter.hasNext()){
94 Annotation token = (Annotation)tokIter.next();
95 String kind = (String)token.getFeatures().
96 get(ANNIEConstants.TOKEN_KIND_FEATURE_NAME);
97 if(kind.equals(ANNIEConstants.TOKEN_KIND_FEATURE_NAME))
98 assertNotNull(token.getFeatures().
99 get(ANNIEConstants.TOKEN_CATEGORY_FEATURE_NAME));
100 }
101 }
102 }