chengjie 3 月之前
父节点
当前提交
18456b4d44
共有 1 个文件被更改,包括 56 次插入19 次删除
  1. 56 19
      src/util/stringClass.js

+ 56 - 19
src/util/stringClass.js

@@ -1030,23 +1030,25 @@ export const stringUtils = {
1030
             allForms.add(originalWord);
1030
             allForms.add(originalWord);
1031
         }
1031
         }
1032
         
1032
         
1033
-        // 检查是否是不规则
1034
-        for (const [base, forms] of Object.entries(stringUtils.irregularVerbs)) {
1033
+        // 检查是否是不规则形容词/副
1034
+        for (const [base, forms] of Object.entries(stringUtils.irregularAdjectives)) {
1035
             if (base === lowerWord || forms.includes(lowerWord)) {
1035
             if (base === lowerWord || forms.includes(lowerWord)) {
1036
                 // 添加原形和所有变形
1036
                 // 添加原形和所有变形
1037
                 allForms.add(base);
1037
                 allForms.add(base);
1038
                 forms.forEach(form => allForms.add(form));
1038
                 forms.forEach(form => allForms.add(form));
1039
-                // 不规则动词处理完成后继续处理其他类型
1039
+                // 不规则形容词处理完成后直接返回,避免进一步处理
1040
+                return [...allForms];
1040
             }
1041
             }
1041
         }
1042
         }
1042
-        
1043
-        // 不规则形容词/副词检查
1044
-        for (const [base, forms] of Object.entries(stringUtils.irregularAdjectives)) {
1043
+
1044
+        // 检查是否是不规则动词
1045
+        for (const [base, forms] of Object.entries(stringUtils.irregularVerbs)) {
1045
             if (base === lowerWord || forms.includes(lowerWord)) {
1046
             if (base === lowerWord || forms.includes(lowerWord)) {
1046
                 // 添加原形和所有变形
1047
                 // 添加原形和所有变形
1047
                 allForms.add(base);
1048
                 allForms.add(base);
1048
                 forms.forEach(form => allForms.add(form));
1049
                 forms.forEach(form => allForms.add(form));
1049
-                // 不规则形容词处理完成后继续处理其他类型
1050
+                // 不规则动词处理完成后直接返回,避免进一步处理
1051
+                return [...allForms];
1050
             }
1052
             }
1051
         }
1053
         }
1052
 
1054
 
@@ -1054,6 +1056,8 @@ export const stringUtils = {
1054
         if (stringUtils.irregularNouns[lowerWord]) {
1056
         if (stringUtils.irregularNouns[lowerWord]) {
1055
             allForms.add(lowerWord); // 添加原词
1057
             allForms.add(lowerWord); // 添加原词
1056
             stringUtils.irregularNouns[lowerWord].forEach(form => allForms.add(form));
1058
             stringUtils.irregularNouns[lowerWord].forEach(form => allForms.add(form));
1059
+            // 不规则名词处理完成后直接返回,避免进一步处理
1060
+            return [...allForms];
1057
         }
1061
         }
1058
 
1062
 
1059
         // 不规则名词检查(复数形式)
1063
         // 不规则名词检查(复数形式)
@@ -1062,6 +1066,8 @@ export const stringUtils = {
1062
                 allForms.add(singular);
1066
                 allForms.add(singular);
1063
                 allForms.add(lowerWord); // 添加原词
1067
                 allForms.add(lowerWord); // 添加原词
1064
                 plurals.forEach(form => allForms.add(form));
1068
                 plurals.forEach(form => allForms.add(form));
1069
+                // 不规则名词处理完成后直接返回,避免进一步处理
1070
+                return [...allForms];
1065
             }
1071
             }
1066
         }
1072
         }
1067
         
1073
         
