Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion text/packages/chaff/src/detectors/acronym-gloss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ import { numberedSeries } from "./acronym-series.ts";
*/
const DASH_GLOSS = /(?<![\p{L}\p{N}_&])(?<acronym>[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]?(?<acronym>[A-Z][A-Z0-9&]{1,9})(?![A-Za-z])/gu;

export const glossedAcronyms = (source: string): ReadonlySet<string> =>
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;
Expand Down
15 changes: 15 additions & 0 deletions text/test/test_acronym_titles_glosses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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]));
});
Expand All @@ -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))], []));
});
Expand Down Expand Up @@ -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"]);
});
Expand Down
Loading