From 595e4eb8728efb82bf34d359145bdd9334b4c862 Mon Sep 17 00:00:00 2001 From: isamu Date: Mon, 30 Nov 2026 08:13:58 +0900 Subject: [PATCH] fix: latin-spacing does not count a source line with a URL and an access date Co-Authored-By: Claude Opus 5.5 --- text/packages/chaff/rules/latin-spacing.yaml | 6 ++++-- .../chaff/src/detectors/orthography.ts | 3 ++- .../packages/chaff/src/latin-spacing-source.ts | 18 +++++++++++++++++- text/test/test_latin_spacing_source.ts | 11 +++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/text/packages/chaff/rules/latin-spacing.yaml b/text/packages/chaff/rules/latin-spacing.yaml index b1e3bee13..e69694c48 100644 --- a/text/packages/chaff/rules/latin-spacing.yaml +++ b/text/packages/chaff/rules/latin-spacing.yaml @@ -12,6 +12,7 @@ uses: [pos] # 建物の名前の後ろに空白で区切った階・部屋の番号(本社 5階)を見分ける。 # 名前だけを並べた行で、組織の名前と名前のあいだの空白(経営企画部 IR担当)を見分ける。 # 行の頭に図表の札だけを書いた後ろの空白(表 6種類の…)を見分ける。 +# URL と参照日の括弧書き((2024/3/12参照))を書いた出典の行を見分ける。 extra_word_lists: [ prefecture-unit, @@ -27,6 +28,7 @@ extra_word_lists: company-form, licence-word, figure-label, + access-date-label, ] name: @@ -73,8 +75,8 @@ example: 表は Excel で作り、Word に貼ります。図は PowerPoint で描きます。最後に PDF にします。 not_flagged: - ja: 電話番号や日付のような番号、版番号(1.0.0)、予約番号や型番(MN-48215)の前後、単位つきの日付や時刻(9月、10時5分)、AM・PM を付けた時刻(9:30AM)の後ろ、建物の名前の後ろに空白で区切った階や部屋の番号(本社 5階)の前、名前だけを並べた行の名前と名前のあいだ(経営企画部 IR担当)、英字の肩書きと、行の終わりまでの人の名前のあいだ(代表取締役CEO 森川 遼)、6 桁以上の番号やナンバープレートの前後、項目名とコロンの後ろの値の組のあいだ(所属:経済学科 1年)、項目名と値のあいだ(Bronzeプラン 10万円 (税込))、日本語の句をつなぐ英語の語の前後(名前 or メッセージ)、英字の語に付けた接尾の語(PDF版、IT化)の前、チャンネルや宛先の名前(#pj_oss-team、@sato)の後ろ、見出しの番号、行の頭の項目の番号(「一 JIS…」の一、イ)の後ろ、行の頭に図表の札だけを書いた後ろ(表 6種類の…)、名前だけを並べた行の空白を含む組織の名前の前(初等中等教育局 GIGA StuDX(…)推進チーム)、「」と“”の中、文献の記載の行、変換で区切りが消えて一続きになった数の表の数の前後、リンクの文字の中、文書の最後に掲載先が付けた利用条件の断り書き(ライセンスの名前と条件の URL を書いた短い段落)は数えません。どちらの空け方が正しいかは決めません。少ないほうが全体の 2 割を超えるほど多ければ(5 箇所以上)、また二通りが 2 箇所以上ずつの同数なら、1 箇所ずつではなく、書き方が二通りあることを 1 件で言います。1 対 1 の同数は言いません。 - en: Codes such as phone numbers, dates and version numbers (1.0.0), the spaces beside a booking or model number (MN-48215), dates and times with units (9月, 10時5分), the space after a time with AM or PM (9:30AM), the space before a floor or room number after the name of a building (本社 5階), the space between names on a line of names alone (経営企画部 IR担当), the space between a title in letters and the person's name that ends the line (代表取締役CEO 森川 遼), the spaces beside a code of six digits or more or a number plate, the space between the parts of a value after a label and a colon (所属:経済学科 1年), the space between a label and its value (Bronzeプラン 10万円 (税込)), the spaces around an English word joining Japanese phrases (名前 or メッセージ), the boundary before a suffix bound to a Latin word (PDF版, IT化), the boundary after a channel or handle name (#pj_oss-team, @sato), heading numbers, the space after an item number at the head of a line (一 JIS…), the space after a figure or table label alone at the head of a line (表 6種類の…), the space before an organisation's name that holds spaces on a line of names alone (初等中等教育局 GIGA StuDX(…)推進チーム), quotations in 「」 and “”, a line of a bibliographic entry, the spaces beside the numbers of a table of numbers a converter ran together, the text of links and a licence notice the publisher appends at the end (a short closing paragraph that names a licence and links to its terms) are not counted. Neither way is called right. When the less common way is more than a fifth of the places (and at least five), or both ways are used equally at two places or more each, it is reported once, as a document written two ways, rather than place by place. A one-to-one tie is not reported. + ja: 電話番号や日付のような番号、版番号(1.0.0)、予約番号や型番(MN-48215)の前後、単位つきの日付や時刻(9月、10時5分)、AM・PM を付けた時刻(9:30AM)の後ろ、建物の名前の後ろに空白で区切った階や部屋の番号(本社 5階)の前、名前だけを並べた行の名前と名前のあいだ(経営企画部 IR担当)、英字の肩書きと、行の終わりまでの人の名前のあいだ(代表取締役CEO 森川 遼)、6 桁以上の番号やナンバープレートの前後、項目名とコロンの後ろの値の組のあいだ(所属:経済学科 1年)、項目名と値のあいだ(Bronzeプラン 10万円 (税込))、日本語の句をつなぐ英語の語の前後(名前 or メッセージ)、英字の語に付けた接尾の語(PDF版、IT化)の前、チャンネルや宛先の名前(#pj_oss-team、@sato)の後ろ、見出しの番号、行の頭の項目の番号(「一 JIS…」の一、イ)の後ろ、行の頭に図表の札だけを書いた後ろ(表 6種類の…)、名前だけを並べた行の空白を含む組織の名前の前(初等中等教育局 GIGA StuDX(…)推進チーム)、「」と“”の中、文献の記載の行、URL と参照日の括弧書き((2024/3/12参照))を書いた出典の行、変換で区切りが消えて一続きになった数の表の数の前後、リンクの文字の中、文書の最後に掲載先が付けた利用条件の断り書き(ライセンスの名前と条件の URL を書いた短い段落)は数えません。どちらの空け方が正しいかは決めません。少ないほうが全体の 2 割を超えるほど多ければ(5 箇所以上)、また二通りが 2 箇所以上ずつの同数なら、1 箇所ずつではなく、書き方が二通りあることを 1 件で言います。1 対 1 の同数は言いません。 + en: Codes such as phone numbers, dates and version numbers (1.0.0), the spaces beside a booking or model number (MN-48215), dates and times with units (9月, 10時5分), the space after a time with AM or PM (9:30AM), the space before a floor or room number after the name of a building (本社 5階), the space between names on a line of names alone (経営企画部 IR担当), the space between a title in letters and the person's name that ends the line (代表取締役CEO 森川 遼), the spaces beside a code of six digits or more or a number plate, the space between the parts of a value after a label and a colon (所属:経済学科 1年), the space between a label and its value (Bronzeプラン 10万円 (税込)), the spaces around an English word joining Japanese phrases (名前 or メッセージ), the boundary before a suffix bound to a Latin word (PDF版, IT化), the boundary after a channel or handle name (#pj_oss-team, @sato), heading numbers, the space after an item number at the head of a line (一 JIS…), the space after a figure or table label alone at the head of a line (表 6種類の…), the space before an organisation's name that holds spaces on a line of names alone (初等中等教育局 GIGA StuDX(…)推進チーム), quotations in 「」 and “”, a line of a bibliographic entry, a source line that gives a URL and an access date in brackets ((2024/3/12参照)), the spaces beside the numbers of a table of numbers a converter ran together, the text of links and a licence notice the publisher appends at the end (a short closing paragraph that names a licence and links to its terms) are not counted. Neither way is called right. When the less common way is more than a fifth of the places (and at least five), or both ways are used equally at two places or more each, it is reported once, as a document written two ways, rather than place by place. A one-to-one tie is not reported. level_meaning: ja: 少ないほうの空け方が {limit} 箇所あれば指摘 en: reported once {limit} {limit|place goes|places go} against the document's habit diff --git a/text/packages/chaff/src/detectors/orthography.ts b/text/packages/chaff/src/detectors/orthography.ts index 5eb77811f..9cdda79f8 100644 --- a/text/packages/chaff/src/detectors/orthography.ts +++ b/text/packages/chaff/src/detectors/orthography.ts @@ -230,6 +230,7 @@ export const latinSpacing: Detector = (doc, options): Finding[] => { }; // 文書の最後の利用条件の断り書き(クリエイティブ・コモンズ 表示 4.0 国際)は、掲載先の書き方で書き手の空け方ではない。 const licence = licenceNoticeSentences(doc, doc.lexicons["licence-word"] ?? []); + const accessLabels = patternList(doc, "access-date-label"); const located: Located[] = doc.sentences.flatMap((sentence) => { if (licence.has(sentence)) return []; // 「」『』のほか、“”で引いた題名(“パブリック・ドメイン・マーク 1.0 全世界コモンズ証”)も元の書き方。 @@ -243,7 +244,7 @@ export const latinSpacing: Detector = (doc, options): Finding[] => { return ( latinBoundaries(sentence.text, doc.source.slice(sentence.span.start, sentence.span.end)) .filter((boundary) => !isQuoted(quoted, boundary) && !isInsideLink(doc.links, sentence.span.start + boundary.offset)) - .filter((boundary) => !isCitedEntryLine(lineAt(doc.source, sentence.span.start + boundary.offset))) + .filter((boundary) => !isCitedEntryLine(lineAt(doc.source, sentence.span.start + boundary.offset), accessLabels)) // 変換で一続きになった数の表の、升の区切りの空白。 .filter((boundary) => !isNumberTableBoundary(sentence.text, boundary)) .filter((boundary) => isCounted(sentence, boundary, context, codes)) diff --git a/text/packages/chaff/src/latin-spacing-source.ts b/text/packages/chaff/src/latin-spacing-source.ts index 2519d1540..2b59e7304 100644 --- a/text/packages/chaff/src/latin-spacing-source.ts +++ b/text/packages/chaff/src/latin-spacing-source.ts @@ -11,7 +11,23 @@ import { hasGluedNumbers } from "./detectors/sentence-parts.ts"; const ENTRY_AUTHOR = /^[ \t]*[^.。.\n]{1,60}\.\s/u; const ENTRY_YEAR = /\.\s(?:1[89]|20)\d{2}[,,]/u; -export const isCitedEntryLine = (line: string): boolean => ENTRY_AUTHOR.test(line) && ENTRY_YEAR.test(line); +const URL_MARK = /https?:\/\//u; +/** 括弧書き((2024/3/12参照)、(閲覧日 2024年3月12日))の中身。 */ +const ASIDES = /[((]([^()()]*)[))]/gu; +const NUMERAL = /\d/u; + +/** 出典の後ろの参照日の括弧書き: 中身が参照日の語(語彙表 access-date-label)で始まるか終わる。 */ +const hasAccessDate = (line: string, accessLabels: readonly string[]): boolean => + [...line.matchAll(ASIDES)].some( + ([, inside = ""]) => NUMERAL.test(inside) && accessLabels.some((label) => inside.trim().startsWith(label) || inside.trim().endsWith(label)), + ); + +/** + * 文献の記載の行: SIST の書き方か、URL と参照日の括弧書きを書いた出典の行(注の「内閣府 ○○会議「題」,(2024/3/12参照)」)。 + * 出典の行の空白は発行元と会議の名前の区切りのような記載の区切りで、文の中の空け方ではない。 + */ +export const isCitedEntryLine = (line: string, accessLabels: readonly string[] = []): boolean => + (ENTRY_AUTHOR.test(line) && ENTRY_YEAR.test(line)) || (URL_MARK.test(line) && hasAccessDate(line, accessLabels)); /** at を含む行。 */ export const lineAt = (text: string, at: number): string => { diff --git a/text/test/test_latin_spacing_source.ts b/text/test/test_latin_spacing_source.ts index 889ef2b78..b998dae1f 100644 --- a/text/test/test_latin_spacing_source.ts +++ b/text/test/test_latin_spacing_source.ts @@ -80,6 +80,17 @@ describe("文献の記載の行", () => { assert.deepEqual(spacing(withBody("図書館の夢を見るか LRG編を読みました。")), ["英字:空けています"]); }); + it("URL と参照日の括弧書き((2024/3/12参照))を書いた行も、出典の記載と読む", () => { + const labels = ["参照", "閲覧"]; + const footnote = "12 架空県 DX推進会議「地域の計画」,(2024/3/12参照)"; + assert.equal(isCitedEntryLine(footnote, labels), true); + assert.equal(isCitedEntryLine("架空県 DX推進会議の資料は https://example.com/plan.pdf にあります(閲覧日 2024年3月12日)", labels), true); + assert.equal(isCitedEntryLine("架空県 DX推進会議の資料は https://example.com/plan.pdf にあります。", labels), false); + assert.equal(isCitedEntryLine("架空県 DX推進会議の資料を参照してください(2024/3/12参照)", labels), false); + assert.equal(isCitedEntryLine(footnote), false); + assert.deepEqual(spacing(withBody(footnote)), []); + }); + it("lineAt は位置を含む行", () => { assert.equal(lineAt("一\n二三\n四", 3), "二三"); assert.equal(lineAt("一\n二三\n四", 0), "一");