/** * 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
/** * Add a node to this LinearDefinition. * <p> * NOTE: this will throw a GateRuntimeException if anything goes wrong * when reading the list. * * @param index * @param ln */ @Override public void add(int index, LinearNode ln) { String list = ln.getList(); if(!nodesByList.containsKey(list)) { try { GazetteerList gl = loadSingleList(list); gazListsByNode.put(ln, gl); nodes.add(index, ln); nodesByList.put(list, ln); lists.add(list); isModified = true; } catch(ResourceInstantiationException x) { throw new GateRuntimeException("Error loading list: " + list + ": " + x.getMessage(), x); } } // if unique }
@Override public void actionPerformed(ActionEvent e) { if (selectedLinearNode == null) { return; } GazetteerList gazetteerList = linearDefinition.getListsByNode().get(selectedLinearNode); gazetteerList.clear(); try { gazetteerList.load(true); } catch (ResourceInstantiationException rie) { rie.printStackTrace(); return; } // reselect the row to redisplay the list int row = definitionTable.getSelectedRow(); definitionTable.clearSelection(); definitionTable.getSelectionModel().setSelectionInterval(row, row); } }
rie.printStackTrace(); return;
/** * 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); }
} catch(ResourceInstantiationException x) { throw new GateRuntimeException("Error loading list: " + list + ": " + x.getMessage(), x);
gazetteerList = linearDefinition.loadSingleList(listName, true); } catch (ResourceInstantiationException rie) { rie.printStackTrace(); return;
@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; }
if(theList.isModified()) theList.store(); } catch(ResourceInstantiationException ex) { throw new GateRuntimeException(ex.getMessage());
/** * 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();
MainFrame.getInstance().statusChanged( "Unable to save the Gazetteer."); Err.prln("Unable to save the Gazetteer.\n" + re.getMessage()); } catch (MalformedURLException mue) { mue.printStackTrace();
/** * 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();
@Override public void actionPerformed(ActionEvent e) { try { if (linearDefinition.isModified()) { linearDefinition.store(); } for (Object object : linearDefinition.getListsByNode().values()) { GazetteerList gazetteerList = (GazetteerList) object; if (gazetteerList.isModified()) { gazetteerList.store(); } } gazetteer.reInit(); MainFrame.getInstance().statusChanged("Gazetteer saved in " + linearDefinition.getURL().getPath()); definitionTable.repaint(); } catch (ResourceInstantiationException re) { MainFrame.getInstance().statusChanged( "Unable to save the Gazetteer."); Err.prln("Unable to save the Gazetteer.\n" + re.getMessage()); } } }
/** * 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()
+ gazetteerList.getURL().getPath()); } catch (ResourceInstantiationException rie) { Err.prln("Unable to save the list.\n" + rie.getMessage()); return;
@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 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();
/** * 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();
throw new ResourceInstantiationException("URL not specified (null)."); throw new ResourceInstantiationException(x.getClass() + ":" + x.getMessage(),x);