@fpw/en-wiktionary-la-modules 0.2.2 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +75 -75
- package/README.md +19 -15
- package/dist/LaEngine.d.ts +23 -23
- package/dist/LaEngine.js +64 -66
- package/dist/index.d.ts +12 -11
- package/dist/index.js +12 -28
- package/dist/modules/common.d.ts +67 -66
- package/dist/modules/common.js +145 -157
- package/dist/modules/conjugation/LaVerb.d.ts +118 -109
- package/dist/modules/conjugation/LaVerb.js +2861 -2295
- package/dist/modules/conjugation/VerbAffix.d.ts +18 -18
- package/dist/modules/conjugation/VerbAffix.js +19 -23
- package/dist/modules/conjugation/VerbForm.d.ts +204 -182
- package/dist/modules/conjugation/VerbForm.js +215 -199
- package/dist/modules/conjugation/VerbType.d.ts +54 -40
- package/dist/modules/conjugation/VerbType.js +66 -58
- package/dist/modules/declination/LaAdjData.d.ts +16 -16
- package/dist/modules/declination/LaAdjData.js +1474 -908
- package/dist/modules/declination/LaNominal.d.ts +136 -130
- package/dist/modules/declination/LaNominal.js +1884 -1804
- package/dist/modules/declination/LaNounData.d.ts +16 -2
- package/dist/modules/declination/LaNounData.js +935 -855
- package/dist/modules/declination/LaPersonalPronoun.d.ts +12 -12
- package/dist/modules/declination/LaPersonalPronoun.js +80 -85
- package/dist/modules/declination/NominalForm.d.ts +85 -69
- package/dist/modules/declination/NominalForm.js +101 -91
- package/dist/modules/declination/NominalType.d.ts +191 -120
- package/dist/modules/declination/NominalType.js +211 -146
- package/dist/modules/headword/HeadWord.d.ts +107 -107
- package/dist/modules/headword/HeadWord.js +28 -32
- package/dist/modules/headword/HeadwordParser.d.ts +29 -29
- package/dist/modules/headword/HeadwordParser.js +456 -452
- package/package.json +23 -15
- package/dist/LaEngine.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/modules/common.js.map +0 -1
- package/dist/modules/conjugation/LaVerb.js.map +0 -1
- package/dist/modules/conjugation/VerbAffix.js.map +0 -1
- package/dist/modules/conjugation/VerbForm.js.map +0 -1
- package/dist/modules/conjugation/VerbType.js.map +0 -1
- package/dist/modules/declination/LaAdjData.js.map +0 -1
- package/dist/modules/declination/LaNominal.js.map +0 -1
- package/dist/modules/declination/LaNounData.js.map +0 -1
- package/dist/modules/declination/LaPersonalPronoun.js.map +0 -1
- package/dist/modules/declination/NominalForm.js.map +0 -1
- package/dist/modules/declination/NominalType.js.map +0 -1
- package/dist/modules/headword/HeadWord.js.map +0 -1
- package/dist/modules/headword/HeadwordParser.js.map +0 -1
- package/src/LaEngine.ts +0 -86
- package/src/index.ts +0 -16
- package/src/modules/common.ts +0 -164
- package/src/modules/conjugation/LaVerb.ts +0 -2669
- package/src/modules/conjugation/VerbAffix.ts +0 -18
- package/src/modules/conjugation/VerbForm.ts +0 -223
- package/src/modules/conjugation/VerbType.ts +0 -55
- package/src/modules/declination/LaAdjData.ts +0 -1036
- package/src/modules/declination/LaNominal.ts +0 -2025
- package/src/modules/declination/LaNounData.ts +0 -897
- package/src/modules/declination/LaPersonalPronoun.ts +0 -92
- package/src/modules/declination/NominalForm.ts +0 -89
- package/src/modules/declination/NominalType.ts +0 -157
- package/src/modules/headword/HeadWord.ts +0 -132
- package/src/modules/headword/HeadwordParser.ts +0 -515
|
@@ -1,452 +1,456 @@
|
|
|
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
|
-
this.nominal = nominal;
|
|
68
|
-
this.conj = conj;
|
|
69
|
-
this.logger = logger;
|
|
70
|
-
}
|
|
71
|
-
isHeadwordTemplate(template) {
|
|
72
|
-
const args =
|
|
73
|
-
const templateName = args.get("0");
|
|
74
|
-
if (!templateName) {
|
|
75
|
-
throw Error(`Invalid template string: ${template}`);
|
|
76
|
-
}
|
|
77
|
-
return this.templateParsers.has(templateName);
|
|
78
|
-
}
|
|
79
|
-
parse(template, lemma) {
|
|
80
|
-
const args =
|
|
81
|
-
const templateName = args.get("0") || "nil";
|
|
82
|
-
const parseFunc = this.templateParsers.get(templateName);
|
|
83
|
-
if (!parseFunc) {
|
|
84
|
-
throw Error(`Not a headword template: ${template}`);
|
|
85
|
-
}
|
|
86
|
-
const data = parseFunc(args, lemma);
|
|
87
|
-
if (data.heads.length == 0) {
|
|
88
|
-
throw Error(`No heads for ${template} in ${lemma}`);
|
|
89
|
-
}
|
|
90
|
-
return data;
|
|
91
|
-
}
|
|
92
|
-
log(msg) {
|
|
93
|
-
if (this.logger) {
|
|
94
|
-
this.logger(msg);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
parseNominalHead(args, pos) {
|
|
98
|
-
const overridePos = args.get("pos") || pos;
|
|
99
|
-
const decl = this.nominal.do_generate_noun_forms(args, overridePos, true, args.get("lemma"));
|
|
100
|
-
const isNum = (pos == "numerals");
|
|
101
|
-
let lemmata = decl.overriding_lemma;
|
|
102
|
-
const lemmaNum = (decl.num == "pl" ? "pl" : "sg");
|
|
103
|
-
if (lemmata.length == 0) {
|
|
104
|
-
lemmata =
|
|
105
|
-
}
|
|
106
|
-
let genders = decl.overriding_genders || [];
|
|
107
|
-
if (genders.length == 0) {
|
|
108
|
-
if (decl.gender) {
|
|
109
|
-
genders = [decl.gender.toLowerCase()];
|
|
110
|
-
}
|
|
111
|
-
else if (!isNum) {
|
|
112
|
-
throw Error("Couldn't infer gender");
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
templateType: "headword",
|
|
117
|
-
headType: "nominal",
|
|
118
|
-
partOfSpeech: pos,
|
|
119
|
-
indeclinable: args.has("indecl"),
|
|
120
|
-
data: decl,
|
|
121
|
-
heads: lemmata,
|
|
122
|
-
genders: genders,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
parseAdjectivalHead(args, pos) {
|
|
126
|
-
const overridePos = args.get("pos") || pos;
|
|
127
|
-
const decl = this.nominal.do_generate_adj_forms(args, overridePos, true);
|
|
128
|
-
let lemmata = decl.overriding_lemma;
|
|
129
|
-
const lemmaNum = (decl.num == "pl" ? "pl" : "sg");
|
|
130
|
-
if (lemmata.length == 0) {
|
|
131
|
-
lemmata =
|
|
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
|
-
const
|
|
169
|
-
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
gerundive
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (
|
|
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
|
-
if (
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
if (
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
if (
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
heads
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
upper
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
}
|
|
381
|
-
else {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
heads
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
1
|
+
/**
|
|
2
|
+
* This is based on https://en.wiktionary.org/wiki/Module:la-headword developed by Benwing2.
|
|
3
|
+
* It was converted from Lua to TypeScript by Folke Will <folko@solhost.org>.
|
|
4
|
+
*
|
|
5
|
+
* Original source: https://en.wiktionary.org/wiki/Module:la-headword
|
|
6
|
+
*
|
|
7
|
+
* Lua idioms, function and variable names kept as in the original in order to easily
|
|
8
|
+
* backport later changes to this implementation.
|
|
9
|
+
*
|
|
10
|
+
* For that reason, it's suggested to add a type-aware wrapper around this class and leave
|
|
11
|
+
* this code unchanged instead of improving the types and use of idioms in this class.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
import { parse_template, read_list } from "../common.js";
|
|
15
|
+
import { LaVerb } from "../conjugation/LaVerb.js";
|
|
16
|
+
import { getVerbForm } from "../conjugation/VerbForm.js";
|
|
17
|
+
import { getNominalForm } from "../declination/NominalForm.js";
|
|
18
|
+
import { AdjectivalType, AdverbType, NominalPosType, VerbalType } from "./HeadWord.js";
|
|
19
|
+
export class HeadwordParser {
|
|
20
|
+
templateParsers = new Map([
|
|
21
|
+
// these are parsed by la-ndecl
|
|
22
|
+
["la-noun", args => this.parseNominalHead(args, NominalPosType.Noun)],
|
|
23
|
+
["la-num-noun", args => this.parseNominalHead(args, NominalPosType.Numeral)],
|
|
24
|
+
["la-suffix-noun", args => this.parseNominalHead(args, NominalPosType.Suffix)],
|
|
25
|
+
["la-proper noun", args => this.parseNominalHead(args, NominalPosType.ProperNoun)],
|
|
26
|
+
["la-prop", args => this.parseNominalHead(args, NominalPosType.ProperNoun)],
|
|
27
|
+
// these are parsed by la-adecl
|
|
28
|
+
["la-adj", args => this.parseAdjectivalHead(args, AdjectivalType.Adjective)],
|
|
29
|
+
["la-num-adj", args => this.parseAdjectivalHead(args, AdjectivalType.Numeral)],
|
|
30
|
+
["la-suffix-adj", args => this.parseAdjectivalHead(args, AdjectivalType.Suffix)],
|
|
31
|
+
["la-pronoun", args => this.parseAdjectivalHead(args, AdjectivalType.Pronoun)],
|
|
32
|
+
["la-det", args => this.parseAdjectivalHead(args, AdjectivalType.Determiner)],
|
|
33
|
+
["la-part", args => this.parseAdjectivalHead(args, AdjectivalType.Participle)],
|
|
34
|
+
// these are parsed by la-verb
|
|
35
|
+
["la-verb", args => this.parseVerbalHead(args, VerbalType.Verb)],
|
|
36
|
+
["la-suffix-verb", args => this.parseVerbalHead(args, VerbalType.Suffix)],
|
|
37
|
+
// these are all custom
|
|
38
|
+
["la-gerund", (args, lemma) => this.parseGerund(args)],
|
|
39
|
+
["la-adj-comp", (args, lemma) => this.parseComparativeAdj(args, lemma)],
|
|
40
|
+
["la-adj-sup", (args, lemma) => this.parseSuperlativeAdj(args, lemma)],
|
|
41
|
+
["la-adv", (args, lemma) => this.parseAdverb(args, AdverbType.Adverb)],
|
|
42
|
+
["la-adv-comp", (args, lemma) => this.parseAdverbCompSup(args, AdverbType.Comparative)],
|
|
43
|
+
["la-adv-sup", (args, lemma) => this.parseAdverbCompSup(args, AdverbType.Superlative)],
|
|
44
|
+
["la-suffix-adv", (args, lemma) => this.parseAdverb(args, AdverbType.Suffix)],
|
|
45
|
+
["la-num-adv", (args, lemma) => this.parseAdverbNumeral(args)],
|
|
46
|
+
["la-prep", (args, lemma) => this.parsePreposition(args, lemma)],
|
|
47
|
+
["la-letter", (args, lemma) => this.parseLetter(args, lemma)],
|
|
48
|
+
["la-interj", (args, lemma) => this.parseInterjection(args, lemma)],
|
|
49
|
+
["la-phrase", (args, lemma) => this.parsePhrase(args, lemma)],
|
|
50
|
+
["head", (args, lemma) => this.parseHead(args, lemma)],
|
|
51
|
+
// forms only
|
|
52
|
+
["la-adj-form", (args, lemma) => this.parseForm(args, lemma, "adjectives")],
|
|
53
|
+
["la-noun-form", (args, lemma) => this.parseForm(args, lemma, "nouns")],
|
|
54
|
+
["la-proper noun-form", (args, lemma) => this.parseForm(args, lemma, "proper nouns")],
|
|
55
|
+
["la-num-form", (args, lemma) => this.parseForm(args, lemma, "numerals")],
|
|
56
|
+
["la-pronoun-form", (args, lemma) => this.parseForm(args, lemma, "pronouns")],
|
|
57
|
+
["la-part-form", (args, lemma) => this.parseForm(args, lemma, "participles")],
|
|
58
|
+
["la-verb-form", (args, lemma) => this.parseForm(args, lemma, "verbs")],
|
|
59
|
+
["la-gerund-form", (args, lemma) => this.parseForm(args, lemma, "gerunds")],
|
|
60
|
+
["la-suffix-form", (args, lemma) => this.parseForm(args, lemma, "suffixes")],
|
|
61
|
+
["la-det-form", (args, lemma) => this.parseForm(args, lemma, "determiners")],
|
|
62
|
+
]);
|
|
63
|
+
nominal;
|
|
64
|
+
conj;
|
|
65
|
+
logger;
|
|
66
|
+
constructor(nominal, conj, logger) {
|
|
67
|
+
this.nominal = nominal;
|
|
68
|
+
this.conj = conj;
|
|
69
|
+
this.logger = logger;
|
|
70
|
+
}
|
|
71
|
+
isHeadwordTemplate(template) {
|
|
72
|
+
const args = parse_template(template);
|
|
73
|
+
const templateName = args.get("0");
|
|
74
|
+
if (!templateName) {
|
|
75
|
+
throw Error(`Invalid template string: ${template}`);
|
|
76
|
+
}
|
|
77
|
+
return this.templateParsers.has(templateName);
|
|
78
|
+
}
|
|
79
|
+
parse(template, lemma) {
|
|
80
|
+
const args = parse_template(template);
|
|
81
|
+
const templateName = args.get("0") || "nil";
|
|
82
|
+
const parseFunc = this.templateParsers.get(templateName);
|
|
83
|
+
if (!parseFunc) {
|
|
84
|
+
throw Error(`Not a headword template: ${template}`);
|
|
85
|
+
}
|
|
86
|
+
const data = parseFunc(args, lemma);
|
|
87
|
+
if (data.heads.length == 0) {
|
|
88
|
+
throw Error(`No heads for ${template} in ${lemma}`);
|
|
89
|
+
}
|
|
90
|
+
return data;
|
|
91
|
+
}
|
|
92
|
+
log(msg) {
|
|
93
|
+
if (this.logger) {
|
|
94
|
+
this.logger(msg);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
parseNominalHead(args, pos) {
|
|
98
|
+
const overridePos = args.get("pos") || pos;
|
|
99
|
+
const decl = this.nominal.do_generate_noun_forms(args, overridePos, true, args.get("lemma"));
|
|
100
|
+
const isNum = (pos == "numerals");
|
|
101
|
+
let lemmata = decl.overriding_lemma;
|
|
102
|
+
const lemmaNum = (decl.num == "pl" ? "pl" : "sg");
|
|
103
|
+
if (lemmata.length == 0) {
|
|
104
|
+
lemmata = getNominalForm(decl.forms, `linked_nom_${lemmaNum}`) || [];
|
|
105
|
+
}
|
|
106
|
+
let genders = decl.overriding_genders || [];
|
|
107
|
+
if (genders.length == 0) {
|
|
108
|
+
if (decl.gender) {
|
|
109
|
+
genders = [decl.gender.toLowerCase()];
|
|
110
|
+
}
|
|
111
|
+
else if (!isNum) {
|
|
112
|
+
throw Error("Couldn't infer gender");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
templateType: "headword",
|
|
117
|
+
headType: "nominal",
|
|
118
|
+
partOfSpeech: pos,
|
|
119
|
+
indeclinable: args.has("indecl"),
|
|
120
|
+
data: decl,
|
|
121
|
+
heads: lemmata,
|
|
122
|
+
genders: genders,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
parseAdjectivalHead(args, pos) {
|
|
126
|
+
const overridePos = args.get("pos") || pos;
|
|
127
|
+
const decl = this.nominal.do_generate_adj_forms(args, overridePos, true);
|
|
128
|
+
let lemmata = decl.overriding_lemma;
|
|
129
|
+
const lemmaNum = (decl.num == "pl" ? "pl" : "sg");
|
|
130
|
+
if (lemmata.length == 0) {
|
|
131
|
+
lemmata = getNominalForm(decl.forms, `linked_nom_${lemmaNum}_m`) || [];
|
|
132
|
+
if (lemmata.length == 0) {
|
|
133
|
+
lemmata = getNominalForm(decl.forms, `linked_nom_${lemmaNum}_n`) || [];
|
|
134
|
+
}
|
|
135
|
+
if (lemmata.length == 0) {
|
|
136
|
+
lemmata = getNominalForm(decl.forms, `linked_nom_${lemmaNum}_f`) || [];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
templateType: "headword",
|
|
141
|
+
headType: "adjectival",
|
|
142
|
+
partOfSpeech: pos,
|
|
143
|
+
indeclinable: args.has("indecl"),
|
|
144
|
+
data: decl,
|
|
145
|
+
heads: lemmata,
|
|
146
|
+
comparatives: decl.comp,
|
|
147
|
+
superlatives: decl.sup,
|
|
148
|
+
adverbs: decl.adv,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
parseVerbalHead(args, pos) {
|
|
152
|
+
const conj = this.conj.make_data(args);
|
|
153
|
+
let lemma_forms = conj.data.overriding_lemma;
|
|
154
|
+
if (lemma_forms.length == 0) {
|
|
155
|
+
lemma_forms = LaVerb.get_lemma_forms(conj.data, true);
|
|
156
|
+
}
|
|
157
|
+
const infinitives = getVerbForm(conj.data.forms, "pres_actv_inf") || [];
|
|
158
|
+
return {
|
|
159
|
+
templateType: "headword",
|
|
160
|
+
headType: "verbal",
|
|
161
|
+
data: conj,
|
|
162
|
+
partOfSpeech: pos,
|
|
163
|
+
heads: lemma_forms,
|
|
164
|
+
infinitives: infinitives,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
parseGerund(args) {
|
|
168
|
+
const gerund = args.get("1") || "";
|
|
169
|
+
const match = gerund.match(/^(.*)um$/);
|
|
170
|
+
if (!match) {
|
|
171
|
+
throw Error(`Unrecognized gerund ending in: ${gerund}`);
|
|
172
|
+
}
|
|
173
|
+
const stem = match[1];
|
|
174
|
+
const a2 = args.get("2") || "";
|
|
175
|
+
let gerundive;
|
|
176
|
+
if (a2 == "-") {
|
|
177
|
+
gerundive = undefined;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
gerundive = a2 || (stem + "us");
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
templateType: "headword",
|
|
184
|
+
headType: "gerund",
|
|
185
|
+
heads: [gerund],
|
|
186
|
+
gerundive: gerundive,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
parseComparativeAdj(args, lemma) {
|
|
190
|
+
const a1 = args.get("1");
|
|
191
|
+
const a2 = args.get("2");
|
|
192
|
+
const is_lemma = args.get("is_lemma");
|
|
193
|
+
const heads = read_list(args, "head");
|
|
194
|
+
const positive = read_list(args, "pos");
|
|
195
|
+
if (heads.length == 0) {
|
|
196
|
+
if (a1) {
|
|
197
|
+
heads.push(a1);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
heads.push(lemma);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (positive.length == 0) {
|
|
204
|
+
if (a2) {
|
|
205
|
+
positive.push(a2);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const n = [];
|
|
209
|
+
for (const head of heads) {
|
|
210
|
+
if (!head.endsWith("or")) {
|
|
211
|
+
this.log(`Strange comparative head ${head} in ${lemma}`);
|
|
212
|
+
}
|
|
213
|
+
const neuter = head.replace(/or$/, "us");
|
|
214
|
+
n.push(neuter);
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
templateType: "headword",
|
|
218
|
+
headType: "comparative",
|
|
219
|
+
isLemma: is_lemma ? true : false,
|
|
220
|
+
heads: heads,
|
|
221
|
+
neuter: n,
|
|
222
|
+
positive: positive,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
parseSuperlativeAdj(args, lemma) {
|
|
226
|
+
const a1 = args.get("1");
|
|
227
|
+
const a2 = args.get("2");
|
|
228
|
+
const is_lemma = args.get("is_lemma");
|
|
229
|
+
const heads = read_list(args, "head");
|
|
230
|
+
const positive = read_list(args, "pos");
|
|
231
|
+
if (heads.length == 0) {
|
|
232
|
+
if (a1) {
|
|
233
|
+
heads.push(a1);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
heads.push(lemma);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (positive.length == 0) {
|
|
240
|
+
if (a2) {
|
|
241
|
+
positive.push(a2);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const n = [];
|
|
245
|
+
const f = [];
|
|
246
|
+
for (const head of heads) {
|
|
247
|
+
if (!head.endsWith("us")) {
|
|
248
|
+
this.log(`Skpping invalid superlative head ${head} in ${lemma}`);
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
const stem = head.replace(/us$/, "");
|
|
252
|
+
f.push(stem + "a");
|
|
253
|
+
n.push(stem + "um");
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
templateType: "headword",
|
|
257
|
+
headType: "superlative",
|
|
258
|
+
isLemma: is_lemma ? true : false,
|
|
259
|
+
heads: heads,
|
|
260
|
+
neuter: n,
|
|
261
|
+
feminine: f,
|
|
262
|
+
positive: positive,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
parseAdverb(args, pos) {
|
|
266
|
+
const a1 = args.get("1");
|
|
267
|
+
const a2 = args.get("2");
|
|
268
|
+
const a3 = args.get("3");
|
|
269
|
+
const heads = read_list(args, "head");
|
|
270
|
+
let comp = read_list(args, "comp");
|
|
271
|
+
let sup = read_list(args, "sup");
|
|
272
|
+
if (a1) {
|
|
273
|
+
heads.push(a1);
|
|
274
|
+
}
|
|
275
|
+
if (a2) {
|
|
276
|
+
comp.push(a2);
|
|
277
|
+
}
|
|
278
|
+
if (a3) {
|
|
279
|
+
sup.push(a3);
|
|
280
|
+
}
|
|
281
|
+
if (comp.length > 0 && comp[0] == "-") {
|
|
282
|
+
sup = ["-"];
|
|
283
|
+
}
|
|
284
|
+
if (comp.length == 0 || sup.length == 0) {
|
|
285
|
+
const default_comp = [];
|
|
286
|
+
const default_sup = [];
|
|
287
|
+
for (const head of heads) {
|
|
288
|
+
let stem;
|
|
289
|
+
for (let suff of ["iter", "nter", "ter", "er", "iē", "ē", "im", "ō"]) {
|
|
290
|
+
const match = head.match(new RegExp(`(.*)${suff}$`));
|
|
291
|
+
if (match) {
|
|
292
|
+
stem = match[1];
|
|
293
|
+
if (suff == "nter") {
|
|
294
|
+
stem = stem + "nt";
|
|
295
|
+
suff = "er";
|
|
296
|
+
}
|
|
297
|
+
default_comp.push(stem + "ius");
|
|
298
|
+
default_sup.push(stem + "issimē");
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (!stem) {
|
|
303
|
+
throw Error("Unrecognized adverb type");
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (comp.length == 0) {
|
|
307
|
+
comp = default_comp;
|
|
308
|
+
}
|
|
309
|
+
if (sup.length == 0) {
|
|
310
|
+
sup = default_sup;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (comp.length > 0 && comp[0] == "-") {
|
|
314
|
+
comp = [];
|
|
315
|
+
}
|
|
316
|
+
if (sup.length > 0 && sup[0] == "-") {
|
|
317
|
+
sup = [];
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
templateType: "headword",
|
|
321
|
+
headType: "adverb",
|
|
322
|
+
partOfSpeech: pos,
|
|
323
|
+
heads: heads,
|
|
324
|
+
comparatives: comp,
|
|
325
|
+
superlatives: sup,
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
parseAdverbNumeral(args) {
|
|
329
|
+
const a1 = args.get("1") || "";
|
|
330
|
+
const numType = args.get("type") || "";
|
|
331
|
+
return {
|
|
332
|
+
templateType: "headword",
|
|
333
|
+
headType: "numeral_adverb",
|
|
334
|
+
heads: [a1],
|
|
335
|
+
numType: numType,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
parseAdverbCompSup(args, pos) {
|
|
339
|
+
const head = args.get("1");
|
|
340
|
+
let heads;
|
|
341
|
+
if (head) {
|
|
342
|
+
heads = [head];
|
|
343
|
+
}
|
|
344
|
+
return {
|
|
345
|
+
templateType: "headword",
|
|
346
|
+
headType: "adverb",
|
|
347
|
+
partOfSpeech: pos,
|
|
348
|
+
heads: heads || [],
|
|
349
|
+
comparatives: [],
|
|
350
|
+
superlatives: [],
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
parseLetter(args, lemma) {
|
|
354
|
+
const upper = read_list(args, "upper");
|
|
355
|
+
const lower = read_list(args, "lower");
|
|
356
|
+
const mixed = read_list(args, "mixed");
|
|
357
|
+
const sc = args.get("sc") || "";
|
|
358
|
+
if (upper.length == 0 && lower.length == 0 && mixed.length == 0) {
|
|
359
|
+
this.log(`No parameters for letter ${lemma}`);
|
|
360
|
+
upper.push(lemma);
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
templateType: "headword",
|
|
364
|
+
headType: "letter",
|
|
365
|
+
heads: upper.concat(lower).concat(mixed),
|
|
366
|
+
upper: upper,
|
|
367
|
+
lower: lower,
|
|
368
|
+
mixed: mixed,
|
|
369
|
+
scriptCode: sc,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
parsePreposition(args, lemma) {
|
|
373
|
+
let genitive = false;
|
|
374
|
+
let ablative = false;
|
|
375
|
+
let accusative = false;
|
|
376
|
+
const heads = read_list(args, "head");
|
|
377
|
+
for (const [key, value] of args) {
|
|
378
|
+
if (value == "genitive") {
|
|
379
|
+
genitive = true;
|
|
380
|
+
}
|
|
381
|
+
else if (value == "ablative") {
|
|
382
|
+
ablative = true;
|
|
383
|
+
}
|
|
384
|
+
else if (value == "accusative") {
|
|
385
|
+
accusative = true;
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
if (key != "0") {
|
|
389
|
+
heads.push(value);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (heads.length == 0) {
|
|
394
|
+
heads.push(lemma);
|
|
395
|
+
}
|
|
396
|
+
return {
|
|
397
|
+
templateType: "headword",
|
|
398
|
+
headType: "preposition",
|
|
399
|
+
heads: heads,
|
|
400
|
+
genitive: genitive,
|
|
401
|
+
accusative: accusative,
|
|
402
|
+
ablative: ablative,
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
parseInterjection(args, lemma) {
|
|
406
|
+
const head = args.get("head");
|
|
407
|
+
let interj = head || args.get("1");
|
|
408
|
+
if (!interj) {
|
|
409
|
+
interj = lemma;
|
|
410
|
+
}
|
|
411
|
+
return {
|
|
412
|
+
templateType: "headword",
|
|
413
|
+
headType: "interjection",
|
|
414
|
+
heads: [interj],
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
parsePhrase(args, lemma) {
|
|
418
|
+
let phrase = args.get("1");
|
|
419
|
+
if (!phrase) {
|
|
420
|
+
phrase = lemma;
|
|
421
|
+
}
|
|
422
|
+
return {
|
|
423
|
+
templateType: "headword",
|
|
424
|
+
headType: "phrase",
|
|
425
|
+
heads: [phrase],
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
parseHead(args, lemma) {
|
|
429
|
+
const pos = args.get("2");
|
|
430
|
+
const heads = read_list(args, "head");
|
|
431
|
+
if (!pos) {
|
|
432
|
+
throw Error(`la-head without pos: ${lemma}`);
|
|
433
|
+
}
|
|
434
|
+
if (heads.length == 0) {
|
|
435
|
+
heads.push(lemma);
|
|
436
|
+
}
|
|
437
|
+
return {
|
|
438
|
+
templateType: "headword",
|
|
439
|
+
headType: "particle",
|
|
440
|
+
partOfSpeech: pos,
|
|
441
|
+
heads: heads,
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
parseForm(args, lemma, pos) {
|
|
445
|
+
let form = args.get("1");
|
|
446
|
+
if (!form) {
|
|
447
|
+
form = lemma;
|
|
448
|
+
}
|
|
449
|
+
return {
|
|
450
|
+
templateType: "headword",
|
|
451
|
+
headType: "form",
|
|
452
|
+
partOfSpeech: pos,
|
|
453
|
+
heads: [form],
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
}
|