File size: 2,639 Bytes
83dae89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
667319c
 
 
 
 
 
 
 
 
 
 
83dae89
 
 
 
 
 
 
 
 
 
1e6d8b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from scripts.syntax_normalization import (
    canonical_stoicheia_deprel,
    is_universal_deprel,
    punctuationless_lemma,
    punctuationless_tokens,
    syntax_text_normalize,
)


def test_parser_input_removes_attached_punctuation_and_splits_hidden_words():
    assert punctuationless_tokens("Ἀστάσπης,") == ["Ἀστάσπης"]
    assert punctuationless_tokens("Φαρανδάκης θʼ,") == ["Φαρανδάκης", "θ"]
    assert punctuationless_tokens("ͅ") == []


def test_editorial_symbols_are_stripped_like_punctuation():
    assert punctuationless_tokens("<ἄλαστ>") == ["ἄλαστ"]
    assert punctuationless_tokens("<ἔστ") == ["ἔστ"]
    assert punctuationless_lemma("δι~ος") == "διος"
    assert punctuationless_lemma("῎ἴλιος") == "ἴλιος"
    assert punctuationless_lemma("??") == "_"
    assert punctuationless_lemma("λέγω3") == "λέγω"
    assert punctuationless_tokens("ἔλλαχες1") == ["ἔλλαχες"]
    assert punctuationless_tokens("20") == []


def test_punctuated_lemmas_are_cleaned_without_removing_diacritics():
    assert punctuationless_lemma("Σοσθάνης.") == "Σοσθάνης"
    assert syntax_text_normalize("θʼ,") == syntax_text_normalize("θ")


def test_auxp_and_unknown_legacy_relations_cannot_survive_ud_normalization():
    assert canonical_stoicheia_deprel("AuxP", "ADP", 2) == "case"
    assert canonical_stoicheia_deprel("nsubj", "NOUN", 2) == "nsubj"
    assert canonical_stoicheia_deprel("made_up", "NOUN", 2) == "dep"
    assert all(is_universal_deprel(value) for value in ("case", "nsubj", "dep"))


def test_coordinators_attach_to_the_following_conjunct_whatever_the_project_did() -> None:
    from scripts.syntax_normalization import normalize_cc_heads

    # A καὶ B καὶ C, with UD Perseus' convention: both καί on the first conjunct.
    ids = [1, 2, 3, 4, 5]
    deprels = ["nsubj", "cc", "conj", "cc", "conj"]
    assert normalize_cc_heads(ids, [0, 1, 1, 1, 1], deprels) == [0, 3, 1, 5, 1]
    # PROIEL's convention is already the guideline and is left alone.
    assert normalize_cc_heads(ids, [0, 3, 1, 5, 1], deprels) == [0, 3, 1, 5, 1]
    # A conjunction with no following conjunct stays on the last member, and a
    # sentence-opening καί with no coordination at all stays where it was.
    assert normalize_cc_heads([1, 2, 3], [0, 1, 1], ["root", "conj", "cc"]) == [0, 1, 2]
    assert normalize_cc_heads([1, 2], [2, 0], ["cc", "root"]) == [2, 0]
    # A subtype is still a coordinator.
    assert normalize_cc_heads([1, 2, 3], [0, 1, 1], ["root", "cc:preconj", "conj"]) == [0, 3, 1]