twl-generator 1.2.8 → 1.2.10
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/package.json +1 -1
- package/src/utils/twl-matcher.js +38 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "twl-generator",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.10",
|
|
4
4
|
"description": "Generate term-to-article lists from unfoldingWord en_tw archive for Bible books. Works in both Node.js (CLI) and React.js (browser) environments.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
package/src/utils/twl-matcher.js
CHANGED
|
@@ -1,63 +1,67 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generate morphological variants of a term
|
|
3
3
|
*/
|
|
4
|
-
function generateVariants(term) {
|
|
4
|
+
function generateVariants(term, isName = false) {
|
|
5
5
|
const variants = new Set([term]);
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const isNoun = ['horn', 'mare', 'steed', 'horse', 'doe', 'deer', 'father', 'Father'].includes(term) || isName;
|
|
8
|
+
const doNotPluralize = ['doe'].includes(term);
|
|
9
|
+
const doNotDepluralize = ['kids'].includes(term) || isName;
|
|
8
10
|
|
|
9
11
|
// Handle pluralization - simple 's' removal (but not for words ending in 'ss')
|
|
10
|
-
if (term.endsWith('s') && term.length > 2 && !term.endsWith('ss') && !term.endsWith('es')) {
|
|
12
|
+
if (term.endsWith('s') && term.length > 2 && !term.endsWith('ss') && !term.endsWith('es') && !doNotDepluralize) {
|
|
11
13
|
variants.add(term.slice(0, -1)); // dogs -> dog (but not does -> doe)
|
|
12
|
-
} else {
|
|
14
|
+
} else if (!doNotPluralize) {
|
|
13
15
|
variants.add(term + 's'); // dog -> dogs
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
// Handle 'es' endings - but only for legitimate plural patterns
|
|
17
|
-
if (term.endsWith('es') && term.length > 4) {
|
|
19
|
+
if (term.endsWith('es') && term.length > 4 && !doNotDepluralize) {
|
|
18
20
|
const base = term.slice(0, -2);
|
|
19
21
|
// Only if the base word would naturally take 'es' plural
|
|
20
22
|
if (/[sxz]$|[cs]h$/.test(base)) {
|
|
21
23
|
variants.add(base); // horses -> horse, churches -> church
|
|
22
24
|
}
|
|
23
|
-
} else if (term.endsWith('e')) {
|
|
25
|
+
} else if (term.endsWith('e') && !doNotPluralize) {
|
|
24
26
|
variants.add(term + 's'); // horse -> horses
|
|
25
|
-
} else if (/[sxz]$|[cs]h$/.test(term)) {
|
|
27
|
+
} else if (/[sxz]$|[cs]h$/.test(term) && !doNotPluralize) {
|
|
26
28
|
variants.add(term + 'es'); // church -> churches
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
// Handle 'ies' endings for words ending in 'y'
|
|
30
|
-
if (term.endsWith('ies') && term.length > 4) {
|
|
32
|
+
if (term.endsWith('ies') && term.length > 4 && !doNotDepluralize) {
|
|
31
33
|
variants.add(term.slice(0, -3) + 'y'); // cities -> city
|
|
32
|
-
} else if (term.endsWith('y') && term.length > 2 && !/[aeiou]y$/.test(term)) {
|
|
34
|
+
} else if (term.endsWith('y') && term.length > 2 && !/[aeiou]y$/.test(term) && !doNotPluralize) {
|
|
33
35
|
variants.add(term.slice(0, -1) + 'ies'); // city -> cities
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
// // Handle possessive forms
|
|
38
|
+
// // Handle possessive forms -- // Commented out since we use curly quotes
|
|
37
39
|
// variants.add(term + "'s");
|
|
38
40
|
// variants.add(term + "'");
|
|
39
41
|
// if (term.endsWith('s')) {
|
|
40
42
|
// variants.add(term + "'");
|
|
41
43
|
// }
|
|
42
44
|
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
45
|
+
// if (!isNoun) {
|
|
46
|
+
// // Handle -ed forms - but only for legitimate verb patterns
|
|
47
|
+
// if (term.endsWith('ed') && term.length > 4) {
|
|
48
|
+
// const base = term.slice(0, -2);
|
|
49
|
+
// // Only create base form if it looks like a legitimate verb stem
|
|
50
|
+
// if (base.length > 2) {
|
|
51
|
+
// variants.add(base); // walked -> walk
|
|
52
|
+
// }
|
|
53
|
+
// }
|
|
54
|
+
|
|
55
|
+
// // Handle -ing forms
|
|
56
|
+
// if (term.endsWith('ing') && term.length > 5) {
|
|
57
|
+
// const base = term.slice(0, -3);
|
|
58
|
+
// if (base.length > 2) {
|
|
59
|
+
// variants.add(base); // walking -> walk
|
|
60
|
+
// }
|
|
61
|
+
// }
|
|
51
62
|
|
|
52
|
-
// Handle -ing forms
|
|
53
|
-
if (term.endsWith('ing') && term.length > 5) {
|
|
54
|
-
const base = term.slice(0, -3);
|
|
55
|
-
if (base.length > 2) {
|
|
56
|
-
variants.add(base); // walking -> walk
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
63
|
|
|
60
|
-
if (!
|
|
64
|
+
if (!isNoun) {
|
|
61
65
|
// Double consonant handling for -ed/-ing
|
|
62
66
|
if (/[bcdfghjklmnpqrstvwxyz][aeiou][bcdfghjklmnpqrstvwxyz]$/.test(term)) {
|
|
63
67
|
variants.add(term + term.slice(-1) + 'ed'); // stop -> stopped
|
|
@@ -74,6 +78,12 @@ function generateVariants(term) {
|
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
80
|
|
|
81
|
+
for (const variant of Array.from(variants)) {
|
|
82
|
+
if (variant.length > 0 && variant[0] === variant[0].toLowerCase() && /[a-z]/.test(variant[0])) {
|
|
83
|
+
variants.add(variant[0].toUpperCase() + variant.slice(1));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
77
87
|
return Array.from(variants);
|
|
78
88
|
}
|
|
79
89
|
|
|
@@ -212,9 +222,8 @@ function createOptimizedTermMap(twTerms) {
|
|
|
212
222
|
// Generate and add variants for single words only to avoid exponential explosion
|
|
213
223
|
if (!originalTerm.includes(' ')) {
|
|
214
224
|
let variants = new Set([originalTerm]);
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
225
|
+
const isName = articles[0].startsWith('names/') || articles[1]?.startsWith('names/')
|
|
226
|
+
variants = generateVariants(originalTerm, isName);
|
|
218
227
|
console.log(variants)
|
|
219
228
|
for (const variant of variants) {
|
|
220
229
|
if (variant !== originalTerm) {
|