1
16 package gate.creole.gazetteer;
17
18 import gate.*;
19 import gate.creole.ExecutionException;
20 import gate.creole.ResourceInstantiationException;
21
22
26 public class OntoGazetteerImpl extends AbstractOntoGazetteer {
27
28 public OntoGazetteerImpl() {
29 }
30
31 public java.util.Set lookup(String singleItem) {
32 return gaz.lookup(singleItem);
33 }
34
35
37 public Resource init() throws ResourceInstantiationException {
38 try {
39 checkParameters();
40
41 Class cl = Class.forName(gazetteerName);
42
43 FeatureMap params = Factory.newFeatureMap();
44
45 mappingDefinition = new MappingDefinition();
46 mappingDefinition.setURL(mappingURL);
47 mappingDefinition.load();
48
49 params.put("caseSensitive",caseSensitive);
50 params.put("listsURL",listsURL);
51 params.put("encoding",encoding);
52 params.put("mappingDefinition",mappingDefinition);
53 gaz = (Gazetteer)Factory.createResource(cl.getName(),params);
54
55 } catch (ClassNotFoundException e) {
56 throw new RuntimeException("ClassNotFoundException : "+e.getMessage());
57 } catch (InvalidFormatException e) {
58 throw new ResourceInstantiationException(e);
59 }
60 return this;
61 }
63
65 public void execute()throws ExecutionException {
66 if (null == gaz) {
67 throw new ExecutionException("gazetteer not initialized (null).");
68 }
69
70 gaz.setDocument(document);
71 gaz.setAnnotationSetName(annotationSetName);
72 gaz.setEncoding(encoding);
73 gaz.setCorpus(corpus);
74 gaz.execute();
75 }
77
81 private void checkParameters() throws ResourceInstantiationException {
82 boolean set = null!=gazetteerName;
83 set &= null!=listsURL;
84 set&=null!=mappingURL;
85 if (!set) {
86 throw new ResourceInstantiationException("some parameters are not set (e.g.gazetteerName,"
87 +"listURL,mappingDefinition, document");
88 }
89
90 }
92
97 public boolean remove(String singleItem) {
98 return gaz.remove(singleItem);
99 }
100
101
107 public boolean add(String singleItem, Lookup lookup) {
108 return gaz.add(singleItem,lookup);
109 }
110
111 }