forked from cldf-datasets/audersetinterrog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcldfbench_audersetinterrog.py
134 lines (117 loc) · 4.87 KB
/
cldfbench_audersetinterrog.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
import collections
import pathlib
from cldfbench import CLDFSpec
from cldfbench import Dataset as BaseDataset
from clldutils.misc import slug
class Dataset(BaseDataset):
dir = pathlib.Path(__file__).parent
id = "audersetinterrog"
def cldf_specs(self):
return CLDFSpec(dir=self.cldf_dir, module="StructureDataset")
def cmd_makecldf(self, args):
# read raw data
parameters = list(self.etc_dir.read_csv("parameters.csv", dicts=True))
codes_by_id = collections.OrderedDict(
(row['ID'], row)
for row in self.etc_dir.read_csv('codes.csv', dicts=True))
raw_data = list(self.raw_dir.read_csv(
"InterrogativeRelativeIE_Appendix1.csv", dicts=True))
# knead into a cldfifiable shape
languages_by_id = collections.OrderedDict()
for row in raw_data:
if row['Glottocode'] not in languages_by_id:
languages_by_id[row['Glottocode']] = {
'ID': row['Glottocode'],
'Glottocode': row['Glottocode'],
'Name': row['Language'],
'Family': row['Branch'],
'Subbranch': row['Subbranch'],
'Subsubbranch': row['Subsubbranch'],
'EarlyTimeBP': row['EarlyTimeBP'],
'LateTimeBP': row['LateTimeBP'],
'AvTimeBP': row['AvTimeBP'],
'Latitude': row['Latitude'],
'Longitude': row['Longitude'],
}
constructions = [
{
'ID': row['ID'],
'Name': '{} relative pronoun {}'.format(
languages_by_id[row['Glottocode']]['Name'],
row['RMform']),
'Language_ID': row['Glottocode'],
}
for row in raw_data]
cvalues = []
for row in raw_data:
for parameter in parameters:
if parameter['ID'] == 'rmform':
code_id = None
comment = row['Notes']
else:
code_id = '{}-{}'.format(
parameter['ID'], slug(row[parameter['Name']]))
comment = None
cvalue = {
'ID': '{}-{}'.format(row['ID'], parameter['ID']),
'Construction_ID': row['ID'],
'Parameter_ID': parameter['ID'],
'Value': row[parameter['Name']],
'Code_ID': code_id,
'Comment': comment,
}
cvalues.append(cvalue)
parameters.append({
'ID': 'rmforms',
'Name': 'RMForms',
'Description': 'collection of relative markers used in a language',
})
forms_by_language = collections.OrderedDict()
for row in raw_data:
glottocode = row['Glottocode']
if glottocode not in forms_by_language:
forms_by_language[glottocode] = []
forms_by_language[glottocode].append(row['RMform'])
values = [
{
'ID': 'rmforms-{}'.format(lang_id),
'Language_ID': lang_id,
'Parameter_ID': 'rmforms',
'Value': ' / '.join(forms),
}
for lang_id, forms in forms_by_language.items()]
# cldf output
args.writer.cldf.add_component(
"LanguageTable",
"Family",
"Subbranch",
"Subsubbranch",
"EarlyTimeBP",
"LateTimeBP",
"AvTimeBP",
)
args.writer.cldf.add_component("ParameterTable")
args.writer.cldf.add_component("CodeTable")
args.writer.cldf.add_table(
'constructions.csv',
'http://cldf.clld.org/v1.0/terms.rdf#id',
'http://cldf.clld.org/v1.0/terms.rdf#languageReference',
'http://cldf.clld.org/v1.0/terms.rdf#name',
'http://cldf.clld.org/v1.0/terms.rdf#description')
args.writer.cldf.add_table(
'cvalues.csv',
'http://cldf.clld.org/v1.0/terms.rdf#id',
'Construction_ID',
'http://cldf.clld.org/v1.0/terms.rdf#parameterReference',
'http://cldf.clld.org/v1.0/terms.rdf#codeReference',
'http://cldf.clld.org/v1.0/terms.rdf#value',
'http://cldf.clld.org/v1.0/terms.rdf#comment')
args.writer.cldf.add_foreign_key(
'cvalues.csv', 'Construction_ID',
'constructions.csv', 'ID')
args.writer.objects['LanguageTable'] = languages_by_id.values()
args.writer.objects['constructions.csv'] = constructions
args.writer.objects['ParameterTable'] = parameters
args.writer.objects['CodeTable'] = codes_by_id.values()
args.writer.objects['cvalues.csv'] = cvalues
args.writer.objects['values.csv'] = values