예제 #1
0
def test_html_rendering():
    text = ("Boris Johnson has been elected new Conservative leader in "
            "a ballot of party members and will become the "
            "next UK prime minister. &")
    sentence = Sentence(text)

    print(sentence[0:2].add_label("ner", "PER"))
    print(sentence[6:7].add_label("ner", "MISC"))
    print(sentence[19:20].add_label("ner", "LOC"))
    colors = {
        "PER": "#F7FF53",
        "ORG": "#E8902E",
        "LOC": "yellow",
        "MISC": "#4647EB",
        "O": "#ddd",
    }
    actual = render_ner_html([sentence], colors=colors)

    expected_res = HTML_PAGE.format(
        text=PARAGRAPH.format(
            sentence=TAGGED_ENTITY.format(
                color="#F7FF53", entity="Boris Johnson", label="PER") +
            " has been elected new " + TAGGED_ENTITY.format(
                color="#4647EB", entity="Conservative", label="MISC") +
            " leader in a ballot of party members and will become the next " +
            TAGGED_ENTITY.format(color="yellow", entity="UK", label="LOC") +
            " prime minister. &"),
        title="Flair",
    )

    assert expected_res == actual
예제 #2
0
def test_html_rendering():
    text = (
        "Boris Johnson has been elected new Conservative leader in a ballot of party members and will become the "
        "next UK prime minister. &")
    sent = Sentence()
    sent.get_spans = MagicMock()
    sent.get_spans.return_value = [
        mock_ner_span(text, "PER", 0, 13),
        mock_ner_span(text, "MISC", 35, 47),
        mock_ner_span(text, "LOC", 109, 111),
    ]
    sent.to_original_text = MagicMock()
    sent.to_original_text.return_value = text
    colors = {
        "PER": "#F7FF53",
        "ORG": "#E8902E",
        "LOC": "yellow",
        "MISC": "#4647EB",
        "O": "#ddd",
    }
    actual = render_ner_html([sent], colors=colors)

    expected_res = HTML_PAGE.format(
        text=PARAGRAPH.format(
            sentence=TAGGED_ENTITY.format(
                color="#F7FF53", entity="Boris Johnson", label="PER") +
            " has been elected new " + TAGGED_ENTITY.format(
                color="#4647EB", entity="Conservative", label="MISC") +
            " leader in a ballot of party members and will become the next " +
            TAGGED_ENTITY.format(color="yellow", entity="UK", label="LOC") +
            " prime minister. &"),
        title="Flair",
    )

    assert expected_res == actual