use of edu.stanford.nlp.io.StringOutputStream in project CoreNLP by stanfordnlp.
the class JSONOutputter method jsonPrint.
public static String jsonPrint(Annotation annotation) throws IOException {
StringOutputStream os = new StringOutputStream();
new JSONOutputter().print(annotation, os);
return os.toString();
}
use of edu.stanford.nlp.io.StringOutputStream in project CoreNLP by stanfordnlp.
the class XMLUtils method documentToString.
public static String documentToString(Document document) {
StringOutputStream s = new StringOutputStream();
printNode(s, document, true, true);
return s.toString();
}
use of edu.stanford.nlp.io.StringOutputStream in project CoreNLP by stanfordnlp.
the class CorefScorer method getEvalSummary.
public static String getEvalSummary(String evalScript, String goldFile, String predictFile) throws IOException {
ProcessBuilder process = new ProcessBuilder(evalScript, "all", goldFile, predictFile, "none");
StringOutputStream errSos = new StringOutputStream();
StringOutputStream outSos = new StringOutputStream();
PrintWriter out = new PrintWriter(outSos);
PrintWriter err = new PrintWriter(errSos);
SystemUtils.run(process, out, err);
out.close();
err.close();
String summary = outSos.toString();
String errStr = errSos.toString();
if (!errStr.isEmpty()) {
summary += "\nERROR: " + errStr;
}
Pattern pattern = Pattern.compile("\\d+\\.\\d\\d\\d+");
DecimalFormat df = new DecimalFormat("#.##");
Matcher matcher = pattern.matcher(summary);
while (matcher.find()) {
String number = matcher.group();
summary = summary.replaceFirst(number, df.format(Double.parseDouble(number)));
}
return summary;
}
use of edu.stanford.nlp.io.StringOutputStream in project CoreNLP by stanfordnlp.
the class CharniakScoredParsesReaderWriter method parsesToString.
/**
* Convert list of scored parse trees to string representing scored parses
* (in the charniak parser output format)
* @param parses - list of scored parse trees
* @return string representing scored parses
*/
public String parsesToString(List<ScoredObject<Tree>> parses) {
if (parses == null)
return null;
StringOutputStream os = new StringOutputStream();
PrintWriter pw = new PrintWriter(os);
printScoredTrees(pw, 0, parses);
pw.close();
return os.toString();
}
use of edu.stanford.nlp.io.StringOutputStream in project CoreNLP by stanfordnlp.
the class SieveCoreferenceSystem method getConllEvalSummary.
public static String getConllEvalSummary(String conllMentionEvalScript, String goldFile, String predictFile) throws IOException {
ProcessBuilder process = new ProcessBuilder(conllMentionEvalScript, "all", goldFile, predictFile, "none");
StringOutputStream errSos = new StringOutputStream();
StringOutputStream outSos = new StringOutputStream();
PrintWriter out = new PrintWriter(outSos);
PrintWriter err = new PrintWriter(errSos);
SystemUtils.run(process, out, err);
out.close();
err.close();
String summary = outSos.toString();
String errStr = errSos.toString();
if (!errStr.isEmpty()) {
summary += "\nERROR: " + errStr;
}
Pattern pattern = Pattern.compile("\\d+\\.\\d\\d\\d+");
DecimalFormat df = new DecimalFormat("#.##");
Matcher matcher = pattern.matcher(summary);
while (matcher.find()) {
String number = matcher.group();
summary = summary.replaceFirst(number, df.format(Double.parseDouble(number)));
}
return summary;
}
Aggregations