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
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Boundary } from "./orthography.ts";
|
|
2
|
+
import { hasGluedNumbers } from "./detectors/sentence-parts.ts";
|
|
3
|
+
|
|
4
|
+
// 英数字の前後の空け方が、書き手のものでない所。文献の記載の行(題名は出版されたとおりに写す)、変換で区切りが消えて
|
|
5
|
+
// 一続きになった表(升の区切りの空白)、行の頭の図表の札と題のあいだ(表 6種類の…)。Pure.
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 文献の記載(SIST の書き方)の行: 著者の後ろに「. 」、その後ろに「. 年,」(佐藤翔. 題. 誌名. 2019, (26), p. 136-147.)。
|
|
9
|
+
* 著者の欄は句点を含まない短い語の並び(佐藤翔, 鈴木一郎)。
|
|
10
|
+
*/
|
|
11
|
+
const ENTRY_AUTHOR = /^[ \t]*[^.。.\n]{1,60}\.\s/u;
|
|
12
|
+
const ENTRY_YEAR = /\.\s(?:1[89]|20)\d{2}[,,]/u;
|
|
13
|
+
|
|
14
|
+
export const isCitedEntryLine = (line: string): boolean => ENTRY_AUTHOR.test(line) && ENTRY_YEAR.test(line);
|
|
15
|
+
|
|
16
|
+
/** at を含む行。 */
|
|
17
|
+
export const lineAt = (text: string, at: number): string => {
|
|
18
|
+
const end = text.indexOf("\n", at);
|
|
19
|
+
return text.slice(text.lastIndexOf("\n", at - 1) + 1, end === -1 ? text.length : end);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 変換で区切りが消えた数の表(桁の区切りの崩れた数の列 8,776,90087,769)を一つの文にしたものの、数の前後の境目。
|
|
24
|
+
* 数の前後の空白は升の区切り。英字の前後は升の中の書き手の言葉なので数える(年表の「合弁会社 SANKO」)。
|
|
25
|
+
*/
|
|
26
|
+
export const isNumberTableBoundary = (text: string, boundary: Boundary): boolean => boundary.kind !== "letter" && hasGluedNumbers(text);
|
|
27
|
+
|
|
28
|
+
/** 行の頭の字下げと箇条書きの印。 */
|
|
29
|
+
const LINE_LEAD = /^[\s\-*+]*/u;
|
|
30
|
+
|
|
31
|
+
/** 境目が、行の頭に図表の札(表、図)だけを書いた後ろの空白か(表 6種類のCCライセンス)。札と題の区切りで、空け方の好みではない。 */
|
|
32
|
+
export const followsCaptionLabel = (text: string, boundary: Boundary, labels: ReadonlySet<string>): boolean =>
|
|
33
|
+
boundary.spaced && labels.has(text.slice(text.lastIndexOf("\n", boundary.offset - 1) + 1, boundary.offset).replace(LINE_LEAD, ""));
|
package/src/name-separator.ts
CHANGED
|
@@ -161,6 +161,9 @@ export const isNameSeparator = (text: string, boundary: Boundary, tokens: readon
|
|
|
161
161
|
if (tokens === undefined || boundary.kind !== "letter" || !boundary.spaced) return false;
|
|
162
162
|
const before = { start: wordStart(text, boundary.offset), end: boundary.offset };
|
|
163
163
|
const after = { start: boundary.offset + 1, end: wordEnd(text, boundary.offset + 1) };
|
|
164
|
+
const line = lineAround(text, boundary.offset);
|
|
164
165
|
const isName = (span: Span): boolean => isOrganizationName(text.slice(span.start, span.end), tokensIn(tokens, span, base), words);
|
|
165
|
-
|
|
166
|
+
// 後ろの名前が空白を含むこともある(初等中等教育局 GIGA StuDX(ギガ スタディーエックス)推進チーム)。行の残りが一つの名前なら区切り。
|
|
167
|
+
const restOfLine = { start: after.start, end: line.end };
|
|
168
|
+
return isName(before) && (isName(after) || isName(restOfLine)) && isNameLine(tokensIn(tokens, line, base));
|
|
166
169
|
};
|
package/src/paragraph-length.ts
CHANGED
|
@@ -7,3 +7,34 @@ export const isTooLongParagraph = (sentenceSizes: readonly number[], limit: numb
|
|
|
7
7
|
const size = sentenceSizes.reduce((sum, sentence) => sum + sentence, 0);
|
|
8
8
|
return sentenceSizes.length > limit && (fullSentence === undefined || size > limit * fullSentence);
|
|
9
9
|
};
|
|
10
|
+
|
|
11
|
+
type Spanned = { readonly span: { readonly start: number; readonly end: number } };
|
|
12
|
+
|
|
13
|
+
/** 【】の見出しや段落番号だけの行(【0001】、【従来の技術】)。特許の明細書や公文書を写すと改行一つでつながり、Markdown では一つの段落になる。 */
|
|
14
|
+
const LABEL_LINE = /^[ \t\u3000]*【[^】\n]+】[ \t\u3000]*$/gmu;
|
|
15
|
+
|
|
16
|
+
/** 段落の頭の、番号付きの【】の見出しに、改行なしで本文が続く(2【沿革】1893年…)。写すときに改行が落ち、どこが段落の切れ目か分からない。 */
|
|
17
|
+
const FUSED_HEADING = /^[ \t\u3000]*[0-90-9①-⑳]{1,3}【[^】\n]+】[ \t\u3000]*[^\s]/u;
|
|
18
|
+
|
|
19
|
+
/** 段落の本文が、番号付きの見出しから改行なしで始まる。段落の切れ目が失われた文書で、長さを測っても書き手の段落ではない。 */
|
|
20
|
+
export const opensWithFusedHeading = (text: string): boolean => FUSED_HEADING.test(text);
|
|
21
|
+
|
|
22
|
+
/** 【】のラベルだけの文(【0001】【技術分野】)。見出しで、文に数えない。 */
|
|
23
|
+
const LABELS_ONLY = /^\s*(?:【[^】\n]+】\s*)+$/u;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 段落の文を、【】の見出しや段落番号だけの行で割った組。読み手にとってはその行が段落の切れ目で、ラベルだけの文は数えない。
|
|
27
|
+
* text は段落の文字列で、start はその文書の中の位置(文の span と同じ座標)。割る行が無ければ段落の文がそのまま一つの組。
|
|
28
|
+
*/
|
|
29
|
+
export const labelledBlocks = <T extends Spanned>(text: string, start: number, sentences: readonly T[]): T[][] => {
|
|
30
|
+
const cuts = [...text.matchAll(LABEL_LINE)].map((match) => start + match.index);
|
|
31
|
+
if (cuts.length === 0) return sentences.length === 0 ? [] : [[...sentences]];
|
|
32
|
+
const blocks = new Map<number, T[]>();
|
|
33
|
+
sentences
|
|
34
|
+
.filter((sentence) => !LABELS_ONLY.test(text.slice(sentence.span.start - start, sentence.span.end - start)))
|
|
35
|
+
.forEach((sentence) => {
|
|
36
|
+
const block = cuts.filter((cut) => cut < sentence.span.end).length;
|
|
37
|
+
blocks.set(block, [...(blocks.get(block) ?? []), sentence]);
|
|
38
|
+
});
|
|
39
|
+
return [...blocks.values()];
|
|
40
|
+
};
|
package/src/paragraph-runs.ts
CHANGED
|
@@ -50,25 +50,83 @@ export const isReferenceEntry = (source: string, paragraph: Paragraph, reference
|
|
|
50
50
|
REFERENCE_LABEL.test(source.slice(paragraph.span.start, paragraph.span.end)) ||
|
|
51
51
|
referenceLists.some((list) => list.start <= paragraph.span.start && paragraph.span.start < list.end);
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* An enumerator a paragraph opens with: (1), (2), (iii), (a), ① . Paragraphs numbered this way are the items of a list
|
|
55
|
+
* written as plain text, as a glossary's terms or an appendix's categories are.
|
|
56
|
+
*/
|
|
57
|
+
const BRACKETED_LABEL = /^[ \t\u3000]*[((]([^))\s]{1,6})[))]/u;
|
|
58
|
+
const CIRCLED_NUMBER = /^[ \t\u3000]*[①-⑳]/u;
|
|
59
|
+
const ENUMERATOR_LABEL = /^(?:\d{1,3}|[0-9]{1,3}|[ivxlc]{1,6}|[IVXLC]{1,6}|[a-zA-Z]|[一二三四五六七八九十]{1,3})$/u;
|
|
60
|
+
|
|
61
|
+
const opensWithEnumerator = (source: string, paragraph: Paragraph): boolean => {
|
|
62
|
+
const text = source.slice(paragraph.span.start, paragraph.span.end);
|
|
63
|
+
return CIRCLED_NUMBER.test(text) || ENUMERATOR_LABEL.test(BRACKETED_LABEL.exec(text)?.[1] ?? "");
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** A lead-in's last mark: the paragraph announces what follows (Follow these steps:, 次のとおりです:). */
|
|
67
|
+
const LEAD_IN_END = /[::]$/u;
|
|
68
|
+
|
|
69
|
+
/** How many sentences an item under a lead-in may hold before the paragraphs read as prose again. */
|
|
70
|
+
const MAX_ITEM_SENTENCES = 2;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The paragraphs that follow a lead-in ending with a colon, adjacent to it and to one another, each short enough to be an item.
|
|
74
|
+
* A list converted from HTML often loses its markup and keeps only its lead-in; its items are not prose split into paragraphs.
|
|
75
|
+
*/
|
|
76
|
+
const underLeadIn = (source: string, paragraphs: readonly Paragraph[]): ReadonlySet<Paragraph> => {
|
|
77
|
+
const items = new Set<Paragraph>();
|
|
78
|
+
paragraphs.reduce<Paragraph | undefined>((open, paragraph, at) => {
|
|
79
|
+
const previous = paragraphs[at - 1];
|
|
80
|
+
const continues =
|
|
81
|
+
open !== undefined && previous !== undefined && isAdjacent(source, previous, paragraph) && paragraph.sentences.length <= MAX_ITEM_SENTENCES;
|
|
82
|
+
if (continues) items.add(paragraph);
|
|
83
|
+
if (LEAD_IN_END.test(source.slice(paragraph.span.start, paragraph.span.end).trim())) return paragraph;
|
|
84
|
+
return continues ? open : undefined;
|
|
85
|
+
}, undefined);
|
|
86
|
+
return items;
|
|
87
|
+
};
|
|
88
|
+
|
|
53
89
|
/** Whether a paragraph can be counted in a run: one sentence, ending as a sentence, not an item or a reference entry. */
|
|
54
|
-
const counts = (source: string, paragraph: Paragraph, referenceLists: readonly Span[]): boolean =>
|
|
90
|
+
const counts = (source: string, paragraph: Paragraph, referenceLists: readonly Span[], leadInItems: ReadonlySet<Paragraph>): boolean =>
|
|
55
91
|
paragraph.sentences.length === 1 &&
|
|
56
92
|
endsAsSentence(source, paragraph) &&
|
|
57
93
|
!opensAsItem(source, paragraph) &&
|
|
94
|
+
!opensWithEnumerator(source, paragraph) &&
|
|
95
|
+
!leadInItems.has(paragraph) &&
|
|
58
96
|
!isReferenceEntry(source, paragraph, referenceLists);
|
|
59
97
|
|
|
98
|
+
/** How many opening words every paragraph of a run must share for the run to be a list of parallel entries. */
|
|
99
|
+
const PARALLEL_WORDS = 3;
|
|
100
|
+
|
|
101
|
+
const openingOf = (source: string, paragraph: Paragraph): string =>
|
|
102
|
+
source.slice(paragraph.span.start, paragraph.span.end).trim().split(/\s+/u).slice(0, PARALLEL_WORDS).join(" ").toLowerCase();
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Whether every paragraph of a run opens with the same words (The government's 'How to … guide, one per guide): entries set
|
|
106
|
+
* out in one frame, a list in all but markup. Text written without spaces between words never shares a whole opening.
|
|
107
|
+
*/
|
|
108
|
+
const isParallel = (source: string, run: readonly Paragraph[]): boolean => {
|
|
109
|
+
const openings = run.map((paragraph) => openingOf(source, paragraph));
|
|
110
|
+
const first = openings[0];
|
|
111
|
+
return run.length > 1 && first !== undefined && first.split(" ").length === PARALLEL_WORDS && openings.every((opening) => opening === first);
|
|
112
|
+
};
|
|
113
|
+
|
|
60
114
|
/**
|
|
61
115
|
* Each run of adjacent one-sentence paragraphs, in document order, as the paragraphs it holds. A paragraph of two sentences or
|
|
62
|
-
* more, a paragraph that does not end as a sentence, opens with an item mark or
|
|
63
|
-
* between two paragraphs, ends the run.
|
|
116
|
+
* more, a paragraph that does not end as a sentence, opens with an item mark or an enumerator, follows a lead-in as its item or
|
|
117
|
+
* is a reference list's entry, or anything between two paragraphs, ends the run. A run of parallel entries is a list, not a run.
|
|
64
118
|
*/
|
|
65
|
-
export const oneSentenceRuns = (source: string, paragraphs: readonly Paragraph[], referenceLists: readonly Span[] = []): Paragraph[][] =>
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
119
|
+
export const oneSentenceRuns = (source: string, paragraphs: readonly Paragraph[], referenceLists: readonly Span[] = []): Paragraph[][] => {
|
|
120
|
+
const leadInItems = underLeadIn(source, paragraphs);
|
|
121
|
+
return paragraphs
|
|
122
|
+
.reduce<Paragraph[][]>((runs, paragraph, at) => {
|
|
123
|
+
if (!counts(source, paragraph, referenceLists, leadInItems)) return runs;
|
|
124
|
+
const previous = paragraphs[at - 1];
|
|
125
|
+
const current = runs.at(-1);
|
|
126
|
+
const continues = previous !== undefined && current?.at(-1) === previous && isAdjacent(source, previous, paragraph);
|
|
127
|
+
if (continues) current.push(paragraph);
|
|
128
|
+
else runs.push([paragraph]);
|
|
129
|
+
return runs;
|
|
130
|
+
}, [])
|
|
131
|
+
.filter((run) => !isParallel(source, run));
|
|
132
|
+
};
|
package/src/plugin.ts
CHANGED
|
@@ -75,6 +75,8 @@ export type LexiconEntry = {
|
|
|
75
75
|
readonly first_year?: number | undefined;
|
|
76
76
|
/** The genres or groups the entry holds in (legal, blog/tech). Without them, every genre. A detector reads them with entriesForGenre. */
|
|
77
77
|
readonly genres?: readonly string[] | undefined;
|
|
78
|
+
/** The entry counts only in a heading: a title phrase that body text uses plainly. A detector that reads headings honours it. */
|
|
79
|
+
readonly heading_only?: boolean | undefined;
|
|
78
80
|
/** pattern を adapter が語に分けたもの。品詞が読めるときだけ core が入れる。語彙表を書く側は書かない。 */
|
|
79
81
|
readonly tokens?: readonly Token[] | undefined;
|
|
80
82
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Span } from "./plugin.ts";
|
|
2
|
+
|
|
3
|
+
// A phrase the writer repeats from a quotation in the same document (「勇気と真心をもって真実を語る」 quoted, then 勇気と真心を
|
|
4
|
+
// もって真実を語り in the writer's own sentence): the words of the echo keep the quotation's spelling. Pure.
|
|
5
|
+
|
|
6
|
+
/** How many characters on each side of a word are read with it: enough to tell an echo from a word that merely recurs. */
|
|
7
|
+
const ECHO_REACH = 4;
|
|
8
|
+
/** The shortest stretch, the word and its sides, that counts as an echo. */
|
|
9
|
+
const MIN_ECHO_LENGTH = 8;
|
|
10
|
+
|
|
11
|
+
/** The insides of the quotations in a text, as quotedSpans places them. */
|
|
12
|
+
export const quotationsIn = (text: string, spans: readonly Span[]): string[] => spans.map((span) => text.slice(span.start, span.end));
|
|
13
|
+
|
|
14
|
+
/** Whether the word at start..end of text, with the characters around it, stands word for word in one of the quotations. */
|
|
15
|
+
export const echoesQuotation = (text: string, { start, end }: Span, quotations: readonly string[]): boolean => {
|
|
16
|
+
const phrase = text.slice(Math.max(0, start - ECHO_REACH), Math.min(text.length, end + ECHO_REACH));
|
|
17
|
+
return phrase.length >= MIN_ECHO_LENGTH && quotations.some((quotation) => quotation.includes(phrase));
|
|
18
|
+
};
|
package/src/run.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { PatternTimeout } from "./custom/pattern-timeout.ts";
|
|
|
19
19
|
import { PluginRuleFailure } from "./extension/module-detector.ts";
|
|
20
20
|
import { failureReason } from "./extension/failure-text.ts";
|
|
21
21
|
import { tagCoverage } from "./tag-coverage.ts";
|
|
22
|
+
import { compositeSignals } from "./composite-signals.ts";
|
|
22
23
|
|
|
23
24
|
export type Skipped = {
|
|
24
25
|
readonly rule: string;
|
|
@@ -210,9 +211,10 @@ export const place = (starts: readonly number[], finding: Finding): Finding => {
|
|
|
210
211
|
* まとめるために消すと本物の指摘が見えなくなる。
|
|
211
212
|
*/
|
|
212
213
|
const compositeOf = (rule: RuleDefinition, found: readonly Finding[], limit: number, starts: readonly number[], language: string): Finding[] => {
|
|
213
|
-
const fired = rule.from
|
|
214
|
+
const fired = compositeSignals(rule.from, found);
|
|
214
215
|
if (fired.length < limit) return [];
|
|
215
|
-
|
|
216
|
+
// 数えなかった signal も含めて、最初に出た所に置く。同じ形を 1 種に数えても、指摘の位置は動かない。
|
|
217
|
+
const first = found.find((finding) => rule.from.includes(finding.rule));
|
|
216
218
|
return [
|
|
217
219
|
place(starts, {
|
|
218
220
|
rule: rule.id,
|
package/src/semantic.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { calendarUnitsOf } from "./calendar-number.ts";
|
|
2
2
|
import { closingAndEarlier, newNumbers } from "./closing-numbers.ts";
|
|
3
|
+
import { hasNewCodeOrLink, isLinkList } from "./closing-code.ts";
|
|
3
4
|
import { openingProse, opensWithNumber } from "./opening-passage.ts";
|
|
4
5
|
import { proseText } from "./measure.ts";
|
|
5
6
|
import type { ProseDocument, Section } from "./plugin.ts";
|
|
@@ -31,8 +32,6 @@ export const riskDisclosure: Filter = (doc) => {
|
|
|
31
32
|
return [{ text: body.slice(0, 4000), offset: doc.sentences[0]?.span.start ?? 0 }];
|
|
32
33
|
};
|
|
33
34
|
|
|
34
|
-
const EVIDENCE = /`|https?:\/\//u;
|
|
35
|
-
|
|
36
35
|
/** 結びに、前に書いていない数があるか。本文の数を繰り返すだけ(「以上のように、9月は…」)なら具体物ではない。 */
|
|
37
36
|
const hasNewNumber = (doc: ProseDocument, last: Section): boolean => {
|
|
38
37
|
const { closing, earlier } = closingAndEarlier(doc, last);
|
|
@@ -47,7 +46,7 @@ export const emptyConclusion: Filter = (doc) => {
|
|
|
47
46
|
const last = doc.sections.at(-1);
|
|
48
47
|
if (last === undefined || last.sentences.length === 0) return [];
|
|
49
48
|
const text = sectionText(doc, last);
|
|
50
|
-
if (
|
|
49
|
+
if (isLinkList(text) || hasNewCodeOrLink(text, doc.source.slice(0, last.span.start)) || hasNewNumber(doc, last)) return [];
|
|
51
50
|
return [{ text: text.slice(0, 2000), offset: last.sentences[0]?.span.start ?? last.span.start }];
|
|
52
51
|
};
|
|
53
52
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Token } from "./plugin.ts";
|
|
2
|
+
|
|
3
|
+
// A particle inside a set phrase (絶滅のおそれのある種: おそれのある, "at risk of"): the phrase is read as one word, so its particle
|
|
4
|
+
// is not a link of a nesting chain. Pure.
|
|
5
|
+
|
|
6
|
+
const touches = (left: Token | undefined, right: Token | undefined): boolean => left !== undefined && right !== undefined && left.span.end === right.span.start;
|
|
7
|
+
|
|
8
|
+
/** How many words before a particle are read for a phrase's head: the tokenizer may cut it (おそれ as お and それ). */
|
|
9
|
+
const MAX_HEAD_WORDS = 3;
|
|
10
|
+
|
|
11
|
+
/** The words written straight before tokens[at], joined (おそれ from お and それ). */
|
|
12
|
+
const headBefore = (tokens: readonly Token[], at: number): string => {
|
|
13
|
+
const window = tokens.slice(Math.max(0, at - MAX_HEAD_WORDS), at + 1);
|
|
14
|
+
const gap = window.findLastIndex((token, index) => index < window.length - 1 && !touches(token, window[index + 1]));
|
|
15
|
+
return window
|
|
16
|
+
.slice(gap + 1, -1)
|
|
17
|
+
.map((token) => token.surface)
|
|
18
|
+
.join("");
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Whether the particle at `at`, the words before it and the dictionary form of the word after it spell one of phrases (おそれのある). */
|
|
22
|
+
const isInPhrase = (tokens: readonly Token[], at: number, phrases: readonly string[]): boolean => {
|
|
23
|
+
const [particle, after] = [tokens[at], tokens[at + 1]];
|
|
24
|
+
if (particle === undefined || after === undefined || !touches(particle, after)) return false;
|
|
25
|
+
const tail = `${particle.surface}${after.lemma ?? after.surface}`;
|
|
26
|
+
const head = headBefore(tokens, at);
|
|
27
|
+
return phrases.some((phrase) => phrase.endsWith(tail) && phrase.length > tail.length && head.endsWith(phrase.slice(0, -tail.length)));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** The counted particles (particles) of a sentence that stand inside one of phrases, each written whole (おそれのある). */
|
|
31
|
+
export const setPhraseParticles = (tokens: readonly Token[], particles: readonly string[], phrases: readonly string[]): ReadonlySet<Token> =>
|
|
32
|
+
new Set(tokens.filter((token, at) => particles.includes(token.surface) && isInPhrase(tokens, at, phrases)));
|
|
@@ -23,21 +23,46 @@ const isLabelLine = (line: string): boolean => {
|
|
|
23
23
|
return text.startsWith("#") || ("【〔[[((".includes(text.charAt(0)) && "】〕]]))".includes(text.charAt(text.length - 1)));
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
/** A division whose heading, or the label line just before it, the test names. */
|
|
27
|
+
const divisionNamedBy =
|
|
28
|
+
(source: string, names: (text: string) => boolean): ((node: StructureNode) => boolean) =>
|
|
29
|
+
(node) => {
|
|
30
|
+
const heading = node.attrs["heading"];
|
|
31
|
+
if (typeof heading === "string" && names(heading)) return true;
|
|
32
|
+
const label = previousLineOf(source, node.span.start);
|
|
33
|
+
return isLabelLine(label) && names(label);
|
|
34
|
+
};
|
|
35
|
+
|
|
26
36
|
/**
|
|
27
37
|
* A division its heading, or the label line just before it (【18条変更オプション条項:知財調停】), names as an alternative
|
|
28
38
|
* (alternative-clause-label).
|
|
29
39
|
*/
|
|
30
40
|
export const alternativeReader = (source: string, labels: readonly string[]): ((node: StructureNode) => boolean) => {
|
|
31
41
|
const words = labels.filter((label) => label !== "");
|
|
32
|
-
|
|
33
|
-
return (node) => {
|
|
34
|
-
const heading = node.attrs["heading"];
|
|
35
|
-
if (typeof heading === "string" && names(heading)) return true;
|
|
36
|
-
const label = previousLineOf(source, node.span.start);
|
|
37
|
-
return isLabelLine(label) && names(label);
|
|
38
|
-
};
|
|
42
|
+
return divisionNamedBy(source, (text) => words.some((word) => text.includes(word)));
|
|
39
43
|
};
|
|
40
44
|
|
|
45
|
+
/** One number or letter after the word (オプション2, Option B), not the first of a range or a list (オプション1~3, Options 1 and 2). */
|
|
46
|
+
const ONE_CHOICE = /^\s?(?:[0-90-9]+|[A-ZA-Z])(?![0-90-9A-Za-zA-Z])(?!\s*(?:[~〜~\-–—‐・、,,&&]|to\b|and\b|or\b))/u;
|
|
47
|
+
|
|
48
|
+
/** The text names one choice among numbered ones: an option word (option-choice-label) followed by its number or letter. */
|
|
49
|
+
export const namesOneChoice = (text: string, words: readonly string[]): boolean =>
|
|
50
|
+
words
|
|
51
|
+
.filter((word) => word !== "")
|
|
52
|
+
.some((word) =>
|
|
53
|
+
text
|
|
54
|
+
.split(word)
|
|
55
|
+
.slice(1)
|
|
56
|
+
.some((after) => ONE_CHOICE.test(after)),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A division its heading or label line names as one of numbered choices (第1条(オプション2:…), "Option B"): only one of
|
|
61
|
+
* them stays in the signed text (option-choice-label).
|
|
62
|
+
*/
|
|
63
|
+
export const choiceReader = (source: string, words: readonly string[]): ((node: StructureNode) => boolean) =>
|
|
64
|
+
divisionNamedBy(source, (text) => namesOneChoice(text, words));
|
|
65
|
+
|
|
41
66
|
/** Where a line starts with a division whose number is left blank (placeholder-division: 第●条): a new run of numbers. */
|
|
42
67
|
export const placeholderStarts = (source: string, patterns: readonly string[]): number[] => {
|
|
43
68
|
const heads = patterns.filter((pattern) => pattern !== "");
|
|
@@ -55,3 +55,11 @@ export const referencesInCitedDocuments = (tree: StructureNode): ReadonlySet<Str
|
|
|
55
55
|
const quoted = visits.filter((visit) => visit.node.kind === "reference" && visit.inArticle && visit.heading !== undefined && cited.has(visit.heading));
|
|
56
56
|
return new Set(quoted.map((visit) => visit.node));
|
|
57
57
|
};
|
|
58
|
+
|
|
59
|
+
/** 見出しが他の文書の名前そのもので、その名前を文書がほかで他の文書として引いている節に引き写した条。Pure. */
|
|
60
|
+
export const articlesInCitedDocuments = (tree: StructureNode): readonly StructureNode[] => {
|
|
61
|
+
const visits = visitsOf(tree);
|
|
62
|
+
const cited = documentsCited(visits.map((visit) => visit.node));
|
|
63
|
+
if (cited.size === 0) return [];
|
|
64
|
+
return visits.filter((visit) => visit.node.kind === "article" && visit.heading !== undefined && cited.has(visit.heading)).map((visit) => visit.node);
|
|
65
|
+
};
|
package/src/structure/issues.ts
CHANGED
|
@@ -209,18 +209,20 @@ export const referenceResolver = (tree: StructureNode, source: string): ((refere
|
|
|
209
209
|
};
|
|
210
210
|
};
|
|
211
211
|
|
|
212
|
-
|
|
212
|
+
/** choice: the division, one of several to choose from, that holds the definition (undefined when the text keeps it whatever is chosen). */
|
|
213
|
+
type Definition = { readonly node: StructureNode; readonly article: string; readonly choice: StructureNode | undefined };
|
|
213
214
|
|
|
214
|
-
/**
|
|
215
|
-
const definitionsInOrder = (tree: StructureNode): Definition[] => {
|
|
215
|
+
/** 定義を文書の順に、それが置かれた条の番地と、選ぶ条項の中ならその条項と一緒に並べる。範囲を限った定義は、その条の中でだけ比べるため。 */
|
|
216
|
+
const definitionsInOrder = (tree: StructureNode, isChoice: (node: StructureNode) => boolean): Definition[] => {
|
|
216
217
|
const found: Definition[] = [];
|
|
217
|
-
const pending: Definition[] = [{ node: tree, article: "" }];
|
|
218
|
+
const pending: Definition[] = [{ node: tree, article: "", choice: undefined }];
|
|
218
219
|
while (pending.length > 0) {
|
|
219
220
|
const current = pending.pop();
|
|
220
221
|
if (current === undefined) break;
|
|
221
222
|
if (current.node.kind === "definition") found.push(current);
|
|
222
223
|
const article = current.node.kind === "article" ? current.node.address : current.article;
|
|
223
|
-
current.node.
|
|
224
|
+
const choice = current.choice ?? (current.node.kind !== "definition" && isChoice(current.node) ? current.node : undefined);
|
|
225
|
+
current.node.children.toReversed().forEach((child) => pending.push({ node: child, article, choice }));
|
|
224
226
|
}
|
|
225
227
|
return found;
|
|
226
228
|
};
|
|
@@ -231,17 +233,25 @@ const definitionsInOrder = (tree: StructureNode): Definition[] => {
|
|
|
231
233
|
* 添付した文書(partStarts から始まる Exhibit A など)は別の文書なので、その中の定義はその中でだけ比べる。
|
|
232
234
|
* 同じ名前の後ろの括弧で同じ語を定義し直したもの(件名と本文の Financial Crimes Enforcement Network ("FinCEN"))は、
|
|
233
235
|
* 一つの定義を書き直しただけで食い違えないので言わない。名前は source から読む。
|
|
236
|
+
* ひな形の選ぶ条項(オプション1、オプション2)の中の定義は、選ばなければ消える。先の定義が消えうるなら、後の定義は二度目と決まらない。
|
|
237
|
+
* そこで選ぶ条項の中の定義は、どれを選んでも残る定義と、同じ条項の中の定義とだけ比べる。
|
|
234
238
|
*/
|
|
235
|
-
export const duplicateDefinitions = (
|
|
239
|
+
export const duplicateDefinitions = (
|
|
240
|
+
tree: StructureNode,
|
|
241
|
+
partStarts: readonly number[] = [],
|
|
242
|
+
source = "",
|
|
243
|
+
isChoice: (node: StructureNode) => boolean = () => false,
|
|
244
|
+
): StructureIssue[] => {
|
|
236
245
|
const first = new Map<string, StructureNode>();
|
|
237
|
-
return definitionsInOrder(tree).flatMap(({ node, article }) => {
|
|
246
|
+
return definitionsInOrder(tree, isChoice).flatMap(({ node, article, choice }) => {
|
|
238
247
|
const term = textOf(node, "term");
|
|
239
248
|
const within = node.attrs["within"] === undefined ? article : textOf(node, "within");
|
|
240
249
|
const scoped = node.attrs["scope"] === "local" ? `${within}\u0000${term}` : term;
|
|
241
250
|
const key = `${partAt(partStarts, node.span.start)}\u0000${scoped}`;
|
|
242
|
-
const
|
|
251
|
+
const choiceKey = choice === undefined ? undefined : `${choice.span.start}\u0000${key}`;
|
|
252
|
+
const earlier = first.get(key) ?? (choiceKey === undefined ? undefined : first.get(choiceKey));
|
|
243
253
|
if (earlier === undefined) {
|
|
244
|
-
first.set(key, node);
|
|
254
|
+
first.set(choiceKey ?? key, node);
|
|
245
255
|
return [];
|
|
246
256
|
}
|
|
247
257
|
const name = nameBeforeDefinition(source, node);
|
|
@@ -3,6 +3,7 @@ import { inDocumentOrder, type StructureIssue } from "./issues.ts";
|
|
|
3
3
|
import { numbersQuotedInside } from "./quoted-number.ts";
|
|
4
4
|
import { isVersionHistory } from "./version-order.ts";
|
|
5
5
|
import { withRepeatsNamed } from "./repeated-number.ts";
|
|
6
|
+
import { labelWrittenBetween } from "./unread-label.ts";
|
|
6
7
|
|
|
7
8
|
const labelOf = (node: StructureNode): string => String(node.attrs["label"] ?? node.address);
|
|
8
9
|
|
|
@@ -17,6 +18,14 @@ export type ClauseReadings = { readonly isAlternative: (node: StructureNode) =>
|
|
|
17
18
|
|
|
18
19
|
const NO_CLAUSES: ClauseReadings = { isAlternative: () => false, restarts: [] };
|
|
19
20
|
|
|
21
|
+
/**
|
|
22
|
+
* What a skip is checked against besides the tree. source: the text, for labels set out that the tree did not read
|
|
23
|
+
* (unread-label.ts). isPartialHeading: a heading saying what is under it is only some (抜粋, excerpt), where numbers skip by choice.
|
|
24
|
+
*/
|
|
25
|
+
export type SkipReadings = { readonly source: string; readonly isPartialHeading: (heading: string) => boolean };
|
|
26
|
+
|
|
27
|
+
const NO_SKIPS: SkipReadings = { source: "", isPartialHeading: () => false };
|
|
28
|
+
|
|
20
29
|
const OPENING_BRACKET = /^[([{〔【〈《]/u;
|
|
21
30
|
|
|
22
31
|
/** 括弧で囲んだ番号((1)、(a))か。全角と半角は同じに見る。 */
|
|
@@ -74,7 +83,7 @@ const unreadBetween = (unread: readonly Span[], previous: Ordered, current: Orde
|
|
|
74
83
|
* あいだに読めなかった範囲(unread)があれば、抜けた番号はそこにあるかもしれないので言わない。重なりは言う。
|
|
75
84
|
*/
|
|
76
85
|
const breaksIn =
|
|
77
|
-
(unread: readonly Span[], restarts: readonly Span[]) =>
|
|
86
|
+
(unread: readonly Span[], restarts: readonly Span[], isSkipAllowed: (previous: Ordered, current: Ordered) => boolean) =>
|
|
78
87
|
(sequence: readonly Ordered[]): StructureIssue[] =>
|
|
79
88
|
sequence.flatMap((current, index) => {
|
|
80
89
|
const previous = sequence[index - 1];
|
|
@@ -84,6 +93,7 @@ const breaksIn =
|
|
|
84
93
|
if (unreadBetween(restarts, previous, current)) return [];
|
|
85
94
|
if (current.ordinal > previous.last + 1 && unreadBetween(unread, previous, current)) return [];
|
|
86
95
|
if (current.ordinal > previous.last + 1 && current.ordinal <= previous.last + 1 + current.sideSteps) return [];
|
|
96
|
+
if (current.ordinal > previous.last + 1 && isSkipAllowed(previous, current)) return [];
|
|
87
97
|
return [
|
|
88
98
|
{
|
|
89
99
|
offset: current.node.span.start,
|
|
@@ -92,6 +102,32 @@ const breaksIn =
|
|
|
92
102
|
];
|
|
93
103
|
});
|
|
94
104
|
|
|
105
|
+
/** 抜粋と書いた見出し(## 根拠条文の抜粋)の下の節点。そこの番号は選んで引いたので、飛んでよい。 */
|
|
106
|
+
const underPartialHeadings = (tree: StructureNode, isPartialHeading: (heading: string) => boolean): Set<StructureNode> => {
|
|
107
|
+
const under = new Set<StructureNode>();
|
|
108
|
+
const pending: [StructureNode, boolean][] = [[tree, false]];
|
|
109
|
+
while (pending.length > 0) {
|
|
110
|
+
const [node, inherited] = pending.pop() ?? [tree, false];
|
|
111
|
+
const heading = node.attrs["heading"];
|
|
112
|
+
const partial = inherited || (node.kind === "section" && typeof heading === "string" && isPartialHeading(heading));
|
|
113
|
+
if (partial) under.add(node);
|
|
114
|
+
node.children.forEach((child) => pending.push([child, partial]));
|
|
115
|
+
}
|
|
116
|
+
return under;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/** 並びの始まりの番号。番号は 1 から振る(法令の項は 2 から)。 */
|
|
120
|
+
const LAST_START = 2;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 番号が一つしかなく、それが並びの始まりでない並び(用語集の見出し Section 508 Program、Section 508 Program Manager)は
|
|
124
|
+
* 名前で、番号の並びではない。法令の「2」「2」と続く項(第 1 項は番号が無い)は重なり。
|
|
125
|
+
*/
|
|
126
|
+
const isOneNumber = (sequence: readonly Ordered[]): boolean => {
|
|
127
|
+
const [first] = sequence;
|
|
128
|
+
return first !== undefined && sequence.length > 1 && first.ordinal > LAST_START && sequence.every((ordered) => ordered.ordinal === first.ordinal);
|
|
129
|
+
};
|
|
130
|
+
|
|
95
131
|
/**
|
|
96
132
|
* 番号の抜けと重なり。比べるのは同じ親の子どうしだけ。英米の法令は章ごとに Section 101、201 と百の位を変えるので、
|
|
97
133
|
* 文書全体の通し番号として比べると抜けに見える。最初の番号は見ない。日本語の項は 2 から番号を振る。
|
|
@@ -102,18 +138,29 @@ const breaksIn =
|
|
|
102
138
|
* unread は、読み手には見えるが木に入らない範囲(Markdown の HTML ブロックの中の文字)を、始まりの順に並べたもの。
|
|
103
139
|
* isSideStep は、番号の代わりに「and」と書いた手順(前の手順と並べて行う)。その数だけ、次の番号は飛んでよい。
|
|
104
140
|
* clauses は、別案の条(並びに入れない)と、番号を空けた条の位置(そこから振り直す)。
|
|
141
|
+
* skips は、抜けを言わない場合: 抜けた番号を木が読まずに本文に書いてある((e) の前の行末の (d))か、抜粋と書いた見出しの下。
|
|
105
142
|
*/
|
|
106
143
|
export const numberingBreaks = (
|
|
107
144
|
tree: StructureNode,
|
|
108
145
|
unread: readonly Span[] = [],
|
|
109
146
|
isSideStep: (node: StructureNode) => boolean = () => false,
|
|
110
147
|
clauses: ClauseReadings = NO_CLAUSES,
|
|
148
|
+
skips: SkipReadings = NO_SKIPS,
|
|
111
149
|
): StructureIssue[] => {
|
|
112
150
|
const quoting = numbersQuotedInside(tree);
|
|
113
151
|
const restarts = clauses.restarts.map((start) => ({ start, end: start }));
|
|
152
|
+
const partial = underPartialHeadings(tree, skips.isPartialHeading);
|
|
153
|
+
const spanOf = (ordered: Ordered): { label: string; ordinal: number; start: number; last: number } => ({
|
|
154
|
+
label: labelOf(ordered.node),
|
|
155
|
+
ordinal: ordered.ordinal,
|
|
156
|
+
start: ordered.node.span.start,
|
|
157
|
+
last: ordered.last,
|
|
158
|
+
});
|
|
159
|
+
const isSkipAllowed = (previous: Ordered, current: Ordered): boolean =>
|
|
160
|
+
partial.has(current.node) || labelWrittenBetween(skips.source, spanOf(previous), spanOf(current));
|
|
114
161
|
const breaks = inDocumentOrder(tree)
|
|
115
162
|
.flatMap((parent) => sequencesOf(parent, quoting, isSideStep, clauses))
|
|
116
|
-
.filter((sequence) => !isVersionHistory(sequence.map((ordered) => labelOf(ordered.node))))
|
|
117
|
-
.flatMap(breaksIn(unread, restarts));
|
|
163
|
+
.filter((sequence) => !isVersionHistory(sequence.map((ordered) => labelOf(ordered.node))) && !isOneNumber(sequence))
|
|
164
|
+
.flatMap(breaksIn(unread, restarts, isSkipAllowed));
|
|
118
165
|
return withRepeatsNamed(tree, quoting, breaks, unread);
|
|
119
166
|
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// A number the tree did not read but the text writes: "(d)" run into the end of the line before "(e)", "6.1" and "6.2"
|
|
2
|
+
// written as plain paragraphs before the "6.3" the tree read, "(11)" joined to the heading of "(10)". A skip across such
|
|
3
|
+
// a label is not a missing number. Pure.
|
|
4
|
+
|
|
5
|
+
const LETTERS = "abcdefghijklmnopqrstuvwxyz";
|
|
6
|
+
|
|
7
|
+
/** At most this many missing numbers are looked for; a wider skip is not a few labels the tree missed. */
|
|
8
|
+
const MAX_MISSING = 30;
|
|
9
|
+
|
|
10
|
+
/** A label in brackets ((11)): in the heading before, a bare number may be any number in its words. */
|
|
11
|
+
const BRACKETED = /^[([]/u;
|
|
12
|
+
/** An HTML comment: text the reader does not see, so a label in it is not written. */
|
|
13
|
+
const HTML_COMMENT = /<!--[\s\S]*?-->/gu;
|
|
14
|
+
|
|
15
|
+
const escapeRegExp = (text: string): string => text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
16
|
+
|
|
17
|
+
/** The label written with another number in place of its own: digits for digits, a letter in the same case for a letter. */
|
|
18
|
+
const relabel = (label: string, ordinal: number): ((other: number) => string) | undefined => {
|
|
19
|
+
const digits = [...label.matchAll(/\d+/gu)].findLast((match) => Number(match[0]) === ordinal);
|
|
20
|
+
if (digits !== undefined) return (other) => `${label.slice(0, digits.index)}${other}${label.slice(digits.index + digits[0].length)}`;
|
|
21
|
+
const letter = [...label.matchAll(/(?<![A-Za-z])[A-Za-z](?![A-Za-z])/gu)].findLast((match) => LETTERS.indexOf(match[0].toLowerCase()) + 1 === ordinal);
|
|
22
|
+
if (letter === undefined) return undefined;
|
|
23
|
+
const upper = letter[0] !== letter[0].toLowerCase();
|
|
24
|
+
return (other) => {
|
|
25
|
+
const written = LETTERS.charAt(other - 1);
|
|
26
|
+
return `${label.slice(0, letter.index)}${upper ? written.toUpperCase() : written}${label.slice(letter.index + 1)}`;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A label set out as one: at the start of a line behind the same marks as the later label (## for a heading, none for a
|
|
32
|
+
* paragraph), after a run of spaces within a line, or after a space in the heading that opens the node before
|
|
33
|
+
* ("##### (10) … (11) …", a label in brackets). A label in a sentence or in an HTML comment ("under clause (d)") is a reference, and a list item's "3." under
|
|
34
|
+
* headings numbered "## 4." is another numbering.
|
|
35
|
+
*/
|
|
36
|
+
const setOutIn = (text: string, label: string, lead: string): boolean => {
|
|
37
|
+
const escaped = escapeRegExp(label);
|
|
38
|
+
const after = String.raw`(?![0-9A-Za-z])`;
|
|
39
|
+
const atLineStart = new RegExp(String.raw`^[ \t]*${escapeRegExp(lead)}[ \t]*${escaped}${after}`, "mu");
|
|
40
|
+
const afterSpaces = new RegExp(String.raw`\S[ \t]{2,}${escaped}${after}`, "u");
|
|
41
|
+
if (atLineStart.test(text) || afterSpaces.test(text)) return true;
|
|
42
|
+
const firstLine = text.split("\n", 1)[0] ?? "";
|
|
43
|
+
const bracketed = BRACKETED.test(label);
|
|
44
|
+
return bracketed && firstLine.trimStart().startsWith("#") && new RegExp(String.raw`\s${escaped}${after}`, "u").test(firstLine);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** The marks before a label on its own line (## of a heading, > of a quotation), spaces left out. */
|
|
48
|
+
const leadOf = (source: string, start: number, label: string): string => {
|
|
49
|
+
const lineStart = source.lastIndexOf("\n", start - 1) + 1;
|
|
50
|
+
const lineEnd = source.indexOf("\n", start);
|
|
51
|
+
const line = source.slice(lineStart, lineEnd === -1 ? source.length : lineEnd).normalize("NFKC");
|
|
52
|
+
const at = line.indexOf(label);
|
|
53
|
+
return at === -1 ? "" : line.slice(0, at).trim();
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type LabelSpan = { readonly label: string; readonly ordinal: number; readonly start: number };
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Whether the text between two numbered nodes sets out a label of the later one's kind with a number the skip leaves out
|
|
60
|
+
* (between previous's last number and current's), which the tree did not read as a node.
|
|
61
|
+
*/
|
|
62
|
+
export const labelWrittenBetween = (source: string, previous: LabelSpan & { readonly last: number }, current: LabelSpan): boolean => {
|
|
63
|
+
const missing = current.ordinal - previous.last - 1;
|
|
64
|
+
if (missing < 1 || missing > MAX_MISSING || current.start <= previous.start) return false;
|
|
65
|
+
const label = current.label.normalize("NFKC");
|
|
66
|
+
const written = relabel(label, current.ordinal);
|
|
67
|
+
if (written === undefined) return false;
|
|
68
|
+
const lead = leadOf(source, current.start, label);
|
|
69
|
+
const text = source
|
|
70
|
+
.slice(source.lastIndexOf("\n", previous.start - 1) + 1, current.start)
|
|
71
|
+
.replaceAll(HTML_COMMENT, "")
|
|
72
|
+
.normalize("NFKC");
|
|
73
|
+
return Array.from({ length: missing }, (_, index) => written(previous.last + 1 + index)).some((missingLabel) => setOutIn(text, missingLabel, lead));
|
|
74
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Lexicon, Section } from "../plugin.ts";
|
|
2
|
+
import { containsWord, headingWords } from "./heading-words.ts";
|
|
3
|
+
|
|
4
|
+
/** A heading still open at a point of the outline: its depth, and whether it is a question-and-answer heading. */
|
|
5
|
+
type Open = { readonly depth: number; readonly faq: boolean };
|
|
6
|
+
|
|
7
|
+
const isFaqHeading = (heading: string, faqHeadings: Lexicon): boolean =>
|
|
8
|
+
faqHeadings.some((entry) => containsWord(headingWords(heading), entry.pattern.toLowerCase()));
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Whether each section stands under a question-and-answer heading (FAQ, よくある質問), at any depth below it. An FAQ's
|
|
12
|
+
* headings are its readers' questions, so the form they take is not the writer's.
|
|
13
|
+
*/
|
|
14
|
+
export const underFaq = (headed: readonly Section[], faqHeadings: Lexicon): boolean[] =>
|
|
15
|
+
headed
|
|
16
|
+
.reduce<{ readonly open: readonly Open[]; readonly under: readonly boolean[] }>(
|
|
17
|
+
(outline, section) => {
|
|
18
|
+
const ancestors = outline.open.filter((open) => open.depth < section.depth);
|
|
19
|
+
const faq = isFaqHeading(section.heading, faqHeadings);
|
|
20
|
+
return { open: [...ancestors, { depth: section.depth, faq }], under: [...outline.under, ancestors.some((open) => open.faq)] };
|
|
21
|
+
},
|
|
22
|
+
{ open: [], under: [] },
|
|
23
|
+
)
|
|
24
|
+
.under.slice();
|