private String getNext() { try { return reader.readLine(); } catch (IOException ex) { throw new RuntimeIOException(ex); } }
public TreeRecorder(Mode mode, String filename) { this.mode = mode; try { out = new BufferedWriter(new FileWriter(filename)); } catch (IOException e) { throw new RuntimeIOException(e); } }
public void saveSerialized(String path) { try { IOUtils.writeObjectToFile(this, path); } catch (IOException e) { throw new RuntimeIOException(e); } }
public static SentimentModel loadSerialized(String path) { try { return IOUtils.readObjectFromURLOrClasspathOrFileSystem(path); } catch (IOException | ClassNotFoundException e) { throw new RuntimeIOException(e); } }
public void loadSegmenter(String filename, Properties p) { try { classifier = CRFClassifier.getClassifier(filename, p); } catch (ClassCastException | IOException | ClassNotFoundException e) { throw new RuntimeIOException("Failed to load segmenter " + filename, e); } }
public void saveModel(String path) { try { IOUtils.writeObjectToFile(this, path); } catch (IOException e) { throw new RuntimeIOException(e); } }
/** * Annotate for named entities -- note that this combines multiple NER tag sets, and some auxiliary things (like temporal tagging) */ public Annotator ner(Properties properties) { try { return new NERCombinerAnnotator(properties); } catch (IOException e) { throw new RuntimeIOException(e); } }
@Override public void annotate(Annotation annotation) { try { this.annotate((CoreMap)annotation); } catch (IOException e) { throw new RuntimeIOException(e); } } private static final Map<String, String> TRANSLATE = new HashMap<String, String>() {{
@Override public void annotate(Annotation annotation) { try { this.annotate((CoreMap)annotation); } catch (IOException e) { throw new RuntimeIOException(e); } }
public void annotate(Annotation annotation) { try { this.annotate((CoreMap)annotation); } catch (IOException e) { throw new RuntimeIOException(e); } }
private static Properties loadPropertiesOrException(String propsFileNamePrefix) { Properties props = loadProperties(propsFileNamePrefix); if (props == null) { throw new RuntimeIOException("ERROR: cannot find properties file \"" + propsFileNamePrefix + "\" in the classpath!"); } return props; }
public void readGrammar(String filename) { try { FileReader fin = new FileReader(filename); BufferedReader bin = new BufferedReader(fin); readGrammar(bin); bin.close(); fin.close(); } catch (IOException e) { throw new RuntimeIOException(e); } }
private void loadCountriesLists(String file) { try (BufferedReader reader = IOUtils.readerFromString(file)) { for (String line; (line = reader.readLine()) != null; ) { countries.add(line.split("\t")[1].toLowerCase()); } } catch (IOException e) { throw new RuntimeIOException(e); } }
private static Stream<SentimentDatum> imdb(String path, SentimentClass label) { return StreamSupport.stream( IOUtils.iterFilesRecursive(new File(path)).spliterator(), true) .map(x -> { try { return new SentimentDatum(IOUtils.slurpFile(x), label); } catch (IOException e) { throw new RuntimeIOException(e); } }); }
private void loadNumberLists(String pluralWordsFile, String singularWordsFile) { try { getWordsFromFile(pluralWordsFile, pluralWords, false); getWordsFromFile(singularWordsFile, singularWords, false); } catch (IOException e) { throw new RuntimeIOException(e); } } private void loadStatesLists(String file) {
private void loadNumberLists(String pluralWordsFile, String singularWordsFile) { try { getWordsFromFile(pluralWordsFile, pluralWords, false); getWordsFromFile(singularWordsFile, singularWords, false); } catch (IOException e) { throw new RuntimeIOException(e); } } private void loadStatesLists(String file) {
public void outputXml(PrintWriter out, Annotation annotation) throws IOException { outputByWriter(writer -> { try { pipeline.xmlPrint(annotation, writer); } catch (IOException e) { throw new RuntimeIOException(e); } }, out); }
private void loadGenderLists(String maleWordsFile, String neutralWordsFile, String femaleWordsFile) { try { getWordsFromFile(maleWordsFile, maleWords, false); getWordsFromFile(neutralWordsFile, neutralWords, false); getWordsFromFile(femaleWordsFile, femaleWords, false); } catch (IOException e) { throw new RuntimeIOException(e); } }
/** Static helper */ public static void prettyPrint(Annotation annotation, PrintWriter pw, StanfordCoreNLP pipeline) { try { TaggedTextOutputter.print(annotation, pw, getOptions(pipeline.getProperties())); // already flushed // don't close, might not want to close underlying stream } catch (IOException e) { throw new RuntimeIOException(e); } }
public static <T> T readObjectAnnouncingTimingFromURLOrClasspathOrFileSystem(Redwood.RedwoodChannels log, String msg, String path) { T obj; try { Timing timing = new Timing(); obj = IOUtils.readObjectFromURLOrClasspathOrFileSystem(path); log.info(msg + ' ' + path + " ... done [" + timing.toSecondsString() + " sec]."); } catch (IOException | ClassNotFoundException e) { throw new RuntimeIOException(e); } return obj; }