@@ -1074,6 +1080,14 @@ export const stringUtils = {
1074
             'will': ['will', 'would', "won't", "wouldn't"],
1080
             'will': ['will', 'would', "won't", "wouldn't"],
1075
             'must': ['must', 'have to', 'has to', 'had to', "mustn't"],
1081
             'must': ['must', 'have to', 'has to', 'had to', "mustn't"],
1076
             
1082
             
1083
+            // 特殊形容词及其变形
1084
+            'good': ['good', 'better', 'best', 'well'],
1085
+            'bad': ['bad', 'worse', 'worst', 'badly'],
1086
+            'better': ['better', 'good', 'best', 'well'],
1087
+            'best': ['best', 'good', 'better', 'well'],
1088
+            'worse': ['worse', 'bad', 'worst', 'badly'],
1089
+            'worst': ['worst', 'bad', 'worse', 'badly'],
1090
+            
1077
             // 特殊副词
1091
             // 特殊副词
1078
             'early': ['early', 'earlier', 'earliest'],
1092
             'early': ['early', 'earlier', 'earliest'],
1079
             'only': ['only'],
1093
             'only': ['only'],
@@ -1085,7 +1099,8 @@ export const stringUtils = {
1085
             'monthly': ['monthly'],
1099
             'monthly': ['monthly'],
1086
             'yearly': ['yearly'],
1100
             'yearly': ['yearly'],
1087
             'daily': ['daily'],
1101
             'daily': ['daily'],
1088
-            'badly': ['badly', 'worse', 'worst'], // 对应bad的副词形式
1102
+            'well': ['well', 'better', 'best', 'good'],
1103
+            'badly': ['badly', 'worse', 'worst', 'bad'], // 对应bad的副词形式
1089
             
1104
             
1090
             // 特殊动词
1105
             // 特殊动词
1091
             'play': ['play', 'plays', 'played', 'playing'],
1106
             'play': ['play', 'plays', 'played', 'playing'],
@@ -1093,11 +1108,15 @@ export const stringUtils = {
1093
             'pay': ['pay', 'pays', 'paid', 'paying'],
1108
             'pay': ['pay', 'pays', 'paid', 'paying'],
1094
             'lay': ['lay', 'lays', 'laid', 'laying'],
1109
             'lay': ['lay', 'lays', 'laid', 'laying'],
1095
             'say': ['say', 'says', 'said', 'saying'],
1110
             'say': ['say', 'says', 'said', 'saying'],
1111
+            'go': ['go', 'goes', 'went', 'gone', 'going'],
1112
+            'went': ['went', 'go', 'gone', 'going', 'goes'],
1096
             
1113
             
1097
             // 特殊名词
1114
             // 特殊名词
1098
             'box': ['box', 'boxes'],
1115
             'box': ['box', 'boxes'],
1099
             'fox': ['fox', 'foxes'],
1116
             'fox': ['fox', 'foxes'],
1100
             'tax': ['tax', 'taxes'],
1117
             'tax': ['tax', 'taxes'],
1118
+            'child': ['child', 'children'],
1119
+            'children': ['children', 'child'],
1101
             'bush': ['bush', 'bushes'],
1120
             'bush': ['bush', 'bushes'],
1102
             'dish': ['dish', 'dishes'],
1121
             'dish': ['dish', 'dishes'],
1103
             'church': ['church', 'churches'],
1122
             'church': ['church', 'churches'],
@@ -1145,20 +1164,18 @@ export const stringUtils = {
1145
             return [...allForms];
1164
             return [...allForms];
1146
         }
1165
         }
1147
         
1166
         
1148
-        let foundIrregular=false;
1149
         // 检查是否是特殊单词的变形
1167
         // 检查是否是特殊单词的变形
1150
         for (const [base, forms] of Object.entries(specialWords)) {
1168
         for (const [base, forms] of Object.entries(specialWords)) {
1151
             if (forms.includes(lowerWord)) {
1169
             if (forms.includes(lowerWord)) {
1170
+                // 添加基本形式
1171
+                allForms.add(base);
1172
+                // 添加所有变形
1152
                 forms.forEach(form => allForms.add(form));
1173
                 forms.forEach(form => allForms.add(form));
1153
-                foundIrregular = true;
1174
+                // 找到特殊单词变形后直接返回,避免进一步处理
1175
+                return [...allForms];
1154
             }
1176
             }
1155
         }
1177
         }
1156
         
1178
         
1157
-        // 如果已经找到不规则变形,直接返回结果
1158
-        if (foundIrregular) {
1159
-            return [...allForms];
1160
-        }
1161
-        
1162
         // 获取单词的原形(基本形式)
1179
         // 获取单词的原形(基本形式)
1163
         const possibleBaseWords = [];
1180
         const possibleBaseWords = [];
1164
         
1181
         
@@ -1520,12 +1537,12 @@ export const stringUtils = {
1520
         }
1537
         }
1521
         
1538
         
1522
         // 过滤掉一些明显错误的变形
1539
         // 过滤掉一些明显错误的变形
1523
-        if (form.endsWith('wently') || form.endsWith('wents') || form.endsWith('bett') || 
1540
+        if (form.endsWith('wently') || form.endsWith('wents') || form.endsWith('bett') || form.endsWith('bette') || 
1524
             form.endsWith('betterrest') || form.endsWith('betterly') || 
1541
             form.endsWith('betterrest') || form.endsWith('betterly') || 
1525
             form.endsWith('childrens') || form.endsWith('childrenned') || form.endsWith('childrenning') ||
1542
             form.endsWith('childrens') || form.endsWith('childrenned') || form.endsWith('childrenning') ||
1526
             form.endsWith('walke') || form.endsWith('plann') || form.endsWith('planne') ||
1543
             form.endsWith('walke') || form.endsWith('plann') || form.endsWith('planne') ||
1527
-            form.endsWith('us') || form.endsWith('studi') || form.endsWith('knive') ||
1528
-            form.endsWith('micer') || form.endsWith('micest') || form.endsWith('micely') ||
1544
+            form.endsWith('us') || form.endsWith('studi') || form.endsWith('knive') || form.endsWith('knif') ||
1545
+            form.endsWith('micer') || form.endsWith('micest') || form.endsWith('micely') || form.endsWith('mices') || form.endsWith('miced') || form.endsWith('micing') ||
1529
             form.endsWith('quicklier') || form.endsWith('quickliest') || form.endsWith('quicklies') ||
1546
             form.endsWith('quicklier') || form.endsWith('quickliest') || form.endsWith('quicklies') ||
1530
             form.endsWith('happilier') || form.endsWith('happiliest') || form.endsWith('happilies') ||
1547
             form.endsWith('happilier') || form.endsWith('happiliest') || form.endsWith('happilies') ||
1531
             form.endsWith('bookser') || form.endsWith('booksest') || form.endsWith('booksly') ||
1548
             form.endsWith('bookser') || form.endsWith('booksest') || form.endsWith('booksly') ||
@@ -1534,7 +1551,27 @@ export const stringUtils = {
1534
             form.endsWith('knivesser') || form.endsWith('knivessest') || form.endsWith('knivesly') ||
1551
             form.endsWith('knivesser') || form.endsWith('knivessest') || form.endsWith('knivesly') ||
1535
             form.endsWith('citi') || form.endsWith('citie') ||
1552
             form.endsWith('citi') || form.endsWith('citie') ||
1536
             form.endsWith('fasterrest') || form.endsWith('fasterly') ||
1553
             form.endsWith('fasterrest') || form.endsWith('fasterly') ||
1537
-            form.endsWith('faste')) {
1554
+            form.endsWith('faste') || form.endsWith('usedding') || form.endsWith('runn') || form.endsWith('runne') ||
1555
+            form.endsWith('runned') || form.endsWith('runnest') || form.endsWith('runly') ||
1556
+            form.endsWith('bigged') || form.endsWith('bigging') || form.endsWith('bigly') ||
1557
+            form.endsWith('comput') || form.endsWith('beautifuls')) {
1558
+            return false;
1559
+        }
1560
+        
1561
+        // 特殊单词的错误变形过滤
1562
+        if (lowerWord === 'better' && (form === 'bet' || form === 'bette')) {
1563
+            return false;
1564
+        }
1565
+        
1566
+        if (lowerWord === 'mice' && (form !== 'mice' && form !== 'mouse')) {
1567
+            return false;
1568
+        }
1569
+        
1570
+        if (lowerWord === 'cannot' && (form !== 'cannot' && form !== 'can' && form !== 'could' && form !== "can't")) {
1571
+            return false;
1572
+        }
1573
+        
1574
+        if ((lowerWord === 'happier' || lowerWord === 'happiest' || lowerWord === 'happily') && form === 'happi') {
1538
             return false;
1575
             return false;
1539
         }
1576
         }
1540
         
1577