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, true, Gate.getClassLoader());
43
44 FeatureMap params = Factory.newFeatureMap();
45
46 mappingDefinition = new MappingDefinition();
47 mappingDefinition.setURL(mappingURL);
48 mappingDefinition.load();
49
50 params.put("caseSensitive",caseSensitive);
51 params.put("listsURL",listsURL);
52 params.put("encoding",encoding);
53 params.put("mappingDefinition",mappingDefinition);
54 gaz = (Gazetteer)Factory.createResource(cl.getName(),params);
55
56 } catch (ClassNotFoundException e) {
57 throw new RuntimeException("ClassNotFoundException : "+e.getMessage());
58 } catch (InvalidFormatException e) {
59 throw new ResourceInstantiationException(e);
60 }
61 return this;
62 }
64
66 public void execute()throws ExecutionException {
67 if (null == gaz) {
68 throw new ExecutionException("gazetteer not initialized (null).");
69 }
70
71 gaz.setDocument(document);
72 gaz.setAnnotationSetName(annotationSetName);
73 gaz.setEncoding(encoding);
74 gaz.setCorpus(corpus);
75 gaz.execute();
76 }
78
82 private void checkParameters() throws ResourceInstantiationException {
83 boolean set = null!=gazetteerName;
84 set &= null!=listsURL;
85 set&=null!=mappingURL;
86 if (!set) {
87 throw new ResourceInstantiationException("some parameters are not set (e.g.gazetteerName,"
88 +"listURL,mappingDefinition, document");
89 }
90
91 }
93
98 public boolean remove(String singleItem) {
99 return gaz.remove(singleItem);
100 }
101
102
108 public boolean add(String singleItem, Lookup lookup) {
109 return gaz.add(singleItem,lookup);
110 }
111
112 }