chaffjs 0.24.0 → 0.26.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/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/detect.d.ts.map +1 -1
- package/dist/detect.js +4 -5
- package/dist/detect.js.map +1 -1
- package/dist/detectors/connective-hierarchy.d.ts +16 -0
- package/dist/detectors/connective-hierarchy.d.ts.map +1 -0
- package/dist/detectors/connective-hierarchy.js +68 -0
- package/dist/detectors/connective-hierarchy.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/missing-final-period.d.ts +17 -0
- package/dist/detectors/missing-final-period.d.ts.map +1 -0
- package/dist/detectors/missing-final-period.js +62 -0
- package/dist/detectors/missing-final-period.js.map +1 -0
- package/dist/detectors/missing-space-after-comma.d.ts +10 -0
- package/dist/detectors/missing-space-after-comma.d.ts.map +1 -0
- package/dist/detectors/missing-space-after-comma.js +42 -0
- package/dist/detectors/missing-space-after-comma.js.map +1 -0
- package/dist/detectors/orthographic-variant.d.ts.map +1 -1
- package/dist/detectors/orthographic-variant.js +44 -17
- 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/connective-hierarchy.d.ts +3 -0
- package/dist/detectors/registry/connective-hierarchy.d.ts.map +1 -0
- package/dist/detectors/registry/connective-hierarchy.js +3 -0
- package/dist/detectors/registry/connective-hierarchy.js.map +1 -0
- package/dist/detectors/registry/missing-final-period.d.ts +3 -0
- package/dist/detectors/registry/missing-final-period.d.ts.map +1 -0
- package/dist/detectors/registry/missing-final-period.js +3 -0
- package/dist/detectors/registry/missing-final-period.js.map +1 -0
- package/dist/detectors/registry/missing-space-after-comma.d.ts +3 -0
- package/dist/detectors/registry/missing-space-after-comma.d.ts.map +1 -0
- package/dist/detectors/registry/missing-space-after-comma.js +3 -0
- package/dist/detectors/registry/missing-space-after-comma.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/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 +4 -1
- package/dist/detectors/structure-tree.d.ts.map +1 -1
- package/dist/detectors/structure-tree.js +21 -2
- 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/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/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/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/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-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/cliche.yaml +28 -8
- package/rules/connective-hierarchy.yaml +62 -0
- 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/missing-final-period.yaml +76 -0
- package/rules/missing-space-after-comma.yaml +57 -0
- package/rules/no-mixed-desumasu.yaml +2 -2
- package/rules/orthographic-variant.yaml +2 -2
- package/rules/party-role-name.yaml +94 -0
- package/rules/quote-without-source.yaml +61 -0
- package/rules/total-mismatch.yaml +8 -8
- package/rules/vague-deadline.yaml +95 -0
- package/rules/weasel-word.yaml +25 -7
- package/skills/chaff/SKILL.md +32 -5
- 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/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/detect.ts +4 -5
- package/src/detectors/connective-hierarchy.ts +99 -0
- package/src/detectors/date-year.ts +51 -12
- package/src/detectors/defined-term-form.ts +28 -6
- package/src/detectors/missing-final-period.ts +79 -0
- package/src/detectors/missing-space-after-comma.ts +54 -0
- package/src/detectors/orthographic-variant.ts +59 -18
- 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/connective-hierarchy.ts +4 -0
- package/src/detectors/registry/missing-final-period.ts +4 -0
- package/src/detectors/registry/missing-space-after-comma.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/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 +28 -6
- package/src/detectors/unbalanced-bracket.ts +25 -10
- package/src/detectors/vague-deadline.ts +132 -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/date-range.ts +28 -3
- package/src/structure/issues.ts +61 -6
- package/src/structure/party-role.ts +94 -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-shape/baseline-load.ts +4 -5
- package/src/style-load.ts +5 -6
|
@@ -4,6 +4,7 @@ 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";
|
|
7
8
|
|
|
8
9
|
/** 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
10
|
type Placed = KeyedWord & { readonly sentence: Sentence; readonly offset: number; readonly shown?: string };
|
|
@@ -22,42 +23,82 @@ const MIN_LATIN_KEY = 3;
|
|
|
22
23
|
/** Lexicons: readings and spellings whose kanji and kana forms mean different things (成る and なる, 者 and もの), and adverbs hiragana-fukushi reads. */
|
|
23
24
|
const DISTINCT = "orthographic-variant-distinct";
|
|
24
25
|
const FUKUSHI = "hiragana-fukushi";
|
|
26
|
+
/** Lexicon: idioms written as noun, particle and verb (気をつける). The verb there is compared apart from the verb on its own. */
|
|
27
|
+
const IDIOM = "orthographic-variant-idiom";
|
|
25
28
|
|
|
26
29
|
const patternsOf = (doc: ProseDocument, id: string): string[] => (doc.lexicons[id] ?? []).map((entry) => entry.pattern);
|
|
27
30
|
|
|
28
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Whether a stretch of the sentence is outside a quotation, the team's names and a reading in brackets (HTTP(えいちてぃーてぃーぴー)):
|
|
33
|
+
* the first two keep their own spelling, and a reading is not a spelling at all.
|
|
34
|
+
*/
|
|
29
35
|
const isOpenIn = (sentence: Sentence, names: readonly string[]): IsOpen => {
|
|
30
|
-
const
|
|
36
|
+
const closed = [...quotedSpans(sentence.text, QUOTATION_MARKS), ...furiganaSpans(sentence.text)];
|
|
31
37
|
const named = nameSpans(sentence.text, names);
|
|
32
|
-
return (start, end) => !isWithinAny(
|
|
38
|
+
return (start, end) => !isWithinAny(closed, { start, end }) && !touchesAny(named, start, end);
|
|
33
39
|
};
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
/** A word and the two words before it, in its sentence. */
|
|
42
|
+
type InContext = { readonly token: Token; readonly previous: Token | undefined; readonly before: Token | undefined };
|
|
43
|
+
|
|
44
|
+
/** A verb's て-form the tokenizer read as a conjunction (追って at the head of a sentence): a kanji stem and て or で. Connectives (そして, それで) are kana. */
|
|
45
|
+
const TE_FORM_CONJUNCTION = /^\p{Script=Han}.*[てで]$/u;
|
|
46
|
+
|
|
47
|
+
/** After a て-form (見てみる). The tokenizer reads the て as a joining word, or the whole て-form as a conjunction (追って / みる). */
|
|
48
|
+
const followsTeForm = (previous: Token | undefined): boolean =>
|
|
49
|
+
(previous?.pos === "SCONJ" && (previous.surface === "て" || previous.surface === "で")) ||
|
|
50
|
+
(previous?.pos === "CCONJ" && TE_FORM_CONJUNCTION.test(previous.surface));
|
|
51
|
+
|
|
52
|
+
const isHelper = ({ token, previous }: InContext): boolean => token.features?.["Bound"] === "Yes" || followsTeForm(previous);
|
|
53
|
+
|
|
54
|
+
const isTouching = (left: Token | undefined, right: Token): boolean => left !== undefined && left.span.end === right.span.start;
|
|
55
|
+
|
|
56
|
+
const HIRAGANA_ONLY = /^[ぁ-ゖー]+$/u;
|
|
57
|
+
|
|
58
|
+
/** A kana noun written onto a noun (全員ぶん): a suffix, which may not be the free noun of the same reading (文). */
|
|
59
|
+
const isKanaSuffix = ({ token, previous }: InContext): boolean =>
|
|
60
|
+
token.pos === "NOUN" && previous?.pos === "NOUN" && isTouching(previous, token) && HIRAGANA_ONLY.test(token.surface);
|
|
61
|
+
|
|
62
|
+
/** The verb of an idiom (気をつける): the noun, the particle and the verb's dictionary form are in the idiom lexicon. */
|
|
63
|
+
const isIdiomVerb = ({ token, previous, before }: InContext, idioms: ReadonlySet<string>): boolean =>
|
|
64
|
+
token.pos === "VERB" && previous?.pos === "ADP" && before !== undefined && idioms.has(`${before.surface}${previous.surface}${token.lemma ?? token.surface}`);
|
|
37
65
|
|
|
38
66
|
/**
|
|
39
67
|
* 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 (このように).
|
|
68
|
+
* The two uses are compared apart, so a document that follows that convention is consistent. A suffix (業務用, 全員ぶん) is a third use:
|
|
69
|
+
* it is not the dependent noun of the same reading (このように). The verb of an idiom (気をつける) is a fourth.
|
|
42
70
|
*/
|
|
43
|
-
const useOf = (
|
|
44
|
-
if (
|
|
45
|
-
|
|
71
|
+
const useOf = (word: InContext, idioms: ReadonlySet<string>): string => {
|
|
72
|
+
if (isIdiomVerb(word, idioms)) return "idiom";
|
|
73
|
+
if (isKanaSuffix(word)) return "suffix";
|
|
74
|
+
if (!isHelper(word)) return "free";
|
|
75
|
+
return word.token.pos === "NOUN" && word.token.features?.["NounType"] !== "Dependent" ? "suffix" : "bound";
|
|
46
76
|
};
|
|
47
77
|
|
|
48
|
-
|
|
78
|
+
/** One katakana and then kana that is not katakana (スる): no verb stem is one katakana long, as サボる and ググる are two. */
|
|
79
|
+
const ONE_KATAKANA_HEAD = /^\p{Script=Katakana}(?!\p{Script=Katakana})/u;
|
|
80
|
+
const KATAKANA_END = /\p{Script=Katakana}$/u;
|
|
81
|
+
|
|
82
|
+
/** A piece the tokenizer cut out of a katakana run (ミスっ read as ミ and スる): not a word of its own. */
|
|
83
|
+
const isCutFromKatakana = ({ token, previous }: InContext): boolean =>
|
|
84
|
+
ONE_KATAKANA_HEAD.test(token.surface) && token.surface.length > 1 && isTouching(previous, token) && KATAKANA_END.test(previous?.surface ?? "");
|
|
85
|
+
|
|
86
|
+
type Skips = { readonly skip: ReadonlySet<string>; readonly idioms: ReadonlySet<string> };
|
|
87
|
+
|
|
88
|
+
const readingKeyOf = (word: InContext, { skip, idioms }: Skips): string | undefined => {
|
|
89
|
+
const { token } = word;
|
|
49
90
|
const lemma = token.lemma;
|
|
50
91
|
if (!CONTENT.has(token.pos) || token.reading === undefined || lemma === undefined || !JAPANESE_WORD.test(lemma) || skip.has(lemma)) return undefined;
|
|
51
92
|
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(
|
|
93
|
+
if (reading === undefined || [...reading].length < MIN_READING || skip.has(reading) || isCutFromKatakana(word)) return undefined;
|
|
94
|
+
return `${token.pos}|${useOf(word, idioms)}|${reading}`;
|
|
54
95
|
};
|
|
55
96
|
|
|
56
97
|
/** 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,
|
|
98
|
+
const readingWords = (sentence: Sentence, isOpen: IsOpen, skips: Skips): Placed[] => {
|
|
58
99
|
const tokens = sentence.tokens ?? [];
|
|
59
100
|
return tokens.flatMap((token, at): Placed[] => {
|
|
60
|
-
const key = readingKeyOf(token, tokens[at - 1],
|
|
101
|
+
const key = readingKeyOf({ token, previous: tokens[at - 1], before: tokens[at - 2] }, skips);
|
|
61
102
|
const local = token.span.start - sentence.span.start;
|
|
62
103
|
if (key === undefined || token.lemma === undefined || !isOpen(local, local + token.surface.length)) return [];
|
|
63
104
|
return [{ key, spelling: token.lemma, sentence, offset: token.span.start }];
|
|
@@ -140,11 +181,11 @@ const findingOf = (words: readonly Placed[], odd: OddSpelling<Placed>): Finding
|
|
|
140
181
|
* document writes less is pointed at. No way is called right; limit is the largest share, in percent, the minority may have.
|
|
141
182
|
*/
|
|
142
183
|
export const orthographicVariant: Detector = (doc, options): Finding[] => {
|
|
143
|
-
const
|
|
184
|
+
const skips: Skips = { skip: new Set([...patternsOf(doc, DISTINCT), ...patternsOf(doc, FUKUSHI)]), idioms: new Set(patternsOf(doc, IDIOM)) };
|
|
144
185
|
const placed = doc.sentences.map((sentence) => ({ sentence, isOpen: isOpenIn(sentence, doc.names ?? []) }));
|
|
145
|
-
const reading = byKanji(placed.flatMap(({ sentence, isOpen }) => readingWords(sentence, isOpen,
|
|
186
|
+
const reading = byKanji(placed.flatMap(({ sentence, isOpen }) => readingWords(sentence, isOpen, skips)));
|
|
146
187
|
const katakana = placed.flatMap(({ sentence, isOpen }) => katakanaWords(sentence, isOpen));
|
|
147
|
-
const latin = placed.flatMap(({ sentence, isOpen }) => latinWords(sentence, isOpen, skip));
|
|
188
|
+
const latin = placed.flatMap(({ sentence, isOpen }) => latinWords(sentence, isOpen, skips.skip));
|
|
148
189
|
const odd = [reading, katakana, latin].flatMap((words) => oddSpellings(words, options.limit));
|
|
149
190
|
const all = [...reading, ...katakana, ...latin];
|
|
150
191
|
// 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"),
|
|
@@ -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
|
});
|
|
@@ -4,6 +4,7 @@ import { numberingBreaks } from "../structure/numbering.ts";
|
|
|
4
4
|
import { weekdayMismatches } from "../structure/weekday.ts";
|
|
5
5
|
import { dateOrderBreaks } from "../structure/date-order.ts";
|
|
6
6
|
import { totalMismatches, type Amount } from "../structure/total.ts";
|
|
7
|
+
import { proseTotalMismatches } from "../structure/prose-total.ts";
|
|
7
8
|
import { rangeFrameOf, reversedRanges, type DatedSpan, type RangeWords } from "../structure/date-range.ts";
|
|
8
9
|
import { percentSumMismatches, type ShareWords } from "../structure/percent-sum.ts";
|
|
9
10
|
import { isQuotedAlone } from "../quoted-span.ts";
|
|
@@ -104,15 +105,35 @@ const amountsOf = (tree: NonNullable<ProseDocument["structure"]>): Amount[] =>
|
|
|
104
105
|
node.kind === "quantity" ? [{ offset: node.span.start, end: node.span.end, value: Number(node.attrs["value"]), unit: String(node.attrs["unit"]) }] : [],
|
|
105
106
|
);
|
|
106
107
|
|
|
107
|
-
|
|
108
|
+
const patternsOf = (doc: ProseDocument, lexicon: string): string[] => (doc.lexicons[lexicon] ?? []).map((entry) => entry.pattern);
|
|
109
|
+
|
|
110
|
+
/** 合計の行と内訳の行、文の中の合計と内訳。同じ金額は一度だけ言う。 */
|
|
111
|
+
const totalIssues = (doc: ProseDocument, tree: NonNullable<ProseDocument["structure"]>): StructureIssue[] => {
|
|
112
|
+
const amounts = amountsOf(tree);
|
|
113
|
+
const lines = totalMismatches(doc.source, amounts, patternsOf(doc, "total-label"));
|
|
114
|
+
const words = {
|
|
115
|
+
totals: patternsOf(doc, "total-phrase"),
|
|
116
|
+
breakdowns: patternsOf(doc, "breakdown-phrase"),
|
|
117
|
+
discounts: patternsOf(doc, "discount-word"),
|
|
118
|
+
joiners: patternsOf(doc, "breakdown-gap-joiner"),
|
|
119
|
+
};
|
|
120
|
+
const prose = proseTotalMismatches(
|
|
121
|
+
doc.source,
|
|
122
|
+
doc.sentences.map((sentence) => sentence.span),
|
|
123
|
+
amounts,
|
|
124
|
+
words,
|
|
125
|
+
);
|
|
126
|
+
return [...lines, ...prose.filter((issue) => !lines.some((line) => line.offset === issue.offset))];
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 合計が内訳の和と合わない。表と箇条書きの合計の行(合計の語は total-label)と、文の中の合計(total-phrase、breakdown-phrase)。
|
|
131
|
+
* 語は言語パッケージの語彙表から取る。
|
|
132
|
+
*/
|
|
108
133
|
export const totalMismatch: Detector = (doc): Finding[] =>
|
|
109
134
|
doc.structure === undefined
|
|
110
135
|
? []
|
|
111
|
-
:
|
|
112
|
-
doc.source,
|
|
113
|
-
amountsOf(doc.structure),
|
|
114
|
-
(doc.lexicons["total-label"] ?? []).map((entry) => entry.pattern),
|
|
115
|
-
).map((issue) => ({
|
|
136
|
+
: totalIssues(doc, doc.structure).map((issue) => ({
|
|
116
137
|
rule: "total-mismatch",
|
|
117
138
|
severity: "error",
|
|
118
139
|
line: 0,
|
|
@@ -127,6 +148,7 @@ const rangeWordsOf = (doc: ProseDocument): RangeWords => ({
|
|
|
127
148
|
closers: (doc.lexicons["range-closer"] ?? []).map((entry) => entry.pattern),
|
|
128
149
|
frames: (doc.lexicons["range-frame"] ?? []).flatMap((entry) => rangeFrameOf(entry.pattern) ?? []),
|
|
129
150
|
changes: (doc.lexicons["date-change-word"] ?? []).map((entry) => entry.pattern),
|
|
151
|
+
weekdays: (doc.lexicons["weekday"] ?? []).map((entry) => entry.pattern),
|
|
130
152
|
});
|
|
131
153
|
|
|
132
154
|
/** 期間の終わりが始まりより前。範囲の記号と語は言語パッケージの語彙表(range-connector、range-opener、range-closer)から取る。 */
|
|
@@ -108,25 +108,40 @@ export const bracketProblems = (text: string): BracketProblem[] => {
|
|
|
108
108
|
return [...scan.problems, ...scan.open.map(unclosedOf)].toSorted((left, right) => left.offset - right.offset);
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
-
/** sorted
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
|
|
111
|
+
/** sorted(昇順・接しもしない)で、offset の後ろの最初の境目: offset を含む範囲の終わりか、次の範囲の始まり。 */
|
|
112
|
+
const borderAfter = (sorted: readonly Span[], offset: number): number => {
|
|
113
|
+
const next = sorted[firstEndingAfter(sorted, offset)];
|
|
114
|
+
if (next === undefined) return Number.POSITIVE_INFINITY;
|
|
115
|
+
return next.start <= offset ? next.end : next.start;
|
|
115
116
|
};
|
|
116
117
|
|
|
118
|
+
/** 覆いの中で URL そのものが終わる位置。ASCII でない字か、コードと字のまま見える範囲の境目(「`https://…`)」の「`」)で終わる。 */
|
|
119
|
+
const urlProperEnd = (written: string, start: number, readable: readonly Span[]): number => {
|
|
120
|
+
const nonAscii = written.search(/[^\p{ASCII}]/u);
|
|
121
|
+
return Math.min(nonAscii === -1 ? written.length : nonAscii, borderAfter(readable, start) - start, written.length);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/** sorted(昇順・重ならない)のうち range に重なるものを、range の中に切り詰めたもの。何万もの字の節があっても、URL ごとに全部をなめない。 */
|
|
125
|
+
const clippedTo = (sorted: readonly Span[], range: Span): Span[] =>
|
|
126
|
+
sorted
|
|
127
|
+
.slice(firstEndingAfter(sorted, range.start), firstEndingAfter(sorted, range.end) + 1)
|
|
128
|
+
.filter((span) => span.start < range.end)
|
|
129
|
+
.map((span) => ({ start: Math.max(span.start, range.start), end: Math.min(span.end, range.end) }));
|
|
130
|
+
|
|
117
131
|
/**
|
|
118
132
|
* 本文(prose)では URL を覆うが、覆いは空白まで取るので、URL の直後に続けて書いた字(「(https://example.jp/)」の「)」)まで消える。
|
|
119
|
-
* 読み手には見えている字なので、
|
|
133
|
+
* 読み手には見えている字なので、URL が終わった後ろの、字のまま見える範囲(texts)を元に戻す。コードの中の URL の後ろも同じ。
|
|
120
134
|
*/
|
|
121
135
|
export const withRunOnRestored = (prose: string, source: string, texts: readonly Span[]): string => {
|
|
122
|
-
const readable = mergeSpans(texts,
|
|
136
|
+
const readable = mergeSpans(texts, true);
|
|
123
137
|
const parts: string[] = [];
|
|
124
138
|
const cursor = { at: 0 };
|
|
125
139
|
[...source.matchAll(BARE_URL)].forEach((match) => {
|
|
126
|
-
const tail = match[0].
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
140
|
+
const tail = { start: match.index + urlProperEnd(match[0], match.index, readable), end: match.index + match[0].length };
|
|
141
|
+
clippedTo(readable, tail).forEach((span) => {
|
|
142
|
+
parts.push(prose.slice(cursor.at, span.start), source.slice(span.start, span.end));
|
|
143
|
+
cursor.at = span.end;
|
|
144
|
+
});
|
|
130
145
|
});
|
|
131
146
|
parts.push(prose.slice(cursor.at));
|
|
132
147
|
return parts.join("");
|