コード例 #1
0
def show_one_doc_annotations(doc_name, doc_text, annotations, annotator_a,
                             annotator_b):
    from pyConTextNLP.display.html import __insert_color
    html = []
    color = 'blue'
    window_size = 50
    html.append("<tr>")
    html.append("<td style=\"text-align:left\">{0}</td>".format(doc_name))
    html.append(
        "<td><a href=\"https://brat.jupyter.med.utah.edu/diff.xhtml?diff=%2Fstudent_folders%2F"
        + annotator_a + "%2F#/student_folders/" + annotator_b + "/" +
        doc_name + "\" target=\"_blank\">document view</a></td>")
    html.append("</tr>")
    for anno in annotations:
        #           make sure the our snippet will be cut inside the text boundary
        begin = anno.start_index - window_size
        end = anno.end_index + window_size
        begin = begin if begin > 0 else 0
        end = end if end < len(doc_text) else len(doc_text)
        #           render a highlighted snippet
        cell = __insert_color(doc_text[begin:end],
                              [anno.start_index - begin, anno.end_index - end],
                              color)
        #           add the snippet into table
        html.append("<tr>")
        html.append("<td></td>")
        html.append("<td style=\"text-align:left\">{0}</td>".format(cell))
        html.append("</tr>")
    return html
コード例 #2
0
def snippet_markup(doc_name,
                   anno_doc,
                   display_types={'SPAN_POSITIVE_PNEUMONIA_EVIDENCE'}):
    from pyConTextNLP.display.html import __sort_by_span
    from pyConTextNLP.display.html import __insert_color
    html = []
    color = 'blue'
    window_size = 50
    html.append("<tr>")
    html.append("<td style=\"text-align:left\">{0}</td>".format(doc_name))
    html.append("<td></td>")
    html.append("</tr>")
    for anno in anno_doc.annotations:
        if anno.type in display_types:
            #           make sure the our snippet will be cut inside the text boundary
            begin = anno.start_index - window_size
            end = anno.end_index + window_size
            begin = begin if begin > 0 else 0
            end = end if end < len(anno_doc.text) else len(anno_doc.text)
            #           render a highlighted snippet
            cell = __insert_color(
                anno_doc.text[begin:end],
                [anno.start_index - begin, anno.end_index - end], color)
            #           add the snippet into table
            html.append("<tr>")
            html.append("<td></td>")
            html.append("<td style=\"text-align:left\">{0}</td>".format(cell))
            html.append("</tr>")
    return html
コード例 #3
0
def mark_text(txt, nodes, colors={"name": "red", "pet": "blue"}, default_color="black"):
    # this function had to be copied and modified from pyConTextNLP.display.html.mark_text
    # so that the default_color could be passed through
    if not nodes:
        return txt
    else:
        n = nodes.pop(-1)
        from pyConTextNLP.display.html import __insert_color
        return mark_text(__insert_color(txt,
                                        n.getSpan(),
                                        colors.get(n.getCategory()[0], default_color)),
                         nodes,
                         colors=colors,
                         # this was not being passed through
                         default_color=default_color)