Exemplo n.º 1
0
def test_relation_tags():
    # set 3 labels for 2 spans (HU is tagged twice with different tags)
    sentence = Sentence(
        "Humboldt Universität zu Berlin is located in Berlin .")

    # create two relation label
    Relation(sentence[0:4], sentence[7:8]).add_label("rel", "located in")
    Relation(sentence[0:2], sentence[3:4]).add_label("rel", "university of")
    Relation(sentence[0:2], sentence[3:4]).add_label("syntactic", "apposition")

    # there should be two relation labels
    labels: List[Label] = sentence.get_labels("rel")
    assert 2 == len(labels)
    assert "located in" == labels[0].value
    assert "university of" == labels[1].value

    # there should be one syntactic labels
    labels: List[Label] = sentence.get_labels("syntactic")
    assert 1 == len(labels)

    # there should be two relations, one with two and one with one label
    relations: List[Relation] = sentence.get_relations("rel")
    assert 2 == len(relations)
    assert 1 == len(relations[0].labels)
    assert 2 == len(relations[1].labels)