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
2 changes: 1 addition & 1 deletion text/corpus/expected/max-sentence-length.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ kantei-221-shisei-hoshin 8
kantei-unga81-general-debate-speech 4
kantei-unga81-general-debate-speech-en 49
kep-2214-indexed-job 1
loc-signal-new-online-2026-07 5
loc-signal-new-online-2026-07 4
maff-kyodo-ryori-okaisan-en 1
mdn-using-fetch-en 1
meti-keiryoshi-exam-correction 1
Expand Down
2 changes: 1 addition & 1 deletion text/corpus/expected/orthographic-variant.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ qiita-jnchito-good-sample-code 1
react-ja-thinking 3
rfc3693-geopriv-requirements 2
ruby-3-4-0-released-ja 2
saitama-shokuiku-soboro-oyakodon 4
saitama-shokuiku-soboro-oyakodon 3
soumu-kokumin-cyber-glossary-a 2
soumu-wp-r06-misinformation 1
sre-next-bunsho-kanri 1
Expand Down
6 changes: 3 additions & 3 deletions text/corpus/expected/undefined-acronym.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ irs-online-account-faq 3
kep-2214-indexed-job 5
kimino-opendata-site 2
koenote-requirements 6
mhlw-icd-committee-26-minutes 3
mhlw-icd-committee-26-minutes 2
mhlw-kokuji-h18-107-keiji-jiko 4
mhlw-norovirus-qa 5
nasa-advisory-crew-13-coverage 5
neeview-changelog-ja 16
noaa-press-flood-mapping 3
nodejs-tsc-minutes-2026-05-06 5
nttcom-onboarding-week1 3
nodejs-tsc-minutes-2026-05-06 4
nttcom-onboarding-week1 2
nws-glossary-a 9
rfc3693-geopriv-requirements 12
rfc9293-tcp 26
Expand Down
4 changes: 2 additions & 2 deletions text/packages/chaff/rules/max-sentence-length.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ example:

