use of java.io.BufferedReader in project CoreNLP by stanfordnlp.
the class Counters method deserializeStringCounter.
/**
* Read a Counter from a serialized file
* @param filename The file to read from
*
* @see Counters#serializeStringCounter(Counter, String, double)
*/
public static ClassicCounter<String> deserializeStringCounter(String filename) throws IOException {
String[] fields = new String[4];
BufferedReader reader = IOUtils.readerFromString(filename);
String line;
ClassicCounter<String> counts = new ClassicCounter<>(1000000);
while ((line = reader.readLine()) != null) {
StringUtils.splitOnChar(fields, line, '\t');
long mantissa = SloppyMath.parseInt(fields[2]);
int exponent = (int) SloppyMath.parseInt(fields[3]);
double value = SloppyMath.parseDouble(fields[1].equals("-"), mantissa, exponent);
counts.setCount(fields[0], value);
}
return counts;
}
use of java.io.BufferedReader in project CoreNLP by stanfordnlp.
the class Counters method loadInto2DCounter.
public static <T1, T2> void loadInto2DCounter(String filename, Class<T1> t1, Class<T2> t2, TwoDimensionalCounter<T1, T2> tdc) throws RuntimeException {
try {
Constructor<T1> m1 = t1.getConstructor(String.class);
Constructor<T2> m2 = t2.getConstructor(String.class);
// new
BufferedReader in = IOUtils.getBufferedFileReader(filename);
// FileReader(filename));
for (String line; (line = in.readLine()) != null; ) {
String[] tuple = line.trim().split("\t");
String outer = tuple[0];
String inner = tuple[1];
String valStr = tuple[2];
tdc.setCount(m1.newInstance(outer.trim()), m2.newInstance(inner.trim()), Double.parseDouble(valStr.trim()));
}
in.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of java.io.BufferedReader in project CoreNLP by stanfordnlp.
the class TrueCasingForNISTDocumentReaderAndWriter method main.
/**
* for test only
**/
public static void main(String[] args) throws IOException {
Reader reader = new BufferedReader(new FileReader(args[0]));
TrueCasingForNISTDocumentReaderAndWriter raw = new TrueCasingForNISTDocumentReaderAndWriter();
raw.init(null);
for (Iterator<List<CoreLabel>> it = raw.getIterator(reader); it.hasNext(); ) {
List<CoreLabel> l = it.next();
for (CoreLabel cl : l) {
System.out.println(cl);
}
System.out.println("========================================");
}
}
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 loadSignatures.
private static void loadSignatures(String file, Map<String, Counter<String>> sigs) {
BufferedReader reader = null;
try {
reader = IOUtils.readerFromString(file);
while (reader.ready()) {
String[] split = reader.readLine().split("\t");
Counter<String> cntr = new ClassicCounter<>();
sigs.put(split[0], cntr);
for (int i = 1; i < split.length; i = i + 2) {
cntr.setCount(split[i], Double.parseDouble(split[i + 1]));
}
}
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeIgnoringExceptions(reader);
}
}
Aggregations