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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DocumentNamer, Span } from "../plugin.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 文の中に書いた文書の名前(「高齢者、障害者等の移動等の円滑化の促進に関する法律」)の位置。
|
|
5
|
+
* 題名は書き手が言い換えられないので、鉤括弧で引いた題名と同じく、中の助詞を数えず一つの名詞として読む。
|
|
6
|
+
* 名前は言語パッケージが読む(名前の終わりの位置を渡すと、そこで終わる名前を返す)。読めない言語では何も返さない。
|
|
7
|
+
*/
|
|
8
|
+
export const documentNameSpans = (text: string, within: Span, namer: DocumentNamer | undefined): Span[] => {
|
|
9
|
+
if (namer === undefined) return [];
|
|
10
|
+
const ends = Array.from({ length: within.end - within.start }, (_, index) => within.start + index + 1);
|
|
11
|
+
return ends.flatMap((end) => {
|
|
12
|
+
const named = namer(text, end);
|
|
13
|
+
// 名前の後ろの括弧書きやつなぎの語(「民法の」の「の」)を読み飛ばした名前は、ここで終わる名前ではない。
|
|
14
|
+
const endsHere = named !== undefined && named.name !== "" && text.slice(end - named.name.length, end) === named.name;
|
|
15
|
+
return endsHere ? [{ start: end - named.name.length, end }] : [];
|
|
16
|
+
});
|
|
17
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// proper-noun-density: names per 1000 words (characters in Japanese) of prose. A name counts once however many words
|
|
2
|
+
// it has, a line that is not a sentence is not prose, and the everyday names of lexicon everyday-name are not counted.
|
|
3
|
+
import { lengthOf, proseText } from "../measure.ts";
|
|
4
|
+
import { nameSpans } from "../team-names.ts";
|
|
5
|
+
import { QUOTATION_MARKS, quotedIn } from "../quoted-span.ts";
|
|
6
|
+
import type { Detector, Finding, ProseDocument, Sentence, Span, Token } from "../plugin.ts";
|
|
7
|
+
|
|
8
|
+
const PER = 1000;
|
|
9
|
+
/** 密度を見る rule は短い文書を測らない。単位は言語で違うので床も分ける。 */
|
|
10
|
+
const FLOOR = { word: 200, char: 500 };
|
|
11
|
+
const EVERYDAY_NAME = "everyday-name";
|
|
12
|
+
const PREDICATES: ReadonlySet<string> = new Set(["VERB", "AUX"]);
|
|
13
|
+
/**
|
|
14
|
+
* What may stand between two words of one name: spaces, a hyphen, a slash, an initial's full stop, an ampersand, an apostrophe,
|
|
15
|
+
* and an opening bracket, since a name's short form in brackets right after it is the same name (Office of the Comptroller (OCC)).
|
|
16
|
+
*/
|
|
17
|
+
const INSIDE_NAME = /^[\s\-‐/.&'’((]*$/u;
|
|
18
|
+
const LATIN = /\p{Script=Latin}/u;
|
|
19
|
+
const CAPITAL = /\p{Lu}/u;
|
|
20
|
+
const LETTER = /\p{L}/u;
|
|
21
|
+
const LOWER_START = /^\p{Ll}/u;
|
|
22
|
+
const CONTENT: ReadonlySet<string> = new Set(["NOUN", "ADJ", "ADV"]);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A word only prose has: a verb in lower case or in a script without case (a capitalised one is a title's: Arrangements to
|
|
26
|
+
* Deliver Services), or any other lower-case content word, since the tagger can read a verb among many names as a noun (flew).
|
|
27
|
+
*/
|
|
28
|
+
const isProseWord = (token: Token): boolean => {
|
|
29
|
+
if (PREDICATES.has(token.pos)) return !CAPITAL.test(token.surface.charAt(0));
|
|
30
|
+
return CONTENT.has(token.pos) && LATIN.test(token.surface) && LOWER_START.test(token.surface);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** A sentence may open with its verb (Moved by D. Kim, ...; Meet Alice at Contoso.). */
|
|
34
|
+
const opensWithVerb = (tokens: readonly Token[]): boolean => {
|
|
35
|
+
const first = tokens.find((token) => LETTER.test(token.surface));
|
|
36
|
+
return first !== undefined && PREDICATES.has(first.pos);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A sentence with no word of prose is a line, not prose: a letterhead, a roster, a signature, an address, a heading, a list of
|
|
41
|
+
* document titles or a table row read as text. A reader does not parse it as a sentence, so its names hide no sentence's shape.
|
|
42
|
+
*/
|
|
43
|
+
export const isProse = (sentence: Sentence): boolean => {
|
|
44
|
+
const tokens = sentence.tokens ?? [];
|
|
45
|
+
return opensWithVerb(tokens) || tokens.some(isProseWord);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** A Latin word with no capital is no name, whatever the tagger said: the Japanese tagger marks English words (rule, requests) as proper nouns. */
|
|
49
|
+
const isNameWord = (token: Token): boolean => token.pos === "PROPN" && !(LATIN.test(token.surface) && !CAPITAL.test(token.surface));
|
|
50
|
+
|
|
51
|
+
const within = (spans: readonly Span[], token: Token): Span | undefined => spans.find((span) => token.span.start >= span.start && token.span.end <= span.end);
|
|
52
|
+
|
|
53
|
+
const spansIn = (sentence: Sentence, names: readonly string[]): Span[] =>
|
|
54
|
+
nameSpans(sentence.text, names).map((span) => ({ start: sentence.span.start + span.start, end: sentence.span.start + span.end }));
|
|
55
|
+
|
|
56
|
+
const between = (sentence: Sentence, end: number, start: number): string => sentence.text.slice(end - sentence.span.start, start - sentence.span.start);
|
|
57
|
+
|
|
58
|
+
/** The first word of each name: adjacent name words (Federal Reserve System, 赤堀 政明, Randall D. Guynn) are one name. */
|
|
59
|
+
const nameStarts = (sentence: Sentence, everyday: readonly Span[]): Token[] => {
|
|
60
|
+
const words = (sentence.tokens ?? []).filter((token) => isNameWord(token) && within(everyday, token) === undefined);
|
|
61
|
+
return words.filter((token, index) => {
|
|
62
|
+
const previous = words[index - 1];
|
|
63
|
+
return previous === undefined || !INSIDE_NAME.test(between(sentence, previous.span.end, token.span.start));
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const tokensWithin = (sentence: Sentence, span: Span): Token[] =>
|
|
68
|
+
(sentence.tokens ?? []).filter((token) => token.span.start >= span.start && token.span.end <= span.end);
|
|
69
|
+
|
|
70
|
+
/** Quoted words with no word of prose are a title: “Joint Statement on the Risk-Based Approach to Assessing Customer Relationships” is one name. */
|
|
71
|
+
const titlesIn = (sentence: Sentence): Span[] => quotedIn(sentence, QUOTATION_MARKS).filter((span) => !tokensWithin(sentence, span).some(isProseWord));
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The names one sentence counts. A name the team listed in chaff.yaml is one, however many names the words in it make
|
|
75
|
+
* (Bank of England is one, not two), and so is a quoted title.
|
|
76
|
+
*/
|
|
77
|
+
export const namesIn = (sentence: Sentence, listed: readonly string[], everyday: readonly string[]): Token[] => {
|
|
78
|
+
const named = [...spansIn(sentence, listed), ...titlesIn(sentence)];
|
|
79
|
+
const counted = new Set<Span>();
|
|
80
|
+
return nameStarts(sentence, spansIn(sentence, everyday)).filter((token) => {
|
|
81
|
+
const name = within(named, token);
|
|
82
|
+
if (name === undefined) return true;
|
|
83
|
+
if (counted.has(name)) return false;
|
|
84
|
+
counted.add(name);
|
|
85
|
+
return true;
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const everydayNamesOf = (doc: ProseDocument): string[] => (doc.lexicons[EVERYDAY_NAME] ?? []).map((entry) => entry.pattern);
|
|
90
|
+
|
|
91
|
+
export const properNounDensity: Detector = (doc, options): Finding[] => {
|
|
92
|
+
const prose = doc.sentences.filter(isProse);
|
|
93
|
+
const everyday = everydayNamesOf(doc);
|
|
94
|
+
const hits = prose.flatMap((sentence) => namesIn(sentence, doc.names ?? [], everyday).map((token) => ({ sentence, token })));
|
|
95
|
+
const length = prose.reduce((sum, sentence) => sum + lengthOf(sentence, doc.lengthUnit), 0);
|
|
96
|
+
const rate = length === 0 ? 0 : Math.round((hits.length / length) * PER);
|
|
97
|
+
const first = hits[0];
|
|
98
|
+
if (length < FLOOR[doc.lengthUnit] || first === undefined || rate <= options.limit) return [];
|
|
99
|
+
return [
|
|
100
|
+
{
|
|
101
|
+
rule: "proper-noun-density",
|
|
102
|
+
severity: "info",
|
|
103
|
+
line: 0,
|
|
104
|
+
column: 0,
|
|
105
|
+
quote: proseText(first.sentence),
|
|
106
|
+
values: { count: hits.length, density: rate, limit: options.limit, offset: first.token.span.start },
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Quotations that mark an omission (… or * * *) inside them: an excerpt of another text, such as a statute quoted in a
|
|
2
|
+
// ruling. A list inside one is punctuated by that text, not by the writer. Pure.
|
|
3
|
+
import type { Token } from "../plugin.ts";
|
|
4
|
+
|
|
5
|
+
type Span = { readonly start: number; readonly end: number };
|
|
6
|
+
|
|
7
|
+
/** Room for a closing mark the sentence's last token leaves outside (law * * *.'). */
|
|
8
|
+
const CLOSING_REACH = 2;
|
|
9
|
+
|
|
10
|
+
/** The marks that open and close a quotation, by family. A straight mark both opens and closes. */
|
|
11
|
+
const OPENING: ReadonlyMap<string, string> = new Map([
|
|
12
|
+
["“", "double"],
|
|
13
|
+
['"', "double"],
|
|
14
|
+
["‘", "single"],
|
|
15
|
+
["'", "single"],
|
|
16
|
+
]);
|
|
17
|
+
const CLOSING: ReadonlyMap<string, string> = new Map([
|
|
18
|
+
["”", "double"],
|
|
19
|
+
['"', "double"],
|
|
20
|
+
["’", "single"],
|
|
21
|
+
["'", "single"],
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
const WORD_CHAR = /[\p{L}\p{N}]/u;
|
|
25
|
+
const SPACE = /\s/u;
|
|
26
|
+
|
|
27
|
+
const isWordChar = (char: string): boolean => WORD_CHAR.test(char);
|
|
28
|
+
|
|
29
|
+
/** An opening mark follows no letter and precedes no space; a closing one follows no space and precedes no letter (don't). */
|
|
30
|
+
const opensAt = (text: string, at: number): boolean => !isWordChar(text.charAt(at - 1)) && at + 1 < text.length && !SPACE.test(text.charAt(at + 1));
|
|
31
|
+
|
|
32
|
+
const closesAt = (text: string, at: number): boolean => at > 0 && !SPACE.test(text.charAt(at - 1)) && !isWordChar(text.charAt(at + 1));
|
|
33
|
+
|
|
34
|
+
type Scan = { readonly spans: Span[]; open: { readonly family: string; readonly at: number } | undefined };
|
|
35
|
+
|
|
36
|
+
const step = (text: string, scan: Scan, char: string, at: number): Scan => {
|
|
37
|
+
const { open } = scan;
|
|
38
|
+
if (open !== undefined && CLOSING.get(char) === open.family && closesAt(text, at)) {
|
|
39
|
+
scan.spans.push({ start: open.at, end: at + 1 });
|
|
40
|
+
scan.open = undefined;
|
|
41
|
+
} else if (open === undefined && OPENING.has(char) && opensAt(text, at)) {
|
|
42
|
+
scan.open = { family: OPENING.get(char) ?? "", at };
|
|
43
|
+
}
|
|
44
|
+
return scan;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** The quotations in a text, each from its opening mark to its closing mark. Quotations do not nest here. */
|
|
48
|
+
export const quotationsIn = (text: string): Span[] =>
|
|
49
|
+
text.split("").reduce<Scan>((scan, char, at) => step(text, scan, char, at), { spans: [], open: undefined }).spans;
|
|
50
|
+
|
|
51
|
+
/** The spans of the quotations in a stretch of the source that hold one of the elision marks, as offsets in the source. */
|
|
52
|
+
export const excerptSpans = (source: string, from: number, to: number, marks: readonly string[]): Span[] => {
|
|
53
|
+
const text = source.slice(from, to);
|
|
54
|
+
return quotationsIn(text)
|
|
55
|
+
.filter((span) => marks.some((mark) => mark !== "" && text.slice(span.start + 1, span.end - 1).includes(mark)))
|
|
56
|
+
.map((span) => ({ start: from + span.start, end: from + span.end }));
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** For each token of a sentence, whether it stands inside a quoted excerpt. */
|
|
60
|
+
export const inExcerpt = (tokens: readonly Token[], source: string, marks: readonly string[]): ((at: number) => boolean) => {
|
|
61
|
+
const [first, last] = [tokens[0], tokens.at(-1)];
|
|
62
|
+
if (first === undefined || last === undefined || marks.length === 0) return () => false;
|
|
63
|
+
const spans = excerptSpans(source, first.span.start, last.span.end + CLOSING_REACH, marks);
|
|
64
|
+
return (at) => {
|
|
65
|
+
const offset = tokens[at]?.span.start ?? -1;
|
|
66
|
+
return spans.some((span) => offset > span.start && offset < span.end);
|
|
67
|
+
};
|
|
68
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Entries of a reference list keyed by a bracketed label, as an RFC prints them:
|
|
2
|
+
//
|
|
3
|
+
// [FETCH] WHATWG, "Fetch - Living Standard",
|
|
4
|
+
// <https://fetch.spec.whatwg.org/>.
|
|
5
|
+
//
|
|
6
|
+
// The entry is written in the cited work's words. Pure.
|
|
7
|
+
|
|
8
|
+
type Span = { readonly start: number; readonly end: number };
|
|
9
|
+
|
|
10
|
+
/** A label in square brackets opening a line, then a wide gap: two spaces or a tab. A link definition ([x]: url) has a colon. */
|
|
11
|
+
const ENTRY_START = /^(?<indent>[ \t]*)\[[A-Za-z0-9][\w.:+-]*\](?: {2,}|\t)\S/u;
|
|
12
|
+
|
|
13
|
+
type Line = { readonly text: string; readonly start: number };
|
|
14
|
+
|
|
15
|
+
const linesOf = (source: string): Line[] =>
|
|
16
|
+
source.split("\n").reduce<Line[]>((lines, text) => {
|
|
17
|
+
const previous = lines.at(-1);
|
|
18
|
+
lines.push({ text, start: previous === undefined ? 0 : previous.start + previous.text.length + 1 });
|
|
19
|
+
return lines;
|
|
20
|
+
}, []);
|
|
21
|
+
|
|
22
|
+
const indentOf = (text: string): number => text.length - text.trimStart().length;
|
|
23
|
+
|
|
24
|
+
/** The entry's own lines: the label's line and the lines after it indented deeper than the label, up to a blank line. */
|
|
25
|
+
// A loop from at: slicing the rest for every entry would be quadratic in a long reference list.
|
|
26
|
+
const entryEnd = (lines: readonly Line[], at: number, indent: number): number => {
|
|
27
|
+
for (let index = at + 1; index < lines.length; index += 1) {
|
|
28
|
+
const text = lines[index]?.text ?? "";
|
|
29
|
+
if (text.trim() === "" || indentOf(text) <= indent) return index;
|
|
30
|
+
}
|
|
31
|
+
return lines.length;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const referenceEntrySpans = (source: string): Span[] => {
|
|
35
|
+
const lines = linesOf(source);
|
|
36
|
+
return lines.flatMap((line, at) => {
|
|
37
|
+
const indent = ENTRY_START.exec(line.text)?.groups?.["indent"];
|
|
38
|
+
if (indent === undefined) return [];
|
|
39
|
+
const last = lines[entryEnd(lines, at, indent.length) - 1] ?? line;
|
|
40
|
+
return [{ start: line.start, end: last.start + last.text.length }];
|
|
41
|
+
});
|
|
42
|
+
};
|
|
@@ -4,7 +4,8 @@ import type { LexiconEntry, Sentence, Token } from "../plugin.ts";
|
|
|
4
4
|
* ですます調にもである調にも数えない文の形。どちらの調子の文書にも同じ形で現れる。
|
|
5
5
|
* - へりくだる動詞の願い(受け継いでいただきたい。ご協力願いたい。): 丁寧さは動詞が持ち、訓示でも論文でもこの形で頼む。
|
|
6
6
|
* - 句点で閉じた常体の問い(対処できているか。どうすればよいのだろうか。): 自分や聞き手に投げる問いで、ですます調の演説や記事にも混ざる。
|
|
7
|
-
* -
|
|
7
|
+
* - 「て」に付けた相手への願い(信じてほしい。): 願いの言い切りは、ですます調の挨拶でもこの形で言う。語は語彙表 neutral-wish。
|
|
8
|
+
* - 言いさし(いつもと違っていたら・・・。これが数万行のコードだったら?): 条件だけ言って文末を言わない文には、文末の調子が無い。
|
|
8
9
|
* Pure。
|
|
9
10
|
*/
|
|
10
11
|
|
|
@@ -14,6 +15,8 @@ const CONDITIONAL = new Set(["たら", "だら"]);
|
|
|
14
15
|
/** 三点リーダー・二点リーダーと、二つ以上の中黒、三つ以上のピリオドで書いた「…」。後ろの句点は除いてから見る。 */
|
|
15
16
|
const ELLIPSIS_ENDINGS = ["…", "‥", "・・", "..."];
|
|
16
17
|
const FULL_STOP = /[。.]$/u;
|
|
18
|
+
const QUESTION_MARK = /[??]$/u;
|
|
19
|
+
const TE = new Set(["て", "で"]);
|
|
17
20
|
|
|
18
21
|
const endsWithEllipsis = (text: string): boolean => {
|
|
19
22
|
const body = text.replace(FULL_STOP, "");
|
|
@@ -38,9 +41,26 @@ const endsAsQuestion = (sentence: Sentence, ending: readonly Token[]): boolean =
|
|
|
38
41
|
return tokens[at + 1]?.surface === QUESTION && CLOSES_QUESTION.has(tokens[at + 2]?.surface ?? "");
|
|
39
42
|
};
|
|
40
43
|
|
|
41
|
-
const trailsOff = (sentence: Sentence, ending: readonly Token[]): boolean =>
|
|
42
|
-
|
|
44
|
+
const trailsOff = (sentence: Sentence, ending: readonly Token[]): boolean => {
|
|
45
|
+
const text = sentence.text.trim();
|
|
46
|
+
return CONDITIONAL.has(ending.at(-1)?.surface ?? "") && (endsWithEllipsis(text) || QUESTION_MARK.test(text));
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** 「て」の直後の、語彙表 neutral-wish の語だけで終わる文末(信じてほしい。)。「ほしいです」「ほしかった」は入らない。 */
|
|
50
|
+
const isWishToOthers = (sentence: Sentence, ending: readonly Token[], wishes: readonly LexiconEntry[]): boolean => {
|
|
51
|
+
const [wish, ...rest] = ending;
|
|
52
|
+
if (wish === undefined || rest.length > 0 || !wishes.some((entry) => entry.pattern === wish.surface)) return false;
|
|
53
|
+
const tokens = sentence.tokens ?? [];
|
|
54
|
+
return TE.has(tokens[tokens.indexOf(wish) - 1]?.surface ?? "");
|
|
55
|
+
};
|
|
43
56
|
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
|
|
57
|
+
/**
|
|
58
|
+
* 常体と読める文末でも調子に数えない文か。ending は sentence-shape の endingTokens、verbs は語彙表 neutral-request、
|
|
59
|
+
* wishes は語彙表 neutral-wish。
|
|
60
|
+
*/
|
|
61
|
+
export const isNeutralPlainShape = (
|
|
62
|
+
sentence: Sentence,
|
|
63
|
+
ending: readonly Token[],
|
|
64
|
+
verbs: readonly LexiconEntry[],
|
|
65
|
+
wishes: readonly LexiconEntry[] = [],
|
|
66
|
+
): boolean => isHumbleWish(ending, verbs) || isWishToOthers(sentence, ending, wishes) || endsAsQuestion(sentence, ending) || trailsOff(sentence, ending);
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { escapeRegExp } from "../orthography.ts";
|
|
2
|
+
import type { LexiconEntry, Paragraph, Sentence, Span } from "../plugin.ts";
|
|
3
|
+
|
|
4
|
+
// Sentences that are not the writer's running prose and so are not compared for register: wording quoted under a label
|
|
5
|
+
// (例:…, Q: …, a paragraph under a lone 用例), the value of a field set out under a marked label line (■ 調査目的\n…) and a contact
|
|
6
|
+
// block (a paragraph with a 〒 or 電話: line). A note on a ※ line and a cell of a table laid out as lines are set apart too, but
|
|
7
|
+
// stay counted: only some of a table's cells take the shape, and dropping those would leave the rest a smaller minority. Pure.
|
|
8
|
+
|
|
9
|
+
/** A label, a number after it (Q1, 例2), then the mark that ends it. */
|
|
10
|
+
const labelPattern = (labels: readonly LexiconEntry[]): RegExp | undefined =>
|
|
11
|
+
labels.length === 0 ? undefined : new RegExp(`^(?:${labels.map((label) => escapeRegExp(label.pattern)).join("|")})[0-90-9-]*[ \\t\\u3000]*[::))]`, "u");
|
|
12
|
+
|
|
13
|
+
/** A paragraph that is nothing but a label (用例, 例:), which sets the next paragraph out as quoted wording. */
|
|
14
|
+
const isLoneLabel = (text: string, labels: readonly LexiconEntry[]): boolean => {
|
|
15
|
+
const words = text.trim().replace(/[::]$/u, "");
|
|
16
|
+
return labels.some((label) => label.pattern === words);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const textOf = (source: string, paragraph: Paragraph): string => source.slice(paragraph.span.start, paragraph.span.end);
|
|
20
|
+
|
|
21
|
+
/** The sentences that open with a quote label, and those of a paragraph right after a lone label. */
|
|
22
|
+
export const labelledQuoteSentences = (paragraphs: readonly Paragraph[], source: string, labels: readonly LexiconEntry[]): Set<Sentence> => {
|
|
23
|
+
const opener = labelPattern(labels);
|
|
24
|
+
if (opener === undefined) return new Set();
|
|
25
|
+
return new Set(
|
|
26
|
+
paragraphs.flatMap((paragraph, index) => {
|
|
27
|
+
const previous = paragraphs[index - 1];
|
|
28
|
+
if (previous !== undefined && isLoneLabel(textOf(source, previous), labels)) return paragraph.sentences;
|
|
29
|
+
return paragraph.sentences.filter((sentence) => opener.test(sentence.text.trim()));
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** A line that opens with a contact mark or label (〒173-8501, 電話:03-…): the mark, then a colon, a space or a digit. */
|
|
35
|
+
const contactLinePattern = (openers: readonly LexiconEntry[]): RegExp | undefined =>
|
|
36
|
+
openers.length === 0
|
|
37
|
+
? undefined
|
|
38
|
+
: new RegExp(`^[ \\t\\u3000]*(?:${openers.map((opener) => escapeRegExp(opener.pattern)).join("|")})[ \\t\\u3000]*[::0-90-9]`, "mu");
|
|
39
|
+
|
|
40
|
+
const BLANK_LINE = /\n[^\S\n]*\n/gu;
|
|
41
|
+
|
|
42
|
+
/** The blocks of lines between blank lines. The document builder may cut a block of short lines into several paragraphs. */
|
|
43
|
+
const blocksOf = (source: string): Span[] => {
|
|
44
|
+
const gaps = [...source.matchAll(BLANK_LINE)].map((match) => ({ start: match.index, end: match.index + match[0].length }));
|
|
45
|
+
return [...gaps, { start: source.length, end: source.length }].map((gap, index) => ({ start: gaps[index - 1]?.end ?? 0, end: gap.start }));
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The sentences of a contact block: lines between blank lines, one of them the page's address or numbers. Its wording
|
|
50
|
+
* (…へのお問い合わせは専用フォームをご利用ください。) is the page's, not the text's.
|
|
51
|
+
*/
|
|
52
|
+
export const contactBlockSentences = (sentences: readonly Sentence[], source: string, openers: readonly LexiconEntry[]): Set<Sentence> => {
|
|
53
|
+
const contactLine = contactLinePattern(openers);
|
|
54
|
+
if (contactLine === undefined || !contactLine.test(source)) return new Set();
|
|
55
|
+
const contacts = blocksOf(source).filter((block) => contactLine.test(source.slice(block.start, block.end)));
|
|
56
|
+
return new Set(sentences.filter((sentence) => contacts.some((block) => sentence.span.start >= block.start && sentence.span.start < block.end)));
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** A marked label line (■ 調査目的): a square or diamond mark, then words that do not end as a sentence. */
|
|
60
|
+
const FIELD_LABEL = /^[ \t\u3000]*[■□◆◇▪▫][^\n。..!?!?]*$/u;
|
|
61
|
+
|
|
62
|
+
/** Where the value starts in a block whose first line is a marked label line, or undefined. */
|
|
63
|
+
const valueStartOf = (source: string, block: Span): number | undefined => {
|
|
64
|
+
const lineEnd = source.indexOf("\n", block.start);
|
|
65
|
+
if (lineEnd === -1 || lineEnd >= block.end || !FIELD_LABEL.test(source.slice(block.start, lineEnd))) return undefined;
|
|
66
|
+
return lineEnd;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The sentences on the lines under a marked label line in the same block. A field's value (■ 調査目的\n…の参考とする。) is written
|
|
71
|
+
* as forms write it, whatever the register of the text around the fields.
|
|
72
|
+
*/
|
|
73
|
+
export const fieldValueSentences = (sentences: readonly Sentence[], source: string): Set<Sentence> => {
|
|
74
|
+
const values = blocksOf(source).flatMap((block) => {
|
|
75
|
+
const start = valueStartOf(source, block);
|
|
76
|
+
return start === undefined ? [] : [{ start, end: block.end }];
|
|
77
|
+
});
|
|
78
|
+
return new Set(sentences.filter((sentence) => values.some((value) => sentence.span.start >= value.start && sentence.span.start < value.end)));
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/** A line that opens with a reference mark (※PDFファイルが開けない…): a note set beside the text. */
|
|
82
|
+
const NOTE_LINE = /^[ \t\u3000]*※/u;
|
|
83
|
+
|
|
84
|
+
const lineStartOf = (source: string, offset: number): number => source.lastIndexOf("\n", offset - 1) + 1;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The sentences on a line that opens with ※. A note (※…の場合はこちらをご覧ください。) is the page's aside to the reader, written in
|
|
88
|
+
* its own register whatever the text around it uses.
|
|
89
|
+
*/
|
|
90
|
+
export const referenceNoteSentences = (sentences: readonly Sentence[], source: string): Set<Sentence> =>
|
|
91
|
+
new Set(sentences.filter((sentence) => NOTE_LINE.test(source.slice(lineStartOf(source, sentence.span.start), sentence.span.end))));
|
|
92
|
+
|
|
93
|
+
/** A line that ends as a sentence does. */
|
|
94
|
+
const CLOSED_LINE = /[。..!?!?][\s」』))]*$/u;
|
|
95
|
+
|
|
96
|
+
/** A heading or a comment line, which a table's cells are not. */
|
|
97
|
+
const MARKUP_LINE = /^[ \t\u3000]*(?:#|<!--)/u;
|
|
98
|
+
|
|
99
|
+
/** A block of lines none of which ends as a sentence: a table's cell or a list of conditions, set out as their own lines. */
|
|
100
|
+
const isFragmentBlock = (source: string, block: Span): boolean => {
|
|
101
|
+
const lines = source
|
|
102
|
+
.slice(block.start, block.end)
|
|
103
|
+
.split("\n")
|
|
104
|
+
.filter((line) => line.trim() !== "");
|
|
105
|
+
return lines.length > 0 && lines.every((line) => !CLOSED_LINE.test(line.trim()) && !MARKUP_LINE.test(line));
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/** How many fragment blocks must stand on each side of a block for it to read as one cell of a table laid out as lines. */
|
|
109
|
+
const CELL_NEIGHBOURS = 2;
|
|
110
|
+
|
|
111
|
+
const isAmongFragments = (source: string, blocks: readonly Span[], index: number): boolean => {
|
|
112
|
+
const sides = [blocks.slice(Math.max(0, index - CELL_NEIGHBOURS), index), blocks.slice(index + 1, index + 1 + CELL_NEIGHBOURS)];
|
|
113
|
+
return sides.every((side) => side.length === CELL_NEIGHBOURS && side.every((block) => isFragmentBlock(source, block)));
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The sentences of a block that stands between runs of fragment blocks: a table copied from a page, its cells one per block
|
|
118
|
+
* (電池の種類 / 受託要件 / 制限なし。ただし…場合がある。). A cell is written as tables write it, whatever the text around the table.
|
|
119
|
+
*/
|
|
120
|
+
export const tableCellSentences = (sentences: readonly Sentence[], source: string): Set<Sentence> => {
|
|
121
|
+
const blocks = blocksOf(source).filter((block) => source.slice(block.start, block.end).trim() !== "");
|
|
122
|
+
const cells = blocks.filter((_, index) => isAmongFragments(source, blocks, index));
|
|
123
|
+
return new Set(sentences.filter((sentence) => cells.some((cell) => sentence.span.start >= cell.start && sentence.span.start < cell.end)));
|
|
124
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { LexiconEntry, Sentence, Token } from "../plugin.ts";
|
|
2
|
+
|
|
3
|
+
// Sentence shapes whose register is a deliberate voice, not a slip: counted, never pointed at. Pure.
|
|
4
|
+
|
|
5
|
+
/** Marks after a sentence's last word: its full stop, an exclamation, closing brackets and spaces. */
|
|
6
|
+
const TRAILING_MARKS: ReadonlySet<string> = new Set(["。", ".", ".", "!", "!", "」", "』", ")", ")", " ", "\t", "\n", " "]);
|
|
7
|
+
|
|
8
|
+
const withoutTrailingMarks = (text: string): string => {
|
|
9
|
+
const chars = [...text];
|
|
10
|
+
return chars.slice(0, chars.findLastIndex((char) => !TRAILING_MARKS.has(char)) + 1).join("");
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** A polite sentence that ends in a greeting said only politely (農業まつり、お疲れ様でした。). Plain remarks greet people so too. */
|
|
14
|
+
export const endsInSetGreeting = (sentence: Sentence, phrases: readonly LexiconEntry[]): boolean => {
|
|
15
|
+
const text = withoutTrailingMarks(sentence.text);
|
|
16
|
+
return phrases.some((phrase) => text.endsWith(phrase.pattern));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const PAST = new Set(["た", "だ"]);
|
|
20
|
+
|
|
21
|
+
const hasParticle = (tokens: readonly Token[], particles: readonly LexiconEntry[]): boolean =>
|
|
22
|
+
tokens.some((token) => token.pos === "ADP" && particles.some((particle) => particle.pattern === token.surface));
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A speaker's declaration (負担軽減を、目に見える形で実現する。二度と繰り返さない。): an object particle, no subject particle, and a
|
|
26
|
+
* verb in the present at the end. particles is the declaration-particle word list already narrowed to the document's genre; without
|
|
27
|
+
* an object particle for the genre the shape does not hold.
|
|
28
|
+
*/
|
|
29
|
+
export const isDeclaration = (sentence: Sentence, ending: readonly Token[], particles: readonly LexiconEntry[]): boolean => {
|
|
30
|
+
const objects = particles.filter((particle) => particle.group === "object");
|
|
31
|
+
const subjects = particles.filter((particle) => particle.group === "subject");
|
|
32
|
+
const tokens = sentence.tokens ?? [];
|
|
33
|
+
const last = ending.at(-1);
|
|
34
|
+
if (objects.length === 0 || last === undefined || PAST.has(last.surface)) return false;
|
|
35
|
+
return ending.some((token) => token.pos === "VERB") && hasParticle(tokens, objects) && !hasParticle(tokens, subjects);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** The most tokens an opener in takeup-opener spans (これ/だけ). */
|
|
39
|
+
const OPENER_TOKENS_MAX = 3;
|
|
40
|
+
|
|
41
|
+
/** The words a sentence opens with, as whole tokens: そんな, then これ, これだけ, これだけで for これ/だけ/で. */
|
|
42
|
+
const openingWords = (tokens: readonly Token[]): Set<string> =>
|
|
43
|
+
new Set(
|
|
44
|
+
tokens.map((_, index) =>
|
|
45
|
+
tokens
|
|
46
|
+
.slice(0, index + 1)
|
|
47
|
+
.map((token) => token.surface)
|
|
48
|
+
.join(""),
|
|
49
|
+
),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
/** The next sentence of the same paragraph opens with words that take up the scene or act this one set (…送れない。そんなときの…, …と書いて送る。これだけで…). */
|
|
53
|
+
export const isTakenUp = (next: Sentence | undefined, between: string, openers: readonly LexiconEntry[]): boolean => {
|
|
54
|
+
const tokens = next?.tokens ?? [];
|
|
55
|
+
if (tokens.length === 0 || between.trim() !== "" || between.includes("\n")) return false;
|
|
56
|
+
const opening = openingWords(tokens.slice(0, OPENER_TOKENS_MAX));
|
|
57
|
+
return openers.some((opener) => opening.has(opener.pattern));
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const EXCLAMATION = /[!!][\s」』))]*$/u;
|
|
61
|
+
|
|
62
|
+
/** A sentence closed by an exclamation mark (わかるかっ!!!): a cry in the writer's voice, said plainly in either register. */
|
|
63
|
+
export const isExclamation = (sentence: Sentence): boolean => EXCLAMATION.test(sentence.text);
|
|
@@ -54,6 +54,21 @@ const EXCLAIMED = /[!?!?]$/u;
|
|
|
54
54
|
export const continuesInto = (sentence: Sentence, next: Sentence | undefined): boolean =>
|
|
55
55
|
EXCLAIMED.test(sentence.text) && next !== undefined && next.span.start === sentence.span.end && next.tokens?.[0]?.pos === "ADP";
|
|
56
56
|
|
|
57
|
+
/** 「!」「?」で切れて、間を置かずに次の文が続くか。 */
|
|
58
|
+
const touches = (sentence: Sentence, next: Sentence | undefined): next is Sentence =>
|
|
59
|
+
EXCLAIMED.test(sentence.text) && next !== undefined && next.span.start === sentence.span.end;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* sentences[index] から「!」「?」で切れた文が間を置かずに並び、その並びが助詞で始まる文へ続くか。
|
|
63
|
+
* 「これはリストか?順序付きか?…持つべきか?などです。」の問いの並びは、全体で一つの文の中に引いた問いで、どの問いも書き手の文末ではない。
|
|
64
|
+
*/
|
|
65
|
+
export const continuesThrough = (sentences: readonly Sentence[], index: number): boolean => {
|
|
66
|
+
const sentence = sentences[index];
|
|
67
|
+
const next = sentences[index + 1];
|
|
68
|
+
if (sentence === undefined || !touches(sentence, next)) return false;
|
|
69
|
+
return continuesInto(sentence, next) || continuesThrough(sentences, index + 1);
|
|
70
|
+
};
|
|
71
|
+
|
|
57
72
|
/** 位置 offset を含む一番外側の箇条書きの始まり。本文なら undefined。入れ子の項目は外側の箇条書きと一緒に見る。 */
|
|
58
73
|
export const outermostList = (offset: number, lists: readonly Span[]): number | undefined =>
|
|
59
74
|
lists
|