twl-generator 1.4.5 → 1.4.7
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 +3 -2
- package/src/index.js +8 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "twl-generator",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.7",
|
|
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": {
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"compromise": "^14.14.2",
|
|
50
50
|
"csv-parse": "^5.5.6",
|
|
51
51
|
"csv-stringify": "^6.5.0",
|
|
52
|
+
"en-inflectors": "^1.0.12",
|
|
52
53
|
"jszip": "^3.10.1",
|
|
53
54
|
"tsv-quote-converters": "^1.1.14"
|
|
54
55
|
},
|
|
@@ -60,4 +61,4 @@
|
|
|
60
61
|
"optional": true
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
|
-
}
|
|
64
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BibleBookData } from './common/books.js';
|
|
2
2
|
import { addGLQuoteCols, convertGLQuotes2OLQuotes } from 'tsv-quote-converters';
|
|
3
|
+
import { Inflectors } from 'en-inflectors';
|
|
3
4
|
|
|
4
5
|
const isBrowser = typeof window !== 'undefined';
|
|
5
6
|
|
|
@@ -865,32 +866,17 @@ export async function generateTwlByBook(bookCode, options = {}) {
|
|
|
865
866
|
|
|
866
867
|
// Helpers for Variant of decision (allow only plural/-ed/-ing without marking variant)
|
|
867
868
|
const pluralizeWord = (w) => {
|
|
868
|
-
|
|
869
|
-
if (/(s|x|z|ch|sh)$/i.test(w)) return w + 'es';
|
|
870
|
-
if (/f$/i.test(w) && !/(roof|belief|chief|proof)$/i.test(w)) return w.replace(/f$/i, 'ves');
|
|
871
|
-
if (/fe$/i.test(w)) return w.replace(/fe$/i, 'ves');
|
|
872
|
-
if (/o$/i.test(w)) return w + 'es';
|
|
873
|
-
return w + 's';
|
|
869
|
+
return new Inflectors(w).toPlural();
|
|
874
870
|
};
|
|
875
|
-
const isVowel = (ch) => /[aeiou]/i.test(ch);
|
|
876
|
-
const isConsonant = (ch) => /[a-z]/i.test(ch) && !isVowel(ch);
|
|
877
|
-
const endsWithCVC = (w) => w.length >= 3 && isConsonant(w[w.length - 3]) && isVowel(w[w.length - 2]) && isConsonant(w[w.length - 1]) && !/[wxy]/i.test(w[w.length - 1]);
|
|
878
871
|
const edForm = (w) => {
|
|
879
|
-
|
|
880
|
-
if (/[^aeiou]y$/i.test(w)) return w.replace(/y$/i, 'ied');
|
|
881
|
-
// Do not double the final consonant for words ending in "er" (e.g., gather -> gathered)
|
|
882
|
-
const lastCh = w[w.length - 1];
|
|
883
|
-
if (endsWithCVC(w) && !/(?:er|en)$/i.test(w)) return w + lastCh + 'ed';
|
|
884
|
-
return w + 'ed';
|
|
872
|
+
return new Inflectors(w).toPast()
|
|
885
873
|
};
|
|
886
874
|
const ingForm = (w) => {
|
|
887
|
-
|
|
888
|
-
if (/ee$/i.test(w)) return w + 'ing';
|
|
889
|
-
if (/e$/i.test(w)) return w.replace(/e$/i, 'ing');
|
|
890
|
-
const lastCh = w[w.length - 1];
|
|
891
|
-
if (endsWithCVC(w) && !/(?:er|en)$/i.test(w)) return w + lastCh + 'ing';
|
|
892
|
-
return w + 'ing';
|
|
875
|
+
return new Inflectors(w).toGerund()
|
|
893
876
|
};
|
|
877
|
+
const singularForm = (w) => {
|
|
878
|
+
return new Inflectors(w).toSingular();
|
|
879
|
+
}
|
|
894
880
|
|
|
895
881
|
const allowNoVariant = (base, match) => {
|
|
896
882
|
const b = String(base || '');
|
|
@@ -904,6 +890,7 @@ export async function generateTwlByBook(bookCode, options = {}) {
|
|
|
904
890
|
head + pluralizeWord(last),
|
|
905
891
|
head + edForm(last),
|
|
906
892
|
head + ingForm(last),
|
|
893
|
+
head + singularForm(last),
|
|
907
894
|
].map(x => x.toLowerCase()));
|
|
908
895
|
return allowed.has(m.toLowerCase());
|
|
909
896
|
};
|