|
|
@@ -67,6 +67,35 @@ import os from 'os';
|
|
67
|
67
|
* @property {Function} cleanWord - 清理单词中的非字母字符
|
|
68
|
68
|
* @property {Function} extractEnglishWords - 从文本中提取英语单词
|
|
69
|
69
|
*/
|
|
|
70
|
+// 不规则动词映射
|
|
|
71
|
+const irregularVerbs = {
|
|
|
72
|
+ 'go': ['went', 'gone', 'going', 'goes'],
|
|
|
73
|
+ 'be': ['am', 'is', 'are', 'was', 'were', 'been', 'being'],
|
|
|
74
|
+ 'do': ['did', 'done', 'doing', 'does'],
|
|
|
75
|
+ 'have': ['has', 'had', 'having'],
|
|
|
76
|
+ 'say': ['said', 'saying', 'says'],
|
|
|
77
|
+ 'make': ['made', 'making', 'makes'],
|
|
|
78
|
+ 'get': ['got', 'gotten', 'getting', 'gets'],
|
|
|
79
|
+ 'know': ['knew', 'known', 'knowing', 'knows'],
|
|
|
80
|
+ 'take': ['took', 'taken', 'taking', 'takes'],
|
|
|
81
|
+ 'see': ['saw', 'seen', 'seeing', 'sees'],
|
|
|
82
|
+ 'come': ['came', 'coming', 'comes'],
|
|
|
83
|
+ 'think': ['thought', 'thinking', 'thinks'],
|
|
|
84
|
+ 'look': ['looked', 'looking', 'looks'],
|
|
|
85
|
+ 'want': ['wanted', 'wanting', 'wants'],
|
|
|
86
|
+ 'give': ['gave', 'given', 'giving', 'gives'],
|
|
|
87
|
+ 'use': ['used', 'using', 'uses'],
|
|
|
88
|
+ 'find': ['found', 'finding', 'finds'],
|
|
|
89
|
+ 'tell': ['told', 'telling', 'tells'],
|
|
|
90
|
+ 'ask': ['asked', 'asking', 'asks'],
|
|
|
91
|
+ 'work': ['worked', 'working', 'works'],
|
|
|
92
|
+ 'seem': ['seemed', 'seeming', 'seems'],
|
|
|
93
|
+ 'feel': ['felt', 'feeling', 'feels'],
|
|
|
94
|
+ 'try': ['tried', 'trying', 'tries'],
|
|
|
95
|
+ 'leave': ['left', 'leaving', 'leaves'],
|
|
|
96
|
+ 'call': ['called', 'calling', 'calls']
|
|
|
97
|
+};
|
|
|
98
|
+
|
|
70
|
99
|
export const stringUtils = {
|
|
71
|
100
|
//给字符串左侧补零
|
|
72
|
101
|
AddZero: (str, length) => {
|
|
|
@@ -725,4 +754,95 @@ export const stringUtils = {
|
|
725
|
754
|
//console.groupEnd();
|
|
726
|
755
|
return result;
|
|
727
|
756
|
},
|
|
|
757
|
+
|
|
|
758
|
+ /**
|
|
|
759
|
+ * 获取单词的原形(基本形式)
|
|
|
760
|
+ * @param {string} word - 要转换的单词
|
|
|
761
|
+ * @returns {string[]} - 可能的原形单词数组
|
|
|
762
|
+ */
|
|
|
763
|
+ getWordBaseForm: (word) => {
|
|
|
764
|
+ const lowerWord = word.toLowerCase();
|
|
|
765
|
+ const possibleBaseWords = [];
|
|
|
766
|
+
|
|
|
767
|
+ // 检查是否是不规则动词的变形
|
|
|
768
|
+ for (const [base, forms] of Object.entries(irregularVerbs)) {
|
|
|
769
|
+ if (forms.includes(lowerWord)) {
|
|
|
770
|
+ possibleBaseWords.push(base);
|
|
|
771
|
+ return possibleBaseWords; // 不规则动词直接返回原形
|
|
|
772
|
+ }
|
|
|
773
|
+ }
|
|
|
774
|
+
|
|
|
775
|
+ // 处理规则变形
|
|
|
776
|
+
|
|
|
777
|
+ // 处理过去式/过去分词 (-ed)
|
|
|
778
|
+ if (lowerWord.endsWith('ed')) {
|
|
|
779
|
+ possibleBaseWords.push(lowerWord.slice(0, -2)); // 常规情况 (walked -> walk)
|
|
|
780
|
+ }
|
|
|
781
|
+
|
|
|
782
|
+ // 处理以e结尾的动词加d的情况
|
|
|
783
|
+ if (lowerWord.endsWith('d') && !lowerWord.endsWith('ed')) {
|
|
|
784
|
+ possibleBaseWords.push(lowerWord.slice(0, -1)); // 如 used -> use
|
|
|
785
|
+ }
|
|
|
786
|
+
|
|
|
787
|
+ // 处理以辅音+y结尾变为ied的情况
|
|
|
788
|
+ if (lowerWord.endsWith('ied')) {
|
|
|
789
|
+ possibleBaseWords.push(lowerWord.slice(0, -3) + 'y'); // 如 tried -> try
|
|
|
790
|
+ }
|
|
|
791
|
+
|
|
|
792
|
+ // 处理现在分词 (-ing)
|
|
|
793
|
+ if (lowerWord.endsWith('ing')) {
|
|
|
794
|
+ possibleBaseWords.push(lowerWord.slice(0, -3)); // 常规情况 (walking -> walk)
|
|
|
795
|
+ possibleBaseWords.push(lowerWord.slice(0, -3) + 'e'); // 以e结尾的动词 (making -> make)
|
|
|
796
|
+ }
|
|
|
797
|
+
|
|
|
798
|
+ // 处理比较级/最高级
|
|
|
799
|
+ if (lowerWord.endsWith('er')) {
|
|
|
800
|
+ possibleBaseWords.push(lowerWord.slice(0, -2)); // 常规情况 (faster -> fast)
|
|
|
801
|
+ }
|
|
|
802
|
+ if (lowerWord.endsWith('est')) {
|
|
|
803
|
+ possibleBaseWords.push(lowerWord.slice(0, -3)); // 常规情况 (fastest -> fast)
|
|
|
804
|
+ }
|
|
|
805
|
+
|
|
|
806
|
+ // 处理以辅音+y结尾变为ier/iest的情况
|
|
|
807
|
+ if (lowerWord.endsWith('ier')) {
|
|
|
808
|
+ possibleBaseWords.push(lowerWord.slice(0, -3) + 'y'); // 如 happier -> happy
|
|
|
809
|
+ }
|
|
|
810
|
+ if (lowerWord.endsWith('iest')) {
|
|
|
811
|
+ possibleBaseWords.push(lowerWord.slice(0, -4) + 'y'); // 如 happiest -> happy
|
|
|
812
|
+ }
|
|
|
813
|
+
|
|
|
814
|
+ // 处理副词 (-ly)
|
|
|
815
|
+ if (lowerWord.endsWith('ly')) {
|
|
|
816
|
+ possibleBaseWords.push(lowerWord.slice(0, -2)); // 常规情况 (quickly -> quick)
|
|
|
817
|
+ }
|
|
|
818
|
+
|
|
|
819
|
+ // 处理以y结尾变为ily的情况
|
|
|
820
|
+ if (lowerWord.endsWith('ily')) {
|
|
|
821
|
+ possibleBaseWords.push(lowerWord.slice(0, -3) + 'y'); // 如 happily -> happy
|
|
|
822
|
+ }
|
|
|
823
|
+
|
|
|
824
|
+ // 处理复数形式
|
|
|
825
|
+ if (lowerWord.endsWith('s') && !lowerWord.endsWith('ss')) {
|
|
|
826
|
+ possibleBaseWords.push(lowerWord.slice(0, -1)); // 常规情况 (books -> book)
|
|
|
827
|
+ }
|
|
|
828
|
+ if (lowerWord.endsWith('es')) {
|
|
|
829
|
+ possibleBaseWords.push(lowerWord.slice(0, -2)); // 常规情况 (boxes -> box)
|
|
|
830
|
+ }
|
|
|
831
|
+
|
|
|
832
|
+ // 处理以y结尾变为ies的情况
|
|
|
833
|
+ if (lowerWord.endsWith('ies')) {
|
|
|
834
|
+ possibleBaseWords.push(lowerWord.slice(0, -3) + 'y'); // 如 cities -> city
|
|
|
835
|
+ }
|
|
|
836
|
+
|
|
|
837
|
+ // 处理以fe结尾变为ves的情况
|
|
|
838
|
+ if (lowerWord.endsWith('ves')) {
|
|
|
839
|
+ possibleBaseWords.push(lowerWord.slice(0, -3) + 'fe'); // 如 knives -> knife
|
|
|
840
|
+ possibleBaseWords.push(lowerWord.slice(0, -3) + 'f'); // 如 leaves -> leaf
|
|
|
841
|
+ }
|
|
|
842
|
+
|
|
|
843
|
+ // 去重并过滤掉过短的单词
|
|
|
844
|
+ const uniqueBaseWords = [...new Set(possibleBaseWords)].filter(w => w.length >= 2);
|
|
|
845
|
+
|
|
|
846
|
+ return uniqueBaseWords;
|
|
|
847
|
+ },
|
|
728
|
848
|
}
|