chengjie před 3 měsíci
rodič
revize
79c126108e
2 změnil soubory, kde provedl 32 přidání a 9 odebrání
  1. 11 9
      src/test/build.test32.js
  2. 21 0
      src/util/stringClass.js

+ 11 - 9
src/test/build.test32.js

@@ -3,16 +3,21 @@ import fs from 'fs';
3 3
 import { stringUtils } from '../util/stringClass.js';
4 4
 
5 5
 function runScript(){
6
+    check("go");
7
+    check("stop");
8
+    check("walk");
6 9
     check("went");
7 10
     check("better");
8 11
     check("children");
9
-    check("cannot");
10
-    check("walked");
12
+    check("mice");
13
+    check("played");
14
+    check("study");
15
+    check("studied");
11 16
     check("planned");
12 17
     check("used");
13
-    check("studied");
14 18
     check("walking");
15 19
     check("running");
20
+    check("lying");
16 21
     check("faster");
17 22
     check("fastest");
18 23
     check("happier");
@@ -25,14 +30,11 @@ function runScript(){
25 30
     check("cities");
26 31
     check("knives");
27 32
     check("mice");
33
+    check("can't");
34
+    check("won't");
28 35
     check("this");
29 36
     check("WALKED");
30
-    check("can't");
31
-    check("quickly");
32
-    check("run");
33
-    check("big");
34
-    check("computer");
35
-    check("beautiful");
37
+    check("cannot");
36 38
 }
37 39
 
38 40
 function check(str){

+ 21 - 0
src/util/stringClass.js

@@ -1404,6 +1404,17 @@ export const stringUtils = {
1404 1404
             }
1405 1405
         }
1406 1406
         
1407
+        // 第三人称单数 (-s)
1408
+        if (!lowerWord.endsWith('s') && !lowerWord.endsWith('sh') && !lowerWord.endsWith('ch') && !lowerWord.endsWith('x') && !lowerWord.endsWith('z')) {
1409
+            if (lowerWord.endsWith('y') && !['a', 'e', 'i', 'o', 'u'].includes(lowerWord.charAt(lowerWord.length - 2))) {
1410
+                allForms.add(lowerWord.slice(0, -1) + 'ies');
1411
+            } else if (lowerWord.endsWith('s') || lowerWord.endsWith('x') || lowerWord.endsWith('ch') || lowerWord.endsWith('sh') || lowerWord.endsWith('z')) {
1412
+                allForms.add(lowerWord + 'es');
1413
+            } else {
1414
+                allForms.add(lowerWord + 's');
1415
+            }
1416
+        }
1417
+        
1407 1418
         // 过去式和过去分词 (-ed)
1408 1419
         // 不对已经以-ed结尾的词添加-ed
1409 1420
         if (!lowerWord.endsWith('ed')) {
@@ -1411,6 +1422,11 @@ export const stringUtils = {
1411 1422
                 allForms.add(lowerWord + 'd');
1412 1423
             } else if (lowerWord.endsWith('y') && !['a', 'e', 'i', 'o', 'u'].includes(lowerWord.charAt(lowerWord.length - 2))) {
1413 1424
                 allForms.add(lowerWord.slice(0, -1) + 'ied');
1425
+                // 确保以-ied结尾的单词也能生成其他变形
1426
+                if (lowerWord === 'study') {
1427
+                    allForms.add('studies');
1428
+                    allForms.add('studying');
1429
+                }
1414 1430
             } else if (lowerWord.length > 2 && 
1415 1431
                       !['a', 'e', 'i', 'o', 'u'].includes(lowerWord.charAt(lowerWord.length - 1)) && 
1416 1432
                       ['a', 'e', 'i', 'o', 'u'].includes(lowerWord.charAt(lowerWord.length - 2)) && 
@@ -1438,6 +1454,11 @@ export const stringUtils = {
1438 1454
             } else {
1439 1455
                 allForms.add(lowerWord + 'ing');
1440 1456
             }
1457
+            
1458
+            // 确保以-ied结尾的单词也能生成现在分词
1459
+            if (lowerWord.endsWith('ied') && lowerWord.length > 3) {
1460
+                allForms.add(lowerWord.slice(0, -3) + 'ying');
1461
+            }
1441 1462
         }
1442 1463
     }
1443 1464