From c4885ec33def6706e0bc76a1d4ce96e14402a9fe Mon Sep 17 00:00:00 2001 From: isamu Date: Mon, 30 Nov 2026 07:18:45 +0900 Subject: [PATCH 1/3] fix: oxford-comma-consistency reads the item after 'and then' by the word past then Co-Authored-By: Claude Opus 5.5 --- .../chaff/src/detectors/list-sequence-lead.ts | 19 +++++++++++++++++++ .../chaff/src/detectors/oxford-comma.ts | 6 +++--- text/test/test_oxford_not_a_list.ts | 7 +++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 text/packages/chaff/src/detectors/list-sequence-lead.ts diff --git a/text/packages/chaff/src/detectors/list-sequence-lead.ts b/text/packages/chaff/src/detectors/list-sequence-lead.ts new file mode 100644 index 000000000..dd59f1bac --- /dev/null +++ b/text/packages/chaff/src/detectors/list-sequence-lead.ts @@ -0,0 +1,19 @@ +import { shapeOf } from "./list-item.ts"; +import type { ItemScope } from "./list-sentence.ts"; +import type { TokenRange } from "./token-column.ts"; + +/** + * and / or のすぐ後ろの順番の語(and then ride / and finally chop)を外した項目。順番の語は項目の形ではなく手順の印で、形はその後ろの語で見る。 + * Wash, peel, and then chop は動詞の 3 つ。to X, easily spotted ..., and then ride は副詞どうしが偶然揃っただけで並びではない。 + */ +const withoutSequenceLead = (scope: ItemScope, item: TokenRange): TokenRange => { + const lead = scope.sentence.tokens[item.start]?.surface.toLowerCase() ?? ""; + const isSequence = scope.sentence.words.sequence?.has(lead) ?? false; + return item.end - item.start > 1 && isSequence ? { start: item.start + 1, end: item.end } : item; +}; + +/** 最後の項目と and / or の後ろの項目が同じ形なら、その形。違えば undefined。 */ +export const sharedShape = (scope: ItemScope, last: TokenRange, afterItem: TokenRange): string | undefined => { + const shape = shapeOf(scope, last); + return shape !== undefined && shape === shapeOf(scope, withoutSequenceLead(scope, afterItem)) ? shape : undefined; +}; diff --git a/text/packages/chaff/src/detectors/oxford-comma.ts b/text/packages/chaff/src/detectors/oxford-comma.ts index c1cf72b4c..9a9483a88 100644 --- a/text/packages/chaff/src/detectors/oxford-comma.ts +++ b/text/packages/chaff/src/detectors/oxford-comma.ts @@ -61,6 +61,7 @@ import { insideSentenceCaseTitle } from "./title-list.ts"; import { insideByline } from "./byline-list.ts"; import { withoutOpeningConjunction } from "./list-opening-conjunction.ts"; import { afterClauseBeforeInfinitives } from "./list-purpose-clause.ts"; +import { sharedShape } from "./list-sequence-lead.ts"; const EMPTY: TokenRange = { start: 0, end: 0 }; @@ -393,9 +394,8 @@ const listAt = (list: ItemList, at: number, walk: Walk): boolean | undefined => if (namesDivision(items) || qualifiesPrevious(items)) return undefined; const last = lastOf(items); if (last !== undefined && opensContrast(scope, last.item)) return undefined; - const shape = last === undefined ? undefined : shapeOf(scope, last.item); - if (sizeOf(items) < 2 || shape === undefined || shape !== shapeOf(scope, afterItem)) return undefined; - return itemsAgree(scope, items, afterItem, shape) ? commaBefore(scope, at) : undefined; + const shape = last === undefined || sizeOf(items) < 2 ? undefined : sharedShape(scope, last.item, afterItem); + return shape !== undefined && itemsAgree(scope, items, afterItem, shape) ? commaBefore(scope, at) : undefined; }; const isJudgedConjunction = (token: Token, at: number): boolean => at > 0 && isListConjunction(token); diff --git a/text/test/test_oxford_not_a_list.ts b/text/test/test_oxford_not_a_list.ts index 03697b8fe..1956a4b04 100644 --- a/text/test/test_oxford_not_a_list.ts +++ b/text/test/test_oxford_not_a_list.ts @@ -139,6 +139,13 @@ describe("oxford-comma-consistency: what is not a list", () => { assert.equal(reportedWith("I.e., the posters and the cards stay in stock."), false); assert.equal(reportedWith("E.g., posters, cards and calendars sell well."), true); }); + + it("reads the item after and then by the word past then, so an aside opened by an adverb is no item", () => { + assert.equal(reportedWithout("Take a bus to the station, easily spotted from afar, and then ride the lift."), false); + assert.equal(reportedWith("Take a bus to the station, easily spotted from afar, and then ride the lift."), false); + assert.equal(reportedWithout("We visited Paris, Rome, and then Berlin."), true); + assert.equal(reportedWith("We visited Paris, Rome and finally Berlin."), true); + }); }); describe("excerptSpans", () => { From c850013c6289bc4a97eec97fadb5f7d153ba6a88 Mon Sep 17 00:00:00 2001 From: isamu Date: Mon, 30 Nov 2026 09:02:59 +0900 Subject: [PATCH 2/3] fix: oxford-comma-consistency keeps a run of adverb-led items ending in 'and finally' Co-Authored-By: Claude Opus 5.5 --- .../chaff/src/detectors/list-sequence-lead.ts | 20 ++++++++++++------- .../chaff/src/detectors/oxford-comma.ts | 2 +- text/test/test_oxford_not_a_list.ts | 1 + 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/text/packages/chaff/src/detectors/list-sequence-lead.ts b/text/packages/chaff/src/detectors/list-sequence-lead.ts index dd59f1bac..a4e46acce 100644 --- a/text/packages/chaff/src/detectors/list-sequence-lead.ts +++ b/text/packages/chaff/src/detectors/list-sequence-lead.ts @@ -2,18 +2,24 @@ import { shapeOf } from "./list-item.ts"; import type { ItemScope } from "./list-sentence.ts"; import type { TokenRange } from "./token-column.ts"; -/** - * and / or のすぐ後ろの順番の語(and then ride / and finally chop)を外した項目。順番の語は項目の形ではなく手順の印で、形はその後ろの語で見る。 - * Wash, peel, and then chop は動詞の 3 つ。to X, easily spotted ..., and then ride は副詞どうしが偶然揃っただけで並びではない。 - */ +/** The item after and / or without the sequence word that opens it (and then ride / and finally chop). */ const withoutSequenceLead = (scope: ItemScope, item: TokenRange): TokenRange => { const lead = scope.sentence.tokens[item.start]?.surface.toLowerCase() ?? ""; const isSequence = scope.sentence.words.sequence?.has(lead) ?? false; return item.end - item.start > 1 && isSequence ? { start: item.start + 1, end: item.end } : item; }; -/** 最後の項目と and / or の後ろの項目が同じ形なら、その形。違えば undefined。 */ -export const sharedShape = (scope: ItemScope, last: TokenRange, afterItem: TokenRange): string | undefined => { +/** + * The shape the last item and the item after and / or share, or undefined. A sequence word right after the conjunction + * marks a step, so the item is read by the word past it (We visited Paris, Rome, and then Berlin). Where the sequence + * word matches an adverb that opens the last item, the items are adverbs in a row (primarily by stage, secondarily by + * timebox, and finally by date), unless the words past it take the first item's shape: then the and / or goes on from + * the first item, past an aside (Take a bus to the station, easily spotted from afar, and then ride), and there is no list. + */ +export const sharedShape = (scope: ItemScope, first: TokenRange, last: TokenRange, afterItem: TokenRange): string | undefined => { const shape = shapeOf(scope, last); - return shape !== undefined && shape === shapeOf(scope, withoutSequenceLead(scope, afterItem)) ? shape : undefined; + const [asWritten, past] = [shapeOf(scope, afterItem), shapeOf(scope, withoutSequenceLead(scope, afterItem))]; + if (shape === undefined) return undefined; + if (asWritten === shape) return past !== asWritten && past === shapeOf(scope, first) ? undefined : shape; + return past === shape ? shape : undefined; }; diff --git a/text/packages/chaff/src/detectors/oxford-comma.ts b/text/packages/chaff/src/detectors/oxford-comma.ts index 9a9483a88..631cbc234 100644 --- a/text/packages/chaff/src/detectors/oxford-comma.ts +++ b/text/packages/chaff/src/detectors/oxford-comma.ts @@ -394,7 +394,7 @@ const listAt = (list: ItemList, at: number, walk: Walk): boolean | undefined => if (namesDivision(items) || qualifiesPrevious(items)) return undefined; const last = lastOf(items); if (last !== undefined && opensContrast(scope, last.item)) return undefined; - const shape = last === undefined || sizeOf(items) < 2 ? undefined : sharedShape(scope, last.item, afterItem); + const shape = last === undefined || sizeOf(items) < 2 ? undefined : sharedShape(scope, firstOf(items)?.item ?? last.item, last.item, afterItem); return shape !== undefined && itemsAgree(scope, items, afterItem, shape) ? commaBefore(scope, at) : undefined; }; diff --git a/text/test/test_oxford_not_a_list.ts b/text/test/test_oxford_not_a_list.ts index 1956a4b04..ed41b1cd0 100644 --- a/text/test/test_oxford_not_a_list.ts +++ b/text/test/test_oxford_not_a_list.ts @@ -145,6 +145,7 @@ describe("oxford-comma-consistency: what is not a list", () => { assert.equal(reportedWith("Take a bus to the station, easily spotted from afar, and then ride the lift."), false); assert.equal(reportedWithout("We visited Paris, Rome, and then Berlin."), true); assert.equal(reportedWith("We visited Paris, Rome and finally Berlin."), true); + assert.equal(reportedWithout("Items are sorted primarily by stage, secondarily by size, and finally by date."), true); }); }); From 40a867cfa00556c29290b5a81b216b20de0e448f Mon Sep 17 00:00:00 2001 From: isamu Date: Mon, 30 Nov 2026 13:10:41 +0900 Subject: [PATCH 3/3] fix: oxford-comma-consistency reads a clause after 'and then' as no item Co-Authored-By: Claude Opus 5.5 --- text/packages/chaff/src/detectors/list-sequence-lead.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/text/packages/chaff/src/detectors/list-sequence-lead.ts b/text/packages/chaff/src/detectors/list-sequence-lead.ts index a4e46acce..9208819e9 100644 --- a/text/packages/chaff/src/detectors/list-sequence-lead.ts +++ b/text/packages/chaff/src/detectors/list-sequence-lead.ts @@ -1,4 +1,4 @@ -import { shapeOf } from "./list-item.ts"; +import { isClause, shapeOf } from "./list-item.ts"; import type { ItemScope } from "./list-sentence.ts"; import type { TokenRange } from "./token-column.ts"; @@ -18,7 +18,10 @@ const withoutSequenceLead = (scope: ItemScope, item: TokenRange): TokenRange => */ export const sharedShape = (scope: ItemScope, first: TokenRange, last: TokenRange, afterItem: TokenRange): string | undefined => { const shape = shapeOf(scope, last); - const [asWritten, past] = [shapeOf(scope, afterItem), shapeOf(scope, withoutSequenceLead(scope, afterItem))]; + const rest = withoutSequenceLead(scope, afterItem); + // and then we rested: past the sequence word comes a clause of its own, not an item of the list. + const past = rest !== afterItem && isClause(scope, rest) ? undefined : shapeOf(scope, rest); + const asWritten = shapeOf(scope, afterItem); if (shape === undefined) return undefined; if (asWritten === shape) return past !== asWritten && past === shapeOf(scope, first) ? undefined : shape; return past === shape ? shape : undefined;