File size: 8,700 Bytes
26786e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env python3
"""Extract Rhaetic (xrr) and Messapic (cms) lexicons from Wiktionary/scholarly sources.

Words are hardcoded from WebFetch of:
  - Thesaurus Inscriptionum Raeticarum (tir.univie.ac.at)
  - mnamon.sns.it (Scuola Normale Superiore, Pisa)
  - Grokipedia / Wikipedia mirrors
  - Paleoglot blog (paleoglot.blogspot.com)
  - en-academic.com (Messapian language article)

Transliteration→IPA via the existing maps in transliteration_maps.py.
SCA encoding via cognate_pipeline's ipa_to_sound_class().
"""

from __future__ import annotations

import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT / "cognate_pipeline" / "src"))
sys.path.insert(0, str(ROOT / "scripts"))

from cognate_pipeline.normalise.sound_class import ipa_to_sound_class
from transliteration_maps import transliterate


# ============================================================================
# RHAETIC (xrr) — Words from TIR, mnamon.sns.it, Grokipedia, Paleoglot
#
# Sources:
#   - Thesaurus Inscriptionum Raeticarum (tir.univie.ac.at/wiki/The_Raetic_language)
#   - mnamon.sns.it/index.php?page=Scrittura&id=63&lang=en
#   - grokipedia.com/page/Rhaetic
#   - paleoglot.blogspot.com (Schum PU 1, Schum CE 1, upiku texts)
#
# Format: (transliterated_form, gloss_or_note)
# ============================================================================
RHAETIC_WORDS = [
    # --- Verbs and verbal forms ---
    # Scholarly transliteration uses: ph=pʰ, th=tʰ, kh=kʰ, ś=ʃ, z=ts, v=w
    # Sources use þ for /th/, φ for /ph/, χ for /kh/ — normalized to digraphs here
    ("tinake", "made/donated (preterite)"),
    ("tinakhe", "made/donated (preterite, aspirated variant)"),
    ("eluku", "sacrificed (participle)"),
    ("upiku", "offered (participle/verbal noun)"),
    ("utiku", "given/donated (participle)"),
    ("trinakhe", "it was poured (passive preterite)"),
    ("tauke", "perfective preterite verb"),
    # --- Nouns ---
    ("akhvil", "present/gift"),
    ("sphura", "community"),
    ("vaku", "votive offering"),
    ("hepru", "artifact/plaque"),
    ("hil", "property/land"),
    # --- Numerals ---
    ("thal", "two"),
    # --- Adverbs/particles ---
    ("ikh", "thus"),
    ("khan", "this"),
    ("ihi", "here/there (locative particle)"),
    # --- Nouns/obscure ---
    ("taniun", "obscure recurring term"),
    ("terisna", "obscure, -na suffix"),
    ("phuter", "noun (plural form)"),
    ("vinutalina", "wine-bearing"),
    ("phelna", "name element or noun"),
    # --- Personal names attested in inscriptions ---
    ("reithe", "personal name"),
    ("muiu", "personal name"),
    ("kastrie", "personal name"),
    ("ethunnu", "personal name"),
    ("tvalos", "personal name"),
    ("pithamne", "personal name"),
    ("helanu", "personal name"),
    ("lasta", "personal name"),
    ("pithamnu", "personal name (variant)"),
    ("tvalur", "personal name (variant)"),
    ("khaisurus", "personal name"),
    ("enikes", "personal name"),
    ("laviseseli", "patronymic (of the son of Lavis)"),
    ("velkhanu", "deity name"),
    ("lupinu", "dead/crossed over"),
    ("pitiave", "locative form"),
    ("kusenkus", "uncertain (artifact descriptor)"),
    ("avaśuerasi", "for the departed ones"),
    ("avaśura", "the departed (nom. pl.)"),
    ("kleimunteis", "to that in this plot"),
    ("phelturies", "relating to Velturie"),
    ("klanturus", "uncertain meaning"),
    # --- Morphological elements used as standalone clitics ---
    ("ka", "and (enclitic)"),
    # --- Adjective/inhabitant ---
    ("śaili", "inhabitant"),
]


