1
15
16 package gate.creole.ml.maxent;
17
18 import junit.framework.*;
19 import gate.*;
20 import gate.corpora.*;
21 import java.net.*;
22 import gate.gui.MainFrame;
23 import gate.util.Files;
24
25 public class TestMaxentWrapper extends TestCase {
26
27 private static final boolean DEBUG=false;
28
29 public TestMaxentWrapper(String name) {
30 super(name);
31 }
32
33
34 public void setUp() throws Exception {
35 }
36
37
38 public void tearDown() throws Exception {
39 }
41
44 public void testMaxentWrapper() throws Exception {
45 java.io.PrintStream normalOutputStream=System.out;
47
48 if (DEBUG) {
50 MainFrame mainFrame = new MainFrame();
51 mainFrame.setVisible(true);
52 } else {
53 System.setOut(new java.io.PrintStream(
56 new java.io.OutputStream() {
57 public void write(int b) { }
58 public void write(byte[] b, int off, int len) { }
59 }));
60 }
61
62 Document doc = Factory.newDocument(
65 new URL(TestDocument.getTestServerName() + "tests/doc0.html")
66 );
67
68 gate.creole.tokeniser.DefaultTokeniser tokeniser=
70 (gate.creole.tokeniser.DefaultTokeniser) Factory.createResource(
71 "gate.creole.tokeniser.DefaultTokeniser");
72
73 gate.creole.gazetteer.Gazetteer gazetteerInst =
75 (gate.creole.gazetteer.DefaultGazetteer) Factory.createResource(
76 "gate.creole.gazetteer.DefaultGazetteer");
77
78 FeatureMap maxentParameters = Factory.newFeatureMap();
81 maxentParameters.put("configFileURL",
82 Gate.class.getResource(Files.getResourcePath() +
83 "/gate.ac.uk/tests/TestMaxentConfigFile.xml"));
84 gate.creole.ml.MachineLearningPR maxentPR =
86 (gate.creole.ml.MachineLearningPR)
87 Factory.createResource("gate.creole.ml.MachineLearningPR",
88 maxentParameters);
89
90 tokeniser.setDocument(doc);
93 tokeniser.execute();
94 gazetteerInst.setDocument(doc);
95 gazetteerInst.execute();
96 maxentPR.setDocument(doc);
97 maxentPR.execute();
98
99 maxentPR.setTraining(new Boolean(false));
101 maxentPR.execute();
102
103 Factory.deleteResource(doc);
105 Factory.deleteResource(tokeniser);
106 Factory.deleteResource(maxentPR);
107 Factory.deleteResource(gazetteerInst);
108
109 System.setOut(normalOutputStream);
111 }
113
114 public static Test suite() {
115 return new TestSuite(TestMaxentWrapper.class);
116 }
118 public static void main(String[] args) {
121 try{
122 Gate.init();
123 TestMaxentWrapper testMax = new TestMaxentWrapper("");
124 testMax.setUp();
125 testMax.testMaxentWrapper();
126 testMax.tearDown();
127 } catch(Exception e) {
128 e.printStackTrace();
129 }
130 }
132 }