chaffjs 0.43.0 → 0.45.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/dist/bound-word-particles.d.ts +9 -0
- package/dist/bound-word-particles.d.ts.map +1 -0
- package/dist/bound-word-particles.js +16 -0
- package/dist/bound-word-particles.js.map +1 -0
- package/dist/derived/stays.d.ts +0 -1
- package/dist/derived/stays.d.ts.map +1 -1
- package/dist/derived/stays.js +3 -1
- package/dist/derived/stays.js.map +1 -1
- package/dist/detectors/absolute-exception.d.ts.map +1 -1
- package/dist/detectors/absolute-exception.js +10 -4
- package/dist/detectors/absolute-exception.js.map +1 -1
- package/dist/detectors/abstract-length.d.ts +5 -1
- package/dist/detectors/abstract-length.d.ts.map +1 -1
- package/dist/detectors/abstract-length.js +13 -5
- package/dist/detectors/abstract-length.js.map +1 -1
- package/dist/detectors/adversative-ga.d.ts +1 -1
- package/dist/detectors/adversative-ga.d.ts.map +1 -1
- package/dist/detectors/adversative-ga.js +19 -2
- package/dist/detectors/adversative-ga.js.map +1 -1
- package/dist/detectors/agreement-slip.d.ts +2 -0
- package/dist/detectors/agreement-slip.d.ts.map +1 -1
- package/dist/detectors/agreement-slip.js +22 -8
- package/dist/detectors/agreement-slip.js.map +1 -1
- package/dist/detectors/bold-label.d.ts +5 -1
- package/dist/detectors/bold-label.d.ts.map +1 -1
- package/dist/detectors/bold-label.js +74 -14
- package/dist/detectors/bold-label.js.map +1 -1
- package/dist/detectors/bold-quoted.d.ts +4 -0
- package/dist/detectors/bold-quoted.d.ts.map +1 -0
- package/dist/detectors/bold-quoted.js +17 -0
- package/dist/detectors/bold-quoted.js.map +1 -0
- package/dist/detectors/caps-caption.d.ts +5 -0
- package/dist/detectors/caps-caption.d.ts.map +1 -1
- package/dist/detectors/caps-caption.js +7 -0
- package/dist/detectors/caps-caption.js.map +1 -1
- package/dist/detectors/char-shape.d.ts +0 -6
- package/dist/detectors/char-shape.d.ts.map +1 -1
- package/dist/detectors/char-shape.js +4 -21
- package/dist/detectors/char-shape.js.map +1 -1
- package/dist/detectors/clause-shape.d.ts +2 -0
- package/dist/detectors/clause-shape.d.ts.map +1 -1
- package/dist/detectors/clause-shape.js +11 -2
- package/dist/detectors/clause-shape.js.map +1 -1
- package/dist/detectors/cleft-focus.d.ts +4 -0
- package/dist/detectors/cleft-focus.d.ts.map +1 -0
- package/dist/detectors/cleft-focus.js +31 -0
- package/dist/detectors/cleft-focus.js.map +1 -0
- package/dist/detectors/count-per-section.d.ts.map +1 -1
- package/dist/detectors/count-per-section.js +7 -4
- package/dist/detectors/count-per-section.js.map +1 -1
- package/dist/detectors/defined-term-form.d.ts.map +1 -1
- package/dist/detectors/defined-term-form.js +2 -1
- package/dist/detectors/defined-term-form.js.map +1 -1
- package/dist/detectors/definition-use.d.ts.map +1 -1
- package/dist/detectors/definition-use.js +13 -3
- package/dist/detectors/definition-use.js.map +1 -1
- package/dist/detectors/emoticon.d.ts +6 -0
- package/dist/detectors/emoticon.d.ts.map +1 -0
- package/dist/detectors/emoticon.js +19 -0
- package/dist/detectors/emoticon.js.map +1 -0
- package/dist/detectors/empty-section.d.ts +1 -1
- package/dist/detectors/empty-section.d.ts.map +1 -1
- package/dist/detectors/empty-section.js +3 -2
- package/dist/detectors/empty-section.js.map +1 -1
- package/dist/detectors/en-shape.d.ts +6 -1
- package/dist/detectors/en-shape.d.ts.map +1 -1
- package/dist/detectors/en-shape.js +9 -1
- package/dist/detectors/en-shape.js.map +1 -1
- package/dist/detectors/fullwidth-alnum.d.ts +2 -2
- package/dist/detectors/fullwidth-alnum.d.ts.map +1 -1
- package/dist/detectors/fullwidth-alnum.js +19 -3
- package/dist/detectors/fullwidth-alnum.js.map +1 -1
- package/dist/detectors/heading-echo.d.ts.map +1 -1
- package/dist/detectors/heading-echo.js +20 -7
- package/dist/detectors/heading-echo.js.map +1 -1
- package/dist/detectors/heading-number.d.ts +7 -0
- package/dist/detectors/heading-number.d.ts.map +1 -0
- package/dist/detectors/heading-number.js +21 -0
- package/dist/detectors/heading-number.js.map +1 -0
- package/dist/detectors/katakana-density.d.ts +6 -1
- package/dist/detectors/katakana-density.d.ts.map +1 -1
- package/dist/detectors/katakana-density.js +14 -1
- package/dist/detectors/katakana-density.js.map +1 -1
- package/dist/detectors/lexicon.d.ts.map +1 -1
- package/dist/detectors/lexicon.js +2 -1
- package/dist/detectors/lexicon.js.map +1 -1
- package/dist/detectors/lookalike-character.d.ts +2 -1
- package/dist/detectors/lookalike-character.d.ts.map +1 -1
- package/dist/detectors/lookalike-character.js +14 -1
- package/dist/detectors/lookalike-character.js.map +1 -1
- package/dist/detectors/mark-shape.d.ts +8 -3
- package/dist/detectors/mark-shape.d.ts.map +1 -1
- package/dist/detectors/mark-shape.js +55 -16
- package/dist/detectors/mark-shape.js.map +1 -1
- package/dist/detectors/mentioned-phrase.d.ts +3 -1
- package/dist/detectors/mentioned-phrase.d.ts.map +1 -1
- package/dist/detectors/mentioned-phrase.js +9 -0
- package/dist/detectors/mentioned-phrase.js.map +1 -1
- package/dist/detectors/middle-dot.d.ts +7 -0
- package/dist/detectors/middle-dot.d.ts.map +1 -1
- package/dist/detectors/middle-dot.js +19 -0
- package/dist/detectors/middle-dot.js.map +1 -1
- package/dist/detectors/named-by-context.d.ts +13 -0
- package/dist/detectors/named-by-context.d.ts.map +1 -0
- package/dist/detectors/named-by-context.js +10 -0
- package/dist/detectors/named-by-context.js.map +1 -0
- package/dist/detectors/number-style.d.ts.map +1 -1
- package/dist/detectors/number-style.js +13 -1
- package/dist/detectors/number-style.js.map +1 -1
- package/dist/detectors/obligation-without-deadline.d.ts +10 -2
- package/dist/detectors/obligation-without-deadline.d.ts.map +1 -1
- package/dist/detectors/obligation-without-deadline.js +47 -2
- package/dist/detectors/obligation-without-deadline.js.map +1 -1
- package/dist/detectors/open-end-names.d.ts +2 -0
- package/dist/detectors/open-end-names.d.ts.map +1 -1
- package/dist/detectors/open-end-names.js +8 -1
- package/dist/detectors/open-end-names.js.map +1 -1
- package/dist/detectors/orthographic-variant.d.ts.map +1 -1
- package/dist/detectors/orthographic-variant.js +5 -3
- package/dist/detectors/orthographic-variant.js.map +1 -1
- package/dist/detectors/paragraph-pointer.d.ts +4 -0
- package/dist/detectors/paragraph-pointer.d.ts.map +1 -0
- package/dist/detectors/paragraph-pointer.js +22 -0
- package/dist/detectors/paragraph-pointer.js.map +1 -0
- package/dist/detectors/phrase-match.d.ts +4 -1
- package/dist/detectors/phrase-match.d.ts.map +1 -1
- package/dist/detectors/phrase-match.js +12 -5
- package/dist/detectors/phrase-match.js.map +1 -1
- package/dist/detectors/placeholder-context.d.ts +16 -0
- package/dist/detectors/placeholder-context.d.ts.map +1 -0
- package/dist/detectors/placeholder-context.js +57 -0
- package/dist/detectors/placeholder-context.js.map +1 -0
- package/dist/detectors/placeholder-text.d.ts +2 -0
- package/dist/detectors/placeholder-text.d.ts.map +1 -1
- package/dist/detectors/placeholder-text.js +1 -1
- package/dist/detectors/placeholder-text.js.map +1 -1
- package/dist/detectors/redundant-pair.d.ts +5 -0
- package/dist/detectors/redundant-pair.d.ts.map +1 -0
- package/dist/detectors/redundant-pair.js +18 -0
- package/dist/detectors/redundant-pair.js.map +1 -0
- package/dist/detectors/registry/middle-dot.js +1 -1
- package/dist/detectors/registry/redundant-pair.d.ts +3 -0
- package/dist/detectors/registry/redundant-pair.d.ts.map +1 -0
- package/dist/detectors/registry/redundant-pair.js +3 -0
- package/dist/detectors/registry/redundant-pair.js.map +1 -0
- package/dist/detectors/request-owner.d.ts +1 -0
- package/dist/detectors/request-owner.d.ts.map +1 -1
- package/dist/detectors/request-owner.js +6 -3
- package/dist/detectors/request-owner.js.map +1 -1
- package/dist/detectors/sentence-counts.d.ts +2 -0
- package/dist/detectors/sentence-counts.d.ts.map +1 -1
- package/dist/detectors/sentence-counts.js +13 -4
- package/dist/detectors/sentence-counts.js.map +1 -1
- package/dist/detectors/signals.d.ts.map +1 -1
- package/dist/detectors/signals.js +10 -1
- package/dist/detectors/signals.js.map +1 -1
- package/dist/detectors/structure-tree.d.ts.map +1 -1
- package/dist/detectors/structure-tree.js +1 -0
- package/dist/detectors/structure-tree.js.map +1 -1
- package/dist/detectors/structure.d.ts.map +1 -1
- package/dist/detectors/structure.js +6 -5
- package/dist/detectors/structure.js.map +1 -1
- package/dist/detectors/superlative-context.d.ts +7 -0
- package/dist/detectors/superlative-context.d.ts.map +1 -1
- package/dist/detectors/superlative-context.js +9 -0
- package/dist/detectors/superlative-context.js.map +1 -1
- package/dist/detectors/template-sections.d.ts +1 -0
- package/dist/detectors/template-sections.d.ts.map +1 -1
- package/dist/detectors/template-sections.js +1 -1
- package/dist/detectors/template-sections.js.map +1 -1
- package/dist/detectors/token-shape.d.ts.map +1 -1
- package/dist/detectors/token-shape.js +7 -5
- package/dist/detectors/token-shape.js.map +1 -1
- package/dist/detectors/unbalanced-bracket.d.ts.map +1 -1
- package/dist/detectors/unbalanced-bracket.js +2 -1
- package/dist/detectors/unbalanced-bracket.js.map +1 -1
- package/dist/detectors/unfilled-placeholder.d.ts.map +1 -1
- package/dist/detectors/unfilled-placeholder.js +18 -1
- package/dist/detectors/unfilled-placeholder.js.map +1 -1
- package/dist/detectors/verse-block.d.ts +4 -0
- package/dist/detectors/verse-block.d.ts.map +1 -0
- package/dist/detectors/verse-block.js +40 -0
- package/dist/detectors/verse-block.js.map +1 -0
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +1 -0
- package/dist/document.js.map +1 -1
- package/dist/email-parts.d.ts +2 -0
- package/dist/email-parts.d.ts.map +1 -1
- package/dist/email-parts.js +10 -7
- package/dist/email-parts.js.map +1 -1
- package/dist/eval.d.ts.map +1 -1
- package/dist/eval.js +3 -0
- package/dist/eval.js.map +1 -1
- package/dist/paragraph-length.d.ts +4 -0
- package/dist/paragraph-length.d.ts.map +1 -1
- package/dist/paragraph-length.js +6 -0
- package/dist/paragraph-length.js.map +1 -1
- package/dist/plugin.d.ts +4 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/reasons.d.ts +2 -0
- package/dist/reasons.d.ts.map +1 -1
- package/dist/reasons.js +2 -0
- package/dist/reasons.js.map +1 -1
- package/dist/rule-of-three.d.ts +13 -1
- package/dist/rule-of-three.d.ts.map +1 -1
- package/dist/rule-of-three.js +32 -3
- package/dist/rule-of-three.js.map +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +4 -1
- package/dist/run.js.map +1 -1
- package/dist/structure/build.d.ts.map +1 -1
- package/dist/structure/build.js +2 -1
- package/dist/structure/build.js.map +1 -1
- package/dist/structure/cited-elsewhere.d.ts +5 -2
- package/dist/structure/cited-elsewhere.d.ts.map +1 -1
- package/dist/structure/cited-elsewhere.js +16 -6
- package/dist/structure/cited-elsewhere.js.map +1 -1
- package/dist/structure/definition-use.d.ts +2 -1
- package/dist/structure/definition-use.d.ts.map +1 -1
- package/dist/structure/definition-use.js +10 -2
- package/dist/structure/definition-use.js.map +1 -1
- package/dist/structure/issues.js +1 -1
- package/dist/structure/issues.js.map +1 -1
- package/dist/structure/negated-act.d.ts +1 -0
- package/dist/structure/negated-act.d.ts.map +1 -1
- package/dist/structure/negated-act.js +1 -1
- package/dist/structure/negated-act.js.map +1 -1
- package/dist/structure/own-name.d.ts +4 -0
- package/dist/structure/own-name.d.ts.map +1 -0
- package/dist/structure/own-name.js +20 -0
- package/dist/structure/own-name.js.map +1 -0
- package/dist/structure/percent-sum-prose.d.ts.map +1 -1
- package/dist/structure/percent-sum-prose.js +9 -1
- package/dist/structure/percent-sum-prose.js.map +1 -1
- package/dist/structure/percent-sum.d.ts +2 -0
- package/dist/structure/percent-sum.d.ts.map +1 -1
- package/dist/structure/percent-sum.js.map +1 -1
- package/dist/structure/reference-text.d.ts.map +1 -1
- package/dist/structure/reference-text.js +3 -1
- package/dist/structure/reference-text.js.map +1 -1
- package/dist/te-form-helper.d.ts +22 -0
- package/dist/te-form-helper.d.ts.map +1 -0
- package/dist/te-form-helper.js +35 -0
- package/dist/te-form-helper.js.map +1 -0
- package/dist/word-use.d.ts +7 -0
- package/dist/word-use.d.ts.map +1 -1
- package/dist/word-use.js +11 -0
- package/dist/word-use.js.map +1 -1
- package/package.json +3 -3
- package/rules/absolute-exception.yaml +3 -3
- package/rules/abstract-length.yaml +2 -2
- package/rules/adversative-ga-repeat.yaml +2 -2
- package/rules/all-caps-shouting.yaml +2 -2
- package/rules/attachment-not-attached.yaml +11 -6
- package/rules/bold-label-list.yaml +29 -6
- package/rules/bracket-width-consistency.yaml +2 -2
- package/rules/demonstrative-opener-run.yaml +2 -2
- package/rules/duration-mismatch.yaml +2 -2
- package/rules/emoji-density.yaml +2 -2
- package/rules/empty-section.yaml +2 -2
- package/rules/fullwidth-alnum-consistency.yaml +2 -2
- package/rules/katakana-density.yaml +3 -3
- package/rules/lookalike-character.yaml +8 -5
- package/rules/max-kanji-continuous.yaml +4 -0
- package/rules/no-doubled-joshi.yaml +2 -2
- package/rules/number-style-consistency.yaml +2 -2
- package/rules/obligation-without-deadline.yaml +2 -2
- package/rules/padded-intro.yaml +1 -1
- package/rules/paragraph-length-variance.yaml +27 -3
- package/rules/redundant-expression.yaml +1 -1
- package/rules/repeated-sentence-ending.yaml +2 -2
- package/rules/request-without-deadline.yaml +2 -2
- package/rules/requirement-smell.yaml +2 -2
- package/rules/rule-of-three.yaml +2 -2
- package/rules/sentence-spacing-consistency.yaml +2 -2
- package/rules/teki-overuse.yaml +2 -0
- package/rules/unfilled-placeholder.yaml +2 -2
- package/rules/use-before-definition.yaml +2 -2
- package/src/bound-word-particles.ts +23 -0
- package/src/derived/stays.ts +4 -1
- package/src/detectors/absolute-exception.ts +11 -5
- package/src/detectors/abstract-length.ts +16 -6
- package/src/detectors/adversative-ga.ts +24 -2
- package/src/detectors/agreement-slip.ts +35 -10
- package/src/detectors/bold-label.ts +82 -14
- package/src/detectors/bold-quoted.ts +21 -0
- package/src/detectors/caps-caption.ts +10 -0
- package/src/detectors/char-shape.ts +8 -22
- package/src/detectors/clause-shape.ts +14 -3
- package/src/detectors/cleft-focus.ts +40 -0
- package/src/detectors/count-per-section.ts +9 -4
- package/src/detectors/defined-term-form.ts +2 -1
- package/src/detectors/definition-use.ts +23 -4
- package/src/detectors/emoticon.ts +21 -0
- package/src/detectors/empty-section.ts +3 -2
- package/src/detectors/en-shape.ts +10 -1
- package/src/detectors/fullwidth-alnum.ts +24 -3
- package/src/detectors/heading-echo.ts +21 -8
- package/src/detectors/heading-number.ts +20 -0
- package/src/detectors/katakana-density.ts +17 -2
- package/src/detectors/lexicon.ts +2 -1
- package/src/detectors/lookalike-character.ts +19 -2
- package/src/detectors/mark-shape.ts +61 -13
- package/src/detectors/mentioned-phrase.ts +13 -1
- package/src/detectors/middle-dot.ts +22 -0
- package/src/detectors/named-by-context.ts +15 -0
- package/src/detectors/number-style.ts +14 -1
- package/src/detectors/obligation-without-deadline.ts +69 -5
- package/src/detectors/open-end-names.ts +21 -2
- package/src/detectors/orthographic-variant.ts +20 -15
- package/src/detectors/paragraph-pointer.ts +28 -0
- package/src/detectors/phrase-match.ts +13 -5
- package/src/detectors/placeholder-context.ts +72 -0
- package/src/detectors/placeholder-text.ts +1 -1
- package/src/detectors/redundant-pair.ts +25 -0
- package/src/detectors/registry/middle-dot.ts +1 -1
- package/src/detectors/registry/redundant-pair.ts +4 -0
- package/src/detectors/request-owner.ts +6 -3
- package/src/detectors/sentence-counts.ts +16 -4
- package/src/detectors/signals.ts +11 -1
- package/src/detectors/structure-tree.ts +1 -0
- package/src/detectors/structure.ts +6 -5
- package/src/detectors/superlative-context.ts +12 -0
- package/src/detectors/template-sections.ts +1 -1
- package/src/detectors/token-shape.ts +10 -7
- package/src/detectors/unbalanced-bracket.ts +2 -1
- package/src/detectors/unfilled-placeholder.ts +22 -1
- package/src/detectors/verse-block.ts +48 -0
- package/src/document.ts +1 -0
- package/src/email-parts.ts +16 -7
- package/src/eval.ts +2 -0
- package/src/paragraph-length.ts +10 -0
- package/src/plugin.ts +4 -0
- package/src/reasons.ts +4 -0
- package/src/rule-of-three.ts +47 -4
- package/src/run.ts +3 -1
- package/src/structure/build.ts +2 -1
- package/src/structure/cited-elsewhere.ts +18 -6
- package/src/structure/definition-use.ts +10 -1
- package/src/structure/issues.ts +1 -1
- package/src/structure/negated-act.ts +1 -1
- package/src/structure/own-name.ts +28 -0
- package/src/structure/percent-sum-prose.ts +12 -1
- package/src/structure/percent-sum.ts +2 -0
- package/src/structure/reference-text.ts +5 -1
- package/src/te-form-helper.ts +52 -0
- package/src/word-use.ts +13 -0
- package/src/honorific-group.ts +0 -22
|
@@ -11,7 +11,7 @@ const LATIN = /\p{Script=Latin}/u;
|
|
|
11
11
|
/** Does the character beside a match end the word? A Latin edge needs a non-letter next to it; a CJK word stands anywhere. */
|
|
12
12
|
const boundsWord = (edge: string, beside: string | undefined): boolean => !LATIN.test(edge) || beside === undefined || !/[\p{L}\p{N}]/u.test(beside);
|
|
13
13
|
|
|
14
|
-
const holdsWordAt = (text: string, pattern: string, index: number): boolean =>
|
|
14
|
+
export const holdsWordAt = (text: string, pattern: string, index: number): boolean =>
|
|
15
15
|
boundsWord(pattern[0] ?? "", text[index - 1]) && boundsWord(pattern.at(-1) ?? "", text[index + pattern.length]);
|
|
16
16
|
|
|
17
17
|
/** The heading names a template: one of the words appears in it as a whole word, in any case. */
|
|
@@ -4,7 +4,7 @@ import { chronologyRows } from "../chronology-rows.ts";
|
|
|
4
4
|
import { externalLinkTitleSpans } from "../link-title.ts";
|
|
5
5
|
import type { Detector, Finding, Span, Token } from "../plugin.ts";
|
|
6
6
|
import { countedTokens, uncountedWordsOf, type UncountedWords } from "../uncounted-particles.ts";
|
|
7
|
-
import {
|
|
7
|
+
import { boundWordParticles } from "../bound-word-particles.ts";
|
|
8
8
|
import { setPhraseParticles } from "../set-phrase-particles.ts";
|
|
9
9
|
import { noteSentences } from "../note-paragraphs.ts";
|
|
10
10
|
import { documentNameSpans } from "./particle-run-names.ts";
|
|
@@ -100,15 +100,18 @@ const RUN_BREAK_LEXICON = "particle-run-break";
|
|
|
100
100
|
/** 人の集まりを敬って呼ぶ語(国民の皆様の「皆様」)。直前の助詞は呼び方の一部で、入れ子の輪に数えない。 */
|
|
101
101
|
const HONORIFIC_GROUP_LEXICON = "honorific-group";
|
|
102
102
|
|
|
103
|
+
/** 置き場所を言う語(ラックの下の「下」)。直前の助詞は「ラックの下」という一つの場所の名前の中にあり、入れ子の輪に数えない。 */
|
|
104
|
+
const POSITION_LEXICON = "particle-run-position";
|
|
105
|
+
|
|
103
106
|
/** 助詞を挟んで一語のように読む決まった言い回し(おそれのある)。中の助詞は入れ子の輪に数えない。 */
|
|
104
107
|
const SET_PHRASE_LEXICON = "particle-run-set-phrase";
|
|
105
108
|
|
|
106
|
-
/**
|
|
107
|
-
type Phrases = { readonly
|
|
109
|
+
/** 前の語と組んで一つの名前になる語(皆様、下)と決まった言い回し(おそれのある)。 */
|
|
110
|
+
type Phrases = { readonly boundWords: readonly string[]; readonly setPhrases: readonly string[] };
|
|
108
111
|
|
|
109
|
-
/**
|
|
110
|
-
const chainTokens = (tokens: readonly Token[], numbering: UncountedWords, {
|
|
111
|
-
const uncounted = new Set([...
|
|
112
|
+
/** 数えない助詞(番号をつなぐ「の」、敬って呼ぶ語や置き場所を言う語の前の「の」、決まった言い回しの中の「の」)を除いた語。 */
|
|
113
|
+
const chainTokens = (tokens: readonly Token[], numbering: UncountedWords, { boundWords, setPhrases }: Phrases): readonly Token[] => {
|
|
114
|
+
const uncounted = new Set([...boundWordParticles(tokens, numbering.particles, boundWords), ...setPhraseParticles(tokens, numbering.particles, setPhrases)]);
|
|
112
115
|
const counted = countedTokens(tokens, numbering);
|
|
113
116
|
return uncounted.size === 0 ? counted : counted.filter((token) => !uncounted.has(token));
|
|
114
117
|
};
|
|
@@ -119,7 +122,7 @@ export const doubledParticle: Detector = (doc, options): Finding[] => {
|
|
|
119
122
|
const breaks = (doc.lexicons[RUN_BREAK_LEXICON] ?? []).map((entry) => entry.pattern);
|
|
120
123
|
const numbering = uncountedWordsOf(doc.lexicons, nesting);
|
|
121
124
|
const phrases: Phrases = {
|
|
122
|
-
|
|
125
|
+
boundWords: [HONORIFIC_GROUP_LEXICON, POSITION_LEXICON].flatMap((id) => (doc.lexicons[id] ?? []).map((entry) => entry.pattern)),
|
|
123
126
|
setPhrases: (doc.lexicons[SET_PHRASE_LEXICON] ?? []).map((entry) => entry.pattern),
|
|
124
127
|
};
|
|
125
128
|
const prose = doc.prose ?? doc.source;
|
|
@@ -6,6 +6,7 @@ import { mergeSpans } from "../span-merge.ts";
|
|
|
6
6
|
import { firstEndingAfter } from "../soft-break.ts";
|
|
7
7
|
import { isLabelClose, isLabelInAside } from "./bracket-label.ts";
|
|
8
8
|
import { isInchMark } from "./inch-mark.ts";
|
|
9
|
+
import { isEmoticonMouth } from "./emoticon.ts";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* 括弧の組。どの言語でも同じ字の決まりなので、語彙表ではなくここに置く。family は形(丸・角)で、全角と半角は同じ形の別の幅。
|
|
@@ -95,7 +96,7 @@ export const bracketProblems = (text: string): BracketProblem[] => {
|
|
|
95
96
|
const heads = paragraphHeads(text);
|
|
96
97
|
[...text.matchAll(MARKS)].forEach((match) => {
|
|
97
98
|
const quoteOpen = scan.open.some((entry) => entry.bracket.family === "quote");
|
|
98
|
-
if (isInchMark(text, match.index, quoteOpen)) return;
|
|
99
|
+
if (isInchMark(text, match.index, quoteOpen) || isEmoticonMouth(text, match.index)) return;
|
|
99
100
|
const opening = BY_OPEN.get(match[0]);
|
|
100
101
|
const closing = BY_CLOSE.get(match[0]);
|
|
101
102
|
if (opening !== undefined) openWith(scan, opening, match.index, heads.has(match.index));
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Detector, Finding, Lexicon, ProseDocument } from "../plugin.ts";
|
|
2
2
|
import { entriesForGenre } from "../lexicon-genres.ts";
|
|
3
3
|
import { unfilledPlaceholder } from "./ai-phrasing.ts";
|
|
4
|
-
import { placeholderSpans } from "./placeholder-text.ts";
|
|
4
|
+
import { BLANK_SUFFIX, placeholderSpans } from "./placeholder-text.ts";
|
|
5
5
|
import { TEMPLATE, isInside, templateSections } from "./template-sections.ts";
|
|
6
6
|
import { tableBodyCells } from "../facts/table-facts.ts";
|
|
7
7
|
import { proseAndTablesOf } from "../table-text.ts";
|
|
8
|
+
import { EXAMPLE_LEAD, captionsFillLine, filledFieldLabels, insideQuotedExample, lineAround } from "./placeholder-context.ts";
|
|
8
9
|
|
|
9
10
|
/** The prose covers tables, so a blank left in a cell (| Owner | [Name] |) is read from the cells themselves. */
|
|
10
11
|
const cellBlanks = (doc: ProseDocument, lexicon: Lexicon): Finding[] =>
|
|
@@ -19,6 +20,24 @@ const cellBlanks = (doc: ProseDocument, lexicon: Lexicon): Finding[] =>
|
|
|
19
20
|
})),
|
|
20
21
|
);
|
|
21
22
|
|
|
23
|
+
/**
|
|
24
|
+
* A bracket that is not a forgotten blank, read from the line around it: the caption of a form's fill line, a blank inside
|
|
25
|
+
* a quoted example, or a field label the document fills in elsewhere.
|
|
26
|
+
*/
|
|
27
|
+
const isNamedOrExample = (doc: ProseDocument, lexicon: Lexicon): ((finding: Finding) => boolean) => {
|
|
28
|
+
const leads = lexicon.filter((word) => word.group === EXAMPLE_LEAD);
|
|
29
|
+
const fields = filledFieldLabels(
|
|
30
|
+
doc.source,
|
|
31
|
+
lexicon.filter((word) => word.group === BLANK_SUFFIX),
|
|
32
|
+
);
|
|
33
|
+
return (finding) => {
|
|
34
|
+
const matched = String(finding.values["matched"]);
|
|
35
|
+
const start = Number(finding.values["offset"]);
|
|
36
|
+
const line = lineAround(doc.source, start, start + matched.length);
|
|
37
|
+
return fields.has(matched) || captionsFillLine(line) || insideQuotedExample(line, leads);
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
22
41
|
/**
|
|
23
42
|
* A blank under a heading that names a template (Template, 雛形) is what the template is for, so it is not reported.
|
|
24
43
|
* Words that hold in some genres only (〇〇様 in a letter) count in those genres.
|
|
@@ -27,7 +46,9 @@ export const unfilledPlaceholderOutsideTemplates: Detector = (doc, options) => {
|
|
|
27
46
|
const lexicon = entriesForGenre(options.lexicon ?? [], options.genre);
|
|
28
47
|
const words = lexicon.filter((word) => word.group === TEMPLATE);
|
|
29
48
|
const templates = templateSections(doc.markup?.headings ?? [], doc.source.length, words);
|
|
49
|
+
const named = isNamedOrExample(doc, lexicon);
|
|
30
50
|
return [...unfilledPlaceholder(doc, { ...options, lexicon }), ...cellBlanks(doc, lexicon)]
|
|
31
51
|
.filter((finding) => !isInside(templates, Number(finding.values["offset"])))
|
|
52
|
+
.filter((finding) => !named(finding))
|
|
32
53
|
.toSorted((left, right) => Number(left.values["offset"]) - Number(right.values["offset"]));
|
|
33
54
|
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Span } from "../plugin.ts";
|
|
2
|
+
|
|
3
|
+
// Stanzas: blocks of lines between blank lines where every line opens with a capital, as a verse line does, in a document
|
|
4
|
+
// where several such blocks also run a sentence on across a line into a capital ("How public, like a frog / To tell…").
|
|
5
|
+
// Prose wrapped at a column goes on in lower case, and prose with one sentence a line ends each line with its sentence.
|
|
6
|
+
|
|
7
|
+
const VERSE_LINE = /^[\t ]*["'“‘(]?\p{Lu}/u;
|
|
8
|
+
const SENTENCE_CLOSE = /[.!?]["'”’)\]]*[\t ]*$/u;
|
|
9
|
+
/** The run-on stanzas a document needs before its capitalised blocks are read as verse: one may be a list of names. */
|
|
10
|
+
const MIN_RUN_ON_STANZAS = 3;
|
|
11
|
+
const MIN_LINES = 2;
|
|
12
|
+
|
|
13
|
+
type Block = { start: number; end: number; readonly lines: string[] };
|
|
14
|
+
|
|
15
|
+
/** The runs of lines between blank lines, each with its span in the source. */
|
|
16
|
+
const blocksOf = (source: string): Block[] => {
|
|
17
|
+
const blocks: Block[] = [];
|
|
18
|
+
const state = { offset: 0, open: false };
|
|
19
|
+
source.split("\n").forEach((line) => {
|
|
20
|
+
const start = state.offset;
|
|
21
|
+
state.offset += line.length + 1;
|
|
22
|
+
if (line.trim() === "") {
|
|
23
|
+
state.open = false;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const last = blocks.at(-1);
|
|
27
|
+
if (state.open && last !== undefined) {
|
|
28
|
+
last.end = start + line.length;
|
|
29
|
+
last.lines.push(line);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
blocks.push({ start, end: start + line.length, lines: [line] });
|
|
33
|
+
state.open = true;
|
|
34
|
+
});
|
|
35
|
+
return blocks;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const isCapitalised = (lines: readonly string[]): boolean => lines.every((line) => VERSE_LINE.test(line));
|
|
39
|
+
|
|
40
|
+
/** A line inside the block, past its first, that runs on into the next: a first line alone may be a caption ("Article 1 Purpose"). */
|
|
41
|
+
const runsOn = (lines: readonly string[]): boolean => lines.slice(1, -1).some((line) => !SENTENCE_CLOSE.test(line));
|
|
42
|
+
|
|
43
|
+
/** The spans of the source's stanzas, sorted by start and never overlapping; none when the document is not verse. */
|
|
44
|
+
export const verseBlockSpans = (source: string): Span[] => {
|
|
45
|
+
const blocks = blocksOf(source).filter(({ lines }) => lines.length >= MIN_LINES && isCapitalised(lines));
|
|
46
|
+
const runOn = blocks.filter(({ lines }) => runsOn(lines)).length;
|
|
47
|
+
return runOn >= MIN_RUN_ON_STANZAS ? blocks.map(({ start, end }) => ({ start, end })) : [];
|
|
48
|
+
};
|
package/src/document.ts
CHANGED
|
@@ -370,6 +370,7 @@ const documentOf = (path: string, source: string, adapter: LanguageAdapter, team
|
|
|
370
370
|
namedDocument: adapter.structure?.namedDocument,
|
|
371
371
|
dictionary: adapter.dictionary,
|
|
372
372
|
replyQuotes: emailLayout.replyQuotes,
|
|
373
|
+
sentMessage: emailLayout.sent,
|
|
373
374
|
get markup(): Markup {
|
|
374
375
|
return documentMarkup(root, source, markdown, [...emailLayout.replyQuotes, ...syntax]);
|
|
375
376
|
},
|
package/src/email-parts.ts
CHANGED
|
@@ -25,6 +25,8 @@ export type EmailParts = {
|
|
|
25
25
|
readonly furniture: readonly Span[];
|
|
26
26
|
/** An attribution line and the quoted lines after it: someone else's words, so not this document's headings or structure. */
|
|
27
27
|
readonly replyQuotes: readonly Span[];
|
|
28
|
+
/** A header names a field the writer does not type (From, Date): a message as sent or kept, not a draft. */
|
|
29
|
+
readonly sent: boolean;
|
|
28
30
|
};
|
|
29
31
|
|
|
30
32
|
const lowerCased = (lexicon: Lexicon | undefined): ReadonlySet<string> => new Set((lexicon ?? []).map((entry) => entry.pattern.toLowerCase()));
|
|
@@ -142,12 +144,17 @@ const fieldMask = (field: readonly Line[], vocabulary: EmailVocabulary): Span |
|
|
|
142
144
|
return { start: first.start, end: first.start + label[0].length };
|
|
143
145
|
};
|
|
144
146
|
|
|
145
|
-
const
|
|
146
|
-
blocksOf(lines).
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
const headerBlocks = (lines: readonly Line[], vocabulary: EmailVocabulary): Line[][] =>
|
|
148
|
+
blocksOf(lines).filter((block) => block[0] !== undefined && isHeader(block, opensMessage(lines, block[0]), vocabulary));
|
|
149
|
+
|
|
150
|
+
const headerSpans = (headers: readonly Line[][], vocabulary: EmailVocabulary): Span[] =>
|
|
151
|
+
headers.flatMap((block) => fieldsOf(block).flatMap((field) => fieldMask(field, vocabulary) ?? []));
|
|
152
|
+
|
|
153
|
+
/** A header line the writer does not type: a known field outside the written ones (From, Date), or the envelope line. */
|
|
154
|
+
const isSentField = (line: Line, vocabulary: EmailVocabulary): boolean => {
|
|
155
|
+
const name = FIELD.exec(line.text)?.[1]?.toLowerCase();
|
|
156
|
+
return name === undefined ? ENVELOPE.test(line.text) : vocabulary.headerFields.has(name) && !vocabulary.writtenFields.has(name);
|
|
157
|
+
};
|
|
151
158
|
|
|
152
159
|
const isUrlField = (line: Line | undefined): boolean => {
|
|
153
160
|
const label = line === undefined ? null : FIELD.exec(line.text);
|
|
@@ -256,14 +263,16 @@ export const emailParts = (source: string, vocabulary: EmailVocabulary): EmailPa
|
|
|
256
263
|
const lines = linesOf(source);
|
|
257
264
|
const replies = repliesOf(lines, vocabulary);
|
|
258
265
|
const separators = lines.filter((line) => isSeparator(line)).map((line) => spanOfLines(line, line));
|
|
266
|
+
const headers = headerBlocks(lines, vocabulary);
|
|
259
267
|
return {
|
|
260
268
|
furniture: [
|
|
261
|
-
...headerSpans(
|
|
269
|
+
...headerSpans(headers, vocabulary),
|
|
262
270
|
...attachmentStubSpans(lines, vocabulary),
|
|
263
271
|
...separators,
|
|
264
272
|
...signatureSpans(lines),
|
|
265
273
|
...replies.map((reply) => reply.attribution),
|
|
266
274
|
].toSorted(bySpanStart),
|
|
267
275
|
replyQuotes: replies.map((reply) => reply.quote),
|
|
276
|
+
sent: headers.some((block) => block.some((line) => isSentField(line, vocabulary))),
|
|
268
277
|
};
|
|
269
278
|
};
|
package/src/eval.ts
CHANGED
|
@@ -77,6 +77,8 @@ const meets = (need: string, docs: readonly ProseDocument[]): boolean => {
|
|
|
77
77
|
if (need === "headings") return docs.some((doc) => bodySectionOf(doc.sections) !== undefined);
|
|
78
78
|
// 記法を読む rule は Markdown の文書でしか動かない。
|
|
79
79
|
if (need === "markdown") return docs.some((doc) => doc.markup?.markdown === true);
|
|
80
|
+
// 下書きでは lint が動かない。送ったメールが 1 つも無ければ、どの閾値でも 0 件になる。
|
|
81
|
+
if (need === "sent-message") return docs.some((doc) => doc.sentMessage === true);
|
|
80
82
|
return false;
|
|
81
83
|
};
|
|
82
84
|
|
package/src/paragraph-length.ts
CHANGED
|
@@ -19,6 +19,16 @@ const FUSED_HEADING = /^[ \t\u3000]*[0-90-9①-⑳]{1,3}【[^】\n]+】[ \t\
|
|
|
19
19
|
/** 段落の本文が、番号付きの見出しから改行なしで始まる。段落の切れ目が失われた文書で、長さを測っても書き手の段落ではない。 */
|
|
20
20
|
export const opensWithFusedHeading = (text: string): boolean => FUSED_HEADING.test(text);
|
|
21
21
|
|
|
22
|
+
/** A sentence end glued to the next sentence with no space ("speculate about it.Judge the claim"): a line break lost in copying. The next word ends in a space or a mark other than a period: "Cong.Rec." is an abbreviation. */
|
|
23
|
+
const GLUED_SENTENCES = /(?<=\p{Ll}\p{Ll})[.!?](?=\p{Lu}\p{Ll}+[\s,;:])/gu;
|
|
24
|
+
|
|
25
|
+
/** One glued pair is a typo; two or more mean the block's line breaks were lost, so its sentences were not one paragraph. */
|
|
26
|
+
const MIN_GLUED = 2;
|
|
27
|
+
|
|
28
|
+
/** 文の終わりと次の文の頭が空白なしでつながる所が二つ以上ある。改行が落ちた塊で、長さを測っても書き手の段落ではない。 */
|
|
29
|
+
export const lostLineBreaks = (sentences: readonly { readonly text: string }[]): boolean =>
|
|
30
|
+
sentences.reduce((count, sentence) => count + [...sentence.text.matchAll(GLUED_SENTENCES)].length, 0) >= MIN_GLUED;
|
|
31
|
+
|
|
22
32
|
/** 【】のラベルだけの文(【0001】【技術分野】)。見出しで、文に数えない。 */
|
|
23
33
|
const LABELS_ONLY = /^\s*(?:【[^】\n]+】\s*)+$/u;
|
|
24
34
|
|
package/src/plugin.ts
CHANGED
|
@@ -77,6 +77,8 @@ export type LexiconEntry = {
|
|
|
77
77
|
readonly genres?: readonly string[] | undefined;
|
|
78
78
|
/** The entry counts only in a heading: a title phrase that body text uses plainly. A detector that reads headings honours it. */
|
|
79
79
|
readonly heading_only?: boolean | undefined;
|
|
80
|
+
/** The entry counts only where it opens the sentence (近年、… but not その後、近年の…). phrase-match honours it. */
|
|
81
|
+
readonly opens?: boolean | undefined;
|
|
80
82
|
/** pattern を adapter が語に分けたもの。品詞が読めるときだけ core が入れる。語彙表を書く側は書かない。 */
|
|
81
83
|
readonly tokens?: readonly Token[] | undefined;
|
|
82
84
|
};
|
|
@@ -379,6 +381,8 @@ export type ProseDocument = {
|
|
|
379
381
|
readonly namedDocument?: DocumentNamer | undefined;
|
|
380
382
|
/** メールの引用した返信(前置きの行と「> 」の行)。ほかの人の言葉なので、見出しにも木にも入れない。 */
|
|
381
383
|
readonly replyQuotes?: readonly Span[] | undefined;
|
|
384
|
+
/** ヘッダーに書き手の打たない項目(From・Date)がある。送った・届いたメールで、下書きではない。下書きの添付は送るときに付くので本文から見えない。 */
|
|
385
|
+
readonly sentMessage?: boolean | undefined;
|
|
382
386
|
/** 記法の手がかり(見出し・画像・リンク)。記法を読む rule だけが触れ、触れたときに作る。 */
|
|
383
387
|
readonly markup?: Markup | undefined;
|
|
384
388
|
/** adapter の綴りの辞書。持たない言語では無い。 */
|
package/src/reasons.ts
CHANGED
|
@@ -20,6 +20,8 @@ export type Reasons = {
|
|
|
20
20
|
readonly noHeadings: string;
|
|
21
21
|
readonly patternTimeout: (budgetMs: number) => string;
|
|
22
22
|
readonly notMarkdown: string;
|
|
23
|
+
/** A rule that reads what a message carries, on a draft: its attachments are added when sending. */
|
|
24
|
+
readonly draftMessage: string;
|
|
23
25
|
/** A rule that compares documents, in a run of one: it runs when chaff is given two or more files, or a folder. */
|
|
24
26
|
readonly oneDocument: string;
|
|
25
27
|
};
|
|
@@ -57,6 +59,7 @@ export const REASONS: Texts<Reasons> = {
|
|
|
57
59
|
noHeadings: "表題より下の見出しが無いため",
|
|
58
60
|
patternTimeout: (budgetMs) => `正規表現が ${String(budgetMs)} ms で終わらなかったため(chaff.yaml の pattern を単純にしてください)`,
|
|
59
61
|
notMarkdown: "Markdown の文書ではないため",
|
|
62
|
+
draftMessage: "送る前の下書き(差出人や日時のヘッダーが無い)で、添付は送るときに付けるため本文からは見えないため",
|
|
60
63
|
oneDocument: "比べるほかの文書が無いため(ファイルを二つ以上かフォルダを渡すと動きます)",
|
|
61
64
|
},
|
|
62
65
|
en: {
|
|
@@ -80,6 +83,7 @@ export const REASONS: Texts<Reasons> = {
|
|
|
80
83
|
noHeadings: "the document has no headings below its title",
|
|
81
84
|
patternTimeout: (budgetMs) => `the pattern did not finish within ${String(budgetMs)} ms (simplify the pattern in chaff.yaml)`,
|
|
82
85
|
notMarkdown: "the document is not Markdown",
|
|
86
|
+
draftMessage: "the text is a draft (no From: or Date: header), and a draft's files are attached when sending, out of the text's sight",
|
|
83
87
|
oneDocument: "it compares documents, and there is only one to compare (it runs when chaff is given two or more files, or a folder)",
|
|
84
88
|
},
|
|
85
89
|
};
|
package/src/rule-of-three.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { BulletList } from "./plugin.ts";
|
|
|
6
6
|
* 箇条書きが少ないと、1 つで割合が大きく動く(4 つなら 25 ポイント)。そのときは全部が 3 項目のときだけ報告する。
|
|
7
7
|
* 2 つでも測る。生成文の報告書は「要因 3 つ」「提言 3 つ」の 2 つの箇条書きで終わることが多く、人の文書で 2 つとも 3 項目は少ない。
|
|
8
8
|
* 本文の最初の文より前の箇条書き(題・日付・見出しのすぐ下の要点や概要)は数えない。項目の数はサイトの型が決めている。
|
|
9
|
+
* どの項目も「札:数」の内訳も、どの項目も 3 文以上ある箇条書きも、ちょうど 3 項目とは数えない。
|
|
9
10
|
*/
|
|
10
11
|
export type ThreeShare = { readonly count: number; readonly total: number; readonly share: number; readonly first: BulletList };
|
|
11
12
|
|
|
@@ -48,14 +49,56 @@ const isProseLine = (line: string): boolean => !NOT_PROSE_LINE.test(line) && SEN
|
|
|
48
49
|
/** 本文の最初の文がある行の頭。それより前は題・日付・見出しだけ。文が無ければ文書の終わり。 */
|
|
49
50
|
export const firstProseOffset = (source: string): number => [...source.matchAll(/^.*$/gmu)].find(([line]) => isProseLine(line))?.index ?? source.length;
|
|
50
51
|
|
|
51
|
-
const
|
|
52
|
-
|
|
52
|
+
const ITEM_MARKER = /^\s*(?:[-*+]|\d+[.)])\s+/u;
|
|
53
|
+
const LABEL_COLON = /[::]/u;
|
|
54
|
+
const DIGIT = /[0-90-9]/u;
|
|
55
|
+
const EMPHASIS = /[*_]/u;
|
|
56
|
+
/** 札と値の長さの上限。「執務エリアの通路沿い」「大きめを2鉢」は入り、文になった値は入らない。 */
|
|
57
|
+
const MAX_LABEL = 20;
|
|
58
|
+
const MAX_VALUE = 12;
|
|
59
|
+
|
|
60
|
+
/** 太字でない短い札とコロン、その後ろに数字を含む短い値だけがある項目(「受付:大きめを2鉢」「Rent: $1,200」)。 */
|
|
61
|
+
const isLabelledFigure = (item: string): boolean => {
|
|
62
|
+
const line = item.replace(ITEM_MARKER, "").split("\n")[0] ?? "";
|
|
63
|
+
const colon = line.search(LABEL_COLON);
|
|
64
|
+
const label = line.slice(0, colon);
|
|
65
|
+
const value = line.slice(colon + 1).trim();
|
|
66
|
+
return colon > 0 && label.length <= MAX_LABEL && !EMPHASIS.test(label) && value.length <= MAX_VALUE && DIGIT.test(value);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* どの項目も「札:数」の箇条書き(置き場所ごとの鉢の数、費目ごとの金額)。数の内訳で、項目の数は中身が決めている。
|
|
71
|
+
* 札の側だけに数がある日程(「2026年12月:承認」)は内訳ではない。太字の札や、値が文になった項目(「**件数**:月平均 420 件届く」)は、
|
|
72
|
+
* 生成文が理由を 3 つに揃える形なので内訳と読まない。
|
|
73
|
+
*/
|
|
74
|
+
export const isFigureBreakdown = (source: string, list: BulletList): boolean =>
|
|
75
|
+
list.itemSpans.length > 0 && list.itemSpans.every((item) => isLabelledFigure(source.slice(item.start, item.end)));
|
|
76
|
+
|
|
77
|
+
/** 段落として書いた項目の文の数の下限。太字の見出しの文と、それを説く 2 文。 */
|
|
78
|
+
const MIN_ITEM_SENTENCES = 3;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* どの項目も 3 文以上ある箇条書き(太字の助言と、それを説く数文)。項目ごとに段落を書いた心得の一覧で、数は中身が決めている。
|
|
82
|
+
* 数を合わせるために足した項目は、1 文か 2 文の薄いものになる。
|
|
83
|
+
*/
|
|
84
|
+
export const isParagraphItems = (list: BulletList, sentenceStarts: readonly number[]): boolean =>
|
|
85
|
+
list.itemSpans.length > 0 &&
|
|
86
|
+
list.itemSpans.every((item) => sentenceStarts.filter((start) => start >= item.start && start < item.end).length >= MIN_ITEM_SENTENCES);
|
|
87
|
+
|
|
88
|
+
const isExactlyThree = (source: string, list: BulletList, openWords: readonly string[], sentenceStarts: readonly number[]): boolean =>
|
|
89
|
+
list.items.length === THREE && !continuesBeyond(source, list, openWords) && !isFigureBreakdown(source, list) && !isParagraphItems(list, sentenceStarts);
|
|
53
90
|
|
|
54
91
|
/** 報告するときの数。報告しないときは undefined。 */
|
|
55
|
-
export const threeShare = (
|
|
92
|
+
export const threeShare = (
|
|
93
|
+
source: string,
|
|
94
|
+
allLists: readonly BulletList[],
|
|
95
|
+
openWords: readonly string[],
|
|
96
|
+
limit: number,
|
|
97
|
+
sentenceStarts: readonly number[] = [],
|
|
98
|
+
): ThreeShare | undefined => {
|
|
56
99
|
const bodyStart = firstProseOffset(source);
|
|
57
100
|
const lists = allLists.filter((list) => list.span.start >= bodyStart);
|
|
58
|
-
const threes = lists.filter((list) => isExactlyThree(source, list, openWords));
|
|
101
|
+
const threes = lists.filter((list) => isExactlyThree(source, list, openWords, sentenceStarts));
|
|
59
102
|
const first = threes[0];
|
|
60
103
|
if (lists.length < MIN_LISTS || first === undefined) return undefined;
|
|
61
104
|
const share = Math.round((threes.length / lists.length) * PERCENT);
|
package/src/run.ts
CHANGED
|
@@ -103,11 +103,13 @@ const unreadOf = (doc: ProseDocument): Unread | undefined => {
|
|
|
103
103
|
/** 見出しを読む rule の要求。表題より下の見出しが無い文書では、本題の前を測れない。0 件を「前置きが短い」に見せない。 */
|
|
104
104
|
/** 記法を読む rule の要求(markdown)。.txt には見出しの記法も画像もリンクの記法も無いので、0 件を「問題なし」に見せない。 */
|
|
105
105
|
/** documents: a rule that compares the documents of one run (cross-run.ts). Run on one document, it says so instead of finding nothing. */
|
|
106
|
-
|
|
106
|
+
/** sent-message: a rule that reads what a message carries (its attachments). A draft's are added when sending, out of the text's sight. */
|
|
107
|
+
const DOCUMENT_NEEDS: ReadonlySet<string> = new Set(["headings", "markdown", "documents", "sent-message"]);
|
|
107
108
|
|
|
108
109
|
const documentNeed = (rule: RuleDefinition, doc: ProseDocument): string | undefined => {
|
|
109
110
|
if (rule.requires.includes("markdown") && !isMarkdownPath(doc.path)) return reasonsFor(doc).notMarkdown;
|
|
110
111
|
if (rule.requires.includes("headings") && bodySectionOf(doc.sections) === undefined) return reasonsFor(doc).noHeadings;
|
|
112
|
+
if (rule.requires.includes("sent-message") && doc.sentMessage !== true) return reasonsFor(doc).draftMessage;
|
|
111
113
|
if (!rule.requires.includes("documents")) return undefined;
|
|
112
114
|
// Set aside only what the cross pass can run: a missing word list is said here, as for any rule.
|
|
113
115
|
const absent = missingList(rule, doc.lexicons);
|
package/src/structure/build.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { atxHeadingText, headingText } from "../heading-text.ts";
|
|
|
3
3
|
import { addressSpans } from "../address-chain.ts";
|
|
4
4
|
import { relativeMentions, substitutedDocuments } from "./relative-find.ts";
|
|
5
5
|
import { resolveRelative } from "./relative-resolve.ts";
|
|
6
|
+
import { resolveOwnNames } from "./own-name.ts";
|
|
6
7
|
import { maskSpans } from "../mask.ts";
|
|
7
8
|
import type { DocumentProfile, Mention, NumberedLine, NumberingContext, Span, StructureKind, StructureNode, StructurePatterns } from "../plugin.ts";
|
|
8
9
|
import { lineNumberAt, linesOf, type Line } from "./lines.ts";
|
|
@@ -398,7 +399,7 @@ export const buildTree = (input: StructureInput, patterns: StructurePatterns): S
|
|
|
398
399
|
// コードの行は覆って読まないが、開いている節の中身ではある。節の最後にコードブロックがあっても、範囲をそこまで伸ばす。
|
|
399
400
|
else if (input.source.slice(line.start, line.start + line.text.length).trim() !== "") extend(state, line.start + line.text.length);
|
|
400
401
|
});
|
|
401
|
-
const tree = freeze(doc);
|
|
402
|
+
const tree = resolveOwnNames(freeze(doc), input.source);
|
|
402
403
|
const relative = input.profile?.relative;
|
|
403
404
|
return relative === undefined ? tree : resolveRelative(tree, relative.implicitFirst);
|
|
404
405
|
};
|
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
// An address the document cites to another document once ("Section 504 of the Rehabilitation Act") is that document's
|
|
2
2
|
// address wherever the document writes it bare ("In Section 504, …", "Section 504/501 complaints"): a reader who met the
|
|
3
|
-
// named form reads the bare one the same way.
|
|
3
|
+
// named form reads the bare one the same way. So is a part of that unit ("§111(a)" after "§111(c) of the Act") when the
|
|
4
|
+
// document has no unit of that number of its own. Pure.
|
|
4
5
|
import type { StructureNode } from "../plugin.ts";
|
|
5
6
|
|
|
6
7
|
/** The unit (section, article; 条) and the address. A reference without both takes no part. */
|
|
7
|
-
const keyOf = (node: StructureNode): string | undefined => {
|
|
8
|
+
const keyOf = (node: StructureNode, address: (target: string) => string = (target) => target): string | undefined => {
|
|
8
9
|
const unit = node.attrs["numbering"] ?? node.attrs["unitWord"];
|
|
9
10
|
const target = node.attrs["target"];
|
|
10
|
-
return unit === undefined || target === undefined || target === "" ? undefined : `${String(unit)}:${String(target)}`;
|
|
11
|
+
return unit === undefined || target === undefined || target === "" ? undefined : `${String(unit)}:${address(String(target))}`;
|
|
11
12
|
};
|
|
12
13
|
|
|
13
|
-
/**
|
|
14
|
+
/** The top unit of an address: 111 of 111.a.1. */
|
|
15
|
+
const topOf = (target: string): string => target.split(".")[0] ?? target;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Whether a bare reference names the same unit and address as a reference the document cites to another document, or a
|
|
19
|
+
* part of a unit cited there whose number the document does not hold itself (own says whether an address is the document's).
|
|
20
|
+
*/
|
|
14
21
|
export const citedElsewhereReader = (
|
|
15
22
|
references: readonly StructureNode[],
|
|
16
23
|
citesOther: (node: StructureNode) => boolean,
|
|
24
|
+
own: (address: string) => boolean = () => true,
|
|
17
25
|
): ((node: StructureNode) => boolean) => {
|
|
18
|
-
const
|
|
26
|
+
const named = references.filter(citesOther);
|
|
27
|
+
const cited = new Set(named.flatMap((node) => keyOf(node) ?? []));
|
|
28
|
+
const citedTops = new Set(named.flatMap((node) => keyOf(node, topOf) ?? []));
|
|
19
29
|
return (node) => {
|
|
20
30
|
const key = keyOf(node);
|
|
21
|
-
|
|
31
|
+
if (key === undefined) return false;
|
|
32
|
+
const top = topOf(String(node.attrs["target"]));
|
|
33
|
+
return cited.has(key) || (!own(top) && citedTops.has(keyOf(node, topOf) ?? ""));
|
|
22
34
|
};
|
|
23
35
|
};
|
|
@@ -346,6 +346,12 @@ const insideLongerNameIn = (texts: readonly BodyText[], terms: readonly DefinedT
|
|
|
346
346
|
};
|
|
347
347
|
};
|
|
348
348
|
|
|
349
|
+
/** 英語の語が、前の大文字の語から続く長い名前の終わりにあるか(The National Security Act of 1947 の Act)。 */
|
|
350
|
+
const endsNameAt = (texts: readonly BodyText[], term: string, offset: number): boolean => {
|
|
351
|
+
const sentence = sentenceAt(texts, offset);
|
|
352
|
+
return sentence !== undefined && endsLatinName(sentence, offset - sentence.start, term);
|
|
353
|
+
};
|
|
354
|
+
|
|
349
355
|
/**
|
|
350
356
|
* 前で書いても読み手が分かる所。文書自身の名前と定義した語(この就業規則(以下「規則」))を同じ頭を付けて書いた所(この規則は、…)と、
|
|
351
357
|
* すぐ後ろの括弧に定義の長い名前を書き添えた所(こども性暴力防止法(…に関する法律))。
|
|
@@ -378,7 +384,8 @@ const citesSource = (texts: readonly BodyText[], markers: readonly string[], off
|
|
|
378
384
|
* 文の途中で括弧に入れて定義した語((the "Seller")、以下「甲」という)を、その定義の文より前で使っている所。最初の一つだけ。
|
|
379
385
|
* 定義の文の中の現れ(株式会社GovTech東京(以下「GovTech東京」という。))は、定義する名前そのものなので数えない。札の文も、
|
|
380
386
|
* isTitle が言う題・見出し・目次の行も、漢字で終わる語にさらに漢字が続く長い語の一部も、定義の括弧の前の長い名前を写した所も、
|
|
381
|
-
* 語を含むもっと長い名前の中も、語の前に意味の出どころを書いた所(69条の3
|
|
387
|
+
* 語を含むもっと長い名前の中も、語の前に意味の出どころを書いた所(69条の3所定の小規模宅地等)も数えない。
|
|
388
|
+
* 英語の語を長い名前の終わりに書いた所(The National Security Act of 1947)より後ろの現れ(the Act)は、その名前を指すので数えない。文書自身の名前を定義した語は、selfPrefixes(この、本、this)を付けて前で書いても数えない。
|
|
382
389
|
* 定義の条("Seller" means、「甲」とは)は条の並びの頭にも終わりにも置く書き方があるので、前で使っても言わない。
|
|
383
390
|
* 定義の語の無い括弧の引用(("The key point is"))は例の引用と同じ形なので、その語を引用符で挙げただけの現れ
|
|
384
391
|
* (Its sentences open with "The key point is")は使用ではない。定義の語のある定義((the "Seller")、以下「買主」という)は、
|
|
@@ -400,8 +407,10 @@ export const usesBeforeDefinition = (
|
|
|
400
407
|
.flatMap(({ first: defined, spans }) => {
|
|
401
408
|
const defining = sentenceAt(texts, defined.span.start)?.start ?? defined.span.start;
|
|
402
409
|
const uses = usesOf(defined.term, texts, spans, "exact", defined.bare === true ? mentioned : NEVER_MENTIONED).filter((offset) => offset < defining);
|
|
410
|
+
const namedFirst = uses.find((offset) => endsNameAt(texts, defined.term, offset));
|
|
403
411
|
const first = uses.find(
|
|
404
412
|
(offset) =>
|
|
413
|
+
!(namedFirst !== undefined && namedFirst < offset) &&
|
|
405
414
|
!isLabel(sentenceAt(texts, offset), defined.term) &&
|
|
406
415
|
!insideCaption(sentenceAt(texts, offset), offset) &&
|
|
407
416
|
!isTitle(offset, defined.span.start) &&
|
package/src/structure/issues.ts
CHANGED
|
@@ -163,7 +163,7 @@ export const danglingReferences = (
|
|
|
163
163
|
const quoted = referencesInCitedDocuments(tree);
|
|
164
164
|
const references = nodes.filter((node) => node.kind === "reference");
|
|
165
165
|
const named = namedTargets(references, source, nameNouns);
|
|
166
|
-
const citedElsewhereToo = citedElsewhereReader(references, citesOther);
|
|
166
|
+
const citedElsewhereToo = citedElsewhereReader(references, citesOther, (address) => addresses.has(address));
|
|
167
167
|
const unresolved = references
|
|
168
168
|
.filter((node) => !citesOther(node) && !otherNumbering(node) && !pointsToNamedSection(node, named) && !citedElsewhereToo(node))
|
|
169
169
|
.filter((node) => !namesAbsentUnit(node, articleLabels) && !withinAbsentUnit(node, unitLabels) && !elsewhere.has(node))
|
|
@@ -13,7 +13,7 @@ export const NEGATED = "¬";
|
|
|
13
13
|
export const negationWords = (lexicon: Lexicon | undefined): ReadonlySet<string> =>
|
|
14
14
|
new Set((lexicon ?? []).filter((entry) => entry.group === undefined).map((entry) => entry.pattern.toLowerCase()));
|
|
15
15
|
|
|
16
|
-
const isNegation = (token: Token, words: ReadonlySet<string>): boolean =>
|
|
16
|
+
export const isNegation = (token: Token, words: ReadonlySet<string>): boolean =>
|
|
17
17
|
words.has(token.surface.toLowerCase()) || (token.lemma !== undefined && words.has(token.lemma.toLowerCase()));
|
|
18
18
|
|
|
19
19
|
export const isMarkedNegation = (token: Token): boolean => token.features?.[NEGATION_FEATURE] !== undefined;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { StructureNode } from "../plugin.ts";
|
|
2
|
+
import { foldPostOrder } from "../tree-walk.ts";
|
|
3
|
+
|
|
4
|
+
// A reference named with a longer form of the document's own name (本共同研究開発契約第6条 where 本契約 is the document's
|
|
5
|
+
// short own name) points into another document only when the document calls itself by the short form; otherwise the
|
|
6
|
+
// longer form is the document's own name (本利用規約 with no 本規約) and the reference stays in it. The language package
|
|
7
|
+
// marks such a reference with document and ownName; this pass decides, over the whole text. Pure.
|
|
8
|
+
|
|
9
|
+
const resolvedAttrs = (attrs: StructureNode["attrs"], ownName: string, source: string): StructureNode["attrs"] => {
|
|
10
|
+
const elsewhere = source.includes(ownName);
|
|
11
|
+
return Object.fromEntries(Object.entries(attrs).filter(([key]) => key !== "ownName" && (elsewhere || key !== "document")));
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** One node rebuilt over its resolved children; a node whose children did not change and that holds no marker is kept as it was. */
|
|
15
|
+
const resolved = (node: StructureNode, children: readonly StructureNode[], source: string): StructureNode => {
|
|
16
|
+
const ownName = node.attrs["ownName"];
|
|
17
|
+
const same = children.every((child, index) => child === node.children[index]);
|
|
18
|
+
if (typeof ownName !== "string") return same ? node : { ...node, children };
|
|
19
|
+
return { ...node, attrs: resolvedAttrs(node.attrs, ownName, source), children };
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** The tree with each ownName-marked reference kept in another document or brought back into this one. Read without recursion: a tree may be thousands of levels deep. */
|
|
23
|
+
export const resolveOwnNames = (tree: StructureNode, source: string): StructureNode =>
|
|
24
|
+
foldPostOrder<StructureNode, StructureNode>(
|
|
25
|
+
tree,
|
|
26
|
+
(node) => node.children,
|
|
27
|
+
(node, children) => resolved(node, children, source),
|
|
28
|
+
);
|
|
@@ -77,11 +77,22 @@ const namesRest = (source: string, sentence: Span, shares: readonly Amount[], wo
|
|
|
77
77
|
});
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
+
/** Whether only a joiner stands between two percentages ("from 51% to 53%", 「50%〜60%」): one share at two values. */
|
|
81
|
+
const joinedTo = (source: string, earlier: Amount, later: Amount, joiners: readonly string[]): boolean => {
|
|
82
|
+
const written = source.slice(earlier.end, later.offset);
|
|
83
|
+
const between = (written.startsWith(earlier.unit) ? written.slice(earlier.unit.length) : written).trim().toLowerCase();
|
|
84
|
+
return joiners.some((joiner) => joiner.toLowerCase() === between);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** Two shares joined into a range or a change: which of the two values is the part cannot be told, so the sentence is not added. */
|
|
88
|
+
const holdsJoinedPair = (source: string, shares: readonly Amount[], joiners: readonly string[]): boolean =>
|
|
89
|
+
shares.some((share, index) => index > 0 && joinedTo(source, shares[index - 1] ?? share, share, joiners));
|
|
90
|
+
|
|
80
91
|
const issueIn = (source: string, sentence: Span, percents: readonly Amount[], words: ShareWords): StructureIssue[] => {
|
|
81
92
|
const text = source.slice(sentence.start, sentence.end);
|
|
82
93
|
if (includesAny(text, words.exceptions)) return [];
|
|
83
94
|
const shares = percents.filter((amount) => amount.offset >= sentence.start && amount.end <= sentence.end);
|
|
84
|
-
if (shares.length < MIN_PARTS || shares.some((share) => isSigned(source, share))) return [];
|
|
95
|
+
if (shares.length < MIN_PARTS || shares.some((share) => isSigned(source, share)) || holdsJoinedPair(source, shares, words.joiners ?? [])) return [];
|
|
85
96
|
if (!includesAny(text, words.labels) && !namesRest(source, sentence, shares, words)) return [];
|
|
86
97
|
const sum = shares.reduce((total, share) => total + share.value, 0);
|
|
87
98
|
const decimals = Math.max(0, ...shares.map((share) => decimalsOf(source, share)));
|
|
@@ -24,6 +24,8 @@ export type ShareWords = {
|
|
|
24
24
|
readonly rests?: readonly string[];
|
|
25
25
|
/** 値の動いた向きの語(伸び、grew)。その文の百分率は変化で、「その他」があっても内訳ではない。 */
|
|
26
26
|
readonly changes?: readonly string[];
|
|
27
|
+
/** 二つの値を一つの範囲や変化につなぐ語と印(to, 〜)。つないだ二つの百分率は一つの割合の二つの値で、どちらが内訳の部分かは言えない。 */
|
|
28
|
+
readonly joiners?: readonly string[];
|
|
27
29
|
readonly units: readonly string[];
|
|
28
30
|
readonly totalLabels: readonly string[];
|
|
29
31
|
};
|
|
@@ -116,9 +116,13 @@ const EN_TOPIC = /^(?:the |a |an )?([a-z][a-z-]{2,}(?: [a-z][a-z-]{2,}){0,2})/iu
|
|
|
116
116
|
const STEM = 5;
|
|
117
117
|
const LATIN_TOPIC = /^[a-z -]+$/iu;
|
|
118
118
|
|
|
119
|
+
/** The link starts the text as a whole word: "for" in "for pricing", not in "formulate". */
|
|
120
|
+
const startsWithLink = (text: string, link: string): boolean =>
|
|
121
|
+
text.toLowerCase().startsWith(link.toLowerCase()) && !(LATIN_TOPIC.test(link) && LETTER.test(text.charAt(link.length)));
|
|
122
|
+
|
|
119
123
|
const topicAfter = (source: string, end: number, links: readonly string[]): string | undefined => {
|
|
120
124
|
const after = source.slice(end, end + 60);
|
|
121
|
-
const link = links.find((candidate) => after.replace(SPACE_BEFORE, "")
|
|
125
|
+
const link = links.find((candidate) => startsWithLink(after.replace(SPACE_BEFORE, ""), candidate));
|
|
122
126
|
if (link === undefined) return undefined;
|
|
123
127
|
const rest = after.replace(SPACE_BEFORE, "").slice(link.length).replace(SPACE_BEFORE, "");
|
|
124
128
|
return JA_TOPIC.exec(rest)?.[0] ?? EN_TOPIC.exec(rest)?.[1];
|