Esempio n. 1
0
def test_graph():
    all_tags = [
        ["B-V", "B-ARGM-TMP", "I-ARGM-TMP", "O", "O", "O"],
        ["O", "O", "B-V", "B-ARG1", "O", "O"],
        ["O", "O", "O", "B-ARG1", "B-V", "O"],
    ]
    sent = create_spacy_sent(6)
    s = subsentence.create_subsentences(all_tags, sent)
    c = list(subsentence.create_combinations_from_subsentences(s))
    assert len(s) == 3
    assert len(c) == 1

    g = c[0].to_graph()
    verify_graph(g, s, all_tags)

    adj = g[s[0]]
    assert len(adj) == 1
    assert not adj[s[2]]["label"]

    adj = g[s[1]]
    assert len(adj) == 1
    assert cmp_tokens_to_indices(adj[s[0]]["label"], 1)

    adj = g[s[2]]
    assert len(adj) == 1
    assert cmp_tokens_to_words(adj["End-0"]["label"], ".")
Esempio n. 2
0
def test_multiple_combinations():
    all_tags = [
        ["B-V", "O", "O", "O", "O"],
        ["O", "B-V", "B-ARG1", "I-ARG1", "I-ARG1"],
        ["O", "O", "B-V", "B-ARG1", "O"],
        ["O", "B-V", "O", "O", "O"],
        ["O", "B-ARG1", "I-ARG1", "I-ARG1", "B-V"],
        ["O", "O", "O", "O", "B-V"],
    ]
    sent = create_spacy_sent(5)
    s = subsentence.create_subsentences(all_tags, sent)
    c = list(subsentence.create_combinations_from_subsentences(s))
    c_tags = [[sub.tags for sub in comb] for comb in c]

    assert len(c) == 3
    assert len(c[0]) == 4
    assert all_tags[0] in c_tags[0]
    assert all_tags[2] in c_tags[0]
    assert all_tags[3] in c_tags[0]
    assert all_tags[5] in c_tags[0]
    assert len(c[1]) == 2
    assert all_tags[0] in c_tags[1]
    assert all_tags[1] in c_tags[1]
    assert len(c[1]) == 2
    assert all_tags[0] in c_tags[2]
    assert all_tags[4] in c_tags[2]
Esempio n. 3
0
def test_single_combination():
    all_tags = [
        ["B-V", "O", "O", "O", "B-ARGM-TMP", "I-ARGM-TMP"],
        ["O", "O", "B-V", "B-ARG1", "B-ARGM-TMP", "I-ARGM-TMP"],
        ["O", "O", "O", "O", "O", "B-V"],
    ]
    sent = create_spacy_sent(6)
    s = subsentence.create_subsentences(all_tags, sent)
    c = list(subsentence.create_combinations_from_subsentences(s))

    assert len(c) == 1
    assert len(c[0]) == 3
    assert all(tags in [sub.tags for sub in c[0]] for tags in all_tags)
Esempio n. 4
0
def test_graph_multiple_argms_negation():
    all_tags = [
        [
            "B-V",
            "O",
            "O",
            "B-ARG1",
            "I-ARG1",
            "B-ARGM-TMP",
            "I-ARGM-TMP",
            "I-ARGM-TMP",
            "I-ARGM-TMP",
            "O",
        ],
        [
            "O",
            "O",
            "B-V",
            "B-ARG1",
            "I-ARG1",
            "B-ARGM-TMP",
            "I-ARGM-TMP",
            "I-ARGM-TMP",
            "I-ARGM-TMP",
            "O",
        ],
        ["O", "O", "O", "O", "O", "O", "B-ARGM-NEG", "B-V", "B-ARG1", "O"],
    ]
    sent = create_spacy_sent(
        10, "Open and extend your arm while not saying hello.")
    s = subsentence.create_subsentences(all_tags, sent)
    c = list(subsentence.create_combinations_from_subsentences(s))
    assert len(s) == 3
    assert len(c) == 1

    g = c[0].to_graph()
    verify_graph(g, s, all_tags)

    adj = g[s[0]]
    assert len(adj) == 1
    assert cmp_tokens_to_words(adj[s[1]]["label"], "and")

    adj = g[s[2]]
    assert len(adj) == 2
    assert cmp_tokens_to_words(adj[s[0]]["label"], "while", "not")
    assert cmp_tokens_to_words(adj[s[1]]["label"], "while", "not")

    adj = g[s[1]]
    assert len(adj) == 1
    assert cmp_tokens_to_words(adj["End-0"]["label"], ".")
Esempio n. 5
0
def test_graph_common_argms():
    all_tags = [
        [
            "B-V",
            "O",
            "O",
            "B-ARG1",
            "I-ARG1",
            "I-ARG1",
            "B-ARGM-TMP",
            "I-ARGM-TMP",
            "O",
        ],
        [
            "O",
            "O",
            "B-V",
            "B-ARG1",
            "I-ARG1",
            "I-ARG1",
            "B-ARGM-TMP",
            "I-ARGM-TMP",
            "O",
        ],
        ["O", "O", "O", "O", "O", "O", "O", "B-V", "O"],
    ]
    sent = create_spacy_sent(9, "Wave and extend your left arm while running.")
    s = subsentence.create_subsentences(all_tags, sent)
    c = list(subsentence.create_combinations_from_subsentences(s))
    assert len(s) == 3
    assert len(c) == 1

    g = c[0].to_graph()
    verify_graph(g, s, all_tags)

    adj = g[s[0]]
    assert len(adj) == 1
    assert cmp_tokens_to_words(adj[s[1]]["label"], "and")

    adj = g[s[2]]
    assert len(adj) == 2
    assert cmp_tokens_to_words(adj[s[0]]["label"], "while")
    assert cmp_tokens_to_words(adj[s[1]]["label"], "while")

    adj = g[s[1]]
    assert len(adj) == 1
    assert cmp_tokens_to_words(adj["End-0"]["label"], ".")
Esempio n. 6
0
def test_two_combinations():
    all_tags = [
        ["B-V", "O", "O", "B-ARG1", "I-ARG1", "I-ARG1"],
        ["B-V", "O", "O", "B-ARG1", "I-ARG1", "O"],
        ["O", "O", "B-V", "B-ARG1", "I-ARG1", "I-ARG1"],
        ["O", "B-V", "O", "O", "O", "O"],
    ]
    sent = create_spacy_sent(6)
    s = subsentence.create_subsentences(all_tags, sent)
    c = list(subsentence.create_combinations_from_subsentences(s))

    assert len(c) == 2
    tags1 = [sub.tags for sub in c[0]]
    tags2 = [sub.tags for sub in c[1]]

    assert (all_tags[0] in tags1) ^ (all_tags[0] in tags2)
    assert (all_tags[1] in tags1) ^ (all_tags[1] in tags2)
    assert all_tags[2] in tags1
    assert all_tags[2] in tags2
    assert all_tags[3] in tags1
    assert all_tags[3] in tags2