twl-generator 1.2.7 → 1.2.9
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 +2 -2
- package/src/utils/twl-matcher.js +28 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "twl-generator",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9",
|
|
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": {
|
|
@@ -56,4 +56,4 @@
|
|
|
56
56
|
"optional": true
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
}
|
|
59
|
+
}
|
package/src/utils/twl-matcher.js
CHANGED
|
@@ -4,60 +4,62 @@
|
|
|
4
4
|
function generateVariants(term) {
|
|
5
5
|
const variants = new Set([term]);
|
|
6
6
|
|
|
7
|
-
const nouns = ['doe', 'deer', 'father'];
|
|
7
|
+
const nouns = ['doe', 'deer', 'father', 'Father'];
|
|
8
|
+
const do_not_pluralize = ['doe'];
|
|
9
|
+
const do_not_depluralize = [];
|
|
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') && !do_not_depluralize.includes(term)) {
|
|
11
13
|
variants.add(term.slice(0, -1)); // dogs -> dog (but not does -> doe)
|
|
12
|
-
} else {
|
|
14
|
+
} else if (!do_not_pluralize.includes(term)) {
|
|
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 && !do_not_depluralize.includes(term)) {
|
|
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') && !do_not_pluralize.includes(term)) {
|
|
24
26
|
variants.add(term + 's'); // horse -> horses
|
|
25
|
-
} else if (/[sxz]$|[cs]h$/.test(term)) {
|
|
27
|
+
} else if (/[sxz]$|[cs]h$/.test(term) && !do_not_pluralize.includes(term)) {
|
|
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 && !do_not_depluralize.includes(term)) {
|
|
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) && !do_not_pluralize.includes(term)) {
|
|
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
|
-
|
|
45
|
+
if (!nouns.includes(term)) {
|
|
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
|
+
}
|
|
49
53
|
}
|
|
50
|
-
}
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
+
}
|
|
57
61
|
}
|
|
58
|
-
}
|
|
59
62
|
|
|
60
|
-
if (!nouns.includes(term)) {
|
|
61
63
|
// Double consonant handling for -ed/-ing
|
|
62
64
|
if (/[bcdfghjklmnpqrstvwxyz][aeiou][bcdfghjklmnpqrstvwxyz]$/.test(term)) {
|
|
63
65
|
variants.add(term + term.slice(-1) + 'ed'); // stop -> stopped
|
|
@@ -90,8 +92,8 @@ class PrefixTrie {
|
|
|
90
92
|
// Insert into exact case trie
|
|
91
93
|
this._insertIntoTree(this.exactCaseRoot, term, originalTerm, articles, isOriginal, true);
|
|
92
94
|
|
|
93
|
-
// Also insert into lowercase trie for fallback
|
|
94
|
-
this._insertIntoTree(this.lowerCaseRoot, term.toLowerCase(), originalTerm, articles, isOriginal, false);
|
|
95
|
+
// // Also insert into lowercase trie for fallback - removed, too many falses
|
|
96
|
+
// this._insertIntoTree(this.lowerCaseRoot, term.toLowerCase(), originalTerm, articles, isOriginal, false);
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
_insertIntoTree(root, term, originalTerm, articles, isOriginal, isExactCase) {
|
|
@@ -300,7 +302,7 @@ function generateId() {
|
|
|
300
302
|
for (let i = 0; i < 3; i++) {
|
|
301
303
|
id += lettersAndDigits[Math.floor(Math.random() * lettersAndDigits.length)];
|
|
302
304
|
}
|
|
303
|
-
return id;
|
|
305
|
+
return 'abcd' || id;
|
|
304
306
|
}
|
|
305
307
|
|
|
306
308
|
/**
|