chaffjs 0.39.0 → 0.41.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 +3 -2
- package/README.md +2 -1
- package/dist/ai-score/human-shares.d.ts.map +1 -1
- package/dist/ai-score/human-shares.js +1 -0
- package/dist/ai-score/human-shares.js.map +1 -1
- package/dist/alternative-words.d.ts +6 -0
- package/dist/alternative-words.d.ts.map +1 -1
- package/dist/alternative-words.js +10 -0
- package/dist/alternative-words.js.map +1 -1
- package/dist/closing-code.d.ts +8 -0
- package/dist/closing-code.d.ts.map +1 -0
- package/dist/closing-code.js +18 -0
- package/dist/closing-code.js.map +1 -0
- package/dist/composite-signals.d.ts +6 -0
- package/dist/composite-signals.d.ts.map +1 -0
- package/dist/composite-signals.js +23 -0
- package/dist/composite-signals.js.map +1 -0
- package/dist/date-format.d.ts +19 -1
- package/dist/date-format.d.ts.map +1 -1
- package/dist/date-format.js +41 -5
- package/dist/date-format.js.map +1 -1
- package/dist/detectors/acronym-context.d.ts +5 -1
- package/dist/detectors/acronym-context.d.ts.map +1 -1
- package/dist/detectors/acronym-context.js +48 -2
- package/dist/detectors/acronym-context.js.map +1 -1
- package/dist/detectors/acronym-mention.d.ts +5 -0
- package/dist/detectors/acronym-mention.d.ts.map +1 -1
- package/dist/detectors/acronym-mention.js +16 -0
- package/dist/detectors/acronym-mention.js.map +1 -1
- package/dist/detectors/acronym-name.d.ts +5 -0
- package/dist/detectors/acronym-name.d.ts.map +1 -1
- package/dist/detectors/acronym-name.js +15 -0
- package/dist/detectors/acronym-name.js.map +1 -1
- package/dist/detectors/acronym-series.d.ts +5 -0
- package/dist/detectors/acronym-series.d.ts.map +1 -1
- package/dist/detectors/acronym-series.js +18 -3
- package/dist/detectors/acronym-series.js.map +1 -1
- package/dist/detectors/ai-phrasing.d.ts.map +1 -1
- package/dist/detectors/ai-phrasing.js +7 -1
- package/dist/detectors/ai-phrasing.js.map +1 -1
- package/dist/detectors/ai-structure.d.ts.map +1 -1
- package/dist/detectors/ai-structure.js +6 -2
- package/dist/detectors/ai-structure.js.map +1 -1
- package/dist/detectors/blank-runs.d.ts +12 -0
- package/dist/detectors/blank-runs.d.ts.map +1 -0
- package/dist/detectors/blank-runs.js +27 -0
- package/dist/detectors/blank-runs.js.map +1 -0
- package/dist/detectors/bold-label.d.ts +3 -1
- package/dist/detectors/bold-label.d.ts.map +1 -1
- package/dist/detectors/bold-label.js +16 -6
- package/dist/detectors/bold-label.js.map +1 -1
- package/dist/detectors/capitalised-term.d.ts.map +1 -1
- package/dist/detectors/capitalised-term.js +28 -9
- package/dist/detectors/capitalised-term.js.map +1 -1
- package/dist/detectors/citation-string.d.ts +6 -0
- package/dist/detectors/citation-string.d.ts.map +1 -1
- package/dist/detectors/citation-string.js +52 -0
- package/dist/detectors/citation-string.js.map +1 -1
- package/dist/detectors/contraction-emphasis.d.ts +3 -0
- package/dist/detectors/contraction-emphasis.d.ts.map +1 -0
- package/dist/detectors/contraction-emphasis.js +24 -0
- package/dist/detectors/contraction-emphasis.js.map +1 -0
- package/dist/detectors/contraction-mention.d.ts +12 -1
- package/dist/detectors/contraction-mention.d.ts.map +1 -1
- package/dist/detectors/contraction-mention.js +39 -6
- package/dist/detectors/contraction-mention.js.map +1 -1
- package/dist/detectors/contraction-mix.d.ts +3 -0
- package/dist/detectors/contraction-mix.d.ts.map +1 -0
- package/dist/detectors/contraction-mix.js +76 -0
- package/dist/detectors/contraction-mix.js.map +1 -0
- package/dist/detectors/contraction-set-apart.d.ts +14 -0
- package/dist/detectors/contraction-set-apart.d.ts.map +1 -0
- package/dist/detectors/contraction-set-apart.js +42 -0
- package/dist/detectors/contraction-set-apart.js.map +1 -0
- package/dist/detectors/date-format.d.ts.map +1 -1
- package/dist/detectors/date-format.js +13 -1
- package/dist/detectors/date-format.js.map +1 -1
- package/dist/detectors/densest-stretch.d.ts +11 -0
- package/dist/detectors/densest-stretch.d.ts.map +1 -0
- package/dist/detectors/densest-stretch.js +14 -0
- package/dist/detectors/densest-stretch.js.map +1 -0
- package/dist/detectors/doubled-word.d.ts.map +1 -1
- package/dist/detectors/doubled-word.js +8 -4
- package/dist/detectors/doubled-word.js.map +1 -1
- package/dist/detectors/duplicate-definition.d.ts +3 -0
- package/dist/detectors/duplicate-definition.d.ts.map +1 -0
- package/dist/detectors/duplicate-definition.js +16 -0
- package/dist/detectors/duplicate-definition.js.map +1 -0
- package/dist/detectors/final-period-captions.d.ts +15 -0
- package/dist/detectors/final-period-captions.d.ts.map +1 -0
- package/dist/detectors/final-period-captions.js +61 -0
- package/dist/detectors/final-period-captions.js.map +1 -0
- package/dist/detectors/fullwidth-alnum.d.ts +3 -0
- package/dist/detectors/fullwidth-alnum.d.ts.map +1 -1
- package/dist/detectors/fullwidth-alnum.js +11 -2
- package/dist/detectors/fullwidth-alnum.js.map +1 -1
- package/dist/detectors/gram-furniture.d.ts +8 -5
- package/dist/detectors/gram-furniture.d.ts.map +1 -1
- package/dist/detectors/gram-furniture.js +23 -13
- package/dist/detectors/gram-furniture.js.map +1 -1
- package/dist/detectors/gram-openers.d.ts +11 -0
- package/dist/detectors/gram-openers.d.ts.map +1 -1
- package/dist/detectors/gram-openers.js +42 -1
- package/dist/detectors/gram-openers.js.map +1 -1
- package/dist/detectors/gram-repetition.d.ts.map +1 -1
- package/dist/detectors/gram-repetition.js +18 -7
- package/dist/detectors/gram-repetition.js.map +1 -1
- package/dist/detectors/heading-sentences.d.ts +10 -0
- package/dist/detectors/heading-sentences.d.ts.map +1 -0
- package/dist/detectors/heading-sentences.js +32 -0
- package/dist/detectors/heading-sentences.js.map +1 -0
- package/dist/detectors/known-correction.d.ts.map +1 -1
- package/dist/detectors/known-correction.js +11 -9
- package/dist/detectors/known-correction.js.map +1 -1
- package/dist/detectors/lexicon.d.ts +2 -3
- package/dist/detectors/lexicon.d.ts.map +1 -1
- package/dist/detectors/lexicon.js +16 -56
- package/dist/detectors/lexicon.js.map +1 -1
- package/dist/detectors/list-lead-in.d.ts +1 -1
- package/dist/detectors/list-lead-in.d.ts.map +1 -1
- package/dist/detectors/list-lead-in.js +42 -11
- package/dist/detectors/list-lead-in.js.map +1 -1
- package/dist/detectors/list-run.d.ts.map +1 -1
- package/dist/detectors/list-run.js +16 -2
- package/dist/detectors/list-run.js.map +1 -1
- package/dist/detectors/missing-final-period.d.ts.map +1 -1
- package/dist/detectors/missing-final-period.js +3 -1
- package/dist/detectors/missing-final-period.js.map +1 -1
- package/dist/detectors/numbering-readings.d.ts +2 -2
- package/dist/detectors/numbering-readings.d.ts.map +1 -1
- package/dist/detectors/numbering-readings.js +7 -0
- package/dist/detectors/numbering-readings.js.map +1 -1
- package/dist/detectors/open-end-anaphor.d.ts +8 -0
- package/dist/detectors/open-end-anaphor.d.ts.map +1 -0
- package/dist/detectors/open-end-anaphor.js +22 -0
- package/dist/detectors/open-end-anaphor.js.map +1 -0
- package/dist/detectors/open-end-lead.d.ts +4 -0
- package/dist/detectors/open-end-lead.d.ts.map +1 -0
- package/dist/detectors/open-end-lead.js +34 -0
- package/dist/detectors/open-end-lead.js.map +1 -0
- package/dist/detectors/open-end-scope.d.ts.map +1 -1
- package/dist/detectors/open-end-scope.js +7 -1
- package/dist/detectors/open-end-scope.js.map +1 -1
- package/dist/detectors/ordinal-run-gaps.d.ts +1 -0
- package/dist/detectors/ordinal-run-gaps.d.ts.map +1 -1
- package/dist/detectors/ordinal-run-gaps.js +1 -1
- package/dist/detectors/ordinal-run-gaps.js.map +1 -1
- package/dist/detectors/orthographic-variant-open.d.ts +4 -2
- package/dist/detectors/orthographic-variant-open.d.ts.map +1 -1
- package/dist/detectors/orthographic-variant-open.js +5 -3
- package/dist/detectors/orthographic-variant-open.js.map +1 -1
- package/dist/detectors/orthography.d.ts.map +1 -1
- package/dist/detectors/orthography.js +14 -5
- package/dist/detectors/orthography.js.map +1 -1
- package/dist/detectors/oxford-comma.d.ts.map +1 -1
- package/dist/detectors/oxford-comma.js +17 -2
- package/dist/detectors/oxford-comma.js.map +1 -1
- package/dist/detectors/phrase-match.d.ts.map +1 -1
- package/dist/detectors/phrase-match.js +3 -2
- package/dist/detectors/phrase-match.js.map +1 -1
- package/dist/detectors/placeholder-text.d.ts.map +1 -1
- package/dist/detectors/placeholder-text.js +14 -2
- package/dist/detectors/placeholder-text.js.map +1 -1
- package/dist/detectors/quote-without-source.d.ts +6 -2
- package/dist/detectors/quote-without-source.d.ts.map +1 -1
- package/dist/detectors/quote-without-source.js +33 -8
- package/dist/detectors/quote-without-source.js.map +1 -1
- package/dist/detectors/quoted-pattern.d.ts +2 -0
- package/dist/detectors/quoted-pattern.d.ts.map +1 -0
- package/dist/detectors/quoted-pattern.js +13 -0
- package/dist/detectors/quoted-pattern.js.map +1 -0
- package/dist/detectors/reference-entry.d.ts +5 -0
- package/dist/detectors/reference-entry.d.ts.map +1 -1
- package/dist/detectors/reference-entry.js +6 -1
- package/dist/detectors/reference-entry.js.map +1 -1
- package/dist/detectors/register-separate-part.d.ts +7 -0
- package/dist/detectors/register-separate-part.d.ts.map +1 -0
- package/dist/detectors/register-separate-part.js +32 -0
- package/dist/detectors/register-separate-part.js.map +1 -0
- package/dist/detectors/registry/contraction-mix.js +1 -1
- package/dist/detectors/registry/contraction-mix.js.map +1 -1
- package/dist/detectors/registry/duplicate-definition.js +1 -1
- package/dist/detectors/registry/duplicate-definition.js.map +1 -1
- package/dist/detectors/relative-pronoun-mix.d.ts.map +1 -1
- package/dist/detectors/relative-pronoun-mix.js +7 -3
- package/dist/detectors/relative-pronoun-mix.js.map +1 -1
- package/dist/detectors/reproduced-text.d.ts +5 -0
- package/dist/detectors/reproduced-text.d.ts.map +1 -0
- package/dist/detectors/reproduced-text.js +19 -0
- package/dist/detectors/reproduced-text.js.map +1 -0
- package/dist/detectors/request-owner.d.ts +2 -1
- package/dist/detectors/request-owner.d.ts.map +1 -1
- package/dist/detectors/request-owner.js +31 -7
- package/dist/detectors/request-owner.js.map +1 -1
- package/dist/detectors/requirement-smell.d.ts.map +1 -1
- package/dist/detectors/requirement-smell.js +16 -5
- package/dist/detectors/requirement-smell.js.map +1 -1
- package/dist/detectors/sentence-counts.d.ts +2 -1
- package/dist/detectors/sentence-counts.d.ts.map +1 -1
- package/dist/detectors/sentence-counts.js +23 -7
- package/dist/detectors/sentence-counts.js.map +1 -1
- package/dist/detectors/sentence-ending.d.ts +1 -0
- package/dist/detectors/sentence-ending.d.ts.map +1 -1
- package/dist/detectors/sentence-ending.js +5 -2
- 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 +13 -3
- package/dist/detectors/sentence-length.js.map +1 -1
- package/dist/detectors/sentence-parts.d.ts +7 -0
- package/dist/detectors/sentence-parts.d.ts.map +1 -1
- package/dist/detectors/sentence-parts.js +11 -1
- package/dist/detectors/sentence-parts.js.map +1 -1
- package/dist/detectors/signals.d.ts.map +1 -1
- package/dist/detectors/signals.js +31 -7
- package/dist/detectors/signals.js.map +1 -1
- package/dist/detectors/spelling-variety.d.ts.map +1 -1
- package/dist/detectors/spelling-variety.js +20 -2
- package/dist/detectors/spelling-variety.js.map +1 -1
- package/dist/detectors/structure-tree.d.ts +2 -1
- package/dist/detectors/structure-tree.d.ts.map +1 -1
- package/dist/detectors/structure-tree.js +2 -7
- package/dist/detectors/structure-tree.js.map +1 -1
- package/dist/detectors/structure.d.ts.map +1 -1
- package/dist/detectors/structure.js +19 -5
- package/dist/detectors/structure.js.map +1 -1
- package/dist/detectors/superlative-context.d.ts +2 -1
- package/dist/detectors/superlative-context.d.ts.map +1 -1
- package/dist/detectors/superlative-context.js +9 -2
- package/dist/detectors/superlative-context.js.map +1 -1
- package/dist/detectors/title-list.d.ts +7 -0
- package/dist/detectors/title-list.d.ts.map +1 -0
- package/dist/detectors/title-list.js +14 -0
- package/dist/detectors/title-list.js.map +1 -0
- package/dist/detectors/token-shape.d.ts.map +1 -1
- package/dist/detectors/token-shape.js +17 -7
- package/dist/detectors/token-shape.js.map +1 -1
- package/dist/detectors/undefined-term.d.ts +5 -0
- package/dist/detectors/undefined-term.d.ts.map +1 -1
- package/dist/detectors/undefined-term.js +22 -1
- package/dist/detectors/undefined-term.js.map +1 -1
- package/dist/detectors/unfilled-placeholder.d.ts.map +1 -1
- package/dist/detectors/unfilled-placeholder.js +15 -1
- package/dist/detectors/unfilled-placeholder.js.map +1 -1
- package/dist/detectors/unknown-word-context.d.ts +9 -0
- package/dist/detectors/unknown-word-context.d.ts.map +1 -1
- package/dist/detectors/unknown-word-context.js +15 -0
- package/dist/detectors/unknown-word-context.js.map +1 -1
- package/dist/detectors/unknown-word.d.ts.map +1 -1
- package/dist/detectors/unknown-word.js +12 -4
- package/dist/detectors/unknown-word.js.map +1 -1
- package/dist/latin-spacing-source.d.ts +12 -0
- package/dist/latin-spacing-source.d.ts.map +1 -0
- package/dist/latin-spacing-source.js +25 -0
- package/dist/latin-spacing-source.js.map +1 -0
- package/dist/name-separator.d.ts.map +1 -1
- package/dist/name-separator.js +4 -1
- package/dist/name-separator.js.map +1 -1
- package/dist/paragraph-length.d.ts +14 -0
- package/dist/paragraph-length.d.ts.map +1 -1
- package/dist/paragraph-length.js +25 -0
- package/dist/paragraph-length.js.map +1 -1
- package/dist/paragraph-runs.d.ts +2 -2
- package/dist/paragraph-runs.d.ts.map +1 -1
- package/dist/paragraph-runs.js +65 -14
- package/dist/paragraph-runs.js.map +1 -1
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/quote-echo.d.ts +6 -0
- package/dist/quote-echo.d.ts.map +1 -0
- package/dist/quote-echo.js +14 -0
- package/dist/quote-echo.js.map +1 -0
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +4 -2
- package/dist/run.js.map +1 -1
- package/dist/semantic.d.ts.map +1 -1
- package/dist/semantic.js +2 -2
- package/dist/semantic.js.map +1 -1
- package/dist/set-phrase-particles.d.ts +4 -0
- package/dist/set-phrase-particles.d.ts.map +1 -0
- package/dist/set-phrase-particles.js +26 -0
- package/dist/set-phrase-particles.js.map +1 -0
- package/dist/structure/alternative-clause.d.ts +7 -0
- package/dist/structure/alternative-clause.d.ts.map +1 -1
- package/dist/structure/alternative-clause.js +23 -8
- package/dist/structure/alternative-clause.js.map +1 -1
- package/dist/structure/cited-document-section.d.ts +2 -0
- package/dist/structure/cited-document-section.d.ts.map +1 -1
- package/dist/structure/cited-document-section.js +8 -0
- package/dist/structure/cited-document-section.js.map +1 -1
- package/dist/structure/issues.d.ts +3 -1
- package/dist/structure/issues.d.ts.map +1 -1
- package/dist/structure/issues.js +12 -8
- package/dist/structure/issues.js.map +1 -1
- package/dist/structure/numbering.d.ts +10 -1
- package/dist/structure/numbering.d.ts.map +1 -1
- package/dist/structure/numbering.js +41 -4
- package/dist/structure/numbering.js.map +1 -1
- package/dist/structure/unread-label.d.ts +13 -0
- package/dist/structure/unread-label.d.ts.map +1 -0
- package/dist/structure/unread-label.js +70 -0
- package/dist/structure/unread-label.js.map +1 -0
- package/dist/structure-shape/faq-sections.d.ts +7 -0
- package/dist/structure-shape/faq-sections.d.ts.map +1 -0
- package/dist/structure-shape/faq-sections.js +14 -0
- package/dist/structure-shape/faq-sections.js.map +1 -0
- package/dist/structure-shape/features.d.ts.map +1 -1
- package/dist/structure-shape/features.js +5 -3
- package/dist/structure-shape/features.js.map +1 -1
- package/dist/topic-clause.d.ts.map +1 -1
- package/dist/topic-clause.js +15 -2
- package/dist/topic-clause.js.map +1 -1
- package/package.json +3 -3
- package/rules/ai-generated-composite.yaml +3 -2
- package/rules/ai-structure.yaml +2 -2
- package/rules/ai-tell.yaml +8 -4
- package/rules/bold-label-list.yaml +6 -6
- package/rules/closing-cliche.yaml +2 -2
- package/rules/colon-lead-in.yaml +2 -2
- package/rules/contraction-consistency.yaml +4 -2
- package/rules/contrast-framing.yaml +3 -3
- package/rules/date-format-consistency.yaml +2 -2
- package/rules/duplicate-definition.yaml +2 -2
- package/rules/fullwidth-alnum-consistency.yaml +2 -2
- package/rules/honesty-marker.yaml +84 -0
- package/rules/latin-spacing.yaml +6 -4
- package/rules/max-paragraph-length.yaml +2 -2
- package/rules/max-sentence-length.yaml +4 -2
- package/rules/missing-final-period.yaml +2 -2
- package/rules/ngram-repetition.yaml +2 -2
- package/rules/no-doubled-joshi.yaml +2 -2
- package/rules/no-mixed-desumasu.yaml +2 -2
- package/rules/nominalization.yaml +1 -1
- package/rules/numbering-gap.yaml +2 -2
- package/rules/one-sentence-paragraph-run.yaml +2 -2
- package/rules/orthographic-variant.yaml +2 -2
- package/rules/oxford-comma-consistency.yaml +2 -2
- package/rules/quote-without-source.yaml +2 -2
- package/rules/request-without-deadline.yaml +2 -2
- package/rules/requirement-smell.yaml +2 -2
- package/rules/spelling-consistency.yaml +4 -4
- package/rules/teki-overuse.yaml +2 -2
- package/rules/topic-predicate-distance.yaml +2 -2
- package/rules/undefined-acronym.yaml +5 -2
- package/rules/undefined-term.yaml +2 -2
- package/rules/unfilled-placeholder.yaml +2 -2
- package/rules/unknown-word.yaml +2 -2
- package/rules/unqualified-superlative.yaml +1 -1
- package/skills/chaff/SKILL.md +2 -1
- package/src/ai-score/human-shares.ts +1 -0
- package/src/alternative-words.ts +15 -0
- package/src/closing-code.ts +21 -0
- package/src/composite-signals.ts +27 -0
- package/src/date-format.ts +54 -7
- package/src/detectors/acronym-context.ts +61 -2
- package/src/detectors/acronym-mention.ts +17 -0
- package/src/detectors/acronym-name.ts +18 -0
- package/src/detectors/acronym-series.ts +22 -3
- package/src/detectors/ai-phrasing.ts +7 -1
- package/src/detectors/ai-structure.ts +6 -2
- package/src/detectors/blank-runs.ts +30 -0
- package/src/detectors/bold-label.ts +22 -6
- package/src/detectors/capitalised-term.ts +36 -9
- package/src/detectors/citation-string.ts +57 -0
- package/src/detectors/contraction-emphasis.ts +46 -0
- package/src/detectors/contraction-mention.ts +52 -6
- package/src/detectors/contraction-mix.ts +104 -0
- package/src/detectors/contraction-set-apart.ts +52 -0
- package/src/detectors/date-format.ts +18 -2
- package/src/detectors/densest-stretch.ts +21 -0
- package/src/detectors/doubled-word.ts +10 -10
- package/src/detectors/duplicate-definition.ts +21 -0
- package/src/detectors/final-period-captions.ts +78 -0
- package/src/detectors/fullwidth-alnum.ts +19 -3
- package/src/detectors/gram-furniture.ts +27 -13
- package/src/detectors/gram-openers.ts +54 -1
- package/src/detectors/gram-repetition.ts +21 -7
- package/src/detectors/heading-sentences.ts +36 -0
- package/src/detectors/known-correction.ts +15 -8
- package/src/detectors/lexicon.ts +18 -62
- package/src/detectors/list-lead-in.ts +60 -11
- package/src/detectors/list-run.ts +16 -2
- package/src/detectors/missing-final-period.ts +9 -1
- package/src/detectors/numbering-readings.ts +10 -2
- package/src/detectors/open-end-anaphor.ts +31 -0
- package/src/detectors/open-end-lead.ts +46 -0
- package/src/detectors/open-end-scope.ts +8 -1
- package/src/detectors/ordinal-run-gaps.ts +1 -1
- package/src/detectors/orthographic-variant-open.ts +8 -3
- package/src/detectors/orthography.ts +20 -7
- package/src/detectors/oxford-comma.ts +17 -2
- package/src/detectors/phrase-match.ts +3 -2
- package/src/detectors/placeholder-text.ts +21 -4
- package/src/detectors/quote-without-source.ts +52 -10
- package/src/detectors/quoted-pattern.ts +14 -0
- package/src/detectors/reference-entry.ts +8 -1
- package/src/detectors/register-separate-part.ts +42 -0
- package/src/detectors/registry/contraction-mix.ts +1 -1
- package/src/detectors/registry/duplicate-definition.ts +1 -1
- package/src/detectors/relative-pronoun-mix.ts +5 -3
- package/src/detectors/reproduced-text.ts +33 -0
- package/src/detectors/request-owner.ts +31 -8
- package/src/detectors/requirement-smell.ts +21 -5
- package/src/detectors/sentence-counts.ts +27 -7
- package/src/detectors/sentence-ending.ts +6 -2
- package/src/detectors/sentence-length.ts +18 -3
- package/src/detectors/sentence-parts.ts +19 -1
- package/src/detectors/signals.ts +35 -7
- package/src/detectors/spelling-variety.ts +26 -2
- package/src/detectors/structure-tree.ts +2 -8
- package/src/detectors/structure.ts +22 -6
- package/src/detectors/superlative-context.ts +10 -2
- package/src/detectors/title-list.ts +21 -0
- package/src/detectors/token-shape.ts +35 -21
- package/src/detectors/undefined-term.ts +26 -1
- package/src/detectors/unfilled-placeholder.ts +20 -2
- package/src/detectors/unknown-word-context.ts +23 -0
- package/src/detectors/unknown-word.ts +23 -4
- package/src/latin-spacing-source.ts +33 -0
- package/src/name-separator.ts +4 -1
- package/src/paragraph-length.ts +31 -0
- package/src/paragraph-runs.ts +71 -13
- package/src/plugin.ts +2 -0
- package/src/quote-echo.ts +18 -0
- package/src/run.ts +4 -2
- package/src/semantic.ts +2 -3
- package/src/set-phrase-particles.ts +32 -0
- package/src/structure/alternative-clause.ts +32 -7
- package/src/structure/cited-document-section.ts +8 -0
- package/src/structure/issues.ts +19 -9
- package/src/structure/numbering.ts +50 -3
- package/src/structure/unread-label.ts +74 -0
- package/src/structure-shape/faq-sections.ts +24 -0
- package/src/structure-shape/features.ts +5 -3
- package/src/topic-clause.ts +16 -2
|
@@ -6,7 +6,7 @@ import { loneNumeralSpans, nameNumeralSpans } from "./name-numeral.ts";
|
|
|
6
6
|
import { placeholderSpans } from "./placeholder.ts";
|
|
7
7
|
import { numeralWordSpans } from "./numeral-word.ts";
|
|
8
8
|
import { seriesLabelSpans } from "./series-label.ts";
|
|
9
|
-
import { nameSpansOf, oneOf } from "./acronym-name.ts";
|
|
9
|
+
import { nameSpansOf, oneOf, postalAddressSpans } from "./acronym-name.ts";
|
|
10
10
|
import { grammarSpans } from "./abnf-grammar.ts";
|
|
11
11
|
import { outlineLabelSpans } from "./outline-label.ts";
|
|
12
12
|
import { referenceListSpans } from "../reference-lists.ts";
|
|
@@ -43,6 +43,10 @@ export type NotationWords = {
|
|
|
43
43
|
readonly dateTimeUnits: readonly string[];
|
|
44
44
|
/** ショートメッセージでキーワードを送る動詞(text GNPCGS to 333111 の text)。 */
|
|
45
45
|
readonly textMessageVerbs?: readonly string[];
|
|
46
|
+
/** 行の頭に大文字で書く接続詞(OR, Skip to …)。略語でもある語(OR は Oregon)なので、行の頭で読点と名前の形か行の終わりが続くときだけ。 */
|
|
47
|
+
readonly openingConjunctions?: readonly string[];
|
|
48
|
+
/** 電話番号の前に置く語(TEL、FAX)。大文字で書いた形だけを、番号のすぐ前でだけ外す。 */
|
|
49
|
+
readonly phoneLabels?: readonly string[];
|
|
46
50
|
};
|
|
47
51
|
|
|
48
52
|
const MINUTES = String.raw`:[0-5]\d`;
|
|
@@ -107,9 +111,45 @@ const placeAndState = (states: string): RegExp =>
|
|
|
107
111
|
const textMessageKeyword = (verbs: readonly string[]): RegExp =>
|
|
108
112
|
new RegExp(String.raw`(?<![\p{L}\p{N}_])${oneOf(verbs)}\s+["“']?[A-Z][A-Z0-9]+["”']?\s+to\s+\d{4,6}(?!\d)`, "giu");
|
|
109
113
|
|
|
114
|
+
/**
|
|
115
|
+
* 行の頭に大文字で書いた接続詞(OR, Skip to the topics …、選択肢の間に一行で置いた OR)。読点の後ろに頭だけ大文字の語が続くか、
|
|
116
|
+
* その行がそこで終わるときだけ。州の並び(OR, WA and ID)や文の途中の OR(the OR staff)は略語のまま数える。
|
|
117
|
+
*/
|
|
118
|
+
const openingConjunction = (words: readonly string[]): RegExp =>
|
|
119
|
+
new RegExp(String.raw`(?<=(?:^|\n)[ \t]*)${oneOf(words)}(?=,[ \t]+\p{Lu}\p{Ll}|[ \t]*(?:\r?\n|$))`, "gu");
|
|
120
|
+
|
|
110
121
|
/** メールアドレス(OASH-RFI@hhs.gov)。@ の前の大文字は宛先の名前で、略語ではない。 */
|
|
111
122
|
const EMAIL_ADDRESS = /(?<![\p{L}\p{N}._%+-])[\p{L}\p{N}._%+-]+@[\p{L}\p{N}-]+(?:\.[\p{L}\p{N}-]+)+/gu;
|
|
112
123
|
|
|
124
|
+
/** SNS のアカウント名(follow us at @USGSA)。@ のすぐ後ろの大文字はアカウントの綴りで、略語ではない。 */
|
|
125
|
+
const SOCIAL_HANDLE = /(?<![\p{L}\p{N}_.%+-])[@@]\w+/gu;
|
|
126
|
+
|
|
127
|
+
/** 『』で囲んだ大文字だけの名前(中期計画『SHIFT』)。日本語の文が計画や作品の名前に付ける括弧で、中身は名前。 */
|
|
128
|
+
const HOOKED_NAME = /『[A-Z][A-Z0-9&.・ -]*』/gu;
|
|
129
|
+
|
|
130
|
+
/** 電話番号の桁。全角の数字と区切り、雛形の伏せ字(03-〇〇〇〇-〇〇〇〇)も数える。 */
|
|
131
|
+
const PHONE_DIGIT = String.raw`[\d0-9〇○]`;
|
|
132
|
+
const PHONE_CHARACTER = String.raw`[\d0-9〇○()()++\-‐-ー.\s]`;
|
|
133
|
+
const MIN_PHONE_DIGITS = 7;
|
|
134
|
+
const DIGIT = new RegExp(PHONE_DIGIT, "gu");
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 電話番号の前の大文字の札(TEL 03-3222-1061、FAX: (202) 555-0100)。札は語彙表 phone-label の語を大文字にした形で、
|
|
138
|
+
* すぐ後ろに 7 桁以上の番号が続くときだけ外す。番号の無い TEL や FAX(the FAX machine)は略語のまま数える。
|
|
139
|
+
*/
|
|
140
|
+
const phoneLabelSpans = (labels: readonly string[]): ((text: string) => Span[]) => {
|
|
141
|
+
const capitals = [...new Set(labels.filter((label) => /^[A-Za-z]{2,6}$/u.test(label)).map((label) => label.toUpperCase()))];
|
|
142
|
+
if (capitals.length === 0) return () => [];
|
|
143
|
+
const pattern = new RegExp(
|
|
144
|
+
String.raw`(?<![\p{L}\p{N}_])${oneOf(capitals)}[ \t]*[.::]?[ \t\u3000]*(?<number>[((++]?${PHONE_DIGIT}${PHONE_CHARACTER}*${PHONE_DIGIT})`,
|
|
145
|
+
"gu",
|
|
146
|
+
);
|
|
147
|
+
return (text) =>
|
|
148
|
+
[...text.matchAll(pattern)]
|
|
149
|
+
.filter((match) => ((match.groups?.["number"] ?? "").match(DIGIT) ?? []).length >= MIN_PHONE_DIGITS)
|
|
150
|
+
.map((match) => ({ start: match.index, end: match.index + match[0].length }));
|
|
151
|
+
};
|
|
152
|
+
|
|
113
153
|
// 強調の記号は空白に置き換えてある(**3:30** PM)ので、部品の間の空白は数を問わない。
|
|
114
154
|
const patternsOf = (words: NotationWords): readonly RegExp[] => [
|
|
115
155
|
new RegExp(String.raw`${CLOCK_12}\s*${oneOf(words.meridiem)}`, "gu"),
|
|
@@ -124,7 +164,10 @@ const patternsOf = (words: NotationWords): readonly RegExp[] => [
|
|
|
124
164
|
capitalHonorific(words.honorifics),
|
|
125
165
|
...titledName(oneOf(words.titles)),
|
|
126
166
|
textMessageKeyword(words.textMessageVerbs ?? []),
|
|
167
|
+
openingConjunction(words.openingConjunctions ?? []),
|
|
127
168
|
EMAIL_ADDRESS,
|
|
169
|
+
SOCIAL_HANDLE,
|
|
170
|
+
HOOKED_NAME,
|
|
128
171
|
];
|
|
129
172
|
|
|
130
173
|
export type NotAcronymSpans = (text: string) => Span[];
|
|
@@ -135,7 +178,9 @@ export type NotAcronymSpans = (text: string) => Span[];
|
|
|
135
178
|
*/
|
|
136
179
|
export const notAcronymSpansOf = (words: NotationWords): NotAcronymSpans => {
|
|
137
180
|
const patterns = patternsOf(words);
|
|
181
|
+
const phoneLabels = phoneLabelSpans(words.phoneLabels ?? []);
|
|
138
182
|
return (text) => [
|
|
183
|
+
...phoneLabels(text),
|
|
139
184
|
...patterns.flatMap((pattern) => [...text.matchAll(pattern)].map((match) => ({ start: match.index, end: match.index + match[0].length }))),
|
|
140
185
|
...citationKeySpans(text),
|
|
141
186
|
...dottedNameSpans(text),
|
|
@@ -165,6 +210,8 @@ export const lexiconNotationOf = (wordsOf: (id: string) => string[]): NotAcronym
|
|
|
165
210
|
titles: wordsOf("name-title"),
|
|
166
211
|
dateTimeUnits: wordsOf("date-time-unit"),
|
|
167
212
|
textMessageVerbs: wordsOf("text-message-verb"),
|
|
213
|
+
openingConjunctions: wordsOf("opening-conjunction"),
|
|
214
|
+
phoneLabels: wordsOf("phone-label"),
|
|
168
215
|
});
|
|
169
216
|
const names = nameSpansOf({
|
|
170
217
|
legalForms: wordsOf("legal-form"),
|
|
@@ -180,11 +227,23 @@ export const lexiconNotationOf = (wordsOf: (id: string) => string[]): NotAcronym
|
|
|
180
227
|
return (text) => [...notation(text), ...names(text)];
|
|
181
228
|
};
|
|
182
229
|
|
|
183
|
-
/**
|
|
230
|
+
/**
|
|
231
|
+
* 午前・午後の点の後ろで文が切れた時刻と時間帯(between 8 a.m. and 8 p.m. ET, Monday …)。文分けは p.m. の点で文を切るので、
|
|
232
|
+
* 時間帯は次の文の頭に来る。文の中で見る組み立てと同じものを、文書の上で見る。強調の記号(**8 p.m.** ET)も挟んでよい。
|
|
233
|
+
*/
|
|
234
|
+
const clockZoneSpans = (source: string, timeZones: readonly string[]): Span[] => {
|
|
235
|
+
if (timeZones.length === 0) return [];
|
|
236
|
+
const pattern = new RegExp(String.raw`${CLOCK_12}\s*${ANY_MERIDIEM}[\s*_]*${oneOf(timeZones)}(?![\p{L}\p{N}_&])`, "gu");
|
|
237
|
+
return [...source.matchAll(pattern)].map((match) => ({ start: match.index, end: match.index + match[0].length }));
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
/** 文書全体で読む、略語として数えない範囲。文献一覧の誌名や会議名、番号の付いた区切りの見出し、ABNF の文法、文に切れ目の入る所在地(Rd. NE)。 */
|
|
184
241
|
export const sourceNotAcronymSpans = (source: string, wordsOf: (id: string) => string[]): Span[] => [
|
|
242
|
+
...postalAddressSpans(source, wordsOf("street-suffix"), wordsOf("us-state-code")),
|
|
185
243
|
...referenceListSpans(source, wordsOf("reference-list-heading")),
|
|
186
244
|
...outlineLabelSpans(source, wordsOf("numbered-division")),
|
|
187
245
|
...grammarSpans(source),
|
|
246
|
+
...clockZoneSpans(source, wordsOf("time-zone")),
|
|
188
247
|
];
|
|
189
248
|
|
|
190
249
|
/**
|
|
@@ -42,3 +42,20 @@ export const caseVariantsIn = (text: string, acronym: string): string[] => {
|
|
|
42
42
|
const variants = [...text.matchAll(written)].map((match) => match[0]);
|
|
43
43
|
return [...new Set(variants)].filter((variant) => variant !== acronym && (variant.match(CAPITAL) ?? []).length >= MIN_CAPITALS);
|
|
44
44
|
};
|
|
45
|
+
|
|
46
|
+
/** A name in capitals that the text also writes as a word is that word set in capitals; short capitals (IT, It) are left alone. */
|
|
47
|
+
const MIN_WORD_LETTERS = 4;
|
|
48
|
+
/** Before a word inside a sentence: a lower-case word, a number, a comma or a slash, not a sentence's or a line's start (Its, It). */
|
|
49
|
+
const INSIDE_SENTENCE = /(?:[\p{Ll}\p{N},;&)][ \t]+|[/(][ \t]*)$/u;
|
|
50
|
+
const LOOK_BEHIND = 4;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Whether the text writes the acronym's letters as a word with only its first letter a capital, inside a sentence (AIRBNB
|
|
54
|
+
* beside "a hotel / Airbnb"). The capitals are then the name written loud, not an acronym with an expansion.
|
|
55
|
+
*/
|
|
56
|
+
export const writtenAsWordIn = (text: string, acronym: string): boolean => {
|
|
57
|
+
if (!/^\p{Lu}+$/u.test(acronym) || Array.from(acronym).length < MIN_WORD_LETTERS) return false;
|
|
58
|
+
const word = `${acronym.slice(0, 1)}${acronym.slice(1).toLowerCase()}`;
|
|
59
|
+
const written = new RegExp(String.raw`(?<![\p{L}\p{N}])${escapeRegExp(word)}(?![\p{L}\p{N}])`, "gu");
|
|
60
|
+
return [...text.matchAll(written)].some((match) => INSIDE_SENTENCE.test(text.slice(Math.max(0, match.index - LOOK_BEHIND), match.index)));
|
|
61
|
+
};
|
|
@@ -134,6 +134,24 @@ export const streetSuffixSpans = (text: string, suffixes: readonly string[]): Sp
|
|
|
134
134
|
? []
|
|
135
135
|
: spansOf(text, new RegExp(String.raw`(?<=${EDGE_BEFORE}\d+[A-Z]?[ \t]+(?:\p{Lu}\p{Ll}[\p{L}'’.-]*[ \t]+){1,3})${oneOf(suffixes)}${EDGE_AFTER}`, "gu"));
|
|
136
136
|
|
|
137
|
+
/** 通りの種類は、語彙表の大文字の書き方と頭だけ大文字の書き方(DR と Dr)、略さずに書いた語(Road)。 */
|
|
138
|
+
const streetTypesOf = (suffixes: readonly string[]): string[] =>
|
|
139
|
+
suffixes.flatMap((suffix) => [suffix, `${suffix.slice(0, 1)}${suffix.slice(1).toLowerCase()}`]);
|
|
140
|
+
|
|
141
|
+
/** 番地から州と郵便番号までの、一行の所在地の長さの上限。 */
|
|
142
|
+
const MAX_ADDRESS_TAIL = 80;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 番地・通り・市・州と郵便番号まで揃った一行の所在地(1600 Clifton Rd. NE, MS H21-8, Atlanta, GA 30329)。その中の大文字
|
|
146
|
+
* (通りの方角 NE、局内の宛先 MS)は所在地の部品で、略語ではない。州と郵便番号で終わらないもの(3 AI CT)は所在地と読まない。
|
|
147
|
+
*/
|
|
148
|
+
export const postalAddressSpans = (text: string, suffixes: readonly string[], states: readonly string[]): Span[] => {
|
|
149
|
+
if (suffixes.length === 0 || states.length === 0) return [];
|
|
150
|
+
const street = String.raw`${EDGE_BEFORE}\d+[A-Z]?[ \t]+(?:\p{Lu}\p{Ll}[\p{L}'’.-]*[ \t]+){1,3}(?:${oneOf(streetTypesOf(suffixes))}\.?|\p{Lu}\p{Ll}+)(?=[ \t,])`;
|
|
151
|
+
const city = String.raw`,[ \t]+\p{Lu}[\p{L}'’.-]*(?:[ \t]+\p{Lu}[\p{L}'’.-]*){0,2},[ \t]+${oneOf(states)}[ \t]+\d{5}(?:-\d{4})?(?!\d)`;
|
|
152
|
+
return spansOf(text, new RegExp(`${street}[^\n]{0,${MAX_ADDRESS_TAIL}}?${city}`, "gu"));
|
|
153
|
+
};
|
|
154
|
+
|
|
137
155
|
/** 大文字で書く決まり文句(NOW, THEREFORE、AND/OR)。 */
|
|
138
156
|
export const capitalPhraseSpans = (text: string, phrases: readonly string[]): Span[] =>
|
|
139
157
|
phrases.length === 0 ? [] : spansOf(text, new RegExp(`${EDGE_BEFORE}${oneOf(phrases)}${EDGE_AFTER}`, "gu"));
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
// Capitals a document uses as the name of a numbered series (RFC 5785 and RFC 7230, BCP 78 and BCP 14, DR 4339 and
|
|
2
2
|
// DR 4340). Pure.
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Capitals, a space, and a whole number that is not part of a decimal, a range or a longer identifier. A letter's number
|
|
6
|
+
* (SR 24-2, CA 21-13) is a two-digit year and the letter's place in it.
|
|
7
|
+
*/
|
|
8
|
+
const NUMBERED = /(?<![\p{L}\p{N}_&.-])(?<series>[A-Z]{2,6}) (?<number>\d\d-\d{1,3}|\d{1,6})(?![\p{L}\p{N}_&]|[.,:/-]\d)/gu;
|
|
9
|
+
|
|
10
|
+
/** Two numbers of one length, the smaller first (10-20), are a range, not a year and a letter's place in it. */
|
|
11
|
+
const isRange = (number: string): boolean => {
|
|
12
|
+
const [low, high] = number.split("-");
|
|
13
|
+
return high !== undefined && low !== undefined && low.length === high.length && Number(low) < Number(high);
|
|
14
|
+
};
|
|
6
15
|
|
|
7
16
|
/** A year after capitals is when something was held or issued (FOSDEM 2024, SKO 2025), not a number in a series. */
|
|
8
17
|
const YEAR = /^(?:19|20)\d\d$/u;
|
|
@@ -20,8 +29,18 @@ export const numberedSeries = (source: string): ReadonlySet<string> => {
|
|
|
20
29
|
[...source.matchAll(NUMBERED)].forEach((match) => {
|
|
21
30
|
const series = match.groups?.["series"] ?? "";
|
|
22
31
|
const number = match.groups?.["number"] ?? "";
|
|
23
|
-
if (YEAR.test(number)) return;
|
|
32
|
+
if (YEAR.test(number) || isRange(number)) return;
|
|
24
33
|
numbers.set(series, (numbers.get(series) ?? new Set<string>()).add(number));
|
|
25
34
|
});
|
|
26
35
|
return new Set([...numbers].filter(([, seen]) => seen.size >= MIN_NUMBERS).map(([series]) => series));
|
|
27
36
|
};
|
|
37
|
+
|
|
38
|
+
/** A heading that opens with a document's number in its series and a colon (### SR 26-8: Updates to …). */
|
|
39
|
+
const NUMBER_HEADING = /^(?<series>[A-Z]{2,6}) \d+(?:-\d+)+:\s/u;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The capitals of a series whose number titles a heading: the page is that numbered letter or notice, and its series is
|
|
43
|
+
* how the reader finds it. A plain number (KPI 1: Revenue) numbers the headings and makes no series.
|
|
44
|
+
*/
|
|
45
|
+
export const headingSeries = (headings: readonly string[]): ReadonlySet<string> =>
|
|
46
|
+
new Set(headings.flatMap((heading) => NUMBER_HEADING.exec(heading)?.groups?.["series"] ?? []));
|
|
@@ -48,6 +48,11 @@ const contrastWordsOf = (doc: ProseDocument, frames: Lexicon): ContrastWords =>
|
|
|
48
48
|
|
|
49
49
|
/** 対比の枠は、一つなら論点の整理。二つ目から数える(割合の上限が、長い文書の二つを落とす)。 */
|
|
50
50
|
const MIN_CONTRASTS = 2;
|
|
51
|
+
/**
|
|
52
|
+
* 枠が 1000 語(日本語は 1000 字)に 1 つ以下なら重なっていない。文の長い文書(有価証券報告書の方針の節)は文の数が少なく、
|
|
53
|
+
* 離れた二つの枠でも割合が上限を超える。生成文は短い文書に二つ三つを詰める。
|
|
54
|
+
*/
|
|
55
|
+
const MIN_CONTRAST_DENSITY = 1;
|
|
51
56
|
const PERCENT = 100;
|
|
52
57
|
|
|
53
58
|
/** 文書の言語の文のうち、対比の枠で書いた文の割合(百分率、小数 1 桁)。文の長さが言語で違っても同じ物差しで比べられる。 */
|
|
@@ -62,7 +67,8 @@ export const contrastFraming: Detector = (doc, options): Finding[] => {
|
|
|
62
67
|
const hits = contrastSentences(doc.sentences, words)
|
|
63
68
|
.filter((sentence) => sentence.embeddedLanguage === undefined)
|
|
64
69
|
.map((sentence) => ({ sentence, matched: (firstIn(sentence, words.frames) ?? firstIn(sentence, words.leads))?.pattern ?? "" }));
|
|
65
|
-
|
|
70
|
+
const length = wordsOf(doc);
|
|
71
|
+
if (hits.length < MIN_CONTRASTS || length < MIN_DOCUMENT_LENGTH[doc.lengthUnit] || hits.length * PER <= length * MIN_CONTRAST_DENSITY) return [];
|
|
66
72
|
const share = contrastShare(doc, hits.length);
|
|
67
73
|
return share <= options.limit ? [] : hits.map((hit) => findingOf(hit, { count: hits.length, share, limit: options.limit }));
|
|
68
74
|
};
|
|
@@ -5,6 +5,8 @@ import { structureOf } from "../structure-shape/of-document.ts";
|
|
|
5
5
|
import { headedSections } from "../structure-shape/features.ts";
|
|
6
6
|
import { headingWords } from "../structure-shape/heading-words.ts";
|
|
7
7
|
import { isTemplateOutline, templateSectionsOf } from "../structure-shape/template-outline.ts";
|
|
8
|
+
import { SAME_SHAPE } from "../ai-score/signals.ts";
|
|
9
|
+
import { SAME_SHAPE_VALUE } from "../composite-signals.ts";
|
|
8
10
|
|
|
9
11
|
/** The template outline's name in the message, beside the structure measures past the human articles. */
|
|
10
12
|
const TEMPLATE_NAME: Texts<string> = { ja: "提案書・報告書の定型の見出し", en: "the textbook proposal or report headings" };
|
|
@@ -27,7 +29,9 @@ export const aiStructure: Detector = (doc, options): Finding[] => {
|
|
|
27
29
|
if (count < options.limit) return [];
|
|
28
30
|
const language = uiLanguageOf(doc.language);
|
|
29
31
|
const text = STRUCTURE_TEXT[language];
|
|
30
|
-
const
|
|
32
|
+
const beyond = scored.placements.filter((placement) => placement.beyond).map((placement) => placement.feature.id);
|
|
33
|
+
const measures = beyond.map((id) => text.features[id].name);
|
|
34
|
+
const sameShape = beyond.flatMap((id) => SAME_SHAPE[id] ?? []);
|
|
31
35
|
const names = template ? [...measures, TEMPLATE_NAME[language]] : measures;
|
|
32
36
|
const heading = (doc.markup?.headings ?? []).find((entry) => entry.depth > 1) ?? doc.markup?.headings[0];
|
|
33
37
|
return [
|
|
@@ -37,7 +41,7 @@ export const aiStructure: Detector = (doc, options): Finding[] => {
|
|
|
37
41
|
line: 0,
|
|
38
42
|
column: 0,
|
|
39
43
|
quote: heading?.text ?? "",
|
|
40
|
-
values: { word: names.join(text.listSeparator), count, limit: options.limit, offset: heading?.start ?? 0 },
|
|
44
|
+
values: { word: names.join(text.listSeparator), count, limit: options.limit, offset: heading?.start ?? 0, [SAME_SHAPE_VALUE]: sameShape.join(",") },
|
|
41
45
|
},
|
|
42
46
|
];
|
|
43
47
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
type Span = { readonly start: number; readonly end: number };
|
|
2
|
+
|
|
3
|
+
/** Between two pieces of one blank: marks, spaces (\s takes in the full-width one) and a number's hyphens, on one line (〇〇区〇〇 〇丁目, 03-〇〇〇〇-〇〇〇〇). */
|
|
4
|
+
const JOINER = /^(?:(?!\n)[\s○〇◯△\-‐-])*$/u;
|
|
5
|
+
const JOINER_CHAR = /(?!\n)[\s○〇◯△\-‐-]/u;
|
|
6
|
+
const MARK = /[○〇◯△]/u;
|
|
7
|
+
|
|
8
|
+
/** How far the joiner characters reach from `from` in one direction, ending on a blank mark (〇〇区〇〇 takes in the last 〇〇). */
|
|
9
|
+
const reach = (text: string, from: number, step: 1 | -1): number => {
|
|
10
|
+
const chars = step === 1 ? Array.from(text.slice(from)) : Array.from(text.slice(0, from)).reverse();
|
|
11
|
+
const run = chars.findIndex((char) => !JOINER_CHAR.test(char));
|
|
12
|
+
const within = (run === -1 ? chars : chars.slice(0, run)).map((char) => char.length);
|
|
13
|
+
const lastMark = (run === -1 ? chars : chars.slice(0, run)).findLastIndex((char) => MARK.test(char));
|
|
14
|
+
return from + step * within.slice(0, lastMark + 1).reduce((sum, length) => sum + length, 0);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The spans as the blanks a reader sees: pieces that overlap, or that only blank marks, spaces and hyphens on one line
|
|
19
|
+
* separate, are one blank, and so are the marks right beside them (〒〇〇〇-〇〇〇〇, 〇丁目〇番〇号 〇〇ビル, 東京都〇〇区〇〇).
|
|
20
|
+
* A filled word between two pieces (株式会社〇〇の〇〇様) keeps them two.
|
|
21
|
+
*/
|
|
22
|
+
export const joinedBlanks = (text: string, spans: readonly Span[]): Span[] =>
|
|
23
|
+
spans
|
|
24
|
+
.toSorted((left, right) => left.start - right.start || left.end - right.end)
|
|
25
|
+
.reduce<Span[]>((joined, span) => {
|
|
26
|
+
const last = joined.at(-1);
|
|
27
|
+
if (last === undefined || (span.start > last.end && !JOINER.test(text.slice(last.end, span.start)))) return [...joined, span];
|
|
28
|
+
return [...joined.slice(0, -1), { start: last.start, end: Math.max(last.end, span.end) }];
|
|
29
|
+
}, [])
|
|
30
|
+
.map((span) => ({ start: reach(text, span.start, -1), end: reach(text, span.end, 1) }));
|
|
@@ -32,16 +32,32 @@ export const opensWithBoldLabel = (item: string): boolean => BOLD_LABEL.test(ite
|
|
|
32
32
|
/** Whether the line holding `offset` is quoted (`> - **a**:…`): someone else's words, not the writer's to fix. */
|
|
33
33
|
export const isQuotedAt = (source: string, offset: number): boolean => source.slice(source.lastIndexOf("\n", offset - 1) + 1, offset).includes(">");
|
|
34
34
|
|
|
35
|
-
/**
|
|
36
|
-
|
|
35
|
+
/** A bold run longer than this is a paragraph in bold, not a lead sentence. */
|
|
36
|
+
const MAX_LEAD_CHARS = 80;
|
|
37
|
+
|
|
38
|
+
/** `**Label.** text`: a bold lead sentence, its stop inside the bold, then the item goes on. The same label, closed by a stop instead of a colon. */
|
|
39
|
+
const BOLD_LEAD = new RegExp(String.raw`^(\*\*|__)(?!\s)((?:(?!\1)[^\n]){1,${MAX_LEAD_CHARS}}?[.!?。!?])\1[ \t]*\S`, "u");
|
|
40
|
+
|
|
41
|
+
/** The lead sentence a list item opens with in bold, its stop left off, or undefined. `item` is the item as written, marker and all. */
|
|
42
|
+
export const boldLeadOf = (item: string): string | undefined =>
|
|
43
|
+
BOLD_LEAD.exec(item.replace(ITEM_MARKER, "").replace(TASK_BOX, ""))?.[2]
|
|
44
|
+
?.trim()
|
|
45
|
+
.replace(/[.!?。!?]$/u, "");
|
|
46
|
+
|
|
47
|
+
const labelOrLeadOf = (item: string): string | undefined => boldLabelOf(item) ?? boldLeadOf(item);
|
|
48
|
+
|
|
49
|
+
const unquotedItems = (doc: ProseDocument, opens: (item: string) => string | undefined): Span[] =>
|
|
37
50
|
doc.lists
|
|
38
51
|
.flatMap((list) => list.itemSpans)
|
|
39
|
-
.filter((span) => !isQuotedAt(doc.source, span.start) &&
|
|
52
|
+
.filter((span) => !isQuotedAt(doc.source, span.start) && opens(doc.source.slice(span.start, span.end)) !== undefined)
|
|
40
53
|
.toSorted((left, right) => left.start - right.start);
|
|
41
54
|
|
|
42
|
-
/**
|
|
55
|
+
/** The list items, in document order, that open with a bold label and are not quoted. */
|
|
56
|
+
export const boldLabelItems = (doc: ProseDocument): Span[] => unquotedItems(doc, boldLabelOf);
|
|
57
|
+
|
|
58
|
+
/** A count, not a density: a person writes one or two labels even in a long article. A bold lead sentence counts as a label. */
|
|
43
59
|
export const boldLabelList: Detector = (doc, options): Finding[] => {
|
|
44
|
-
const items =
|
|
60
|
+
const items = unquotedItems(doc, labelOrLeadOf);
|
|
45
61
|
const first = items[0];
|
|
46
62
|
if (first === undefined || items.length < options.limit) return [];
|
|
47
63
|
const written = doc.source.slice(first.start, first.end);
|
|
@@ -52,7 +68,7 @@ export const boldLabelList: Detector = (doc, options): Finding[] => {
|
|
|
52
68
|
line: 0,
|
|
53
69
|
column: 0,
|
|
54
70
|
quote: (written.split("\n")[0] ?? "").trim(),
|
|
55
|
-
values: { label:
|
|
71
|
+
values: { label: labelOrLeadOf(written) ?? "", count: items.length, limit: options.limit, offset: first.start },
|
|
56
72
|
},
|
|
57
73
|
];
|
|
58
74
|
};
|
|
@@ -73,27 +73,52 @@ const formsOf = (term: string): string[] => {
|
|
|
73
73
|
return lasts.map((form) => (head === "" ? form : `${head} ${form}`));
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
+
/** Whether two tokens are next to each other in a run: at most one character apart, or only spaces apart on one line (Normal Business Hours). */
|
|
77
|
+
type Near = (left: Token, right: Token) => boolean;
|
|
78
|
+
|
|
79
|
+
const nearIn =
|
|
80
|
+
(source: string): Near =>
|
|
81
|
+
(left, right) =>
|
|
82
|
+
adjacent(left, right) || /^[ \t]+$/u.test(source.slice(left.span.end, right.span.start));
|
|
83
|
+
|
|
76
84
|
/** How many tokens the capitalised run starting at index takes: words that continue it, and a joiner or hyphen between two. */
|
|
77
|
-
const runLength = (tokens: readonly Token[], index: number, joiners: ReadonlySet<string
|
|
85
|
+
const runLength = (tokens: readonly Token[], index: number, joiners: ReadonlySet<string>, near: Near): number => {
|
|
78
86
|
const word = tokens[index];
|
|
79
87
|
const next = tokens[index + 1];
|
|
80
88
|
const after = tokens[index + 2];
|
|
81
|
-
if (next === undefined || word === undefined || !
|
|
82
|
-
if (continues(next)) return 1 + runLength(tokens, index + 1, joiners);
|
|
89
|
+
if (next === undefined || word === undefined || !near(word, next)) return 1;
|
|
90
|
+
if (continues(next)) return 1 + runLength(tokens, index + 1, joiners, near);
|
|
83
91
|
const hyphened = next.surface === HYPHEN && touching(word, next) && after !== undefined && touching(next, after);
|
|
84
|
-
const joined = hyphened || (joiners.has(next.surface) && after !== undefined &&
|
|
85
|
-
return joined && continues(after) ? 2 + runLength(tokens, index + 2, joiners) : 1;
|
|
92
|
+
const joined = hyphened || (joiners.has(next.surface) && after !== undefined && near(next, after));
|
|
93
|
+
return joined && continues(after) ? 2 + runLength(tokens, index + 2, joiners, near) : 1;
|
|
86
94
|
};
|
|
87
95
|
|
|
88
96
|
type Run = { readonly start: number; readonly end: number };
|
|
89
97
|
|
|
90
98
|
/** The capitalised runs of one sentence, as [start, end) token indexes; a run never starts inside the one before. */
|
|
91
|
-
const runsOf = (tokens: readonly Token[], joiners: ReadonlySet<string
|
|
99
|
+
const runsOf = (tokens: readonly Token[], joiners: ReadonlySet<string>, near: Near): Run[] =>
|
|
92
100
|
tokens.reduce<Run[]>((runs, token, index) => {
|
|
93
101
|
if ((runs.at(-1)?.end ?? 0) > index || !isCapitalised(token)) return runs;
|
|
94
|
-
return [...runs, { start: index, end: index + runLength(tokens, index, joiners) }];
|
|
102
|
+
return [...runs, { start: index, end: index + runLength(tokens, index, joiners, near) }];
|
|
95
103
|
}, []);
|
|
96
104
|
|
|
105
|
+
/** Marks that glue a word to the next with no space (Borrowmoney.com, Leased/rent): one written form, not a term. */
|
|
106
|
+
const WORD_GLUE = new Set([".", "/"]);
|
|
107
|
+
const LETTER_START = /^\p{L}/u;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The run is not written as a term: its last word is glued to more letters (a web address, a slash pair), or a small
|
|
111
|
+
* word inside it is capitalised too (Maintenance And Deployment), which is capitalising every word, not naming a term.
|
|
112
|
+
*/
|
|
113
|
+
const notWrittenAsTerm = (tokens: readonly Token[], start: number, end: number, small: ReadonlySet<string>): boolean => {
|
|
114
|
+
const last = tokens[end - 1];
|
|
115
|
+
const glue = tokens[end];
|
|
116
|
+
const more = tokens[end + 1];
|
|
117
|
+
const glued = last !== undefined && glue !== undefined && more !== undefined && WORD_GLUE.has(glue.surface) && touching(last, glue) && touching(glue, more);
|
|
118
|
+
if (glued && LETTER_START.test(more.surface)) return true;
|
|
119
|
+
return tokens.slice(start + 1, end - 1).some((token) => isCapitalised(token) && small.has(token.surface.toLowerCase()));
|
|
120
|
+
};
|
|
121
|
+
|
|
97
122
|
const inside = (offset: number, spans: readonly Span[]): boolean => spans.some((span) => span.start <= offset && offset < span.end);
|
|
98
123
|
|
|
99
124
|
/** Used like a defined term: after a lower-case word, and not a modifier of a lower-case noun after it (the Premium plan). */
|
|
@@ -273,18 +298,20 @@ export const capitalisedTerms = (input: CapitalisedInput): CapitalisedTerm[] =>
|
|
|
273
298
|
const defining = input.defined.filter((definition) => definition.bare !== true && DEFINED_FORM.test(definition.term));
|
|
274
299
|
if (defining.length < MIN_DEFINED) return [];
|
|
275
300
|
const joiners = new Set(input.words.joiners);
|
|
301
|
+
const small = new Set([...input.words.joiners, ...input.words.articles].map((word) => word.toLowerCase()));
|
|
302
|
+
const near = nearIn(input.source);
|
|
276
303
|
const isName = nameCues(input, joiners);
|
|
277
304
|
const divisions = new Set(input.words.divisions.flatMap(formsOf));
|
|
278
305
|
const known = new Set([...input.defined.map((definition) => definition.term), ...input.named, ...input.words.names].flatMap(formsOf));
|
|
279
306
|
const isKnown = (term: string): boolean => partsOf(term).some((part) => formsOf(part).some((form) => known.has(form)));
|
|
280
307
|
const uses = input.sentences.flatMap((tokens) =>
|
|
281
|
-
runsOf(tokens, joiners).flatMap(({ start, end }): CapitalisedTerm[] => {
|
|
308
|
+
runsOf(tokens, joiners, near).flatMap(({ start, end }): CapitalisedTerm[] => {
|
|
282
309
|
const first = tokens[start];
|
|
283
310
|
const last = tokens[end - 1];
|
|
284
311
|
if (first === undefined || last === undefined || !placedLikeATerm(tokens[start - 1], tokens[end])) return [];
|
|
285
312
|
if (inside(first.span.start, input.marked) || formsOf(first.surface).some((form) => divisions.has(form))) return [];
|
|
286
313
|
const term = input.source.slice(first.span.start, last.span.end);
|
|
287
|
-
if (isKnown(term) || isName(tokens, start, end, term)) return [];
|
|
314
|
+
if (isKnown(term) || isName(tokens, start, end, term) || notWrittenAsTerm(tokens, start, end, small)) return [];
|
|
288
315
|
return writtenInLowerCase(input.readable, term) ? [] : [{ offset: first.span.start, term }];
|
|
289
316
|
}),
|
|
290
317
|
);
|
|
@@ -34,3 +34,60 @@ export const isCitationString = (text: string, signals: readonly string[]): bool
|
|
|
34
34
|
const cited = afterOpeningSignal(text, signals);
|
|
35
35
|
return cited !== undefined && ((SECTION_SIGN.test(cited) && CITATION_DETAIL.test(cited)) || isTitleSeries(cited));
|
|
36
36
|
};
|
|
37
|
+
|
|
38
|
+
/** A quoted title (“Frequently Asked Questions …,”), cited as it is published. */
|
|
39
|
+
const QUOTED_TITLE = /“[^“”]*”|"[^"]*"/gu;
|
|
40
|
+
const PARENTHESIS = /\(([^()]*)\)/gu;
|
|
41
|
+
const PARENTHESIS_WORD_BREAK = /[\s,]+/u;
|
|
42
|
+
const STARTS_CAPITAL_OR_DIGIT = /^[\p{Lu}\p{N}]/u;
|
|
43
|
+
/** A capitalised word or a number, as the words of a cited name are written (Act, 2001, U.S., Questions:). */
|
|
44
|
+
const NAME_WORD = /^(?:\p{Lu}[\p{L}\p{N}.'’&-]*:?|\p{N}[\p{N}.-]*)$/u;
|
|
45
|
+
/** Short words a name keeps in lower case between its capitalised words (Act of 2001, Tools Required to Intercept). */
|
|
46
|
+
const NAME_JOINERS: ReadonlySet<string> = new Set(["of", "and", "the", "for", "to", "by", "in", "on", "at", "with", "or", "from", "a", "an"]);
|
|
47
|
+
const CAPITALISED = /^\p{Lu}/u;
|
|
48
|
+
/** Fewer capitalised words than this are the writer's own (the CIP Rule), not the name of a cited document or body. */
|
|
49
|
+
const MIN_NAME_WORDS = 3;
|
|
50
|
+
|
|
51
|
+
/** A parenthesis of names, codes and dates only ((FEMA), (DR 4339), (January 18, 2023)): every word in it starts with a capital or a digit. */
|
|
52
|
+
const isNameParenthesis = (inside: string): boolean => {
|
|
53
|
+
const words = inside.split(PARENTHESIS_WORD_BREAK).filter((word) => word !== "");
|
|
54
|
+
return words.length > 0 && words.every((word) => STARTS_CAPITAL_OR_DIGIT.test(word));
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** The words in runs: a run is name words, with joiners only between two of them. */
|
|
58
|
+
type Runs = { readonly runs: string[][]; readonly joiners: string[] };
|
|
59
|
+
|
|
60
|
+
const addWord = (state: Runs, word: string): Runs => {
|
|
61
|
+
const current = state.runs.at(-1);
|
|
62
|
+
if (NAME_WORD.test(word)) {
|
|
63
|
+
if (current !== undefined && current.length > 0 && NAME_WORD.test(current.at(-1) ?? "")) current.push(...state.joiners, word);
|
|
64
|
+
else state.runs.push(...(state.joiners.length > 0 ? [state.joiners.slice()] : []), [word]);
|
|
65
|
+
return { runs: state.runs, joiners: [] };
|
|
66
|
+
}
|
|
67
|
+
if (NAME_JOINERS.has(word) && current !== undefined && NAME_WORD.test(current.at(-1) ?? "")) return { runs: state.runs, joiners: [...state.joiners, word] };
|
|
68
|
+
state.runs.push([...state.joiners, word]);
|
|
69
|
+
return { runs: state.runs, joiners: [] };
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const isCitedName = (run: readonly string[]): boolean => NAME_WORD.test(run[0] ?? "") && run.filter((word) => CAPITALISED.test(word)).length >= MIN_NAME_WORDS;
|
|
73
|
+
|
|
74
|
+
/** The words left once every run of three capitalised words or more (Act of 2001, Hurricane Maria) is taken out. */
|
|
75
|
+
const withoutNames = (cited: string): string => {
|
|
76
|
+
const { runs, joiners } = cited
|
|
77
|
+
.split(/\s+/u)
|
|
78
|
+
.filter((word) => word !== "")
|
|
79
|
+
.reduce<Runs>(addWord, { runs: [], joiners: [] });
|
|
80
|
+
return [...runs.filter((run) => !isCitedName(run)).flat(), ...joiners].join(" ");
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The writer's words in a footnote that opens with a citation signal: the signal and what is left once the cited names
|
|
85
|
+
* (Uniting and Strengthening America … Act of 2001), quoted titles and parentheses of codes and dates are taken out
|
|
86
|
+
* (See also SR letter 05-9, “…,” for interagency guidance on …). Undefined when the text does not open with a signal.
|
|
87
|
+
*/
|
|
88
|
+
export const wordsAroundCitation = (text: string, signals: readonly string[]): string | undefined => {
|
|
89
|
+
const cited = afterOpeningSignal(text, signals);
|
|
90
|
+
if (cited === undefined) return undefined;
|
|
91
|
+
const signal = text.trim().slice(0, text.trim().length - cited.length);
|
|
92
|
+
return `${signal} ${withoutNames(cited.replace(QUOTED_TITLE, " ").replace(PARENTHESIS, (whole, inside: string) => (isNameParenthesis(inside) ? " " : whole)))}`;
|
|
93
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Span } from "../plugin.ts";
|
|
2
|
+
|
|
3
|
+
// A word emphasised alone is stressed: "does **not**" keeps the full form because a contraction cannot carry the stress,
|
|
4
|
+
// so it does not say which form the writer's prose uses. A longer emphasised stretch (a bold label, an italic note) is
|
|
5
|
+
// still the writer's prose and is counted.
|
|
6
|
+
|
|
7
|
+
/** A run of emphasis marks in the source that the prose masks out (chrome), with its place. */
|
|
8
|
+
type Marks = { readonly start: number; readonly end: number };
|
|
9
|
+
|
|
10
|
+
const MARK_RUN = /[*_]+/gu;
|
|
11
|
+
const BLANK_LINE = /\n[ \t]*\n/u;
|
|
12
|
+
const ONE_WORD = /^[\p{L}'’]+$/u;
|
|
13
|
+
|
|
14
|
+
const isMasked = (prose: string, start: number, end: number): boolean => prose.slice(start, end).trim() === "";
|
|
15
|
+
|
|
16
|
+
const isText = (char: string | undefined): boolean => char !== undefined && char.trim() !== "";
|
|
17
|
+
|
|
18
|
+
/** Emphasis marks the parser took as markup: masked in the prose and touching unmasked text on one side. */
|
|
19
|
+
const markRuns = (source: string, prose: string): (Marks & { readonly opens: boolean; readonly closes: boolean })[] =>
|
|
20
|
+
[...source.matchAll(MARK_RUN)].flatMap((match) => {
|
|
21
|
+
const start = match.index;
|
|
22
|
+
const end = start + match[0].length;
|
|
23
|
+
if (!isMasked(prose, start, end)) return [];
|
|
24
|
+
const opens = isText(prose[end]);
|
|
25
|
+
const closes = isText(prose[start - 1]);
|
|
26
|
+
return opens || closes ? [{ start, end, opens, closes }] : [];
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The words emphasised alone in the document, without their marks, in source coordinates. Emphasis does not cross a
|
|
31
|
+
* blank line, so an opening mark left without its closing one in its paragraph covers nothing.
|
|
32
|
+
*/
|
|
33
|
+
type Pairing = { readonly open: Marks | undefined; readonly words: readonly Span[] };
|
|
34
|
+
|
|
35
|
+
const pairRun =
|
|
36
|
+
(source: string) =>
|
|
37
|
+
(state: Pairing, run: Marks & { readonly opens: boolean; readonly closes: boolean }): Pairing => {
|
|
38
|
+
const { open } = state;
|
|
39
|
+
if (open === undefined || !run.closes || BLANK_LINE.test(source.slice(open.end, run.start)))
|
|
40
|
+
return { open: run.opens ? run : undefined, words: state.words };
|
|
41
|
+
const inside = { start: open.end, end: run.start };
|
|
42
|
+
return { open: undefined, words: ONE_WORD.test(source.slice(inside.start, inside.end)) ? [...state.words, inside] : state.words };
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const stressedWords = (source: string, prose: string): readonly Span[] =>
|
|
46
|
+
markRuns(source, prose).reduce<Pairing>(pairRun(source), { open: undefined, words: [] }).words;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { quotedSpans } from "../quoted-span.ts";
|
|
2
2
|
|
|
3
|
+
import type { Span } from "../plugin.ts";
|
|
4
|
+
|
|
3
5
|
// A short phrase in quotation marks ("Do Not Disturb", ‘we’re going to x’) is a name or an example: the form is mentioned,
|
|
4
6
|
// not used, so it says nothing about the document's register. Spoken words carry punctuation ("We don't know," she
|
|
5
|
-
// said) and stay
|
|
7
|
+
// said) and stay, unless they are quoted inside another quotation (a platform's label in a quoted sentence), which is
|
|
8
|
+
// someone else's wording twice over. The text must already have straight apostrophes, so a ’ left in it closes a quotation.
|
|
6
9
|
|
|
7
10
|
const MENTION_MARKS: Readonly<Record<string, string>> = { "“": "”", '"': '"', "‘": "’" };
|
|
8
11
|
/** More words than this in quotation marks is a quoted sentence, not a phrase named as an example. */
|
|
@@ -14,11 +17,54 @@ const isMention = (quoted: string): boolean => {
|
|
|
14
17
|
return PHRASE.test(phrase) && phrase.split(/\s+/u).length <= MAX_MENTION_WORDS;
|
|
15
18
|
};
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
const isNested = (span: Span, spans: readonly Span[]): boolean => spans.some((outer) => outer !== span && outer.start < span.start && span.end < outer.end);
|
|
21
|
+
|
|
22
|
+
/** text with the characters in each span replaced by spaces, every other character at its place. */
|
|
23
|
+
const blankSpans = (text: string, spans: readonly Span[]): string => {
|
|
24
|
+
if (spans.length === 0) return text;
|
|
21
25
|
const units = text.split("");
|
|
22
|
-
|
|
26
|
+
spans.forEach((span) => units.fill(" ", Math.max(0, span.start), Math.min(text.length, span.end)));
|
|
23
27
|
return units.join("");
|
|
24
28
|
};
|
|
29
|
+
|
|
30
|
+
/** The text with each quoted short phrase, and each quotation inside another, blanked out. */
|
|
31
|
+
export const withoutMentions = (text: string): string => {
|
|
32
|
+
const quoted = quotedSpans(text, MENTION_MARKS);
|
|
33
|
+
return blankSpans(
|
|
34
|
+
text,
|
|
35
|
+
quoted.filter((span) => isMention(text.slice(span.start, span.end)) || isNested(span, quoted)),
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The text (which starts at offset in the document) with the document ranges that fall in it blanked out.
|
|
41
|
+
* Ranges are in document coordinates; those outside the text change nothing.
|
|
42
|
+
*/
|
|
43
|
+
export const blankRanges = (text: string, offset: number, ranges: readonly Span[]): string =>
|
|
44
|
+
blankSpans(
|
|
45
|
+
text,
|
|
46
|
+
ranges
|
|
47
|
+
.filter((range) => range.end > offset && range.start < offset + text.length)
|
|
48
|
+
.map((range) => ({ start: range.start - offset, end: range.end - offset })),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
/** A list of search terms or keywords runs to at least this many comma-separated items. */
|
|
52
|
+
const MIN_LIST_TERMS = 8;
|
|
53
|
+
/** A term is a few words; a longer item is a clause of prose. */
|
|
54
|
+
const MAX_TERM_WORDS = 4;
|
|
55
|
+
/** Share of the items that must be terms: a list's label ("(i) Functional errors (k1=50): error") may run longer. */
|
|
56
|
+
const MIN_TERM_SHARE = 0.9;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A sentence that is a list of terms (keywords, search strings: "won't load, wont load, can't login, …") names its
|
|
60
|
+
* contractions as items; it does not write in a register.
|
|
61
|
+
*/
|
|
62
|
+
export const isTermList = (text: string): boolean => {
|
|
63
|
+
const items = text
|
|
64
|
+
.split(/[,;]/u)
|
|
65
|
+
.map((item) => item.trim())
|
|
66
|
+
.filter((item) => item !== "");
|
|
67
|
+
if (items.length < MIN_LIST_TERMS) return false;
|
|
68
|
+
const terms = items.filter((item) => item.split(/\s+/u).length <= MAX_TERM_WORDS);
|
|
69
|
+
return terms.length >= items.length * MIN_TERM_SHARE;
|
|
70
|
+
};
|