|
OntoGazetteerImpl |
|
1 /* 2 * OntoGazetteerImpl.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 gate.*; 19 import gate.creole.*; 20 21 22 23 import java.io.*; 24 25 /** OntoGazetteerImpl <br> 26 * An ontology-aware gazetteer, producing additional annotations 27 * with features [class] and [ontology]. 28 */ 29 public class OntoGazetteerImpl extends AbstractOntoGazetteer { 30 31 public OntoGazetteerImpl() { 32 } 33 34 public java.util.Set lookup(String singleItem) { 35 return gaz.lookup(singleItem); 36 } 37 38 /** Initialize this onto gazetteer 39 * @return .*/ 40 public Resource init() throws ResourceInstantiationException { 41 try { 42 checkParameters(); 43 44 Class cl = Class.forName(gazetteerName); 45 46 FeatureMap params = Factory.newFeatureMap(); 47 48 mappingDefinition = new MappingDefinition(); 49 mappingDefinition.setURL(mappingURL); 50 mappingDefinition.load(); 51 52 params.put("caseSensitive",caseSensitive); 53 params.put("listsURL",listsURL); 54 params.put("encoding",encoding); 55 params.put("mappingDefinition",mappingDefinition); 56 gaz = (Gazetteer)Factory.createResource(cl.getName(),params); 57 58 } catch (ClassNotFoundException e) { 59 throw new RuntimeException("ClassNotFoundException : "+e.getMessage()); 60 } catch (InvalidFormatException e) { 61 throw new ResourceInstantiationException(e); 62 } 63 return this; 64 } // init 65 66 /** Executes this onto gazetteer over a pre-set document 67 * @throws ExecutionException if something goes wrong with the execution */ 68 public void execute()throws ExecutionException { 69 if (null == gaz) { 70 throw new ExecutionException("gazetteer not initialized (null)."); 71 } 72 73 gaz.setDocument(document); 74 gaz.setAnnotationSetName(annotationSetName); 75 gaz.setEncoding(encoding); 76 gaz.setCorpus(corpus); 77 gaz.execute(); 78 } // execute 79 80 /** 81 * Checks the parameters set to this gazetteer 82 * @throws ResourceInstantiationException if something goes wrong 83 */ 84 private void checkParameters() throws ResourceInstantiationException { 85 boolean set = null!=gazetteerName; 86 set &= null!=listsURL; 87 set&=null!=mappingURL; 88 if (!set) { 89 throw new ResourceInstantiationException("some parameters are not set (e.g.gazetteerName," 90 +"listURL,mappingDefinition, document"); 91 } 92 93 } // checkParameters 94 95 /** 96 * Removes a single string item from the gazetteer model 97 * @param singleItem removes a string item from the gazetteer model 98 * @return true if the string is removed from the model, otherwise - false 99 */ 100 public boolean remove(String singleItem) { 101 return gaz.remove(singleItem); 102 } 103 104 /** 105 * Adds a string item to the model and associates it with a Lookup 106 * @param singleItem the string item to be added 107 * @param lookup the lookup to be associated with the string item 108 * @return true if the item has been added, otherwise - false. 109 */ 110 public boolean add(String singleItem, Lookup lookup) { 111 return gaz.add(singleItem,lookup); 112 } 113 114 } // OntoGazetteerImpl
|
OntoGazetteerImpl |
|