Skip to content
Open
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
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, …)は一語として数えます。括弧の中で閉じた文(「….)」)は、後ろの文と別に測ります。句点で閉じた文を二つ以上引いた「」(「…転落。…入院。」)は、引いた文を一つずつ、括弧の外を別に測ります。すぐ前か、すぐ後ろの括弧に条を挙げて引いた一文(第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. 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(-), a header row whose cells close in a unit in brackets run into the next cell: 資本金(千円)主要な事業の内容 … 割合(%)関係内容) 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
11 changes: 10 additions & 1 deletion text/packages/chaff/src/detectors/sentence-length.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ import { pageMarkerPattern, pageMarkerSize } from "./page-marker.ts";
import { quotedSentenceParts } from "./quoted-sentences.ts";
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 {
colonQuotationParts,
figureCellParts,
flattenedTableParts,
isGrammarBlock,
labelLineParts,
parentheticalSentenceParts,
unitHeaderParts,
} from "./sentence-parts.ts";
import { isInListItem, isReferenceLine, isTitleLine, quotedTitleWords, remarkAfterTitle, termSeriesSaving } from "./sentence-title.ts";

type Measure = { readonly size: number; readonly limit: number; readonly variant?: string };
Expand Down Expand Up @@ -95,6 +103,7 @@ const partsOf = (sentence: Sentence, text: string, unit: LengthUnit, words: Sent
labelLineParts(sentence.text) ??
flattenedTableParts(text, words.eras) ??
figureCellParts(text) ??
unitHeaderParts(text) ??
colonQuotationParts(text) ??
parentheticalSentenceParts(text) ??
titleParts(sentence, text, unit, words.source);
Expand Down
14 changes: 14 additions & 0 deletions text/packages/chaff/src/detectors/sentence-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ const MIN_FIGURE_CELLS = 3;
export const figureCellParts = (text: string): readonly string[] | undefined =>
(text.match(FIGURE_CELL)?.length ?? 0) >= MIN_FIGURE_CELLS ? nonEmpty(text.split(FIGURE_CELL)) : undefined;

/**
* A header cell closed by its unit in brackets and glued to the next cell (資本金(千円)主要な…, 割合(%)関係内容): a
* table's header row. A sentence names a unit before a particle or a comma (金額(千円)は), not before the next heading.
*/
const GLUED_UNIT_HEADER = /[((](?:%|%|人|名|株|件|台|社|円|千円|百万円)[))](?=[\p{Script=Han}\p{Script=Katakana}((])/gu;
/** Fewer glued header cells than this are a unit named once, not a header row. */
const MIN_GLUED_UNIT_HEADERS = 2;

/** The cells of a flattened table with a header row of units, cut at each unit and at the spaces between cells. */
export const unitHeaderParts = (text: string): readonly string[] | undefined =>
(text.match(GLUED_UNIT_HEADER)?.length ?? 0) >= MIN_GLUED_UNIT_HEADERS
? nonEmpty(text.split(GLUED_UNIT_HEADER).flatMap((part) => part.split(CELL_SPACE)))
: undefined;

/** A quotation the writer opens after a colon (has observed: "The credibility of money …"), in straight or curly quotes. */
const COLON_QUOTATION = /[::]\s*["“]([^"“”]+)["”]/gu;

Expand Down
29 changes: 29 additions & 0 deletions text/test/test_sentence_length_shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
isGrammarBlock,
labelLineParts,
parentheticalSentenceParts,
unitHeaderParts,
} from "../packages/chaff/src/detectors/sentence-parts.ts";
import { isReferenceLine, remarkAfterTitle } from "../packages/chaff/src/detectors/sentence-title.ts";
import { noteLabelLength } from "../packages/chaff/src/labelled-note-paragraphs.ts";
Expand Down Expand Up @@ -160,6 +161,34 @@ describe("a table whose rows end in a figure and a bracketed figure (ja)", () =>
});
});

const HEADER_ROW =
"4【関係会社の状況】名称住所資本金(千円)主要な事業の内容議決権の所有割合(%)関係内容(連結子会社) みどり商事株式会社名古屋市中区20,000情報処理サービス100.0当社業務の一部委託経理事務総務事務人事業務の一部受託役員の兼任 2名(注)「主要な事業の内容」欄には、事業の区分の名称を記載しております。";

describe("a flattened table with a header row of cells closed by units (ja)", () => {
it("cuts the cells at each unit glued to the next header cell", () => {
const parts = unitHeaderParts(HEADER_ROW);
assert.equal(parts?.at(0), "4【関係会社の状況】名称住所資本金");
assert.equal(parts?.at(1), "主要な事業の内容議決権の所有割合");
assert.deepEqual(jaFindings(HEADER_ROW), []);
});

it("leaves a sentence that names a unit before a particle or a comma alone", () => {
[
"売上高(千円)と営業利益(千円)は、いずれも前期を上回りました。",
"表の金額(千円)、比率(%)は四捨五入しております。",
"従業員数(人)を記載しております。",
].forEach((text) => assert.equal(unitHeaderParts(text), undefined, text));
});

it("still reports a long sentence after such a header row", () => {
const longNote = HEADER_ROW.replace(
"記載しております。",
"記載しており、事業の区分は当連結会計年度から改めましたので、前連結会計年度の区分とはそのまま比べることができず、比べる場合には前連結会計年度の数を新しい区分に組み替えた上で、注記に記載した方法に従って読み替えていただく必要がございますので、ご注意ください。",
);
assert.equal(jaFindings(longNote).length, 1);
});
});

const NOTE_WORDS = ["注"];
const NOTE_MARKS = ["※"];
/** A note of exactly 140 characters, the limit of a business report: one more and it is reported. */
Expand Down
Loading