Просмотр исходного кода

fix-chinese-hook-ledger-matching

Ma 6 месяцев назад
Родитель
Сommit
a876bad2b1

+ 10 - 0
packages/core/src/__tests__/hook-ledger-validator.test.ts

@@ -181,4 +181,14 @@ resolve:
     const violations = validateHookLedger(memo, draft);
     expect(violations).toEqual([]);
   });
+
+  it("accepts middle keywords from a longer Chinese hook name", () => {
+    const memo = `## 本章 hook 账
+advance:
+- H007 "被定位的安全威胁" → evoked → pressured
+`;
+    const draft = "旧手机弹出定位结果,林知夏发现店外有人盯梢,安全空间塌了。";
+    const violations = validateHookLedger(memo, draft);
+    expect(violations).toEqual([]);
+  });
 });

+ 7 - 2
packages/core/src/utils/hook-ledger-validator.ts

@@ -171,9 +171,14 @@ function extractKeywords(descriptor: string): ReadonlyArray<string> {
   const cjkTokens: string[] = [];
   for (const run of cjkRuns) {
     cjkTokens.push(run);
+    if (run.length >= 3) {
+      for (let index = 0; index <= run.length - 2; index++) {
+        cjkTokens.push(run.slice(index, index + 2));
+      }
+    }
     if (run.length >= 4) {
-      cjkTokens.push(run.slice(0, 2));
-      cjkTokens.push(run.slice(-2));
+      cjkTokens.push(run.slice(0, 3));
+      cjkTokens.push(run.slice(-3));
     }
   }
   const ascii = (source.match(/[A-Za-z]{3,}/g) ?? []).map((w) => w.toLowerCase());