def pneumonia_annotation_html_markup(anno_doc): from pyConTextNLP.display.html import __sort_by_span # this bit mimics 'mark_document_with_html' from pyConTextNLP.display.html colors = {} colors['DOCUMENT_PNEUMONIA_YES'] = 'red' colors['DOCUMENT_PNEUMONIA_NO'] = 'green' colors['SPAN_POSITIVE_PNEUMONIA_EVIDENCE'] = 'red' default_color = 'red' html = """<p> {0} </p>""".format(" ".join([mark_text_custom(anno_doc.text, __sort_by_span(anno_doc.annotations), colors=colors, default_color=default_color)])) return html
def mark_document_with_html(doc, colors={"name": "red", "pet": "blue"}, default_color="black"): """takes a ConTextDocument object and returns an HTML paragraph with marked phrases in the object highlighted with the colors coded in colors doc: ConTextDocument colors: dictionary keyed by ConText category with values valid HTML colors """ from pyConTextNLP.display.html import __sort_by_span from pyConTextNLP.utils import get_document_markups return """<p> {0} </p>""".format(" ".join([mark_text_custom(m.graph['__txt'], __sort_by_span(m.nodes()), colors=colors, default_color=default_color) for m in get_document_markups(doc)]))