# ============================================================================
# MESSAPIC (cms) — Words from mnamon.sns.it, en-academic.com, Eupedia,
#                   Verbix, Paleoglot, Grokipedia
#
# Sources:
#   - mnamon.sns.it/index.php?page=Lingua&id=29&lang=en
#   - en-academic.com/dic.nsf/enwiki/324322
#   - eupedia.com/forum/threads/messapian-albanian-connection.35943
#   - docs.verbix.com/Languages/Messapic
#
# Format: (transliterated_form, gloss_or_note)
# ============================================================================
MESSAPIC_WORDS = [
    # --- Nouns ---
    # Scholarly transliteration: θ=θ, ph=pʰ, th=tʰ, kh=kʰ, h=h
    # Sources use θ (theta) directly — preserved here
    ("bilia", "daughter"),
    ("bennan", "a sort of vehicle"),
    ("tabara", "priestess"),
    ("argorapandes", "treasurer/coin magistrate"),
    ("teuta", "community/people"),
    ("kalator", "herald"),
    ("aran", "arable land"),
    ("brendon", "deer"),
    ("brention", "place name (Brindisi)"),
    ("menzana", "colt"),
    ("dasta", "personal name"),
    ("morθana", "personal name"),
    # --- Verbs ---
    ("apistaθi", "he offers (present indicative 3sg)"),
    ("hipades", "he dedicated (aorist indicative 3sg)"),
    ("hadive", "he put/stood (perfect indicative 3sg)"),
    ("klaohi", "hear (present imperative 3sg)"),
    ("beran", "let them bring (present conjunctive 3pl)"),
    ("berain", "they must bring (present optative 3pl)"),
    ("tepise", "placed/offered (aorist indicative 3sg)"),
    ("epigravan", "they have offered"),
    ("rodita", "verb form (from Aphrodite inscription)"),
    # --- Numerals ---
    ("penkaheh", "five"),
    # --- Articles ---
    ("toi", "dative masculine article"),
    ("tai", "dative feminine article"),
    ("tan", "accusative feminine singular article"),
    # --- Particles/function words ---
    ("ai", "conjunction (hypothetical)"),
    ("ma", "prohibition particle"),
    ("apa", "preposition: from"),
    ("epi", "verbal preposition"),
    ("kos", "relative pronoun: someone"),
    ("si", "enclitic conjunction: and"),
    ("θi", "enclitic conjunction: and"),
    ("ti", "enclitic conjunction: and"),
    # --- Adjectives ---
    ("mazzes", "greater"),
    ("andirahho", "adjective (possibly 'under')"),
    # --- Theonyms ---
    ("zis", "Zeus (Messapic form)"),
    ("thautori", "infernal god (related to Tartarus)"),
    ("aprodita", "Aphrodite (loanword from Greek)"),
    # --- Additional personal names from inscriptions ---
    ("artorres", "personal name"),
    ("blatθes", "personal name"),
    ("dazimas", "personal name"),
    ("dekias", "personal name"),
    ("artahias", "patronym/nomen gentile"),
    # --- Additional verbal/nominal forms ---
    ("tabaras", "genitive of tabara"),
    ("logetibas", "theonym (dative plural)"),
]


def build_tsv_rows(
    words: list[tuple[str, str]],
    iso: str,
) -> list[str]:
    """Convert word list to TSV rows: Word, IPA, SCA, Source, Concept_ID, Cognate_Set_ID."""
    rows = []
    errors = []
    for translit, gloss in words:
        try:
            ipa = transliterate(translit, iso)
            sca = ipa_to_sound_class(ipa)
            if not sca:
                errors.append(f"  WARN: empty SCA for {translit!r} -> IPA={ipa!r}")
                sca = "?"
            rows.append(f"{translit}\t{ipa}\t{sca}\twiktionary\t{gloss}\t-")
        except Exception as exc:
            errors.append(f"  ERROR: {translit!r}: {exc}")
    return rows, errors


def main():
    outdir = ROOT / "data" / "training" / "lexicons"
    outdir.mkdir(parents=True, exist_ok=True)

    header = "Word\tIPA\tSCA\tSource\tConcept_ID\tCognate_Set_ID"
    total_errors = []

    # --- Rhaetic ---
    xrr_rows, xrr_errors = build_tsv_rows(RHAETIC_WORDS, "xrr")
    xrr_path = outdir / "xrr.tsv"
    with open(xrr_path, "w", encoding="utf-8") as f:
        f.write(header + "\n")
        for row in xrr_rows:
            f.write(row + "\n")
    print(f"Rhaetic (xrr): {len(xrr_rows)} entries -> {xrr_path}")
    if xrr_errors:
        total_errors.extend(["Rhaetic errors:"] + xrr_errors)

    # --- Messapic ---
    cms_rows, cms_errors = build_tsv_rows(MESSAPIC_WORDS, "cms")
    cms_path = outdir / "cms.tsv"
    with open(cms_path, "w", encoding="utf-8") as f:
        f.write(header + "\n")
        for row in cms_rows:
            f.write(row + "\n")
    print(f"Messapic (cms): {len(cms_rows)} entries -> {cms_path}")
    if cms_errors:
        total_errors.extend(["Messapic errors:"] + cms_errors)

    # --- Summary ---
    print()
    if total_errors:
        print("ERRORS/WARNINGS:")
        for e in total_errors:
            print(e)
    else:
        print("No errors.")

    # Quick sanity: show first 5 entries of each
    import io, sys as _sys
    _sys.stdout = io.TextIOWrapper(_sys.stdout.buffer, encoding="utf-8", errors="replace")
    print("\n--- Rhaetic sample ---")
    for row in xrr_rows[:5]:
        print(row)
    print("\n--- Messapic sample ---")
    for row in cms_rows[:5]:
        print(row)


if __name__ == "__main__":
    main()