use of java.io.BufferedReader in project CoreNLP by stanfordnlp.
the class Dictionaries method loadCorefDict.
private static void loadCorefDict(String[] file, ArrayList<Counter<Pair<String, String>>> dict) {
for (int i = 0; i < 4; i++) {
dict.add(new ClassicCounter<>());
BufferedReader reader = null;
try {
reader = IOUtils.readerFromString(file[i]);
// Skip the first line (header)
reader.readLine();
while (reader.ready()) {
String[] split = reader.readLine().split("\t");
dict.get(i).setCount(new Pair<>(split[0], split[1]), Double.parseDouble(split[2]));
}
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeIgnoringExceptions(reader);
}
}
}
use of java.io.BufferedReader in project CoreNLP by stanfordnlp.
the class Dictionaries method loadCorefDictPMI.
private static void loadCorefDictPMI(String file, Counter<Pair<String, String>> dict) {
BufferedReader reader = null;
try {
reader = IOUtils.readerFromString(file);
// Skip the first line (header)
reader.readLine();
while (reader.ready()) {
String[] split = reader.readLine().split("\t");
dict.setCount(new Pair<>(split[0], split[1]), Double.parseDouble(split[3]));
}
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeIgnoringExceptions(reader);
}
}
use of java.io.BufferedReader 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 java.io.BufferedReader in project CoreNLP by stanfordnlp.
the class Dictionaries method loadDemonymLists.
/** The format of the demonyms file is
* countryCityOrState ( TAB demonym )*
* Lines starting with # are ignored
* The file is cased but stored in in-memory data structures uncased.
* The results are:
* demonyms is a hash from each country (etc.) to a set of demonymic Strings;
* adjectiveNation is a set of demonymic Strings;
* demonymSet has all country (etc.) names and all demonymic Strings.
*/
private void loadDemonymLists(String demonymFile) {
BufferedReader reader = null;
try {
reader = IOUtils.readerFromString(demonymFile);
for (String line; (line = reader.readLine()) != null; ) {
line = line.toLowerCase(Locale.ENGLISH);
String[] tokens = line.split("\t");
if (tokens[0].startsWith("#"))
continue;
Set<String> set = Generics.newHashSet();
for (String s : tokens) {
set.add(s);
demonymSet.add(s);
}
demonyms.put(tokens[0], set);
}
adjectiveNation.addAll(demonymSet);
adjectiveNation.removeAll(demonyms.keySet());
} catch (IOException e) {
throw new RuntimeIOException(e);
} finally {
IOUtils.closeIgnoringExceptions(reader);
}
}
use of java.io.BufferedReader in project CoreNLP by stanfordnlp.
the class ConvertGenderFile method main.
public static void main(String[] args) throws IOException {
String input = null;
String output = null;
for (int argIndex = 0; argIndex < args.length; ) {
if (args[argIndex].equalsIgnoreCase("-input")) {
input = args[argIndex + 1];
argIndex += 2;
} else if (args[argIndex].equalsIgnoreCase("-output")) {
output = args[argIndex + 1];
argIndex += 2;
} else {
throw new IllegalArgumentException("Unknown argument " + args[argIndex]);
}
}
if (input == null) {
throw new IllegalArgumentException("Must specify input with -input");
}
if (output == null) {
throw new IllegalArgumentException("Must specify output with -output");
}
Map<List<String>, Gender> genderNumber = Generics.newHashMap();
BufferedReader reader = IOUtils.readerFromString(input);
for (String line; (line = reader.readLine()) != null; ) {
String[] split = line.split("\t");
String[] countStr = split[1].split(" ");
int male = Integer.parseInt(countStr[0]);
int female = Integer.parseInt(countStr[1]);
int neutral = Integer.parseInt(countStr[2]);
Gender gender = Gender.UNKNOWN;
if (male * 0.5 > female + neutral && male > 2) {
gender = Gender.MALE;
} else if (female * 0.5 > male + neutral && female > 2) {
gender = Gender.FEMALE;
} else if (neutral * 0.5 > male + female && neutral > 2) {
gender = Gender.NEUTRAL;
}
if (gender == Gender.UNKNOWN) {
continue;
}
String[] words = split[0].split(" ");
List<String> tokens = Arrays.asList(words);
genderNumber.put(tokens, gender);
}
IOUtils.writeObjectToFile(genderNumber, output);
}
Aggregations