not_flagged:
ja: >-
見出し、表のセル、コードは数えません。メールの件名の欄の値(「件名:」「SUBJECT:」の行や、その下の行に書いた件名)も、文ではないので数えません(件名の長さは email-subject-length が見ます)。句点の無い、名前や肩書きを「、」で並べただけの行(出席者の一覧)も数えません。印刷版を文字にした文書が文の途中に残すページの印(「( printed page 52044)」「- 12 -」)も数えません。注の頭の札と番号(「(注)1.」「※3:」)も数えません。脚注の文献の記載(著者 (2025), "題," 出版者)は、その前に書き手が置いた言葉(For example, see …)だけを数え、前の文献の終わり((Washington: …); and)から始まる文は、そこまでを数えません。姓と頭文字で並べた文献の著者(Kreimer AR, Porras C, …)は一語として数えます。括弧の中で閉じた文(「….)」)は、後ろの文と別に測ります。句点で閉じた文を二つ以上引いた「」(「…転落。…入院。」)は、引いた文を一つずつ、括弧の外を別に測ります。すぐ前か、すぐ後ろの括弧に条を挙げて引いた一文(第13条「…ものとする。」)も同じです。句点の無い「項目:値」の行が続くもの(日時:…/場所:…)は一行ずつ、変換で区切りが消えて一続きになった表(桁区切りの崩れた数字の列、行頭の年月が前のセルに続く年表、数の後ろに括弧書きの数を添えたセルが続く行(201(16)…831(-)))はセルごとに測ります。行の頭に置いたリンクの題名に紹介文が空白一つで続く行(「法令」×「デジタル」ハッカソン 「法令」×…を開催しました。)は、題名が括弧で始まるか、後ろの文にもう一度出てくるとき、題名と紹介文を別に測ります。コロンの後に引いた「"…"」は括弧の外と別に測ります。仕様書の文法(name = a / b)、引用記号で始まる法令や文書の列挙(See, e.g., 12 C.F.R. § …; …)は数えません。英文の題名の後の括弧書きは括弧の中だけを、文書の参照(番号、"題名"、(日付))は題名を除いて数えます。引用記号で始まる脚注(See …)は、引いた法令や文書の名前・"題名"・略称や番号の括弧を除いた言葉だけを数えます。他の文書をそのまま写した文(文書がほかで名前を挙げて引いている法律を見出しにした節の条、「reads as follows:」のような前置きの次の段落)は数えません。法令や論文のように長い一文が普通の種類では、ジャンルが上限を長くします。
見出し、表のセル、コードは数えません。メールの件名の欄の値(「件名:」「SUBJECT:」の行や、その下の行に書いた件名)も、文ではないので数えません(件名の長さは email-subject-length が見ます)。句点の無い、名前や肩書きを「、」で並べただけの行(出席者の一覧)も数えません。印刷版を文字にした文書が文の途中に残すページの印(「( printed page 52044)」「- 12 -」)も数えません。注の頭の札と番号(「(注)1.」「※3:」)も数えません。脚注の文献の記載(著者 (2025), "題," 出版者)は、その前に書き手が置いた言葉(For example, see …)だけを数え、前の文献の終わり((Washington: …); and)から始まる文は、そこまでを数えません。姓と頭文字で並べた文献の著者(Kreimer AR, Porras C, …)は一語として数えます。コロンの後に読点で並べた、頭だけ大文字の三つ以上の題名(New books include: The lighthouse keeper, A short history of tea, …)も、一つずつを一語として数えます。語ごとに大文字で始める名前の並びは数えます。括弧の中で閉じた文(「….)」)は、後ろの文と別に測ります。句点で閉じた文を二つ以上引いた「」(「…転落。…入院。」)は、引いた文を一つずつ、括弧の外を別に測ります。すぐ前か、すぐ後ろの括弧に条を挙げて引いた一文(第13条「…ものとする。」)も同じです。句点の無い「項目:値」の行が続くもの(日時:…/場所:…)は一行ずつ、変換で区切りが消えて一続きになった表(桁区切りの崩れた数字の列、行頭の年月が前のセルに続く年表、数の後ろに括弧書きの数を添えたセルが続く行(201(16)…831(-)))はセルごとに測ります。行の頭に置いたリンクの題名に紹介文が空白一つで続く行(「法令」×「デジタル」ハッカソン 「法令」×…を開催しました。)は、題名が括弧で始まるか、後ろの文にもう一度出てくるとき、題名と紹介文を別に測ります。コロンの後に引いた「"…"」は括弧の外と別に測ります。仕様書の文法(name = a / b)、引用記号で始まる法令や文書の列挙(See, e.g., 12 C.F.R. § …; …)は数えません。英文の題名の後の括弧書きは括弧の中だけを、文書の参照(番号、"題名"、(日付))は題名を除いて数えます。引用記号で始まる脚注(See …)は、引いた法令や文書の名前・"題名"・略称や番号の括弧を除いた言葉だけを数えます。他の文書をそのまま写した文(文書がほかで名前を挙げて引いている法律を見出しにした節の条、「reads as follows:」のような前置きの次の段落)は数えません。法令や論文のように長い一文が普通の種類では、ジャンルが上限を長くします。
en: >-
Headings, table cells and code are not counted, nor is the value of an email's subject field (on the "Subject:" line, or on the line under a bare "SUBJECT:"), which email-subject-length measures, nor is a line that only lists names or titles with 、 and has no full stop (an attendee list), nor are the page markers a converted print edition leaves inside a sentence ("( printed page 52044)", "[[Page 52044]]"), nor, in Japanese, the label and number that open a note ((注)1., ※3:). A footnote that is a bibliographic citation (authors (2025), "Title," publisher) counts only the words the writer puts before it ("For example, see …"), and not the end of an earlier reference it begins inside ("(Washington: …); and"). The authors of a reference written as surname and initials (Kreimer AR, Porras C, …) count as one word. A sentence closed inside parentheses ("….)") is measured apart from the sentence after it. A 「」 quotation holding two or more sentences closed by 。 is measured sentence by sentence, apart from the words around it, and so is one sentence quoted with the article it comes from named right before it or in the bracket after it (第13条「…ものとする。」). Lines of a label and a value with no full stop (When: … / Where: …) are measured one line at a time, and a table a converter ran together (numbers whose digit groups broke, a chronology whose dates run into the cell before, rows of a figure with another in brackets after it: 201(16) … 831(-)) cell by cell. In Japanese, a link title at the head of a line that runs into its blurb after one space (「法令」×「デジタル」ハッカソン 「法令」×…を開催しました。) is measured apart from the blurb, when the title opens with a bracket or comes back in the sentence after it. A quotation opened after a colon (has observed: "…") is measured apart from the writer's words. A grammar in a specification (name = a / b), a citation string after a signal (See, e.g., 12 C.F.R. § …; …), the title before a remark in parentheses and the quoted title of a reference line (Letter 21-8, "Title" (April 9, 2021).) are not counted. A footnote that opens with a signal (See …) counts only its words outside the names, "titles" and parentheses of codes it cites. Text copied word for word from another document is not counted: the articles of a statute under a heading that names it, where the document cites that statute elsewhere, and the paragraph after a lead-in such as "reads as follows:". Genres where long sentences are normal (statutes, papers) raise the limit.
Headings, table cells and code are not counted, nor is the value of an email's subject field (on the "Subject:" line, or on the line under a bare "SUBJECT:"), which email-subject-length measures, nor is a line that only lists names or titles with 、 and has no full stop (an attendee list), nor are the page markers a converted print edition leaves inside a sentence ("( printed page 52044)", "[[Page 52044]]"), nor, in Japanese, the label and number that open a note ((注)1., ※3:). A footnote that is a bibliographic citation (authors (2025), "Title," publisher) counts only the words the writer puts before it ("For example, see …"), and not the end of an earlier reference it begins inside ("(Washington: …); and"). The authors of a reference written as surname and initials (Kreimer AR, Porras C, …) count as one word. So does each of three or more titles in sentence case listed after a colon (New books include: The lighthouse keeper, A short history of tea, …); names written in title case are still counted. A sentence closed inside parentheses ("….)") is measured apart from the sentence after it. A 「」 quotation holding two or more sentences closed by 。 is measured sentence by sentence, apart from the words around it, and so is one sentence quoted with the article it comes from named right before it or in the bracket after it (第13条「…ものとする。」). Lines of a label and a value with no full stop (When: … / Where: …) are measured one line at a time, and a table a converter ran together (numbers whose digit groups broke, a chronology whose dates run into the cell before, rows of a figure with another in brackets after it: 201(16) … 831(-)) cell by cell. In Japanese, a link title at the head of a line that runs into its blurb after one space (「法令」×「デジタル」ハッカソン 「法令」×…を開催しました。) is measured apart from the blurb, when the title opens with a bracket or comes back in the sentence after it. A quotation opened after a colon (has observed: "…") is measured apart from the writer's words. A grammar in a specification (name = a / b), a citation string after a signal (See, e.g., 12 C.F.R. § …; …), the title before a remark in parentheses and the quoted title of a reference line (Letter 21-8, "Title" (April 9, 2021).) are not counted. A footnote that opens with a signal (See …) counts only its words outside the names, "titles" and parentheses of codes it cites. Text copied word for word from another document is not counted: the articles of a statute under a heading that names it, where the document cites that statute elsewhere, and the paragraph after a lead-in such as "reads as follows:". Genres where long sentences are normal (statutes, papers) raise the limit.
level_meaning:
ja: 一文 {limit} 字まで
en: up to {limit} {limit|word|words} in a sentence
Expand Down
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
12 changes: 11 additions & 1 deletion text/packages/chaff/src/detectors/number-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ const isCountedNoun = (token: Token | undefined, figureNouns: readonly string[])
const endsInNameWord = (before: string, nameWords: readonly string[]): boolean =>
nameWords.length > 0 && new RegExp(`(?<![\\p{L}\\p{N}])(?:${alternation(nameWords)})\\s*$`, "u").test(before);

