Search in sources :

Example 1 with StringOutputStream

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();
}
Also used : StringOutputStream(edu.stanford.nlp.io.StringOutputStream)

Example 2 with StringOutputStream

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();
}
Also used : StringOutputStream(edu.stanford.nlp.io.StringOutputStream)

Example 3 with StringOutputStream

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;
}
Also used : StringOutputStream(edu.stanford.nlp.io.StringOutputStream) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) DecimalFormat(java.text.DecimalFormat) PrintWriter(java.io.PrintWriter)

Example 4 with StringOutputStream

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();
}
Also used : StringOutputStream(edu.stanford.nlp.io.StringOutputStream) PrintWriter(java.io.PrintWriter)

Example 5 with StringOutputStream

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;
}
Also used : StringOutputStream(edu.stanford.nlp.io.StringOutputStream) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) DecimalFormat(java.text.DecimalFormat) PrintWriter(java.io.PrintWriter)

Aggregations

StringOutputStream (edu.stanford.nlp.io.StringOutputStream)6 PrintWriter (java.io.PrintWriter)3 DecimalFormat (java.text.DecimalFormat)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2