private static void OutputHighlighting(PrintWriter @out, CRFClassifier <ICoreMap> classifier, string input) { ICollection <string> labels = classifier.Labels(); string background = classifier.BackgroundSymbol(); IList <IList <ICoreMap> > sentences = classifier.Classify(input); IDictionary <string, Color> tagToColorMap = NERGUI.MakeTagToColorMap(labels, background); StringBuilder result = new StringBuilder(); int lastEndOffset = 0; foreach (IList <ICoreMap> sentence in sentences) { foreach (ICoreMap word in sentence) { int beginOffset = word.Get(typeof(CoreAnnotations.CharacterOffsetBeginAnnotation)); int endOffset = word.Get(typeof(CoreAnnotations.CharacterOffsetEndAnnotation)); string answer = word.Get(typeof(CoreAnnotations.AnswerAnnotation)); if (beginOffset > lastEndOffset) { result.Append(StringEscapeUtils.EscapeHtml4(Sharpen.Runtime.Substring(input, lastEndOffset, beginOffset))); } // Add a color bar for any tagged words if (!background.Equals(answer)) { Color color = tagToColorMap[answer]; result.Append("<span style=\"color:#ffffff;background:" + NERGUI.ColorToHTML(color) + "\">"); } result.Append(StringEscapeUtils.EscapeHtml4(Sharpen.Runtime.Substring(input, beginOffset, endOffset))); // Turn off the color bar if (!background.Equals(answer)) { result.Append("</span>"); } lastEndOffset = endOffset; } } if (lastEndOffset < input.Length) { result.Append(StringEscapeUtils.EscapeHtml4(Sharpen.Runtime.Substring(input, lastEndOffset))); } result.Append("<br><br>"); result.Append("Potential tags:"); foreach (KeyValuePair <string, Color> stringColorEntry in tagToColorMap) { result.Append("<br> "); Color color = stringColorEntry.Value; result.Append("<span style=\"color:#ffffff;background:" + NERGUI.ColorToHTML(color) + "\">"); result.Append(StringEscapeUtils.EscapeHtml4(stringColorEntry.Key)); result.Append("</span>"); } @out.Print(result); }