/** A figure glued to the word or the dot before it (php7.4-fpm, v2) is part of a name or a version, not a count. */
const GLUED_TO_NAME = /[\p{L}\p{N}._]$/u;

/**
* A figure right after the clock time that opens a log entry (- 17:59 4 pages are sent) opens a log line, not prose, so
* it is not a vote on how the document writes counts.
*/
const OPENS_LOG_ENTRY = /^\s*(?:[-*+]\s+)?\d{1,2}:\d{2}(?::\d{2})?\s+$/u;

/**
* A number before a plural noun (three files, 3 files), from two to the last number word the language lists. One is a
* pronoun as often as a count. A number word that opens the sentence is spelt out by every style, so it is not counted,
Expand All @@ -234,7 +243,8 @@ const englishCountMarks = (sentence: Sentence, words: NumberWords): NumberMark[]
const value = valueOf(token.surface, words.countWords);
if (value === undefined || value < SMALL_FROM || value > words.countWords.length || index === 0 || !isCountedNoun(tokens[index + 1], words.figureNouns))
return [];
if (endsInNameWord(sentence.text.slice(0, token.span.start - sentence.span.start), words.nameWords)) return [];
const before = sentence.text.slice(0, token.span.start - sentence.span.start);
if (endsInNameWord(before, words.nameWords) || GLUED_TO_NAME.test(before) || OPENS_LOG_ENTRY.test(before)) return [];
const style = /^\d+$/u.test(token.surface) ? "digits" : "words";
return [{ kind: value < LARGE_FROM ? "count-small" : "count-large", style, written: token.surface, offset: token.span.start }];
});
Expand Down
8 changes: 4 additions & 4 deletions text/packages/chaff/src/detectors/orthographic-variant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ const isOutsideComparative = ({ token, following }: InContext, { comparative, co
return !COMPARATIVE_PARTICLES.has(particle) || (particle === "が" && comparativePerson.has(following?.[1]?.lemma ?? ""));
};

/** A spelling listed as reading two ways, alone or with the word written onto it (様を), read as the reading in doubt. */
const readsTwoWays = ({ token, following }: InContext, reading: string, twoReadings: ReadonlyMap<string, string>): boolean => {
const next = following?.[0];
/** A listed spelling read as the reading in doubt: alone, with the word written onto it (様を), or onto a noun as 〜丼 (親子丼). */
const readsTwoWays = ({ token, previous, following: [next] = [] }: InContext, reading: string, twoReadings: ReadonlyMap<string, string>): boolean => {
const withNext = next !== undefined && isTouching(token, next) ? twoReadings.get(`${token.surface}${next.surface}`) : undefined;
return (twoReadings.get(token.surface) ?? withNext) === reading;
const ontoNoun = previous?.pos === "NOUN" && isTouching(previous, token) ? twoReadings.get(`〜${token.surface}`) : undefined;
return (twoReadings.get(token.surface) ?? withNext ?? ontoNoun) === reading;
};

/** A piece the tokenizer cut from a word (ラオ|カイ, 誂ら|え), a pronoun's kana (私みたような) or a numeral (三十の三). */
Expand Down
6 changes: 5 additions & 1 deletion text/packages/chaff/src/detectors/sentence-length.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { isReproduced, reproducedSpans } from "./reproduced-text.ts";
import { runInTitleParts } from "./run-in-title.ts";
import { colonQuotationParts, figureCellParts, flattenedTableParts, isGrammarBlock, labelLineParts, parentheticalSentenceParts } from "./sentence-parts.ts";
import { isInListItem, isReferenceLine, isTitleLine, quotedTitleWords, remarkAfterTitle, termSeriesSaving } from "./sentence-title.ts";
import { titleSeriesSaving } from "./title-series.ts";

type Measure = { readonly size: number; readonly limit: number; readonly variant?: string };

Expand Down Expand Up @@ -42,7 +43,10 @@ const noteLabelSize = (text: string, unit: LengthUnit, words: SentenceWords): nu
* Only where words are the unit: the shapes are read from capitals and spaces.
*/
const unwrittenWords = (sentence: Sentence, text: string, listItems: SentenceWords["listItems"]): number =>
termSeriesSaving(text) + authorListSaving(text) + (isInListItem(sentence.span, listItems) || isReferenceLine(text) ? quotedTitleWords(text) : 0);
termSeriesSaving(text) +
authorListSaving(text) +
titleSeriesSaving(text) +
(isInListItem(sentence.span, listItems) || isReferenceLine(text) ? quotedTitleWords(text) : 0);

/**
* A comma or a stop typed with one space before it ("the same brick , and"). It is no word of its own. One space only:
Expand Down
Loading
Loading