chaffjs 0.38.0 → 0.39.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.ja.md +20 -4
- package/README.md +19 -2
- package/checks/ai-tells.yaml +153 -0
- package/dist/acronym-expansion.d.ts +4 -0
- package/dist/acronym-expansion.d.ts.map +1 -0
- package/dist/acronym-expansion.js +46 -0
- package/dist/acronym-expansion.js.map +1 -0
- package/dist/ai-score/human-shares.d.ts.map +1 -1
- package/dist/ai-score/human-shares.js +53 -12
- package/dist/ai-score/human-shares.js.map +1 -1
- package/dist/ai-score/of-document.d.ts.map +1 -1
- package/dist/ai-score/of-document.js +4 -2
- package/dist/ai-score/of-document.js.map +1 -1
- package/dist/body-section.d.ts +3 -1
- package/dist/body-section.d.ts.map +1 -1
- package/dist/body-section.js +9 -2
- package/dist/body-section.js.map +1 -1
- package/dist/capitals-with-small.d.ts +5 -0
- package/dist/capitals-with-small.d.ts.map +1 -1
- package/dist/capitals-with-small.js +15 -0
- package/dist/capitals-with-small.js.map +1 -1
- package/dist/checks.d.ts +11 -0
- package/dist/checks.d.ts.map +1 -1
- package/dist/checks.js +27 -1
- package/dist/checks.js.map +1 -1
- package/dist/cli-args.js +1 -1
- package/dist/cli-args.js.map +1 -1
- package/dist/cli-text.d.ts.map +1 -1
- package/dist/cli-text.js +4 -0
- package/dist/cli-text.js.map +1 -1
- package/dist/commands/fix-plan.d.ts.map +1 -1
- package/dist/commands/fix-plan.js +64 -4
- package/dist/commands/fix-plan.js.map +1 -1
- package/dist/commands/test.d.ts.map +1 -1
- package/dist/commands/test.js +16 -2
- package/dist/commands/test.js.map +1 -1
- package/dist/detectors/acronym-context.d.ts +4 -1
- package/dist/detectors/acronym-context.d.ts.map +1 -1
- package/dist/detectors/acronym-context.js +16 -2
- package/dist/detectors/acronym-context.js.map +1 -1
- package/dist/detectors/acronym-expansion.d.ts.map +1 -1
- package/dist/detectors/acronym-expansion.js +25 -0
- package/dist/detectors/acronym-expansion.js.map +1 -1
- package/dist/detectors/acronym-gloss.d.ts +19 -0
- package/dist/detectors/acronym-gloss.d.ts.map +1 -1
- package/dist/detectors/acronym-gloss.js +115 -0
- package/dist/detectors/acronym-gloss.js.map +1 -1
- package/dist/detectors/acronym-name.d.ts +9 -2
- package/dist/detectors/acronym-name.d.ts.map +1 -1
- package/dist/detectors/acronym-name.js +13 -3
- package/dist/detectors/acronym-name.js.map +1 -1
- package/dist/detectors/acronym-series.d.ts +7 -0
- package/dist/detectors/acronym-series.d.ts.map +1 -0
- package/dist/detectors/acronym-series.js +25 -0
- package/dist/detectors/acronym-series.js.map +1 -0
- package/dist/detectors/ai-phrasing.d.ts +3 -6
- package/dist/detectors/ai-phrasing.d.ts.map +1 -1
- package/dist/detectors/ai-phrasing.js +17 -16
- package/dist/detectors/ai-phrasing.js.map +1 -1
- package/dist/detectors/ai-structure.d.ts +1 -0
- package/dist/detectors/ai-structure.d.ts.map +1 -1
- package/dist/detectors/ai-structure.js +15 -4
- package/dist/detectors/ai-structure.js.map +1 -1
- package/dist/detectors/alnum-number.d.ts +1 -0
- package/dist/detectors/alnum-number.d.ts.map +1 -1
- package/dist/detectors/alnum-number.js +7 -3
- package/dist/detectors/alnum-number.js.map +1 -1
- package/dist/detectors/bare-comparative.d.ts +6 -0
- package/dist/detectors/bare-comparative.d.ts.map +1 -1
- package/dist/detectors/bare-comparative.js +31 -12
- package/dist/detectors/bare-comparative.js.map +1 -1
- package/dist/detectors/bold-emphasis-form.d.ts +8 -0
- package/dist/detectors/bold-emphasis-form.d.ts.map +1 -0
- package/dist/detectors/bold-emphasis-form.js +40 -0
- package/dist/detectors/bold-emphasis-form.js.map +1 -0
- package/dist/detectors/bold-emphasis.d.ts +0 -1
- package/dist/detectors/bold-emphasis.d.ts.map +1 -1
- package/dist/detectors/bold-emphasis.js +14 -12
- package/dist/detectors/bold-emphasis.js.map +1 -1
- package/dist/detectors/caps-caption.d.ts +5 -0
- package/dist/detectors/caps-caption.d.ts.map +1 -1
- package/dist/detectors/caps-caption.js +20 -2
- package/dist/detectors/caps-caption.js.map +1 -1
- package/dist/detectors/char-shape.d.ts.map +1 -1
- package/dist/detectors/char-shape.js +86 -27
- package/dist/detectors/char-shape.js.map +1 -1
- package/dist/detectors/chat-log-line.d.ts +8 -0
- package/dist/detectors/chat-log-line.d.ts.map +1 -0
- package/dist/detectors/chat-log-line.js +13 -0
- package/dist/detectors/chat-log-line.js.map +1 -0
- package/dist/detectors/citation-string.d.ts +3 -0
- package/dist/detectors/citation-string.d.ts.map +1 -0
- package/dist/detectors/citation-string.js +34 -0
- package/dist/detectors/citation-string.js.map +1 -0
- package/dist/detectors/closing-cliche.d.ts +18 -0
- package/dist/detectors/closing-cliche.d.ts.map +1 -0
- package/dist/detectors/closing-cliche.js +58 -0
- package/dist/detectors/closing-cliche.js.map +1 -0
- package/dist/detectors/closing-exhortation.d.ts +18 -0
- package/dist/detectors/closing-exhortation.d.ts.map +1 -0
- package/dist/detectors/closing-exhortation.js +55 -0
- package/dist/detectors/closing-exhortation.js.map +1 -0
- package/dist/detectors/cold-open.d.ts +25 -0
- package/dist/detectors/cold-open.d.ts.map +1 -0
- package/dist/detectors/cold-open.js +121 -0
- package/dist/detectors/cold-open.js.map +1 -0
- package/dist/detectors/comparative-context.d.ts +21 -0
- package/dist/detectors/comparative-context.d.ts.map +1 -0
- package/dist/detectors/comparative-context.js +57 -0
- package/dist/detectors/comparative-context.js.map +1 -0
- package/dist/detectors/concrete-evidence-density.d.ts +3 -0
- package/dist/detectors/concrete-evidence-density.d.ts.map +1 -0
- package/dist/detectors/concrete-evidence-density.js +75 -0
- package/dist/detectors/concrete-evidence-density.js.map +1 -0
- package/dist/detectors/concrete-evidence.d.ts +14 -0
- package/dist/detectors/concrete-evidence.d.ts.map +1 -1
- package/dist/detectors/concrete-evidence.js +24 -0
- package/dist/detectors/concrete-evidence.js.map +1 -1
- package/dist/detectors/contrast-frame.d.ts +5 -0
- package/dist/detectors/contrast-frame.d.ts.map +1 -1
- package/dist/detectors/contrast-frame.js +53 -6
- package/dist/detectors/contrast-frame.js.map +1 -1
- package/dist/detectors/coordinate-adjective.d.ts +2 -1
- package/dist/detectors/coordinate-adjective.d.ts.map +1 -1
- package/dist/detectors/coordinate-adjective.js +4 -2
- package/dist/detectors/coordinate-adjective.js.map +1 -1
- package/dist/detectors/duplicate-heading.d.ts +4 -2
- package/dist/detectors/duplicate-heading.d.ts.map +1 -1
- package/dist/detectors/duplicate-heading.js +35 -11
- package/dist/detectors/duplicate-heading.js.map +1 -1
- package/dist/detectors/email-frame-words.d.ts +10 -0
- package/dist/detectors/email-frame-words.d.ts.map +1 -0
- package/dist/detectors/email-frame-words.js +34 -0
- package/dist/detectors/email-frame-words.js.map +1 -0
- package/dist/detectors/email-letter.d.ts +3 -7
- package/dist/detectors/email-letter.d.ts.map +1 -1
- package/dist/detectors/email-letter.js +13 -21
- package/dist/detectors/email-letter.js.map +1 -1
- package/dist/detectors/fullwidth-alnum.d.ts.map +1 -1
- package/dist/detectors/fullwidth-alnum.js +20 -4
- package/dist/detectors/fullwidth-alnum.js.map +1 -1
- package/dist/detectors/gram-furniture.d.ts +18 -1
- package/dist/detectors/gram-furniture.d.ts.map +1 -1
- package/dist/detectors/gram-furniture.js +71 -0
- package/dist/detectors/gram-furniture.js.map +1 -1
- package/dist/detectors/gram-openers.d.ts +16 -0
- package/dist/detectors/gram-openers.d.ts.map +1 -1
- package/dist/detectors/gram-openers.js +52 -0
- package/dist/detectors/gram-openers.js.map +1 -1
- package/dist/detectors/gram-predicate.d.ts.map +1 -1
- package/dist/detectors/gram-predicate.js +40 -7
- package/dist/detectors/gram-predicate.js.map +1 -1
- package/dist/detectors/gram-repetition.d.ts +3 -0
- package/dist/detectors/gram-repetition.d.ts.map +1 -0
- package/dist/detectors/gram-repetition.js +158 -0
- package/dist/detectors/gram-repetition.js.map +1 -0
- package/dist/detectors/heading-level-skip.d.ts +6 -0
- package/dist/detectors/heading-level-skip.d.ts.map +1 -1
- package/dist/detectors/heading-level-skip.js +24 -1
- package/dist/detectors/heading-level-skip.js.map +1 -1
- package/dist/detectors/heading-numbering.js +2 -2
- package/dist/detectors/heading-numbering.js.map +1 -1
- package/dist/detectors/hyphen-copied-text.d.ts +3 -0
- package/dist/detectors/hyphen-copied-text.d.ts.map +1 -0
- package/dist/detectors/hyphen-copied-text.js +49 -0
- package/dist/detectors/hyphen-copied-text.js.map +1 -0
- package/dist/detectors/kanji-name-edge.d.ts +15 -0
- package/dist/detectors/kanji-name-edge.d.ts.map +1 -1
- package/dist/detectors/kanji-name-edge.js +30 -0
- package/dist/detectors/kanji-name-edge.js.map +1 -1
- package/dist/detectors/kanji-run-pieces.d.ts +7 -0
- package/dist/detectors/kanji-run-pieces.d.ts.map +1 -1
- package/dist/detectors/kanji-run-pieces.js +14 -4
- package/dist/detectors/kanji-run-pieces.js.map +1 -1
- package/dist/detectors/kutoten-consistency.d.ts.map +1 -1
- package/dist/detectors/kutoten-consistency.js +22 -4
- package/dist/detectors/kutoten-consistency.js.map +1 -1
- package/dist/detectors/lead-in-dash.d.ts +5 -0
- package/dist/detectors/lead-in-dash.d.ts.map +1 -1
- package/dist/detectors/lead-in-dash.js +9 -0
- package/dist/detectors/lead-in-dash.js.map +1 -1
- package/dist/detectors/letter-joined-name.d.ts +2 -0
- package/dist/detectors/letter-joined-name.d.ts.map +1 -1
- package/dist/detectors/letter-joined-name.js +8 -0
- package/dist/detectors/letter-joined-name.js.map +1 -1
- package/dist/detectors/lexicon.d.ts.map +1 -1
- package/dist/detectors/lexicon.js +11 -2
- package/dist/detectors/lexicon.js.map +1 -1
- package/dist/detectors/list-item.d.ts +14 -0
- package/dist/detectors/list-item.d.ts.map +1 -1
- package/dist/detectors/list-item.js +30 -1
- package/dist/detectors/list-item.js.map +1 -1
- package/dist/detectors/list-items.d.ts +1 -1
- package/dist/detectors/list-items.d.ts.map +1 -1
- package/dist/detectors/list-items.js +2 -0
- package/dist/detectors/list-items.js.map +1 -1
- package/dist/detectors/list-joint.d.ts +18 -0
- package/dist/detectors/list-joint.d.ts.map +1 -0
- package/dist/detectors/list-joint.js +42 -0
- package/dist/detectors/list-joint.js.map +1 -0
- package/dist/detectors/list-layout.d.ts +14 -0
- package/dist/detectors/list-layout.d.ts.map +1 -0
- package/dist/detectors/list-layout.js +29 -0
- package/dist/detectors/list-layout.js.map +1 -0
- package/dist/detectors/list-lead-in.d.ts +6 -1
- package/dist/detectors/list-lead-in.d.ts.map +1 -1
- package/dist/detectors/list-lead-in.js +42 -2
- package/dist/detectors/list-lead-in.js.map +1 -1
- package/dist/detectors/list-parallel.d.ts +6 -0
- package/dist/detectors/list-parallel.d.ts.map +1 -1
- package/dist/detectors/list-parallel.js +106 -13
- package/dist/detectors/list-parallel.js.map +1 -1
- package/dist/detectors/list-run.d.ts +13 -0
- package/dist/detectors/list-run.d.ts.map +1 -0
- package/dist/detectors/list-run.js +80 -0
- package/dist/detectors/list-run.js.map +1 -0
- package/dist/detectors/list-sentence.d.ts +11 -0
- package/dist/detectors/list-sentence.d.ts.map +1 -1
- package/dist/detectors/list-sentence.js +1 -0
- package/dist/detectors/list-sentence.js.map +1 -1
- package/dist/detectors/mark-shape.d.ts +2 -1
- package/dist/detectors/mark-shape.d.ts.map +1 -1
- package/dist/detectors/mark-shape.js +10 -6
- package/dist/detectors/mark-shape.js.map +1 -1
- package/dist/detectors/name-run.d.ts +2 -0
- package/dist/detectors/name-run.d.ts.map +1 -1
- package/dist/detectors/name-run.js +1 -1
- package/dist/detectors/name-run.js.map +1 -1
- package/dist/detectors/name-variant-two-things.d.ts +18 -0
- package/dist/detectors/name-variant-two-things.d.ts.map +1 -0
- package/dist/detectors/name-variant-two-things.js +84 -0
- package/dist/detectors/name-variant-two-things.js.map +1 -0
- package/dist/detectors/name-variant.d.ts.map +1 -1
- package/dist/detectors/name-variant.js +14 -15
- package/dist/detectors/name-variant.js.map +1 -1
- package/dist/detectors/organisation-run.d.ts +6 -0
- package/dist/detectors/organisation-run.d.ts.map +1 -1
- package/dist/detectors/organisation-run.js +26 -2
- package/dist/detectors/organisation-run.js.map +1 -1
- package/dist/detectors/orthographic-variant-open.d.ts +35 -0
- package/dist/detectors/orthographic-variant-open.d.ts.map +1 -0
- package/dist/detectors/orthographic-variant-open.js +79 -0
- package/dist/detectors/orthographic-variant-open.js.map +1 -0
- package/dist/detectors/orthographic-variant.d.ts.map +1 -1
- package/dist/detectors/orthographic-variant.js +55 -59
- package/dist/detectors/orthographic-variant.js.map +1 -1
- package/dist/detectors/over-general-claim.d.ts.map +1 -1
- package/dist/detectors/over-general-claim.js +82 -4
- package/dist/detectors/over-general-claim.js.map +1 -1
- package/dist/detectors/oxford-comma.d.ts.map +1 -1
- package/dist/detectors/oxford-comma.js +61 -27
- package/dist/detectors/oxford-comma.js.map +1 -1
- package/dist/detectors/particle-run-names.d.ts +8 -0
- package/dist/detectors/particle-run-names.d.ts.map +1 -0
- package/dist/detectors/particle-run-names.js +17 -0
- package/dist/detectors/particle-run-names.js.map +1 -0
- package/dist/detectors/proper-noun-density.d.ts +13 -0
- package/dist/detectors/proper-noun-density.d.ts.map +1 -0
- package/dist/detectors/proper-noun-density.js +97 -0
- package/dist/detectors/proper-noun-density.js.map +1 -0
- package/dist/detectors/quoted-excerpt.d.ts +13 -0
- package/dist/detectors/quoted-excerpt.d.ts.map +1 -0
- package/dist/detectors/quoted-excerpt.js +53 -0
- package/dist/detectors/quoted-excerpt.js.map +1 -0
- package/dist/detectors/reference-entry.d.ts +7 -0
- package/dist/detectors/reference-entry.d.ts.map +1 -0
- package/dist/detectors/reference-entry.js +35 -0
- package/dist/detectors/reference-entry.js.map +1 -0
- package/dist/detectors/register-neutral-shape.d.ts +5 -2
- package/dist/detectors/register-neutral-shape.d.ts.map +1 -1
- package/dist/detectors/register-neutral-shape.js +21 -4
- package/dist/detectors/register-neutral-shape.js.map +1 -1
- package/dist/detectors/register-set-apart.d.ts +24 -0
- package/dist/detectors/register-set-apart.d.ts.map +1 -0
- package/dist/detectors/register-set-apart.js +102 -0
- package/dist/detectors/register-set-apart.js.map +1 -0
- package/dist/detectors/register-voice.d.ts +14 -0
- package/dist/detectors/register-voice.d.ts.map +1 -0
- package/dist/detectors/register-voice.js +47 -0
- package/dist/detectors/register-voice.js.map +1 -0
- package/dist/detectors/register.d.ts +5 -0
- package/dist/detectors/register.d.ts.map +1 -1
- package/dist/detectors/register.js +13 -0
- package/dist/detectors/register.js.map +1 -1
- package/dist/detectors/registry/closing-cliche.d.ts +3 -0
- package/dist/detectors/registry/closing-cliche.d.ts.map +1 -0
- package/dist/detectors/registry/closing-cliche.js +3 -0
- package/dist/detectors/registry/closing-cliche.js.map +1 -0
- package/dist/detectors/registry/closing-exhortation.d.ts +3 -0
- package/dist/detectors/registry/closing-exhortation.d.ts.map +1 -0
- package/dist/detectors/registry/closing-exhortation.js +3 -0
- package/dist/detectors/registry/closing-exhortation.js.map +1 -0
- package/dist/detectors/registry/cold-open.d.ts +3 -0
- package/dist/detectors/registry/cold-open.d.ts.map +1 -0
- package/dist/detectors/registry/cold-open.js +3 -0
- package/dist/detectors/registry/cold-open.js.map +1 -0
- package/dist/detectors/registry/colon-lead-in.js +1 -1
- package/dist/detectors/registry/colon-lead-in.js.map +1 -1
- package/dist/detectors/registry/concrete-evidence.js +1 -1
- package/dist/detectors/registry/concrete-evidence.js.map +1 -1
- package/dist/detectors/registry/ngram-repetition.js +1 -1
- package/dist/detectors/registry/ngram-repetition.js.map +1 -1
- package/dist/detectors/registry/proper-noun-density.js +1 -1
- package/dist/detectors/registry/proper-noun-density.js.map +1 -1
- package/dist/detectors/registry/topic-predicate-distance.js +1 -1
- package/dist/detectors/registry/topic-predicate-distance.js.map +1 -1
- package/dist/detectors/registry/unprompted-denial.d.ts +3 -0
- package/dist/detectors/registry/unprompted-denial.d.ts.map +1 -0
- package/dist/detectors/registry/unprompted-denial.js +3 -0
- package/dist/detectors/registry/unprompted-denial.js.map +1 -0
- package/dist/detectors/sentence-ending.d.ts +6 -1
- package/dist/detectors/sentence-ending.d.ts.map +1 -1
- package/dist/detectors/sentence-ending.js +42 -9
- package/dist/detectors/sentence-ending.js.map +1 -1
- package/dist/detectors/sentence-length.d.ts.map +1 -1
- package/dist/detectors/sentence-length.js +25 -10
- package/dist/detectors/sentence-length.js.map +1 -1
- package/dist/detectors/sentence-load.d.ts +5 -3
- package/dist/detectors/sentence-load.d.ts.map +1 -1
- package/dist/detectors/sentence-load.js +3 -5
- package/dist/detectors/sentence-load.js.map +1 -1
- package/dist/detectors/sentence-parts.d.ts +9 -0
- package/dist/detectors/sentence-parts.d.ts.map +1 -0
- package/dist/detectors/sentence-parts.js +62 -0
- package/dist/detectors/sentence-parts.js.map +1 -0
- package/dist/detectors/sentence-title.d.ts +3 -0
- package/dist/detectors/sentence-title.d.ts.map +1 -1
- package/dist/detectors/sentence-title.js +10 -0
- package/dist/detectors/sentence-title.js.map +1 -1
- package/dist/detectors/signals.d.ts +0 -2
- package/dist/detectors/signals.d.ts.map +1 -1
- package/dist/detectors/signals.js +12 -163
- package/dist/detectors/signals.js.map +1 -1
- package/dist/detectors/structure-tree.d.ts.map +1 -1
- package/dist/detectors/structure-tree.js +1 -1
- package/dist/detectors/structure-tree.js.map +1 -1
- package/dist/detectors/structure.d.ts +9 -1
- package/dist/detectors/structure.d.ts.map +1 -1
- package/dist/detectors/structure.js +24 -11
- package/dist/detectors/structure.js.map +1 -1
- package/dist/detectors/superlative-clause.d.ts.map +1 -1
- package/dist/detectors/superlative-clause.js +19 -2
- package/dist/detectors/superlative-clause.js.map +1 -1
- package/dist/detectors/superlative-context.d.ts +35 -0
- package/dist/detectors/superlative-context.d.ts.map +1 -0
- package/dist/detectors/superlative-context.js +71 -0
- package/dist/detectors/superlative-context.js.map +1 -0
- package/dist/detectors/superlative-scope.d.ts +6 -2
- package/dist/detectors/superlative-scope.d.ts.map +1 -1
- package/dist/detectors/superlative-scope.js +20 -6
- package/dist/detectors/superlative-scope.js.map +1 -1
- package/dist/detectors/team.d.ts +0 -1
- package/dist/detectors/team.d.ts.map +1 -1
- package/dist/detectors/team.js +0 -46
- package/dist/detectors/team.js.map +1 -1
- package/dist/detectors/titled-code-citation.d.ts +12 -0
- package/dist/detectors/titled-code-citation.d.ts.map +1 -0
- package/dist/detectors/titled-code-citation.js +11 -0
- package/dist/detectors/titled-code-citation.js.map +1 -0
- package/dist/detectors/titled-run.d.ts +8 -1
- package/dist/detectors/titled-run.d.ts.map +1 -1
- package/dist/detectors/titled-run.js +14 -4
- package/dist/detectors/titled-run.js.map +1 -1
- package/dist/detectors/token-shape.d.ts.map +1 -1
- package/dist/detectors/token-shape.js +22 -11
- package/dist/detectors/token-shape.js.map +1 -1
- package/dist/detectors/topic-predicate-distance.d.ts +4 -0
- package/dist/detectors/topic-predicate-distance.d.ts.map +1 -0
- package/dist/detectors/topic-predicate-distance.js +22 -0
- package/dist/detectors/topic-predicate-distance.js.map +1 -0
- package/dist/detectors/unknown-word-context.d.ts +28 -0
- package/dist/detectors/unknown-word-context.d.ts.map +1 -0
- package/dist/detectors/unknown-word-context.js +89 -0
- package/dist/detectors/unknown-word-context.js.map +1 -0
- package/dist/detectors/unknown-word.d.ts +0 -5
- package/dist/detectors/unknown-word.d.ts.map +1 -1
- package/dist/detectors/unknown-word.js +16 -19
- package/dist/detectors/unknown-word.js.map +1 -1
- package/dist/detectors/unprompted-denial.d.ts +25 -0
- package/dist/detectors/unprompted-denial.d.ts.map +1 -0
- package/dist/detectors/unprompted-denial.js +100 -0
- package/dist/detectors/unprompted-denial.js.map +1 -0
- package/dist/document-sections.d.ts.map +1 -1
- package/dist/document-sections.js +3 -1
- package/dist/document-sections.js.map +1 -1
- package/dist/fix-plan/all-signs.d.ts +17 -0
- package/dist/fix-plan/all-signs.d.ts.map +1 -0
- package/dist/fix-plan/all-signs.js +26 -0
- package/dist/fix-plan/all-signs.js.map +1 -0
- package/dist/fix-plan/plan.d.ts +31 -0
- package/dist/fix-plan/plan.d.ts.map +1 -1
- package/dist/fix-plan/plan.js +23 -3
- package/dist/fix-plan/plan.js.map +1 -1
- package/dist/fix-plan/render.d.ts.map +1 -1
- package/dist/fix-plan/render.js +31 -2
- package/dist/fix-plan/render.js.map +1 -1
- package/dist/fix-plan/risen.d.ts +10 -0
- package/dist/fix-plan/risen.d.ts.map +1 -0
- package/dist/fix-plan/risen.js +7 -0
- package/dist/fix-plan/risen.js.map +1 -0
- package/dist/fix-plan/text.d.ts +15 -0
- package/dist/fix-plan/text.d.ts.map +1 -1
- package/dist/fix-plan/text.js +38 -2
- package/dist/fix-plan/text.js.map +1 -1
- package/dist/heading-numbering.d.ts +2 -1
- package/dist/heading-numbering.d.ts.map +1 -1
- package/dist/heading-numbering.js +40 -10
- package/dist/heading-numbering.js.map +1 -1
- package/dist/html/html-site-chrome.d.ts.map +1 -1
- package/dist/html/html-site-chrome.js +7 -2
- package/dist/html/html-site-chrome.js.map +1 -1
- package/dist/law-title.d.ts +7 -0
- package/dist/law-title.d.ts.map +1 -0
- package/dist/law-title.js +29 -0
- package/dist/law-title.js.map +1 -0
- package/dist/name-ending-run.d.ts +11 -0
- package/dist/name-ending-run.d.ts.map +1 -0
- package/dist/name-ending-run.js +37 -0
- package/dist/name-ending-run.js.map +1 -0
- package/dist/name-title-slip.d.ts +11 -0
- package/dist/name-title-slip.d.ts.map +1 -0
- package/dist/name-title-slip.js +51 -0
- package/dist/name-title-slip.js.map +1 -0
- package/dist/name-variant-shapes.d.ts +14 -0
- package/dist/name-variant-shapes.d.ts.map +1 -0
- package/dist/name-variant-shapes.js +43 -0
- package/dist/name-variant-shapes.js.map +1 -0
- package/dist/name-word-use.d.ts +5 -0
- package/dist/name-word-use.d.ts.map +1 -0
- package/dist/name-word-use.js +12 -0
- package/dist/name-word-use.js.map +1 -0
- package/dist/opening-passage.d.ts +8 -0
- package/dist/opening-passage.d.ts.map +1 -0
- package/dist/opening-passage.js +24 -0
- package/dist/opening-passage.js.map +1 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/quote-gloss.d.ts +4 -0
- package/dist/quote-gloss.d.ts.map +1 -0
- package/dist/quote-gloss.js +7 -0
- package/dist/quote-gloss.js.map +1 -0
- package/dist/quoted-spelling.d.ts +17 -0
- package/dist/quoted-spelling.d.ts.map +1 -0
- package/dist/quoted-spelling.js +27 -0
- package/dist/quoted-spelling.js.map +1 -0
- package/dist/render/semantic.d.ts +1 -1
- package/dist/render/semantic.d.ts.map +1 -1
- package/dist/render/semantic.js +2 -1
- package/dist/render/semantic.js.map +1 -1
- package/dist/rule-of-three.d.ts +19 -0
- package/dist/rule-of-three.d.ts.map +1 -0
- package/dist/rule-of-three.js +33 -0
- package/dist/rule-of-three.js.map +1 -0
- package/dist/run-semantic.d.ts.map +1 -1
- package/dist/run-semantic.js +2 -2
- package/dist/run-semantic.js.map +1 -1
- package/dist/section-levels.d.ts +18 -0
- package/dist/section-levels.d.ts.map +1 -0
- package/dist/section-levels.js +80 -0
- package/dist/section-levels.js.map +1 -0
- package/dist/semantic.d.ts +2 -0
- package/dist/semantic.d.ts.map +1 -1
- package/dist/semantic.js +13 -0
- package/dist/semantic.js.map +1 -1
- package/dist/sentence-load.d.ts +2 -1
- package/dist/sentence-load.d.ts.map +1 -1
- package/dist/sentence-load.js +4 -2
- package/dist/sentence-load.js.map +1 -1
- package/dist/spelling.d.ts +11 -0
- package/dist/spelling.d.ts.map +1 -1
- package/dist/spelling.js +19 -5
- package/dist/spelling.js.map +1 -1
- package/dist/structure/cited-document-section.d.ts.map +1 -1
- package/dist/structure/cited-document-section.js +15 -1
- package/dist/structure/cited-document-section.js.map +1 -1
- package/dist/structure/issues.d.ts +1 -1
- package/dist/structure/issues.d.ts.map +1 -1
- package/dist/structure/issues.js +5 -1
- package/dist/structure/issues.js.map +1 -1
- package/dist/structure-shape/template-outline.d.ts +11 -0
- package/dist/structure-shape/template-outline.d.ts.map +1 -0
- package/dist/structure-shape/template-outline.js +25 -0
- package/dist/structure-shape/template-outline.js.map +1 -0
- package/dist/title-case-name.d.ts +12 -0
- package/dist/title-case-name.d.ts.map +1 -0
- package/dist/title-case-name.js +37 -0
- package/dist/title-case-name.js.map +1 -0
- package/dist/topic-clause.d.ts +6 -1
- package/dist/topic-clause.d.ts.map +1 -1
- package/dist/topic-clause.js +77 -3
- package/dist/topic-clause.js.map +1 -1
- package/dist/word-use.d.ts +12 -4
- package/dist/word-use.d.ts.map +1 -1
- package/dist/word-use.js +47 -5
- package/dist/word-use.js.map +1 -1
- package/package.json +4 -3
- package/rules/ai-generated-composite.yaml +11 -3
- package/rules/ai-structure.yaml +7 -6
- package/rules/ai-tell.yaml +4 -4
- package/rules/all-caps-shouting.yaml +2 -2
- package/rules/bold-emphasis.yaml +5 -4
- package/rules/closing-cliche.yaml +4 -5
- package/rules/closing-exhortation.yaml +74 -0
- package/rules/cold-open.yaml +95 -0
- package/rules/colon-lead-in.yaml +68 -10
- package/rules/comparative-without-baseline.yaml +2 -2
- package/rules/concrete-evidence-density.yaml +2 -2
- package/rules/contrast-framing.yaml +16 -13
- package/rules/dangling-reference.yaml +2 -2
- package/rules/duplicate-heading.yaml +5 -2
- package/rules/email-greeting-closing.yaml +2 -2
- package/rules/email-stock-courtesy.yaml +62 -0
- package/rules/fullwidth-alnum-consistency.yaml +2 -2
- package/rules/generic-opening.yaml +63 -0
- package/rules/heading-level-skip.yaml +2 -2
- package/rules/heading-numbering-mix.yaml +20 -20
- package/rules/hyphen-as-dash.yaml +2 -2
- package/rules/kutoten-consistency.yaml +4 -4
- package/rules/list-item-form-mix.yaml +2 -2
- package/rules/max-kanji-continuous.yaml +7 -3
- package/rules/max-sentence-length.yaml +4 -2
- package/rules/name-variant.yaml +5 -2
- package/rules/ngram-repetition.yaml +2 -2
- package/rules/no-doubled-joshi.yaml +2 -2
- package/rules/no-em-dash.yaml +2 -2
- package/rules/no-mixed-desumasu.yaml +16 -3
- package/rules/orthographic-variant.yaml +2 -2
- package/rules/over-general-claim.yaml +2 -2
- package/rules/oxford-comma-consistency.yaml +15 -3
- package/rules/proper-noun-density.yaml +14 -7
- package/rules/rule-of-three.yaml +3 -3
- package/rules/section-length-uniformity.yaml +2 -2
- package/rules/topic-predicate-distance.yaml +3 -2
- package/rules/undefined-acronym.yaml +8 -2
- package/rules/unknown-word.yaml +2 -2
- package/rules/unprompted-denial.yaml +88 -0
- package/rules/unqualified-superlative.yaml +8 -2
- package/skills/chaff/SKILL.md +38 -6
- package/src/acronym-expansion.ts +57 -0
- package/src/ai-score/human-shares.ts +53 -12
- package/src/ai-score/of-document.ts +5 -2
- package/src/body-section.ts +11 -2
- package/src/capitals-with-small.ts +16 -0
- package/src/checks.ts +32 -1
- package/src/cli-args.ts +1 -1
- package/src/cli-text.ts +4 -0
- package/src/commands/fix-plan.ts +72 -5
- package/src/commands/test.ts +18 -2
- package/src/detectors/acronym-context.ts +20 -2
- package/src/detectors/acronym-expansion.ts +26 -0
- package/src/detectors/acronym-gloss.ts +123 -0
- package/src/detectors/acronym-name.ts +22 -3
- package/src/detectors/acronym-series.ts +27 -0
- package/src/detectors/ai-phrasing.ts +18 -17
- package/src/detectors/ai-structure.ts +23 -6
- package/src/detectors/alnum-number.ts +8 -3
- package/src/detectors/bare-comparative.ts +41 -13
- package/src/detectors/bold-emphasis-form.ts +58 -0
- package/src/detectors/bold-emphasis.ts +16 -17
- package/src/detectors/caps-caption.ts +24 -2
- package/src/detectors/char-shape.ts +118 -29
- package/src/detectors/chat-log-line.ts +17 -0
- package/src/detectors/citation-string.ts +36 -0
- package/src/detectors/closing-cliche.ts +74 -0
- package/src/detectors/closing-exhortation.ts +74 -0
- package/src/detectors/cold-open.ts +145 -0
- package/src/detectors/comparative-context.ts +74 -0
- package/src/detectors/concrete-evidence-density.ts +99 -0
- package/src/detectors/concrete-evidence.ts +40 -0
- package/src/detectors/contrast-frame.ts +65 -7
- package/src/detectors/coordinate-adjective.ts +4 -2
- package/src/detectors/duplicate-heading.ts +44 -15
- package/src/detectors/email-frame-words.ts +39 -0
- package/src/detectors/email-letter.ts +15 -20
- package/src/detectors/fullwidth-alnum.ts +24 -4
- package/src/detectors/gram-furniture.ts +87 -1
- package/src/detectors/gram-openers.ts +71 -0
- package/src/detectors/gram-predicate.ts +49 -6
- package/src/detectors/gram-repetition.ts +199 -0
- package/src/detectors/heading-level-skip.ts +31 -1
- package/src/detectors/heading-numbering.ts +2 -2
- package/src/detectors/hyphen-copied-text.ts +65 -0
- package/src/detectors/kanji-name-edge.ts +31 -0
- package/src/detectors/kanji-run-pieces.ts +26 -0
- package/src/detectors/kutoten-consistency.ts +24 -4
- package/src/detectors/lead-in-dash.ts +11 -0
- package/src/detectors/letter-joined-name.ts +14 -0
- package/src/detectors/lexicon.ts +15 -2
- package/src/detectors/list-item.ts +37 -1
- package/src/detectors/list-items.ts +4 -1
- package/src/detectors/list-joint.ts +44 -0
- package/src/detectors/list-layout.ts +39 -0
- package/src/detectors/list-lead-in.ts +50 -3
- package/src/detectors/list-parallel.ts +119 -13
- package/src/detectors/list-run.ts +86 -0
- package/src/detectors/list-sentence.ts +11 -0
- package/src/detectors/mark-shape.ts +12 -7
- package/src/detectors/name-run.ts +2 -1
- package/src/detectors/name-variant-two-things.ts +136 -0
- package/src/detectors/name-variant.ts +14 -19
- package/src/detectors/organisation-run.ts +26 -2
- package/src/detectors/orthographic-variant-open.ts +119 -0
- package/src/detectors/orthographic-variant.ts +82 -82
- package/src/detectors/over-general-claim.ts +106 -5
- package/src/detectors/oxford-comma.ts +68 -28
- package/src/detectors/particle-run-names.ts +17 -0
- package/src/detectors/proper-noun-density.ts +109 -0
- package/src/detectors/quoted-excerpt.ts +68 -0
- package/src/detectors/reference-entry.ts +42 -0
- package/src/detectors/register-neutral-shape.ts +26 -6
- package/src/detectors/register-set-apart.ts +124 -0
- package/src/detectors/register-voice.ts +63 -0
- package/src/detectors/register.ts +15 -0
- package/src/detectors/registry/closing-cliche.ts +4 -0
- package/src/detectors/registry/closing-exhortation.ts +4 -0
- package/src/detectors/registry/cold-open.ts +4 -0
- package/src/detectors/registry/colon-lead-in.ts +1 -1
- package/src/detectors/registry/concrete-evidence.ts +1 -1
- package/src/detectors/registry/ngram-repetition.ts +1 -1
- package/src/detectors/registry/proper-noun-density.ts +1 -1
- package/src/detectors/registry/topic-predicate-distance.ts +1 -1
- package/src/detectors/registry/unprompted-denial.ts +4 -0
- package/src/detectors/sentence-ending.ts +60 -12
- package/src/detectors/sentence-length.ts +26 -9
- package/src/detectors/sentence-load.ts +3 -6
- package/src/detectors/sentence-parts.ts +70 -0
- package/src/detectors/sentence-title.ts +14 -0
- package/src/detectors/signals.ts +13 -198
- package/src/detectors/structure-tree.ts +3 -1
- package/src/detectors/structure.ts +25 -13
- package/src/detectors/superlative-clause.ts +21 -2
- package/src/detectors/superlative-context.ts +99 -0
- package/src/detectors/superlative-scope.ts +27 -9
- package/src/detectors/team.ts +1 -50
- package/src/detectors/titled-code-citation.ts +19 -0
- package/src/detectors/titled-run.ts +22 -5
- package/src/detectors/token-shape.ts +25 -13
- package/src/detectors/topic-predicate-distance.ts +25 -0
- package/src/detectors/unknown-word-context.ts +112 -0
- package/src/detectors/unknown-word.ts +18 -20
- package/src/detectors/unprompted-denial.ts +133 -0
- package/src/document-sections.ts +3 -1
- package/src/fix-plan/all-signs.ts +35 -0
- package/src/fix-plan/plan.ts +50 -3
- package/src/fix-plan/render.ts +41 -3
- package/src/fix-plan/risen.ts +13 -0
- package/src/fix-plan/text.ts +56 -2
- package/src/heading-numbering.ts +44 -10
- package/src/html/html-site-chrome.ts +9 -2
- package/src/law-title.ts +38 -0
- package/src/name-ending-run.ts +49 -0
- package/src/name-title-slip.ts +59 -0
- package/src/name-variant-shapes.ts +58 -0
- package/src/name-word-use.ts +17 -0
- package/src/opening-passage.ts +31 -0
- package/src/plugin.ts +2 -0
- package/src/quote-gloss.ts +11 -0
- package/src/quoted-spelling.ts +48 -0
- package/src/render/semantic.ts +2 -2
- package/src/rule-of-three.ts +50 -0
- package/src/run-semantic.ts +2 -2
- package/src/section-levels.ts +98 -0
- package/src/semantic.ts +14 -0
- package/src/sentence-load.ts +5 -3
- package/src/spelling.ts +37 -7
- package/src/structure/cited-document-section.ts +16 -1
- package/src/structure/issues.ts +10 -1
- package/src/structure-shape/template-outline.ts +34 -0
- package/src/title-case-name.ts +55 -0
- package/src/topic-clause.ts +96 -5
- package/src/word-use.ts +57 -6
- package/dist/legal-address.d.ts +0 -2
- package/dist/legal-address.d.ts.map +0 -1
- package/dist/legal-address.js +0 -16
- package/dist/legal-address.js.map +0 -1
|
@@ -3,20 +3,30 @@ import { compacted } from "./gram-place.ts";
|
|
|
3
3
|
import { leadingCounter, trailingPrefix } from "./counter-edge.ts";
|
|
4
4
|
import { trailingAddressee, type AddresseeSuffix } from "./addressee-edge.ts";
|
|
5
5
|
import { leadingPrefix, trailingTitle, type AddresseeWords } from "./addressee-title-edge.ts";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
followsForm,
|
|
8
|
+
followsUnit,
|
|
9
|
+
holdsName,
|
|
10
|
+
isListItem,
|
|
11
|
+
leadingDate,
|
|
12
|
+
leadingOrdinal,
|
|
13
|
+
leadingReference,
|
|
14
|
+
trailingConjunction,
|
|
15
|
+
type Edge,
|
|
16
|
+
} from "./kanji-name-edge.ts";
|
|
7
17
|
import { isNameList } from "./name-list-sentence.ts";
|
|
8
18
|
import { maskAddresses } from "../address-chain.ts";
|
|
9
19
|
import { isAddressRun } from "./place-run.ts";
|
|
10
20
|
import { isOneName } from "./name-run.ts";
|
|
11
|
-
import { isOrganisationRun, type OrganisationWords } from "./organisation-run.ts";
|
|
12
|
-
import { endsInTitle, isTitlePosition, isTitledName, repeatedRuns, type TitleWords } from "./titled-run.ts";
|
|
21
|
+
import { isOrganisationHead, isOrganisationRun, type OrganisationWords } from "./organisation-run.ts";
|
|
22
|
+
import { endsInTitle, inStatuteTitle, isTitlePosition, isTitledName, repeatedRuns, titleBody, type TitleWords } from "./titled-run.ts";
|
|
13
23
|
import { proseText } from "../measure.ts";
|
|
14
24
|
import { parallelDotCount } from "./middle-dot.ts";
|
|
15
25
|
import { maskSpans } from "../mask.ts";
|
|
16
26
|
import { quotedSpans } from "../quoted-span.ts";
|
|
17
27
|
import { nameSpans } from "../team-names.ts";
|
|
18
28
|
import { isIn } from "../lexicon-genres.ts";
|
|
19
|
-
import { standaloneNames, unknownPieces } from "./kanji-run-pieces.ts";
|
|
29
|
+
import { isTitledPerson, standaloneNames, unknownPieces } from "./kanji-run-pieces.ts";
|
|
20
30
|
|
|
21
31
|
/**
|
|
22
32
|
* 文字の並びを見る検出。漢字の連なりが住所か名前かだけは、形態素解析の固有名詞と数で決める。
|
|
@@ -37,16 +47,22 @@ type KanjiRun = {
|
|
|
37
47
|
readonly placed: boolean;
|
|
38
48
|
readonly after: string | undefined;
|
|
39
49
|
readonly before: string;
|
|
50
|
+
/** 連なりの後ろから文の終わりまでの文字(中黒の後ろへ続く名前の「・適応小委員会」)。 */
|
|
51
|
+
readonly next: string;
|
|
40
52
|
/** 文がこの連なりだけ(用語集の見出し語の行)。 */
|
|
41
53
|
readonly alone: boolean;
|
|
42
54
|
/** 名前の並び(区長、副区長、…選挙管理委員会事務局長)の、「、」で区切った 1 項目がこの連なりだけ。 */
|
|
43
55
|
readonly listItem: boolean;
|
|
56
|
+
/** 連なりを中に含む括弧(ENCLOSING_MARKS)の中身の、文書全体の座標での範囲。 */
|
|
57
|
+
readonly brackets: readonly Span[];
|
|
44
58
|
};
|
|
45
59
|
|
|
46
60
|
const SPACE = /\s/gu;
|
|
47
61
|
|
|
48
|
-
/**
|
|
49
|
-
const NAME_MARKS = { "「": "」", "『": "』", "【": "】" };
|
|
62
|
+
/** 名前を囲む括弧。鉤括弧と、見出しや分類の名前を囲む隅付き括弧(【浪速区役所公募型比較見積】)と、欄の名前を囲む角括弧([当事者系審判請求人])。 */
|
|
63
|
+
const NAME_MARKS = { "「": "」", "『": "』", "【": "】", "[": "]" };
|
|
64
|
+
/** 法令の題(〜に関する法律)を囲む括弧。題の中の連なりは、題の一部。 */
|
|
65
|
+
const ENCLOSING_MARKS = { "「": "」", "『": "』", "(": ")", "(": ")" };
|
|
50
66
|
|
|
51
67
|
/**
|
|
52
68
|
* 同じ連なりが文に二度出ても、それぞれの位置で読む。proseText は空白を詰めたり除いたりするだけなので、
|
|
@@ -71,12 +87,26 @@ const runsOf = (sentence: Sentence, profile: DocumentProfile | undefined, names:
|
|
|
71
87
|
const before = prose.slice(0, match.index).replace(SPACE, "").length;
|
|
72
88
|
const [start, last] = [printed[before], printed[before + match[0].length - 1]];
|
|
73
89
|
if (start === undefined || last === undefined)
|
|
74
|
-
return {
|
|
90
|
+
return {
|
|
91
|
+
text: match[0],
|
|
92
|
+
span: undefined,
|
|
93
|
+
quoted: false,
|
|
94
|
+
placed: false,
|
|
95
|
+
after: undefined,
|
|
96
|
+
before: "",
|
|
97
|
+
next: "",
|
|
98
|
+
alone: false,
|
|
99
|
+
listItem: false,
|
|
100
|
+
brackets: [],
|
|
101
|
+
};
|
|
75
102
|
const span = { start: sentence.span.start + start, end: sentence.span.start + last + 1 };
|
|
76
103
|
const after = sentence.text.slice(0, start).trim() === "" ? sentence.text.slice(last + 1) : undefined;
|
|
77
104
|
const quoted = fillsQuote(sentence, start, last + 1);
|
|
78
105
|
const alone = sentence.text.slice(0, start).trim() === "" && sentence.text.slice(last + 1).trim() === "";
|
|
79
106
|
const listItem = nameList && isListItem(sentence.text, start, last + 1);
|
|
107
|
+
const brackets = quotedSpans(sentence.text, ENCLOSING_MARKS)
|
|
108
|
+
.filter((bracket) => bracket.start <= start && last < bracket.end)
|
|
109
|
+
.map((bracket) => ({ start: sentence.span.start + bracket.start, end: sentence.span.start + bracket.end }));
|
|
80
110
|
return {
|
|
81
111
|
text: match[0],
|
|
82
112
|
span,
|
|
@@ -84,8 +114,10 @@ const runsOf = (sentence: Sentence, profile: DocumentProfile | undefined, names:
|
|
|
84
114
|
placed: isTitlePosition(sentence.text, start, last + 1),
|
|
85
115
|
after,
|
|
86
116
|
before: sentence.text.slice(0, start),
|
|
117
|
+
next: sentence.text.slice(last + 1),
|
|
87
118
|
alone,
|
|
88
119
|
listItem,
|
|
120
|
+
brackets,
|
|
89
121
|
};
|
|
90
122
|
});
|
|
91
123
|
};
|
|
@@ -121,8 +153,10 @@ type RunContext = {
|
|
|
121
153
|
readonly titled: readonly string[];
|
|
122
154
|
/** 文書の文の中に二度以上出る連なり(repeatedRuns)。題を閉じる語で終われば、書き手が名前として使い回している。 */
|
|
123
155
|
readonly repeated: ReadonlySet<string>;
|
|
124
|
-
/** 文書がほかで単独の連なりとして使う組織の名前(standaloneNames:
|
|
156
|
+
/** 文書がほかで単独の連なりとして使う組織の名前(standaloneNames: 安全保障理事会)と法令の名前とその名の元の語(statuteTerms)。 */
|
|
125
157
|
readonly terms: ReadonlySet<string>;
|
|
158
|
+
/** 文書のどこかで、括弧の中身がまるごとその連なりである名前(「署名用電子証明書確認画面」)。 */
|
|
159
|
+
readonly presented: ReadonlySet<string>;
|
|
126
160
|
/** 見出し語の行(文がその連なりだけ)を数えない文書か(用語集)。 */
|
|
127
161
|
readonly headwords: boolean;
|
|
128
162
|
/** 知っている語の語数の上限: 知っている語の字数の上限(一字一語のときの語数)。 */
|
|
@@ -141,6 +175,19 @@ const isPlaceName = (tokens: readonly Token[], span: Span, words: NameWords, for
|
|
|
141
175
|
return isAddressRun(tokens, covering, words.topUnits) || isOneName(tokens, covering) || isOrganisationRun(tokens, covering, words.organisation, formBefore);
|
|
142
176
|
};
|
|
143
177
|
|
|
178
|
+
/** 連なりのすぐ後ろの、中黒で続く語の並び(・適応小委員会、・学位授与機構)。 */
|
|
179
|
+
const DOTTED_TAIL = /^(?:・[一-鿿ァ-ヶー]+)+/u;
|
|
180
|
+
|
|
181
|
+
/** 連なりの後ろ(next)が中黒で続き、最後の語が組織の語で閉じるか(社会保障審議会企業年金・個人年金部会の「・個人年金部会」)。 */
|
|
182
|
+
const closesAfterDot = (next: string, units: readonly string[]): boolean => {
|
|
183
|
+
const last = DOTTED_TAIL.exec(next)?.[0].split("・").at(-1);
|
|
184
|
+
return last !== undefined && units.some((unit) => last.endsWith(unit));
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/** 中黒の後ろで閉じる組織の名前の前半(独立行政法人大学改革支援・学位授与機構の「独立行政法人大学改革支援」)。 */
|
|
188
|
+
const isDottedName = (tokens: readonly Token[], span: Span, run: KanjiRun, organisation: OrganisationWords, formBefore: boolean): boolean =>
|
|
189
|
+
closesAfterDot(run.next, organisation.units) && isOrganisationHead(tokens, coveringOf(tokens, span), organisation, formBefore);
|
|
190
|
+
|
|
144
191
|
/**
|
|
145
192
|
* 題の名前か。法令・制度・給付の名前(住民基本台帳法施行令)はそれを閉じる語で終わるだけで名前。題を閉じる語
|
|
146
193
|
* (大阪市鶴見区役所公募型比較見積実施要綱、自衛隊高級幹部会同)は、ここか文書のほかの所で題として置かれているか、文書が同じ連なりを繰り返している。
|
|
@@ -165,7 +212,9 @@ const tailOf = (tokens: readonly Token[], run: KanjiRun, span: Span, words: Name
|
|
|
165
212
|
const prefix = trailingPrefix(tokens, span.end, run.text);
|
|
166
213
|
const suffix =
|
|
167
214
|
prefix === undefined
|
|
168
|
-
? (
|
|
215
|
+
? (trailingConjunction(tokens, span.start, span.end, run.text) ??
|
|
216
|
+
trailingAddressee(tokens, span.end, run.text, words.addressee) ??
|
|
217
|
+
trailingAddressee(tokens, span.end, run.text, words.listSuffixes))
|
|
169
218
|
: { surface: prefix.surface, start: prefix.span.start };
|
|
170
219
|
const title = isNamedEntry(run, words) ? trailingTitle(run.text.slice(0, run.text.length - (suffix?.surface.length ?? 0)), words.addressees) : undefined;
|
|
171
220
|
if (title === undefined) return suffix;
|
|
@@ -175,13 +224,16 @@ const tailOf = (tokens: readonly Token[], run: KanjiRun, span: Span, words: Name
|
|
|
175
224
|
/** 外す語を外した残り。頭の「各」は、宛名の行でなければ、残りが名前と決まったときだけ外す(呼び出し側が戻す)。 */
|
|
176
225
|
type Measured = { readonly rest: Span; readonly text: string; readonly keptHead: string };
|
|
177
226
|
|
|
178
|
-
/** 頭の外す語:
|
|
227
|
+
/** 頭の外す語: 数に付いた助数詞、宛名の「各」、前に書いたものを指す語(上記)か代の序数か漢数字の日付の順に、最初に当たったもの。prefix は「各」のとき。 */
|
|
179
228
|
const headOf = (tokens: readonly Token[], run: KanjiRun, span: Span, name: string, words: NameWords): { head?: Edge; prefix?: Token } => {
|
|
180
229
|
const counter = leadingCounter(tokens, span.start, run.text, words.positional);
|
|
181
230
|
if (counter !== undefined) return { head: counter };
|
|
182
231
|
const prefix = leadingPrefix(tokens, span.start, name, words.addressees);
|
|
183
232
|
if (prefix !== undefined) return { head: prefix, prefix };
|
|
184
|
-
const reference =
|
|
233
|
+
const reference =
|
|
234
|
+
leadingReference(tokens, span.start, name, words.references) ??
|
|
235
|
+
leadingOrdinal(tokens, span.start, name) ??
|
|
236
|
+
leadingDate(tokens, span.start, name, run.before);
|
|
185
237
|
return reference === undefined ? {} : { head: reference };
|
|
186
238
|
};
|
|
187
239
|
|
|
@@ -202,9 +254,11 @@ const measuredRun = (tokens: readonly Token[] | undefined, run: KanjiRun, contex
|
|
|
202
254
|
if (run.quoted || (context.headwords && run.alone)) return "";
|
|
203
255
|
if (tokens === undefined || run.span === undefined) return run.text;
|
|
204
256
|
const { rest, text, keptHead } = measuredOf(tokens, run, run.span, context.words);
|
|
257
|
+
if (context.presented.has(text) || inStatuteTitle(tokens, run.brackets, context.words.fixedName)) return "";
|
|
205
258
|
const organisation = context.words.organisation;
|
|
206
259
|
const formBefore = rest.start === run.span.start && (followsForm(run.before, organisation.forms) || followsUnit(run.before, organisation.units));
|
|
207
260
|
if (isPlaceName(tokens, rest, context.words, formBefore) || isTitle(tokens, rest, text, run.placed, context)) return "";
|
|
261
|
+
if (rest.end === run.span.end && isDottedName(tokens, rest, run, organisation, formBefore)) return "";
|
|
208
262
|
return longestUnknown(tokens, rest, keptHead, context);
|
|
209
263
|
};
|
|
210
264
|
|
|
@@ -213,19 +267,23 @@ const surfaceWithin = (token: Token, span: Span): string =>
|
|
|
213
267
|
token.surface.slice(Math.max(0, span.start - token.span.start), Math.max(0, span.end - token.span.start));
|
|
214
268
|
|
|
215
269
|
/**
|
|
216
|
-
*
|
|
270
|
+
* 連なりの、知っている語(文書がほかで単独で使う組織の名前と法令の名前、連なりを閉じる決まった語、職名の前後の人の名前)を外した残りのうち、最も長いもの。
|
|
217
271
|
* 安全保障理事会常任理事国は(安全保障理事会を単独で使う文書なら)「常任理事国」、日本国内閣総理大臣は「日本国」を数える。
|
|
218
272
|
* 名前に普通の語が続く連なり(日本弁護士連合会臨時総会決議)は、名前がその文書で単独で使われていなければ、まるごと数える。
|
|
219
273
|
*/
|
|
220
274
|
const longestUnknown = (tokens: readonly Token[], rest: Span, keptHead: string, context: RunContext): string => {
|
|
221
|
-
const
|
|
222
|
-
const words =
|
|
275
|
+
const runTokens = coveringOf(tokens, rest).flatMap((index) => tokens.slice(index, index + 1));
|
|
276
|
+
const words = runTokens.map((token) => surfaceWithin(token, rest));
|
|
223
277
|
const whole = words.join("");
|
|
224
278
|
// A run as long as the text holds no known word; reading it word by word would take a pass per word.
|
|
225
279
|
if (![...context.terms, ...context.words.knownWords].some((known) => whole.includes(known))) return keptHead + whole;
|
|
226
280
|
const isKnown = (start: number, end: number): boolean => {
|
|
227
281
|
const piece = words.slice(start, end).join("");
|
|
228
|
-
return
|
|
282
|
+
return (
|
|
283
|
+
context.terms.has(piece) ||
|
|
284
|
+
(end === words.length && context.words.knownWords.has(piece)) ||
|
|
285
|
+
isTitledPerson(runTokens, words, { start, end }, context.words.knownWords, context.maxKnownWords)
|
|
286
|
+
);
|
|
229
287
|
};
|
|
230
288
|
return unknownPieces(words, context.maxKnownWords, isKnown)
|
|
231
289
|
.map((piece) => (piece.first ? keptHead + piece.text : piece.text))
|
|
@@ -241,21 +299,38 @@ const longestKanji = (sentence: Sentence, context: RunContext): string =>
|
|
|
241
299
|
const headingRuns = (doc: ProseDocument): string[] =>
|
|
242
300
|
(doc.markup?.headings ?? []).flatMap((heading) => [...heading.text.matchAll(KANJI_RUN)].map((match) => match[0]));
|
|
243
301
|
|
|
302
|
+
/** 文書の文の中の漢字の連なりと、その文の語。 */
|
|
303
|
+
type DocumentRun = { readonly run: KanjiRun; readonly tokens: readonly Token[] | undefined };
|
|
304
|
+
|
|
305
|
+
const documentRuns = (doc: ProseDocument, profile: DocumentProfile | undefined, names: readonly string[]): DocumentRun[] =>
|
|
306
|
+
doc.sentences.flatMap((sentence) => runsOf(sentence, profile, names).map((run) => ({ run, tokens: sentence.tokens })));
|
|
307
|
+
|
|
244
308
|
/**
|
|
245
309
|
* 文書の中で題として置かれた漢字の連なり: 題の置き方をした文の中の連なりと、見出しの中の連なり。
|
|
246
310
|
* 同じ名前を文の中で使えば(認定職業訓練実施奨励金の支給額)、それも題の名前と読む。
|
|
247
311
|
*/
|
|
248
|
-
const titledNames = (doc: ProseDocument,
|
|
249
|
-
...
|
|
312
|
+
const titledNames = (doc: ProseDocument, runs: readonly DocumentRun[]): string[] => [
|
|
313
|
+
...runs.flatMap(({ run }) => (run.placed ? [run.text] : [])),
|
|
250
314
|
...headingRuns(doc),
|
|
251
315
|
];
|
|
252
316
|
|
|
253
317
|
/** 割る手がかりにする、文書が単独で使う名前の最短の字数。短い名前(事務局、理事会)は普通の語の一部にもなる。 */
|
|
254
318
|
const MIN_TERM_LENGTH = 6;
|
|
255
319
|
|
|
256
|
-
/**
|
|
257
|
-
|
|
258
|
-
|
|
320
|
+
/**
|
|
321
|
+
* 文書が単独の連なりとして使う法令・制度の名前(政治資金規正法)と、その名前の元の語(愛玩動物看護師法の「愛玩動物看護師」)のうち、
|
|
322
|
+
* 字数が MIN_TERM_LENGTH から上限(max)までのもの。法令が名に取った語は、読み手がその法令の名前から知っている語。
|
|
323
|
+
*/
|
|
324
|
+
const statuteTerms = (runs: readonly DocumentRun[], fixedName: TitleWords, max: number): string[] =>
|
|
325
|
+
runs.flatMap(({ run, tokens }) => {
|
|
326
|
+
if (tokens === undefined || run.span === undefined) return [];
|
|
327
|
+
const body = titleBody(
|
|
328
|
+
coveringOf(tokens, run.span).flatMap((index) => tokens.slice(index, index + 1)),
|
|
329
|
+
fixedName,
|
|
330
|
+
);
|
|
331
|
+
const terms = body === undefined ? [] : [run.text, body];
|
|
332
|
+
return terms.filter((term) => [...term].length >= MIN_TERM_LENGTH && [...term].length <= max);
|
|
333
|
+
});
|
|
259
334
|
|
|
260
335
|
/** 文書の genre が、rule の headword_genres(見出し語の行を数えない genre: 用語集)にあるか。 */
|
|
261
336
|
const isHeadwordGenre = (options: DetectorOptions): boolean => {
|
|
@@ -264,11 +339,7 @@ const isHeadwordGenre = (options: DetectorOptions): boolean => {
|
|
|
264
339
|
return genre !== undefined && Array.isArray(genres) && genres.some((target: string) => isIn(genre, target));
|
|
265
340
|
};
|
|
266
341
|
|
|
267
|
-
|
|
268
|
-
* 漢字が続くと、どこで語が切れるのか読み手が探すことになる。
|
|
269
|
-
* 「情報処理推進機構認定試験」は 12 字。ひらがなを 1 つ挟むだけで読める。
|
|
270
|
-
*/
|
|
271
|
-
export const kanjiRun: Detector = (doc, options): Finding[] => {
|
|
342
|
+
const nameWordsOf = (doc: ProseDocument): NameWords => {
|
|
272
343
|
const patterns = (id: string): string[] => (doc.lexicons[id] ?? []).map((entry) => entry.pattern);
|
|
273
344
|
const organisation: OrganisationWords = {
|
|
274
345
|
forms: patterns("organisation-form"),
|
|
@@ -287,18 +358,36 @@ export const kanjiRun: Detector = (doc, options): Finding[] => {
|
|
|
287
358
|
listSuffixes: patterns("list-suffix"),
|
|
288
359
|
knownWords: new Set(patterns("kanji-known-word")),
|
|
289
360
|
};
|
|
361
|
+
return words;
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
const contextOf = (doc: ProseDocument, options: DetectorOptions): RunContext => {
|
|
365
|
+
const words = nameWordsOf(doc);
|
|
290
366
|
const names = doc.names ?? [];
|
|
291
|
-
const
|
|
292
|
-
const
|
|
367
|
+
const runs = documentRuns(doc, doc.profile, names);
|
|
368
|
+
const inSentences = runs.map(({ run }) => run.text);
|
|
369
|
+
return {
|
|
293
370
|
profile: doc.profile,
|
|
294
371
|
names,
|
|
295
372
|
words,
|
|
296
|
-
titled: titledNames(doc,
|
|
373
|
+
titled: titledNames(doc, runs),
|
|
297
374
|
repeated: repeatedRuns(inSentences),
|
|
298
|
-
terms:
|
|
375
|
+
terms: new Set([
|
|
376
|
+
...standaloneNames([...inSentences, ...headingRuns(doc)], MIN_TERM_LENGTH, options.limit, words.organisation.units),
|
|
377
|
+
...statuteTerms(runs, words.fixedName, options.limit),
|
|
378
|
+
]),
|
|
379
|
+
presented: new Set(runs.flatMap(({ run }) => (run.quoted ? [run.text] : []))),
|
|
299
380
|
headwords: isHeadwordGenre(options),
|
|
300
381
|
maxKnownWords: Math.max(options.limit, ...[...words.knownWords].map((word) => [...word].length)),
|
|
301
382
|
};
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* 漢字が続くと、どこで語が切れるのか読み手が探すことになる。
|
|
387
|
+
* 「情報処理推進機構認定試験」は 12 字。ひらがなを 1 つ挟むだけで読める。
|
|
388
|
+
*/
|
|
389
|
+
export const kanjiRun: Detector = (doc, options): Finding[] => {
|
|
390
|
+
const context = contextOf(doc, options);
|
|
302
391
|
return doc.sentences
|
|
303
392
|
.map((sentence) => ({ sentence, run: longestKanji(sentence, context) }))
|
|
304
393
|
.filter(({ run }) => run.length > options.limit)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// A line of a pasted chat log ("<jinxer-wm> FIRING: PHPFPMTooBusy: Not enough idle PHP-FPM workers"): the speaker's nick in
|
|
2
|
+
// angle brackets, then what the speaker (often an alert bot) said. The words are the speaker's, not the writer's. Pure.
|
|
3
|
+
|
|
4
|
+
type Span = { readonly start: number; readonly end: number };
|
|
5
|
+
|
|
6
|
+
const LIST_MARK = String.raw`(?:[-*+][ \t]+)?`;
|
|
7
|
+
const TIME = String.raw`(?:\[?\d{1,2}:\d{2}(?::\d{2})?\]?[ \t]+)?`;
|
|
8
|
+
const NICK = String.raw`<[A-Za-z_\x5B-\x60{|}][\w\x5B-\x60{|}-]{0,31}>`;
|
|
9
|
+
/**
|
|
10
|
+
* An IRC-style nick in angle brackets at the start of a line, after an optional list mark and time ("- [21:00] <bot> …"),
|
|
11
|
+
* then a space and the message. The nick has no space, so an HTML tag with attributes (<a href="…">) is not one.
|
|
12
|
+
*/
|
|
13
|
+
const CHAT_LINE = new RegExp(String.raw`^[ \t]*${LIST_MARK}${TIME}${NICK}[ \t]+\S.*`, "gmu");
|
|
14
|
+
|
|
15
|
+
/** The lines of the source that are a pasted chat log's messages. */
|
|
16
|
+
export const chatLogSpans = (source: string): Span[] =>
|
|
17
|
+
[...source.matchAll(CHAT_LINE)].map((match) => ({ start: match.index, end: match.index + match[0].length }));
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// A footnote that opens with a citation signal and cites, with nothing of the writer's after the signal: a legal citation
|
|
2
|
+
// (See, e.g., 12 C.F.R. §§ 5.34(e)(3) …) or titles of other documents joined by semicolons (See A Title; FDIC: Another Title).
|
|
3
|
+
// Its length is the length of the references. Pure.
|
|
4
|
+
import { escapeRegExp } from "../orthography.ts";
|
|
5
|
+
import { isTitleCase } from "./sentence-title.ts";
|
|
6
|
+
|
|
7
|
+
/** The section sign marks a citation of a code or a regulation in any language. */
|
|
8
|
+
const SECTION_SIGN = /§/u;
|
|
9
|
+
/** A citation string cites more than one source (a semicolon between them) or dates what it cites ((Apr. 28, 2005)). */
|
|
10
|
+
const CITATION_DETAIL = /;|\([^()]*\d{4}\)/u;
|
|
11
|
+
const SEGMENT_SEPARATOR = /;/u;
|
|
12
|
+
const MIN_TITLES = 2;
|
|
13
|
+
/** "See, e.g.," and "See also, e.g.,": the example signal after the signal. */
|
|
14
|
+
const EXAMPLE_SIGNAL = String.raw`(?:,?\s*e\.g\.,)?`;
|
|
15
|
+
|
|
16
|
+
/** What follows a signal at the very start of the text, or undefined when the text does not open with one. */
|
|
17
|
+
const afterOpeningSignal = (text: string, signals: readonly string[]): string | undefined => {
|
|
18
|
+
if (signals.length === 0) return undefined;
|
|
19
|
+
const alternatives = [...signals]
|
|
20
|
+
.sort((left, right) => right.length - left.length)
|
|
21
|
+
.map(escapeRegExp)
|
|
22
|
+
.join("|");
|
|
23
|
+
const opening = new RegExp(String.raw`^(?:${alternatives})${EXAMPLE_SIGNAL}(?![\p{L}\p{N}])`, "iu").exec(text.trim());
|
|
24
|
+
return opening === null ? undefined : text.trim().slice(opening[0].length);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const isTitleSeries = (cited: string): boolean => {
|
|
28
|
+
const segments = cited.split(SEGMENT_SEPARATOR).filter((segment) => segment.trim() !== "");
|
|
29
|
+
return segments.length >= MIN_TITLES && segments.every(isTitleCase);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** Whether the text is a citation string: a signal first, then a legal citation or a series of titles. */
|
|
33
|
+
export const isCitationString = (text: string, signals: readonly string[]): boolean => {
|
|
34
|
+
const cited = afterOpeningSignal(text, signals);
|
|
35
|
+
return cited !== undefined && ((SECTION_SIGN.test(cited) && CITATION_DETAIL.test(cited)) || isTitleSeries(cited));
|
|
36
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Detector, Finding, LexiconEntry, Paragraph, Sentence } from "../plugin.ts";
|
|
2
|
+
import { closingSentences } from "../closing-paragraph.ts";
|
|
3
|
+
import { exhortationIn, exhortationWords } from "./closing-exhortation.ts";
|
|
4
|
+
import { comparableText, entryIn, entryOpens } from "./lexicon-match.ts";
|
|
5
|
+
|
|
6
|
+
// 定型の結び(いかがでしたか、Hope this helps、Happy brewing!)。語はどれも語彙表が持ち、ここは組み方だけを知る。語彙表の group:
|
|
7
|
+
// なし 結び(最後の節の終わりの段落)のどこかにあれば当たる言い回し
|
|
8
|
+
// last 最後の段落にあるときだけ当たる言い回し(てみてほしい)。本文の途中なら普通の勧め
|
|
9
|
+
// lead:/open:/end:<name> 前の語と文の終わりの語の組(気軽に〜ください)。closing-exhortation と同じ書き方
|
|
10
|
+
// signoff 最後の段落の、この語で始まり「!」で終わる短い一行(Happy brewing!)
|
|
11
|
+
|
|
12
|
+
const LAST = "last";
|
|
13
|
+
const SIGNOFF = "signoff";
|
|
14
|
+
|
|
15
|
+
/** 一行の結びの挨拶と読む語の数の上限。「Happy brewing!」は二語、「Happy holidays, everyone!」は三語。 */
|
|
16
|
+
const SIGNOFF_WORDS = 3;
|
|
17
|
+
|
|
18
|
+
const NOT_WORDS = new Set(["PUNCT", "SYM"]);
|
|
19
|
+
|
|
20
|
+
const wordCount = (sentence: Sentence): number =>
|
|
21
|
+
sentence.tokens === undefined
|
|
22
|
+
? comparableText(sentence)
|
|
23
|
+
.split(/\s+/u)
|
|
24
|
+
.filter((word) => /\p{L}/u.test(word)).length
|
|
25
|
+
: sentence.tokens.filter((token) => !NOT_WORDS.has(token.pos)).length;
|
|
26
|
+
|
|
27
|
+
const isSignoff = (sentence: Sentence, entry: LexiconEntry): boolean =>
|
|
28
|
+
entryOpens(sentence, entry) && /[!!]$/u.test(comparableText(sentence).trimEnd()) && wordCount(sentence) <= SIGNOFF_WORDS;
|
|
29
|
+
|
|
30
|
+
/** 結びの最後の段落の文。結びの最後の文を含む段落から後ろ。 */
|
|
31
|
+
const lastParagraphSentences = (sentences: readonly Sentence[], paragraphs: readonly Paragraph[]): readonly Sentence[] => {
|
|
32
|
+
const final = sentences.at(-1);
|
|
33
|
+
if (final === undefined) return [];
|
|
34
|
+
const paragraph = paragraphs.find((each) => each.span.start <= final.span.start && final.span.start < each.span.end);
|
|
35
|
+
return paragraph === undefined ? [final] : sentences.filter((sentence) => sentence.span.start >= paragraph.span.start);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
type Words = { readonly closing: ReturnType<typeof exhortationWords>; readonly last: readonly LexiconEntry[]; readonly signoff: readonly LexiconEntry[] };
|
|
39
|
+
|
|
40
|
+
/** 最後の段落でだけ当たる語。言い回しなら語彙の語、挨拶の一行なら文そのもの。 */
|
|
41
|
+
const lastIn = (sentence: Sentence, words: Words): string | undefined =>
|
|
42
|
+
words.last.find((entry) => entryIn(sentence, entry))?.pattern ??
|
|
43
|
+
(words.signoff.some((entry) => isSignoff(sentence, entry)) ? sentence.text.trim() : undefined);
|
|
44
|
+
|
|
45
|
+
type Hit = { readonly sentence: Sentence; readonly matched: string };
|
|
46
|
+
|
|
47
|
+
/** 結びの、定型の言い回しのある文。一文に一つ。 */
|
|
48
|
+
export const closingClicheHits = (sentences: readonly Sentence[], paragraphs: readonly Paragraph[], words: Words): Hit[] => {
|
|
49
|
+
const last = new Set(lastParagraphSentences(sentences, paragraphs));
|
|
50
|
+
return sentences.flatMap((sentence) => {
|
|
51
|
+
const matched = exhortationIn(sentence, words.closing) ?? (last.has(sentence) ? lastIn(sentence, words) : undefined);
|
|
52
|
+
return matched === undefined ? [] : [{ sentence, matched }];
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const closingClicheWords = (lexicon: readonly LexiconEntry[]): Words => ({
|
|
57
|
+
closing: exhortationWords(lexicon),
|
|
58
|
+
last: lexicon.filter((entry) => entry.group === LAST),
|
|
59
|
+
signoff: lexicon.filter((entry) => entry.group === SIGNOFF),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/** 結び(最後の節の終わりの段落)の定型の言い回し。limit は指摘に要る文の数。 */
|
|
63
|
+
export const closingCliche: Detector = (doc, options): Finding[] => {
|
|
64
|
+
const hits = closingClicheHits(closingSentences(doc.sections, doc.paragraphs), doc.paragraphs, closingClicheWords(options.lexicon ?? []));
|
|
65
|
+
if (hits.length < options.limit) return [];
|
|
66
|
+
return hits.map((hit) => ({
|
|
67
|
+
rule: "",
|
|
68
|
+
severity: "warning",
|
|
69
|
+
line: 0,
|
|
70
|
+
column: 0,
|
|
71
|
+
quote: hit.sentence.text.trim(),
|
|
72
|
+
values: { matched: hit.matched, count: hits.length, limit: options.limit, offset: hit.sentence.span.start },
|
|
73
|
+
}));
|
|
74
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Detector, Finding, Lexicon, LexiconEntry, Sentence } from "../plugin.ts";
|
|
2
|
+
import { closingSentences } from "../closing-paragraph.ts";
|
|
3
|
+
import { comparableText, comparableWords, entryCloses, entryIn, entryOpens } from "./lexicon-match.ts";
|
|
4
|
+
|
|
5
|
+
// 結びで読み手を励ます・請け合う文(ぜひ〜してみてください、きっと〜はず、You've got this)。語はどれも語彙表が持ち、
|
|
6
|
+
// ここは組み方だけを知る。語彙表の group:
|
|
7
|
+
// なし それだけで当たる言い回し(てみてほしい、you've got this)
|
|
8
|
+
// lead:<name> 文の中の前の語(ぜひ、きっと)。同じ <name> の end が後ろにあれば当たる
|
|
9
|
+
// open:<name> 文頭に限る前の語(Happy)
|
|
10
|
+
// end:<name> 文の終わりの語(てみてください、はずだ、!)
|
|
11
|
+
|
|
12
|
+
type Pair = { readonly name: string; readonly leads: Lexicon; readonly opens: Lexicon; readonly ends: Lexicon };
|
|
13
|
+
|
|
14
|
+
const LEAD = "lead:";
|
|
15
|
+
const OPEN = "open:";
|
|
16
|
+
const END = "end:";
|
|
17
|
+
|
|
18
|
+
const withPrefix = (lexicon: Lexicon, prefix: string, name: string): Lexicon => lexicon.filter((entry) => entry.group === `${prefix}${name}`);
|
|
19
|
+
|
|
20
|
+
const pairNames = (lexicon: Lexicon): string[] => [
|
|
21
|
+
...new Set(lexicon.flatMap((entry) => (entry.group?.startsWith(END) === true ? [entry.group.slice(END.length)] : []))),
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
/** 語彙表を、それだけで当たる言い回しと、前後の語の組に分ける。 */
|
|
25
|
+
export const exhortationWords = (lexicon: Lexicon): { readonly phrases: Lexicon; readonly pairs: readonly Pair[] } => ({
|
|
26
|
+
phrases: lexicon.filter((entry) => entry.group === undefined),
|
|
27
|
+
pairs: pairNames(lexicon).map((name) => ({
|
|
28
|
+
name,
|
|
29
|
+
leads: withPrefix(lexicon, LEAD, name),
|
|
30
|
+
opens: withPrefix(lexicon, OPEN, name),
|
|
31
|
+
ends: withPrefix(lexicon, END, name),
|
|
32
|
+
})),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/** 文が語で終わるか。終わりの記号の手前の語(はずだ。)でも、記号そのもの(Happy baking!)でもよい。 */
|
|
36
|
+
const closesWith = (sentence: Sentence, entry: LexiconEntry): boolean =>
|
|
37
|
+
entryCloses(sentence, entry) || withoutClosingQuotes(comparableText(sentence)).endsWith(comparableWords(entry.pattern));
|
|
38
|
+
|
|
39
|
+
/** Quotes, closing brackets and spaces after the last mark ("Happy baking!"), which close the sentence without ending it. */
|
|
40
|
+
const CLOSING_QUOTES = new Set(" \t\n」』))\"'”’");
|
|
41
|
+
|
|
42
|
+
const withoutClosingQuotes = (text: string): string => {
|
|
43
|
+
const chars = [...text];
|
|
44
|
+
return chars.slice(0, chars.findLastIndex((char) => !CLOSING_QUOTES.has(char)) + 1).join("");
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** 前の語が文の中に(open なら文頭に)あり、文が組の後ろの語で終わるか。当たった前の語を返す。 */
|
|
48
|
+
const pairIn = (sentence: Sentence, pair: Pair): LexiconEntry | undefined => {
|
|
49
|
+
if (!pair.ends.some((entry) => closesWith(sentence, entry))) return undefined;
|
|
50
|
+
return pair.opens.find((entry) => entryOpens(sentence, entry)) ?? pair.leads.find((entry) => entryIn(sentence, entry));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** 文が励ましか請け合いなら、言う語。 */
|
|
54
|
+
export const exhortationIn = (sentence: Sentence, words: ReturnType<typeof exhortationWords>): string | undefined =>
|
|
55
|
+
words.phrases.find((entry) => entryIn(sentence, entry))?.pattern ??
|
|
56
|
+
words.pairs.map((pair) => pairIn(sentence, pair)).find((entry) => entry !== undefined)?.pattern;
|
|
57
|
+
|
|
58
|
+
/** 結び(最後の節の終わりの段落)で読み手を励ます・請け合う文の数。limit は指摘に要る数。 */
|
|
59
|
+
export const closingExhortation: Detector = (doc, options): Finding[] => {
|
|
60
|
+
const words = exhortationWords(options.lexicon ?? []);
|
|
61
|
+
const hits = closingSentences(doc.sections, doc.paragraphs).flatMap((sentence) => {
|
|
62
|
+
const matched = exhortationIn(sentence, words);
|
|
63
|
+
return matched === undefined ? [] : [{ sentence, matched }];
|
|
64
|
+
});
|
|
65
|
+
if (hits.length < options.limit) return [];
|
|
66
|
+
return hits.map((hit) => ({
|
|
67
|
+
rule: "",
|
|
68
|
+
severity: "info",
|
|
69
|
+
line: 0,
|
|
70
|
+
column: 0,
|
|
71
|
+
quote: hit.sentence.text.trim(),
|
|
72
|
+
values: { matched: hit.matched, count: hits.length, limit: options.limit, offset: hit.sentence.span.start },
|
|
73
|
+
}));
|
|
74
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { Detector, Finding, Lexicon, LexiconEntry, ProseDocument, Sentence } from "../plugin.ts";
|
|
2
|
+
import { lengthOf } from "../measure.ts";
|
|
3
|
+
import { quotedSpans, QUOTATION_MARKS } from "../quoted-span.ts";
|
|
4
|
+
import { escapeRegExp } from "../orthography.ts";
|
|
5
|
+
import { comparableText, comparableWords, entryIn, entryOpens, entryRanges } from "./lexicon-match.ts";
|
|
6
|
+
|
|
7
|
+
// 書き出しの 3 つの形。語は言語パッケージの語彙表が持ち、ここは形だけを知る。
|
|
8
|
+
// open / end: 最初の文が、その語で始まる・終わる短い願い(〜したい。 / You want to …)
|
|
9
|
+
// echo: 前の文の語を、指す語のすぐ後ろの引用符で引き直す(この「だいたい」が / That ‘almost’)
|
|
10
|
+
// teaser: 易しく見せてから難所を予告する(それだけのことに見えて / Sounds simple.)
|
|
11
|
+
|
|
12
|
+
/** 書き出しとして読む文の数。人の記事でも、ここまでに状況か例が出る。 */
|
|
13
|
+
export const OPENING_SENTENCES = 8;
|
|
14
|
+
|
|
15
|
+
/** 願いが「短い」と言える長さ(和文は字、英文は語)。 */
|
|
16
|
+
const SHORT_WISH = { char: 40, word: 15 };
|
|
17
|
+
|
|
18
|
+
/** 引き直した語の長さの上限(和文は字、英文は語)。長い引用は言葉の引用で、語の引き直しではない。 */
|
|
19
|
+
const ECHO_SPAN = { char: 10, word: 3 };
|
|
20
|
+
|
|
21
|
+
/** 英文で語を引き直す一重の引用符(‘almost’)。直線の ' は省略の印と見分けられないので読まない。 */
|
|
22
|
+
const ECHO_MARKS = { ...QUOTATION_MARKS, "‘": "’" };
|
|
23
|
+
|
|
24
|
+
/** 文末の句点・感嘆符・閉じ括弧。 */
|
|
25
|
+
const SENTENCE_END = new Set('。..!!??」』”"’))');
|
|
26
|
+
|
|
27
|
+
/** 文末の記号と空白を除いた文。 */
|
|
28
|
+
const withoutEnd = (text: string): string => {
|
|
29
|
+
const chars = [...text];
|
|
30
|
+
const last = chars.findLastIndex((char) => !SENTENCE_END.has(char) && char.trim() !== "");
|
|
31
|
+
return chars.slice(0, last + 1).join("");
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type ColdOpenShape = "wish" | "echo" | "teaser";
|
|
35
|
+
|
|
36
|
+
export type ColdOpenHit = { readonly shape: ColdOpenShape; readonly sentence: Sentence; readonly matched: string };
|
|
37
|
+
|
|
38
|
+
const inGroup = (lexicon: Lexicon, group: string): LexiconEntry[] => lexicon.filter((entry) => entry.group === group);
|
|
39
|
+
|
|
40
|
+
/** 書き出しの文:最初の段落から順に、箇条書きと文書と違う言語の文を除いて。 */
|
|
41
|
+
export const openingSentences = (doc: ProseDocument): Sentence[] =>
|
|
42
|
+
doc.paragraphs
|
|
43
|
+
.flatMap((paragraph) => paragraph.sentences)
|
|
44
|
+
.filter((sentence) => sentence.listItem !== true && sentence.embeddedLanguage === undefined)
|
|
45
|
+
.slice(0, OPENING_SENTENCES);
|
|
46
|
+
|
|
47
|
+
const TRAILING_MARK = new Set(["PUNCT", "SYM"]);
|
|
48
|
+
|
|
49
|
+
/** 文が語彙表の語で終わるか。品詞があれば語の並びで照らすので、「みたい」は「たい」に当たらない。 */
|
|
50
|
+
const endsWith = (sentence: Sentence, entry: LexiconEntry): boolean => {
|
|
51
|
+
const tokens = sentence.tokens;
|
|
52
|
+
if (tokens === undefined || entry.tokens === undefined || entry.tokens.length === 0)
|
|
53
|
+
return withoutEnd(comparableText(sentence)).endsWith(comparableWords(entry.pattern));
|
|
54
|
+
const last = tokens.findLastIndex((token) => !TRAILING_MARK.has(token.pos) && token.surface.trim() !== "");
|
|
55
|
+
return entryRanges(sentence, entry).some((range) => range.end === last + 1);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** 最初の文が、語彙表の語で始まるか終わる短い願いか。 */
|
|
59
|
+
export const wishOpening = (first: Sentence | undefined, lexicon: Lexicon, unit: "char" | "word"): ColdOpenHit[] => {
|
|
60
|
+
if (first === undefined || lengthOf(first, unit) > SHORT_WISH[unit]) return [];
|
|
61
|
+
const entry = inGroup(lexicon, "open").find((open) => entryOpens(first, open)) ?? inGroup(lexicon, "end").find((end) => endsWith(first, end));
|
|
62
|
+
return entry === undefined ? [] : [{ shape: "wish", sentence: first, matched: first.text.trim() }];
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const isWordChar = (char: string | undefined): boolean => char !== undefined && /[\p{L}\p{N}]/u.test(char);
|
|
66
|
+
|
|
67
|
+
/** 定義を置く括弧の開き。契約の (this "Agreement") は語の引き直しではなく定義。 */
|
|
68
|
+
const DEFINITION_OPEN = new Set(["(", "("]);
|
|
69
|
+
|
|
70
|
+
/** 引用符の直前が、語彙表の指す語(この、That)で終わるか。英字の語は語の途中に当たらない。 */
|
|
71
|
+
const pointedAt = (before: string, pointers: readonly LexiconEntry[]): LexiconEntry | undefined => {
|
|
72
|
+
const head = comparableWords(before).trimEnd();
|
|
73
|
+
return pointers.find((pointer) => {
|
|
74
|
+
const word = comparableWords(pointer.pattern);
|
|
75
|
+
if (!head.endsWith(word)) return false;
|
|
76
|
+
const preceding = head.slice(0, -word.length).trimEnd().at(-1);
|
|
77
|
+
return !DEFINITION_OPEN.has(preceding ?? "") && !(/^[a-z]/u.test(word) && isWordChar(head.at(-word.length - 1)));
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/** 引用符で引いたところを空白にした文。前の文でも引用符の中にある語は、引き直しではなく同じ語の言及。位置は変えない。 */
|
|
82
|
+
const unquoted = (text: string): string => {
|
|
83
|
+
const quoted = quotedSpans(text, ECHO_MARKS);
|
|
84
|
+
return text
|
|
85
|
+
.split("")
|
|
86
|
+
.map((char, at) => (quoted.some((span) => at >= span.start - 1 && at <= span.end) ? " " : char))
|
|
87
|
+
.join("");
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/** 前の文に、引いた語がそのまま出るか。英字の語は語の途中(database の base)に当たらない。 */
|
|
91
|
+
const occursIn = (previous: string, word: string, unit: "char" | "word"): boolean =>
|
|
92
|
+
unit === "char" ? previous.includes(word) : new RegExp(`(?<![\\p{L}\\p{N}])${escapeRegExp(word)}(?![\\p{L}\\p{N}])`, "u").test(previous);
|
|
93
|
+
|
|
94
|
+
const spanLength = (text: string, unit: "char" | "word"): number =>
|
|
95
|
+
unit === "char" ? text.replace(/\s+/gu, "").length : text.split(/\s+/u).filter(Boolean).length;
|
|
96
|
+
|
|
97
|
+
/** 前の文の語を、指す語の後ろの引用符で引き直した文(この「だいたい」が困ります)。 */
|
|
98
|
+
export const echoQuotes = (sentences: readonly Sentence[], lexicon: Lexicon, unit: "char" | "word"): ColdOpenHit[] => {
|
|
99
|
+
const pointers = inGroup(lexicon, "echo");
|
|
100
|
+
if (pointers.length === 0) return [];
|
|
101
|
+
return sentences.slice(1).flatMap((sentence, index) => {
|
|
102
|
+
const previous = comparableWords(unquoted(sentences[index]?.text ?? ""));
|
|
103
|
+
const echoed = quotedSpans(sentence.text, ECHO_MARKS).find((span) => {
|
|
104
|
+
const inner = sentence.text.slice(span.start, span.end).trim();
|
|
105
|
+
if (inner === "" || spanLength(inner, unit) > ECHO_SPAN[unit]) return false;
|
|
106
|
+
return pointedAt(sentence.text.slice(0, span.start - 1), pointers) !== undefined && occursIn(previous, comparableWords(inner), unit);
|
|
107
|
+
});
|
|
108
|
+
return echoed === undefined ? [] : [{ shape: "echo" as const, sentence, matched: sentence.text.slice(echoed.start, echoed.end).trim() }];
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** 易しく見せてから難所を予告する言い回し。 */
|
|
113
|
+
export const teasers = (sentences: readonly Sentence[], lexicon: Lexicon): ColdOpenHit[] => {
|
|
114
|
+
const phrases = inGroup(lexicon, "teaser");
|
|
115
|
+
return sentences.flatMap((sentence) => {
|
|
116
|
+
const entry = phrases.find((phrase) => entryIn(sentence, phrase));
|
|
117
|
+
return entry === undefined ? [] : [{ shape: "teaser" as const, sentence, matched: entry.pattern }];
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** 書き出しに出た形。形ごとに最初の 1 つ。 */
|
|
122
|
+
export const coldOpenHits = (doc: ProseDocument, lexicon: Lexicon): ColdOpenHit[] => {
|
|
123
|
+
const opening = openingSentences(doc);
|
|
124
|
+
const found = [...wishOpening(opening[0], lexicon, doc.lengthUnit), ...echoQuotes(opening, lexicon, doc.lengthUnit), ...teasers(opening, lexicon)];
|
|
125
|
+
return [...new Map(found.map((hit) => [hit.shape, hit])).values()];
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 状況も例もなく始まる書き出し。形 1 つは人の文書にもある(提案の「〜したい。」、定義の言い直し)。
|
|
130
|
+
* limit は書き出しに要る形の数で、重なったときだけ、形ごとの文を言う。
|
|
131
|
+
*/
|
|
132
|
+
export const coldOpen: Detector = (doc, options): Finding[] => {
|
|
133
|
+
const hits = coldOpenHits(doc, options.lexicon ?? []);
|
|
134
|
+
if (hits.length === 0 || hits.length < options.limit) return [];
|
|
135
|
+
return hits
|
|
136
|
+
.toSorted((a, b) => a.sentence.span.start - b.sentence.span.start)
|
|
137
|
+
.map((hit) => ({
|
|
138
|
+
rule: "",
|
|
139
|
+
severity: "info",
|
|
140
|
+
line: 0,
|
|
141
|
+
column: 0,
|
|
142
|
+
quote: hit.sentence.text.trim(),
|
|
143
|
+
values: { matched: hit.matched, count: hits.length, limit: options.limit, offset: hit.sentence.span.start },
|
|
144
|
+
}));
|
|
145
|
+
};
|