/// <exception cref="System.IO.IOException"/> public static string JsonPrint(Annotation annotation) { StringOutputStream os = new StringOutputStream(); new JSONOutputter().Print(annotation, os); return(os.ToString()); }
/// <exception cref="System.IO.IOException"/> public static string GetEvalSummary(string evalScript, string goldFile, string predictFile) { 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.Parse(number))); } return(summary); }
public static string NodeToString(INode node, bool prettyPrint) { StringOutputStream s = new StringOutputStream(); PrintNode(s, node, prettyPrint, false); return(s.ToString()); }
// todo: revert: According to the docs, neither TransformerFactory nor DocumentBuilderFactory is guaranteed threadsafe. // todo: A good application might make one of these per thread, but maybe easier just to revert to creating one each time, sigh. // static class public static string DocumentToString(IDocument document) { StringOutputStream s = new StringOutputStream(); PrintNode(s, document, true, true); return(s.ToString()); }
/// <summary> /// Convert list of scored parse trees to string representing scored parses /// (in the charniak parser output format). /// </summary> /// <param name="parses">- list of scored parse trees</param> /// <returns>string representing scored parses</returns> public static string ParsesToString(IList <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()); }