use of edu.stanford.nlp.io.RuntimeIOException in project CoreNLP by stanfordnlp.
the class MaxentTagger method saveModel.
protected void saveModel(String filename) {
try {
DataOutputStream file = IOUtils.getDataOutputStream(filename);
saveModel(file);
file.close();
} catch (IOException ioe) {
log.info("Error saving tagger to file " + filename);
throw new RuntimeIOException(ioe);
}
}
use of edu.stanford.nlp.io.RuntimeIOException in project CoreNLP by stanfordnlp.
the class ParsedGigawordReader method iterator.
@Override
public Iterator<Annotation> iterator() {
return new Iterator<Annotation>() {
private Iterator<BufferedReader> readers = Iterables.transform(files, file -> IOUtils.readerFromFile(file)).iterator();
private BufferedReader reader = findReader();
private Annotation annotation = findAnnotation();
@Override
public boolean hasNext() {
return this.annotation != null;
}
@Override
public Annotation next() {
if (this.annotation == null) {
throw new NoSuchElementException();
}
Annotation toReturn = this.annotation;
this.annotation = this.findAnnotation();
return toReturn;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
private BufferedReader findReader() {
return this.readers.hasNext() ? this.readers.next() : null;
}
private Annotation findAnnotation() {
if (this.reader == null) {
return null;
}
try {
String line;
StringBuilder doc = new StringBuilder();
while ((line = this.reader.readLine()) != null) {
doc.append(line);
doc.append('\n');
// }
if (line.equals("</DOC>")) {
break;
}
if (line.contains("</DOC>")) {
throw new RuntimeException(String.format("invalid line '%s'", line));
}
}
if (line == null) {
this.reader.close();
this.reader = findReader();
}
String xml = doc.toString().replaceAll("&", "&");
if (xml == null || xml.equals("")) {
return findAnnotation();
}
xml = xml.replaceAll("num=([0-9]+) (.*)", "num=\"$1\" $2");
xml = xml.replaceAll("sid=(.*)>", "sid=\"$1\">");
xml = xml.replaceAll("</SENT>\n</DOC>", "</SENT>\n</TEXT>\n</DOC>");
xml = new String(xml.getBytes(), "UTF8");
// log.info("This is what goes in:\n" + xml);
return toAnnotation(xml);
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
};
}
use of edu.stanford.nlp.io.RuntimeIOException in project CoreNLP by stanfordnlp.
the class TTags method read.
protected void read(DataInputStream file) {
try {
int size = file.readInt();
index = new HashIndex<>();
for (int i = 0; i < size; i++) {
String tag = file.readUTF();
boolean inClosed = file.readBoolean();
index.add(tag);
if (inClosed)
closed.add(tag);
}
} catch (IOException e) {
throw new RuntimeIOException(e);
}
}
use of edu.stanford.nlp.io.RuntimeIOException in project CoreNLP by stanfordnlp.
the class ColumnDataClassifier method loadClassifier.
private static Pair<Flags[], Classifier<String, String>> loadClassifier(String path) {
Timing t = new Timing();
try (ObjectInputStream ois = IOUtils.readStreamFromString(path)) {
Pair<Flags[], Classifier<String, String>> pair = loadClassifier(ois);
t.done(logger, "Loading classifier from " + path);
return pair;
} catch (IOException | ClassNotFoundException e) {
throw new RuntimeIOException("Error loading classifier from " + path, e);
}
}
use of edu.stanford.nlp.io.RuntimeIOException in project CoreNLP by stanfordnlp.
the class LexicalizedParser method saveParserToSerialized.
/**
* Saves the parser defined by pd to the given filename.
* If there is an error, a RuntimeIOException is thrown.
*/
public void saveParserToSerialized(String filename) {
try {
log.info("Writing parser in serialized format to file " + filename + ' ');
ObjectOutputStream out = IOUtils.writeStreamFromString(filename);
out.writeObject(this);
out.close();
log.info("done.");
} catch (IOException ioe) {
throw new RuntimeIOException(ioe);
}
}
Aggregations