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
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// any site's wording. A landmark role (banner, search, contentinfo), a <search> element, a <header> that belongs to the
|
|
3
3
|
// page rather than to a section, and a block named by a convention CMSs share: a breadcrumb trail (breadcrumb, pankuzu,
|
|
4
4
|
// topicpath), a search box, the header or footer block (id or class exactly "header" or "footer"), and the U.S.
|
|
5
|
-
// government's ".gov" banner (usa-banner)
|
|
5
|
+
// government's ".gov" banner (usa-banner), and a help box the page shows on hover (with-hover, tooltip) when it is not
|
|
6
|
+
// prose. A block holding the page's <h1> is never chrome, nor a header holding a
|
|
6
7
|
// heading followed by prose, nor a search block holding prose (a results page). Pure; a regular-expression reading,
|
|
7
8
|
// not a parser.
|
|
8
9
|
import {
|
|
@@ -29,6 +30,9 @@ const REGION_NAME = /^(?:footer|usa-banner)$/iu;
|
|
|
29
30
|
|
|
30
31
|
const HEADER_NAME = /^header$/iu;
|
|
31
32
|
|
|
33
|
+
// Whole tokens only: "has-tooltip" marks the word a tooltip explains, which is the document's own text.
|
|
34
|
+
const HOVER_HELP_NAME = /^(?:with-hover|tooltip)$/iu;
|
|
35
|
+
|
|
32
36
|
// A form's own controls, also when the form element itself is gone and only its labels remain.
|
|
33
37
|
const FORM_CONTROL = /<(?:input|select|textarea|button|label|fieldset)\b/iu;
|
|
34
38
|
|
|
@@ -80,9 +84,12 @@ const isSearchBlock = (range: ElementRange): boolean =>
|
|
|
80
84
|
|
|
81
85
|
const isHeaderBlock = (range: ElementRange): boolean => names(range.openTag).some((name) => HEADER_NAME.test(name)) && !holdsHeadedProse(range);
|
|
82
86
|
|
|
87
|
+
/** Help text the page shows only on hover, such as what a "Document Headings" box contains; a card holding prose is kept. */
|
|
88
|
+
const isHoverHelp = (range: ElementRange): boolean => names(range.openTag).some((name) => HOVER_HELP_NAME.test(name)) && !isProse(range.inner);
|
|
89
|
+
|
|
83
90
|
/** A block the markup names or marks as the site's chrome, unless it holds the page's title. */
|
|
84
91
|
export const isSiteChrome = (range: ElementRange): boolean =>
|
|
85
|
-
!holdsTitle(range) && (hasChromeRole(range.openTag) || hasChromeName(range.openTag) || isSearchBlock(range) || isHeaderBlock(range));
|
|
92
|
+
!holdsTitle(range) && (hasChromeRole(range.openTag) || hasChromeName(range.openTag) || isSearchBlock(range) || isHeaderBlock(range) || isHoverHelp(range));
|
|
86
93
|
|
|
87
94
|
const SECTIONING = ["article", "section", "main", "aside", "nav"];
|
|
88
95
|
|
package/src/law-title.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// The title of a statute cited with its number (愛がん動物用飼料の安全性の確保に関する法律(ペットフード安全法)(平成20年法律第83号)).
|
|
2
|
+
// The statute fixed its title's spelling, so its words are the statute's and not the writer's. Pure.
|
|
3
|
+
|
|
4
|
+
import type { Span } from "./plugin.ts";
|
|
5
|
+
|
|
6
|
+
/** What a cited title starts after: the end of a sentence or a clause, a quotation, a bracket, a space or a line. */
|
|
7
|
+
const TITLE_BOUNDARY = /[、。,.,.「」『』()()\s]/u;
|
|
8
|
+
const CLOSING_BRACKETS = "))";
|
|
9
|
+
const OPENING_BRACKETS = "((";
|
|
10
|
+
|
|
11
|
+
const lastIndexOfAny = (text: string, characters: string, before: number): number =>
|
|
12
|
+
Math.max(...[...characters].map((character) => text.lastIndexOf(character, before)));
|
|
13
|
+
|
|
14
|
+
/** Where the brackets written right before `at` (a short name, (ペットフード安全法)) open; `at` when none closes there. */
|
|
15
|
+
const bracketsStart = (text: string, at: number): number => {
|
|
16
|
+
if (at === 0 || !CLOSING_BRACKETS.includes(text.charAt(at - 1))) return at;
|
|
17
|
+
const opening = lastIndexOfAny(text, OPENING_BRACKETS, at - 2);
|
|
18
|
+
const nested = lastIndexOfAny(text, CLOSING_BRACKETS, at - 2);
|
|
19
|
+
return opening === -1 || nested > opening ? at : bracketsStart(text, opening);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Where the title before a statute's number begins: past the brackets before the number, back to a boundary. */
|
|
23
|
+
const titleStart = (text: string, numberAt: number): number => {
|
|
24
|
+
const units = text.slice(0, bracketsStart(text, numberAt)).split("");
|
|
25
|
+
return units.findLastIndex((unit) => TITLE_BOUNDARY.test(unit)) + 1;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Each statute title in text, with the brackets after it up to its number. numbers: the patterns of a statute's number in
|
|
30
|
+
* brackets ((平成20年法律第83号)), from the language's lexicon.
|
|
31
|
+
*/
|
|
32
|
+
export const lawTitleSpans = (text: string, numbers: readonly RegExp[]): Span[] =>
|
|
33
|
+
numbers.flatMap((number) =>
|
|
34
|
+
[...text.matchAll(new RegExp(number.source, "gu"))].flatMap((match): Span[] => {
|
|
35
|
+
const start = titleStart(text, match.index);
|
|
36
|
+
return start >= bracketsStart(text, match.index) ? [] : [{ start, end: match.index + match[0].length }];
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// A facility or an organisation named by a run of nouns that ends on a word closing a name (こども動物園, 福島復興浜通りセンター).
|
|
2
|
+
// The name keeps the spelling it was given, so its words (こども, 浜通り) are not the writer's spelling of the same words, unless
|
|
3
|
+
// the document writes the name itself two ways (こども家庭庁 and 子ども家庭庁). Pure.
|
|
4
|
+
|
|
5
|
+
import type { Span, Token } from "./plugin.ts";
|
|
6
|
+
|
|
7
|
+
const NAME_PARTS = new Set(["NOUN", "PROPN"]);
|
|
8
|
+
|
|
9
|
+
const isTouching = (left: Token | undefined, right: Token): boolean => left !== undefined && left.span.end === right.span.start;
|
|
10
|
+
|
|
11
|
+
/** The runs of nouns written onto each other. */
|
|
12
|
+
const nounRuns = (tokens: readonly Token[]): Token[][] =>
|
|
13
|
+
tokens.reduce<Token[][]>((runs, token, at) => {
|
|
14
|
+
if (!NAME_PARTS.has(token.pos)) return runs;
|
|
15
|
+
const current = runs.at(-1);
|
|
16
|
+
if (current !== undefined && current.at(-1) === tokens[at - 1] && isTouching(tokens[at - 1], token)) return [...runs.slice(0, -1), [...current, token]];
|
|
17
|
+
return [...runs, [token]];
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
/** Whether the run's last word ends on a name's closing word and a word stands before the closing word. */
|
|
21
|
+
const closesName = (run: readonly Token[], endings: readonly string[]): boolean => {
|
|
22
|
+
const last = run.at(-1)?.surface ?? "";
|
|
23
|
+
const written = run.map((token) => token.surface).join("");
|
|
24
|
+
return endings.some((ending) => last.endsWith(ending) && written.length > ending.length);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** A name in the source: where it lies, how it is written and how it reads. */
|
|
28
|
+
export type NameRun = Span & { readonly written: string; readonly reading: string };
|
|
29
|
+
|
|
30
|
+
/** The names in tokens: noun runs that end on one of endings (園, センター). */
|
|
31
|
+
export const nameEndingRuns = (tokens: readonly Token[], endings: readonly string[]): NameRun[] =>
|
|
32
|
+
nounRuns(tokens)
|
|
33
|
+
.filter((run) => closesName(run, endings))
|
|
34
|
+
.flatMap((run) => {
|
|
35
|
+
const [first, last] = [run[0], run.at(-1)];
|
|
36
|
+
if (first === undefined || last === undefined) return [];
|
|
37
|
+
const written = run.map((token) => token.surface).join("");
|
|
38
|
+
const reading = run.map((token) => token.reading ?? token.surface).join("");
|
|
39
|
+
return [{ start: first.span.start, end: last.span.end, written, reading }];
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/** The names written one way only among names: a reading written two ways (こども家庭庁, 子ども家庭庁) is not a name's own spelling. */
|
|
43
|
+
export const namesWrittenOneWay = (names: readonly NameRun[]): Set<string> => {
|
|
44
|
+
const ways = names.reduce(
|
|
45
|
+
(byReading, name) => byReading.set(name.reading, (byReading.get(name.reading) ?? new Set<string>()).add(name.written)),
|
|
46
|
+
new Map<string, Set<string>>(),
|
|
47
|
+
);
|
|
48
|
+
return new Set(names.filter((name) => ways.get(name.reading)?.size === 1).map((name) => name.written));
|
|
49
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// name-variant: a slip in one word of a title the document repeats ("National Industrial Recover Act" once beside
|
|
2
|
+
// "National Industrial Recovery Act"). A title of a law or a body ends in a head word (Act, Commission) and is made of
|
|
3
|
+
// ordinary words, which the tagger may read as a verb (Recover), so it is read from the capitals, not from the tagger. Pure.
|
|
4
|
+
import { isEndLetterApart } from "./name-end-letter.ts";
|
|
5
|
+
import { isNearWord } from "./name-variants.ts";
|
|
6
|
+
import { escapeRegExp } from "./orthography.ts";
|
|
7
|
+
|
|
8
|
+
export type TitleSlip = { readonly offset: number; readonly surface: string; readonly usual: string };
|
|
9
|
+
|
|
10
|
+
/** A title has two words or more before its head: two-word titles (Trade Act, Power Act) are often two laws. */
|
|
11
|
+
const MIN_TITLE_WORDS = 3;
|
|
12
|
+
const WORD = "\\p{Lu}[\\p{L}'’]*";
|
|
13
|
+
|
|
14
|
+
type Title = { readonly offset: number; readonly words: readonly string[] };
|
|
15
|
+
|
|
16
|
+
/** Runs of capitalised words ending in a head word, and each tail of them of MIN_TITLE_WORDS words or more. */
|
|
17
|
+
const titlesIn = (text: string, heads: readonly string[]): Title[] => {
|
|
18
|
+
if (heads.length === 0) return [];
|
|
19
|
+
const head = heads.map(escapeRegExp).join("|");
|
|
20
|
+
const pattern = new RegExp(`(?<![\\p{L}'’-])(?:${WORD}[ \\t]+){${String(MIN_TITLE_WORDS - 1)},}(?:${head})(?![\\p{L}'’-])`, "gu");
|
|
21
|
+
return [...text.matchAll(pattern)].flatMap((found) => {
|
|
22
|
+
const placed = [...found[0].matchAll(/\S+/gu)].map((word) => ({ word: word[0], offset: (found.index ?? 0) + (word.index ?? 0) }));
|
|
23
|
+
const words = placed.map(({ word }) => word);
|
|
24
|
+
return placed.slice(0, words.length - MIN_TITLE_WORDS + 1).map(({ offset }, index) => ({ offset, words: words.slice(index) }));
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** One word, lower-cased, one letter apart: replaced, swapped or dropped inside, or its last letter dropped or added (not s). */
|
|
29
|
+
const isWordSlip = (word: string, usual: string): boolean => {
|
|
30
|
+
const [left, right] = [word.toLowerCase(), usual.toLowerCase()];
|
|
31
|
+
return isNearWord(left, right) || isEndLetterApart(left, right);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Whether words is usual with one word other than the head slipped. */
|
|
35
|
+
const isSlipOf = (words: readonly string[], usual: readonly string[]): boolean => {
|
|
36
|
+
if (words.length !== usual.length || words.at(-1) !== usual.at(-1)) return false;
|
|
37
|
+
const differing = words.flatMap((word, index) => (word === usual[index] ? [] : [index]));
|
|
38
|
+
const [at] = differing;
|
|
39
|
+
return differing.length === 1 && at !== undefined && isWordSlip(words[at] ?? "", usual[at] ?? "");
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Titles written once that are a repeated title (two times or more) with one word slipped. A title is read at its longest
|
|
44
|
+
* tail that matches: "the National Industrial Recover Act" is compared as "National Industrial Recover Act".
|
|
45
|
+
*/
|
|
46
|
+
export const titleSlipsIn = (text: string, heads: readonly string[]): TitleSlip[] => {
|
|
47
|
+
const titles = titlesIn(text, heads);
|
|
48
|
+
const counts = new Map<string, number>();
|
|
49
|
+
titles.forEach((title) => counts.set(title.words.join(" "), (counts.get(title.words.join(" ")) ?? 0) + 1));
|
|
50
|
+
const repeated = [...counts].flatMap(([surface, count]) => (count >= 2 ? [surface.split(" ")] : []));
|
|
51
|
+
const slips = titles.flatMap((title): TitleSlip[] => {
|
|
52
|
+
const surface = title.words.join(" ");
|
|
53
|
+
const usual = counts.get(surface) === 1 ? repeated.find((words) => isSlipOf(title.words, words)) : undefined;
|
|
54
|
+
return usual === undefined ? [] : [{ offset: title.offset, surface, usual: usual.join(" ") }];
|
|
55
|
+
});
|
|
56
|
+
return slips.filter(
|
|
57
|
+
(slip) => !slips.some((other) => other.offset < slip.offset && other.offset + other.surface.length === slip.offset + slip.surface.length),
|
|
58
|
+
);
|
|
59
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// name-variant: pairs that look like one name written two ways but are two things — a list mark inside two ordinary words,
|
|
2
|
+
// one direction and its inverse, a word and its form with another ending, a word capitalised by its place. Pure.
|
|
3
|
+
|
|
4
|
+
import { escapeRegExp } from "./orthography.ts";
|
|
5
|
+
|
|
6
|
+
const LOWER = /\p{Ll}/u;
|
|
7
|
+
const UPPER = /\p{Lu}/u;
|
|
8
|
+
/** Capitals after a surname prefix: three or more, so a product name ending in an acronym (MacOS) stays a name. */
|
|
9
|
+
const CAPITALS_AFTER = /^\p{Lu}{3,}$/u;
|
|
10
|
+
const WORD_BREAK = /[\s&・-]+/u;
|
|
11
|
+
|
|
12
|
+
/** A word in capitals, or in capitals after a surname prefix from the lexicon name-capitals-prefix (McCAUL, DesJARLAIS). */
|
|
13
|
+
const isCapitalsWord = (word: string, prefixes: readonly string[]): boolean =>
|
|
14
|
+
!LOWER.test(word) || prefixes.some((prefix) => word.startsWith(prefix) && CAPITALS_AFTER.test(word.slice(prefix.length)));
|
|
15
|
+
|
|
16
|
+
/** Whether a name is set in capitals, as a roster sets it (MICHAEL T. McCAUL, SCOTT DesJARLAIS). */
|
|
17
|
+
export const isSetInCapitals = (surface: string, prefixes: readonly string[]): boolean =>
|
|
18
|
+
UPPER.test(surface) && surface.split(WORD_BREAK).every((word) => isCapitalsWord(word, prefixes));
|
|
19
|
+
|
|
20
|
+
const HAN = /\p{Script=Han}/u;
|
|
21
|
+
const LIST_MARK = "・";
|
|
22
|
+
|
|
23
|
+
/** Whether name differs from usual only by ・ placed between two kanji (動物園・水族館): the mark lists two things there. */
|
|
24
|
+
export const isListedPair = (name: string, usual: string): boolean => {
|
|
25
|
+
const [marked, plain] = name.length > usual.length ? [name, usual] : [usual, name];
|
|
26
|
+
const chars = [...marked];
|
|
27
|
+
const between = chars.some((char, index) => char === LIST_MARK && HAN.test(chars[index - 1] ?? "") && HAN.test(chars[index + 1] ?? ""));
|
|
28
|
+
return between && marked.replaceAll(LIST_MARK, "") === plain;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const LETTERS = /^\p{Script=Latin}+$/u;
|
|
32
|
+
|
|
33
|
+
/** The two sides of a direction word. A word in Latin letters stands between spaces (to, not the "to" in Toronto). */
|
|
34
|
+
const sidesOf = (name: string, direction: string): readonly string[] => {
|
|
35
|
+
const word = escapeRegExp(direction);
|
|
36
|
+
const separator = LETTERS.test(direction) ? new RegExp(`\\s+${word}\\s+`, "u") : new RegExp(word, "u");
|
|
37
|
+
return name.split(separator).map((side) => side.trim());
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** Whether name and usual are one pair of words in the two orders around a word of direction (ASCII to binary, binary to ASCII). */
|
|
41
|
+
export const isInverseOrder = (name: string, usual: string, directions: readonly string[]): boolean =>
|
|
42
|
+
directions.some((direction) => {
|
|
43
|
+
const [from, to, ...rest] = sidesOf(name, direction);
|
|
44
|
+
const [usualFrom, usualTo, ...usualRest] = sidesOf(usual, direction);
|
|
45
|
+
return rest.length === 0 && usualRest.length === 0 && from !== "" && to !== "" && from === usualTo && to === usualFrom;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/** An ending a word may take instead of another (Texas, Texan; Romans, Romano): from the lexicon name-word-ending. */
|
|
49
|
+
export type WordEnding = { readonly ending: string; readonly insteadOf: string };
|
|
50
|
+
|
|
51
|
+
const ONE_WORD = /^\p{L}+$/u;
|
|
52
|
+
|
|
53
|
+
/** Whether two one-word names differ only in a last letter that the lexicon calls another form of the word (Texan for Texas). */
|
|
54
|
+
export const isOtherEnding = (name: string, usual: string, endings: readonly WordEnding[]): boolean => {
|
|
55
|
+
if (!ONE_WORD.test(name) || !ONE_WORD.test(usual) || name.length !== usual.length || name.slice(0, -1) !== usual.slice(0, -1)) return false;
|
|
56
|
+
const [nameEnd, usualEnd] = [name.slice(-1).toLowerCase(), usual.slice(-1).toLowerCase()];
|
|
57
|
+
return endings.some(({ ending, insteadOf }) => (ending === nameEnd && insteadOf === usualEnd) || (ending === usualEnd && insteadOf === nameEnd));
|
|
58
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Token } from "./plugin.ts";
|
|
2
|
+
import type { WordUse } from "./name-end-letter.ts";
|
|
3
|
+
import { isOrdinaryToken } from "./name-ordinary-word.ts";
|
|
4
|
+
|
|
5
|
+
// name-variant: how the document uses its Latin words, read from the tagger's tokens. Pure.
|
|
6
|
+
|
|
7
|
+
const LATIN_WORD = /^[A-Za-z]+$/u;
|
|
8
|
+
const LOWERCASE_WORD = /^[a-z]+$/u;
|
|
9
|
+
|
|
10
|
+
/** 文書が小文字で書くか、品詞解析が普通名詞と読む英字の語(文頭の Hurricane)。 */
|
|
11
|
+
const isCommonToken = (token: Token): boolean => LOWERCASE_WORD.test(token.surface) || (token.pos === "NOUN" && LATIN_WORD.test(token.surface));
|
|
12
|
+
|
|
13
|
+
/** 文書での英字の語の使い方。名前と読んだ語のうち小文字で書けばふつうの語と、普通名詞として書いた語。tokens は文書の語。 */
|
|
14
|
+
export const wordUseOf = (tokens: readonly Token[]): WordUse => ({
|
|
15
|
+
ordinary: new Set(tokens.flatMap((token) => (isOrdinaryToken(token) ? [token.surface.toLowerCase()] : []))),
|
|
16
|
+
common: new Set(tokens.flatMap((token) => (isCommonToken(token) ? [token.surface.toLowerCase()] : []))),
|
|
17
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { proseText } from "./measure.ts";
|
|
2
|
+
import type { ProseDocument, Sentence } from "./plugin.ts";
|
|
3
|
+
|
|
4
|
+
/** 書き出しとして読む文の数。最初の文だけでは、一般論のあとに具体が続くのか分からない。 */
|
|
5
|
+
export const OPENING_PROSE_SENTENCES = 3;
|
|
6
|
+
|
|
7
|
+
/** 文として閉じているか。日付・署名・「6 min read」のような冒頭の飾りの行は句点で終わらない。 */
|
|
8
|
+
const TERMINATED = /[。..!?!?…‥][」』】”"'))]*$/u;
|
|
9
|
+
|
|
10
|
+
const DIGIT = /[0-90-9]/u;
|
|
11
|
+
|
|
12
|
+
const isProse = (sentence: Sentence): boolean => sentence.listItem !== true && sentence.embeddedLanguage === undefined;
|
|
13
|
+
|
|
14
|
+
/** 文を含む節の終わり。次の節の文は書き出しではない。 */
|
|
15
|
+
const sectionEnd = (doc: ProseDocument, sentence: Sentence): number =>
|
|
16
|
+
doc.sections.findLast((section) => section.span.start <= sentence.span.start)?.span.end ?? doc.source.length;
|
|
17
|
+
|
|
18
|
+
/** 書き出しの文。句点で閉じた最初の本文の文から、同じ節の、箇条書きでない文を数える。無ければ空。 */
|
|
19
|
+
export const openingProse = (doc: ProseDocument): readonly Sentence[] => {
|
|
20
|
+
const start = doc.sentences.findIndex((sentence) => isProse(sentence) && TERMINATED.test(proseText(sentence)));
|
|
21
|
+
const first = doc.sentences[start];
|
|
22
|
+
if (first === undefined) return [];
|
|
23
|
+
const end = sectionEnd(doc, first);
|
|
24
|
+
return doc.sentences
|
|
25
|
+
.slice(start)
|
|
26
|
+
.filter((sentence) => isProse(sentence) && sentence.span.end <= end)
|
|
27
|
+
.slice(0, OPENING_PROSE_SENTENCES);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** 最初の文が数(日付・件数・金額)を言うなら、書き出しはもう具体から始まっている。 */
|
|
31
|
+
export const opensWithNumber = (opening: readonly Sentence[]): boolean => opening[0] !== undefined && DIGIT.test(proseText(opening[0]));
|
package/src/plugin.ts
CHANGED
|
@@ -247,6 +247,8 @@ export type Section = {
|
|
|
247
247
|
readonly sentences: readonly Sentence[];
|
|
248
248
|
/** この節に含まれる強調(Markdown の ** **)の数。 */
|
|
249
249
|
readonly strongCount: number;
|
|
250
|
+
/** その強調の範囲(`**` を含む、source の上)。buildDocument は必ず入れる。 */
|
|
251
|
+
readonly strongs?: readonly Span[];
|
|
250
252
|
/** 見出し直後の最初の文。heading-echo が見る。 */
|
|
251
253
|
readonly firstSentence: Sentence | undefined;
|
|
252
254
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// A bracket written straight after a closing quotation mark: the quotation's reading or translation (「天子有道」(天子に道有らば)).
|
|
2
|
+
// It renders the quoted text and keeps the quoted text's words and spelling, not the writer's. Pure.
|
|
3
|
+
|
|
4
|
+
import type { Span } from "./plugin.ts";
|
|
5
|
+
|
|
6
|
+
/** A Japanese quotation's closing mark, then a bracket that closes on the same text. */
|
|
7
|
+
const GLOSS_AFTER_QUOTE = /[」』][((][^()()]*[))]/gu;
|
|
8
|
+
|
|
9
|
+
/** Where each bracket written straight after a closing quotation mark lies in text, the brackets included. */
|
|
10
|
+
export const quoteGlossSpans = (text: string): Span[] =>
|
|
11
|
+
[...text.matchAll(GLOSS_AFTER_QUOTE)].map((match) => ({ start: match.index + 1, end: match.index + match[0].length }));
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Words a document takes from elsewhere: a capitalised name (the Interagency Group) and a cited work (a reference list's entry,
|
|
2
|
+
// a citation written as a sentence). They keep the hyphens their owner gave them, unless the document writes the same name two
|
|
3
|
+
// ways (Co-working Space and Coworking Space), and a cited title keeps its ordinary words
|
|
4
|
+
// (factors beside the dataset FACTors). A capital the citing lost (arxiv for arXiv, ai-generated for AI-generated) is still
|
|
5
|
+
// the document's slip and is still compared. Pure.
|
|
6
|
+
|
|
7
|
+
/** Where a word was taken from: a capitalised name, or a cited work. */
|
|
8
|
+
export type Quoted = "name" | "cited";
|
|
9
|
+
|
|
10
|
+
/** A word, and for a word in a capitalised run, the run as written (Twenty-Nine Palms Band of Mission Indians), quoted or not. */
|
|
11
|
+
type QuotedWord = { readonly key: string; readonly spelling: string; readonly quoted?: Quoted | undefined; readonly name?: string | undefined };
|
|
12
|
+
|
|
13
|
+
/** The spelling without its hyphens: two spellings equal this way differ only in hyphenation (Interagency, inter-agency). */
|
|
14
|
+
const closedUp = (spelling: string): string => spelling.replaceAll("-", "");
|
|
15
|
+
|
|
16
|
+
/** A name without its case and hyphens: two names equal this way are one name (Co-working Space, Coworking Space). */
|
|
17
|
+
const nameKeyOf = (name: string): string => closedUp(name.toLowerCase());
|
|
18
|
+
|
|
19
|
+
/** The ways each group of words is written, grouped by keyOf and written as spellingOf gives. */
|
|
20
|
+
const spellingsBy = <Word>(words: readonly Word[], keyOf: (word: Word) => string, spellingOf: (word: Word) => string): Map<string, Set<string>> =>
|
|
21
|
+
words.reduce((groups, word) => groups.set(keyOf(word), (groups.get(keyOf(word)) ?? new Set<string>()).add(spellingOf(word))), new Map<string, Set<string>>());
|
|
22
|
+
|
|
23
|
+
const SMALL_LETTERS_ONLY = /^[\p{Ll}\d-]+$/u;
|
|
24
|
+
|
|
25
|
+
/** A cited word in small letters that the dictionary knows (factors): the title's own word, not a name written small. */
|
|
26
|
+
const isOrdinaryCitedWord = (word: QuotedWord, isWord: (word: string) => boolean): boolean =>
|
|
27
|
+
word.quoted === "cited" && SMALL_LETTERS_ONLY.test(word.spelling) && isWord(word.spelling);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The words without those taken from elsewhere where their way is their own: in a group of one key whose spellings differ only
|
|
31
|
+
* in hyphens, a cited word and a word of a name the document writes one way only; and a cited ordinary word in small letters. spelling is the word with the first letter of each part
|
|
32
|
+
* in small letters; isWord says whether the language's dictionary has a word.
|
|
33
|
+
*/
|
|
34
|
+
export const withoutQuotedSpellings = <Word extends QuotedWord>(words: readonly Word[], isWord: (word: string) => boolean): Word[] => {
|
|
35
|
+
const closed = spellingsBy(
|
|
36
|
+
words,
|
|
37
|
+
(word) => word.key,
|
|
38
|
+
(word) => closedUp(word.spelling),
|
|
39
|
+
);
|
|
40
|
+
const names = spellingsBy(
|
|
41
|
+
words.filter((word) => word.name !== undefined),
|
|
42
|
+
(word) => nameKeyOf(word.name ?? ""),
|
|
43
|
+
(word) => word.name ?? "",
|
|
44
|
+
);
|
|
45
|
+
const differsInHyphensOnly = (word: Word): boolean => closed.get(word.key)?.size === 1;
|
|
46
|
+
const isOwnWay = (word: Word): boolean => word.quoted === "cited" || names.get(nameKeyOf(word.name ?? ""))?.size === 1;
|
|
47
|
+
return words.filter((word) => word.quoted === undefined || !((differsInHyphensOnly(word) && isOwnWay(word)) || isOrdinaryCitedWord(word, isWord)));
|
|
48
|
+
};
|
package/src/render/semantic.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Finding, RuleDefinition } from "../plugin.ts";
|
|
2
|
-
import type
|
|
2
|
+
import { checkAppliesTo, type UserCheck } from "../checks.ts";
|
|
3
3
|
import type { Narrowing } from "../look-at.ts";
|
|
4
4
|
import type { Job as Plan, SemanticResult } from "../run-semantic.ts";
|
|
5
5
|
import { uiLanguageOf, type Texts, type UiLanguage } from "../ui.ts";
|
|
@@ -116,7 +116,7 @@ type Named = { readonly name: string; readonly howToFix: string };
|
|
|
116
116
|
const nameOf = (rule: string, rules: readonly RuleDefinition[], checks: readonly UserCheck[], language: string): Named => {
|
|
117
117
|
const built = rules.find((entry) => entry.id === rule);
|
|
118
118
|
if (built !== undefined) return { name: localized(built.name, language), howToFix: localized(built.how_to_fix, language) };
|
|
119
|
-
const user = checks.find((entry) => entry.id === rule);
|
|
119
|
+
const user = checks.find((entry) => entry.id === rule && checkAppliesTo(entry, language));
|
|
120
120
|
return { name: user?.name ?? rule, howToFix: user?.how_to_fix ?? "" };
|
|
121
121
|
};
|
|
122
122
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { BulletList } from "./plugin.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* rule-of-three の数え方。箇条書きのうち、ちょうど 3 項目のものがどれだけあるか。
|
|
5
|
+
* すぐ下の行が「など」「etc.」で始まる箇条書きは、書いた 3 つより多くあると書き手が言っている。ちょうど 3 項目とは数えない。
|
|
6
|
+
* 箇条書きが少ないと、1 つで割合が大きく動く(4 つなら 25 ポイント)。そのときは全部が 3 項目のときだけ報告する。
|
|
7
|
+
*/
|
|
8
|
+
export type ThreeShare = { readonly count: number; readonly total: number; readonly share: number; readonly first: BulletList };
|
|
9
|
+
|
|
10
|
+
const PERCENT = 100;
|
|
11
|
+
const THREE = 3;
|
|
12
|
+
/** これより少ない箇条書きは測らない。 */
|
|
13
|
+
const MIN_LISTS = 3;
|
|
14
|
+
/** これより少ない箇条書きでは、割合では判断せず、全部が 3 項目のときだけ報告する。 */
|
|
15
|
+
export const MIN_LISTS_FOR_SHARE = 5;
|
|
16
|
+
|
|
17
|
+
const LINE_BREAK = /\r?\n/u;
|
|
18
|
+
|
|
19
|
+
/** `from` より後ろで、最初の空でない行。 */
|
|
20
|
+
const nextWrittenLine = (source: string, from: number): string =>
|
|
21
|
+
source
|
|
22
|
+
.slice(from)
|
|
23
|
+
.split(LINE_BREAK)
|
|
24
|
+
.find((line) => line.trim() !== "")
|
|
25
|
+
?.trim() ?? "";
|
|
26
|
+
|
|
27
|
+
const LATIN_LETTER = /[A-Za-z]/u;
|
|
28
|
+
|
|
29
|
+
/** 英語の語は語の切れ目まで照らす(etc が etcetera の頭に当たらない)。日本語の語は字面どおり。 */
|
|
30
|
+
const startsWithWord = (line: string, word: string): boolean =>
|
|
31
|
+
line.toLowerCase().startsWith(word.toLowerCase()) && !(LATIN_LETTER.test(word.at(-1) ?? "") && LATIN_LETTER.test(line[word.length] ?? ""));
|
|
32
|
+
|
|
33
|
+
/** 箇条書きのすぐ下の行が、並びが続くことを言う語(など、etc.)で始まる。 */
|
|
34
|
+
export const continuesBeyond = (source: string, list: BulletList, openWords: readonly string[]): boolean => {
|
|
35
|
+
const next = nextWrittenLine(source, list.span.end);
|
|
36
|
+
return openWords.some((word) => startsWithWord(next, word));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const isExactlyThree = (source: string, list: BulletList, openWords: readonly string[]): boolean =>
|
|
40
|
+
list.items.length === THREE && !continuesBeyond(source, list, openWords);
|
|
41
|
+
|
|
42
|
+
/** 報告するときの数。報告しないときは undefined。 */
|
|
43
|
+
export const threeShare = (source: string, lists: readonly BulletList[], openWords: readonly string[], limit: number): ThreeShare | undefined => {
|
|
44
|
+
const threes = lists.filter((list) => isExactlyThree(source, list, openWords));
|
|
45
|
+
const first = threes[0];
|
|
46
|
+
if (lists.length < MIN_LISTS || first === undefined) return undefined;
|
|
47
|
+
const share = Math.round((threes.length / lists.length) * PERCENT);
|
|
48
|
+
const reported = lists.length < MIN_LISTS_FOR_SHARE ? threes.length === lists.length : share > limit;
|
|
49
|
+
return reported ? { count: threes.length, total: lists.length, share, first } : undefined;
|
|
50
|
+
};
|
package/src/run-semantic.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { severityOf, type UserCheck } from "./checks.ts";
|
|
1
|
+
import { checkAppliesTo, severityOf, type UserCheck } from "./checks.ts";
|
|
2
2
|
import { ask, type JudgeOptions } from "./judge.ts";
|
|
3
3
|
import { FILTERS, type Candidate } from "./semantic.ts";
|
|
4
4
|
import { narrow, type Narrowing } from "./look-at.ts";
|
|
@@ -71,7 +71,7 @@ const builtInJobs = (doc: ProseDocument, rules: readonly RuleDefinition[], setti
|
|
|
71
71
|
|
|
72
72
|
const userJobs = (doc: ProseDocument, checks: readonly UserCheck[], genre: string): Job[] =>
|
|
73
73
|
checks
|
|
74
|
-
.filter((check) => check.level !== "off" && check.use_for.some((target) => genre.startsWith(target)))
|
|
74
|
+
.filter((check) => check.level !== "off" && check.use_for.some((target) => genre.startsWith(target)) && checkAppliesTo(check, doc.language))
|
|
75
75
|
.map((check) => {
|
|
76
76
|
// look_at の括弧の中を取り出して絞り込む。取り出せなければ文書全体。spec §14。
|
|
77
77
|
const { candidates, narrowing } = narrow(doc, check.look_at, FILTERS["whole-document"] ?? (() => []));
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { Section } from "./plugin.ts";
|
|
2
|
+
|
|
3
|
+
/** One heading level's section lengths, compared with each other. */
|
|
4
|
+
export type LevelLengths = { readonly lengths: readonly number[] };
|
|
5
|
+
|
|
6
|
+
/** A section's own text and every subsection under it, up to the next heading at its depth or shallower. */
|
|
7
|
+
const withSubsections = (sections: readonly Section[], index: number, size: (section: Section) => number): number => {
|
|
8
|
+
const depth = sections[index]?.depth ?? 0;
|
|
9
|
+
const after = sections.slice(index + 1);
|
|
10
|
+
const end = after.findIndex((section) => section.depth <= depth);
|
|
11
|
+
const subsections = end === -1 ? after : after.slice(0, end);
|
|
12
|
+
return [sections[index], ...subsections].reduce((sum, section) => sum + (section === undefined ? 0 : size(section)), 0);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const depthCounts = (sections: readonly Section[]): Map<number, number> =>
|
|
16
|
+
sections.reduce((counts, section) => counts.set(section.depth, (counts.get(section.depth) ?? 0) + 1), new Map<number, number>());
|
|
17
|
+
|
|
18
|
+
/** The shallowest depth that more than one heading shares: the document's top level of sections, below its title. */
|
|
19
|
+
const topDepth = (sections: readonly Section[]): number | undefined =>
|
|
20
|
+
[...depthCounts(sections).entries()]
|
|
21
|
+
.filter(([, count]) => count > 1)
|
|
22
|
+
.map(([depth]) => depth)
|
|
23
|
+
.sort((a, b) => a - b)[0];
|
|
24
|
+
|
|
25
|
+
/** The nearest heading above the section that is shallower than it. */
|
|
26
|
+
const parentOf = (sections: readonly Section[], index: number): Section | undefined => {
|
|
27
|
+
const depth = sections[index]?.depth ?? 0;
|
|
28
|
+
return sections
|
|
29
|
+
.slice(0, index)
|
|
30
|
+
.reverse()
|
|
31
|
+
.find((section) => section.depth < depth);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** A heading that only groups the subsections under it (Pros, Cons): no text of its own. */
|
|
35
|
+
const isGroupHeading = (section: Section | undefined, top: number, size: (section: Section) => number): boolean =>
|
|
36
|
+
section !== undefined && section.depth >= top && size(section) === 0;
|
|
37
|
+
|
|
38
|
+
const topLevel = (sections: readonly Section[], top: number, size: (section: Section) => number): LevelLengths => ({
|
|
39
|
+
lengths: sections
|
|
40
|
+
.flatMap((section, index) => {
|
|
41
|
+
if (section.depth === top) return [withSubsections(sections, index, size)];
|
|
42
|
+
return section.depth < top ? [size(section)] : [];
|
|
43
|
+
})
|
|
44
|
+
.filter((length) => length > 0),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
type Runs = { readonly runs: readonly (readonly number[])[]; readonly open: boolean };
|
|
48
|
+
|
|
49
|
+
/** Subsections at one depth, read in order; a run goes on across group headings and ends at any heading with text. */
|
|
50
|
+
const subsectionRuns = (sections: readonly Section[], depth: number, top: number, size: (section: Section) => number): LevelLengths[] =>
|
|
51
|
+
sections
|
|
52
|
+
.reduce<Runs>(
|
|
53
|
+
(state, section, index) => {
|
|
54
|
+
if (section.depth === depth && isGroupHeading(parentOf(sections, index), top, size)) {
|
|
55
|
+
const length = withSubsections(sections, index, size);
|
|
56
|
+
const runs = state.open ? [...state.runs.slice(0, -1), [...(state.runs.at(-1) ?? []), length]] : [...state.runs, [length]];
|
|
57
|
+
return { runs, open: true };
|
|
58
|
+
}
|
|
59
|
+
if (section.depth > depth || (section.depth < depth && size(section) === 0)) return state;
|
|
60
|
+
return { runs: state.runs, open: false };
|
|
61
|
+
},
|
|
62
|
+
{ runs: [], open: false },
|
|
63
|
+
)
|
|
64
|
+
.runs.map((run) => ({ lengths: run.filter((length) => length > 0) }));
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Section lengths compared with each other. A subsection is part of its section's length, and the title's introduction
|
|
68
|
+
* is compared with the top level. A run of subsections under headings that only group them is also compared on its own:
|
|
69
|
+
* three pros and three cons are six of one size. Under a heading with text of its own, subsections are parts of that
|
|
70
|
+
* section (seven principles of one guideline), and a section with text between two groups ends the run.
|
|
71
|
+
*/
|
|
72
|
+
export const sectionLevels = (sections: readonly Section[], size: (section: Section) => number): LevelLengths[] => {
|
|
73
|
+
const top = topDepth(sections);
|
|
74
|
+
if (top === undefined) return [];
|
|
75
|
+
const deeper = [...depthCounts(sections).keys()].filter((depth) => depth > top).sort((a, b) => a - b);
|
|
76
|
+
return [topLevel(sections, top, size), ...deeper.flatMap((depth) => subsectionRuns(sections, depth, top, size))].filter((level) => level.lengths.length > 0);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const leadingEmphasis = /^[\s*_]+/u;
|
|
80
|
+
|
|
81
|
+
/** The section's first paragraph opens with an interviewer's mark (―― in Japanese, Q: in English): a question turn. */
|
|
82
|
+
const opensWithPrompt = (source: string, section: Section, firstParagraphStart: number | undefined, marks: readonly string[]): boolean => {
|
|
83
|
+
if (firstParagraphStart === undefined || firstParagraphStart >= section.span.end) return false;
|
|
84
|
+
const text = source.slice(firstParagraphStart, section.span.end).replace(leadingEmphasis, "");
|
|
85
|
+
return marks.some((mark) => text.startsWith(mark));
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* An interview: at least half of the headed sections open with the interviewer's question. Each section is one answer,
|
|
90
|
+
* so even lengths are the form, not a template.
|
|
91
|
+
*/
|
|
92
|
+
export const isInterview = (source: string, sections: readonly Section[], paragraphStarts: readonly number[], marks: readonly string[]): boolean => {
|
|
93
|
+
if (marks.length === 0) return false;
|
|
94
|
+
const headed = sections.filter((section) => section.depth > 0 && section.sentences.length > 0);
|
|
95
|
+
const firstStart = (section: Section): number | undefined => paragraphStarts.find((start) => start >= section.span.start && start < section.span.end);
|
|
96
|
+
const turns = headed.filter((section) => opensWithPrompt(source, section, firstStart(section), marks)).length;
|
|
97
|
+
return turns > 0 && turns * 2 >= headed.length;
|
|
98
|
+
};
|
package/src/semantic.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { calendarUnitsOf } from "./calendar-number.ts";
|
|
2
2
|
import { closingAndEarlier, newNumbers } from "./closing-numbers.ts";
|
|
3
|
+
import { openingProse, opensWithNumber } from "./opening-passage.ts";
|
|
4
|
+
import { proseText } from "./measure.ts";
|
|
3
5
|
import type { ProseDocument, Section } from "./plugin.ts";
|
|
4
6
|
|
|
5
7
|
/**
|
|
@@ -68,6 +70,17 @@ export const unsourcedNumber: Filter = (doc) =>
|
|
|
68
70
|
.filter((sentence) => NUMBER.test(sentence.text) && EFFECT.test(sentence.text) && !hasEvidence(sentence.text))
|
|
69
71
|
.map((sentence) => ({ text: sentence.text.trim(), offset: sentence.span.start }));
|
|
70
72
|
|
|
73
|
+
const OPENING_MAX_CHARS = 1000;
|
|
74
|
+
|
|
75
|
+
/** 書き出しの数文だけを渡す。最初の文が数を言うなら、具体から始まっているので問い合わせない。 */
|
|
76
|
+
export const genericOpening: Filter = (doc) => {
|
|
77
|
+
const opening = openingProse(doc);
|
|
78
|
+
const first = opening[0];
|
|
79
|
+
if (first === undefined || opensWithNumber(opening)) return [];
|
|
80
|
+
const text = opening.map(proseText).join(doc.lengthUnit === "char" ? "" : " ");
|
|
81
|
+
return [{ text: text.slice(0, OPENING_MAX_CHARS), offset: first.span.start }];
|
|
82
|
+
};
|
|
83
|
+
|
|
71
84
|
/** 利用者が checks.yaml に書いた検査の既定。絞り込みを書かなければ文書全体。 */
|
|
72
85
|
export const wholeDocument: Filter = (doc) => {
|
|
73
86
|
const body = doc.sentences.map((sentence) => sentence.text.trim()).join("");
|
|
@@ -78,5 +91,6 @@ export const FILTERS: Readonly<Record<string, Filter>> = {
|
|
|
78
91
|
"risk-disclosure": riskDisclosure,
|
|
79
92
|
"empty-conclusion": emptyConclusion,
|
|
80
93
|
"unsourced-number": unsourcedNumber,
|
|
94
|
+
"generic-opening": genericOpening,
|
|
81
95
|
"whole-document": wholeDocument,
|
|
82
96
|
};
|
package/src/sentence-load.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// How much one sentence asks the reader to hold at once: brackets inside brackets, clauses chained one after another, and how
|
|
2
2
|
// far the topic stands from the end where its predicate is. Pure: a sentence's text and tokens come in, numbers go out.
|
|
3
3
|
import type { Token } from "./plugin.ts";
|
|
4
|
-
import { topicClauseEnd } from "./topic-clause.ts";
|
|
4
|
+
import { topicClauseEnd, type TopicClauseWords } from "./topic-clause.ts";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Opening brackets and the mark that closes each. Quotation marks that open and close with the same character are left out, and
|
|
@@ -117,9 +117,11 @@ const firstTopic = (tokens: readonly Token[]): number => {
|
|
|
117
117
|
* undefined when the sentence has no topic. The distance is the reader's wait: everything between has to be held before the
|
|
118
118
|
* topic is said to do anything.
|
|
119
119
|
*/
|
|
120
|
-
export const topicDistance = (tokens: readonly Token[]): number | undefined => {
|
|
120
|
+
export const topicDistance = (tokens: readonly Token[], words?: TopicClauseWords): number | undefined => {
|
|
121
121
|
const topic = firstTopic(tokens);
|
|
122
122
|
const last = tokens.findLastIndex((token) => !TRAILING.has(token.pos));
|
|
123
123
|
if (topic === -1 || last <= topic) return undefined;
|
|
124
|
-
return tokens
|
|
124
|
+
return tokens
|
|
125
|
+
.slice(topic + 1, topicClauseEnd(tokens, topic, last, words) ?? last)
|
|
126
|
+
.reduce((sum, token) => sum + [...token.surface.replace(/\s/gu, "")].length, 0);
|
|
125
127
|
};
|