TestCoref.java
001 /*
002  *  TestCoref.java
003  *
004  *  Copyright (c) 1995-2010, The University of Sheffield. See the file
005  *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
006  *
007  *  This file is part of GATE (see http://gate.ac.uk/), and is free
008  *  software, licenced under the GNU Library General Public License,
009  *  Version 2, June 1991 (in the distribution as file licence.html,
010  *  and also available at http://gate.ac.uk/gate/licence.html).
011  *
012  *  Marin Dimitrov, 02/01/2002
013  *
014  *  $Id: TestCoref.java 12006 2009-12-01 17:24:28Z thomas_heitz $
015  */
016 
017 package gate.creole.coref;
018 
019 import java.util.List;
020 
021 import junit.framework.*;
022 
023 import gate.*;
024 import gate.creole.ANNIETransducer;
025 import gate.creole.POSTagger;
026 import gate.creole.gazetteer.DefaultGazetteer;
027 import gate.creole.orthomatcher.OrthoMatcher;
028 import gate.creole.splitter.SentenceSplitter;
029 import gate.creole.tokeniser.DefaultTokeniser;
030 
031 public class TestCoref extends TestCase {
032 
033   public TestCoref(String name) {
034     super(name);
035   }
036 
037   public static void main(String[] args) {
038 
039     try{
040       Gate.init();
041       TestCoref testCoref = new TestCoref("");
042 
043       testCoref.setUp();
044       testCoref.useCase01();
045       testCoref.tearDown();
046 
047     catch(Exception e) {
048       e.printStackTrace();
049     }
050   // main
051 
052 
053   /** Test suite routine for the test runner */
054   public static Test suite() {
055     return new TestSuite(TestCoref.class);
056   // suite
057 
058   /** Fixture set up */
059   public void setUp() throws Exception {
060   }
061 
062   public void tearDown() throws Exception {
063   // tearDown
064 
065 
066   private void runANNIE(Document docthrows Exception {
067 System.out.println("starting ANNIE modules...");
068     DefaultTokeniser englishTokeniser = (DefaultTokeniser)Factory.createResource("gate.creole.tokeniser.DefaultTokeniser");
069     DefaultGazetteer gazeteer = (DefaultGazetteer)Factory.createResource("gate.creole.gazetteer.DefaultGazetteer");
070     SentenceSplitter split = (SentenceSplitter)Factory.createResource("gate.creole.splitter.SentenceSplitter");
071     POSTagger tag = (POSTagger)Factory.createResource("gate.creole.POSTagger");
072     ANNIETransducer neTransducer = (ANNIETransducer)Factory.createResource("gate.creole.ANNIETransducer");
073     OrthoMatcher orthoMatcher = (OrthoMatcher)Factory.createResource("gate.creole.orthomatcher.OrthoMatcher");
074 
075     englishTokeniser.init();
076     gazeteer.init();
077     split.init();
078     tag.init();
079     neTransducer.init();
080     orthoMatcher.init();
081 
082     englishTokeniser.setDocument(doc);
083     gazeteer.setDocument(doc);
084     split.setDocument(doc);
085     tag.setDocument(doc);
086     neTransducer.setDocument(doc);
087     orthoMatcher.setDocument(doc);
088 
089     englishTokeniser.execute();
090     gazeteer.execute();
091     split.execute();
092     tag.execute();
093     neTransducer.execute();
094     orthoMatcher.execute();
095 
096   }
097 
098 
099   private Document loadDocument(String url)
100     throws Exception {
101 
102     FeatureMap params = Factory.newFeatureMap()// params list for new doc
103     // set the source URL parameter to a "file:..." URL string
104     params.clear();
105     params.put(Document.DOCUMENT_URL_PARAMETER_NAME, url);
106 
107     // create the document
108     Document doc = (DocumentFactory.createResource("gate.corpora.DocumentImpl", params);
109 
110     return doc;
111   }
112 
113 
114   /** Test suite routine for the test runner */
115   public void useCase01()
116     throws Exception{
117 System.out.println("starting use case 01...");
118 
119     DataStore sds = Factory.openDataStore("gate.persist.SerialDataStore""file:/E:/gate2/serial/debug/");
120     sds.open();
121 
122     List lrIds = sds.getLrIds("gate.corpora.DocumentImpl");
123     Object lrID = lrIds.get(0);
124 
125     Document doc = (Documentsds.getLr("gate.corpora.DocumentImpl", lrID);
126 //    Document doc = loadDocument("file:/E:/Gate2/data/gatecorpora/ace/aps/npaper/clean/9801.35.sgm");
127 //    Document doc = loadDocument("file:/E:/Gate2/data/gatecorpora/ace/aps/npaper/clean/9806.93.sgm");
128 //    Document doc = loadDocument("file:/E:/Gate2/data/gatecorpora/ace/aps/npaper/clean/9802.108.sgm");
129 
130 //--    runANNIE(doc);
131 
132     Coreferencer corefMain = (Coreferencer)Factory.createResource("gate.creole.coref.Coreferencer");
133     corefMain.init();
134     corefMain.setDocument(doc);
135 System.out.println("starting COREF...");
136     corefMain.execute();
137 System.out.println("case 01 finished...");
138     return;
139   // suite
140 
141 }