001 /*
002 * TestGazetteer.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 * Valentin Tablan, 25/10/2000
013 *
014 * $Id: TestGazetteer.java 12006 2009-12-01 17:24:28Z thomas_heitz $
015 */
016
017 package gate.creole.gazetteer;
018
019 import java.net.URL;
020
021 import junit.framework.*;
022
023 import gate.*;
024 import gate.corpora.TestDocument;
025
026 public class TestGazetteer extends TestCase {
027
028 public TestGazetteer(String name) {
029 super(name);
030 }
031
032 /** Fixture set up */
033 public void setUp() throws Exception {
034 }
035
036 public void tearDown() throws Exception {
037 } // tearDown
038
039 /** Test the default tokeniser */
040 public void testDefaultGazetteer() throws Exception {
041 //get a document
042 Document doc = Factory.newDocument(
043 new URL(TestDocument.getTestServerName() + "tests/doc0.html")
044 );
045
046 //create a default gazetteer
047 DefaultGazetteer gaz = (DefaultGazetteer) Factory.createResource(
048 "gate.creole.gazetteer.DefaultGazetteer");
049
050 //runtime stuff
051 gaz.setDocument(doc);
052 gaz.setAnnotationSetName("GazetteerAS");
053 //test with default parameters
054 gaz.execute();
055 AnnotationSet resultAS = doc.getAnnotations("GazetteerAS");
056 assertTrue("Found " + resultAS.size() +
057 " annotations instead of the expected 53!", resultAS.size() == 53);
058 resultAS.clear();
059
060 //test with partial words
061 gaz.setWholeWordsOnly(false);
062 gaz.execute();
063 assertEquals("Wrong number of annotations produced", 135, resultAS.size());
064 gaz.setWholeWordsOnly(true);
065 resultAS.clear();
066
067 //test with prefix matching
068 gaz.setLongestMatchOnly(false);
069 gaz.execute();
070 assertTrue("Found " + resultAS.size() +
071 " annotations instead of the expected 68!", resultAS.size() == 68);
072 gaz.setLongestMatchOnly(true);
073 resultAS.clear();
074 Factory.deleteResource(gaz);
075
076 //test with case insensitive
077 FeatureMap fm = Factory.newFeatureMap();
078 fm.put(DefaultGazetteer.DEF_GAZ_CASE_SENSITIVE_PARAMETER_NAME, false);
079 gaz = (DefaultGazetteer) Factory.createResource(
080 "gate.creole.gazetteer.DefaultGazetteer", fm);
081 gaz.setDocument(doc);
082 gaz.setAnnotationSetName("GazetteerAS");
083 gaz.execute();
084 assertEquals("Wrong number of annotations generated", 96, resultAS.size());
085 gaz.setCaseSensitive(true);
086 resultAS.clear();
087 Factory.deleteResource(gaz);
088 Factory.deleteResource(doc);
089 }
090
091 /** Test suite routine for the test runner */
092 public static Test suite() {
093 return new TestSuite(TestGazetteer.class);
094 } // suite
095
096 public static void main(String[] args) {
097 try{
098 Gate.init();
099 TestGazetteer testGaz = new TestGazetteer("");
100 testGaz.setUp();
101 testGaz.testDefaultGazetteer();
102 testGaz.tearDown();
103 } catch(Exception e) {
104 e.printStackTrace();
105 }
106 } // main
107
108 } // TestGazetteer
|