/** * Checks the parameters set to this gazetteer * @throws ResourceInstantiationException if something goes wrong */ private void checkParameters() throws ResourceInstantiationException { boolean set = null!=gazetteerName; set &= null!=listsURL; set&=null!=mappingURL; if (!set) { throw new ResourceInstantiationException("some parameters are not set (e.g.gazetteerName," +"listURL,mappingDefinition, document"); } } // checkParameters
/** * Generates the error and stop the execution * * @param mess - * message to be displayed as an error on the standard output */ private void generateError(String mess) throws ResourceInstantiationException { System.out.println("\n\n" + mess); System.out.println("Program terminated..."); throw new ResourceInstantiationException("\n\n" + mess); }
@Override public Resource init()throws ResourceInstantiationException{ if(lexiconURL == null){ throw new ResourceInstantiationException( "NoURL provided for the lexicon!"); } if(rulesURL == null){ throw new ResourceInstantiationException( "No URL provided for the rules!"); } try{ tagger = new hepple.postag.POSTagger(lexiconURL.toURL(),rulesURL.toURL(), encoding, separator); }catch(IOException | InvalidRuleException e){ throw new ResourceInstantiationException(e); } return this; }
/** * Stores the mapping definition * @throws ResourceInstantiationException if store fails. */ public void store()throws ResourceInstantiationException{ if (null == url) { throw new ResourceInstantiationException("URL not set (null)."); } try { File fileo = Files.fileFromURL(url); fileo.delete(); BufferedWriter mapWriter = new BufferedWriter(new FileWriter(fileo)); for (int index = 0 ; index < nodes.size() ; index++) { mapWriter.write(nodes.get(index).toString()); mapWriter.newLine(); } mapWriter.close(); } catch (IOException ioe) { throw new ResourceInstantiationException(ioe); } } //store();
/** * Stores this to a definition file. */ public void store() throws ResourceInstantiationException { if(null == url) { throw new ResourceInstantiationException("URL not set.(null)"); } try { File fileo = Files.fileFromURL(url); fileo.delete(); BufferedWriter defWriter = new BufferedWriter(new FileWriter(fileo)); Iterator<LinearNode> inodes = nodes.iterator(); while(inodes.hasNext()) { defWriter.write(inodes.next().toString()); defWriter.newLine(); } defWriter.close(); isModified = false; } catch(Exception x) { throw new ResourceInstantiationException(x); } } // store();
/** * Stores the list to the specified url * * @throws ResourceInstantiationException */ public void store() throws ResourceInstantiationException { try { if(null == url) { throw new ResourceInstantiationException("URL not specified (null)"); } File fileo = Files.fileFromURL(url); fileo.delete(); OutputStreamWriter listWriter = new OutputStreamWriter(new FileOutputStream(fileo), encoding); // BufferedWriter listWriter = new BufferedWriter(new // FileWriter(fileo)); Iterator<GazetteerNode> iter = entries.iterator(); while(iter.hasNext()) { listWriter.write(iter.next().toString()); listWriter.write(13); listWriter.write(10); } listWriter.close(); } catch(Exception x) { throw new ResourceInstantiationException(x.getClass() + ":" + x.getMessage()); } isModified = false; } // store()
@Override public Resource init() throws ResourceInstantiationException { super.init(); try { //sanity checks if(internalSplitListURL == null) throw new ResourceInstantiationException("No list of internal splits provided!"); if(externalSplitListURL == null) throw new ResourceInstantiationException("No list of external splits provided!"); if(nonSplitListURL == null) throw new ResourceInstantiationException("No list of non splits provided!"); if(encoding == null) throw new ResourceInstantiationException("No encoding provided!"); //load the known abbreviations list internalSplitsPattern = compilePattern(internalSplitListURL.toURL(), encoding); externalSplitsPattern = compilePattern(externalSplitListURL.toURL(), encoding); nonSplitsPattern = compilePattern(nonSplitListURL.toURL(), encoding); } catch(UnsupportedEncodingException e) { throw new ResourceInstantiationException(e); } catch(IOException e) { throw new ResourceInstantiationException(e); } return this; }
} else if((startAnnoName == -1 && endAnnoName != -1) || (startAnnoName != -1 && endAnnoName == -1)) { throw new ResourceInstantiationException( "Failed to parse configuration file for Configurable " + "Exporter.");
/** * Loads linear definition if url is set */ public void load() throws ResourceInstantiationException { if(null == url) { throw new ResourceInstantiationException("URL not set (null)."); } BufferedReader defReader = null; try { if("file".equals(url.getProtocol())) { File definitionFile = Files.fileFromURL(url); // create an new definition file only if not existing definitionFile.createNewFile(); } defReader = new BomStrippingInputStreamReader((url).openStream(), ENCODING); String line; LinearNode node; while(null != (line = defReader.readLine())) { node = new LinearNode(line); this.add(node); } // while isModified = false; } catch(Exception x) { throw new ResourceInstantiationException(x); } finally { IOUtils.closeQuietly(defReader); } } // load();
/**Loads the mapping definition * @throws ResourceInstantiationException if load fails. */ public void load() throws ResourceInstantiationException,InvalidFormatException { if (null == url) { throw new ResourceInstantiationException("URL not set (null)."); } try { BufferedReader mapReader = new BomStrippingInputStreamReader((url).openStream(), ENCODING); String line; MappingNode node; while (null != (line = mapReader.readLine())) { if (0 != line.trim().length()) { node = new MappingNode(line); this.add(node); } // if } //while mapReader.close(); } catch (InvalidFormatException ife){ throw new InvalidFormatException(url,"on load"); } catch (IOException ioe) { throw new ResourceInstantiationException(ioe); } } // load();
throw new ResourceInstantiationException("URL not specified (null)."); throw new ResourceInstantiationException(x.getClass() + ":" + x.getMessage(),x);
}else{ throw new ResourceInstantiationException( "No URL provided for the rules!"); throw new ResourceInstantiationException(ioe); }catch(TokeniserException te){ throw new ResourceInstantiationException(te);
throw new ResourceInstantiationException(x); throw new ResourceInstantiationException(murle); } catch(IOException ioex) { throw new ResourceInstantiationException(ioex);
protected static void loadPlugin() throws Exception { if (!Gate.isInitialised()) { Gate.runInSandbox(true); Gate.init(); } URL creoleUrl = GATEPluginTestCase.class.getResource("/creole.xml"); if(creoleUrl == null) { throw new ResourceInstantiationException("Could not load plugin, creole.xml not found"); } Properties properties = new Properties(); URL propsUrl = GATEPluginTestCase.class.getResource("/creole.properties"); if(propsUrl == null) { throw new ResourceInstantiationException("Could not load plugin, creole.properties not found"); } InputStream propsStream = propsUrl.openStream(); properties.load(propsStream); Plugin plugin = new PluginUnderTest(Files.fileFromURL(creoleUrl), properties.getProperty("groupId"), properties.getProperty("artifactId"), properties.getProperty("version")); if (!Gate.getCreoleRegister().getPlugins().contains(plugin)) { Gate.getCreoleRegister().registerPlugin(plugin); } }
/** * Loads the gazetteer lists and maps them to the nodes * * @return a map of nodes vs GazetteerLists * @param isOrdered true if the feature maps used should be ordered * @throws ResourceInstantiationException when the resource cannot be * created */ public Map<LinearNode, GazetteerList> loadLists(boolean isOrdered) throws ResourceInstantiationException { try { gazListsByNode = new HashMap<LinearNode, GazetteerList>(); Iterator<LinearNode> inodes = nodes.iterator(); while(inodes.hasNext()) { LinearNode node = inodes.next(); GazetteerList list = new GazetteerList(); list.setSeparator(separator); URL lurl = new URL(url, node.getList()); list.setURL(lurl); list.setEncoding(encoding); list.load(isOrdered); gazListsByNode.put(node, list); } // while inodes } catch(Exception ex) { throw new ResourceInstantiationException(ex); } return gazListsByNode; } // loadLists()
/** * Copy the references to the shareable state (i.e. the FSM) from the * existing gazetteer. Note that this method <i>deliberately</i> does * not call <code>super.init()</code> as to do so would cause the * lists to be reloaded. */ @Override public Resource init() throws ResourceInstantiationException { if(bootstrapGazetteer == null) { throw new ResourceInstantiationException( "No gazetteer provided to bootstrap this gazetteer creation!"); } this.annotationSetName = bootstrapGazetteer.annotationSetName; this.caseSensitive = bootstrapGazetteer.caseSensitive; this.definition = bootstrapGazetteer.definition; this.encoding = bootstrapGazetteer.encoding; this.fsmStates = bootstrapGazetteer.fsmStates; this.gazetteerFeatureSeparator = bootstrapGazetteer.gazetteerFeatureSeparator; this.initialState = bootstrapGazetteer.initialState; this.listsByNode = bootstrapGazetteer.listsByNode; this.listsURL = bootstrapGazetteer.listsURL; this.longestMatchOnly = bootstrapGazetteer.longestMatchOnly; this.mappingDefinition = bootstrapGazetteer.mappingDefinition; this.wholeWordsOnly = bootstrapGazetteer.wholeWordsOnly; this.getFeatures().putAll(bootstrapGazetteer.getFeatures()); return this; }
throw new ResourceInstantiationException( "No URL provided for gazetteer creation!"); try { throw new ResourceInstantiationException(e); throw new ResourceInstantiationException(exception);
if (rulesFile == null) { throw new ResourceInstantiationException("\n\n No Rule File Provided"); interpret.init(rulesFile.toURL()); } catch(IOException e) { throw new ResourceInstantiationException(e);
initialState = new FSMState(this); if(listsURL == null){ throw new ResourceInstantiationException ( "No URL provided for gazetteer creation!"); throw new ResourceInstantiationException(e);
/** Initialize this onto gazetteer * @return .*/ @Override public Resource init() throws ResourceInstantiationException { try { checkParameters(); FeatureMap params = Factory.newFeatureMap(); mappingDefinition = new MappingDefinition(); mappingDefinition.setURL(mappingURL); mappingDefinition.load(); params.put("caseSensitive",caseSensitive); params.put("listsURL",listsURL); params.put("encoding",encoding); params.put("mappingDefinition",mappingDefinition); gaz = (Gazetteer)Factory.createResource(gazetteerName,params); } catch (InvalidFormatException e) { throw new ResourceInstantiationException(e); } return this; } // init