From 321bb33f1677f251ea440bec1127eba284ca668e Mon Sep 17 00:00:00 2001 From: isamu Date: Mon, 30 Nov 2026 10:08:02 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20undefined-acronym=20reads=20a=20noun=20a?= =?UTF-8?q?nd=20=E3=81=A7=E3=81=82=E3=82=8B=20right=20before=20an=20acrony?= =?UTF-8?q?m=20as=20its=20gloss?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .../packages/chaff/src/detectors/acronym-gloss.ts | 8 +++++++- text/test/test_acronym_titles_glosses.ts | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/text/packages/chaff/src/detectors/acronym-gloss.ts b/text/packages/chaff/src/detectors/acronym-gloss.ts index b0b70472f..57cc32e32 100644 --- a/text/packages/chaff/src/detectors/acronym-gloss.ts +++ b/text/packages/chaff/src/detectors/acronym-gloss.ts @@ -8,8 +8,14 @@ import { numberedSeries } from "./acronym-series.ts"; */ const DASH_GLOSS = /(?[A-Z][A-Z0-9&]{1,9})\s?[—–]\s?(?:an?|the)\s[^—–\n]{3,160}?[—–]/gu; +/** + * 「デザイン部門であるKOEL」「安全規格であるISO」: a noun in kanji or katakana and である right before the acronym say what + * it is, as the dash apposition does in English. After kana (〜のであるNTT) である closes a clause, not a noun. + */ +const DEARU_GLOSS = /(?<=[\p{Script=Han}\p{Script=Katakana}ー])である[ \t]?(?[A-Z][A-Z0-9&]{1,9})(?![A-Za-z])/gu; + export const glossedAcronyms = (source: string): ReadonlySet => - new Set([...source.matchAll(DASH_GLOSS)].flatMap((match) => match.groups?.["acronym"] ?? [])); + new Set([...source.matchAll(DASH_GLOSS), ...source.matchAll(DEARU_GLOSS)].flatMap((match) => match.groups?.["acronym"] ?? [])); /** Two letters are spelled by chance too often ("Data Protection" is not always DP). */ const MIN_SPELLED = 3; diff --git a/text/test/test_acronym_titles_glosses.ts b/text/test/test_acronym_titles_glosses.ts index c8eba3b05..a6a0ada1f 100644 --- a/text/test/test_acronym_titles_glosses.ts +++ b/text/test/test_acronym_titles_glosses.ts @@ -2,6 +2,7 @@ import { describe, it } from "node:test"; import assert from "node:assert/strict"; import { reportedAcronyms } from "./rule-run.ts"; import { adapter as en } from "../packages/lang-en/src/index.ts"; +import { adapter as ja } from "../packages/lang-ja/src/index.ts"; import { glossedAcronyms, headingsSpellingOut } from "../packages/chaff/src/detectors/acronym-gloss.ts"; // undefined-acronym and four ways a document leaves an acronym explained or not an acronym at all (chaff-corpus #54): @@ -14,6 +15,9 @@ describe("glossedAcronyms", () => { ["The VIX—a forward-looking measure of near-term stock market volatility—declined.", "VIX"], ["The VIX – an index of expected volatility – fell.", "VIX"], ["Our SLA—the service level agreement—applies.", "SLA"], + ["研究所のデザイン部門であるDZLでは、全員と面談します。", "DZL"], + ["安全規格であるISO を取得しました。", "ISO"], + ["メールのプロトコルであるSMTPで送ります。", "SMTP"], ].forEach(([text, acronym]) => { it(`valid: ${String(text)}`, () => assert.deepEqual([...glossedAcronyms(String(text))], [acronym])); }); @@ -24,6 +28,9 @@ describe("glossedAcronyms", () => { ["a dash pair without an article", "The VIX—down sharply—ended lower."], ["the closing dash on another line", "The VIX—a measure of\nvolatility—fell."], ["a lower-case word", "The vix—a measure of volatility—fell."], + ["である after kana closes a clause", "それが課題なのであるDZLの話です。"], + ["である before a word, not an acronym", "部門であるDzlabで話します。"], + ["である with no noun before it", "である DZL の話です。"], ].forEach(([form, text]) => { it(`invalid: ${String(form)}`, () => assert.deepEqual([...glossedAcronyms(String(text))], [])); }); @@ -79,6 +86,14 @@ describe("undefined-acronym: titles, indexes, glosses and headings", () => { assert.deepEqual(reportedAcronyms(en, doc("The VIX—a forward-looking measure of near-term stock market volatility—declined.")), ["SRE"]); }); + it("valid: an acronym after a noun and である (デザイン部門であるDZL)", () => { + assert.deepEqual(reportedAcronyms(ja, "# 報告\n\n研究所のデザイン部門であるDZLでは、全員と面談します。SREも参加します。\n"), ["SRE"]); + }); + + it("invalid: the same acronym with no である before it", () => { + assert.deepEqual(reportedAcronyms(ja, "# 報告\n\n研究所のDZLでは、全員と面談します。SREも参加します。\n"), ["DZL", "SRE"]); + }); + it("valid: an acronym under a heading that spells it out", () => { assert.deepEqual(reportedAcronyms(en, ["## Federal Open Market Committee", "", "FOMC Minutes", "", "The SRE joins the call."].join("\n")), ["SRE"]); });