1   /*
2    *  TestCoref.java
3    *
4    *  Copyright (c) 1998-2004, 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   *  Marin Dimitrov, 02/01/2002
12   *
13   *  $Id: TestCoref.java,v 1.7 2004/07/21 17:10:04 akshay Exp $
14   */
15  
16  package gate.creole.coref;
17  
18  import java.util.List;
19  
20  import junit.framework.*;
21  
22  import gate.*;
23  import gate.creole.ANNIETransducer;
24  import gate.creole.POSTagger;
25  import gate.creole.gazetteer.DefaultGazetteer;
26  import gate.creole.orthomatcher.OrthoMatcher;
27  import gate.creole.splitter.SentenceSplitter;
28  import gate.creole.tokeniser.DefaultTokeniser;
29  
30  public class TestCoref extends TestCase {
31  
32    public TestCoref(String name) {
33      super(name);
34    }
35  
36    public static void main(String[] args) {
37  
38      try{
39        Gate.init();
40        TestCoref testCoref = new TestCoref("");
41  
42        testCoref.setUp();
43        testCoref.useCase01();
44        testCoref.tearDown();
45  
46      } catch(Exception e) {
47        e.printStackTrace();
48      }
49    } // main
50  
51  
52    /** Test suite routine for the test runner */
53    public static Test suite() {
54      return new TestSuite(TestCoref.class);
55    } // suite
56  
57    /** Fixture set up */
58    public void setUp() throws Exception {
59    }
60  
61    public void tearDown() throws Exception {
62    } // tearDown
63  
64  
65    private void runANNIE(Document doc) throws Exception {
66  System.out.println("starting ANNIE modules...");
67      DefaultTokeniser englishTokeniser = (DefaultTokeniser)Factory.createResource("gate.creole.tokeniser.DefaultTokeniser");
68      DefaultGazetteer gazeteer = (DefaultGazetteer)Factory.createResource("gate.creole.gazetteer.DefaultGazetteer");
69      SentenceSplitter split = (SentenceSplitter)Factory.createResource("gate.creole.splitter.SentenceSplitter");
70      POSTagger tag = (POSTagger)Factory.createResource("gate.creole.POSTagger");
71      ANNIETransducer neTransducer = (ANNIETransducer)Factory.createResource("gate.creole.ANNIETransducer");
72      OrthoMatcher orthoMatcher = (OrthoMatcher)Factory.createResource("gate.creole.orthomatcher.OrthoMatcher");
73  
74      englishTokeniser.init();
75      gazeteer.init();
76      split.init();
77      tag.init();
78      neTransducer.init();
79      orthoMatcher.init();
80  
81      englishTokeniser.setDocument(doc);
82      gazeteer.setDocument(doc);
83      split.setDocument(doc);
84      tag.setDocument(doc);
85      neTransducer.setDocument(doc);
86      orthoMatcher.setDocument(doc);
87  
88      englishTokeniser.execute();
89      gazeteer.execute();
90      split.execute();
91      tag.execute();
92      neTransducer.execute();
93      orthoMatcher.execute();
94  
95    }
96  
97  
98    private Document loadDocument(String url)
99      throws Exception {
100 
101     FeatureMap params = Factory.newFeatureMap(); // params list for new doc
102     // set the source URL parameter to a "file:..." URL string
103     params.clear();
104     params.put(Document.DOCUMENT_URL_PARAMETER_NAME, url);
105 
106     // create the document
107     Document doc = (Document) Factory.createResource("gate.corpora.DocumentImpl", params);
108 
109     return doc;
110   }
111 
112 
113   /** Test suite routine for the test runner */
114   public void useCase01()
115     throws Exception{
116 System.out.println("starting use case 01...");
117 
118     DataStore sds = Factory.openDataStore("gate.persist.SerialDataStore", "file:/E:/gate2/serial/debug/");
119     sds.open();
120 
121     List lrIds = sds.getLrIds("gate.corpora.DocumentImpl");
122     Object lrID = lrIds.get(0);
123 
124     Document doc = (Document) sds.getLr("gate.corpora.DocumentImpl", lrID);
125 //    Document doc = loadDocument("file:/E:/Gate2/data/gatecorpora/ace/aps/npaper/clean/9801.35.sgm");
126 //    Document doc = loadDocument("file:/E:/Gate2/data/gatecorpora/ace/aps/npaper/clean/9806.93.sgm");
127 //    Document doc = loadDocument("file:/E:/Gate2/data/gatecorpora/ace/aps/npaper/clean/9802.108.sgm");
128 
129 //--    runANNIE(doc);
130 
131     Coreferencer corefMain = (Coreferencer)Factory.createResource("gate.creole.coref.Coreferencer");
132     corefMain.init();
133     corefMain.setDocument(doc);
134 System.out.println("starting COREF...");
135     corefMain.execute();
136 System.out.println("case 01 finished...");
137     return;
138   } // suite
139 
140 }
141