use of edu.stanford.nlp.io.RuntimeIOException in project CoreNLP by stanfordnlp.
the class Document method jsonMinified.
/**
* Like the {@link Document@json(Function...)} function, but with minified JSON more suitable
* for sending over the wire.
*
* @param functions The (possibly empty) list of annotations to populate on the document before dumping it
* to JSON.
* @return The JSON String for this document, without unnecessary whitespace.
*
*/
@SafeVarargs
public final String jsonMinified(Function<Sentence, Object>... functions) {
for (Function<Sentence, Object> f : functions) {
f.apply(this.sentence(0));
}
try {
AnnotationOutputter.Options options = new AnnotationOutputter.Options();
options.pretty = false;
return new JSONOutputter().print(this.asAnnotation(), options);
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
use of edu.stanford.nlp.io.RuntimeIOException in project CoreNLP by stanfordnlp.
the class Dictionaries method loadCountriesLists.
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());
}
reader.close();
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
use of edu.stanford.nlp.io.RuntimeIOException in project CoreNLP by stanfordnlp.
the class TokensRegexNERAnnotator method readEntries.
/**
* Creates a combined list of Entries using the provided mapping files.
*
* @param mappings List of mapping files
* @return list of Entries
*/
private static List<Entry> readEntries(String annotatorName, Set<String> noDefaultOverwriteLabels, List<Boolean> ignoreCaseList, Map<Entry, Integer> entryToMappingFileNumber, boolean verbose, String[] headerFields, String[] annotationFieldnames, String... mappings) {
// Unlike RegexNERClassifier, we don't bother sorting the entries
// We leave it to TokensRegex NER to sort out the priorities and matches
// (typically after all the matches has been made since for some TokenRegex expression,
// we don't know how many tokens are matched until after the matching is done)
List<Entry> entries = new ArrayList<>();
TrieMap<String, Entry> seenRegexes = new TrieMap<>();
//Arrays.sort(mappings);
for (int mappingFileIndex = 0; mappingFileIndex < mappings.length; mappingFileIndex++) {
String mapping = mappings[mappingFileIndex];
BufferedReader rd = null;
try {
rd = IOUtils.readerFromString(mapping);
readEntries(annotatorName, headerFields, annotationFieldnames, entries, seenRegexes, mapping, rd, noDefaultOverwriteLabels, ignoreCaseList.get(mappingFileIndex), mappingFileIndex, entryToMappingFileNumber, verbose);
} catch (IOException e) {
throw new RuntimeIOException("Couldn't read TokensRegexNER from " + mapping, e);
} finally {
IOUtils.closeIgnoringExceptions(rd);
}
}
if (mappings.length != 1) {
logger.log("TokensRegexNERAnnotator " + annotatorName + ": Read " + entries.size() + " unique entries from " + mappings.length + " files");
}
return entries;
}
use of edu.stanford.nlp.io.RuntimeIOException in project CoreNLP by stanfordnlp.
the class TagCount method readTagCount.
/** A TagCount object's fields are read from the file. They are read from
* the current position and the file is not closed afterwards.
*/
public static TagCount readTagCount(DataInputStream rf) {
try {
TagCount tc = new TagCount();
int numTags = rf.readInt();
tc.map = Generics.newHashMap(numTags);
for (int i = 0; i < numTags; i++) {
String tag = rf.readUTF();
int count = rf.readInt();
if (tag.equals(NULL_SYMBOL))
tag = null;
tc.map.put(tag, count);
}
tc.getTagsCache = tc.map.keySet().toArray(new String[tc.map.keySet().size()]);
tc.sumCache = tc.calculateSumCache();
return tc;
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
use of edu.stanford.nlp.io.RuntimeIOException in project CoreNLP by stanfordnlp.
the class Dictionaries method loadGenderLists.
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);
}
}
Aggregations