diff --git a/text/corpus/expected/max-sentence-length.txt b/text/corpus/expected/max-sentence-length.txt index 14ac6fd3f..dfb785b08 100644 --- a/text/corpus/expected/max-sentence-length.txt +++ b/text/corpus/expected/max-sentence-length.txt @@ -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 diff --git a/text/corpus/expected/orthographic-variant.txt b/text/corpus/expected/orthographic-variant.txt index 65cfbc65d..62ce7b1dd 100644 --- a/text/corpus/expected/orthographic-variant.txt +++ b/text/corpus/expected/orthographic-variant.txt @@ -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 diff --git a/text/corpus/expected/undefined-acronym.txt b/text/corpus/expected/undefined-acronym.txt index 06ca2efe2..7afac7bf4 100644 --- a/text/corpus/expected/undefined-acronym.txt +++ b/text/corpus/expected/undefined-acronym.txt @@ -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 diff --git a/text/packages/chaff/rules/max-sentence-length.yaml b/text/packages/chaff/rules/max-sentence-length.yaml index a67a59d78..4567d6146 100644 --- a/text/packages/chaff/rules/max-sentence-length.yaml +++ b/text/packages/chaff/rules/max-sentence-length.yaml @@ -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 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/packages/chaff/src/detectors/number-style.ts b/text/packages/chaff/src/detectors/number-style.ts index 01d37a8a7..e36771e98 100644 --- a/text/packages/chaff/src/detectors/number-style.ts +++ b/text/packages/chaff/src/detectors/number-style.ts @@ -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(`(? 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 }]; }); diff --git a/text/packages/chaff/src/detectors/orthographic-variant.ts b/text/packages/chaff/src/detectors/orthographic-variant.ts index d81d04e08..fe51e8a28 100644 --- a/text/packages/chaff/src/detectors/orthographic-variant.ts +++ b/text/packages/chaff/src/detectors/orthographic-variant.ts @@ -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): 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): 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 (三十の三). */ diff --git a/text/packages/chaff/src/detectors/sentence-length.ts b/text/packages/chaff/src/detectors/sentence-length.ts index 1c5fddd74..c4c0e0ee9 100644 --- a/text/packages/chaff/src/detectors/sentence-length.ts +++ b/text/packages/chaff/src/detectors/sentence-length.ts @@ -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 }; @@ -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: diff --git a/text/packages/chaff/src/detectors/title-series.ts b/text/packages/chaff/src/detectors/title-series.ts new file mode 100644 index 000000000..c0478a439 --- /dev/null +++ b/text/packages/chaff/src/detectors/title-series.ts @@ -0,0 +1,38 @@ +// A run of titles written in sentence case after a colon (New books include: The lighthouse keeper, A short history of +// tea, and …), the way a catalogue writes them: each title, however many words it holds, is one entry of the list, not +// words the writer built into a sentence. Names in title case (Agua Caliente Band of Cahuilla Indians, …) are the +// writer's own long sentence and stay counted. Pure. + +const WORD = /[\p{L}\p{N}][\p{L}\p{N}'’&.-]*/gu; +/** Fewer titles in a row than this are a sentence going on after its colon, not a list. */ +const MIN_ITEMS = 3; +const ITEM_SEPARATOR = /,\s+(?:and\s+|or\s+)?/u; +const STARTS_UPPER = /^\p{Lu}/u; +/** A lower-case word this long is a content word (bridge, story), not one a title-case name keeps small (of, and, the). */ +const CONTENT_WORD_LENGTH = 4; +const COLON = /:\s+/gu; + +const wordsOf = (text: string): string[] => text.match(WORD) ?? []; + +/** A title in sentence case: a capital first word, and a content word after it in lower case. */ +const isSentenceCaseTitle = (item: string): boolean => + STARTS_UPPER.test(item) && + wordsOf(item) + .slice(1) + .some((word) => word.length >= CONTENT_WORD_LENGTH && /^\p{Ll}/u.test(word)); + +/** The titles after one colon, up to the first item that is not one. */ +const leadingTitles = (rest: string): string[] => { + const items = rest.split(ITEM_SEPARATOR); + const stop = items.findIndex((item) => !isSentenceCaseTitle(item)); + return stop === -1 ? items : items.slice(0, stop); +}; + +const savingOf = (titles: readonly string[]): number => titles.reduce((saving, title) => saving + Math.max(0, wordsOf(title).length - 1), 0); + +/** How many words fewer the sentence is when each title listed after a colon counts as one word. */ +export const titleSeriesSaving = (text: string): number => + [...text.matchAll(COLON)] + .map((match) => leadingTitles(text.slice(match.index + match[0].length))) + .filter((titles) => titles.length >= MIN_ITEMS) + .reduce((most, titles) => Math.max(most, savingOf(titles)), 0); diff --git a/text/packages/lang-en/lexicons/figure-noun.yaml b/text/packages/lang-en/lexicons/figure-noun.yaml index f426d825e..93e5b7863 100644 --- a/text/packages/lang-en/lexicons/figure-noun.yaml +++ b/text/packages/lang-en/lexicons/figure-noun.yaml @@ -30,3 +30,17 @@ entries: - pattern: degrees - pattern: percent - pattern: points + # Units of data and of short time, which specifications write in figures (4 bits, 2 bytes, 4 microseconds). + - pattern: milliseconds + - pattern: microseconds + - pattern: nanoseconds + - pattern: bits + - pattern: bytes + - pattern: octets + - pattern: kilobytes + - pattern: megabytes + - pattern: gigabytes + - pattern: terabytes + - pattern: kilobits + - pattern: megabits + - pattern: gigabits diff --git a/text/packages/lang-en/src/emphasis.ts b/text/packages/lang-en/src/emphasis.ts index 2f5c22c42..29c7978c7 100644 --- a/text/packages/lang-en/src/emphasis.ts +++ b/text/packages/lang-en/src/emphasis.ts @@ -65,6 +65,26 @@ export const isCapitalisedOrdinaryWord = (surface: string, tagsOf: TagsOf): bool return tags.some((tag) => OPEN_CLASS_TAG.test(tag)) && !tags.some((tag) => tag.startsWith("NNP")); }; +const BE_FORMS: ReadonlySet = new Set(["am", "is", "are", "was", "were", "be", "been"]); + +/** Prepositions and particles (OUT, OFF, OVER) that can close a sentence after a form of be. */ +const PREDICATE_PARTICLE_TAGS: ReadonlySet = new Set(["IN", "RP"]); + +/** Two-letter particles are state or company names too often (IN Indiana, ON Ontario, UP Union Pacific). */ +const PREDICATE_PARTICLE_MIN_LENGTH = 3; + +const SENTENCE_END = /^[.!?]$/u; + +/** + * A preposition or particle closing a sentence right after a lower-case form of be (version 26 is OUT!): the predicate of the + * sentence, where a noun would need a determiner (is the OUT). Nothing follows it but the sentence's last mark. + */ +const isPredicateParticle = (word: TaggedWord, previous: TaggedWord, next: TaggedWord | undefined): boolean => + PREDICATE_PARTICLE_TAGS.has(word.pos) && + [...word.value].length >= PREDICATE_PARTICLE_MIN_LENGTH && + BE_FORMS.has(previous.value) && + (next === undefined || SENTENCE_END.test(next.value)); + /** After a verb, a word the tagger read as a noun must also be a verb in the dictionary (DID form), or it is what the capitals name (DID token). */ const canFollowVerb = (next: TaggedWord, tagsOf: TagsOf): boolean => !next.pos.startsWith("NN") || (tagsOf(next.value.toLowerCase()) ?? []).includes("VB"); @@ -79,8 +99,10 @@ const canFollowVerb = (next: TaggedWord, tagsOf: TagsOf): boolean => !next.pos.s const isReadAsWord = (tagged: readonly TaggedWord[], at: number, tagsOf: TagsOf): boolean => { const word = tagged[at]; const [previous, next] = [tagged[at - 1], tagged[at + 1]]; - if (word === undefined || previous === undefined || next === undefined) return false; - if (!(tagsOf(word.value.toLowerCase()) ?? []).includes(word.pos) || !LOWERCASE.test(previous.value) || !LOWERCASE.test(next.value)) return false; + if (word === undefined || previous === undefined) return false; + if (!(tagsOf(word.value.toLowerCase()) ?? []).includes(word.pos)) return false; + if (isPredicateParticle(word, previous, next)) return true; + if (next === undefined || !LOWERCASE.test(previous.value) || !LOWERCASE.test(next.value)) return false; if (CLOSED_CLASS_TAGS.has(word.pos)) return word.pos === "CD" || !NOUN_PHRASE_OPENERS.has(previous.pos); return word.pos.startsWith("VB") && SUBJECT_TAGS.has(previous.pos) && canFollowVerb(next, tagsOf); }; diff --git a/text/packages/lang-ja/lexicons/orthographic-variant-two-readings.yaml b/text/packages/lang-ja/lexicons/orthographic-variant-two-readings.yaml index 0d17d3e17..ebc003b94 100644 --- a/text/packages/lang-ja/lexicons/orthographic-variant-two-readings.yaml +++ b/text/packages/lang-ja/lexicons/orthographic-variant-two-readings.yaml @@ -18,3 +18,6 @@ entries: group: サン - pattern: 用 group: ヨウ + # 〜を付けた書き方は、前の名詞に間を空けずに付くときだけ。料理の名前の尻の「丼」(親子丼、牛丼)は「どん」で、器の「どんぶり」とは別の語。 + - pattern: 〜丼 + group: ドンブリ diff --git a/text/test/test_acronym_emphasis.ts b/text/test/test_acronym_emphasis.ts index 6b29265d3..6109d9e4b 100644 --- a/text/test/test_acronym_emphasis.ts +++ b/text/test/test_acronym_emphasis.ts @@ -70,6 +70,9 @@ describe("undefined-acronym: 文の中で前置詞・接続詞・数詞・代名 ["You must complete ALL required steps. The SRE joins.", ["SRE"]], ["The paper has NO calculus and NO equations. The SRE joins.", ["SRE"]], ["Version 26 is OUT now. The SRE joins.", ["SRE"]], + // 文の終わりで be の直後の前置詞・小辞は述語(is OUT!)。名詞なら冠詞が要る。 + ["Version 26 is OUT! The SRE joins.", ["SRE"]], + ["The vote is OFF. The SRE joins.", ["SRE"]], ].forEach(([body, expected]) => { it(`数えない: ${String(body)}`, () => assert.deepEqual(acronymsIn(String(body)), expected)); }); @@ -88,6 +91,10 @@ describe("undefined-acronym: 文の中で前置詞・接続詞・数詞・代名 ["The team uses OR's model.", ["OR"]], // 3 文字までの語は略語であることが多い(PIE、GUT)ので、文の中で読めなければ数える。 ["Build it as a PIE binary under the GUT model.", ["GUT", "PIE"]], + // be の後ろでも、2 文字の語(IN、ON)、文が続く語、be でない動詞の後ろの語は名前でありうる。 + ["The new office is IN.", ["IN"]], + ["The vendor is OUT of scope for the RFP.", ["RFP"]], + ["Please contact OUT.", ["OUT"]], ].forEach(([body, expected]) => { it(`数える: ${String(body)}`, () => assert.deepEqual(acronymsIn(String(body)), expected)); }); 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"]); }); diff --git a/text/test/test_number_style.ts b/text/test/test_number_style.ts index 0a7f72b82..45a410dfb 100644 --- a/text/test/test_number_style.ts +++ b/text/test/test_number_style.ts @@ -136,6 +136,10 @@ describe("numberMarksIn: English", () => { ["The fund paid $12500 to 3 members.", ["grouping:plain:12500", "count-small:digits:3"]], ["We counted 12500 deaf voters.", ["grouping:plain:12500"]], ["The fund paid $12500cafe to members.", ["grouping:plain:12500"]], + ["The php7.4-fpm workers were busy.", []], + ["- 17:59 4 pages are sent to the team.", []], + ["- 17:59 The team gets 4 pages.", ["count-small:digits:4"]], + ["The field is 4 bits wide and takes 2 bytes at 2 megabits a second.", []], ]; cases.forEach(([sentence, marks]) => { it(`${sentence} → ${marks.join(", ") || "none"}`, () => diff --git a/text/test/test_orthographic_variant_two_readings.ts b/text/test/test_orthographic_variant_two_readings.ts index 5e188b4ed..e3b138add 100644 --- a/text/test/test_orthographic_variant_two_readings.ts +++ b/text/test/test_orthographic_variant_two_readings.ts @@ -34,6 +34,13 @@ describe("orthographic-variant: 二つの語に読める漢字の書き方", () assert.deepEqual(findingsOf("# 手順\n\nそれ以外は言いようがありません。直しようがありません。Ruby用のライブラリです。\n"), []); }); + it("料理の名前の尻の「丼」(どん)は、器の「どんぶり」と比べない。名前の外の「丼」は比べる", () => { + const dish = ["# 献立", "", "今日は親子丼です。明日は他人丼にします。", "", "できたら、どんぶりに盛ります。", ""].join("\n"); + assert.deepEqual(findingsOf(dish), []); + const bowl = ["# 献立", "", "丼にごはんを盛ります。丼を温めます。", "", "できたら、どんぶりに盛ります。", ""].join("\n"); + assert.equal(findingsOf(bowl).length, 1); + }); + it("解析器が「行う」と読んだ「行っ」は、おこなうのかなと比べる", () => { const conduct = ["調査を毎年おこなう。", "", "点検も毎月おこなう。", "", "昨年は交渉を行った。", ""].join("\n"); assert.equal(findingsOf(conduct).length, 1); diff --git a/text/test/test_sentence_length_titles.ts b/text/test/test_sentence_length_titles.ts index ca8e7498c..03023ad97 100644 --- a/text/test/test_sentence_length_titles.ts +++ b/text/test/test_sentence_length_titles.ts @@ -3,6 +3,7 @@ import assert from "node:assert/strict"; import { namedRuleRun } from "./rule-run.ts"; import { adapter as en } from "../packages/lang-en/src/index.ts"; import { isTitleCase, isTitleLine, quotedTitleWords, termSeriesSaving } from "../packages/chaff/src/detectors/sentence-title.ts"; +import { titleSeriesSaving } from "../packages/chaff/src/detectors/title-series.ts"; // max-sentence-length and words the writer did not build into a sentence: a title line with no full stop, a quoted title // in a list item, and quoted terms listed one after another. A long sentence beside them is still reported. Every text is @@ -71,3 +72,26 @@ describe("max-sentence-length: titles and quoted term runs", () => { assert.equal(findingsOf(`Notes:\n\nThe desk wrote ${subject}.`).length, 1); }); }); + +describe("max-sentence-length: titles listed after a colon", () => { + const TITLES = + "New books this month include: The lighthouse keeper of the northern bay, A short history of tea in the old ports, The garden that grew back after the long winter, Notes from a quiet river town in the mountains, and Letters to a young printer on the craft of setting type."; + const NAMES = + "The valley is home to many groups today: North Ridge Band of River Peoples, South Ridge Band of River Peoples, East Valley Tribe of Hill Peoples, West Valley Tribe of Hill Peoples, Lake Shore Nation of Fishing Peoples, and the Desert Springs Nation."; + const PROSE = + "The library added new books this month: the staff chose them after a long survey of readers in the northern towns, and they hope that the readers will borrow them often during the winter when the roads are closed and the reading rooms are full."; + + it("titleSeriesSaving: each listed title counts as one word", () => { + assert.equal(titleSeriesSaving("New: The lighthouse keeper, A short history of tea, and The garden plan."), 8); + assert.equal(titleSeriesSaving("New: The lighthouse keeper and A short history of tea."), 0); + assert.equal(titleSeriesSaving("Members: Ann Lee of Leeds, Bo Chan of York, and Cy Moss of Hull."), 0); + assert.equal(titleSeriesSaving("Note: the parser, the renderer and the exporter ship."), 0); + assert.equal(titleSeriesSaving(""), 0); + }); + + it("a sentence that is mostly a list of titles is not reported; long prose or names in title case after a colon are", () => { + assert.deepEqual(findingsOf(TITLES), []); + assert.equal(findingsOf(PROSE).length, 1); + assert.equal(findingsOf(NAMES).length, 1); + }); +});