twl-generator 1.1.3 → 1.1.4
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 +34 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "twl-generator",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
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
|
@@ -4,16 +4,20 @@
|
|
|
4
4
|
function generateVariants(term) {
|
|
5
5
|
const variants = new Set([term]);
|
|
6
6
|
|
|
7
|
-
// Handle pluralization
|
|
8
|
-
if (term.endsWith('s') && term.length > 2) {
|
|
9
|
-
variants.add(term.slice(0, -1)); // dogs -> dog
|
|
7
|
+
// Handle pluralization - simple 's' removal (but not for words ending in 'ss')
|
|
8
|
+
if (term.endsWith('s') && term.length > 2 && !term.endsWith('ss') && !term.endsWith('es')) {
|
|
9
|
+
variants.add(term.slice(0, -1)); // dogs -> dog (but not does -> doe)
|
|
10
10
|
} else {
|
|
11
11
|
variants.add(term + 's'); // dog -> dogs
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
// Handle 'es' endings
|
|
15
|
-
if (term.endsWith('es') && term.length >
|
|
16
|
-
|
|
14
|
+
// Handle 'es' endings - but only for legitimate plural patterns
|
|
15
|
+
if (term.endsWith('es') && term.length > 4) {
|
|
16
|
+
const base = term.slice(0, -2);
|
|
17
|
+
// Only if the base word would naturally take 'es' plural
|
|
18
|
+
if (/[sxz]$|[cs]h$/.test(base)) {
|
|
19
|
+
variants.add(base); // horses -> horse, churches -> church
|
|
20
|
+
}
|
|
17
21
|
} else if (term.endsWith('e')) {
|
|
18
22
|
variants.add(term + 's'); // horse -> horses
|
|
19
23
|
} else if (/[sxz]$|[cs]h$/.test(term)) {
|
|
@@ -34,12 +38,21 @@ function generateVariants(term) {
|
|
|
34
38
|
variants.add(term + "'");
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
// Handle -ed
|
|
38
|
-
if (term.endsWith('ed') && term.length >
|
|
39
|
-
|
|
41
|
+
// Handle -ed forms - but only for legitimate verb patterns
|
|
42
|
+
if (term.endsWith('ed') && term.length > 4) {
|
|
43
|
+
const base = term.slice(0, -2);
|
|
44
|
+
// Only create base form if it looks like a legitimate verb stem
|
|
45
|
+
if (base.length > 2) {
|
|
46
|
+
variants.add(base); // walked -> walk
|
|
47
|
+
}
|
|
40
48
|
}
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
|
|
50
|
+
// Handle -ing forms
|
|
51
|
+
if (term.endsWith('ing') && term.length > 5) {
|
|
52
|
+
const base = term.slice(0, -3);
|
|
53
|
+
if (base.length > 2) {
|
|
54
|
+
variants.add(base); // walking -> walk
|
|
55
|
+
}
|
|
43
56
|
}
|
|
44
57
|
|
|
45
58
|
// Double consonant handling for -ed/-ing
|
|
@@ -48,7 +61,7 @@ function generateVariants(term) {
|
|
|
48
61
|
variants.add(term + term.slice(-1) + 'ing'); // stop -> stopping
|
|
49
62
|
}
|
|
50
63
|
|
|
51
|
-
// Regular -ed/-ing
|
|
64
|
+
// Regular -ed/-ing addition
|
|
52
65
|
if (!term.endsWith('e')) {
|
|
53
66
|
variants.add(term + 'ed');
|
|
54
67
|
variants.add(term + 'ing');
|
|
@@ -134,12 +147,18 @@ class PrefixTrie {
|
|
|
134
147
|
const matchLength = currentPos - startPos;
|
|
135
148
|
const originalMatchedText = text.substring(startPos, currentPos);
|
|
136
149
|
|
|
137
|
-
// Check if this is a valid word boundary match
|
|
138
|
-
const
|
|
150
|
+
// Check if this is a valid word boundary match (both start and end)
|
|
151
|
+
const isStartBoundary = startPos === 0 ||
|
|
152
|
+
/[\s\p{P}]/.test(text[startPos - 1]) ||
|
|
153
|
+
!/[\w]/.test(text[startPos - 1]);
|
|
154
|
+
|
|
155
|
+
const isEndBoundary = currentPos >= text.length ||
|
|
139
156
|
/[\s\p{P}]/.test(text[currentPos]) ||
|
|
140
157
|
!/[\w]/.test(text[currentPos]);
|
|
141
158
|
|
|
142
|
-
|
|
159
|
+
const isWordBoundary = isStartBoundary && isEndBoundary;
|
|
160
|
+
|
|
161
|
+
if (isWordBoundary) {
|
|
143
162
|
for (const termData of node._terms) {
|
|
144
163
|
matches.push({
|
|
145
164
|
term: termData.term,
|