@fpw/en-wiktionary-la-modules 0.2.2 → 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.
- 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
package/dist/modules/common.d.ts
CHANGED
|
@@ -1,66 +1,67 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
/**
|
|
4
|
-
* Parse a MediaWiki template string like {{a|b|c=d}} into a key-value map.
|
|
5
|
-
* Unnamed parameters will use number strings starting at '0'.
|
|
6
|
-
* @param desc the MediaWiki template string
|
|
7
|
-
* @returns a map of keys and values
|
|
8
|
-
*/
|
|
9
|
-
export declare function parse_template(desc: string): ArgMap;
|
|
10
|
-
/**
|
|
11
|
-
* Read a parameter list from a MediaWiki template string.
|
|
12
|
-
* Example: {{...|p=a,p2=b,p3=c}} will become [a, b, c] if p is read
|
|
13
|
-
* @param args a parsed MediaWiki template string
|
|
14
|
-
* @param elem the name of the list
|
|
15
|
-
* @returns elemnts of the lists
|
|
16
|
-
*/
|
|
17
|
-
export declare function read_list(args: ArgMap, elem: string): string[];
|
|
18
|
-
/**
|
|
19
|
-
* Removes MediaWiki links by replacing them with their displayed value.
|
|
20
|
-
* Example [[a|title]] will be replaced with 'title'
|
|
21
|
-
* @param str a string that can contain MediaWiki links
|
|
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
|
-
* @param
|
|
50
|
-
* @
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*
|
|
56
|
-
* @param
|
|
57
|
-
* @
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*
|
|
63
|
-
* @param
|
|
64
|
-
* @
|
|
65
|
-
|
|
66
|
-
|
|
1
|
+
export type ArgMap = Map<string, string>;
|
|
2
|
+
export type FormMap<T> = Map<T, string[]>;
|
|
3
|
+
/**
|
|
4
|
+
* Parse a MediaWiki template string like {{a|b|c=d}} into a key-value map.
|
|
5
|
+
* Unnamed parameters will use number strings starting at '0'.
|
|
6
|
+
* @param desc the MediaWiki template string
|
|
7
|
+
* @returns a map of keys and values
|
|
8
|
+
*/
|
|
9
|
+
export declare function parse_template(desc: string): ArgMap;
|
|
10
|
+
/**
|
|
11
|
+
* Read a parameter list from a MediaWiki template string.
|
|
12
|
+
* Example: {{...|p=a,p2=b,p3=c}} will become [a, b, c] if p is read
|
|
13
|
+
* @param args a parsed MediaWiki template string
|
|
14
|
+
* @param elem the name of the list
|
|
15
|
+
* @returns elemnts of the lists
|
|
16
|
+
*/
|
|
17
|
+
export declare function read_list(args: ArgMap, elem: string): string[];
|
|
18
|
+
/**
|
|
19
|
+
* Removes MediaWiki links by replacing them with their displayed value.
|
|
20
|
+
* Example [[a|title]] will be replaced with 'title'
|
|
21
|
+
* @param str a string that can contain MediaWiki links
|
|
22
|
+
* @param displayed whether to keep the displayed part of the link (e.g. 'title' in [[a|title]]) or the linked part (e.g. 'a' in [[a|title]])
|
|
23
|
+
* @returns the string with all links replaced by their title
|
|
24
|
+
*/
|
|
25
|
+
export declare function remove_links(str: string, displayed?: boolean): string;
|
|
26
|
+
/**
|
|
27
|
+
* Very basic HTML remover to remove simple, non-nested tags from a string.
|
|
28
|
+
* @param str a string containing simple HTML markup
|
|
29
|
+
* @returns a string with HTML tags removed
|
|
30
|
+
*/
|
|
31
|
+
export declare function remove_html(str: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Removes macrons from a string.
|
|
34
|
+
* Example: 'Āfrica' will become 'Africa'
|
|
35
|
+
* @param str a string containing macrons
|
|
36
|
+
* @returns string without macrons
|
|
37
|
+
*/
|
|
38
|
+
export declare function strip_macrons(str: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Removes all diacritical parts from a string except for macrons.
|
|
41
|
+
* Example: 'Thēse͡us' will become 'Thēseus'
|
|
42
|
+
* @param str string containing diactricial characters
|
|
43
|
+
* @returns string with all diactricial marks except macrons removed
|
|
44
|
+
*/
|
|
45
|
+
export declare function remove_diacritical(str: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Given a word and an ending, returns the base part of the word excluding the ending.
|
|
48
|
+
* The given ending can be a RegEx with a capture group - in that case, the first group will be returned.
|
|
49
|
+
* @param lemma word to extract the base from
|
|
50
|
+
* @param ending ending to remove, can be a RegEx
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
export declare function extract_base(lemma: string, ending: string): string | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Checks if two one-dimensional arrays are equal.
|
|
56
|
+
* @param a array a
|
|
57
|
+
* @param b array b
|
|
58
|
+
* @returns true if the arrays are equal
|
|
59
|
+
*/
|
|
60
|
+
export declare function array_equals(a: string[] | undefined, b: string[] | undefined): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Check if a value is a value of a given enum
|
|
63
|
+
* @param enumType pass the enum type as value
|
|
64
|
+
* @param val the value to check
|
|
65
|
+
* @returns whether the value is part of the enum values
|
|
66
|
+
*/
|
|
67
|
+
export declare function is_enum_value<E>(enumType: E, val: unknown): val is E[keyof E];
|
package/dist/modules/common.js
CHANGED
|
@@ -1,157 +1,145 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
res.set(
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (
|
|
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
|
-
* @returns whether the value is part of the enum values
|
|
147
|
-
*/
|
|
148
|
-
function is_enum_value(enumType, val) {
|
|
149
|
-
for (const key in enumType) {
|
|
150
|
-
if (enumType[key] === val) {
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
exports.is_enum_value = is_enum_value;
|
|
157
|
-
//# sourceMappingURL=common.js.map
|
|
1
|
+
/**
|
|
2
|
+
* Parse a MediaWiki template string like {{a|b|c=d}} into a key-value map.
|
|
3
|
+
* Unnamed parameters will use number strings starting at '0'.
|
|
4
|
+
* @param desc the MediaWiki template string
|
|
5
|
+
* @returns a map of keys and values
|
|
6
|
+
*/
|
|
7
|
+
export function parse_template(desc) {
|
|
8
|
+
// remove {{ }}
|
|
9
|
+
const paramStr = desc
|
|
10
|
+
.replace(/[\r\n]/g, "")
|
|
11
|
+
.replace(/^{{(.*)}}$/, "$1");
|
|
12
|
+
const partStr = remove_links(paramStr, false);
|
|
13
|
+
const parts = partStr.split("|");
|
|
14
|
+
const res = new Map();
|
|
15
|
+
let i = 0;
|
|
16
|
+
for (const part of parts) {
|
|
17
|
+
if (part.includes("=")) {
|
|
18
|
+
const [key, value] = part.split("=");
|
|
19
|
+
res.set(key, value);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
res.set(`${i++}`, part);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return res;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Read a parameter list from a MediaWiki template string.
|
|
29
|
+
* Example: {{...|p=a,p2=b,p3=c}} will become [a, b, c] if p is read
|
|
30
|
+
* @param args a parsed MediaWiki template string
|
|
31
|
+
* @param elem the name of the list
|
|
32
|
+
* @returns elemnts of the lists
|
|
33
|
+
*/
|
|
34
|
+
export function read_list(args, elem) {
|
|
35
|
+
const entries = [];
|
|
36
|
+
for (const [key, value] of args.entries()) {
|
|
37
|
+
const match = key.match(new RegExp(`^${elem}([0-9]*)$`));
|
|
38
|
+
if (!match) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
let idx = 0;
|
|
42
|
+
if (match[1]) {
|
|
43
|
+
idx = Number.parseInt(match[1], 10) - 1;
|
|
44
|
+
}
|
|
45
|
+
entries[idx] = value;
|
|
46
|
+
}
|
|
47
|
+
return entries.filter(x => x !== undefined);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Removes MediaWiki links by replacing them with their displayed value.
|
|
51
|
+
* Example [[a|title]] will be replaced with 'title'
|
|
52
|
+
* @param str a string that can contain MediaWiki links
|
|
53
|
+
* @param displayed whether to keep the displayed part of the link (e.g. 'title' in [[a|title]]) or the linked part (e.g. 'a' in [[a|title]])
|
|
54
|
+
* @returns the string with all links replaced by their title
|
|
55
|
+
*/
|
|
56
|
+
export function remove_links(str, displayed = true) {
|
|
57
|
+
// flatten links [[a|b]] to [[b]]
|
|
58
|
+
const norm1 = str.replace(/\[\[([^\]]*?\|([^\]]*?))\]\]/g, displayed ? "[[$2]]" : "[[$1]]");
|
|
59
|
+
// replace [[b]] with b
|
|
60
|
+
const norm2 = norm1.replace(/\[\[([^\]]*?)\]\]/g, "$1");
|
|
61
|
+
return norm2;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Very basic HTML remover to remove simple, non-nested tags from a string.
|
|
65
|
+
* @param str a string containing simple HTML markup
|
|
66
|
+
* @returns a string with HTML tags removed
|
|
67
|
+
*/
|
|
68
|
+
export function remove_html(str) {
|
|
69
|
+
return str.replace(/<.*?>(.*?)<\/.*?>/g, "$1");
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Removes macrons from a string.
|
|
73
|
+
* Example: 'Āfrica' will become 'Africa'
|
|
74
|
+
* @param str a string containing macrons
|
|
75
|
+
* @returns string without macrons
|
|
76
|
+
*/
|
|
77
|
+
export function strip_macrons(str) {
|
|
78
|
+
return str
|
|
79
|
+
.normalize("NFD")
|
|
80
|
+
.replace(/\u0304/g, "")
|
|
81
|
+
.normalize("NFC");
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Removes all diacritical parts from a string except for macrons.
|
|
85
|
+
* Example: 'Thēse͡us' will become 'Thēseus'
|
|
86
|
+
* @param str string containing diactricial characters
|
|
87
|
+
* @returns string with all diactricial marks except macrons removed
|
|
88
|
+
*/
|
|
89
|
+
export function remove_diacritical(str) {
|
|
90
|
+
const noDias = str
|
|
91
|
+
.normalize("NFD")
|
|
92
|
+
.replace(/[\u0300-\u0303\u0305-\u036F]/g, "")
|
|
93
|
+
.normalize("NFC");
|
|
94
|
+
return noDias;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Given a word and an ending, returns the base part of the word excluding the ending.
|
|
98
|
+
* The given ending can be a RegEx with a capture group - in that case, the first group will be returned.
|
|
99
|
+
* @param lemma word to extract the base from
|
|
100
|
+
* @param ending ending to remove, can be a RegEx
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
export function extract_base(lemma, ending) {
|
|
104
|
+
let regex;
|
|
105
|
+
if (ending.includes("(")) {
|
|
106
|
+
regex = ending;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
regex = `^(.*)${ending}$`;
|
|
110
|
+
}
|
|
111
|
+
const match = lemma.match(new RegExp(regex));
|
|
112
|
+
if (match) {
|
|
113
|
+
return match[1];
|
|
114
|
+
}
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Checks if two one-dimensional arrays are equal.
|
|
119
|
+
* @param a array a
|
|
120
|
+
* @param b array b
|
|
121
|
+
* @returns true if the arrays are equal
|
|
122
|
+
*/
|
|
123
|
+
export function array_equals(a, b) {
|
|
124
|
+
if ((!a && b) || (a && !b)) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
if (!a || !b) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
return (a.length == b.length) && a.every((x, i) => b[i] == x);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Check if a value is a value of a given enum
|
|
134
|
+
* @param enumType pass the enum type as value
|
|
135
|
+
* @param val the value to check
|
|
136
|
+
* @returns whether the value is part of the enum values
|
|
137
|
+
*/
|
|
138
|
+
export function is_enum_value(enumType, val) {
|
|
139
|
+
for (const key in enumType) {
|
|
140
|
+
if (enumType[key] === val) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|