chaffjs 0.25.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +179 -42
- package/dist/adapter-import.d.ts +2 -0
- package/dist/adapter-import.d.ts.map +1 -0
- package/dist/adapter-import.js +11 -0
- package/dist/adapter-import.js.map +1 -0
- package/dist/adapter-load.d.ts.map +1 -1
- package/dist/adapter-load.js +2 -9
- package/dist/adapter-load.js.map +1 -1
- package/dist/ai-score/human-shares.d.ts +4 -0
- package/dist/ai-score/human-shares.d.ts.map +1 -0
- package/dist/ai-score/human-shares.js +205 -0
- package/dist/ai-score/human-shares.js.map +1 -0
- package/dist/ai-score/lint-line.d.ts +4 -0
- package/dist/ai-score/lint-line.d.ts.map +1 -0
- package/dist/ai-score/lint-line.js +9 -0
- package/dist/ai-score/lint-line.js.map +1 -0
- package/dist/ai-score/of-document.d.ts +7 -0
- package/dist/ai-score/of-document.d.ts.map +1 -0
- package/dist/ai-score/of-document.js +40 -0
- package/dist/ai-score/of-document.js.map +1 -0
- package/dist/ai-score/render.d.ts +24 -0
- package/dist/ai-score/render.d.ts.map +1 -0
- package/dist/ai-score/render.js +100 -0
- package/dist/ai-score/render.js.map +1 -0
- package/dist/ai-score/score.d.ts +77 -0
- package/dist/ai-score/score.d.ts.map +1 -0
- package/dist/ai-score/score.js +52 -0
- package/dist/ai-score/score.js.map +1 -0
- package/dist/ai-score/signals.d.ts +19 -0
- package/dist/ai-score/signals.d.ts.map +1 -0
- package/dist/ai-score/signals.js +30 -0
- package/dist/ai-score/signals.js.map +1 -0
- package/dist/ai-score/text.d.ts +37 -0
- package/dist/ai-score/text.d.ts.map +1 -0
- package/dist/ai-score/text.js +59 -0
- package/dist/ai-score/text.js.map +1 -0
- package/dist/ai-score/view.d.ts +5 -0
- package/dist/ai-score/view.d.ts.map +1 -0
- package/dist/ai-score/view.js +19 -0
- package/dist/ai-score/view.js.map +1 -0
- package/dist/backends/anthropic.d.ts +0 -1
- package/dist/backends/anthropic.d.ts.map +1 -1
- package/dist/backends/anthropic.js +0 -1
- package/dist/backends/anthropic.js.map +1 -1
- package/dist/backends/default-model.d.ts +3 -0
- package/dist/backends/default-model.d.ts.map +1 -0
- package/dist/backends/default-model.js +5 -0
- package/dist/backends/default-model.js.map +1 -0
- package/dist/backends/openai.d.ts +0 -1
- package/dist/backends/openai.d.ts.map +1 -1
- package/dist/backends/openai.js +0 -1
- package/dist/backends/openai.js.map +1 -1
- package/dist/browser/adapter-import.d.ts +2 -0
- package/dist/browser/adapter-import.d.ts.map +1 -0
- package/dist/browser/adapter-import.js +17 -0
- package/dist/browser/adapter-import.js.map +1 -0
- package/dist/browser/bounded-match.d.ts +3 -0
- package/dist/browser/bounded-match.d.ts.map +1 -0
- package/dist/browser/bounded-match.js +4 -0
- package/dist/browser/bounded-match.js.map +1 -0
- package/dist/browser/check-text.d.ts +43 -0
- package/dist/browser/check-text.d.ts.map +1 -0
- package/dist/browser/check-text.js +50 -0
- package/dist/browser/check-text.js.map +1 -0
- package/dist/browser/detectors.d.ts +4 -0
- package/dist/browser/detectors.d.ts.map +1 -0
- package/dist/browser/detectors.js +22 -0
- package/dist/browser/detectors.js.map +1 -0
- package/dist/browser/package-files.d.ts +5 -0
- package/dist/browser/package-files.d.ts.map +1 -0
- package/dist/browser/package-files.js +8 -0
- package/dist/browser/package-files.js.map +1 -0
- package/dist/browser/path.d.ts +9 -0
- package/dist/browser/path.d.ts.map +1 -0
- package/dist/browser/path.js +70 -0
- package/dist/browser/path.js.map +1 -0
- package/dist/browser/working-dir.d.ts +2 -0
- package/dist/browser/working-dir.d.ts.map +1 -0
- package/dist/browser/working-dir.js +3 -0
- package/dist/browser/working-dir.js.map +1 -0
- package/dist/browser-files.d.ts +21 -0
- package/dist/browser-files.d.ts.map +1 -0
- package/dist/browser-files.js +65 -0
- package/dist/browser-files.js.map +1 -0
- package/dist/browser.d.ts +9 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +13 -0
- package/dist/browser.js.map +1 -0
- package/dist/capitals-with-small.d.ts +8 -0
- package/dist/capitals-with-small.d.ts.map +1 -0
- package/dist/capitals-with-small.js +20 -0
- package/dist/capitals-with-small.js.map +1 -0
- package/dist/cli-text.d.ts.map +1 -1
- package/dist/cli-text.js +2 -0
- package/dist/cli-text.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +4 -1
- package/dist/cli.js.map +1 -1
- package/dist/commands/ai-score.d.ts +8 -0
- package/dist/commands/ai-score.d.ts.map +1 -0
- package/dist/commands/ai-score.js +59 -0
- package/dist/commands/ai-score.js.map +1 -0
- package/dist/commands/document-commands.d.ts.map +1 -1
- package/dist/commands/document-commands.js +2 -0
- package/dist/commands/document-commands.js.map +1 -1
- package/dist/config/by-path-problems.d.ts +5 -0
- package/dist/config/by-path-problems.d.ts.map +1 -0
- package/dist/config/by-path-problems.js +11 -0
- package/dist/config/by-path-problems.js.map +1 -0
- package/dist/config/load.d.ts +9 -2
- package/dist/config/load.d.ts.map +1 -1
- package/dist/config/load.js +21 -8
- package/dist/config/load.js.map +1 -1
- package/dist/config/read.d.ts +2 -0
- package/dist/config/read.d.ts.map +1 -1
- package/dist/config/read.js +4 -1
- package/dist/config/read.js.map +1 -1
- package/dist/config/warnings.d.ts +1 -1
- package/dist/config/warnings.d.ts.map +1 -1
- package/dist/config/warnings.js +3 -1
- package/dist/config/warnings.js.map +1 -1
- package/dist/config/working-dir.d.ts +2 -0
- package/dist/config/working-dir.d.ts.map +1 -0
- package/dist/config/working-dir.js +3 -0
- package/dist/config/working-dir.js.map +1 -0
- package/dist/custom/bounded-match.d.ts +1 -12
- package/dist/custom/bounded-match.d.ts.map +1 -1
- package/dist/custom/bounded-match.js +1 -11
- package/dist/custom/bounded-match.js.map +1 -1
- package/dist/custom/pattern-timeout.d.ts +13 -0
- package/dist/custom/pattern-timeout.d.ts.map +1 -0
- package/dist/custom/pattern-timeout.js +13 -0
- package/dist/custom/pattern-timeout.js.map +1 -0
- package/dist/derived/relative-weekdays.d.ts +16 -0
- package/dist/derived/relative-weekdays.d.ts.map +1 -0
- package/dist/derived/relative-weekdays.js +52 -0
- package/dist/derived/relative-weekdays.js.map +1 -0
- package/dist/detect.d.ts.map +1 -1
- package/dist/detect.js +4 -5
- package/dist/detect.js.map +1 -1
- package/dist/detectors/change-rate.d.ts +3 -0
- package/dist/detectors/change-rate.d.ts.map +1 -0
- package/dist/detectors/change-rate.js +102 -0
- package/dist/detectors/change-rate.js.map +1 -0
- package/dist/detectors/date-year.d.ts +10 -2
- package/dist/detectors/date-year.d.ts.map +1 -1
- package/dist/detectors/date-year.js +44 -8
- package/dist/detectors/date-year.js.map +1 -1
- package/dist/detectors/defined-term-form.d.ts +5 -0
- package/dist/detectors/defined-term-form.d.ts.map +1 -1
- package/dist/detectors/defined-term-form.js +22 -5
- package/dist/detectors/defined-term-form.js.map +1 -1
- package/dist/detectors/derived-numbers.d.ts.map +1 -1
- package/dist/detectors/derived-numbers.js +3 -7
- package/dist/detectors/derived-numbers.js.map +1 -1
- package/dist/detectors/document-date.d.ts +4 -0
- package/dist/detectors/document-date.d.ts.map +1 -0
- package/dist/detectors/document-date.js +12 -0
- package/dist/detectors/document-date.js.map +1 -0
- package/dist/detectors/orthographic-variant.d.ts.map +1 -1
- package/dist/detectors/orthographic-variant.js +60 -28
- package/dist/detectors/orthographic-variant.js.map +1 -1
- package/dist/detectors/party-role-name.d.ts +3 -0
- package/dist/detectors/party-role-name.d.ts.map +1 -0
- package/dist/detectors/party-role-name.js +35 -0
- package/dist/detectors/party-role-name.js.map +1 -0
- package/dist/detectors/quote-without-source.d.ts +17 -0
- package/dist/detectors/quote-without-source.d.ts.map +1 -0
- package/dist/detectors/quote-without-source.js +64 -0
- package/dist/detectors/quote-without-source.js.map +1 -0
- package/dist/detectors/reference-text.js +1 -1
- package/dist/detectors/reference-text.js.map +1 -1
- package/dist/detectors/registry/change-rate.d.ts +3 -0
- package/dist/detectors/registry/change-rate.d.ts.map +1 -0
- package/dist/detectors/registry/change-rate.js +3 -0
- package/dist/detectors/registry/change-rate.js.map +1 -0
- package/dist/detectors/registry/party-role-name.d.ts +3 -0
- package/dist/detectors/registry/party-role-name.d.ts.map +1 -0
- package/dist/detectors/registry/party-role-name.js +3 -0
- package/dist/detectors/registry/party-role-name.js.map +1 -0
- package/dist/detectors/registry/quote-without-source.d.ts +3 -0
- package/dist/detectors/registry/quote-without-source.d.ts.map +1 -0
- package/dist/detectors/registry/quote-without-source.js +3 -0
- package/dist/detectors/registry/quote-without-source.js.map +1 -0
- package/dist/detectors/registry/vague-deadline.d.ts +3 -0
- package/dist/detectors/registry/vague-deadline.d.ts.map +1 -0
- package/dist/detectors/registry/vague-deadline.js +3 -0
- package/dist/detectors/registry/vague-deadline.js.map +1 -0
- package/dist/detectors/registry/version-mismatch.d.ts +3 -0
- package/dist/detectors/registry/version-mismatch.d.ts.map +1 -0
- package/dist/detectors/registry/version-mismatch.js +3 -0
- package/dist/detectors/registry/version-mismatch.js.map +1 -0
- package/dist/detectors/relative-dates.d.ts.map +1 -1
- package/dist/detectors/relative-dates.js +3 -1
- package/dist/detectors/relative-dates.js.map +1 -1
- package/dist/detectors/relative-day-words.d.ts +4 -0
- package/dist/detectors/relative-day-words.d.ts.map +1 -0
- package/dist/detectors/relative-day-words.js +105 -0
- package/dist/detectors/relative-day-words.js.map +1 -0
- package/dist/detectors/run-in-label.d.ts +7 -0
- package/dist/detectors/run-in-label.d.ts.map +1 -0
- package/dist/detectors/run-in-label.js +53 -0
- package/dist/detectors/run-in-label.js.map +1 -0
- package/dist/detectors/sentence-counts.d.ts +3 -1
- package/dist/detectors/sentence-counts.d.ts.map +1 -1
- package/dist/detectors/sentence-counts.js +11 -4
- package/dist/detectors/sentence-counts.js.map +1 -1
- package/dist/detectors/sentence-ending.d.ts +1 -1
- package/dist/detectors/sentence-ending.d.ts.map +1 -1
- package/dist/detectors/sentence-ending.js +2 -1
- package/dist/detectors/sentence-ending.js.map +1 -1
- package/dist/detectors/structure-tree.d.ts +8 -2
- package/dist/detectors/structure-tree.d.ts.map +1 -1
- package/dist/detectors/structure-tree.js +86 -5
- package/dist/detectors/structure-tree.js.map +1 -1
- package/dist/detectors/unbalanced-bracket.d.ts +1 -1
- package/dist/detectors/unbalanced-bracket.d.ts.map +1 -1
- package/dist/detectors/unbalanced-bracket.js +23 -11
- package/dist/detectors/unbalanced-bracket.js.map +1 -1
- package/dist/detectors/vague-deadline.d.ts +25 -0
- package/dist/detectors/vague-deadline.d.ts.map +1 -0
- package/dist/detectors/vague-deadline.js +97 -0
- package/dist/detectors/vague-deadline.js.map +1 -0
- package/dist/detectors/version-mismatch.d.ts +3 -0
- package/dist/detectors/version-mismatch.d.ts.map +1 -0
- package/dist/detectors/version-mismatch.js +19 -0
- package/dist/detectors/version-mismatch.js.map +1 -0
- package/dist/furigana.d.ts +7 -0
- package/dist/furigana.d.ts.map +1 -0
- package/dist/furigana.js +16 -0
- package/dist/furigana.js.map +1 -0
- package/dist/genre-load.d.ts.map +1 -1
- package/dist/genre-load.js +5 -7
- package/dist/genre-load.js.map +1 -1
- package/dist/grade/ai-score.d.ts +16 -0
- package/dist/grade/ai-score.d.ts.map +1 -0
- package/dist/grade/ai-score.js +17 -0
- package/dist/grade/ai-score.js.map +1 -0
- package/dist/grade/finding.d.ts +6 -0
- package/dist/grade/finding.d.ts.map +1 -0
- package/dist/grade/finding.js +13 -0
- package/dist/grade/finding.js.map +1 -0
- package/dist/grade/grade-item.d.ts.map +1 -1
- package/dist/grade/grade-item.js +4 -11
- package/dist/grade/grade-item.js.map +1 -1
- package/dist/grade/render-variants.d.ts.map +1 -1
- package/dist/grade/render-variants.js +3 -0
- package/dist/grade/render-variants.js.map +1 -1
- package/dist/grade/render.d.ts.map +1 -1
- package/dist/grade/render.js +1 -0
- package/dist/grade/render.js.map +1 -1
- package/dist/grade/result.d.ts +3 -0
- package/dist/grade/result.d.ts.map +1 -1
- package/dist/grade/results-read.d.ts.map +1 -1
- package/dist/grade/results-read.js +13 -2
- package/dist/grade/results-read.js.map +1 -1
- package/dist/grade/summary.d.ts +3 -0
- package/dist/grade/summary.d.ts.map +1 -1
- package/dist/grade/summary.js +6 -0
- package/dist/grade/summary.js.map +1 -1
- package/dist/grade/text.d.ts +2 -0
- package/dist/grade/text.d.ts.map +1 -1
- package/dist/grade/text.js +2 -0
- package/dist/grade/text.js.map +1 -1
- package/dist/grade/variants-text.d.ts +3 -0
- package/dist/grade/variants-text.d.ts.map +1 -1
- package/dist/grade/variants-text.js +4 -0
- package/dist/grade/variants-text.js.map +1 -1
- package/dist/grade/variants.d.ts +3 -0
- package/dist/grade/variants.d.ts.map +1 -1
- package/dist/grade/variants.js +1 -0
- package/dist/grade/variants.js.map +1 -1
- package/dist/grade-api.d.ts +1 -0
- package/dist/grade-api.d.ts.map +1 -1
- package/dist/grade-api.js +2 -1
- package/dist/grade-api.js.map +1 -1
- package/dist/judge.d.ts +0 -1
- package/dist/judge.d.ts.map +1 -1
- package/dist/judge.js +0 -1
- package/dist/judge.js.map +1 -1
- package/dist/known-genres.js +2 -2
- package/dist/known-genres.js.map +1 -1
- package/dist/package-files.d.ts +6 -0
- package/dist/package-files.d.ts.map +1 -0
- package/dist/package-files.js +11 -0
- package/dist/package-files.js.map +1 -0
- package/dist/profile/load.d.ts.map +1 -1
- package/dist/profile/load.js +5 -6
- package/dist/profile/load.js.map +1 -1
- package/dist/rule-load.d.ts.map +1 -1
- package/dist/rule-load.js +5 -6
- package/dist/rule-load.js.map +1 -1
- package/dist/rule-offs.js +3 -3
- package/dist/rule-offs.js.map +1 -1
- package/dist/run.js +1 -1
- package/dist/run.js.map +1 -1
- package/dist/structure/change-rate.d.ts +33 -0
- package/dist/structure/change-rate.d.ts.map +1 -0
- package/dist/structure/change-rate.js +71 -0
- package/dist/structure/change-rate.js.map +1 -0
- package/dist/structure/date-range.d.ts +4 -0
- package/dist/structure/date-range.d.ts.map +1 -1
- package/dist/structure/date-range.js +23 -3
- package/dist/structure/date-range.js.map +1 -1
- package/dist/structure/issues.d.ts +17 -1
- package/dist/structure/issues.d.ts.map +1 -1
- package/dist/structure/issues.js +54 -5
- package/dist/structure/issues.js.map +1 -1
- package/dist/structure/list-numbering.d.ts +17 -0
- package/dist/structure/list-numbering.d.ts.map +1 -0
- package/dist/structure/list-numbering.js +27 -0
- package/dist/structure/list-numbering.js.map +1 -0
- package/dist/structure/party-role.d.ts +30 -0
- package/dist/structure/party-role.d.ts.map +1 -0
- package/dist/structure/party-role.js +58 -0
- package/dist/structure/party-role.js.map +1 -0
- package/dist/structure/percent-sum-prose.d.ts +7 -0
- package/dist/structure/percent-sum-prose.d.ts.map +1 -0
- package/dist/structure/percent-sum-prose.js +44 -0
- package/dist/structure/percent-sum-prose.js.map +1 -0
- package/dist/structure/prose-total.d.ts +28 -0
- package/dist/structure/prose-total.d.ts.map +1 -0
- package/dist/structure/prose-total.js +99 -0
- package/dist/structure/prose-total.js.map +1 -0
- package/dist/structure/reference-text.d.ts +5 -0
- package/dist/structure/reference-text.d.ts.map +1 -1
- package/dist/structure/reference-text.js +17 -4
- package/dist/structure/reference-text.js.map +1 -1
- package/dist/structure/term-prefix.d.ts +18 -0
- package/dist/structure/term-prefix.d.ts.map +1 -0
- package/dist/structure/term-prefix.js +40 -0
- package/dist/structure/term-prefix.js.map +1 -0
- package/dist/structure/total.d.ts +2 -0
- package/dist/structure/total.d.ts.map +1 -1
- package/dist/structure/total.js +2 -0
- package/dist/structure/total.js.map +1 -1
- package/dist/structure/version-mismatch.d.ts +23 -0
- package/dist/structure/version-mismatch.d.ts.map +1 -0
- package/dist/structure/version-mismatch.js +74 -0
- package/dist/structure/version-mismatch.js.map +1 -0
- package/dist/structure/weekday.d.ts +21 -2
- package/dist/structure/weekday.d.ts.map +1 -1
- package/dist/structure/weekday.js +70 -8
- package/dist/structure/weekday.js.map +1 -1
- package/dist/structure-shape/baseline-load.d.ts.map +1 -1
- package/dist/structure-shape/baseline-load.js +4 -5
- package/dist/structure-shape/baseline-load.js.map +1 -1
- package/dist/style-load.d.ts.map +1 -1
- package/dist/style-load.js +5 -6
- package/dist/style-load.js.map +1 -1
- package/package.json +24 -3
- package/rules/agreement-slip.yaml +2 -2
- package/rules/change-rate-mismatch.yaml +44 -0
- package/rules/cliche.yaml +28 -8
- package/rules/date-weekday-mismatch.yaml +4 -4
- package/rules/date-without-year.yaml +28 -3
- package/rules/defined-term-form.yaml +9 -6
- package/rules/demonstrative-opener-run.yaml +24 -7
- package/rules/max-sentence-length.yaml +1 -0
- package/rules/no-mixed-desumasu.yaml +2 -2
- package/rules/numbering-gap.yaml +4 -4
- package/rules/one-sentence-paragraph-run.yaml +1 -0
- package/rules/orthographic-variant.yaml +3 -3
- package/rules/party-role-name.yaml +94 -0
- package/rules/percent-sum-mismatch.yaml +4 -4
- package/rules/quote-without-source.yaml +61 -0
- package/rules/relative-date-mismatch.yaml +4 -4
- package/rules/total-mismatch.yaml +8 -8
- package/rules/undefined-acronym.yaml +1 -0
- package/rules/vague-deadline.yaml +95 -0
- package/rules/version-mismatch.yaml +77 -0
- package/rules/weasel-word.yaml +25 -7
- package/skills/chaff/SKILL.md +12 -2
- package/src/adapter-import.ts +3 -0
- package/src/adapter-load.ts +2 -1
- package/src/ai-score/human-shares.ts +207 -0
- package/src/ai-score/lint-line.ts +10 -0
- package/src/ai-score/of-document.ts +46 -0
- package/src/ai-score/render.ts +124 -0
- package/src/ai-score/score.ts +121 -0
- package/src/ai-score/signals.ts +39 -0
- package/src/ai-score/text.ts +103 -0
- package/src/ai-score/view.ts +21 -0
- package/src/backends/anthropic.ts +0 -2
- package/src/backends/default-model.ts +9 -0
- package/src/backends/openai.ts +0 -2
- package/src/browser/adapter-import.ts +19 -0
- package/src/browser/bounded-match.ts +9 -0
- package/src/browser/check-text.ts +106 -0
- package/src/browser/detectors.ts +40 -0
- package/src/browser/import-meta-glob.d.ts +5 -0
- package/src/browser/package-files.ts +13 -0
- package/src/browser/path.ts +73 -0
- package/src/browser/working-dir.ts +3 -0
- package/src/browser-files.ts +87 -0
- package/src/browser.ts +19 -0
- package/src/capitals-with-small.ts +23 -0
- package/src/cli-text.ts +2 -0
- package/src/cli.ts +4 -1
- package/src/commands/ai-score.ts +77 -0
- package/src/commands/document-commands.ts +2 -0
- package/src/config/by-path-problems.ts +17 -0
- package/src/config/load.ts +21 -8
- package/src/config/read.ts +5 -1
- package/src/config/warnings.ts +3 -1
- package/src/config/working-dir.ts +3 -0
- package/src/custom/bounded-match.ts +1 -16
- package/src/custom/pattern-timeout.ts +17 -0
- package/src/derived/relative-weekdays.ts +65 -0
- package/src/detect.ts +4 -5
- package/src/detectors/change-rate.ts +122 -0
- package/src/detectors/date-year.ts +51 -12
- package/src/detectors/defined-term-form.ts +28 -6
- package/src/detectors/derived-numbers.ts +3 -11
- package/src/detectors/document-date.ts +18 -0
- package/src/detectors/orthographic-variant.ts +67 -22
- package/src/detectors/party-role-name.ts +44 -0
- package/src/detectors/quote-without-source.ts +90 -0
- package/src/detectors/reference-text.ts +1 -1
- package/src/detectors/registry/change-rate.ts +4 -0
- package/src/detectors/registry/party-role-name.ts +4 -0
- package/src/detectors/registry/quote-without-source.ts +4 -0
- package/src/detectors/registry/vague-deadline.ts +4 -0
- package/src/detectors/registry/version-mismatch.ts +4 -0
- package/src/detectors/relative-dates.ts +3 -1
- package/src/detectors/relative-day-words.ts +126 -0
- package/src/detectors/run-in-label.ts +60 -0
- package/src/detectors/sentence-counts.ts +13 -4
- package/src/detectors/sentence-ending.ts +3 -2
- package/src/detectors/structure-tree.ts +104 -10
- package/src/detectors/unbalanced-bracket.ts +25 -10
- package/src/detectors/vague-deadline.ts +132 -0
- package/src/detectors/version-mismatch.ts +23 -0
- package/src/furigana.ts +20 -0
- package/src/genre-load.ts +5 -7
- package/src/grade/ai-score.ts +32 -0
- package/src/grade/finding.ts +16 -0
- package/src/grade/grade-item.ts +4 -13
- package/src/grade/render-variants.ts +5 -0
- package/src/grade/render.ts +1 -0
- package/src/grade/result.ts +3 -0
- package/src/grade/results-read.ts +17 -2
- package/src/grade/summary.ts +9 -0
- package/src/grade/text.ts +6 -0
- package/src/grade/variants-text.ts +7 -0
- package/src/grade/variants.ts +4 -0
- package/src/grade-api.ts +3 -1
- package/src/judge.ts +0 -2
- package/src/known-genres.ts +2 -2
- package/src/package-files.ts +15 -0
- package/src/profile/load.ts +5 -6
- package/src/rule-load.ts +5 -6
- package/src/rule-offs.ts +3 -3
- package/src/run.ts +1 -1
- package/src/structure/change-rate.ts +103 -0
- package/src/structure/date-range.ts +28 -3
- package/src/structure/issues.ts +61 -6
- package/src/structure/list-numbering.ts +34 -0
- package/src/structure/party-role.ts +94 -0
- package/src/structure/percent-sum-prose.ts +54 -0
- package/src/structure/prose-total.ts +135 -0
- package/src/structure/reference-text.ts +17 -4
- package/src/structure/term-prefix.ts +54 -0
- package/src/structure/total.ts +4 -0
- package/src/structure/version-mismatch.ts +103 -0
- package/src/structure/weekday.ts +83 -6
- package/src/structure-shape/baseline-load.ts +4 -5
- package/src/style-load.ts +5 -6
|
@@ -4,6 +4,8 @@ import { kanjiSkeleton, katakanaKey, lemmaReading } from "../kana-spelling.ts";
|
|
|
4
4
|
import { isKatakanaWord, stemOf } from "../long-vowel.ts";
|
|
5
5
|
import { QUOTATION_MARKS, isWithinAny, quotedSpans } from "../quoted-span.ts";
|
|
6
6
|
import { nameSpans, touchesAny } from "../team-names.ts";
|
|
7
|
+
import { furiganaSpans } from "../furigana.ts";
|
|
8
|
+
import { acronymsIn, isCapitalsNotSpelling } from "../capitals-with-small.ts";
|
|
7
9
|
|
|
8
10
|
/** A word found in the document: where it is, which sentence it is in, its key and spelling, and how it is written when that differs. */
|
|
9
11
|
type Placed = KeyedWord & { readonly sentence: Sentence; readonly offset: number; readonly shown?: string };
|
|
@@ -22,42 +24,82 @@ const MIN_LATIN_KEY = 3;
|
|
|
22
24
|
/** Lexicons: readings and spellings whose kanji and kana forms mean different things (成る and なる, 者 and もの), and adverbs hiragana-fukushi reads. */
|
|
23
25
|
const DISTINCT = "orthographic-variant-distinct";
|
|
24
26
|
const FUKUSHI = "hiragana-fukushi";
|
|
27
|
+
/** Lexicon: idioms written as noun, particle and verb (気をつける). The verb there is compared apart from the verb on its own. */
|
|
28
|
+
const IDIOM = "orthographic-variant-idiom";
|
|
25
29
|
|
|
26
30
|
const patternsOf = (doc: ProseDocument, id: string): string[] => (doc.lexicons[id] ?? []).map((entry) => entry.pattern);
|
|
27
31
|
|
|
28
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Whether a stretch of the sentence is outside a quotation, the team's names and a reading in brackets (HTTP(えいちてぃーてぃーぴー)):
|
|
34
|
+
* the first two keep their own spelling, and a reading is not a spelling at all.
|
|
35
|
+
*/
|
|
29
36
|
const isOpenIn = (sentence: Sentence, names: readonly string[]): IsOpen => {
|
|
30
|
-
const
|
|
37
|
+
const closed = [...quotedSpans(sentence.text, QUOTATION_MARKS), ...furiganaSpans(sentence.text)];
|
|
31
38
|
const named = nameSpans(sentence.text, names);
|
|
32
|
-
return (start, end) => !isWithinAny(
|
|
39
|
+
return (start, end) => !isWithinAny(closed, { start, end }) && !touchesAny(named, start, end);
|
|
33
40
|
};
|
|
34
41
|
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
/** A word and the two words before it, in its sentence. */
|
|
43
|
+
type InContext = { readonly token: Token; readonly previous: Token | undefined; readonly before: Token | undefined };
|
|
44
|
+
|
|
45
|
+
/** A verb's て-form the tokenizer read as a conjunction (追って at the head of a sentence): a kanji stem and て or で. Connectives (そして, それで) are kana. */
|
|
46
|
+
const TE_FORM_CONJUNCTION = /^\p{Script=Han}.*[てで]$/u;
|
|
47
|
+
|
|
48
|
+
/** After a て-form (見てみる). The tokenizer reads the て as a joining word, or the whole て-form as a conjunction (追って / みる). */
|
|
49
|
+
const followsTeForm = (previous: Token | undefined): boolean =>
|
|
50
|
+
(previous?.pos === "SCONJ" && (previous.surface === "て" || previous.surface === "で")) ||
|
|
51
|
+
(previous?.pos === "CCONJ" && TE_FORM_CONJUNCTION.test(previous.surface));
|
|
52
|
+
|
|
53
|
+
const isHelper = ({ token, previous }: InContext): boolean => token.features?.["Bound"] === "Yes" || followsTeForm(previous);
|
|
54
|
+
|
|
55
|
+
const isTouching = (left: Token | undefined, right: Token): boolean => left !== undefined && left.span.end === right.span.start;
|
|
56
|
+
|
|
57
|
+
const HIRAGANA_ONLY = /^[ぁ-ゖー]+$/u;
|
|
58
|
+
|
|
59
|
+
/** A kana noun written onto a noun (全員ぶん): a suffix, which may not be the free noun of the same reading (文). */
|
|
60
|
+
const isKanaSuffix = ({ token, previous }: InContext): boolean =>
|
|
61
|
+
token.pos === "NOUN" && previous?.pos === "NOUN" && isTouching(previous, token) && HIRAGANA_ONLY.test(token.surface);
|
|
62
|
+
|
|
63
|
+
/** The verb of an idiom (気をつける): the noun, the particle and the verb's dictionary form are in the idiom lexicon. */
|
|
64
|
+
const isIdiomVerb = ({ token, previous, before }: InContext, idioms: ReadonlySet<string>): boolean =>
|
|
65
|
+
token.pos === "VERB" && previous?.pos === "ADP" && before !== undefined && idioms.has(`${before.surface}${previous.surface}${token.lemma ?? token.surface}`);
|
|
37
66
|
|
|
38
67
|
/**
|
|
39
68
|
* A helper verb or a dependent noun (見て下さい, その事) is written kana by many guides while the full word keeps its kanji (資料を下さい).
|
|
40
|
-
* The two uses are compared apart, so a document that follows that convention is consistent. A suffix (
|
|
41
|
-
* it is not the dependent noun of the same reading (このように).
|
|
69
|
+
* The two uses are compared apart, so a document that follows that convention is consistent. A suffix (業務用, 全員ぶん) is a third use:
|
|
70
|
+
* it is not the dependent noun of the same reading (このように). The verb of an idiom (気をつける) is a fourth.
|
|
42
71
|
*/
|
|
43
|
-
const useOf = (
|
|
44
|
-
if (
|
|
45
|
-
|
|
72
|
+
const useOf = (word: InContext, idioms: ReadonlySet<string>): string => {
|
|
73
|
+
if (isIdiomVerb(word, idioms)) return "idiom";
|
|
74
|
+
if (isKanaSuffix(word)) return "suffix";
|
|
75
|
+
if (!isHelper(word)) return "free";
|
|
76
|
+
return word.token.pos === "NOUN" && word.token.features?.["NounType"] !== "Dependent" ? "suffix" : "bound";
|
|
46
77
|
};
|
|
47
78
|
|
|
48
|
-
|
|
79
|
+
/** One katakana and then kana that is not katakana (スる): no verb stem is one katakana long, as サボる and ググる are two. */
|
|
80
|
+
const ONE_KATAKANA_HEAD = /^\p{Script=Katakana}(?!\p{Script=Katakana})/u;
|
|
81
|
+
const KATAKANA_END = /\p{Script=Katakana}$/u;
|
|
82
|
+
|
|
83
|
+
/** A piece the tokenizer cut out of a katakana run (ミスっ read as ミ and スる): not a word of its own. */
|
|
84
|
+
const isCutFromKatakana = ({ token, previous }: InContext): boolean =>
|
|
85
|
+
ONE_KATAKANA_HEAD.test(token.surface) && token.surface.length > 1 && isTouching(previous, token) && KATAKANA_END.test(previous?.surface ?? "");
|
|
86
|
+
|
|
87
|
+
type Skips = { readonly skip: ReadonlySet<string>; readonly idioms: ReadonlySet<string> };
|
|
88
|
+
|
|
89
|
+
const readingKeyOf = (word: InContext, { skip, idioms }: Skips): string | undefined => {
|
|
90
|
+
const { token } = word;
|
|
49
91
|
const lemma = token.lemma;
|
|
50
92
|
if (!CONTENT.has(token.pos) || token.reading === undefined || lemma === undefined || !JAPANESE_WORD.test(lemma) || skip.has(lemma)) return undefined;
|
|
51
93
|
const reading = lemmaReading(token.surface, lemma, token.reading);
|
|
52
|
-
if (reading === undefined || [...reading].length < MIN_READING || skip.has(reading)) return undefined;
|
|
53
|
-
return `${token.pos}|${useOf(
|
|
94
|
+
if (reading === undefined || [...reading].length < MIN_READING || skip.has(reading) || isCutFromKatakana(word)) return undefined;
|
|
95
|
+
return `${token.pos}|${useOf(word, idioms)}|${reading}`;
|
|
54
96
|
};
|
|
55
97
|
|
|
56
98
|
/** Japanese words keyed by part of speech, use and the reading of the dictionary form, spelled as the dictionary form. */
|
|
57
|
-
const readingWords = (sentence: Sentence, isOpen: IsOpen,
|
|
99
|
+
const readingWords = (sentence: Sentence, isOpen: IsOpen, skips: Skips): Placed[] => {
|
|
58
100
|
const tokens = sentence.tokens ?? [];
|
|
59
101
|
return tokens.flatMap((token, at): Placed[] => {
|
|
60
|
-
const key = readingKeyOf(token, tokens[at - 1],
|
|
102
|
+
const key = readingKeyOf({ token, previous: tokens[at - 1], before: tokens[at - 2] }, skips);
|
|
61
103
|
const local = token.span.start - sentence.span.start;
|
|
62
104
|
if (key === undefined || token.lemma === undefined || !isOpen(local, local + token.surface.length)) return [];
|
|
63
105
|
return [{ key, spelling: token.lemma, sentence, offset: token.span.start }];
|
|
@@ -109,17 +151,20 @@ const isPartOfAddress = (text: string, start: number, end: number): boolean =>
|
|
|
109
151
|
|
|
110
152
|
/**
|
|
111
153
|
* Latin words keyed without hyphens and case (e-mail and email, GitHub and Github). A word in capitals only (TEAMS, MAY) is
|
|
112
|
-
* emphasis or an acronym, not a spelling of the word, and is left out
|
|
154
|
+
* emphasis or an acronym, not a spelling of the word, and is left out; so are a name in capitals with an ending (SENDs) and
|
|
155
|
+
* the letters of an acronym of the sentence picked out (CLImatology for CLIPER).
|
|
113
156
|
*/
|
|
114
|
-
const latinWords = (sentence: Sentence, isOpen: IsOpen, skip: ReadonlySet<string>): Placed[] =>
|
|
115
|
-
|
|
157
|
+
const latinWords = (sentence: Sentence, isOpen: IsOpen, skip: ReadonlySet<string>): Placed[] => {
|
|
158
|
+
const acronyms = acronymsIn(sentence.text);
|
|
159
|
+
return [...sentence.text.matchAll(LATIN_WORD)].flatMap((match): Placed[] => {
|
|
116
160
|
const word = match[0];
|
|
117
161
|
const plain = word.toLowerCase().replaceAll("-", "");
|
|
118
162
|
const end = match.index + word.length;
|
|
119
|
-
if (plain.length < MIN_LATIN_KEY || !LOWER.test(word) || skip.has(word.toLowerCase())) return [];
|
|
163
|
+
if (plain.length < MIN_LATIN_KEY || !LOWER.test(word) || isCapitalsNotSpelling(word, acronyms) || skip.has(word.toLowerCase())) return [];
|
|
120
164
|
if (isPartOfAddress(sentence.text, match.index, end) || !isOpen(match.index, end)) return [];
|
|
121
165
|
return [{ key: `latin|${plain}`, spelling: latinSpelling(word), shown: word, sentence, offset: sentence.span.start + match.index }];
|
|
122
166
|
});
|
|
167
|
+
};
|
|
123
168
|
|
|
124
169
|
/** How the usual spelling is written where it first appears (gitHub is shown GitHub). */
|
|
125
170
|
const shownUsual = (words: readonly Placed[], { word, usual }: OddSpelling<Placed>): string =>
|
|
@@ -140,11 +185,11 @@ const findingOf = (words: readonly Placed[], odd: OddSpelling<Placed>): Finding
|
|
|
140
185
|
* document writes less is pointed at. No way is called right; limit is the largest share, in percent, the minority may have.
|
|
141
186
|
*/
|
|
142
187
|
export const orthographicVariant: Detector = (doc, options): Finding[] => {
|
|
143
|
-
const
|
|
188
|
+
const skips: Skips = { skip: new Set([...patternsOf(doc, DISTINCT), ...patternsOf(doc, FUKUSHI)]), idioms: new Set(patternsOf(doc, IDIOM)) };
|
|
144
189
|
const placed = doc.sentences.map((sentence) => ({ sentence, isOpen: isOpenIn(sentence, doc.names ?? []) }));
|
|
145
|
-
const reading = byKanji(placed.flatMap(({ sentence, isOpen }) => readingWords(sentence, isOpen,
|
|
190
|
+
const reading = byKanji(placed.flatMap(({ sentence, isOpen }) => readingWords(sentence, isOpen, skips)));
|
|
146
191
|
const katakana = placed.flatMap(({ sentence, isOpen }) => katakanaWords(sentence, isOpen));
|
|
147
|
-
const latin = placed.flatMap(({ sentence, isOpen }) => latinWords(sentence, isOpen, skip));
|
|
192
|
+
const latin = placed.flatMap(({ sentence, isOpen }) => latinWords(sentence, isOpen, skips.skip));
|
|
148
193
|
const odd = [reading, katakana, latin].flatMap((words) => oddSpellings(words, options.limit));
|
|
149
194
|
const all = [...reading, ...katakana, ...latin];
|
|
150
195
|
// A word can be odd by its reading and by its katakana key at once; one place is said once.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// A party called by a role word (受託者, the Vendor) after the contract gave it a short name (乙, the "Supplier"). The
|
|
2
|
+
// definitions come from the document's structure tree; the role words, short names and company forms from the language
|
|
3
|
+
// package's word lists (party-role, party-short-name, company-form).
|
|
4
|
+
import { definedTerms } from "../structure/definition-use.ts";
|
|
5
|
+
import { partiesOf, roleUses } from "../structure/party-role.ts";
|
|
6
|
+
import { quoteAt } from "./structure-tree.ts";
|
|
7
|
+
import type { Detector, Finding, ProseDocument } from "../plugin.ts";
|
|
8
|
+
|
|
9
|
+
const patternsOf = (doc: ProseDocument, lexicon: string): string[] => (doc.lexicons[lexicon] ?? []).map((entry) => entry.pattern);
|
|
10
|
+
|
|
11
|
+
/** The sentence holding a definition: the role words in the sentences that name the parties are part of naming them. */
|
|
12
|
+
const sentenceAt = (doc: ProseDocument, offset: number): { readonly start: number; readonly end: number } =>
|
|
13
|
+
doc.sentences.find((sentence) => sentence.span.start <= offset && offset < sentence.span.end)?.span ?? { start: offset, end: offset };
|
|
14
|
+
|
|
15
|
+
const NAME_SEPARATOR: Readonly<Record<string, string>> = { ja: "、" };
|
|
16
|
+
|
|
17
|
+
export const partyRoleName: Detector = (doc): Finding[] => {
|
|
18
|
+
if (doc.structure === undefined) return [];
|
|
19
|
+
const terms = definedTerms(doc.structure);
|
|
20
|
+
const words = { roles: patternsOf(doc, "party-role"), shortNames: patternsOf(doc, "party-short-name"), companyForms: patternsOf(doc, "company-form") };
|
|
21
|
+
const parties = partiesOf(doc.source, terms, words);
|
|
22
|
+
if (parties.length === 0) return [];
|
|
23
|
+
// From the sentence that names the first party: a party named later (a subcontractor ("Recipient")) does not hide the role words before it.
|
|
24
|
+
const naming = parties.map((party) => sentenceAt(doc, party.end - 1));
|
|
25
|
+
const after = Math.min(...naming.map((sentence) => sentence.end));
|
|
26
|
+
const names = [...new Set(parties.map((party) => party.term))].join(NAME_SEPARATOR[doc.language] ?? ", ");
|
|
27
|
+
const texts = doc.sentences.map((sentence) => ({ start: sentence.span.start, text: sentence.text }));
|
|
28
|
+
return roleUses(
|
|
29
|
+
doc.source,
|
|
30
|
+
texts,
|
|
31
|
+
words.roles,
|
|
32
|
+
terms.map((term) => term.term),
|
|
33
|
+
after,
|
|
34
|
+
)
|
|
35
|
+
.filter((use) => !naming.some((sentence) => sentence.start <= use.offset && use.offset < sentence.end))
|
|
36
|
+
.map((use) => ({
|
|
37
|
+
rule: "party-role-name",
|
|
38
|
+
severity: "info",
|
|
39
|
+
line: 0,
|
|
40
|
+
column: 0,
|
|
41
|
+
quote: quoteAt(doc.source, use.offset),
|
|
42
|
+
values: { role: use.role, names, offset: use.offset },
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// A quotation the text gives to someone (「…」と述べている, according to X, "…") in a paragraph that names no source for it:
|
|
2
|
+
// no link, no footnote or numbered citation, no year in brackets. Whether the words are really that person's is for
|
|
3
|
+
// `chaff cite` against the source; this only says that there is nothing to check them against. The words that give a
|
|
4
|
+
// quotation to someone come from the language package's word list quote-attribution. Pure.
|
|
5
|
+
import { QUOTATION_MARKS, quotedSpans } from "../quoted-span.ts";
|
|
6
|
+
import type { Detector, Finding, LexiconEntry, ProseDocument } from "../plugin.ts";
|
|
7
|
+
|
|
8
|
+
export type QuoteText = { readonly start: number; readonly text: string };
|
|
9
|
+
|
|
10
|
+
export type QuoteParagraph = { readonly source: string; readonly sentences: readonly QuoteText[] };
|
|
11
|
+
|
|
12
|
+
export type UnsourcedQuote = { readonly offset: number; readonly quote: string };
|
|
13
|
+
|
|
14
|
+
/** Shorter than this, a quotation is a term or a label (「保存」, "Save"), not someone's words. */
|
|
15
|
+
const MIN_QUOTE_CHARS = 10;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A link, a bare URL, a footnote mark, a numbered citation ([3]) or a year that ends a bracket as a citation's does: alone
|
|
19
|
+
* ((1975), (1999年)), after a comma ((架空の本、1975年)) or after a name ((Brooks 1975)). Not (port 2000).
|
|
20
|
+
*/
|
|
21
|
+
const SOURCE_MARKS = [
|
|
22
|
+
/\]\(/u,
|
|
23
|
+
/https?:\/\//u,
|
|
24
|
+
/\[\^[^\]\s]+\]/u,
|
|
25
|
+
/\[\d{1,3}(?:[,,、–-]\s*\d{1,3})*\]/u,
|
|
26
|
+
/[((](?:1[5-9]|20)\d\d[a-z]?年?[))]/u,
|
|
27
|
+
/[((][^()()\n]*[,、,]\s*(?:1[5-9]|20)\d\d[a-z]?年?[))]/u,
|
|
28
|
+
/[((]\p{Lu}[^()()\n]*\s(?:1[5-9]|20)\d\d[a-z]?[))]/u,
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
/** How far before a quotation a cue may end ("According to the study, “…”", 先輩によれば「…」). */
|
|
32
|
+
const CUE_REACH_BEFORE = 40;
|
|
33
|
+
/** How far after a quotation a cue may start: a space ("“…,” said"), or none (「…」と述べた, not 「…」などと書く). */
|
|
34
|
+
const CUE_REACH_AFTER = 1;
|
|
35
|
+
|
|
36
|
+
const LATIN = /\p{Script=Latin}/u;
|
|
37
|
+
const LETTER = /\p{L}/u;
|
|
38
|
+
|
|
39
|
+
const namesSource = (paragraph: string): boolean => SOURCE_MARKS.some((mark) => mark.test(paragraph));
|
|
40
|
+
|
|
41
|
+
const escaped = (word: string): string => word.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Where the cue stands in the sentence, ignoring case, in the sentence's own positions (lowercasing first would move them:
|
|
45
|
+
* İ becomes two units). An English cue is not read inside a longer word (says in essays).
|
|
46
|
+
*/
|
|
47
|
+
const cueStarts = (text: string, cue: string): number[] => {
|
|
48
|
+
if (cue === "") return [];
|
|
49
|
+
return [...text.matchAll(new RegExp(escaped(cue), "giu"))]
|
|
50
|
+
.map((match) => match.index)
|
|
51
|
+
.filter((at) => !LATIN.test(cue) || (!LETTER.test(text.charAt(at - 1)) && !LETTER.test(text.charAt(at + cue.length))));
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type Quoted = { readonly start: number; readonly end: number };
|
|
55
|
+
|
|
56
|
+
/** A cue just before the quotation's opening mark, or just after its closing mark. position says which side it may stand on. */
|
|
57
|
+
const isAttributed = (text: string, quoted: Quoted, cues: readonly LexiconEntry[]): boolean =>
|
|
58
|
+
cues.some((cue) =>
|
|
59
|
+
cueStarts(text, cue.pattern).some((at) => {
|
|
60
|
+
const before = cue.position !== "after" && at + cue.pattern.length <= quoted.start - 1 && at + cue.pattern.length >= quoted.start - 1 - CUE_REACH_BEFORE;
|
|
61
|
+
const after = cue.position !== "before" && at >= quoted.end + 1 && at <= quoted.end + 1 + CUE_REACH_AFTER;
|
|
62
|
+
return before || after;
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const quotesIn = (sentence: QuoteText, cues: readonly LexiconEntry[]): UnsourcedQuote[] => {
|
|
67
|
+
return quotedSpans(sentence.text, QUOTATION_MARKS)
|
|
68
|
+
.filter((span) => [...sentence.text.slice(span.start, span.end).trim()].length >= MIN_QUOTE_CHARS && isAttributed(sentence.text, span, cues))
|
|
69
|
+
.map((span) => ({ offset: sentence.start + span.start, quote: sentence.text.slice(span.start, span.end).trim() }));
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** Each quotation given to someone, in a paragraph that names no source. cues: the word list quote-attribution. */
|
|
73
|
+
export const unsourcedQuotes = (paragraphs: readonly QuoteParagraph[], cues: readonly LexiconEntry[]): UnsourcedQuote[] =>
|
|
74
|
+
paragraphs.filter((paragraph) => !namesSource(paragraph.source)).flatMap((paragraph) => paragraph.sentences.flatMap((sentence) => quotesIn(sentence, cues)));
|
|
75
|
+
|
|
76
|
+
export const quoteWithoutSource: Detector = (doc: ProseDocument): Finding[] =>
|
|
77
|
+
unsourcedQuotes(
|
|
78
|
+
doc.paragraphs.map((paragraph) => ({
|
|
79
|
+
source: doc.source.slice(paragraph.span.start, paragraph.span.end),
|
|
80
|
+
sentences: paragraph.sentences.map((sentence) => ({ start: sentence.span.start, text: sentence.text })),
|
|
81
|
+
})),
|
|
82
|
+
doc.lexicons["quote-attribution"] ?? [],
|
|
83
|
+
).map((hit) => ({
|
|
84
|
+
rule: "quote-without-source",
|
|
85
|
+
severity: "info",
|
|
86
|
+
line: 0,
|
|
87
|
+
column: 0,
|
|
88
|
+
quote: hit.quote,
|
|
89
|
+
values: { quote: hit.quote, offset: hit.offset },
|
|
90
|
+
}));
|
|
@@ -12,7 +12,7 @@ const inputOf = (doc: ProseDocument): ReferenceInput | undefined => {
|
|
|
12
12
|
return {
|
|
13
13
|
source: doc.source,
|
|
14
14
|
references: inDocumentOrder(tree).filter((node) => node.kind === "reference" && node.attrs["document"] === undefined),
|
|
15
|
-
targetOf: referenceResolver(tree),
|
|
15
|
+
targetOf: referenceResolver(tree, doc.source),
|
|
16
16
|
words: {
|
|
17
17
|
asides: patternsOf(doc, "reference-aside"),
|
|
18
18
|
topicLinks: patternsOf(doc, "reference-topic-link"),
|
|
@@ -4,6 +4,7 @@ import { overlapsAny, spanIndex } from "../compare/spans.ts";
|
|
|
4
4
|
import type { DurationUnit } from "../derived/date-arithmetic.ts";
|
|
5
5
|
import { relativeMismatches, type DatedValue, type Relative } from "../derived/relative-dates.ts";
|
|
6
6
|
import { quoteAt } from "./structure-tree.ts";
|
|
7
|
+
import { dayWordFindings } from "./relative-day-words.ts";
|
|
7
8
|
|
|
8
9
|
/** 期間の単位の語彙表。relative-year-unit は、向きの語が付くときだけ期間になる単位(「1年前」の年)。 */
|
|
9
10
|
const DURATION_LEXICONS: readonly (readonly [string, DurationUnit])[] = [
|
|
@@ -96,7 +97,7 @@ export const relativeDateMismatch: Detector = (doc): Finding[] => {
|
|
|
96
97
|
relatives: relativesOf(doc, amounts),
|
|
97
98
|
links: patternsOf(doc, "relative-link"),
|
|
98
99
|
};
|
|
99
|
-
|
|
100
|
+
const counted = relativeMismatches(input).map((mismatch): Finding => ({
|
|
100
101
|
rule: "relative-date-mismatch",
|
|
101
102
|
severity: "warning",
|
|
102
103
|
line: 0,
|
|
@@ -110,4 +111,5 @@ export const relativeDateMismatch: Detector = (doc): Finding[] => {
|
|
|
110
111
|
offset: mismatch.target.start,
|
|
111
112
|
},
|
|
112
113
|
}));
|
|
114
|
+
return [...counted, ...dayWordFindings(doc, dates)];
|
|
113
115
|
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// relative-date-mismatch, the day words: 「来週月曜(10月12日)」「明日(10月7日)」"next Monday (October 12)" against the
|
|
2
|
+
// date field of an email or minutes. The words are the lexicons relative-week, relative-day, weekday and message-date-field;
|
|
3
|
+
// the reckoning is derived/relative-weekdays.ts.
|
|
4
|
+
import type { Finding, ProseDocument, Span } from "../plugin.ts";
|
|
5
|
+
import type { DatedValue } from "../derived/relative-dates.ts";
|
|
6
|
+
import { relativeDayMismatch, type DayWord } from "../derived/relative-weekdays.ts";
|
|
7
|
+
import { escapeRegExp } from "../orthography.ts";
|
|
8
|
+
import { quoteAt } from "./structure-tree.ts";
|
|
9
|
+
|
|
10
|
+
const FULL = /^\d{4}-\d{2}-\d{2}$/u;
|
|
11
|
+
const LATIN = /^[A-Za-z]/u;
|
|
12
|
+
/** 文書の書き出し: 最初の見出しより前と、最初の見出しの節。メールや議事録の頭の日付(日付:、Date:)が書かれる所。 */
|
|
13
|
+
const OPENING_SECTIONS = 1;
|
|
14
|
+
/** The separators a date may follow its day word with: a space, a bracket, a comma (「来週月曜(10月12日)」). */
|
|
15
|
+
const SEPARATORS = /[\s,、,((::]/gu;
|
|
16
|
+
|
|
17
|
+
const wordPattern = (word: string): RegExp => new RegExp(LATIN.test(word) ? `\\b${escapeRegExp(word)}\\b` : escapeRegExp(word), "giu");
|
|
18
|
+
|
|
19
|
+
const spansOf = (source: string, word: string): Span[] =>
|
|
20
|
+
[...source.matchAll(wordPattern(word))].map((match) => ({ start: match.index, end: match.index + match[0].length }));
|
|
21
|
+
|
|
22
|
+
/** The weekday written right after a week word (Sunday is 0), and where it ends: the name, or the name without its last 日 (月曜). */
|
|
23
|
+
const weekdayAt = (source: string, at: number, names: readonly string[]): { readonly weekday: number; readonly end: number } | undefined => {
|
|
24
|
+
const gap = source.slice(at).length - source.slice(at).trimStart().length;
|
|
25
|
+
const rest = source.slice(at + gap).toLowerCase();
|
|
26
|
+
const found = names
|
|
27
|
+
.map((name, weekday) => {
|
|
28
|
+
const lower = name.toLowerCase();
|
|
29
|
+
const short = LATIN.test(name) ? lower : lower.slice(0, -1);
|
|
30
|
+
const written = [lower, short].find((form) => form.length >= 2 && rest.startsWith(form));
|
|
31
|
+
return written === undefined ? undefined : { weekday, end: at + gap + written.length };
|
|
32
|
+
})
|
|
33
|
+
.find((entry) => entry !== undefined);
|
|
34
|
+
return gap > 1 ? undefined : found;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const dayWordsOf = (doc: ProseDocument): DayWord[] => {
|
|
38
|
+
const names = (doc.lexicons["weekday"] ?? []).map((entry) => entry.pattern);
|
|
39
|
+
const weeks = (doc.lexicons["relative-week"] ?? []).flatMap((entry): DayWord[] =>
|
|
40
|
+
spansOf(doc.source, entry.pattern).flatMap((span) => {
|
|
41
|
+
const day = weekdayAt(doc.source, span.end, names);
|
|
42
|
+
return day === undefined ? [] : [{ start: span.start, end: day.end, kind: "weekday", weeks: Number(entry.group), weekday: day.weekday }];
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
45
|
+
const days = (doc.lexicons["relative-day"] ?? []).flatMap((entry): DayWord[] =>
|
|
46
|
+
spansOf(doc.source, entry.pattern).map((span) => ({ ...span, kind: "day", days: Number(entry.group) })),
|
|
47
|
+
);
|
|
48
|
+
// 「再来週」の中の「来週」、「明後日」の中の「明日」は読まない: 長い語が覆う語を落とす。
|
|
49
|
+
const all = [...weeks, ...days];
|
|
50
|
+
return all.filter(
|
|
51
|
+
(word) => !all.some((other) => other !== word && other.start <= word.start && word.end <= other.end && other.end - other.start > word.end - word.start),
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** The date written right after the day word: only separators and a link word (の, on) between. */
|
|
56
|
+
const targetOf = (doc: ProseDocument, dates: readonly DatedValue[], word: DayWord): DatedValue | undefined => {
|
|
57
|
+
const next = dates.find((date) => date.start >= word.end);
|
|
58
|
+
if (next === undefined) return undefined;
|
|
59
|
+
const between = doc.source.slice(word.end, next.start).replace(SEPARATORS, "").toLowerCase();
|
|
60
|
+
const links = (doc.lexicons["relative-link"] ?? []).map((entry) => entry.pattern.replace(SEPARATORS, "").toLowerCase());
|
|
61
|
+
return between === "" || links.includes(between) ? next : undefined;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const lineStartAt = (source: string, offset: number): number => source.lastIndexOf("\n", offset - 1) + 1;
|
|
65
|
+
|
|
66
|
+
const lineAt = (source: string, offset: number): string => {
|
|
67
|
+
const start = lineStartAt(source, offset);
|
|
68
|
+
const end = source.indexOf("\n", offset);
|
|
69
|
+
return source.slice(start, end === -1 ? source.length : end);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const FIELD_MARK = /^\s*(?:[-*+]\s+)?(?<label>[^::]{1,12})[::]/u;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The date the day words count from: the first full date on a date field of the opening (「日付:」「日時:」"Date:", lexicon
|
|
76
|
+
* message-date-field), before the first heading or in the first heading's section. A document without one (a press release
|
|
77
|
+
* whose only date is an update stamp) has no date to count from.
|
|
78
|
+
*/
|
|
79
|
+
const baseOf = (doc: ProseDocument, dates: readonly DatedValue[], starts: readonly number[]): DatedValue | undefined => {
|
|
80
|
+
const labels = (doc.lexicons["message-date-field"] ?? []).map((entry) => entry.pattern.toLowerCase());
|
|
81
|
+
return dates.find((date) => {
|
|
82
|
+
const label = FIELD_MARK.exec(lineAt(doc.source, date.start))?.groups?.["label"]?.trim().toLowerCase() ?? "";
|
|
83
|
+
return FULL.test(date.value) && labels.includes(label) && starts.filter((start) => start <= date.start).length <= OPENING_SECTIONS;
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const QUOTED_LINE = /^\s*>/u;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Day words the document's date does not count: in a quoted reply (「> 明日(10月2日)」 counts from the quoted mail's date),
|
|
91
|
+
* or in a section whose heading names a date (「## 10月1日の会」: its 「本日」 is that day).
|
|
92
|
+
*/
|
|
93
|
+
const countedFromBase = (doc: ProseDocument, word: DayWord, datedHeadings: readonly number[], starts: readonly number[]): boolean => {
|
|
94
|
+
const section = starts.filter((start) => start <= word.start).at(-1);
|
|
95
|
+
return !QUOTED_LINE.test(lineAt(doc.source, word.start)) && (section === undefined || !datedHeadings.includes(section));
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const dayWordFindings = (doc: ProseDocument, dates: readonly DatedValue[]): Finding[] => {
|
|
99
|
+
const starts = doc.sections.filter((section) => section.depth > 0).map((section) => section.span.start);
|
|
100
|
+
const base = baseOf(doc, dates, starts);
|
|
101
|
+
if (base === undefined) return [];
|
|
102
|
+
const datedHeadings = starts.filter((start) => dates.some((date) => date.start >= start && date.start < start + lineAt(doc.source, start).length));
|
|
103
|
+
return dayWordsOf(doc)
|
|
104
|
+
.filter((word) => countedFromBase(doc, word, datedHeadings, starts))
|
|
105
|
+
.flatMap((word): Finding[] => {
|
|
106
|
+
const target = targetOf(doc, dates, word);
|
|
107
|
+
const expected = target === undefined || target === base ? undefined : relativeDayMismatch(base.value, word, target.value);
|
|
108
|
+
if (target === undefined || expected === undefined) return [];
|
|
109
|
+
return [
|
|
110
|
+
{
|
|
111
|
+
rule: "relative-date-mismatch",
|
|
112
|
+
severity: "warning",
|
|
113
|
+
line: 0,
|
|
114
|
+
column: 0,
|
|
115
|
+
quote: quoteAt(doc.source, target.start),
|
|
116
|
+
values: {
|
|
117
|
+
base: doc.source.slice(base.start, base.end),
|
|
118
|
+
relative: doc.source.slice(word.start, word.end),
|
|
119
|
+
target: doc.source.slice(target.start, target.end),
|
|
120
|
+
expected,
|
|
121
|
+
offset: target.start,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
];
|
|
125
|
+
});
|
|
126
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Span } from "../plugin.ts";
|
|
2
|
+
|
|
3
|
+
/** 行の頭の引用の印と字下げ、箇条の印、チェックボックス。この後ろで太字が開く。 */
|
|
4
|
+
const QUOTE_INDENT = /^(?:[ \t]*>)*[ \t]*/u;
|
|
5
|
+
const ITEM_MARKER = /^(?:[-*+]|\d{1,9}[.)])[ \t]+/u;
|
|
6
|
+
const TASK_BOX = /^\[[ xX]\][ \t]+/u;
|
|
7
|
+
const BOLD = /^(?:\*\*|__)$/u;
|
|
8
|
+
|
|
9
|
+
type Opening = { readonly marker: string; readonly item: boolean };
|
|
10
|
+
|
|
11
|
+
/** 行の頭から文の始まりまで(before)が、印の後ろで開いた太字だけか。 */
|
|
12
|
+
const openingOf = (before: string): Opening | undefined => {
|
|
13
|
+
const unquoted = before.replace(QUOTE_INDENT, "");
|
|
14
|
+
const rest = unquoted.replace(ITEM_MARKER, "").replace(TASK_BOX, "");
|
|
15
|
+
return BOLD.test(rest) ? { marker: rest, item: rest.length < unquoted.length } : undefined;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** 段落の切れ目になる前の行: 空の行(引用の中の空の行も)と見出し。 */
|
|
19
|
+
const BLOCK_BEFORE = /^(?:[ \t]*>)*[ \t]*(?:#.*)?$/u;
|
|
20
|
+
|
|
21
|
+
/** 文の終わりの句読点。札の句点を太字の外に書く形(**速く書ける**。)もある。 */
|
|
22
|
+
const STOP = /[。..!?!?]$/u;
|
|
23
|
+
|
|
24
|
+
const lineAround = (source: string, offset: number): { readonly start: number; readonly end: number } => {
|
|
25
|
+
const end = source.indexOf("\n", offset);
|
|
26
|
+
return { start: source.lastIndexOf("\n", offset - 1) + 1, end: end === -1 ? source.length : end };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** 太字が閉じる位置。文の直後か、文末の句読点の直前。 */
|
|
30
|
+
const closingOf = (source: string, span: Span, marker: string): number | undefined => {
|
|
31
|
+
if (source.startsWith(marker, span.end)) return span.end;
|
|
32
|
+
const stop = STOP.exec(source.slice(span.start, span.end))?.[0];
|
|
33
|
+
const before = stop === undefined ? -1 : span.end - stop.length - marker.length;
|
|
34
|
+
return before > span.start && source.startsWith(marker, before) ? before : undefined;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** 文全体を一つの太字が包むなら、太字と文の後ろの位置。途中で閉じる太字(**a** と **b。**)は包んでいない。 */
|
|
38
|
+
const closedAt = (source: string, span: Span, marker: string): number | undefined => {
|
|
39
|
+
const closing = closingOf(source, span, marker);
|
|
40
|
+
if (closing === undefined || source.slice(span.start, closing).includes(marker)) return undefined;
|
|
41
|
+
return Math.max(closing + marker.length, span.end);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** 行の頭が段落の頭か。箇条の印のある行は項目の頭。折り返した段落の続きの行(前の行に文がある)は頭ではない。 */
|
|
45
|
+
const opensBlock = (source: string, lineStart: number, item: boolean): boolean => {
|
|
46
|
+
if (item || lineStart === 0) return true;
|
|
47
|
+
return BLOCK_BEFORE.test(source.slice(source.lastIndexOf("\n", lineStart - 2) + 1, lineStart - 1));
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 行の頭の太字だけでできた文で、同じ行に続きがあるもの(「- **速く書ける。** 細かな文法を覚えなくても書けます。」の「速く書ける。」)。
|
|
52
|
+
* 項目や段落の札で、見出しと同じく本文の文ではない。太字だけの行(「**注意してください。**」)は札ではなく文。
|
|
53
|
+
*/
|
|
54
|
+
export const isRunInLabel = (source: string, span: Span): boolean => {
|
|
55
|
+
const line = lineAround(source, span.start);
|
|
56
|
+
const opening = openingOf(source.slice(line.start, span.start));
|
|
57
|
+
if (opening === undefined || !opensBlock(source, line.start, opening.item)) return false;
|
|
58
|
+
const after = closedAt(source, span, opening.marker);
|
|
59
|
+
return after !== undefined && after <= line.end && /\S/u.test(source.slice(after, line.end));
|
|
60
|
+
};
|
|
@@ -73,12 +73,20 @@ export const sentenceConjunctiveCount: Detector = (doc, options): Finding[] => {
|
|
|
73
73
|
|
|
74
74
|
type Opened = { readonly sentence: Sentence; readonly opener: string | undefined };
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
/**
|
|
77
|
+
* The lexicon's word the sentence opens with, unless it opens with one of `notOpeners`: "This Agreement" and "This section"
|
|
78
|
+
* point at the document itself, not back at the sentence before.
|
|
79
|
+
*/
|
|
80
|
+
const openerOf = (sentence: Sentence, lexicon: Lexicon, notOpeners: Lexicon): string | undefined =>
|
|
81
|
+
notOpeners.some((entry) => entryOpens(sentence, entry)) ? undefined : lexicon.find((entry) => entryOpens(sentence, entry))?.pattern;
|
|
82
|
+
|
|
83
|
+
/** The phrases that open a sentence with a lexicon word but do not point back (this-document references). */
|
|
84
|
+
export const NOT_OPENER_LEXICON = "demonstrative-not-opener";
|
|
77
85
|
|
|
78
86
|
/** Runs of consecutive sentences in one paragraph that each open with a lexicon word. */
|
|
79
|
-
export const openerRuns = (sentences: readonly Sentence[], lexicon: Lexicon): Opened[][] =>
|
|
87
|
+
export const openerRuns = (sentences: readonly Sentence[], lexicon: Lexicon, notOpeners: Lexicon = []): Opened[][] =>
|
|
80
88
|
sentences
|
|
81
|
-
.map((sentence) => ({ sentence, opener: openerOf(sentence, lexicon) }))
|
|
89
|
+
.map((sentence) => ({ sentence, opener: openerOf(sentence, lexicon, notOpeners) }))
|
|
82
90
|
.reduce<Opened[][]>(
|
|
83
91
|
(runs, opened) => {
|
|
84
92
|
if (opened.opener === undefined) return [...runs, []];
|
|
@@ -104,8 +112,9 @@ const runFinding = (run: readonly Opened[], options: DetectorOptions): Finding =
|
|
|
104
112
|
/** More than limit sentences in a row within one paragraph, each opening with a word from the lexicon (これ, その). */
|
|
105
113
|
export const openerRun: Detector = (doc, options): Finding[] => {
|
|
106
114
|
const lexicon = options.lexicon ?? [];
|
|
115
|
+
const notOpeners = doc.lexicons[NOT_OPENER_LEXICON] ?? [];
|
|
107
116
|
return doc.paragraphs.flatMap((paragraph) =>
|
|
108
|
-
openerRuns(paragraph.sentences, lexicon)
|
|
117
|
+
openerRuns(paragraph.sentences, lexicon, notOpeners)
|
|
109
118
|
.filter((run) => run.length > options.limit)
|
|
110
119
|
.map((run) => runFinding(run, options)),
|
|
111
120
|
);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { endingTokens, isClosed } from "../sentence-shape.ts";
|
|
2
2
|
import { enumeratedRuns, enumeratorStarts, numberedStarts } from "./enumerated-runs.ts";
|
|
3
3
|
import { continuesInto, groupOf, registerOf, slipsOf, type Register } from "./register.ts";
|
|
4
|
+
import { isRunInLabel } from "./run-in-label.ts";
|
|
4
5
|
import type { Detector, Finding, LexiconEntry, ProseDocument, Sentence, Span } from "../plugin.ts";
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -8,7 +9,7 @@ import type { Detector, Finding, LexiconEntry, ProseDocument, Sentence, Span } f
|
|
|
8
9
|
*
|
|
9
10
|
* どちらが正しいかは決めない。決めると、方針の違う書き手にそのまま無視される。
|
|
10
11
|
* 見るのは文書の中での一貫性だけで、少数派のほうを指摘する。spec §12.3 の方針を日本語にも。
|
|
11
|
-
* 終止符で終わらないもの(見出しの下の `MaaSサービス`
|
|
12
|
+
* 終止符で終わらないもの(見出しの下の `MaaSサービス` のような名前だけの行)と、項目や段落の頭の太字の札(**速く書ける。**)は文として数えない。
|
|
12
13
|
*/
|
|
13
14
|
type Entry = { readonly sentence: Sentence; readonly register: Register; readonly group: number | undefined };
|
|
14
15
|
|
|
@@ -35,7 +36,7 @@ export const judgedSentences = (doc: ProseDocument, polite: readonly LexiconEntr
|
|
|
35
36
|
const neutral = doc.lexicons["neutral-ending"] ?? [];
|
|
36
37
|
const lists = doc.lists.map((list) => list.span);
|
|
37
38
|
const found = doc.sentences.flatMap((sentence, index): { sentence: Sentence; register: Register }[] => {
|
|
38
|
-
if (!isClosed(sentence) || continuesInto(sentence, doc.sentences[index + 1])) return [];
|
|
39
|
+
if (!isClosed(sentence) || continuesInto(sentence, doc.sentences[index + 1]) || isRunInLabel(doc.source, sentence.span)) return [];
|
|
39
40
|
const register = registerOfSentence(sentence, polite, neutral);
|
|
40
41
|
return register === undefined ? [] : [{ sentence, register }];
|
|
41
42
|
});
|