diff --git a/text/corpus/rules-measure.json b/text/corpus/rules-measure.json index 2ea9202c3..4adcd1ddc 100644 --- a/text/corpus/rules-measure.json +++ b/text/corpus/rules-measure.json @@ -9039,6 +9039,42 @@ "cleanSamples": 12 } }, + "section-reflection-ending": { + "groups": { + "academic": { + "documents": 10, + "fired": 0 + }, + "blog": { + "documents": 23, + "fired": 0 + }, + "business": { + "documents": 80, + "fired": 0 + }, + "docs": { + "documents": 21, + "fired": 0 + }, + "legal": { + "documents": 35, + "fired": 0 + }, + "literature": { + "documents": 13, + "fired": 0 + }, + "speech": { + "documents": 7, + "fired": 0 + }, + "technical": { + "documents": 26, + "fired": 0 + } + } + }, "sentence-initial-conjunction-run": { "groups": { "academic": { diff --git a/text/docs/samples/en/README.md b/text/docs/samples/en/README.md index 7a30ec379..62a83286f 100644 --- a/text/docs/samples/en/README.md +++ b/text/docs/samples/en/README.md @@ -11,7 +11,7 @@ Or paste a draft into the [playground](https://isamu.github.io/lab/en/playground 日本語の見本: [../ja/README.md](../ja/README.md) -Rules with a sample: 268 / 268 +Rules with a sample: 269 / 269 ## Readability @@ -320,6 +320,7 @@ Traits common in generated text. None of them alone says the text was generated; | [Questions answered with a fragment](q-fragment-answer.md) (`q-fragment-answer`) | Questions the writer answers at once with a fragment ("Is it perfect? No.") | | [Everything comes in threes](rule-of-three.md) (`rule-of-three`) | Lists that almost all have exactly three items, as if padded or trimmed to fit | | [Section lengths are too uniform](section-length-uniformity.md) (`section-length-uniformity`) | Every section filled to the same size, which is what a template does | +| [Every section closes on a personal reflection](section-reflection-ending.md) (`section-reflection-ending`) | Nearly every section closing on "I think ..." or "I feel ..." | | [Monotonous sentence rhythm](sentence-rhythm.md) (`sentence-rhythm`) | Sentences that are all about the same length, so the text reads as a drone | | [Too many stock transitions](stock-transition.md) (`stock-transition`) | Too many sentences opening with "Moreover" or "Additionally" | | [Too many denials of a premise nobody stated](unprompted-denial.md) (`unprompted-denial`) | Sentences that deny a premise nobody stated ("This isn't about tooling.") | diff --git a/text/docs/samples/en/section-reflection-ending.md b/text/docs/samples/en/section-reflection-ending.md new file mode 100644 index 000000000..baeed0577 --- /dev/null +++ b/text/docs/samples/en/section-reflection-ending.md @@ -0,0 +1,186 @@ + + +# Every section closes on a personal reflection (`section-reflection-ending`) + +**Where it helps:** personal blog posts, trip and event reports, newsletter columns. Especially a draft written to a prompt. + +## Original + +```markdown chaff-before +# Cycling to work + +## Mornings + +The ride to the station takes about ten minutes. I think the fresh air is the best part of the day. + +## Evenings + +The way home has more hills, and my legs ached the first week. I feel it has become good exercise. + +## Rainy days + +On rainy days I take the train. I believe not forcing it is what keeps a habit going. + +## Money + +I save about eighty dollars a month on the train pass. I think small savings add up. +``` + +## What chaff says + +```text chaff-output +$ npx chaffjs --no-guide --genre blog/essay post.md + +post.md blog/essay · English genre from --genre + +─── line 5 ─────────────────────────────────────────────────── + + The ride to the station takes about ten minutes. + + ⚠ Monotonous sentence rhythm + + Sentence length varies by only 24% (want 30%) + When every sentence is the same length, the reader loses the rhythm. It is also a common shape of generated text. + + → Mix in short sentences. Splitting one in two is enough. + + Relax this rule: npx chaffjs relax sentence-rhythm + + +─── line 5 ─────────────────────────────────────────────────── + + I think the fresh air is the best part of the day. + + · Every section closes on a personal reflection + + "I think" and other reflections close 4 of 4 sections (100%, 50% needed) + Closing a section with "I think ..." or "I feel ..." is ordinary in essays and reports. When nearly every section closes that way, it reads as a template that adds a line of feeling after the content, a shape common in generated text. + + → Drop the reflection, or close the section on what it found (a number, what happened, what comes next). Keep a reflection only where it matters most. + + Relax this rule: npx chaffjs relax section-reflection-ending + + +─── line 9 ─────────────────────────────────────────────────── + + I feel it has become good exercise. + + · Every section closes on a personal reflection + + "I feel" and other reflections close 4 of 4 sections (100%, 50% needed) + Closing a section with "I think ..." or "I feel ..." is ordinary in essays and reports. When nearly every section closes that way, it reads as a template that adds a line of feeling after the content, a shape common in generated text. + + → Drop the reflection, or close the section on what it found (a number, what happened, what comes next). Keep a reflection only where it matters most. + + Relax this rule: npx chaffjs relax section-reflection-ending + + +─── line 13 ────────────────────────────────────────────────── + + I believe not forcing it is what keeps a habit going. + + · Every section closes on a personal reflection + + "I believe" and other reflections close 4 of 4 sections (100%, 50% needed) + Closing a section with "I think ..." or "I feel ..." is ordinary in essays and reports. When nearly every section closes that way, it reads as a template that adds a line of feeling after the content, a shape common in generated text. + + → Drop the reflection, or close the section on what it found (a number, what happened, what comes next). Keep a reflection only where it matters most. + + Relax this rule: npx chaffjs relax section-reflection-ending + + +─── line 17 ────────────────────────────────────────────────── + + I think small savings add up. + + · Every section closes on a personal reflection + + "I think" and other reflections close 4 of 4 sections (100%, 50% needed) + Closing a section with "I think ..." or "I feel ..." is ordinary in essays and reports. When nearly every section closes that way, it reads as a template that adds a line of feeling after the content, a shape common in generated text. + + → Drop the reflection, or close the section on what it found (a number, what happened, what comes next). Keep a reflection only where it matters most. + + Relax this rule: npx chaffjs relax section-reflection-ending + + +──────────────────────────────────────────────────────────── + + 1 warning, 4 notes All judged by machine + (the same text gives the same result every time) + + The text was not changed. Fixing it is the writer's job. +``` + +## Revised + +```markdown chaff-after +# Cycling to work + +## Mornings + +The ride to the station takes about ten minutes. I leave home five minutes later. + +## Evenings + +The way home has more hills, and my legs ached the first week. Not now. + +## Rainy days + +On rainy days I take the train, which last month meant six days out of the twenty I worked. + +## Money + +I save about eighty dollars a month on the train pass. The bike pays for itself in a year and a half. +``` + +## How to fix + +Each of the four sections closes on "I think ...", "I feel ..." or "I believe ...". +Closing one section on a reflection is ordinary; closing every one the same way reads as a template that adds a line of feeling after the content. + +The revision replaces each reflection with what the section found: the time of leaving, when the aching stopped, the number of rainy days, how long the bike takes to pay for itself. +If a reflection matters, keep it in the one section where it matters most. + +## Settings + +It reports once half or more of the sections close on a reflection. + +```yaml chaff-settings +rules: + section-reflection-ending: strict +``` + +`strict` reports from 40%, `relaxed` from 67%. +A document with fewer than 4 sections that hold a paragraph is not measured. + +```text chaff-explain +$ npx chaffjs explain section-reflection-ending --genre blog/essay + + Every section closes on a personal reflection (section-reflection-ending) + + Closing a section with "I think ..." or "I feel ..." is ordinary in essays and reports. When nearly every section closes that way, it reads as a template that adds a line of feeling after the content, a shape common in generated text. + + How to fix: Drop the reflection, or close the section on what it found (a number, what happened, what comes next). Keep a reflection only where it matters most. + + Levels: + strict reported when 40% or more of the sections close on a reflection + → normal reported when 50% or more of the sections close on a reflection + relaxed reported when 67% or more of the sections close on a reflection + off not checked + + Options (set under options in chaff.yaml): + min_sections: 4 (default) + The fewest sections measured. With few sections, one or two reflective closings make a large share, and a person's writing is reported too + + Set one: write options: { section-reflection-ending: { : } } in chaff.yaml + + Now: normal. + + Change it: npx chaffjs relax section-reflection-ending --why "reason" +``` + +[All samples](README.md) diff --git a/text/docs/samples/ja/README.md b/text/docs/samples/ja/README.md index b2ad77cc3..6518cb8f0 100644 --- a/text/docs/samples/ja/README.md +++ b/text/docs/samples/ja/README.md @@ -11,7 +11,7 @@ chaff が見つけるまちがいを、ルールごとに一つずつ見本に English samples: [../en/README.md](../en/README.md) -見本のあるルール: 282 / 282 +見本のあるルール: 283 / 283 ## 読みやすさ @@ -333,6 +333,7 @@ English samples: [../en/README.md](../en/README.md) | [段落の長さが揃いすぎている](paragraph-length-variance.md)(`paragraph-length-variance`) | どの段落もほぼ同じ長さで、型に流しこんだように見える所 | | [3 項目の箇条書きばかり](rule-of-three.md)(`rule-of-three`) | 箇条書きがどれも三つの項目で、数を合わせて並べたように見える所 | | [節の長さが揃いすぎている](section-length-uniformity.md)(`section-length-uniformity`) | どの節もほぼ同じ長さに埋めてあり、ひな形を埋めたように見える所 | +| [どの節も所感の文で閉じる](section-reflection-ending.md)(`section-reflection-ending`) | 「〜と思います」「〜と感じています」のように、節のほとんどが所感の文で閉じている所 | | [文の長さが単調](sentence-rhythm.md)(`sentence-rhythm`) | どの文もほぼ同じ長さで、読むリズムが単調な所 | | [決まった接ぎで始まる文が多い](stock-transition.md)(`stock-transition`) | 「さらに」「加えて」「このように」で始まる文が多く、何がどう繋がるのかを言わずに並べている所 | | [翻訳調が多い](translationese-density.md)(`translationese-density`) | 「〜を可能にする」「重要な役割を果たす」「あなたは」のような、英語の構文を写した言い回しが多い所 | diff --git a/text/docs/samples/ja/section-reflection-ending.md b/text/docs/samples/ja/section-reflection-ending.md new file mode 100644 index 000000000..ca2557a9b --- /dev/null +++ b/text/docs/samples/ja/section-reflection-ending.md @@ -0,0 +1,186 @@ + + +# どの節も所感の文で閉じる(`section-reflection-ending`) + +**こんな文書に:** ブログの体験記、出張や展示会の報告、社内報のコラム。とくに AI に下書きを頼んだ文章に出やすい型です。 + +## 元の文章 + +```markdown chaff-before +# 自転車通勤を始めて + +## 朝 + +駅まで歩いていた道を、自転車で十分ほど走ります。朝の空気が気持ちよく、続けてよかったと思います。 + +## 帰り + +帰りは坂が多く、最初の週は脚が張りました。いまは慣れて、いい運動になっていると感じています。 + +## 雨の日 + +雨の日は電車にしています。無理をしないことが、長く続けるこつかもしれません。 + +## お金 + +定期代が月に八千円ほど浮きました。小さな額でも、積み重なると大きいと思います。 +``` + +## chaff の指摘 + +```text chaff-output +$ npx chaffjs --no-guide --genre blog/essay post.md + +post.md blog/essay · 日本語 ジャンルは --genre から + +─── 5 行目 ─────────────────────────────────────────────────── + + 駅まで歩いていた道を、自転車で十分ほど走ります。 + + ⚠ 文の長さが単調 + + 文の長さのばらつきが 19%(36% 以上ほしい) + どの文も同じ長さだと、読者は途中で読むリズムを失います。生成された文章によく出る形でもあります。 + + → 短い文をいくつか混ぜてください。1 文を 2 つに割るだけで変わります。 + + このルールをゆるめる: npx chaffjs relax sentence-rhythm + + +─── 5 行目 ─────────────────────────────────────────────────── + + 朝の空気が気持ちよく、続けてよかったと思います。 + + · どの節も所感の文で閉じる + + 「と思います」など、4 節のうち 4 節が所感の文で閉じています(100%、50% から) + 「〜と思います」「〜と感じています」で節を閉じるのは、人の随筆や報告にも普通にある書き方です。ただ、節のほとんどが同じように所感で閉じると、中身を書いたあとに感想を一文足す型に見え、生成文によくある形です。 + + → 所感の文を消すか、その節で分かったこと(数字、起きたこと、次にすること)で閉じてください。感想を残すなら、一番言いたい節だけにします。 + + このルールをゆるめる: npx chaffjs relax section-reflection-ending + + +─── 9 行目 ─────────────────────────────────────────────────── + + いまは慣れて、いい運動になっていると感じています。 + + · どの節も所感の文で閉じる + + 「と感じています」など、4 節のうち 4 節が所感の文で閉じています(100%、50% から) + 「〜と思います」「〜と感じています」で節を閉じるのは、人の随筆や報告にも普通にある書き方です。ただ、節のほとんどが同じように所感で閉じると、中身を書いたあとに感想を一文足す型に見え、生成文によくある形です。 + + → 所感の文を消すか、その節で分かったこと(数字、起きたこと、次にすること)で閉じてください。感想を残すなら、一番言いたい節だけにします。 + + このルールをゆるめる: npx chaffjs relax section-reflection-ending + + +─── 13 行目 ────────────────────────────────────────────────── + + 無理をしないことが、長く続けるこつかもしれません。 + + · どの節も所感の文で閉じる + + 「かもしれません」など、4 節のうち 4 節が所感の文で閉じています(100%、50% から) + 「〜と思います」「〜と感じています」で節を閉じるのは、人の随筆や報告にも普通にある書き方です。ただ、節のほとんどが同じように所感で閉じると、中身を書いたあとに感想を一文足す型に見え、生成文によくある形です。 + + → 所感の文を消すか、その節で分かったこと(数字、起きたこと、次にすること)で閉じてください。感想を残すなら、一番言いたい節だけにします。 + + このルールをゆるめる: npx chaffjs relax section-reflection-ending + + +─── 17 行目 ────────────────────────────────────────────────── + + 小さな額でも、積み重なると大きいと思います。 + + · どの節も所感の文で閉じる + + 「と思います」など、4 節のうち 4 節が所感の文で閉じています(100%、50% から) + 「〜と思います」「〜と感じています」で節を閉じるのは、人の随筆や報告にも普通にある書き方です。ただ、節のほとんどが同じように所感で閉じると、中身を書いたあとに感想を一文足す型に見え、生成文によくある形です。 + + → 所感の文を消すか、その節で分かったこと(数字、起きたこと、次にすること)で閉じてください。感想を残すなら、一番言いたい節だけにします。 + + このルールをゆるめる: npx chaffjs relax section-reflection-ending + + +──────────────────────────────────────────────────────────── + + 注意 1 件、参考 4 件 すべて機械による判定です + (同じ文章なら何度実行しても同じ結果になります) + + 文章は書き換えていません。直すのは書いた人です。 +``` + +## 直した文章 + +```markdown chaff-after +# 自転車通勤を始めて + +## 朝 + +駅まで歩いていた道を、自転車で十分ほど走ります。家を出るのは五分遅くなりました。 + +## 帰り + +帰りは坂が多く、最初の週は脚が張りました。二週目には治りました。いまは平気です。 + +## 雨の日 + +雨の日は電車です。先月は、雨で自転車に乗れなかった日が月のうち六日ありました。 + +## お金 + +定期代が月に八千円ほど浮きました。自転車の代金は、一年半で元が取れる計算です。 +``` + +## 直し方 + +元の文章は、四つの節がどれも「〜と思います」「〜と感じています」「〜かもしれません」で閉じています。 +一つの節を所感で閉じるのは人もよく書きますが、どの節も同じように閉じると、中身を書いたあとに感想を一文足す型に見えます。 + +直した文章では、所感の文を、その節で分かったこと(家を出る時刻、脚の張りが治った時期、雨の日数、元が取れるまでの期間)に置き換えました。 +感想を残したい節があれば、一番言いたい節だけに残します。 + +## 設定 + +節のうち半分以上が所感の文で閉じると指摘します。 + +```yaml chaff-settings +rules: + section-reflection-ending: strict +``` + +`strict` にすると 40% から、`relaxed` は 67% からです。 +段落のある節が 4 つより少ない文書は測りません。 + +```text chaff-explain +$ npx chaffjs explain section-reflection-ending --genre blog/essay + + どの節も所感の文で閉じる (section-reflection-ending) + + 「〜と思います」「〜と感じています」で節を閉じるのは、人の随筆や報告にも普通にある書き方です。ただ、節のほとんどが同じように所感で閉じると、中身を書いたあとに感想を一文足す型に見え、生成文によくある形です。 + + 直しかた: 所感の文を消すか、その節で分かったこと(数字、起きたこと、次にすること)で閉じてください。感想を残すなら、一番言いたい節だけにします。 + + 設定できる値: + strict 所感の文で閉じる節が 40% 以上なら指摘 + → normal 所感の文で閉じる節が 50% 以上なら指摘 + relaxed 所感の文で閉じる節が 67% 以上なら指摘 + off 見ない + + オプション(chaff.yaml の options で決めます): + min_sections: 4 (既定) + 測る節の数の下限。節が少ないと、所感で閉じる節が 1 つ 2 つでも割合が大きく出て、人の書いた文書でも当たります + + 決める: chaff.yaml に options: { section-reflection-ending: { <名前>: <値> } } を書く + + いまは normal です。 + + 変える: npx chaffjs relax section-reflection-ending --why "理由" +``` + +[見本の一覧へ](README.md) diff --git a/text/packages/chaff/README.ja.md b/text/packages/chaff/README.ja.md index 344bdda5e..392360d8b 100644 --- a/text/packages/chaff/README.ja.md +++ b/text/packages/chaff/README.ja.md @@ -256,7 +256,7 @@ npx chaffjs ai-score article.md 低・中・高と、出てい npx chaffjs ai-score article.md --format json 同じものを JSON で ``` -短すぎる文書は測らず、そう言います。目印の一つが `email-stock-courtesy` で、英文のメールに「I hope this email finds you well」「I apologize for any inconvenience」のような決まり文句が 2 つ以上重なった所を言います。`honesty-marker` は、「正直、」「正直に言うと」「if I'm being honest」のように本音だと前置きする言い回しを、ブログと業務文書では 1 つでも言います。もう一つの例が `closing-exhortation` で、「ぜひ〜してみてください」「きっと〜はずです」のように結びで読み手を励ます文が 2 つ以上重なった所を言います。`cold-open` は、状況も例もないまま、短い願い(「〜に任せたい。」)、前の文の語の引き直し(この「だいたい」が)、難所の予告(「それだけのことに見えて」)が書き出しに重なった所を言います。`unprompted-denial` は、「〜の話ではありません」「〜の材料になりません」のように、誰も言っていない前提を打ち消して終わる文が多い所を言います。 +短すぎる文書は測らず、そう言います。目印の一つが `email-stock-courtesy` で、英文のメールに「I hope this email finds you well」「I apologize for any inconvenience」のような決まり文句が 2 つ以上重なった所を言います。`honesty-marker` は、「正直、」「正直に言うと」「if I'm being honest」のように本音だと前置きする言い回しを、ブログと業務文書では 1 つでも言います。もう一つの例が `closing-exhortation` で、「ぜひ〜してみてください」「きっと〜はずです」のように結びで読み手を励ます文が 2 つ以上重なった所を言います。`cold-open` は、状況も例もないまま、短い願い(「〜に任せたい。」)、前の文の語の引き直し(この「だいたい」が)、難所の予告(「それだけのことに見えて」)が書き出しに重なった所を言います。`section-reflection-ending` は、「〜と思います」「〜と感じています」のように、節のほとんどが所感の文で閉じている所を言います。`unprompted-denial` は、「〜の話ではありません」「〜の材料になりません」のように、誰も言っていない前提を打ち消して終わる文が多い所を言います。 ## AI の評価に使う(chaff grade) @@ -368,7 +368,8 @@ rule the rewrite raised; `npx chaffjs test --checks ai-tells` asks about text that human documents of the same genre rarely show. It is not a verdict on whether AI wrote it. One sign is `email-stock-courtesy`: two or more stock email courtesies in one English email. `honesty-marker`: a sentence flagged as candid ("Honestly,", 「正直、」), reported alone in blog posts and business documents. -`closing-exhortation`: a closing that cheers the reader on two or more times. `unprompted-denial`: many sentences that +`closing-exhortation`: a closing that cheers the reader on two or more times. `section-reflection-ending`: nearly every +section closing on a personal reflection ("I think ...", 「〜と思います」). `unprompted-denial`: many sentences that deny a premise nobody stated ("This isn't about tooling."). **AI evals.** `npx chaffjs grade outputs.jsonl --out results.jsonl` grades a JSONL file of a model's outputs (`id` and diff --git a/text/packages/chaff/README.md b/text/packages/chaff/README.md index 51fbd71bc..49fbcc19f 100644 --- a/text/packages/chaff/README.md +++ b/text/packages/chaff/README.md @@ -210,7 +210,8 @@ it is not meant to be one. Among the signs: `email-stock-courtesy`, two or more ("I hope this email finds you well", "I apologize for any inconvenience") in one English email; `honesty-marker`, a sentence flagged as candid ("Honestly,", "if I'm being honest", 「正直、」), reported alone in blog posts and business documents; `closing-exhortation`, a closing that cheers the reader on two or more times ("You've got this", 「ぜひ〜してみてください」); `cold-open`, an opening that piles a bare wish, a word of -the previous sentence repeated in quotes, and a teaser ("Sounds simple. It isn't.") before any situation or example; and +the previous sentence repeated in quotes, and a teaser ("Sounds simple. It isn't.") before any situation or example; `section-reflection-ending`, nearly every section closing on a +personal reflection ("I think ...", 「〜と思います」); and `unprompted-denial`, many sentences that deny a premise nobody stated ("This isn't about tooling.", 「〜の話ではありません」). ## Grading a model's output diff --git a/text/packages/chaff/rules/section-reflection-ending.yaml b/text/packages/chaff/rules/section-reflection-ending.yaml new file mode 100644 index 000000000..758aad55b --- /dev/null +++ b/text/packages/chaff/rules/section-reflection-ending.yaml @@ -0,0 +1,125 @@ +id: section-reflection-ending +layer: L2 +status: stable +how_to_find: section-reflection-ending +word_list: section-reflection-ending +uses: [pos] +severity: info + +name: + ja: どの節も所感の文で閉じる + en: Every section closes on a personal reflection + +why: + ja: 「〜と思います」「〜と感じています」で節を閉じるのは、人の随筆や報告にも普通にある書き方です。ただ、節のほとんどが同じように所感で閉じると、中身を書いたあとに感想を一文足す型に見え、生成文によくある形です。 + en: Closing a section with "I think ..." or "I feel ..." is ordinary in essays and reports. When nearly every section closes that way, it reads as a template that adds a line of feeling after the content, a shape common in generated text. + +message: + ja: 「{matched}」など、{sections} 節のうち {count} 節が所感の文で閉じています({share}%、{limit}% から) + en: '"{matched}" and other reflections close {count} of {sections} sections ({share}%, {limit}% needed)' + +how_to_fix: + ja: 所感の文を消すか、その節で分かったこと(数字、起きたこと、次にすること)で閉じてください。感想を残すなら、一番言いたい節だけにします。 + en: Drop the reflection, or close the section on what it found (a number, what happened, what comes next). Keep a reflection only where it matters most. + +# 所感の文で閉じる節の割合(%)。人の文書で測った割合の最も高いものより上に置く(rules:measure の人の文書と、isamu/chaff-corpus の人の文書)。 +levels: { strict: 40, normal: 50, relaxed: 67 } + +options: + min_sections: + kind: count + default: 4 + about: + ja: 測る節の数の下限。節が少ないと、所感で閉じる節が 1 つ 2 つでも割合が大きく出て、人の書いた文書でも当たります + en: The fewest sections measured. With few sections, one or two reflective closings make a large share, and a person's writing is reported too + +use_for: [technical/readme, blog, business, legal, docs, academic, literature, speech] + +group: ai-tells +summary: + ja: 「〜と思います」「〜と感じています」のように、節のほとんどが所感の文で閉じている所 + en: Nearly every section closing on "I think ..." or "I feel ..." +example: + ja: + config: { genre: blog/essay } + before: | + # 自転車通勤を始めて + + ## 朝 + + 駅まで歩いていた道を、自転車で十分ほど走ります。朝の空気が気持ちよく、続けてよかったと思います。 + + ## 帰り + + 帰りは坂が多く、最初の週は脚が張りました。いまは慣れて、いい運動になっていると感じています。 + + ## 雨の日 + + 雨の日は電車にしています。無理をしないことが、長く続けるこつかもしれません。 + + ## お金 + + 定期代が月に八千円ほど浮きました。小さな額でも、積み重なると大きいと思います。 + after: | + # 自転車通勤を始めて + + ## 朝 + + 駅まで歩いていた道を、自転車で十分ほど走ります。家を出るのは五分遅くなりました。 + + ## 帰り + + 帰りは坂が多く、最初の週は脚が張りました。二週目には治りました。いまは平気です。 + + ## 雨の日 + + 雨の日は電車です。先月は、雨で自転車に乗れなかった日が月のうち六日ありました。 + + ## お金 + + 定期代が月に八千円ほど浮きました。自転車の代金は、一年半で元が取れる計算です。 + en: + config: { genre: blog/essay } + before: | + # Cycling to work + + ## Mornings + + The ride to the station takes about ten minutes. I think the fresh air is the best part of the day. + + ## Evenings + + The way home has more hills, and my legs ached the first week. I feel it has become good exercise. + + ## Rainy days + + On rainy days I take the train. I believe not forcing it is what keeps a habit going. + + ## Money + + I save about eighty dollars a month on the train pass. I think small savings add up. + after: | + # Cycling to work + + ## Mornings + + The ride to the station takes about ten minutes. I leave home five minutes later. + + ## Evenings + + The way home has more hills, and my legs ached the first week. Not now. + + ## Rainy days + + On rainy days I take the train, which last month meant six days out of the twenty I worked. + + ## Money + + I save about eighty dollars a month on the train pass. The bike pays for itself in a year and a half. + +not_flagged: + ja: 所感で閉じる節が一つでも、節のうち割合が上限より低ければ言いません。節(段落のある節)が 4 より少ない文書は測りません(min_sections で変えられます)。見るのは、節の最後の段落の最後の文だけです。箇条書きだけの節は数えません。 + en: A reflection closing one section, or a share below the limit, is not reported. A document with fewer than 4 sections that hold a paragraph is not measured (min_sections changes it). Only the last sentence of a section's last paragraph is read; a section of only a list is not counted. +level_meaning: + ja: 所感の文で閉じる節が {limit}% 以上なら指摘 + en: reported when {limit}% or more of the sections close on a reflection diff --git a/text/packages/chaff/skills/chaff/SKILL.md b/text/packages/chaff/skills/chaff/SKILL.md index 15eee729a..e60c26f2e 100644 --- a/text/packages/chaff/skills/chaff/SKILL.md +++ b/text/packages/chaff/skills/chaff/SKILL.md @@ -227,6 +227,7 @@ chaff marks the shapes common in generated text (group "Signs of generated text" you well"-type courtesies), `honesty-marker` ("Honestly,", 「正直、」: one is reported in blog posts and business documents), `closing-exhortation` (a closing that cheers the reader on: 「ぜひ〜してみてください」, "You've got this"), `cold-open` (an opening that piles a bare wish, a quoted echo of the previous sentence and a teaser), +`section-reflection-ending` (nearly every section closing on a personal reflection: 「〜と思います」, "I think ..."), `unprompted-denial` (sentences that deny a premise nobody stated: 「〜の話ではありません」, "This isn't about tooling."), and the signals `ai-generated-composite` reads, among others). Most of them do not run in `technical/spec` or in the legal, docs, literature and speech genres; `assistant-residue` (words left from a pasted chat reply) runs in almost every genre. `npx chaffjs rules --json` diff --git a/text/packages/chaff/src/ai-score/human-shares.ts b/text/packages/chaff/src/ai-score/human-shares.ts index 36f5449c3..f9dc7a238 100644 --- a/text/packages/chaff/src/ai-score/human-shares.ts +++ b/text/packages/chaff/src/ai-score/human-shares.ts @@ -226,6 +226,16 @@ export const HUMAN_SHARES: HumanShares = { speech: { documents: 7, fired: 0 }, technical: { documents: 26, fired: 0 }, }, + "section-reflection-ending": { + academic: { documents: 10, fired: 0 }, + blog: { documents: 23, fired: 0 }, + business: { documents: 80, fired: 0 }, + docs: { documents: 21, fired: 0 }, + legal: { documents: 35, fired: 0 }, + literature: { documents: 13, fired: 0 }, + speech: { documents: 7, fired: 0 }, + technical: { documents: 26, fired: 0 }, + }, "sentence-rhythm": { academic: { documents: 10, fired: 0 }, blog: { documents: 23, fired: 1 }, diff --git a/text/packages/chaff/src/detectors/registry/section-reflection-ending.ts b/text/packages/chaff/src/detectors/registry/section-reflection-ending.ts new file mode 100644 index 000000000..5b3be2cec --- /dev/null +++ b/text/packages/chaff/src/detectors/registry/section-reflection-ending.ts @@ -0,0 +1,4 @@ +import type { Detector } from "../../plugin.ts"; +import { sectionReflectionEnding } from "../section-reflection-ending.ts"; + +export const detector: Detector = sectionReflectionEnding; diff --git a/text/packages/chaff/src/detectors/section-reflection-ending.ts b/text/packages/chaff/src/detectors/section-reflection-ending.ts new file mode 100644 index 000000000..fab2a4555 --- /dev/null +++ b/text/packages/chaff/src/detectors/section-reflection-ending.ts @@ -0,0 +1,50 @@ +import type { Detector, DetectorOptions, Finding, Lexicon, Paragraph, ProseDocument, Sentence } from "../plugin.ts"; +import { entryCloses, entryOpens } from "./lexicon-match.ts"; + +// 節を所感の文(〜と思います、〜と感じています、I think ...)で閉じる節が、節のうちどれだけあるか。語はどれも語彙表が持ち、 +// ここは組み方だけを知る。語彙表の group: +// end 文の終わりの語(と思います、かもしれない) +// open 文頭の語(I think、I feel) + +const END = "end"; +const OPEN = "open"; +const DEFAULT_MIN_SECTIONS = 4; +const PERCENT = 100; + +/** 文が所感の文なら、当たった語。 */ +export const reflectionIn = (sentence: Sentence, lexicon: Lexicon): string | undefined => + lexicon.find((entry) => (entry.group === OPEN ? entryOpens(sentence, entry) : entry.group === END && entryCloses(sentence, entry)))?.pattern; + +/** 節を閉じる文:節の中の最後の段落の、最後の文。段落の無い節(見出しと箇条書きだけ)は数えない。 */ +export const sectionClosers = (doc: Pick): Sentence[] => + doc.sections.flatMap((section) => { + const last = doc.paragraphs.filter((paragraph: Paragraph) => paragraph.span.start >= section.span.start && paragraph.span.start < section.span.end).at(-1); + const closer = last?.sentences.at(-1); + return closer === undefined ? [] : [closer]; + }); + +const minimumSections = (options: DetectorOptions): number => { + const value = options.settings?.["min_sections"]; + return typeof value === "number" ? value : DEFAULT_MIN_SECTIONS; +}; + +/** 所感で閉じる節の割合(%)が limit 以上なら、その文ごとに一つ。節が min_sections より少ない文書は測らない。 */ +export const sectionReflectionEnding: Detector = (doc, options): Finding[] => { + const lexicon = options.lexicon ?? []; + const closers = sectionClosers(doc); + if (closers.length < minimumSections(options)) return []; + const hits = closers.flatMap((sentence) => { + const matched = reflectionIn(sentence, lexicon); + return matched === undefined ? [] : [{ sentence, matched }]; + }); + const share = Math.round((hits.length * PERCENT) / closers.length); + if (hits.length === 0 || share < options.limit) return []; + return hits.map((hit) => ({ + rule: "", + severity: "info", + line: 0, + column: 0, + quote: hit.sentence.text.trim(), + values: { matched: hit.matched, count: hits.length, sections: closers.length, share, limit: options.limit, offset: hit.sentence.span.start }, + })); +}; diff --git a/text/packages/lang-en/lexicons/section-reflection-ending.yaml b/text/packages/lang-en/lexicons/section-reflection-ending.yaml new file mode 100644 index 000000000..d7fe2d769 --- /dev/null +++ b/text/packages/lang-en/lexicons/section-reflection-ending.yaml @@ -0,0 +1,24 @@ +# A sentence of personal reflection closing a section. Groups as section-reflection-ending.ts reads them: open, the +# sentence opens with the words ("I think ..."); end, it ends with them ("..., I think."). +# One is ordinary in an essay or a report; only many sections closing so are counted. +id: section-reflection-ending +language: en +entries: + - pattern: I think + group: open + - pattern: I feel + group: open + - pattern: I believe + group: open + - pattern: I suspect + group: open + - pattern: I'd say + group: open + - pattern: Personally + group: open + - pattern: I think + group: end + - pattern: I feel + group: end + - pattern: I believe + group: end diff --git a/text/packages/lang-ja/lexicons/section-reflection-ending.yaml b/text/packages/lang-ja/lexicons/section-reflection-ending.yaml new file mode 100644 index 000000000..70ffad44a --- /dev/null +++ b/text/packages/lang-ja/lexicons/section-reflection-ending.yaml @@ -0,0 +1,49 @@ +# 節を閉じる所感の文。group は section-reflection-ending.ts の組み方(end:文がこの語で終わる)。 +# 一つずつなら人の随筆や報告にも普通にある結び方で、節のうち多くがこれで閉じるときだけ数える。 +id: section-reflection-ending +language: ja +entries: + - pattern: と思います + group: end + - pattern: と思う + group: end + - pattern: と思いました + group: end + - pattern: と思った + group: end + - pattern: 思っています + group: end + - pattern: 思っている + group: end + - pattern: と感じます + group: end + - pattern: と感じる + group: end + - pattern: と感じています + group: end + - pattern: と感じている + group: end + - pattern: と感じました + group: end + - pattern: と感じた + group: end + - pattern: と考えます + group: end + - pattern: と考える + group: end + - pattern: と考えています + group: end + - pattern: と考えている + group: end + - pattern: 気がします + group: end + - pattern: 気がする + group: end + - pattern: 気がしています + group: end + - pattern: 気がしている + group: end + - pattern: かもしれません + group: end + - pattern: かもしれない + group: end diff --git a/text/site/src/content/guide/en/ai-sounding-examples.md b/text/site/src/content/guide/en/ai-sounding-examples.md index 390e99f63..dc0b7c3bc 100644 --- a/text/site/src/content/guide/en/ai-sounding-examples.md +++ b/text/site/src/content/guide/en/ai-sounding-examples.md @@ -434,7 +434,7 @@ The quick AI-likeness score (`ai-score`) compares the article before and after. $ npx chaffjs ai-score ai.md rewritten.md --genre blog/tech ai.md AI-likeness: high (more signs than human-written documents (Blog)) - 8 signs (of 32 compared, ones 90% of human documents do not show); medium from 3, high from 5 + 8 signs (of 33 compared, ones 90% of human documents do not show); medium from 3, high from 5 Not a verdict on whether AI wrote it: how many signs common in generated text show, compared with human documents. Wording and shape @@ -445,7 +445,7 @@ Wording and shape ✗ Too many contrast frames: 3 in 0 of 23 human-written documents (Blog) ✗ Everything comes in threes: 1 in 0 of 23 human-written documents (Blog) ✗ Several signals of generated text together: 6 of its signals (Phrasing common in generated text, Everything comes in threes, Cliched closing, Too many contrast frames, Too many sentences that announce before they say, Bold emphasis scattered through the text); from 2, its strict level, that is one more sign - · the other 19 did not show + · the other 20 did not show not compared (no human baseline): Stock email courtesies piled up, Too many sweeping claims about people, Questions answered with a fragment Structure (against human articles) @@ -454,11 +454,11 @@ Structure (against human articles) rewritten.md AI-likeness: low (about as many signs as human-written documents (Blog)) - 1 sign (of 31 compared, ones 90% of human documents do not show); medium from 3, high from 5 + 1 sign (of 32 compared, ones 90% of human documents do not show); medium from 3, high from 5 Not a verdict on whether AI wrote it: how many signs common in generated text show, compared with human documents. Wording and shape - · the other 25 did not show + · the other 26 did not show not compared (no human baseline): Stock email courtesies piled up, Too many sweeping claims about people, Questions answered with a fragment Structure (against human articles) diff --git a/text/site/src/content/guide/en/ai-sounding.md b/text/site/src/content/guide/en/ai-sounding.md index c913d3751..661ef1627 100644 --- a/text/site/src/content/guide/en/ai-sounding.md +++ b/text/site/src/content/guide/en/ai-sounding.md @@ -135,6 +135,7 @@ Legal documents, manuals, literature and transcripts are written differently, so | `email-stock-courtesy` | Two or more stock email courtesies in one email ("I hope this email finds you well", "I apologize for any inconvenience") (English documents only) | | `honesty-marker` | A sentence flagged as candid ("Honestly,", "if I'm being honest", "my honest take"); one is reported (blog posts and business documents only) | | `closing-exhortation` | A closing that cheers the reader on or promises the outcome, two or more times ("You've got this", "Happy baking!") | +| `section-reflection-ending` | Half or more of the sections closing on a personal reflection ("I think ...", "I feel ..."), in a document with at least 4 sections that hold a paragraph | | `cold-open` | An opening with no situation or example that piles a bare wish ("You want to ..."), a word of the previous sentence repeated in quotes ("That 'almost' is the problem") and a teaser ("Sounds simple. It isn't.") | | `chat-citation-residue` | Marks a pasted chat answer leaves: links ending in "?utm_source=chatgpt.com", "oaicite" | | `closing-cliche` | A stock closing ("In conclusion", "I hope this helps") | diff --git a/text/site/src/content/guide/en/commands.md b/text/site/src/content/guide/en/commands.md index b196f5012..ceb5572d6 100644 --- a/text/site/src/content/guide/en/commands.md +++ b/text/site/src/content/guide/en/commands.md @@ -492,8 +492,8 @@ Three signs make "medium" and five make "high". It does not say whether AI wrote ``` $ npx chaffjs ai-score before.md after.md --compact -before.md: ai-score high 8/32 ai-tell announcing-opener bold-emphasis closing-cliche contrast-framing rule-of-three structure:bold-labels ai-generated-composite:strict -after.md: ai-score low 1/31 structure:short-sections +before.md: ai-score high 8/33 ai-tell announcing-opener bold-emphasis closing-cliche contrast-framing rule-of-three structure:bold-labels ai-generated-composite:strict +after.md: ai-score low 1/32 structure:short-sections ``` `before.md` and `after.md` are the articles the outline was measured on above. Each file gets one line: the level, the signs out of those compared, and the signs that counted. diff --git a/text/site/src/content/guide/ja/ai-sounding-examples.md b/text/site/src/content/guide/ja/ai-sounding-examples.md index cdb37ff9d..cc112efd2 100644 --- a/text/site/src/content/guide/ja/ai-sounding-examples.md +++ b/text/site/src/content/guide/ja/ai-sounding-examples.md @@ -453,7 +453,7 @@ AI らしさの簡易判定(`ai-score`)で、書き直す前と後を比べ $ npx chaffjs ai-score ai.md rewritten.md --genre blog/tech ai.md AI らしさ: 高(人が書いた文書(ブログ)と比べて目印が多い) - 目印 8 個(比べた 33 項目のうち、人の文書の 9 割には出ないもの)。中は 3 個から、高は 5 個から + 目印 8 個(比べた 34 項目のうち、人の文書の 9 割には出ないもの)。中は 3 個から、高は 5 個から ※ 書いたのが AI かどうかの判定ではありません。生成文に多い目印が、人の文書と比べてどれだけ出ているかです。 言い回しと形 @@ -464,7 +464,7 @@ AI らしさ: 高(人が書いた文書(ブログ)と比べて目印が多 ✗ 「正直」と前置きする: 1 件 人が書いた文書(ブログ)23 本のうち 0 本 ✗ 3 項目の箇条書きばかり: 1 件 人が書いた文書(ブログ)23 本のうち 0 本 ✗ 生成文の特徴がそろっている: 6 種(生成文にありがちな言い回し、「正直」と前置きする、3 項目の箇条書きばかり、定型の結び、対比の枠が多い、予告で始まる文が多い)。厳しめの段階の 2 種から、目印 1 個に数えます - · ほかの 20 項目は出ていません + · ほかの 21 項目は出ていません 構成(人の記事と比べて) ✗ 太字の見出しで始まる項目: 3 項目 人の記事の 95% より多い @@ -472,12 +472,12 @@ AI らしさ: 高(人が書いた文書(ブログ)と比べて目印が多 rewritten.md AI らしさ: 低(人が書いた文書(ブログ)と比べて同じくらい) - 目印 1 個(比べた 32 項目のうち、人の文書の 9 割には出ないもの)。中は 3 個から、高は 5 個から + 目印 1 個(比べた 33 項目のうち、人の文書の 9 割には出ないもの)。中は 3 個から、高は 5 個から ※ 書いたのが AI かどうかの判定ではありません。生成文に多い目印が、人の文書と比べてどれだけ出ているかです。 言い回しと形 ✗ 節の長さが揃いすぎている: 1 件 人が書いた文書(ブログ)23 本のうち 0 本 - · ほかの 25 項目は出ていません + · ほかの 26 項目は出ていません 構成(人の記事と比べて) ✗ 節の長さのばらつき: 32% 人の記事の 95% より揃っている(「節の長さが揃いすぎている」と同じ形なので 1 つに数えます) diff --git a/text/site/src/content/guide/ja/ai-sounding.md b/text/site/src/content/guide/ja/ai-sounding.md index 84870c718..c38b851e8 100644 --- a/text/site/src/content/guide/ja/ai-sounding.md +++ b/text/site/src/content/guide/ja/ai-sounding.md @@ -135,6 +135,7 @@ Claude Code の skill(`npx chaffjs skill`)は、指摘より先に指針を | `email-stock-courtesy` | 「I hope this email finds you well」「I apologize for any inconvenience」のような英文メールの決まり文句が、一通のメールに 2 つ以上(英語の文書だけ) | | `honesty-marker` | 「正直、」「正直に言うと」のように本音だと前置きする言い回し。1 つでも言う(ブログと業務文書だけ) | | `closing-exhortation` | 「ぜひ〜してみてください」「きっと〜はずです」のように、結びで読み手を励ます・請け合う文が 2 つ以上 | +| `section-reflection-ending` | 「〜と思います」「〜と感じています」のように、節の半分以上が所感の文で閉じている文書(段落のある節が 4 つ以上) | | `cold-open` | 状況も例もないまま、短い願い(「〜に任せたい。」)、前の文の語の引き直し(この「だいたい」が)、難所の予告(「それだけのことに見えて」)が重なる書き出し | | `chat-citation-residue` | 「?utm_source=chatgpt.com」の付いたリンクや「oaicite」のような、チャットの答えを貼ったときに残る印 | | `closing-cliche` | 「いかがでしたでしょうか」で締める終わり方 | diff --git a/text/site/src/content/guide/ja/commands.md b/text/site/src/content/guide/ja/commands.md index 0749a0077..69ad1ddeb 100644 --- a/text/site/src/content/guide/ja/commands.md +++ b/text/site/src/content/guide/ja/commands.md @@ -477,8 +477,8 @@ after.md の構成: 見出し 5、節の平均 101 字、箇条書き 0%、太 ``` $ npx chaffjs ai-score before.md after.md --compact -before.md: ai-score high 8/33 ai-tell announcing-opener closing-cliche contrast-framing honesty-marker rule-of-three structure:bold-labels ai-generated-composite:strict -after.md: ai-score low 1/32 section-length-uniformity +before.md: ai-score high 8/34 ai-tell announcing-opener closing-cliche contrast-framing honesty-marker rule-of-three structure:bold-labels ai-generated-composite:strict +after.md: ai-score low 1/33 section-length-uniformity ``` 上の `before.md` と `after.md` は、前の節で構成を測った記事です。1 ファイル 1 行で、段階、目印の数と比べた項目の数、数えた目印を出します。 diff --git a/text/test/fixtures/ai-samples/paired/expected.txt b/text/test/fixtures/ai-samples/paired/expected.txt index 3175cf0a4..b74190e68 100644 --- a/text/test/fixtures/ai-samples/paired/expected.txt +++ b/text/test/fixtures/ai-samples/paired/expected.txt @@ -26,6 +26,7 @@ paragraph-length-variance 0/3 0/3 0/3 0/ q-fragment-answer 0/3 0/3 0/3 0/63 rule-of-three 2/3 0/3 0/3 0/63 section-length-uniformity 1/3 0/3 1/3 0/63 +section-reflection-ending 0/3 0/3 0/3 0/63 sentence-rhythm 0/3 0/3 0/3 0/63 stock-transition 0/3 0/3 0/3 0/63 translationese-density 0/3 0/3 0/3 0/63 @@ -60,6 +61,7 @@ paragraph-length-variance 0/3 0/3 0/3 0/ q-fragment-answer 0/3 0/3 0/3 0/74 rule-of-three 2/3 0/3 0/3 0/74 section-length-uniformity 1/3 0/3 0/3 0/74 +section-reflection-ending 0/3 0/3 0/3 0/74 sentence-rhythm 0/3 0/3 0/3 0/74 stock-transition 1/3 0/3 0/3 0/74 translationese-density 0/3 0/3 0/3 0/74 diff --git a/text/test/fixtures/bench/plants/section-reflection-ending.yaml b/text/test/fixtures/bench/plants/section-reflection-ending.yaml new file mode 100644 index 000000000..c2a8f0178 --- /dev/null +++ b/text/test/fixtures/bench/plants/section-reflection-ending.yaml @@ -0,0 +1 @@ +not_planted: the share of sections that close the same way, across the whole document diff --git a/text/test/fixtures/limits/en.md b/text/test/fixtures/limits/en.md index c0d1405a1..5a50cc8db 100644 --- a/text/test/fixtures/limits/en.md +++ b/text/test/fixtures/limits/en.md @@ -92,7 +92,7 @@ The day goes like this: ## 🚀 Before -Bring the key. +Bring the key. I think that is enough. ## ✅ After diff --git a/text/test/fixtures/limits/ja.md b/text/test/fixtures/limits/ja.md index 35197f6a7..643ed2acc 100644 --- a/text/test/fixtures/limits/ja.md +++ b/text/test/fixtures/limits/ja.md @@ -91,7 +91,7 @@ ## ✅ 片付け -鍵を返します。 +鍵を返します。それで足りると思います。 ## 役割 - **司会**:田中さんです。 diff --git a/text/test/test_section_reflection_ending.ts b/text/test/test_section_reflection_ending.ts new file mode 100644 index 000000000..78b11f5fe --- /dev/null +++ b/text/test/test_section_reflection_ending.ts @@ -0,0 +1,130 @@ +import { describe, it, before } from "node:test"; +import assert from "node:assert/strict"; +import { buildDocument } from "../packages/chaff/src/document.ts"; +import { loadRules } from "../packages/chaff/src/rule-load.ts"; +import { runRules } from "../packages/chaff/src/run.ts"; +import { reflectionIn, sectionClosers } from "../packages/chaff/src/detectors/section-reflection-ending.ts"; +import { tokenizedLexicons } from "../packages/chaff/src/lexicon-tokens.ts"; +import { adapter as en } from "../packages/lang-en/src/index.ts"; +import { adapter as ja } from "../packages/lang-ja/src/index.ts"; +import type { LanguageAdapter, Level } from "../packages/chaff/src/plugin.ts"; + +// section-reflection-ending: nearly every section closes on a personal reflection (と思います, I think). One is +// ordinary; most sections closing so is the shape. Self-written samples. + +const RULE = "section-reflection-ending"; + +before(async () => { + await en.prepare?.({ pos: true }); + await ja.prepare?.({ pos: true }); +}); + +const findings = (source: string, adapter: LanguageAdapter, level?: Level, genre = "blog/essay") => + runRules(buildDocument("t.md", source, adapter), loadRules(adapter.id), level === undefined ? {} : { [RULE]: level }, true, genre).findings.filter( + (finding) => finding.rule === RULE, + ); + +const sentenceOf = (adapter: LanguageAdapter, text: string) => { + const sentence = buildDocument("t.md", text, adapter).sentences[0]; + assert.ok(sentence !== undefined); + return sentence; +}; + +const lexiconOf = (adapter: LanguageAdapter) => tokenizedLexicons(adapter.lexicons, adapter)[RULE] ?? []; + +const sections = (closings: readonly string[]): string => + ["# 題", "", ...closings.flatMap((closing, index) => [`## 節${String(index + 1)}`, "", `駅まで十分ほど歩きます。${closing}`, ""])].join("\n"); + +const sectionsEn = (closings: readonly string[]): string => + ["# Title", "", ...closings.flatMap((closing, index) => [`## Part ${String(index + 1)}`, "", `The walk takes ten minutes. ${closing}`, ""])].join("\n"); + +describe("reflectionIn", () => { + const reflective: ReadonlyArray = [ + [ja, "続けてよかったと思います。"], + [ja, "その場で課題を伺えたことが大きかったと感じています。"], + [ja, "準備しておくべきだと考えています。"], + [ja, "それでも、始めてよかったと心から思っている。"], + [ja, "いちばん頭がすっきりしている時間かもしれない。"], + [en, "I think the fresh air is the best part."], + [en, "That was the right call, I think."], + [en, "Personally, I would start earlier."], + ]; + reflective.forEach(([adapter, text]) => { + it(`finds 「${text}」`, () => assert.notEqual(reflectionIn(sentenceOf(adapter, text), lexiconOf(adapter)), undefined)); + }); + + const plain: ReadonlyArray = [ + [ja, "名刺交換は287件でした。"], + [ja, "思うところを三つ書きます。"], + [ja, "と思いますか、と聞かれました。"], + [ja, ""], + [en, "We thinks it through."], + [en, "They think it works."], + [en, "The team felt it was late."], + ]; + plain.forEach(([adapter, text]) => { + it(`does not find 「${text}」`, () => { + const sentence = buildDocument("t.md", text, adapter).sentences[0]; + assert.equal(sentence === undefined ? undefined : reflectionIn(sentence, lexiconOf(adapter)), undefined); + }); + }); + + it("finds nothing with an empty lexicon", () => assert.equal(reflectionIn(sentenceOf(ja, "よかったと思います。"), []), undefined)); +}); + +describe("sectionClosers", () => { + it("takes the last sentence of each section's last paragraph", () => { + const doc = buildDocument("t.md", "## 一\n\n最初です。\n\n次です。終わりです。\n\n## 二\n\n二つ目です。\n", ja); + assert.deepEqual( + sectionClosers(doc).map((sentence) => sentence.text.trim()), + ["終わりです。", "二つ目です。"], + ); + }); + + it("skips a section with no paragraph", () => { + const doc = buildDocument("t.md", "# 題\n\n## 一\n\n- 項目\n- 項目\n\n## 二\n\n本文です。\n", ja); + assert.deepEqual( + sectionClosers(doc).map((sentence) => sentence.text.trim()), + ["本文です。"], + ); + }); + + it("gives nothing for an empty document", () => assert.deepEqual(sectionClosers(buildDocument("t.md", "", ja)), [])); +}); + +describe(RULE, () => { + it("reports every reflective closing when most sections close on one", () => { + const found = findings(sections(["よかったと思います。", "いい運動になっていると感じています。", "こつかもしれません。", "名刺交換は287件でした。"]), ja); + assert.equal(found.length, 3); + assert.equal(found[0]?.values?.["share"], 75); + }); + + it("reports an English document whose sections open their closing with I think", () => { + const found = findings(sectionsEn(["I think it is the best part.", "I feel it helps.", "I believe it lasts.", "It rained twice."]), en); + assert.equal(found.length, 3); + }); + + it("does not report one reflective closing among several sections", () => { + assert.deepEqual(findings(sections(["よかったと思います。", "八千円浮きました。", "六日が雨でした。", "十分かかります。"]), ja), []); + }); + + it("does not report a share below the limit", () => { + const closings = ["よかったと思います。", "八千円浮きました。", "六日が雨でした。", "十分かかります。", "楽しいと感じています。"]; + assert.deepEqual(findings(sections(closings), ja), []); + assert.equal(findings(sections(closings), ja, "strict").length, 2); + }); + + it("does not measure a document with fewer sections than min_sections", () => { + assert.deepEqual(findings(sections(["よかったと思います。", "楽しいと感じています。", "こつかもしれません。"]), ja), []); + }); + + it("does not count a reflection in the middle of a closing paragraph", () => { + const middle = ["よかったと思います。名刺は十枚でした。", "楽しいと感じています。雨は六日でした。", "こつかもしれません。八千円です。", "十分かかります。"]; + assert.deepEqual(findings(sections(middle), ja), []); + }); + + it("runs at the genre's own level when no level is set", () => { + const closings = ["よかったと思います。", "楽しいと感じています。", "こつかもしれません。", "大きいと思います。"]; + assert.equal(findings(sections(closings), ja, undefined, "blog/essay").length, 4); + }); +});