-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexibank_heathdogon.py
297 lines (268 loc) · 12.8 KB
/
lexibank_heathdogon.py
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
from pathlib import Path
from clldutils.misc import slug
from pylexibank import FormSpec, Lexeme, Concept, Language, Lexeme
from pylexibank import Dataset as BaseDataset
from pylexibank import progressbar
from lingpy import *
import attr
from unicodedata import normalize
@attr.s
class CustomConcept(Concept):
PartOfSpeech = attr.ib(default=None)
Swadesh = attr.ib(default=None)
IDS_Gloss = attr.ib(default=None)
@attr.s
class CustomLanguage(Language):
SubGroup = attr.ib(default=None)
NameInSource = attr.ib(default=None)
@attr.s
class CustomLexeme(Lexeme):
Grouped_Segments = attr.ib(
default=None,
metadata={"datatype": "string", "separator": " "}
)
Grouped_Plural_Segments = attr.ib(
default=None,
metadata={"datatype": "string", "separator": " "})
Plural_Segments = attr.ib(
default=None,
metadata={"datatype": "string", "separator": " "})
Plural_Form = attr.ib(
default=None)
Dialect = attr.ib(default=None)
def get_forms(entry, dataset):
forms = dataset.form_spec.split(
dataset.form_spec.separators,
entry)
for form in forms:
form = dataset.form_spec.clean(form)
for s, t in dataset.form_spec.replacements:
form = form.replace(s, t)
segments = dataset.tokenizer({}, form)
yield (form, segments)
def get_form(form, dataset):
return list(get_forms(form, dataset))[0]
def ungroup(sounds):
out = []
for segment in sounds:
if "." in segment:
out += segment.split(".")
else:
out += [segment]
return out
class Dataset(BaseDataset):
dir = Path(__file__).parent
id = "heathdogon"
language_class = CustomLanguage
concept_class = CustomConcept
lexeme_class = CustomLexeme
# define the way in which forms should be handled
form_spec = FormSpec(
brackets={"(": ")", "[": "]"}, # characters that function as brackets
separators=";/,&~,\\", # characters that split forms e.g. "a, b".
missing_data=("∅", "?", "-", "{I", "-:_", "xxx", "-ⁿ"), # characters that denote missing data.
strip_inside_brackets=True, # do you want data removed in brackets?
first_form_only=True, # We ignore all the plural forms
replacements=[
('\u232b', ''),
(",̀̌[X mà cɛ́nɛ̀] "[1:], ""),
("… ", ""),
("ADJ ", ""),
("\u030c ", ""),
(" \u030c", ""),
("[X cɛ́lɛ̀] ɲàwⁿá", "ɲàwⁿá"),
("[X cɛ̀lɛ̀] ", ""),
('\u0008', ''),
('\u030ct', 't'),
('#', ''),
('"', ''),
(" → ", " "),
("ⁿ ~ wⁿ (human)", ""),
("\u030ck", "k"),
("\u030cd", "d"),
("jògù dùyé ` dónì", "jògù dùyé dónì"),
(" PRON ", ""),
(' ', '_'),
], # replacements with spaces
)
def cmd_download(self, args):
url = "https://github.com/clld/dogonlanguages-data/raw/master/beta/Dogon.comp.vocab.UNICODE-2017.xls"
self.raw_dir.download(url, "Dogon.comp.vocab.UNICODE-2017.xls")
self.raw_dir.xls2csv("Dogon.comp.vocab.UNICODE-2017.xls")
def cmd_makecldf(self, args):
"""
Convert the raw data to a CLDF dataset.
"""
# select IDS concept list to check for concepts to be added
ids = {c.concepticon_gloss: c.english for c in
self.concepticon.conceptlists["Key-2016-1310"].concepts.values() if
c.concepticon_gloss}
# select only swadesh 207 terms (Comrie's list combining Swadesh 100
# and Swadesh 200)
swadesh = {c.concepticon_gloss for c in
self.concepticon.conceptlists["Comrie-1977-207"].concepts.values()}
# Write source
args.writer.add_sources()
# Write languages
args.writer.add_languages()
# check for manually separated cases
language_mapper = {
"BonduSoNajamba": "Najamba",
"JamsayGourou": "Gourou",
"TiranigeBoui": "Tiranige",
"TiranigeNingo": "Tiranige",
}
manual = {}
for i, row in enumerate(
self.raw_dir.read_csv("manually-edited.csv", dicts=True)):
if row["SINGULAR"]:
form = normalize("NFD", row["SINGULAR"]).replace("-", "")
elif row["FORM"]:
form = normalize("NFD", row["FORM"]).replace("-", "")
else:
args.log.info("No form found in line {0} (ID: {1})".format(
i, row["ID"]))
form = ""
lng = language_mapper.get(row["DOCULECT"], row["DOCULECT"])
manual[lng, row["GLOSS"], form] = row
manual[lng, row["GLOSS"],
normalize("NFD", row["VALUE_ORG"]).replace("-", "")] = row
# Write concepts
concepts = {}
for concept in self.concepts:
if concept['CONCEPTICON_GLOSS'] in ids:
idx = concept['NUMBER']+'_'+slug(concept['ENGLISH'])
if concept["CONCEPTICON_GLOSS"] in swadesh:
swad = "1"
else:
swad = "0"
args.writer.add_concept(
ID=idx,
Name=concept['ENGLISH'],
PartOfSpeech=concept['POS'],
Concepticon_ID=concept["CONCEPTICON_ID"],
Concepticon_Gloss=concept["CONCEPTICON_GLOSS"],
Swadesh=swad,
IDS_Gloss=ids[concept["CONCEPTICON_GLOSS"]]
)
concepts[concept['ENGLISH'].replace('"', '')] = idx
# Write forms
lexicon = self.raw_dir.read_csv("Dogon.comp.vocab.UNICODE-2017.lexicon.csv",
dicts=True)
missing = set()
missing_values = set()
visited = set()
double_entries = set()
missing_plurals = 0
for row in progressbar(lexicon, desc="cldfify"):
concept = row["English"].replace('"', '')
if concept not in concepts:
missing.add(concept)
else:
for language in self.languages:
lid, lname = language["ID"], language["NameInSource"]
entry = row[lname].replace('-', '').strip()
if entry and entry[0] in "([{" and entry[-1] in ")]}":
continue
elif entry in ["ⁿ ~ wⁿ (human)",
"→ (prolongation, final Htone)",
": (length, falling tone)",
"[ǹdò ŋ̀gá] ... wɔ́",
"(floating L) X",
"[kú ôm] X wǒ",
"[ú yà→] [bírɛ́ yà→], [bìrɛ̀ wó] pǒ:",
"[bɛ̀nnà: íŋ]̀ nì:",
"X yà Y yà",
"X=: (length)",
"→ (vowel prolongation, rising pitch)",
" ̀(final Ltone)",
"[X lè] Y tégé",
"(jɛ̀mbɛ)̀ bálàlù",
"(nàmà)̀ kíndɛ́",
"V gɛ díɛ́",
"(sɔ̀w yàa)̀ jíbú, yàà jìbé",
'sɔ̀: [kû: sɛ̀lɛ̀] [dúlɔ̀ sɛ̀lɛ̀] ("talk without a head or a tail")',
"=∴",
"N",
"\u0060",
"\u0060(final Ltone)",
"[X jɛ́ nɛ̀] X",
"ADJ, ADJ=ẃ (Inan), ADJ=ŋ́ (AnSg), ADJ=yɛ́ (AnPl)",
"Y [X bày] kíyɛ́",
"ní: ! nì:",
"hàlí ... [X là] ... (mɛ̀)",
"[X dá:rú] Y sà",
"{L} after Lfinal pronoun or "
"undetermined noun, {HL} after others",
"mì X=:",
] or "VERB" in entry or "{L}, Astem)" in entry or \
"final Ltone" in entry or "..." in entry \
or "…" in entry or "∅" in entry or "X" in \
entry or "VERB" in entry:
continue
if entry:
if entry in self.lexemes:
entry = self.lexemes[entry]
for form, segments in get_forms(entry, self):
if "Boui" in entry:
variety = "Boui"
elif "Ningo" in entry:
variety = "Ningo"
# check for match in the manually edited file
simple_form = normalize(
"NFD", form.replace("-", "").replace("_", " "))
manual_data = manual.get((lid, concept,
simple_form))
if not manual_data:
simple_form = entry
manual_data = manual.get((lid, concept,
simple_form))
if manual_data:
if (lid, concept, simple_form) not in visited:
visited.add((lid, concept, simple_form))
plurals = ['', []]
if manual_data["SINGULAR"].strip():
new_form, new_segments = get_form(
manual_data["SINGULAR"],
self)
try:
plurals = get_form(
manual_data["PLURAL"],
self)
except:
missing_plurals += 1
elif manual_data["PARSED FORM"].strip():
new_form, new_segments = get_form(
manual_data["PARSED FORM"].strip(),
self)
elif manual_data["FORM"].strip() and manual_data["FORM"].strip() != "?":
new_form, new_segments = get_form(
manual_data["FORM"],
self)
else:
new_form, new_segments = form, segments
args.writer.add_form_with_segments(
Language_ID=lid,
Parameter_ID=concepts[concept.replace('"', '')],
Value=entry,
Form=new_form,
Segments=ungroup(new_segments),
Grouped_Segments=new_segments,
Plural_Form=plurals[0],
Plural_Segments=ungroup(plurals[1]),
Grouped_Plural_Segments=plurals[1],
Source="heathdogon"
)
else:
double_entries.add((lid, concept, simple_form))
else:
if simple_form != "XXX":
missing_values.add((lid, concept, simple_form))
args.log.info("ignoring deliberately {0} rows".format(len(missing)))
for a, b, c in missing_values:
args.log.info("missing values: {0} / {1} / {2}".format(a, b, c))
args.log.info("there are {0} missing values".format(len(missing_values)))
for a, b, c in double_entries:
args.log.info("there are duplicated entries {0} / {1} / {2}".format(a, b, c))
args.log.info("there are {0} duplicated entries".format(len(double_entries)))
args.log.info("there are {0} missing plurals".format(missing_plurals))