1   /*
2    * AbstractGazetteer.java
3    *
4    * Copyright (c) 2002, 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, June1991.
9    *
10   * A copy of this licence is included in the distribution in the file
11   * licence.html, and is also available at http://gate.ac.uk/gate/licence.html.
12   *
13   * borislav popov 02/2002
14   *
15   */
16  package gate.creole.gazetteer;
17  
18  import java.util.*;
19  
20  import gate.FeatureMap;
21  import gate.creole.ResourceInstantiationException;
22  
23  /**AbstractGazetteer
24   * This class implements the common-for-all methods of the Gazetteer interface*/
25  public abstract class AbstractGazetteer
26    extends gate.creole.AbstractLanguageAnalyser implements Gazetteer {
27  
28    /** the set of gazetteer listeners */
29    protected Set listeners = new HashSet();
30  
31    /** Used to store the annotation set currently being used for the newly
32     * generated annotations*/
33    protected String annotationSetName;
34  
35    /** A map of the features */
36    protected FeatureMap features  = null;
37  
38    /** the encoding of the gazetteer */
39    protected String encoding = "UTF-8";
40  
41    /**
42     * The value of this property is the URL that will be used for reading the
43     * lists dtaht define this Gazetteer
44     */
45    protected java.net.URL listsURL;
46  
47    /**
48     * Should this gazetteer be case sensitive. The default value is true.
49     */
50    protected Boolean caseSensitive = new Boolean(true);
51  
52    /**
53     * Should this gazetteer only match whole words. The default value is
54     * <tt>true</tt>.
55     */
56    protected Boolean wholeWordsOnly;
57  
58    /** the linear definition of the gazetteer */
59    protected LinearDefinition definition;
60  
61    /** reference to mapping definiton info
62     *  allows filling of Lookup.ontologyClass according to a list*/
63    protected MappingDefinition mappingDefinition;
64  
65  
66    /**
67     * Sets the AnnotationSet that will be used at the next run for the newly
68     * produced annotations.
69     */
70    public void setAnnotationSetName(String newAnnotationSetName) {
71      annotationSetName = newAnnotationSetName;
72    }
73  
74    /**
75     * Gets the AnnotationSet that will be used at the next run for the newly
76     * produced annotations.
77     */
78    public String getAnnotationSetName() {
79      return annotationSetName;
80    }
81  
82    public void setEncoding(String newEncoding) {
83      encoding = newEncoding;
84    }
85  
86    public String getEncoding() {
87      return encoding;
88    }
89  
90    public java.net.URL getListsURL() {
91      return listsURL;
92    }
93  
94    public void setListsURL(java.net.URL newListsURL) {
95      listsURL = newListsURL;
96    }
97  
98    public void setCaseSensitive(Boolean newCaseSensitive) {
99      caseSensitive = newCaseSensitive;
100   }
101 
102   public Boolean getCaseSensitive() {
103     return caseSensitive;
104   }
105 
106   public void setMappingDefinition(MappingDefinition mapping) {
107     mappingDefinition = mapping;
108   }
109 
110   public MappingDefinition getMappingDefinition(){
111     return mappingDefinition;
112   }
113 
114   /**Gets the linear definition of this gazetteer. there is no parallel
115    * set method because the definition is loaded through the listsUrl
116    * on init().
117    * @return the linear definition of the gazetteer */
118   public LinearDefinition getLinearDefinition() {
119     return definition;
120   }
121 
122   /**     */
123   public FeatureMap getFeatures(){
124     return features;
125   } // getFeatures
126 
127   /**     */
128   public void setFeatures(FeatureMap features){
129     this.features = features;
130   } // setFeatures
131 
132   public void reInit() throws ResourceInstantiationException {
133     super.reInit();
134     fireGazetteerEvent(new GazetteerEvent(this,GazetteerEvent.REINIT));
135   }//reInit()
136 
137   /**
138    * fires a Gazetteer Event
139    * @param ge Gazetteer Event to be fired
140    */
141   public void fireGazetteerEvent(GazetteerEvent ge) {
142     Iterator li = listeners.iterator();
143     while ( li.hasNext()) {
144       GazetteerListener gl = (GazetteerListener) li.next();
145       gl.processGazetteerEvent(ge);
146     }
147   }
148 
149   /**
150    * Registers a Gazetteer Listener
151    * @param gl Gazetteer Listener to be registered
152    */
153   public void addGazetteerListener(GazetteerListener gl){
154     if ( null!=gl )
155       listeners.add(gl);
156   }
157 
158   /**
159    * Gets the value for the {@link #wholeWordsOnly} parameter.
160    * @return a Boolean value.
161    */
162   public Boolean getWholeWordsOnly() {
163     return wholeWordsOnly;
164   }
165 
166   /**
167    * Sets the value for the {@link #wholeWordsOnly} parameter.
168    * @param wholeWordsOnly a Boolean value.
169    */
170   public void setWholeWordsOnly(Boolean wholeWordsOnly) {
171     this.wholeWordsOnly = wholeWordsOnly;
172   }
173 
174 }//class AbstractGazetteer