@fpw/en-wiktionary-la-modules 0.2.1 → 0.3.1

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