From 7fcf20e0890ac9e028fc9082bcf1bdc0cacc8e04 Mon Sep 17 00:00:00 2001 From: isamu Date: Mon, 30 Nov 2026 12:56:36 +0900 Subject: [PATCH] feat: agreement-slip reports a noun where a second verb belongs after to (to watch and photography wildlife) Co-Authored-By: Claude Opus 5.5 --- text/docs/samples/en/agreement-slip.md | 12 +++--- text/packages/chaff/rules/agreement-slip.yaml | 16 +++++--- .../chaff/src/detectors/agreement-slip.ts | 39 +++++++++++++++++-- .../lang-en/lexicons/noun-for-verb.yaml | 9 +++++ text/test/test_agreement_slip.ts | 28 +++++++++++++ 5 files changed, 89 insertions(+), 15 deletions(-) create mode 100644 text/packages/lang-en/lexicons/noun-for-verb.yaml diff --git a/text/docs/samples/en/agreement-slip.md b/text/docs/samples/en/agreement-slip.md index cbf3b750b..755e61a31 100644 --- a/text/docs/samples/en/agreement-slip.md +++ b/text/docs/samples/en/agreement-slip.md @@ -39,9 +39,9 @@ booking-email.md business/email · English genre from --genre ⚠ Words that do not agree "These new version" mixes singular and plural - A determiner and a noun that differ in number ("a significant changes", "these new version"), a possessive where the subject belongs ("Your can check"), or two determiners in a row ("the some roads"), is left over from an edit that fixed one word and not the other. The reader stumbles, and the document looks rushed. Only forms with one reading are counted; nouns spelled alike in both numbers ("series", "data"), a word right after "this" or "these" (which can stand alone), and nouns that modify another noun ("a sales team") are not. + A determiner and a noun that differ in number ("a significant changes", "these new version"), a possessive where the subject belongs ("Your can check"), two determiners in a row ("the some roads"), or a noun where a second verb belongs ("to watch and photography wildlife"), is left over from an edit that fixed one word and not the other. The reader stumbles, and the document looks rushed. Only forms with one reading are counted; nouns spelled alike in both numbers ("series", "data"), a word right after "this" or "these" (which can stand alone), and nouns that modify another noun ("a sales team") are not. - → Make the determiner and the noun agree ("a significant change" or "significant changes"). For a possessive, write the subject you meant ("Your can" becomes "You can", "their will" becomes "they will"). For two determiners in a row, drop one ("the some roads" becomes "some roads", or "that some roads" if that was meant). + → Make the determiner and the noun agree ("a significant change" or "significant changes"). For a possessive, write the subject you meant ("Your can" becomes "You can", "their will" becomes "they will"). For two determiners in a row, drop one ("the some roads" becomes "some roads", or "that some roads" if that was meant). For a noun where a verb belongs, write the verb ("photography" becomes "photograph"). Relax this rule: npx chaffjs relax agreement-slip @@ -53,9 +53,9 @@ booking-email.md business/email · English genre from --genre ⚠ Words that do not agree "a significant changes" mixes singular and plural - A determiner and a noun that differ in number ("a significant changes", "these new version"), a possessive where the subject belongs ("Your can check"), or two determiners in a row ("the some roads"), is left over from an edit that fixed one word and not the other. The reader stumbles, and the document looks rushed. Only forms with one reading are counted; nouns spelled alike in both numbers ("series", "data"), a word right after "this" or "these" (which can stand alone), and nouns that modify another noun ("a sales team") are not. + A determiner and a noun that differ in number ("a significant changes", "these new version"), a possessive where the subject belongs ("Your can check"), two determiners in a row ("the some roads"), or a noun where a second verb belongs ("to watch and photography wildlife"), is left over from an edit that fixed one word and not the other. The reader stumbles, and the document looks rushed. Only forms with one reading are counted; nouns spelled alike in both numbers ("series", "data"), a word right after "this" or "these" (which can stand alone), and nouns that modify another noun ("a sales team") are not. - → Make the determiner and the noun agree ("a significant change" or "significant changes"). For a possessive, write the subject you meant ("Your can" becomes "You can", "their will" becomes "they will"). For two determiners in a row, drop one ("the some roads" becomes "some roads", or "that some roads" if that was meant). + → Make the determiner and the noun agree ("a significant change" or "significant changes"). For a possessive, write the subject you meant ("Your can" becomes "You can", "their will" becomes "they will"). For two determiners in a row, drop one ("the some roads" becomes "some roads", or "that some roads" if that was meant). For a noun where a verb belongs, write the verb ("photography" becomes "photograph"). Relax this rule: npx chaffjs relax agreement-slip @@ -114,9 +114,9 @@ $ npx chaffjs explain agreement-slip --genre business/email Words that do not agree (agreement-slip) - A determiner and a noun that differ in number ("a significant changes", "these new version"), a possessive where the subject belongs ("Your can check"), or two determiners in a row ("the some roads"), is left over from an edit that fixed one word and not the other. The reader stumbles, and the document looks rushed. Only forms with one reading are counted; nouns spelled alike in both numbers ("series", "data"), a word right after "this" or "these" (which can stand alone), and nouns that modify another noun ("a sales team") are not. + A determiner and a noun that differ in number ("a significant changes", "these new version"), a possessive where the subject belongs ("Your can check"), two determiners in a row ("the some roads"), or a noun where a second verb belongs ("to watch and photography wildlife"), is left over from an edit that fixed one word and not the other. The reader stumbles, and the document looks rushed. Only forms with one reading are counted; nouns spelled alike in both numbers ("series", "data"), a word right after "this" or "these" (which can stand alone), and nouns that modify another noun ("a sales team") are not. - How to fix: Make the determiner and the noun agree ("a significant change" or "significant changes"). For a possessive, write the subject you meant ("Your can" becomes "You can", "their will" becomes "they will"). For two determiners in a row, drop one ("the some roads" becomes "some roads", or "that some roads" if that was meant). + How to fix: Make the determiner and the noun agree ("a significant change" or "significant changes"). For a possessive, write the subject you meant ("Your can" becomes "You can", "their will" becomes "they will"). For two determiners in a row, drop one ("the some roads" becomes "some roads", or "that some roads" if that was meant). For a noun where a verb belongs, write the verb ("photography" becomes "photograph"). Levels (there is no limit to count to; a level sets how a finding is marked): strict error diff --git a/text/packages/chaff/rules/agreement-slip.yaml b/text/packages/chaff/rules/agreement-slip.yaml index 9004b44c3..93a6acc55 100644 --- a/text/packages/chaff/rules/agreement-slip.yaml +++ b/text/packages/chaff/rules/agreement-slip.yaml @@ -15,6 +15,7 @@ extra_word_lists: misnumbered-phrase, determiner-after-article, homophone-slip, + noun-for-verb, ] severity: warning @@ -23,8 +24,8 @@ name: en: Words that do not agree why: - ja: 「a significant changes」「these new version」のように限定詞と名詞の単数・複数が食い違う文や、「Your can check」のように所有の語が主語の位置にある文や、「the some roads」のように冠詞の後ろに限定詞が続く文は、書き換えの途中で片方だけ直した跡です。読み手はつまずき、急いで書いた文書に見えます。解析器の読みが一通りに決まる形だけを数え、単数と複数が同じ綴りの語(series / data)、代名詞にも読める this / these の直後の語、名詞を重ねた語(a sales team)は数えていません。 - en: A determiner and a noun that differ in number ("a significant changes", "these new version"), a possessive where the subject belongs ("Your can check"), or two determiners in a row ("the some roads"), is left over from an edit that fixed one word and not the other. The reader stumbles, and the document looks rushed. Only forms with one reading are counted; nouns spelled alike in both numbers ("series", "data"), a word right after "this" or "these" (which can stand alone), and nouns that modify another noun ("a sales team") are not. + ja: 「a significant changes」「these new version」のように限定詞と名詞の単数・複数が食い違う文や、「Your can check」のように所有の語が主語の位置にある文や、「the some roads」のように冠詞の後ろに限定詞が続く文、「to watch and photography wildlife」のように動詞を並べる所に名詞がある文は、書き換えの途中で片方だけ直した跡です。読み手はつまずき、急いで書いた文書に見えます。解析器の読みが一通りに決まる形だけを数え、単数と複数が同じ綴りの語(series / data)、代名詞にも読める this / these の直後の語、名詞を重ねた語(a sales team)は数えていません。 + en: A determiner and a noun that differ in number ("a significant changes", "these new version"), a possessive where the subject belongs ("Your can check"), two determiners in a row ("the some roads"), or a noun where a second verb belongs ("to watch and photography wildlife"), is left over from an edit that fixed one word and not the other. The reader stumbles, and the document looks rushed. Only forms with one reading are counted; nouns spelled alike in both numbers ("series", "data"), a word right after "this" or "these" (which can stand alone), and nouns that modify another noun ("a sales team") are not. message: ja: 「{word}」で単数と複数が合っていません @@ -40,10 +41,13 @@ messages: determiner: ja: 「{word}」で、限定詞が二つ続いています en: '"{word}" puts two determiners in a row' + conjunct: + ja: 「{word}」で、動詞を並べる所に名詞があります({verb} のつもりかもしれません) + en: '"{word}" puts a noun where a second verb belongs ("{verb}" may be meant)' how_to_fix: - ja: 限定詞か名詞のどちらかに揃えてください(a significant change / significant changes)。所有の語なら、主語の語に直してください(Your can → You can、their will → they will)。限定詞が二つ続いていれば、どちらかを消してください(the some roads → some roads か that some roads)。 - en: Make the determiner and the noun agree ("a significant change" or "significant changes"). For a possessive, write the subject you meant ("Your can" becomes "You can", "their will" becomes "they will"). For two determiners in a row, drop one ("the some roads" becomes "some roads", or "that some roads" if that was meant). + ja: 限定詞か名詞のどちらかに揃えてください(a significant change / significant changes)。所有の語なら、主語の語に直してください(Your can → You can、their will → they will)。限定詞が二つ続いていれば、どちらかを消してください(the some roads → some roads か that some roads)。動詞を並べる所の名詞は、動詞に直してください(photography → photograph)。 + en: Make the determiner and the noun agree ("a significant change" or "significant changes"). For a possessive, write the subject you meant ("Your can" becomes "You can", "their will" becomes "they will"). For two determiners in a row, drop one ("the some roads" becomes "some roads", or "that some roads" if that was meant). For a noun where a verb belongs, write the verb ("photography" becomes "photograph"). levels: { strict: error, normal: warning, relaxed: info } @@ -62,5 +66,5 @@ example: after: This new version will ship in May. not_flagged: - ja: 単数と複数で形が同じ名詞(series、data)、this や these の直後の語、名詞を修飾する名詞(a sales team)、前置詞の後ろの所有の語と名詞の will や can(at its will)は指しません。homophone-slip が一覧に持つ組(their are)は、正しい語まで言うその規則が指し、ここでは指しません。 - en: Nouns spelled alike in both numbers ("series", "data"), a word right after "this" or "these", nouns that modify another noun ("a sales team"), and a possessive after a preposition with "will" or "can" as its noun ("at its will") are not reported. A pair homophone-slip lists ("their are") is reported by that rule, with the word meant, and not here. + ja: 単数と複数で形が同じ名詞(series、data)、this や these の直後の語、名詞を修飾する名詞(a sales team)、前置詞の後ろの所有の語と名詞の will や can(at its will)は指しません。homophone-slip が一覧に持つ組(their are)は、正しい語まで言うその規則が指し、ここでは指しません。to と動詞と and の後ろの名詞は、後ろに目的語が無ければ(to hike and photography.)名詞を並べた文かもしれないので指しません。 + en: Nouns spelled alike in both numbers ("series", "data"), a word right after "this" or "these", nouns that modify another noun ("a sales team"), and a possessive after a preposition with "will" or "can" as its noun ("at its will") are not reported. A pair homophone-slip lists ("their are") is reported by that rule, with the word meant, and not here. A noun after "to", a verb and "and" is not reported without an object after it ("to hike and photography."), where it may be a second noun phrase. diff --git a/text/packages/chaff/src/detectors/agreement-slip.ts b/text/packages/chaff/src/detectors/agreement-slip.ts index 8ef0d3786..387758493 100644 --- a/text/packages/chaff/src/detectors/agreement-slip.ts +++ b/text/packages/chaff/src/detectors/agreement-slip.ts @@ -28,9 +28,17 @@ export type AgreementLists = { readonly prepositions?: ReadonlySet; /** homophone-slip が言う組(their are)。その規則が正しい語まで言うので、ここでは数えない。 */ readonly homophones?: ReadonlySet; + /** 動詞の所に書いた、綴りの違う派生名詞と、意図した動詞(photography → photograph)。 */ + readonly nounForVerb?: ReadonlyMap; }; -export type Slip = { readonly variant: "number" | "possessive" | "determiner"; readonly first: Token; readonly last: Token; readonly word: string }; +export type Slip = { + readonly variant: "number" | "possessive" | "determiner" | "conjunct"; + readonly first: Token; + readonly last: Token; + readonly word: string; + readonly verb?: string; +}; const SPACE_ONLY = /^\s+$/u; const UPPER_START = /^\p{Lu}/u; @@ -221,18 +229,42 @@ const doubledDeterminerAt = (source: string, tokens: readonly Token[], at: numbe return slipOf("determiner", source, article, second); }; +/** 名詞の後ろで、目的語の頭になる品詞。名詞は目的語を取らないので、ここに立つ名詞は動詞の書き損じ。 */ +const OBJECT_START = new Set(["NOUN", "PROPN", "DET", "PRON"]); + +/** + * to と動詞の原形と and の後ろの、目的語を取る派生名詞(to safely watch and photography wildlife)。動詞を並べる所に、名詞を書いた跡。 + * 名詞の後ろに目的語が無ければ(to hike and photography.)、名詞句を並べた文かもしれないので数えない。 + */ +const conjunctSlipAt = (source: string, tokens: readonly Token[], at: number, lists: AgreementLists): Slip | undefined => { + const to = tokens[at]; + if (to === undefined || to.pos !== "PART" || lower(to) !== "to") return undefined; + const verbAt = tokens.findIndex((token, index) => index > at && token.pos !== "ADV"); + const [verb, and, noun, object] = [tokens[verbAt], tokens[verbAt + 1], tokens[verbAt + 2], tokens[verbAt + 3]]; + if (verbAt === -1 || !isBaseVerb(verb) || and === undefined || lower(and) !== "and" || !isCommonNoun(noun)) return undefined; + const meant = lists.nounForVerb?.get(lower(noun)); + if (meant === undefined || object === undefined || !OBJECT_START.has(object.pos)) return undefined; + const span = tokens.slice(at, verbAt + 3); + if (!joinedBySpace(source, span) || !joinedBySpace(source, [noun, object])) return undefined; + return { ...slipOf("conjunct", source, to, noun), verb: meant }; +}; + export const agreementIn = (source: string, tokens: readonly Token[], lists: AgreementLists): Slip[] => tokens.flatMap((_, at) => { const slip = numberSlipAt(source, tokens, at, lists) ?? possessiveSlipAt(source, tokens, at, lists) ?? misnumberedAt(source, tokens, at, lists) ?? - doubledDeterminerAt(source, tokens, at, lists); + doubledDeterminerAt(source, tokens, at, lists) ?? + conjunctSlipAt(source, tokens, at, lists); return slip === undefined ? [] : [slip]; }); const setOf = (lexicon: Lexicon | undefined): ReadonlySet => new Set((lexicon ?? []).map((entry) => entry.pattern.toLowerCase())); +const rewritesOf = (lexicon: Lexicon | undefined): ReadonlyMap => + new Map((lexicon ?? []).flatMap((entry): [string, string][] => (entry.rewrite === undefined ? [] : [[entry.pattern.toLowerCase(), entry.rewrite]]))); + const listsOf = (lexicons: Readonly>): AgreementLists => ({ singular: lexicons["singular-determiner"] ?? [], plural: lexicons["plural-determiner"] ?? [], @@ -244,6 +276,7 @@ const listsOf = (lexicons: Readonly>): AgreementLists => afterArticle: setOf(lexicons["determiner-after-article"]), prepositions: setOf(lexicons["object-preposition"]), homophones: setOf(lexicons["homophone-slip"]), + nounForVerb: rewritesOf(lexicons["noun-for-verb"]), }); export const agreementSlip: Detector = (doc): Finding[] => { @@ -255,7 +288,7 @@ export const agreementSlip: Detector = (doc): Finding[] => { line: 0, column: 0, quote: sentence.text.trim(), - values: { word: slip.word, offset: slip.first.span.start }, + values: { word: slip.word, offset: slip.first.span.start, ...(slip.verb === undefined ? {} : { verb: slip.verb }) }, variant: slip.variant, })), ); diff --git a/text/packages/lang-en/lexicons/noun-for-verb.yaml b/text/packages/lang-en/lexicons/noun-for-verb.yaml new file mode 100644 index 000000000..4ca2bb23c --- /dev/null +++ b/text/packages/lang-en/lexicons/noun-for-verb.yaml @@ -0,0 +1,9 @@ +# Nouns made from a verb whose plain form is spelled differently, typed where the verb belongs: "to watch and +# photography wildlife" means "photograph". Read by agreement-slip only after "to", a verb and "and", with an object +# following, where the noun cannot stand; rewrite is the verb meant. Nouns that often modify another noun in a +# compound ("management team", "maintenance window") are left out: after "and" they may begin a second noun phrase. +id: noun-for-verb +language: en +entries: + - pattern: photography + rewrite: photograph diff --git a/text/test/test_agreement_slip.ts b/text/test/test_agreement_slip.ts index a5e28fb82..58ad76e12 100644 --- a/text/test/test_agreement_slip.ts +++ b/text/test/test_agreement_slip.ts @@ -392,3 +392,31 @@ describe("agreement-slip — ファイル名とパス", () => { assert.deepEqual(findingsOf("These new version is out."), ["1:1 These new version"]); }); }); + +describe("agreement-slip — 動詞を並べる所の名詞", () => { + before(async () => { + await en.prepare?.({ pos: true }); + }); + + it("invalid: to と動詞と and の後ろの、目的語を取る派生名詞(to watch and photography wildlife)", () => { + assert.deepEqual(findingsOf("Learn how to safely watch and photography birds on the shore."), ["1:11 to safely watch and photography"]); + assert.deepEqual(findingsOf("We went out to find and photography the owls."), ["1:13 to find and photography"]); + }); + + it("valid: 目的語の無い名詞、動詞の photograph、名詞を並べた文", () => { + const valid = [ + "We love to hike and photography.", + "Learn how to watch and photograph birds.", + "She wanted to travel, and photography gave her a reason.", + "Tips on how to hike and photography for beginners.", + ]; + valid.forEach((text) => assert.deepEqual(findingsOf(text), [], text)); + }); + + it("names the verb meant in the message", () => { + const document = buildDocument("t.md", "Come to watch and photography the herd.", en); + const finding = runRules(document, RULES.en, {}, true, "business/report").findings.find((item) => item.rule === "agreement-slip"); + assert.equal(finding?.values["verb"], "photograph"); + assert.equal(finding?.variant, "conjunct"); + }); +});