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
|
@@ -4,21 +4,31 @@
|
|
|
4
4
|
// a vague limit (promptly) is vague-deadline's; one stating an amount (pays a fee of $9,000) sets a price, and its
|
|
5
5
|
// timing is another clause's. The words come from the language package's word lists: timed-duty (the act),
|
|
6
6
|
// duty-marker (shall, will), duty-ending (う, するものとする: what may follow a Japanese act at the sentence end),
|
|
7
|
-
// stated-deadline (by the, までに) with concrete-deadline and vague-deadline, deadline-permission and
|
|
7
|
+
// stated-deadline (by the, までに) with concrete-deadline and vague-deadline, deadline-permission, currency-notation and paragraph-pointer (前項). Pure.
|
|
8
8
|
import { quoteAt } from "./structure-tree.ts";
|
|
9
9
|
import { actsTimedAt, type NamedDeadline, type Units } from "./deadline-unit.ts";
|
|
10
|
+
import { pointedParagraphs } from "./paragraph-pointer.ts";
|
|
10
11
|
import { inDocumentOrder } from "../structure/issues.ts";
|
|
11
12
|
import { escapeRegExp } from "../orthography.ts";
|
|
12
13
|
import { grantsRight, statesConcrete, vagueIn } from "./vague-deadline.ts";
|
|
13
|
-
import type { Detector, Finding, LexiconEntry, ProseDocument } from "../plugin.ts";
|
|
14
|
+
import type { Detector, Finding, LexiconEntry, ProseDocument, Span, StructureNode } from "../plugin.ts";
|
|
14
15
|
|
|
15
16
|
export type UntimedDuty = { readonly offset: number; readonly act: string };
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* sameLine: the sentence goes on the line of the one before it (no line break between them). timedActs: the acts whose
|
|
19
|
-
* dated deadline (支払期日 for 支払) its article, else its list or paragraph, names; a duty to do one of them is timed.
|
|
20
|
+
* dated deadline (支払期日 for 支払) its article, else its list or paragraph, names; a duty to do one of them is timed. place: its
|
|
21
|
+
* article (where it starts) and its paragraph's number in it.
|
|
20
22
|
*/
|
|
21
|
-
type Text = {
|
|
23
|
+
type Text = {
|
|
24
|
+
readonly start: number;
|
|
25
|
+
readonly text: string;
|
|
26
|
+
readonly sameLine?: boolean;
|
|
27
|
+
readonly timedActs?: readonly string[];
|
|
28
|
+
readonly place?: Place | undefined;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type Place = { readonly article: number; readonly paragraph: number };
|
|
22
32
|
|
|
23
33
|
/** What the word lists give the decision. */
|
|
24
34
|
export type DutyWords = {
|
|
@@ -36,6 +46,8 @@ export type DutyWords = {
|
|
|
36
46
|
readonly deferrals: readonly string[];
|
|
37
47
|
readonly permissions: readonly LexiconEntry[];
|
|
38
48
|
readonly currencies: readonly LexiconEntry[];
|
|
49
|
+
/** Words that point at another paragraph of the article (前項, 本条1項). */
|
|
50
|
+
readonly paragraphPointers?: readonly LexiconEntry[];
|
|
39
51
|
};
|
|
40
52
|
|
|
41
53
|
const LATIN = /\p{Script=Latin}/u;
|
|
@@ -147,13 +159,41 @@ const lineEnds = (texts: readonly Text[]): number[] => {
|
|
|
147
159
|
return ends;
|
|
148
160
|
};
|
|
149
161
|
|
|
162
|
+
type Bound = { readonly place: Place; readonly act: string; readonly text: string };
|
|
163
|
+
|
|
164
|
+
/** The limited sentences of articles, with the act each binds. */
|
|
165
|
+
const limitedBounds = (texts: readonly Text[], words: DutyWords): Bound[] =>
|
|
166
|
+
texts.flatMap((text) => {
|
|
167
|
+
const act = text.place === undefined || !limited(text, words) ? undefined : actIn(text.text, words);
|
|
168
|
+
return act === undefined || text.place === undefined ? [] : [{ place: text.place, act: act.act.toLowerCase(), text: text.text }];
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Whether another paragraph of the duty's article times the same act and one of the two points at the other: an article
|
|
173
|
+
* that says what is paid in its first paragraph and, in its third, pays 「本条1項に定める対価」 within ten days, or pays
|
|
174
|
+
* 「前項の対価」 by bank transfer after the paragraph that gives the time.
|
|
175
|
+
*/
|
|
176
|
+
const timedInArticle = (text: Text, act: string, bounds: readonly Bound[], pointers: readonly LexiconEntry[]): boolean => {
|
|
177
|
+
const place = text.place;
|
|
178
|
+
if (place === undefined || pointers.length === 0) return false;
|
|
179
|
+
const pointed = pointedParagraphs(text.text, place.paragraph, pointers);
|
|
180
|
+
return bounds.some(
|
|
181
|
+
(bound) =>
|
|
182
|
+
bound.place.article === place.article &&
|
|
183
|
+
bound.place.paragraph !== place.paragraph &&
|
|
184
|
+
bound.act === act.toLowerCase() &&
|
|
185
|
+
(pointed.includes(bound.place.paragraph) || pointedParagraphs(bound.text, bound.place.paragraph, pointers).includes(place.paragraph)),
|
|
186
|
+
);
|
|
187
|
+
};
|
|
188
|
+
|
|
150
189
|
/**
|
|
151
190
|
* Each duty to act at a point in time whose sentence, and the rest of whose line, states no limit, holds no vague one, grants no right and states
|
|
152
|
-
* no amount, when more sentences of the document state a limit than hold such a duty: these duties are then the
|
|
191
|
+
* no amount, and whose article times its act in a paragraph one of the two points at, when more sentences of the document state a limit than hold such a duty: these duties are then the
|
|
153
192
|
* document's minority.
|
|
154
193
|
*/
|
|
155
194
|
export const untimedDuties = (texts: readonly Text[], words: DutyWords): UntimedDuty[] => {
|
|
156
195
|
const ends = lineEnds(texts);
|
|
196
|
+
const bounds = limitedBounds(texts, words);
|
|
157
197
|
const found = texts.flatMap((text, index) => {
|
|
158
198
|
const line = texts.slice(index, ends[index]);
|
|
159
199
|
if (line.some((later) => limited(later, words) || words.deferrals.some((deferral) => phraseIn(later.text, deferral)))) return [];
|
|
@@ -161,6 +201,7 @@ export const untimedDuties = (texts: readonly Text[], words: DutyWords): Untimed
|
|
|
161
201
|
const act = actIn(text.text, words);
|
|
162
202
|
if (act === undefined || (LATIN.test(act.act) && !isWordStart(text.text, act.at))) return [];
|
|
163
203
|
if (text.timedActs?.some((timed) => timed.toLowerCase() === act.act.toLowerCase()) === true) return [];
|
|
204
|
+
if (timedInArticle(text, act.act, bounds, words.paragraphPointers ?? [])) return [];
|
|
164
205
|
return [{ offset: text.start + act.at, act: text.text.slice(act.at, act.at + act.act.length) }];
|
|
165
206
|
});
|
|
166
207
|
const limitedSentences = texts.filter((text) => statesLimit(text, words)).length;
|
|
@@ -185,14 +226,36 @@ const timedActsReader = (doc: ProseDocument): ((offset: number) => string[]) =>
|
|
|
185
226
|
return (offset) => actsTimedAt(doc.source, units, offset, deadlines, phraseIn);
|
|
186
227
|
};
|
|
187
228
|
|
|
229
|
+
const within = (span: Span, offset: number): boolean => offset >= span.start && offset < span.end;
|
|
230
|
+
|
|
231
|
+
/** The paragraph's number: its item's label among the article's own items (2, 2), or 1 for the article's first, unnumbered text. */
|
|
232
|
+
const paragraphOf = (article: StructureNode, offset: number): number | undefined => {
|
|
233
|
+
const item = article.children.find((child) => child.kind === "item" && within(child.span, offset));
|
|
234
|
+
if (item === undefined) return 1;
|
|
235
|
+
const label = Number(String(item.attrs["label"] ?? "").normalize("NFKC"));
|
|
236
|
+
return Number.isInteger(label) && label > 0 ? label : undefined;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/** Where a sentence stands: its innermost article and the paragraph in it. */
|
|
240
|
+
const placeReader = (doc: ProseDocument): ((offset: number) => Place | undefined) => {
|
|
241
|
+
const articles = doc.structure === undefined ? [] : inDocumentOrder(doc.structure).filter((node) => node.kind === "article");
|
|
242
|
+
return (offset) => {
|
|
243
|
+
const article = articles.filter((node) => within(node.span, offset)).at(-1);
|
|
244
|
+
const paragraph = article === undefined ? undefined : paragraphOf(article, offset);
|
|
245
|
+
return article === undefined || paragraph === undefined ? undefined : { article: article.span.start, paragraph };
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
|
|
188
249
|
export const obligationWithoutDeadline: Detector = (doc): Finding[] => {
|
|
189
250
|
const timedActs = timedActsReader(doc);
|
|
251
|
+
const placeAt = placeReader(doc);
|
|
190
252
|
return untimedDuties(
|
|
191
253
|
doc.sentences.map((sentence, index) => ({
|
|
192
254
|
start: sentence.span.start,
|
|
193
255
|
text: sentence.text,
|
|
194
256
|
sameLine: index > 0 && !doc.source.slice(doc.sentences[index - 1]?.span.end ?? 0, sentence.span.start).includes("\n"),
|
|
195
257
|
timedActs: timedActs(sentence.span.start),
|
|
258
|
+
place: placeAt(sentence.span.start),
|
|
196
259
|
})),
|
|
197
260
|
{
|
|
198
261
|
acts: patternsOf(doc, "timed-duty"),
|
|
@@ -205,6 +268,7 @@ export const obligationWithoutDeadline: Detector = (doc): Finding[] => {
|
|
|
205
268
|
deferrals: patternsOf(doc, "duty-terms-elsewhere"),
|
|
206
269
|
permissions: doc.lexicons["deadline-permission"] ?? [],
|
|
207
270
|
currencies: doc.lexicons["currency-notation"] ?? [],
|
|
271
|
+
paragraphPointers: doc.lexicons["paragraph-pointer"] ?? [],
|
|
208
272
|
},
|
|
209
273
|
).map((duty) => ({
|
|
210
274
|
rule: "obligation-without-deadline",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { LexiconEntry, ProseDocument, Sentence, Token } from "../plugin.ts";
|
|
2
2
|
import { escapeRegExp } from "../orthography.ts";
|
|
3
3
|
import { entryRanges, type TokenRange } from "./lexicon-match.ts";
|
|
4
|
+
import { inDocumentOrder } from "../structure/issues.ts";
|
|
4
5
|
|
|
5
6
|
// A word that leaves a list open (等, etc.) is also part of names a document gives itself: 「業務執行取締役等」,
|
|
6
7
|
// 銀行等(…をいう。), the head of a definition item (四の二 親会社等 …をいう。), and longer nouns built on them
|
|
@@ -43,7 +44,13 @@ type QuotedName = { readonly name: string; readonly at: readonly number[] };
|
|
|
43
44
|
* The names a document gives that contain an open-end word: the ones it quotes, the ones it defines in an aside right
|
|
44
45
|
* after them (whole, as written there), and the heads of its definition items (which may run on into the definition).
|
|
45
46
|
*/
|
|
46
|
-
export type OpenEndNames = {
|
|
47
|
+
export type OpenEndNames = {
|
|
48
|
+
readonly quoted: readonly QuotedName[];
|
|
49
|
+
readonly defined: ReadonlySet<string>;
|
|
50
|
+
readonly heads: readonly string[];
|
|
51
|
+
/** Every term the document defines (「秘密情報」): the word right after one (秘密情報等) widens a named thing, not an open list. */
|
|
52
|
+
readonly terms: ReadonlySet<string>;
|
|
53
|
+
};
|
|
47
54
|
|
|
48
55
|
const attached = (left: Token | undefined, right: Token | undefined): boolean =>
|
|
49
56
|
left !== undefined && right !== undefined && left.span.end === right.span.start;
|
|
@@ -129,12 +136,19 @@ const quotedNames = (source: string, words: readonly LexiconEntry[]): QuotedName
|
|
|
129
136
|
return at.length === 0 ? [] : [{ name, at }];
|
|
130
137
|
});
|
|
131
138
|
|
|
139
|
+
const definedTerms = (doc: ProseDocument): Set<string> =>
|
|
140
|
+
new Set(
|
|
141
|
+
doc.structure === undefined
|
|
142
|
+
? []
|
|
143
|
+
: inDocumentOrder(doc.structure).flatMap((node) => (node.kind === "definition" && typeof node.attrs["term"] === "string" ? [node.attrs["term"]] : [])),
|
|
144
|
+
);
|
|
145
|
+
|
|
132
146
|
/** The names a document gives that contain an open-end word. statements: the language's words of a definition (をいう, means). */
|
|
133
147
|
export const openEndNames = (doc: ProseDocument, words: readonly LexiconEntry[], statements: readonly string[]): OpenEndNames => {
|
|
134
148
|
const occurrences = doc.sentences.flatMap((sentence) => words.flatMap((word) => occurrencesIn(sentence, word)));
|
|
135
149
|
const defined = occurrences.filter((occurrence) => definedInAside(doc.source, occurrence, statements)).map((occurrence) => nounOf(doc.source, occurrence));
|
|
136
150
|
const heads = occurrences.filter((occurrence) => headsItem(doc.source, occurrence, statements)).map((occurrence) => nounOf(doc.source, occurrence));
|
|
137
|
-
return { quoted: quotedNames(doc.source, words), defined: new Set(defined), heads: [...new Set(heads)] };
|
|
151
|
+
return { quoted: quotedNames(doc.source, words), defined: new Set(defined), heads: [...new Set(heads)], terms: definedTerms(doc) };
|
|
138
152
|
};
|
|
139
153
|
|
|
140
154
|
/** Whether a quoted name holds this occurrence: the text around it reads the whole name (当該責任追及等 holds 「責任追及等」). */
|
|
@@ -152,8 +166,13 @@ const partsHoldingWord = (source: string, occurrence: Occurrence): string[] => {
|
|
|
152
166
|
return starts.flatMap((start) => ends.map((end) => source.slice(start, end)));
|
|
153
167
|
};
|
|
154
168
|
|
|
169
|
+
/** Whether the word follows a defined term written whole (秘密情報等 where 「秘密情報」 is defined). */
|
|
170
|
+
const followsTerm = (source: string, occurrence: Occurrence, terms: ReadonlySet<string>): boolean =>
|
|
171
|
+
occurrence.tokens.slice(occurrence.first, occurrence.range.start).some((token) => terms.has(source.slice(token.span.start, occurrence.start)));
|
|
172
|
+
|
|
155
173
|
const isNamed = (source: string, occurrence: Occurrence, names: OpenEndNames): boolean =>
|
|
156
174
|
inQuotedName(source, occurrence, names.quoted) ||
|
|
175
|
+
followsTerm(source, occurrence, names.terms) ||
|
|
157
176
|
partsHoldingWord(source, occurrence).some((part) => names.defined.has(part) || names.heads.some((head) => head.startsWith(part)));
|
|
158
177
|
|
|
159
178
|
/** Whether the words around an occurrence bound its list; range: the tokens the word covers. */
|
|
@@ -27,24 +27,26 @@ import {
|
|
|
27
27
|
} from "../word-use.ts";
|
|
28
28
|
import { titleCaseNameRuns } from "../title-case-name.ts";
|
|
29
29
|
import { withoutQuotedSpellings, type Quoted } from "../quoted-spelling.ts";
|
|
30
|
+
import { teFormOf, withTeFormFullVerbs, type TeForm } from "../te-form-helper.ts";
|
|
30
31
|
import { citedSpans, isOpenIn, namesOf, patternsOf, type IsOpen, type Names } from "./orthographic-variant-open.ts";
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* A word found in the document: where it is, which sentence it is in, its key and spelling, how it is written when that differs, and
|
|
34
35
|
* whether it is written onto the noun after it (取扱事業者).
|
|
35
36
|
*/
|
|
36
|
-
type Placed = KeyedWord &
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
type Placed = KeyedWord &
|
|
38
|
+
TeForm & {
|
|
39
|
+
readonly sentence: Sentence;
|
|
40
|
+
readonly offset: number;
|
|
41
|
+
readonly shown?: string;
|
|
42
|
+
readonly compoundHead?: boolean;
|
|
43
|
+
/** Where a run of words ends (タイヤレバー). */
|
|
44
|
+
readonly end?: number;
|
|
45
|
+
/** Whether a Latin word stands in a name of capitalised words (the Interagency Group) or in a cited work. */
|
|
46
|
+
readonly quoted?: Quoted | undefined;
|
|
47
|
+
/** The name a word stands in, as written. */
|
|
48
|
+
readonly name?: string | undefined;
|
|
49
|
+
};
|
|
48
50
|
|
|
49
51
|
/** Parts of speech that carry a word of their own. Particles and endings are written one way by the grammar. */
|
|
50
52
|
const CONTENT = new Set(["NOUN", "VERB", "ADJ", "ADV", "PRON", "CCONJ", "DET"]);
|
|
@@ -155,11 +157,12 @@ const readingWords = (sentence: Sentence, isOpen: IsOpen, skips: Skips): Placed[
|
|
|
155
157
|
if (inRun.has(at)) return [];
|
|
156
158
|
const next = tokens[at + 1];
|
|
157
159
|
const token = asNounWhereNominal(written, next, skips.phraseSuffixes, skips.nouns);
|
|
158
|
-
const
|
|
160
|
+
const word = { token, previous: tokens[at - 1], before: tokens[at - 2], following: tokens.slice(at + 1, at + 3) };
|
|
161
|
+
const key = readingKeyOf(word, skips);
|
|
159
162
|
const local = token.span.start - sentence.span.start;
|
|
160
163
|
if (key === undefined || token.lemma === undefined || !isOpen(local, local + token.surface.length)) return [];
|
|
161
164
|
const compoundHead = isCompoundHead(token, tokens, at, skips.phraseSuffixes);
|
|
162
|
-
return [{ key, spelling: token.lemma, sentence, offset: token.span.start, compoundHead }];
|
|
165
|
+
return [{ key, spelling: token.lemma, sentence, offset: token.span.start, compoundHead, ...teFormOf(word, tokens, at) }];
|
|
163
166
|
}),
|
|
164
167
|
];
|
|
165
168
|
};
|
|
@@ -319,7 +322,9 @@ const cellPlace = (cell: TableCell, names: Names): Place => {
|
|
|
319
322
|
|
|
320
323
|
/** The odd spellings among places that speak in one voice. */
|
|
321
324
|
const findingsIn = (placed: readonly Place[], skips: Skips, { isWord, nameJoiners }: Reading, limit: number): Finding[] => {
|
|
322
|
-
const reading = byKanji(
|
|
325
|
+
const reading = byKanji(
|
|
326
|
+
withTeFormFullVerbs(placed.flatMap(({ sentence, isOpen }) => readingWords(withCutNounsJoined(sentence, skips.nouns), isOpen, skips))),
|
|
327
|
+
);
|
|
323
328
|
const katakana = placed.flatMap(({ sentence, isOpen }) => katakanaWords(sentence, isOpen));
|
|
324
329
|
const runs = placed.flatMap(({ sentence, isOpen }) => katakanaRunWords(sentence, isOpen));
|
|
325
330
|
const latin = withoutQuotedSpellings(
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { escapeRegExp } from "../orthography.ts";
|
|
2
|
+
import type { LexiconEntry } from "../plugin.ts";
|
|
3
|
+
|
|
4
|
+
// A sentence that points at another paragraph of its own article: the one before it (前項), or one by its number
|
|
5
|
+
// (本条1項). The words come from the language's paragraph-pointer word list: an entry in the group "previous" points at
|
|
6
|
+
// the paragraph before, and one with … in it is a frame whose … is the paragraph's number. Pure.
|
|
7
|
+
|
|
8
|
+
const FRAME = "…";
|
|
9
|
+
const PREVIOUS = "previous";
|
|
10
|
+
const NUMBER = "([0-90-9]+)";
|
|
11
|
+
const FULL_WIDTH_OFFSET = 0xfee0;
|
|
12
|
+
|
|
13
|
+
const halfWidth = (digits: string): string =>
|
|
14
|
+
[...digits].map((char) => (/[0-9]/u.test(char) ? String.fromCharCode(char.charCodeAt(0) - FULL_WIDTH_OFFSET) : char)).join("");
|
|
15
|
+
|
|
16
|
+
const numberedIn = (text: string, frame: string): number[] => {
|
|
17
|
+
const pattern = new RegExp(frame.split(FRAME).map(escapeRegExp).join(NUMBER), "gu");
|
|
18
|
+
return [...text.matchAll(pattern)].map((match) => Number(halfWidth(match[1] ?? "")));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** The paragraphs of its article a sentence in paragraph own points at. */
|
|
22
|
+
export const pointedParagraphs = (text: string, own: number, pointers: readonly LexiconEntry[]): number[] =>
|
|
23
|
+
pointers
|
|
24
|
+
.filter((entry) => entry.pattern !== "")
|
|
25
|
+
.flatMap((entry) => {
|
|
26
|
+
if (entry.pattern.includes(FRAME)) return numberedIn(text, entry.pattern);
|
|
27
|
+
return entry.group === PREVIOUS && text.includes(entry.pattern) ? [own - 1] : [];
|
|
28
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Detector, DetectorOptions, Finding, Lexicon, LexiconEntry, ProseDocument, Sentence } from "../plugin.ts";
|
|
2
|
-
import { entryEnds, entryIn } from "./lexicon-match.ts";
|
|
3
|
-
import {
|
|
2
|
+
import { entryEnds, entryIn, entryOpens } from "./lexicon-match.ts";
|
|
3
|
+
import { externalLinkTitleSpans } from "../link-title.ts";
|
|
4
|
+
import { mentionCuesOf, onlyInTitles, onlyMentioned } from "./mentioned-phrase.ts";
|
|
4
5
|
import { closingSentences } from "../closing-paragraph.ts";
|
|
5
6
|
import { quotedPattern } from "./quoted-pattern.ts";
|
|
6
7
|
|
|
@@ -22,9 +23,12 @@ type Hit = { readonly sentence: Sentence; readonly matched: string };
|
|
|
22
23
|
/** Whether the entry's words in the sentence count as a use. phrase-match counts every one. */
|
|
23
24
|
type IsUsed = (sentence: Sentence, entry: LexiconEntry) => boolean;
|
|
24
25
|
|
|
26
|
+
/** An entry marked opens counts only at the head of the sentence: 「近年、」 opens a stock opening, 「その後、近年の」 is a plain word. */
|
|
27
|
+
const writtenIn = (sentence: Sentence, entry: LexiconEntry): boolean => (entry.opens === true ? entryOpens(sentence, entry) : entryIn(sentence, entry));
|
|
28
|
+
|
|
25
29
|
const hitsIn = (sentences: readonly Sentence[], lexicon: Lexicon, isUsed: IsUsed = () => true): Hit[] =>
|
|
26
30
|
sentences.flatMap((sentence) => {
|
|
27
|
-
const matched = lexicon.find((entry) =>
|
|
31
|
+
const matched = lexicon.find((entry) => writtenIn(sentence, entry) && isUsed(sentence, entry));
|
|
28
32
|
return matched === undefined ? [] : [{ sentence, matched: quotedPattern(matched.pattern) }];
|
|
29
33
|
});
|
|
30
34
|
|
|
@@ -58,10 +62,14 @@ export const phraseMatchWhere = (doc: ProseDocument, options: DetectorOptions, i
|
|
|
58
62
|
return hits.length < options.limit ? [] : findingsOf(hits, options.limit);
|
|
59
63
|
};
|
|
60
64
|
|
|
61
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* phrase-match の、言葉として名指しただけの言い回し(the phrase "…", 「…」という言い方)を数えない版(mentioned-phrase.ts)。
|
|
67
|
+
* 参考文献のリンクに写した外のページの題名([文章の極意は…](https://…))の言い回しも、書き手の言葉ではないので数えない。
|
|
68
|
+
*/
|
|
62
69
|
export const phraseInUse: Detector = (doc, options): Finding[] => {
|
|
63
70
|
const cues = mentionCuesOf(doc.lexicons["mention-cue"] ?? []);
|
|
64
|
-
const
|
|
71
|
+
const titles = externalLinkTitleSpans(doc.source, doc.links);
|
|
72
|
+
const hits = phraseHits(doc, options, (sentence, entry) => !onlyMentioned(sentence, entry, cues) && !onlyInTitles(sentence, entry, titles));
|
|
65
73
|
return hits.length < options.limit ? [] : findingsOf(hits, options.limit);
|
|
66
74
|
};
|
|
67
75
|
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Lexicon } from "../plugin.ts";
|
|
2
|
+
import { holdsWordAt } from "./template-sections.ts";
|
|
3
|
+
|
|
4
|
+
/** Lexicon group of placeholder-word: a word that opens a line giving an example to copy (Example:, Helpful:, 例:). */
|
|
5
|
+
export const EXAMPLE_LEAD = "example-lead";
|
|
6
|
+
|
|
7
|
+
/** The text of a blank's line before it and after it. */
|
|
8
|
+
export type LineAround = { readonly before: string; readonly after: string };
|
|
9
|
+
|
|
10
|
+
export const lineAround = (source: string, start: number, end: number): LineAround => ({
|
|
11
|
+
before: source.slice(source.lastIndexOf("\n", start - 1) + 1, start),
|
|
12
|
+
after: source.slice(end).split("\n")[0] ?? "",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
/** A run of underscores is the line a form is signed or filled on; a bracket beside it is the caption of that line. */
|
|
16
|
+
const FILL_LINE = "___";
|
|
17
|
+
const SPACE_OR_EMPHASIS = /[\s*]/u;
|
|
18
|
+
|
|
19
|
+
/** text without the spaces and emphasis marks around it. */
|
|
20
|
+
const bare = (text: string): string => {
|
|
21
|
+
const chars = [...text];
|
|
22
|
+
const first = chars.findIndex((char) => !SPACE_OR_EMPHASIS.test(char));
|
|
23
|
+
const last = chars.findLastIndex((char) => !SPACE_OR_EMPHASIS.test(char));
|
|
24
|
+
return first < 0 ? "" : chars.slice(first, last + 1).join("");
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** The bracket names the blank a form leaves to fill by hand ("________ [Name of New Employer]"). */
|
|
28
|
+
export const captionsFillLine = (line: LineAround): boolean => bare(line.before).endsWith(FILL_LINE) || bare(line.after).startsWith(FILL_LINE);
|
|
29
|
+
|
|
30
|
+
/** A list mark or emphasis before the line's first word. */
|
|
31
|
+
const LINE_LEAD = /^\s*(?:[-*+]\s+|\d+[.)]\s+)?[*_]*/u;
|
|
32
|
+
const COLONS = /[::]/u;
|
|
33
|
+
const OPENING_QUOTES: ReadonlySet<string> = new Set(["“", '"', "「", "『"]);
|
|
34
|
+
const CLOSING_QUOTES = /[”"」』]/u;
|
|
35
|
+
|
|
36
|
+
/** After the lead: a colon, then a quotation that opens and has not closed yet before the blank. */
|
|
37
|
+
const opensQuoteAfterColon = (rest: string): boolean => {
|
|
38
|
+
const colon = rest.search(COLONS);
|
|
39
|
+
if (colon < 0) return false;
|
|
40
|
+
const quoted = rest.slice(colon + 1).trimStart();
|
|
41
|
+
return OPENING_QUOTES.has(quoted.charAt(0)) && !CLOSING_QUOTES.test(quoted.slice(1));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** The blank is inside a quotation a line offers as an example ("Helpful: “See the link [insert link name] …”"). */
|
|
45
|
+
export const insideQuotedExample = (line: LineAround, leads: Lexicon): boolean => {
|
|
46
|
+
const text = line.before.slice(LINE_LEAD.exec(line.before)?.[0].length ?? 0);
|
|
47
|
+
const lower = text.toLowerCase();
|
|
48
|
+
const lead = leads.find((word) => lower.startsWith(word.pattern.toLowerCase()) && holdsWordAt(lower, word.pattern.toLowerCase(), 0));
|
|
49
|
+
return lead !== undefined && opensQuoteAfterColon(text.slice(lead.pattern.length));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/** A field label of a filing form at the head of a line, and the value written after it on that line (【氏名】 followed by a name). */
|
|
53
|
+
const LIST_MARK = /^\s*(?:[-*+]\s+)?/u;
|
|
54
|
+
const FIELD_LABEL = /^(?:【[^【】\n]{1,30}】|[[^[]\n]{1,30}])/u;
|
|
55
|
+
const LEADING_SPACES = /^[ \t\u3000]+/u;
|
|
56
|
+
const VALUE_START = /^[\p{Script=Han}\p{Script=Katakana}\p{Script=Latin}\p{N}]/u;
|
|
57
|
+
const BLANK_MARK_START = /^[○〇◯△]/u;
|
|
58
|
+
|
|
59
|
+
const isFilledValue = (value: string, blankSuffixes: Lexicon): boolean =>
|
|
60
|
+
VALUE_START.test(value) && !BLANK_MARK_START.test(value) && !blankSuffixes.some((word) => value.startsWith(word.pattern));
|
|
61
|
+
|
|
62
|
+
/** The label at the head of a line, when a filled value follows it on that line. */
|
|
63
|
+
const filledLabelOf = (line: string, blankSuffixes: Lexicon): string[] => {
|
|
64
|
+
const rest = line.replace(LIST_MARK, "");
|
|
65
|
+
const label = FIELD_LABEL.exec(rest)?.[0];
|
|
66
|
+
if (label === undefined) return [];
|
|
67
|
+
return isFilledValue(rest.slice(label.length).replace(LEADING_SPACES, ""), blankSuffixes) ? [label] : [];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/** The labels a document fills in somewhere: elsewhere the same 【氏名】 names that field of the form, not a blank. */
|
|
71
|
+
export const filledFieldLabels = (source: string, blankSuffixes: Lexicon): ReadonlySet<string> =>
|
|
72
|
+
new Set(source.split("\n").flatMap((line) => filledLabelOf(line, blankSuffixes)));
|
|
@@ -87,7 +87,7 @@ const lineMarkerSpans = (text: string, markers: Lexicon, labels: Lexicon): Span[
|
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
/** Lexicon groups of placeholder-word for a run of blank marks (〇〇): the word after it, the word before it, and a unit after it. */
|
|
90
|
-
const BLANK_SUFFIX = "blank-suffix";
|
|
90
|
+
export const BLANK_SUFFIX = "blank-suffix";
|
|
91
91
|
const BLANK_PREFIX = "blank-prefix";
|
|
92
92
|
const BLANK_UNIT = "blank-unit";
|
|
93
93
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// redundant-expression: phrase-match over the language's pairs, except a pair whose last word starts a hyphenated compound
|
|
2
|
+
// ("true fact-check" is a fact-check whose verdict is true, not a true fact).
|
|
3
|
+
import type { Detector, LexiconEntry, Sentence, Token } from "../plugin.ts";
|
|
4
|
+
import { entryRanges } from "./lexicon-match.ts";
|
|
5
|
+
import { phraseMatchWhere } from "./phrase-match.ts";
|
|
6
|
+
|
|
7
|
+
const HYPHENS: ReadonlySet<string> = new Set(["-", "‐"]);
|
|
8
|
+
|
|
9
|
+
const joined = (left: Token | undefined, right: Token | undefined): boolean => left !== undefined && right !== undefined && left.span.end === right.span.start;
|
|
10
|
+
|
|
11
|
+
/** The token at end is a hyphen that ties the word before it to the next word, with no space on either side. */
|
|
12
|
+
export const hyphenatedOnward = (tokens: readonly Token[], end: number): boolean => {
|
|
13
|
+
const hyphen = tokens[end];
|
|
14
|
+
const next = tokens[end + 1];
|
|
15
|
+
return hyphen !== undefined && HYPHENS.has(hyphen.surface) && joined(tokens[end - 1], hyphen) && joined(hyphen, next) && /^\p{L}/u.test(next?.surface ?? "");
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** Some place of the pair in the sentence ends a phrase rather than running on into a compound. Without tokens every place counts. */
|
|
19
|
+
const standsAsPair = (sentence: Sentence, entry: LexiconEntry): boolean => {
|
|
20
|
+
const tokens = sentence.tokens ?? [];
|
|
21
|
+
const ranges = entryRanges(sentence, entry);
|
|
22
|
+
return ranges.length === 0 || ranges.some((range) => !hyphenatedOnward(tokens, range.end));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const redundantPair: Detector = (doc, options) => phraseMatchWhere(doc, options, standsAsPair);
|
|
@@ -21,6 +21,7 @@ export const REQUEST_LEXICONS = {
|
|
|
21
21
|
prohibition: "request-prohibition",
|
|
22
22
|
deadlineSection: "request-deadline-section",
|
|
23
23
|
noDeadlineTitle: "request-no-deadline-title",
|
|
24
|
+
decision: "request-decision",
|
|
24
25
|
} as const;
|
|
25
26
|
|
|
26
27
|
type Words = Readonly<Record<keyof typeof REQUEST_LEXICONS, readonly string[]>>;
|
|
@@ -44,6 +45,7 @@ const wordsOf = (doc: ProseDocument): Words => ({
|
|
|
44
45
|
prohibition: patternsOf(doc.lexicons[REQUEST_LEXICONS.prohibition]),
|
|
45
46
|
deadlineSection: patternsOf(doc.lexicons[REQUEST_LEXICONS.deadlineSection]),
|
|
46
47
|
noDeadlineTitle: patternsOf(doc.lexicons[REQUEST_LEXICONS.noDeadlineTitle]),
|
|
48
|
+
decision: patternsOf(doc.lexicons[REQUEST_LEXICONS.decision]),
|
|
47
49
|
});
|
|
48
50
|
|
|
49
51
|
/** How far apart, in characters, the action word and the request ending may be: the action must be what is requested. */
|
|
@@ -224,14 +226,15 @@ const withoutDates = (source: string, span: Span, inside: readonly Span[]): stri
|
|
|
224
226
|
source.slice(span.start, span.end),
|
|
225
227
|
);
|
|
226
228
|
|
|
229
|
+
/** A date with a deadline word, or with the decision step (a schedule's 「12月:経営会議にて承認」 says when the decision is made). */
|
|
227
230
|
const statesDeadline = (source: string, sentence: Sentence, words: Words, dates: readonly Span[]): boolean => {
|
|
228
231
|
const inside = datesInside(sentence.span, dates);
|
|
229
|
-
return inside.length > 0 && containsAny(withoutDates(source, sentence.span, inside), words.deadline);
|
|
232
|
+
return inside.length > 0 && containsAny(withoutDates(source, sentence.span, inside), [...words.deadline, ...words.decision]);
|
|
230
233
|
};
|
|
231
234
|
|
|
232
235
|
/**
|
|
233
|
-
* The section headed only by a deadline-section word (a notice's "DATES:", "2. Deadline"
|
|
234
|
-
* deadline word: the document gives its deadline once there. -1 without one.
|
|
236
|
+
* The section headed only by a deadline-section word (a notice's "DATES:", "2. Deadline", a proposal's schedule) that
|
|
237
|
+
* states a date with a deadline or decision word: the document gives its deadline once there. -1 without one.
|
|
235
238
|
*/
|
|
236
239
|
const documentDeadlineSection = (source: string, sections: readonly Section[], words: Words, dates: readonly Span[]): number =>
|
|
237
240
|
sections.findIndex(
|
|
@@ -196,7 +196,17 @@ export const openerRuns = (sentences: readonly Sentence[], lexicon: Lexicon, not
|
|
|
196
196
|
)
|
|
197
197
|
.filter((run) => run.length > 0);
|
|
198
198
|
|
|
199
|
-
|
|
199
|
+
/** The opening words that, repeated at the head of the next sentence, carry the same subject on (It … It …). */
|
|
200
|
+
export const CONTINUING_LEXICON = "demonstrative-continuing";
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* How many sentences of the run send the reader back: a sentence opening with the same continuing word as the one before
|
|
204
|
+
* keeps that sentence's subject, so a chain of them counts once.
|
|
205
|
+
*/
|
|
206
|
+
const runCount = (run: readonly Opened[], continuing: ReadonlySet<string>): number =>
|
|
207
|
+
run.filter((opened, at) => !(opened.opener !== undefined && continuing.has(opened.opener) && run[at - 1]?.opener === opened.opener)).length;
|
|
208
|
+
|
|
209
|
+
const runFinding = (run: readonly Opened[], count: number, options: DetectorOptions): Finding => {
|
|
200
210
|
const first = run[0];
|
|
201
211
|
return {
|
|
202
212
|
rule: "",
|
|
@@ -204,7 +214,7 @@ const runFinding = (run: readonly Opened[], options: DetectorOptions): Finding =
|
|
|
204
214
|
line: 0,
|
|
205
215
|
column: 0,
|
|
206
216
|
quote: run.map(({ sentence }) => sentence.text.trim()).join(""),
|
|
207
|
-
values: { word: first?.opener ?? "", count
|
|
217
|
+
values: { word: first?.opener ?? "", count, limit: options.limit, offset: first?.sentence.span.start ?? 0 },
|
|
208
218
|
};
|
|
209
219
|
};
|
|
210
220
|
|
|
@@ -212,9 +222,11 @@ const runFinding = (run: readonly Opened[], options: DetectorOptions): Finding =
|
|
|
212
222
|
export const openerRun: Detector = (doc, options): Finding[] => {
|
|
213
223
|
const lexicon = options.lexicon ?? [];
|
|
214
224
|
const notOpeners = doc.lexicons[NOT_OPENER_LEXICON] ?? [];
|
|
225
|
+
const continuing = new Set((doc.lexicons[CONTINUING_LEXICON] ?? []).map((entry) => entry.pattern));
|
|
215
226
|
return doc.paragraphs.flatMap((paragraph) =>
|
|
216
227
|
openerRuns(paragraph.sentences, lexicon, notOpeners)
|
|
217
|
-
.
|
|
218
|
-
.
|
|
228
|
+
.map((run) => ({ run, count: runCount(run, continuing) }))
|
|
229
|
+
.filter(({ count }) => count > options.limit)
|
|
230
|
+
.map(({ run, count }) => runFinding(run, count, options)),
|
|
219
231
|
);
|
|
220
232
|
};
|
package/src/detectors/signals.ts
CHANGED
|
@@ -49,9 +49,19 @@ const density = (doc: ProseDocument, count: number): number => {
|
|
|
49
49
|
* 件数ではなく密度で見る。長い文書ほど当たるのを避けるため(bold-density と同じ)。
|
|
50
50
|
*/
|
|
51
51
|
const EMOJI = /\p{Extended_Pictographic}|[←-⇿☀-➿]/gu;
|
|
52
|
+
const ARROW = /^[←-⇿]$/u;
|
|
53
|
+
const WORD_END = /[\p{L}\p{N}*_)\]"'’”]$/u;
|
|
54
|
+
const WORD_START = /^[\p{L}\p{N}*_(["'‘“]/u;
|
|
55
|
+
|
|
56
|
+
/** 語と語の間の矢印(Settings → Printers、A→B)。メニューの道筋や流れを示す区切りで、飾りではない。行頭の矢印(→ 詳しくはこちら)は飾り。 */
|
|
57
|
+
const isArrowBetween = (hit: Hit): boolean => {
|
|
58
|
+
const text = hit.sentence.text;
|
|
59
|
+
const at = hit.offset - hit.sentence.span.start;
|
|
60
|
+
return ARROW.test(text[at] ?? "") && WORD_END.test(text.slice(0, at).trimEnd()) && WORD_START.test(text.slice(at + 1).trimStart());
|
|
61
|
+
};
|
|
52
62
|
|
|
53
63
|
export const emojiDensity: Detector = (doc, options): Finding[] => {
|
|
54
|
-
const hits = findIn(doc, EMOJI);
|
|
64
|
+
const hits = findIn(doc, EMOJI).filter((hit) => !isArrowBetween(hit));
|
|
55
65
|
const first = hits[0];
|
|
56
66
|
const rate = density(doc, hits.length);
|
|
57
67
|
if (wordsOf(doc) < MIN_DOCUMENT_LENGTH[doc.lengthUnit] || first === undefined || rate <= options.limit) return [];
|
|
@@ -336,6 +336,7 @@ const shareWordsOf = (doc: ProseDocument): ShareWords => ({
|
|
|
336
336
|
exceptions: (doc.lexicons["share-exception"] ?? []).map((entry) => entry.pattern),
|
|
337
337
|
rests: (doc.lexicons["share-rest"] ?? []).map((entry) => entry.pattern),
|
|
338
338
|
changes: (doc.lexicons["change-direction"] ?? []).map((entry) => entry.pattern),
|
|
339
|
+
joiners: [...(doc.lexicons["range-connector"] ?? []), ...(doc.lexicons["quantity-range-word"] ?? [])].map((entry) => entry.pattern),
|
|
339
340
|
units: (doc.lexicons["percent-unit"] ?? []).map((entry) => entry.pattern),
|
|
340
341
|
totalLabels: (doc.lexicons["total-label"] ?? []).map((entry) => entry.pattern),
|
|
341
342
|
});
|
|
@@ -4,7 +4,7 @@ import type { Detector, DetectorOptions, Finding, LengthUnit, Paragraph, ProseDo
|
|
|
4
4
|
import { dateStampIndexes, stampCandidates } from "../date-stamp.ts";
|
|
5
5
|
import { inDocumentOrder } from "../structure/issues.ts";
|
|
6
6
|
import { preambleParagraphs } from "../preamble-paragraphs.ts";
|
|
7
|
-
import { isTooLongParagraph, labelledBlocks, opensWithFusedHeading } from "../paragraph-length.ts";
|
|
7
|
+
import { isTooLongParagraph, labelledBlocks, lostLineBreaks, opensWithFusedHeading } from "../paragraph-length.ts";
|
|
8
8
|
import { bodySectionOf } from "../body-section.ts";
|
|
9
9
|
import { threeShare } from "../rule-of-three.ts";
|
|
10
10
|
import { isInterview, sectionLevels } from "../section-levels.ts";
|
|
@@ -38,7 +38,7 @@ const minimumCount = (options: DetectorOptions, name: string, fallback: number):
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
const DEFAULT_MIN_SECTIONS = 5;
|
|
41
|
-
const DEFAULT_MIN_PARAGRAPHS =
|
|
41
|
+
const DEFAULT_MIN_PARAGRAPHS = 9;
|
|
42
42
|
|
|
43
43
|
const uniformity = (doc: ProseDocument, values: readonly number[], span: { start: number }, limit: number, rule: string): Finding[] => {
|
|
44
44
|
const cv = coefficientOfVariation(values);
|
|
@@ -65,12 +65,12 @@ const sentenceSize = (sentence: Sentence, unit: LengthUnit): number =>
|
|
|
65
65
|
type Block = { readonly start: number; readonly sentences: readonly Sentence[] };
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
68
|
+
* 段落の中の、長さを測る文の組と、その頭の位置(最初の組は段落の頭)。見出しが本文に溶けた段落や、文どうしが空白なしでつながった段落(改行の落ちた文書)は測らない。
|
|
69
69
|
* 【】の見出しや段落番号だけの行で段落を割る。
|
|
70
70
|
*/
|
|
71
71
|
const measuredBlocks = (doc: ProseDocument, paragraph: Paragraph): Block[] => {
|
|
72
72
|
const text = doc.source.slice(paragraph.span.start, paragraph.span.end);
|
|
73
|
-
if (opensWithFusedHeading(text)) return [];
|
|
73
|
+
if (opensWithFusedHeading(text) || lostLineBreaks(paragraph.sentences)) return [];
|
|
74
74
|
return labelledBlocks(text, paragraph.span.start, paragraph.sentences).map((sentences, index) => ({
|
|
75
75
|
start: index === 0 ? paragraph.span.start : (sentences[0]?.span.start ?? paragraph.span.start),
|
|
76
76
|
sentences,
|
|
@@ -137,7 +137,8 @@ export const sectionUniformity: Detector = (doc, options): Finding[] => {
|
|
|
137
137
|
*/
|
|
138
138
|
export const ruleOfThree: Detector = (doc, options): Finding[] => {
|
|
139
139
|
const openWords = (doc.lexicons["list-continues"] ?? []).map((entry) => entry.pattern);
|
|
140
|
-
const
|
|
140
|
+
const sentenceStarts = doc.sentences.map((sentence) => sentence.span.start);
|
|
141
|
+
const found = threeShare(doc.source, doc.lists, openWords, options.limit, sentenceStarts);
|
|
141
142
|
if (found === undefined) return [];
|
|
142
143
|
return [
|
|
143
144
|
{
|
|
@@ -12,6 +12,8 @@ export type Context = {
|
|
|
12
12
|
readonly viewpoints: Lexicon;
|
|
13
13
|
/** 全体の部分を言う名詞(part・role・step)。 */
|
|
14
14
|
readonly parts: Lexicon;
|
|
15
|
+
/** 前に名指した名詞の代わりに立つ語(one・ones)。 */
|
|
16
|
+
readonly proForms: Lexicon;
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
/** 語彙表の語が最上級まで届く語の数。これより離れた動詞は、間に別の目的語や節がある。 */
|
|
@@ -33,6 +35,7 @@ export const contextOf = (lexicons: Readonly<Record<string, Lexicon>>): Context
|
|
|
33
35
|
referents: lexicons["superlative-referent"] ?? [],
|
|
34
36
|
viewpoints: lexicons["superlative-viewpoint"] ?? [],
|
|
35
37
|
parts: lexicons["superlative-part"] ?? [],
|
|
38
|
+
proForms: lexicons["superlative-pro-form"] ?? [],
|
|
36
39
|
});
|
|
37
40
|
|
|
38
41
|
const isPunct = (token: Token | undefined): boolean => token === undefined || token.pos === "PUNCT";
|
|
@@ -105,3 +108,12 @@ export const ranksParts = (tokens: readonly Token[], range: TokenRange, parts: L
|
|
|
105
108
|
const at = phraseEnd(tokens, range.end);
|
|
106
109
|
return at > range.end && isWord(tokens[at - 1], parts);
|
|
107
110
|
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 最上級の名詞が、前に名指した名詞の代わりの語か(ten topics … the best-scoring one)。比べている集まりは文章が先に
|
|
114
|
+
* 名指したもので、世の中のものと比べた主張ではない。名詞は最上級の修飾の後ろに来る(英語)。
|
|
115
|
+
*/
|
|
116
|
+
export const picksFromNamedSet = (tokens: readonly Token[], range: TokenRange, proForms: Lexicon): boolean => {
|
|
117
|
+
const at = phraseEnd(tokens, range.end);
|
|
118
|
+
return at > range.end && isWord(tokens[at - 1], proForms);
|
|
119
|
+
};
|