chaffjs 0.39.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +3 -2
- package/README.md +2 -1
- package/dist/ai-score/human-shares.d.ts.map +1 -1
- package/dist/ai-score/human-shares.js +1 -0
- package/dist/ai-score/human-shares.js.map +1 -1
- package/dist/alternative-words.d.ts +6 -0
- package/dist/alternative-words.d.ts.map +1 -1
- package/dist/alternative-words.js +10 -0
- package/dist/alternative-words.js.map +1 -1
- package/dist/closing-code.d.ts +8 -0
- package/dist/closing-code.d.ts.map +1 -0
- package/dist/closing-code.js +18 -0
- package/dist/closing-code.js.map +1 -0
- package/dist/date-format.d.ts +19 -1
- package/dist/date-format.d.ts.map +1 -1
- package/dist/date-format.js +41 -5
- package/dist/date-format.js.map +1 -1
- package/dist/detectors/acronym-context.d.ts +1 -1
- package/dist/detectors/acronym-context.d.ts.map +1 -1
- package/dist/detectors/acronym-context.js +3 -2
- package/dist/detectors/acronym-context.js.map +1 -1
- package/dist/detectors/acronym-mention.d.ts +5 -0
- package/dist/detectors/acronym-mention.d.ts.map +1 -1
- package/dist/detectors/acronym-mention.js +16 -0
- package/dist/detectors/acronym-mention.js.map +1 -1
- package/dist/detectors/acronym-name.d.ts +5 -0
- package/dist/detectors/acronym-name.d.ts.map +1 -1
- package/dist/detectors/acronym-name.js +15 -0
- package/dist/detectors/acronym-name.js.map +1 -1
- package/dist/detectors/blank-runs.d.ts +12 -0
- package/dist/detectors/blank-runs.d.ts.map +1 -0
- package/dist/detectors/blank-runs.js +27 -0
- package/dist/detectors/blank-runs.js.map +1 -0
- package/dist/detectors/bold-label.d.ts +3 -1
- package/dist/detectors/bold-label.d.ts.map +1 -1
- package/dist/detectors/bold-label.js +16 -6
- package/dist/detectors/bold-label.js.map +1 -1
- package/dist/detectors/capitalised-term.d.ts.map +1 -1
- package/dist/detectors/capitalised-term.js +28 -9
- package/dist/detectors/capitalised-term.js.map +1 -1
- package/dist/detectors/citation-string.d.ts +6 -0
- package/dist/detectors/citation-string.d.ts.map +1 -1
- package/dist/detectors/citation-string.js +52 -0
- package/dist/detectors/citation-string.js.map +1 -1
- package/dist/detectors/contraction-emphasis.d.ts +3 -0
- package/dist/detectors/contraction-emphasis.d.ts.map +1 -0
- package/dist/detectors/contraction-emphasis.js +24 -0
- package/dist/detectors/contraction-emphasis.js.map +1 -0
- package/dist/detectors/contraction-mention.d.ts +12 -1
- package/dist/detectors/contraction-mention.d.ts.map +1 -1
- package/dist/detectors/contraction-mention.js +39 -6
- package/dist/detectors/contraction-mention.js.map +1 -1
- package/dist/detectors/contraction-mix.d.ts +3 -0
- package/dist/detectors/contraction-mix.d.ts.map +1 -0
- package/dist/detectors/contraction-mix.js +69 -0
- package/dist/detectors/contraction-mix.js.map +1 -0
- package/dist/detectors/date-format.d.ts.map +1 -1
- package/dist/detectors/date-format.js +13 -1
- package/dist/detectors/date-format.js.map +1 -1
- package/dist/detectors/duplicate-definition.d.ts +3 -0
- package/dist/detectors/duplicate-definition.d.ts.map +1 -0
- package/dist/detectors/duplicate-definition.js +16 -0
- package/dist/detectors/duplicate-definition.js.map +1 -0
- package/dist/detectors/final-period-captions.d.ts +15 -0
- package/dist/detectors/final-period-captions.d.ts.map +1 -0
- package/dist/detectors/final-period-captions.js +61 -0
- package/dist/detectors/final-period-captions.js.map +1 -0
- package/dist/detectors/heading-sentences.d.ts +10 -0
- package/dist/detectors/heading-sentences.d.ts.map +1 -0
- package/dist/detectors/heading-sentences.js +32 -0
- package/dist/detectors/heading-sentences.js.map +1 -0
- package/dist/detectors/lexicon.d.ts +1 -2
- package/dist/detectors/lexicon.d.ts.map +1 -1
- package/dist/detectors/lexicon.js +5 -55
- package/dist/detectors/lexicon.js.map +1 -1
- package/dist/detectors/list-lead-in.d.ts +1 -1
- package/dist/detectors/list-lead-in.d.ts.map +1 -1
- package/dist/detectors/list-lead-in.js +31 -10
- package/dist/detectors/list-lead-in.js.map +1 -1
- package/dist/detectors/missing-final-period.d.ts.map +1 -1
- package/dist/detectors/missing-final-period.js +3 -1
- package/dist/detectors/missing-final-period.js.map +1 -1
- package/dist/detectors/numbering-readings.d.ts +2 -2
- package/dist/detectors/numbering-readings.d.ts.map +1 -1
- package/dist/detectors/numbering-readings.js +7 -0
- package/dist/detectors/numbering-readings.js.map +1 -1
- package/dist/detectors/open-end-anaphor.d.ts +8 -0
- package/dist/detectors/open-end-anaphor.d.ts.map +1 -0
- package/dist/detectors/open-end-anaphor.js +22 -0
- package/dist/detectors/open-end-anaphor.js.map +1 -0
- package/dist/detectors/open-end-lead.d.ts +4 -0
- package/dist/detectors/open-end-lead.d.ts.map +1 -0
- package/dist/detectors/open-end-lead.js +34 -0
- package/dist/detectors/open-end-lead.js.map +1 -0
- package/dist/detectors/open-end-scope.d.ts.map +1 -1
- package/dist/detectors/open-end-scope.js +7 -1
- package/dist/detectors/open-end-scope.js.map +1 -1
- package/dist/detectors/ordinal-run-gaps.d.ts +1 -0
- package/dist/detectors/ordinal-run-gaps.d.ts.map +1 -1
- package/dist/detectors/ordinal-run-gaps.js +1 -1
- package/dist/detectors/ordinal-run-gaps.js.map +1 -1
- package/dist/detectors/orthographic-variant-open.d.ts +4 -2
- package/dist/detectors/orthographic-variant-open.d.ts.map +1 -1
- package/dist/detectors/orthographic-variant-open.js +5 -3
- package/dist/detectors/orthographic-variant-open.js.map +1 -1
- package/dist/detectors/orthography.d.ts.map +1 -1
- package/dist/detectors/orthography.js +14 -5
- package/dist/detectors/orthography.js.map +1 -1
- package/dist/detectors/placeholder-text.d.ts.map +1 -1
- package/dist/detectors/placeholder-text.js +14 -2
- package/dist/detectors/placeholder-text.js.map +1 -1
- package/dist/detectors/quote-without-source.d.ts +6 -2
- package/dist/detectors/quote-without-source.d.ts.map +1 -1
- package/dist/detectors/quote-without-source.js +33 -8
- package/dist/detectors/quote-without-source.js.map +1 -1
- package/dist/detectors/register-separate-part.d.ts +7 -0
- package/dist/detectors/register-separate-part.d.ts.map +1 -0
- package/dist/detectors/register-separate-part.js +32 -0
- package/dist/detectors/register-separate-part.js.map +1 -0
- package/dist/detectors/registry/contraction-mix.js +1 -1
- package/dist/detectors/registry/contraction-mix.js.map +1 -1
- package/dist/detectors/registry/duplicate-definition.js +1 -1
- package/dist/detectors/registry/duplicate-definition.js.map +1 -1
- package/dist/detectors/reproduced-text.d.ts +5 -0
- package/dist/detectors/reproduced-text.d.ts.map +1 -0
- package/dist/detectors/reproduced-text.js +19 -0
- package/dist/detectors/reproduced-text.js.map +1 -0
- package/dist/detectors/request-owner.d.ts +2 -1
- package/dist/detectors/request-owner.d.ts.map +1 -1
- package/dist/detectors/request-owner.js +31 -7
- package/dist/detectors/request-owner.js.map +1 -1
- package/dist/detectors/requirement-smell.d.ts.map +1 -1
- package/dist/detectors/requirement-smell.js +16 -5
- package/dist/detectors/requirement-smell.js.map +1 -1
- package/dist/detectors/sentence-counts.d.ts +2 -1
- package/dist/detectors/sentence-counts.d.ts.map +1 -1
- package/dist/detectors/sentence-counts.js +23 -7
- package/dist/detectors/sentence-counts.js.map +1 -1
- package/dist/detectors/sentence-ending.d.ts +1 -0
- package/dist/detectors/sentence-ending.d.ts.map +1 -1
- package/dist/detectors/sentence-ending.js +5 -2
- package/dist/detectors/sentence-ending.js.map +1 -1
- package/dist/detectors/sentence-length.d.ts.map +1 -1
- package/dist/detectors/sentence-length.js +13 -3
- package/dist/detectors/sentence-length.js.map +1 -1
- package/dist/detectors/sentence-parts.d.ts +2 -0
- package/dist/detectors/sentence-parts.d.ts.map +1 -1
- package/dist/detectors/sentence-parts.js +3 -1
- package/dist/detectors/sentence-parts.js.map +1 -1
- package/dist/detectors/signals.d.ts.map +1 -1
- package/dist/detectors/signals.js +6 -4
- package/dist/detectors/signals.js.map +1 -1
- package/dist/detectors/spelling-variety.d.ts.map +1 -1
- package/dist/detectors/spelling-variety.js +20 -2
- package/dist/detectors/spelling-variety.js.map +1 -1
- package/dist/detectors/structure-tree.d.ts +2 -1
- package/dist/detectors/structure-tree.d.ts.map +1 -1
- package/dist/detectors/structure-tree.js +2 -7
- package/dist/detectors/structure-tree.js.map +1 -1
- package/dist/detectors/structure.d.ts.map +1 -1
- package/dist/detectors/structure.js +19 -5
- package/dist/detectors/structure.js.map +1 -1
- package/dist/detectors/token-shape.d.ts.map +1 -1
- package/dist/detectors/token-shape.js +12 -6
- package/dist/detectors/token-shape.js.map +1 -1
- package/dist/detectors/undefined-term.d.ts +5 -0
- package/dist/detectors/undefined-term.d.ts.map +1 -1
- package/dist/detectors/undefined-term.js +22 -1
- package/dist/detectors/undefined-term.js.map +1 -1
- package/dist/detectors/unfilled-placeholder.d.ts.map +1 -1
- package/dist/detectors/unfilled-placeholder.js +15 -1
- package/dist/detectors/unfilled-placeholder.js.map +1 -1
- package/dist/detectors/unknown-word-context.d.ts +7 -0
- package/dist/detectors/unknown-word-context.d.ts.map +1 -1
- package/dist/detectors/unknown-word-context.js +11 -0
- package/dist/detectors/unknown-word-context.js.map +1 -1
- package/dist/detectors/unknown-word.d.ts.map +1 -1
- package/dist/detectors/unknown-word.js +5 -4
- package/dist/detectors/unknown-word.js.map +1 -1
- package/dist/latin-spacing-source.d.ts +12 -0
- package/dist/latin-spacing-source.d.ts.map +1 -0
- package/dist/latin-spacing-source.js +25 -0
- package/dist/latin-spacing-source.js.map +1 -0
- package/dist/name-separator.d.ts.map +1 -1
- package/dist/name-separator.js +4 -1
- package/dist/name-separator.js.map +1 -1
- package/dist/paragraph-length.d.ts +14 -0
- package/dist/paragraph-length.d.ts.map +1 -1
- package/dist/paragraph-length.js +25 -0
- package/dist/paragraph-length.js.map +1 -1
- package/dist/paragraph-runs.d.ts +2 -2
- package/dist/paragraph-runs.d.ts.map +1 -1
- package/dist/paragraph-runs.js +65 -14
- package/dist/paragraph-runs.js.map +1 -1
- package/dist/quote-echo.d.ts +6 -0
- package/dist/quote-echo.d.ts.map +1 -0
- package/dist/quote-echo.js +14 -0
- package/dist/quote-echo.js.map +1 -0
- package/dist/semantic.d.ts.map +1 -1
- package/dist/semantic.js +2 -2
- package/dist/semantic.js.map +1 -1
- package/dist/set-phrase-particles.d.ts +4 -0
- package/dist/set-phrase-particles.d.ts.map +1 -0
- package/dist/set-phrase-particles.js +26 -0
- package/dist/set-phrase-particles.js.map +1 -0
- package/dist/structure/alternative-clause.d.ts +7 -0
- package/dist/structure/alternative-clause.d.ts.map +1 -1
- package/dist/structure/alternative-clause.js +23 -8
- package/dist/structure/alternative-clause.js.map +1 -1
- package/dist/structure/cited-document-section.d.ts +2 -0
- package/dist/structure/cited-document-section.d.ts.map +1 -1
- package/dist/structure/cited-document-section.js +8 -0
- package/dist/structure/cited-document-section.js.map +1 -1
- package/dist/structure/issues.d.ts +3 -1
- package/dist/structure/issues.d.ts.map +1 -1
- package/dist/structure/issues.js +12 -8
- package/dist/structure/issues.js.map +1 -1
- package/dist/structure/numbering.d.ts +10 -1
- package/dist/structure/numbering.d.ts.map +1 -1
- package/dist/structure/numbering.js +41 -4
- package/dist/structure/numbering.js.map +1 -1
- package/dist/structure/unread-label.d.ts +13 -0
- package/dist/structure/unread-label.d.ts.map +1 -0
- package/dist/structure/unread-label.js +70 -0
- package/dist/structure/unread-label.js.map +1 -0
- package/dist/topic-clause.d.ts.map +1 -1
- package/dist/topic-clause.js +15 -2
- package/dist/topic-clause.js.map +1 -1
- package/package.json +3 -3
- package/rules/ai-generated-composite.yaml +1 -0
- package/rules/ai-tell.yaml +6 -2
- package/rules/bold-label-list.yaml +6 -6
- package/rules/closing-cliche.yaml +2 -2
- package/rules/colon-lead-in.yaml +2 -2
- package/rules/contraction-consistency.yaml +2 -2
- package/rules/date-format-consistency.yaml +2 -2
- package/rules/duplicate-definition.yaml +2 -2
- package/rules/honesty-marker.yaml +84 -0
- package/rules/latin-spacing.yaml +6 -4
- package/rules/max-paragraph-length.yaml +2 -2
- package/rules/max-sentence-length.yaml +4 -2
- package/rules/missing-final-period.yaml +2 -2
- package/rules/no-doubled-joshi.yaml +2 -2
- package/rules/no-mixed-desumasu.yaml +2 -2
- package/rules/nominalization.yaml +1 -1
- package/rules/numbering-gap.yaml +2 -2
- package/rules/one-sentence-paragraph-run.yaml +2 -2
- package/rules/orthographic-variant.yaml +2 -2
- package/rules/quote-without-source.yaml +2 -2
- package/rules/request-without-deadline.yaml +2 -2
- package/rules/requirement-smell.yaml +2 -2
- package/rules/spelling-consistency.yaml +4 -4
- package/rules/teki-overuse.yaml +2 -2
- package/rules/topic-predicate-distance.yaml +2 -2
- package/rules/undefined-acronym.yaml +3 -2
- package/rules/undefined-term.yaml +2 -2
- package/rules/unfilled-placeholder.yaml +2 -2
- package/rules/unknown-word.yaml +2 -2
- package/skills/chaff/SKILL.md +2 -1
- package/src/ai-score/human-shares.ts +1 -0
- package/src/alternative-words.ts +15 -0
- package/src/closing-code.ts +21 -0
- package/src/date-format.ts +54 -7
- package/src/detectors/acronym-context.ts +3 -2
- package/src/detectors/acronym-mention.ts +17 -0
- package/src/detectors/acronym-name.ts +18 -0
- package/src/detectors/blank-runs.ts +30 -0
- package/src/detectors/bold-label.ts +22 -6
- package/src/detectors/capitalised-term.ts +36 -9
- package/src/detectors/citation-string.ts +57 -0
- package/src/detectors/contraction-emphasis.ts +46 -0
- package/src/detectors/contraction-mention.ts +52 -6
- package/src/detectors/contraction-mix.ts +94 -0
- package/src/detectors/date-format.ts +18 -2
- package/src/detectors/duplicate-definition.ts +21 -0
- package/src/detectors/final-period-captions.ts +78 -0
- package/src/detectors/heading-sentences.ts +36 -0
- package/src/detectors/lexicon.ts +5 -61
- package/src/detectors/list-lead-in.ts +44 -10
- package/src/detectors/missing-final-period.ts +9 -1
- package/src/detectors/numbering-readings.ts +10 -2
- package/src/detectors/open-end-anaphor.ts +31 -0
- package/src/detectors/open-end-lead.ts +46 -0
- package/src/detectors/open-end-scope.ts +8 -1
- package/src/detectors/ordinal-run-gaps.ts +1 -1
- package/src/detectors/orthographic-variant-open.ts +8 -3
- package/src/detectors/orthography.ts +20 -7
- package/src/detectors/placeholder-text.ts +21 -4
- package/src/detectors/quote-without-source.ts +52 -10
- package/src/detectors/register-separate-part.ts +42 -0
- package/src/detectors/registry/contraction-mix.ts +1 -1
- package/src/detectors/registry/duplicate-definition.ts +1 -1
- package/src/detectors/reproduced-text.ts +33 -0
- package/src/detectors/request-owner.ts +31 -8
- package/src/detectors/requirement-smell.ts +21 -5
- package/src/detectors/sentence-counts.ts +27 -7
- package/src/detectors/sentence-ending.ts +6 -2
- package/src/detectors/sentence-length.ts +18 -3
- package/src/detectors/sentence-parts.ts +4 -1
- package/src/detectors/signals.ts +7 -4
- package/src/detectors/spelling-variety.ts +26 -2
- package/src/detectors/structure-tree.ts +2 -8
- package/src/detectors/structure.ts +22 -6
- package/src/detectors/token-shape.ts +16 -6
- package/src/detectors/undefined-term.ts +26 -1
- package/src/detectors/unfilled-placeholder.ts +20 -2
- package/src/detectors/unknown-word-context.ts +17 -0
- package/src/detectors/unknown-word.ts +15 -4
- package/src/latin-spacing-source.ts +33 -0
- package/src/name-separator.ts +4 -1
- package/src/paragraph-length.ts +31 -0
- package/src/paragraph-runs.ts +71 -13
- package/src/quote-echo.ts +18 -0
- package/src/semantic.ts +2 -3
- package/src/set-phrase-particles.ts +32 -0
- package/src/structure/alternative-clause.ts +32 -7
- package/src/structure/cited-document-section.ts +8 -0
- package/src/structure/issues.ts +19 -9
- package/src/structure/numbering.ts +50 -3
- package/src/structure/unread-label.ts +74 -0
- package/src/topic-clause.ts +16 -2
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Token } from "./plugin.ts";
|
|
2
|
+
|
|
3
|
+
// A particle inside a set phrase (絶滅のおそれのある種: おそれのある, "at risk of"): the phrase is read as one word, so its particle
|
|
4
|
+
// is not a link of a nesting chain. Pure.
|
|
5
|
+
|
|
6
|
+
const touches = (left: Token | undefined, right: Token | undefined): boolean => left !== undefined && right !== undefined && left.span.end === right.span.start;
|
|
7
|
+
|
|
8
|
+
/** How many words before a particle are read for a phrase's head: the tokenizer may cut it (おそれ as お and それ). */
|
|
9
|
+
const MAX_HEAD_WORDS = 3;
|
|
10
|
+
|
|
11
|
+
/** The words written straight before tokens[at], joined (おそれ from お and それ). */
|
|
12
|
+
const headBefore = (tokens: readonly Token[], at: number): string => {
|
|
13
|
+
const window = tokens.slice(Math.max(0, at - MAX_HEAD_WORDS), at + 1);
|
|
14
|
+
const gap = window.findLastIndex((token, index) => index < window.length - 1 && !touches(token, window[index + 1]));
|
|
15
|
+
return window
|
|
16
|
+
.slice(gap + 1, -1)
|
|
17
|
+
.map((token) => token.surface)
|
|
18
|
+
.join("");
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Whether the particle at `at`, the words before it and the dictionary form of the word after it spell one of phrases (おそれのある). */
|
|
22
|
+
const isInPhrase = (tokens: readonly Token[], at: number, phrases: readonly string[]): boolean => {
|
|
23
|
+
const [particle, after] = [tokens[at], tokens[at + 1]];
|
|
24
|
+
if (particle === undefined || after === undefined || !touches(particle, after)) return false;
|
|
25
|
+
const tail = `${particle.surface}${after.lemma ?? after.surface}`;
|
|
26
|
+
const head = headBefore(tokens, at);
|
|
27
|
+
return phrases.some((phrase) => phrase.endsWith(tail) && phrase.length > tail.length && head.endsWith(phrase.slice(0, -tail.length)));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** The counted particles (particles) of a sentence that stand inside one of phrases, each written whole (おそれのある). */
|
|
31
|
+
export const setPhraseParticles = (tokens: readonly Token[], particles: readonly string[], phrases: readonly string[]): ReadonlySet<Token> =>
|
|
32
|
+
new Set(tokens.filter((token, at) => particles.includes(token.surface) && isInPhrase(tokens, at, phrases)));
|
|
@@ -23,21 +23,46 @@ const isLabelLine = (line: string): boolean => {
|
|
|
23
23
|
return text.startsWith("#") || ("【〔[[((".includes(text.charAt(0)) && "】〕]]))".includes(text.charAt(text.length - 1)));
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
/** A division whose heading, or the label line just before it, the test names. */
|
|
27
|
+
const divisionNamedBy =
|
|
28
|
+
(source: string, names: (text: string) => boolean): ((node: StructureNode) => boolean) =>
|
|
29
|
+
(node) => {
|
|
30
|
+
const heading = node.attrs["heading"];
|
|
31
|
+
if (typeof heading === "string" && names(heading)) return true;
|
|
32
|
+
const label = previousLineOf(source, node.span.start);
|
|
33
|
+
return isLabelLine(label) && names(label);
|
|
34
|
+
};
|
|
35
|
+
|
|
26
36
|
/**
|
|
27
37
|
* A division its heading, or the label line just before it (【18条変更オプション条項:知財調停】), names as an alternative
|
|
28
38
|
* (alternative-clause-label).
|
|
29
39
|
*/
|
|
30
40
|
export const alternativeReader = (source: string, labels: readonly string[]): ((node: StructureNode) => boolean) => {
|
|
31
41
|
const words = labels.filter((label) => label !== "");
|
|
32
|
-
|
|
33
|
-
return (node) => {
|
|
34
|
-
const heading = node.attrs["heading"];
|
|
35
|
-
if (typeof heading === "string" && names(heading)) return true;
|
|
36
|
-
const label = previousLineOf(source, node.span.start);
|
|
37
|
-
return isLabelLine(label) && names(label);
|
|
38
|
-
};
|
|
42
|
+
return divisionNamedBy(source, (text) => words.some((word) => text.includes(word)));
|
|
39
43
|
};
|
|
40
44
|
|
|
45
|
+
/** One number or letter after the word (オプション2, Option B), not the first of a range or a list (オプション1~3, Options 1 and 2). */
|
|
46
|
+
const ONE_CHOICE = /^\s?(?:[0-90-9]+|[A-ZA-Z])(?![0-90-9A-Za-zA-Z])(?!\s*(?:[~〜~\-–—‐・、,,&&]|to\b|and\b|or\b))/u;
|
|
47
|
+
|
|
48
|
+
/** The text names one choice among numbered ones: an option word (option-choice-label) followed by its number or letter. */
|
|
49
|
+
export const namesOneChoice = (text: string, words: readonly string[]): boolean =>
|
|
50
|
+
words
|
|
51
|
+
.filter((word) => word !== "")
|
|
52
|
+
.some((word) =>
|
|
53
|
+
text
|
|
54
|
+
.split(word)
|
|
55
|
+
.slice(1)
|
|
56
|
+
.some((after) => ONE_CHOICE.test(after)),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A division its heading or label line names as one of numbered choices (第1条(オプション2:…), "Option B"): only one of
|
|
61
|
+
* them stays in the signed text (option-choice-label).
|
|
62
|
+
*/
|
|
63
|
+
export const choiceReader = (source: string, words: readonly string[]): ((node: StructureNode) => boolean) =>
|
|
64
|
+
divisionNamedBy(source, (text) => namesOneChoice(text, words));
|
|
65
|
+
|
|
41
66
|
/** Where a line starts with a division whose number is left blank (placeholder-division: 第●条): a new run of numbers. */
|
|
42
67
|
export const placeholderStarts = (source: string, patterns: readonly string[]): number[] => {
|
|
43
68
|
const heads = patterns.filter((pattern) => pattern !== "");
|
|
@@ -55,3 +55,11 @@ export const referencesInCitedDocuments = (tree: StructureNode): ReadonlySet<Str
|
|
|
55
55
|
const quoted = visits.filter((visit) => visit.node.kind === "reference" && visit.inArticle && visit.heading !== undefined && cited.has(visit.heading));
|
|
56
56
|
return new Set(quoted.map((visit) => visit.node));
|
|
57
57
|
};
|
|
58
|
+
|
|
59
|
+
/** 見出しが他の文書の名前そのもので、その名前を文書がほかで他の文書として引いている節に引き写した条。Pure. */
|
|
60
|
+
export const articlesInCitedDocuments = (tree: StructureNode): readonly StructureNode[] => {
|
|
61
|
+
const visits = visitsOf(tree);
|
|
62
|
+
const cited = documentsCited(visits.map((visit) => visit.node));
|
|
63
|
+
if (cited.size === 0) return [];
|
|
64
|
+
return visits.filter((visit) => visit.node.kind === "article" && visit.heading !== undefined && cited.has(visit.heading)).map((visit) => visit.node);
|
|
65
|
+
};
|
package/src/structure/issues.ts
CHANGED
|
@@ -209,18 +209,20 @@ export const referenceResolver = (tree: StructureNode, source: string): ((refere
|
|
|
209
209
|
};
|
|
210
210
|
};
|
|
211
211
|
|
|
212
|
-
|
|
212
|
+
/** choice: the division, one of several to choose from, that holds the definition (undefined when the text keeps it whatever is chosen). */
|
|
213
|
+
type Definition = { readonly node: StructureNode; readonly article: string; readonly choice: StructureNode | undefined };
|
|
213
214
|
|
|
214
|
-
/**
|
|
215
|
-
const definitionsInOrder = (tree: StructureNode): Definition[] => {
|
|
215
|
+
/** 定義を文書の順に、それが置かれた条の番地と、選ぶ条項の中ならその条項と一緒に並べる。範囲を限った定義は、その条の中でだけ比べるため。 */
|
|
216
|
+
const definitionsInOrder = (tree: StructureNode, isChoice: (node: StructureNode) => boolean): Definition[] => {
|
|
216
217
|
const found: Definition[] = [];
|
|
217
|
-
const pending: Definition[] = [{ node: tree, article: "" }];
|
|
218
|
+
const pending: Definition[] = [{ node: tree, article: "", choice: undefined }];
|
|
218
219
|
while (pending.length > 0) {
|
|
219
220
|
const current = pending.pop();
|
|
220
221
|
if (current === undefined) break;
|
|
221
222
|
if (current.node.kind === "definition") found.push(current);
|
|
222
223
|
const article = current.node.kind === "article" ? current.node.address : current.article;
|
|
223
|
-
current.node.
|
|
224
|
+
const choice = current.choice ?? (current.node.kind !== "definition" && isChoice(current.node) ? current.node : undefined);
|
|
225
|
+
current.node.children.toReversed().forEach((child) => pending.push({ node: child, article, choice }));
|
|
224
226
|
}
|
|
225
227
|
return found;
|
|
226
228
|
};
|
|
@@ -231,17 +233,25 @@ const definitionsInOrder = (tree: StructureNode): Definition[] => {
|
|
|
231
233
|
* 添付した文書(partStarts から始まる Exhibit A など)は別の文書なので、その中の定義はその中でだけ比べる。
|
|
232
234
|
* 同じ名前の後ろの括弧で同じ語を定義し直したもの(件名と本文の Financial Crimes Enforcement Network ("FinCEN"))は、
|
|
233
235
|
* 一つの定義を書き直しただけで食い違えないので言わない。名前は source から読む。
|
|
236
|
+
* ひな形の選ぶ条項(オプション1、オプション2)の中の定義は、選ばなければ消える。先の定義が消えうるなら、後の定義は二度目と決まらない。
|
|
237
|
+
* そこで選ぶ条項の中の定義は、どれを選んでも残る定義と、同じ条項の中の定義とだけ比べる。
|
|
234
238
|
*/
|
|
235
|
-
export const duplicateDefinitions = (
|
|
239
|
+
export const duplicateDefinitions = (
|
|
240
|
+
tree: StructureNode,
|
|
241
|
+
partStarts: readonly number[] = [],
|
|
242
|
+
source = "",
|
|
243
|
+
isChoice: (node: StructureNode) => boolean = () => false,
|
|
244
|
+
): StructureIssue[] => {
|
|
236
245
|
const first = new Map<string, StructureNode>();
|
|
237
|
-
return definitionsInOrder(tree).flatMap(({ node, article }) => {
|
|
246
|
+
return definitionsInOrder(tree, isChoice).flatMap(({ node, article, choice }) => {
|
|
238
247
|
const term = textOf(node, "term");
|
|
239
248
|
const within = node.attrs["within"] === undefined ? article : textOf(node, "within");
|
|
240
249
|
const scoped = node.attrs["scope"] === "local" ? `${within}\u0000${term}` : term;
|
|
241
250
|
const key = `${partAt(partStarts, node.span.start)}\u0000${scoped}`;
|
|
242
|
-
const
|
|
251
|
+
const choiceKey = choice === undefined ? undefined : `${choice.span.start}\u0000${key}`;
|
|
252
|
+
const earlier = first.get(key) ?? (choiceKey === undefined ? undefined : first.get(choiceKey));
|
|
243
253
|
if (earlier === undefined) {
|
|
244
|
-
first.set(key, node);
|
|
254
|
+
first.set(choiceKey ?? key, node);
|
|
245
255
|
return [];
|
|
246
256
|
}
|
|
247
257
|
const name = nameBeforeDefinition(source, node);
|
|
@@ -3,6 +3,7 @@ import { inDocumentOrder, type StructureIssue } from "./issues.ts";
|
|
|
3
3
|
import { numbersQuotedInside } from "./quoted-number.ts";
|
|
4
4
|
import { isVersionHistory } from "./version-order.ts";
|
|
5
5
|
import { withRepeatsNamed } from "./repeated-number.ts";
|
|
6
|
+
import { labelWrittenBetween } from "./unread-label.ts";
|
|
6
7
|
|
|
7
8
|
const labelOf = (node: StructureNode): string => String(node.attrs["label"] ?? node.address);
|
|
8
9
|
|
|
@@ -17,6 +18,14 @@ export type ClauseReadings = { readonly isAlternative: (node: StructureNode) =>
|
|
|
17
18
|
|
|
18
19
|
const NO_CLAUSES: ClauseReadings = { isAlternative: () => false, restarts: [] };
|
|
19
20
|
|
|
21
|
+
/**
|
|
22
|
+
* What a skip is checked against besides the tree. source: the text, for labels set out that the tree did not read
|
|
23
|
+
* (unread-label.ts). isPartialHeading: a heading saying what is under it is only some (抜粋, excerpt), where numbers skip by choice.
|
|
24
|
+
*/
|
|
25
|
+
export type SkipReadings = { readonly source: string; readonly isPartialHeading: (heading: string) => boolean };
|
|
26
|
+
|
|
27
|
+
const NO_SKIPS: SkipReadings = { source: "", isPartialHeading: () => false };
|
|
28
|
+
|
|
20
29
|
const OPENING_BRACKET = /^[([{〔【〈《]/u;
|
|
21
30
|
|
|
22
31
|
/** 括弧で囲んだ番号((1)、(a))か。全角と半角は同じに見る。 */
|
|
@@ -74,7 +83,7 @@ const unreadBetween = (unread: readonly Span[], previous: Ordered, current: Orde
|
|
|
74
83
|
* あいだに読めなかった範囲(unread)があれば、抜けた番号はそこにあるかもしれないので言わない。重なりは言う。
|
|
75
84
|
*/
|
|
76
85
|
const breaksIn =
|
|
77
|
-
(unread: readonly Span[], restarts: readonly Span[]) =>
|
|
86
|
+
(unread: readonly Span[], restarts: readonly Span[], isSkipAllowed: (previous: Ordered, current: Ordered) => boolean) =>
|
|
78
87
|
(sequence: readonly Ordered[]): StructureIssue[] =>
|
|
79
88
|
sequence.flatMap((current, index) => {
|
|
80
89
|
const previous = sequence[index - 1];
|
|
@@ -84,6 +93,7 @@ const breaksIn =
|
|
|
84
93
|
if (unreadBetween(restarts, previous, current)) return [];
|
|
85
94
|
if (current.ordinal > previous.last + 1 && unreadBetween(unread, previous, current)) return [];
|
|
86
95
|
if (current.ordinal > previous.last + 1 && current.ordinal <= previous.last + 1 + current.sideSteps) return [];
|
|
96
|
+
if (current.ordinal > previous.last + 1 && isSkipAllowed(previous, current)) return [];
|
|
87
97
|
return [
|
|
88
98
|
{
|
|
89
99
|
offset: current.node.span.start,
|
|
@@ -92,6 +102,32 @@ const breaksIn =
|
|
|
92
102
|
];
|
|
93
103
|
});
|
|
94
104
|
|
|
105
|
+
/** 抜粋と書いた見出し(## 根拠条文の抜粋)の下の節点。そこの番号は選んで引いたので、飛んでよい。 */
|
|
106
|
+
const underPartialHeadings = (tree: StructureNode, isPartialHeading: (heading: string) => boolean): Set<StructureNode> => {
|
|
107
|
+
const under = new Set<StructureNode>();
|
|
108
|
+
const pending: [StructureNode, boolean][] = [[tree, false]];
|
|
109
|
+
while (pending.length > 0) {
|
|
110
|
+
const [node, inherited] = pending.pop() ?? [tree, false];
|
|
111
|
+
const heading = node.attrs["heading"];
|
|
112
|
+
const partial = inherited || (node.kind === "section" && typeof heading === "string" && isPartialHeading(heading));
|
|
113
|
+
if (partial) under.add(node);
|
|
114
|
+
node.children.forEach((child) => pending.push([child, partial]));
|
|
115
|
+
}
|
|
116
|
+
return under;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/** 並びの始まりの番号。番号は 1 から振る(法令の項は 2 から)。 */
|
|
120
|
+
const LAST_START = 2;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 番号が一つしかなく、それが並びの始まりでない並び(用語集の見出し Section 508 Program、Section 508 Program Manager)は
|
|
124
|
+
* 名前で、番号の並びではない。法令の「2」「2」と続く項(第 1 項は番号が無い)は重なり。
|
|
125
|
+
*/
|
|
126
|
+
const isOneNumber = (sequence: readonly Ordered[]): boolean => {
|
|
127
|
+
const [first] = sequence;
|
|
128
|
+
return first !== undefined && sequence.length > 1 && first.ordinal > LAST_START && sequence.every((ordered) => ordered.ordinal === first.ordinal);
|
|
129
|
+
};
|
|
130
|
+
|
|
95
131
|
/**
|
|
96
132
|
* 番号の抜けと重なり。比べるのは同じ親の子どうしだけ。英米の法令は章ごとに Section 101、201 と百の位を変えるので、
|
|
97
133
|
* 文書全体の通し番号として比べると抜けに見える。最初の番号は見ない。日本語の項は 2 から番号を振る。
|
|
@@ -102,18 +138,29 @@ const breaksIn =
|
|
|
102
138
|
* unread は、読み手には見えるが木に入らない範囲(Markdown の HTML ブロックの中の文字)を、始まりの順に並べたもの。
|
|
103
139
|
* isSideStep は、番号の代わりに「and」と書いた手順(前の手順と並べて行う)。その数だけ、次の番号は飛んでよい。
|
|
104
140
|
* clauses は、別案の条(並びに入れない)と、番号を空けた条の位置(そこから振り直す)。
|
|
141
|
+
* skips は、抜けを言わない場合: 抜けた番号を木が読まずに本文に書いてある((e) の前の行末の (d))か、抜粋と書いた見出しの下。
|
|
105
142
|
*/
|
|
106
143
|
export const numberingBreaks = (
|
|
107
144
|
tree: StructureNode,
|
|
108
145
|
unread: readonly Span[] = [],
|
|
109
146
|
isSideStep: (node: StructureNode) => boolean = () => false,
|
|
110
147
|
clauses: ClauseReadings = NO_CLAUSES,
|
|
148
|
+
skips: SkipReadings = NO_SKIPS,
|
|
111
149
|
): StructureIssue[] => {
|
|
112
150
|
const quoting = numbersQuotedInside(tree);
|
|
113
151
|
const restarts = clauses.restarts.map((start) => ({ start, end: start }));
|
|
152
|
+
const partial = underPartialHeadings(tree, skips.isPartialHeading);
|
|
153
|
+
const spanOf = (ordered: Ordered): { label: string; ordinal: number; start: number; last: number } => ({
|
|
154
|
+
label: labelOf(ordered.node),
|
|
155
|
+
ordinal: ordered.ordinal,
|
|
156
|
+
start: ordered.node.span.start,
|
|
157
|
+
last: ordered.last,
|
|
158
|
+
});
|
|
159
|
+
const isSkipAllowed = (previous: Ordered, current: Ordered): boolean =>
|
|
160
|
+
partial.has(current.node) || labelWrittenBetween(skips.source, spanOf(previous), spanOf(current));
|
|
114
161
|
const breaks = inDocumentOrder(tree)
|
|
115
162
|
.flatMap((parent) => sequencesOf(parent, quoting, isSideStep, clauses))
|
|
116
|
-
.filter((sequence) => !isVersionHistory(sequence.map((ordered) => labelOf(ordered.node))))
|
|
117
|
-
.flatMap(breaksIn(unread, restarts));
|
|
163
|
+
.filter((sequence) => !isVersionHistory(sequence.map((ordered) => labelOf(ordered.node))) && !isOneNumber(sequence))
|
|
164
|
+
.flatMap(breaksIn(unread, restarts, isSkipAllowed));
|
|
118
165
|
return withRepeatsNamed(tree, quoting, breaks, unread);
|
|
119
166
|
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// A number the tree did not read but the text writes: "(d)" run into the end of the line before "(e)", "6.1" and "6.2"
|
|
2
|
+
// written as plain paragraphs before the "6.3" the tree read, "(11)" joined to the heading of "(10)". A skip across such
|
|
3
|
+
// a label is not a missing number. Pure.
|
|
4
|
+
|
|
5
|
+
const LETTERS = "abcdefghijklmnopqrstuvwxyz";
|
|
6
|
+
|
|
7
|
+
/** At most this many missing numbers are looked for; a wider skip is not a few labels the tree missed. */
|
|
8
|
+
const MAX_MISSING = 30;
|
|
9
|
+
|
|
10
|
+
/** A label in brackets ((11)): in the heading before, a bare number may be any number in its words. */
|
|
11
|
+
const BRACKETED = /^[([]/u;
|
|
12
|
+
/** An HTML comment: text the reader does not see, so a label in it is not written. */
|
|
13
|
+
const HTML_COMMENT = /<!--[\s\S]*?-->/gu;
|
|
14
|
+
|
|
15
|
+
const escapeRegExp = (text: string): string => text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
16
|
+
|
|
17
|
+
/** The label written with another number in place of its own: digits for digits, a letter in the same case for a letter. */
|
|
18
|
+
const relabel = (label: string, ordinal: number): ((other: number) => string) | undefined => {
|
|
19
|
+
const digits = [...label.matchAll(/\d+/gu)].findLast((match) => Number(match[0]) === ordinal);
|
|
20
|
+
if (digits !== undefined) return (other) => `${label.slice(0, digits.index)}${other}${label.slice(digits.index + digits[0].length)}`;
|
|
21
|
+
const letter = [...label.matchAll(/(?<![A-Za-z])[A-Za-z](?![A-Za-z])/gu)].findLast((match) => LETTERS.indexOf(match[0].toLowerCase()) + 1 === ordinal);
|
|
22
|
+
if (letter === undefined) return undefined;
|
|
23
|
+
const upper = letter[0] !== letter[0].toLowerCase();
|
|
24
|
+
return (other) => {
|
|
25
|
+
const written = LETTERS.charAt(other - 1);
|
|
26
|
+
return `${label.slice(0, letter.index)}${upper ? written.toUpperCase() : written}${label.slice(letter.index + 1)}`;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A label set out as one: at the start of a line behind the same marks as the later label (## for a heading, none for a
|
|
32
|
+
* paragraph), after a run of spaces within a line, or after a space in the heading that opens the node before
|
|
33
|
+
* ("##### (10) … (11) …", a label in brackets). A label in a sentence or in an HTML comment ("under clause (d)") is a reference, and a list item's "3." under
|
|
34
|
+
* headings numbered "## 4." is another numbering.
|
|
35
|
+
*/
|
|
36
|
+
const setOutIn = (text: string, label: string, lead: string): boolean => {
|
|
37
|
+
const escaped = escapeRegExp(label);
|
|
38
|
+
const after = String.raw`(?![0-9A-Za-z])`;
|
|
39
|
+
const atLineStart = new RegExp(String.raw`^[ \t]*${escapeRegExp(lead)}[ \t]*${escaped}${after}`, "mu");
|
|
40
|
+
const afterSpaces = new RegExp(String.raw`\S[ \t]{2,}${escaped}${after}`, "u");
|
|
41
|
+
if (atLineStart.test(text) || afterSpaces.test(text)) return true;
|
|
42
|
+
const firstLine = text.split("\n", 1)[0] ?? "";
|
|
43
|
+
const bracketed = BRACKETED.test(label);
|
|
44
|
+
return bracketed && firstLine.trimStart().startsWith("#") && new RegExp(String.raw`\s${escaped}${after}`, "u").test(firstLine);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** The marks before a label on its own line (## of a heading, > of a quotation), spaces left out. */
|
|
48
|
+
const leadOf = (source: string, start: number, label: string): string => {
|
|
49
|
+
const lineStart = source.lastIndexOf("\n", start - 1) + 1;
|
|
50
|
+
const lineEnd = source.indexOf("\n", start);
|
|
51
|
+
const line = source.slice(lineStart, lineEnd === -1 ? source.length : lineEnd).normalize("NFKC");
|
|
52
|
+
const at = line.indexOf(label);
|
|
53
|
+
return at === -1 ? "" : line.slice(0, at).trim();
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type LabelSpan = { readonly label: string; readonly ordinal: number; readonly start: number };
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Whether the text between two numbered nodes sets out a label of the later one's kind with a number the skip leaves out
|
|
60
|
+
* (between previous's last number and current's), which the tree did not read as a node.
|
|
61
|
+
*/
|
|
62
|
+
export const labelWrittenBetween = (source: string, previous: LabelSpan & { readonly last: number }, current: LabelSpan): boolean => {
|
|
63
|
+
const missing = current.ordinal - previous.last - 1;
|
|
64
|
+
if (missing < 1 || missing > MAX_MISSING || current.start <= previous.start) return false;
|
|
65
|
+
const label = current.label.normalize("NFKC");
|
|
66
|
+
const written = relabel(label, current.ordinal);
|
|
67
|
+
if (written === undefined) return false;
|
|
68
|
+
const lead = leadOf(source, current.start, label);
|
|
69
|
+
const text = source
|
|
70
|
+
.slice(source.lastIndexOf("\n", previous.start - 1) + 1, current.start)
|
|
71
|
+
.replaceAll(HTML_COMMENT, "")
|
|
72
|
+
.normalize("NFKC");
|
|
73
|
+
return Array.from({ length: missing }, (_, index) => written(previous.last + 1 + index)).some((missingLabel) => setOutIn(text, missingLabel, lead));
|
|
74
|
+
};
|
package/src/topic-clause.ts
CHANGED
|
@@ -162,14 +162,28 @@ const isPoliteGa = (tokens: readonly Token[], at: number): boolean => {
|
|
|
162
162
|
const ownGaSubjectBetween = (tokens: readonly Token[], from: number, to: number): boolean =>
|
|
163
163
|
tokens.some((token, at) => at > from && at < to && isParticle(token, "が") && headsSubject(tokens, at));
|
|
164
164
|
|
|
165
|
+
/** A word of a name (赤澤, 大臣), not a noun that sets the time or the case (今後, 当日). */
|
|
166
|
+
const isNameWord = (token: Token): boolean => NOMINAL.has(token.pos) && token.features?.["Adverbial"] !== "Yes";
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 石破総理大臣は…明らかにしましたが、赤澤大臣は…どう考えているか: a name and は straight after the comma is a topic of its own
|
|
170
|
+
* that the rest of the sentence is said of, when no subject of its own (が) follows it. A phrase before は (〜した行為は) is not one.
|
|
171
|
+
*/
|
|
172
|
+
const newNameTopicRunsToEnd = (tokens: readonly Token[], comma: number, last: number): boolean => {
|
|
173
|
+
const topic = tokens.findIndex((token, index) => index > comma && !isNameWord(token));
|
|
174
|
+
const wa = tokens[topic];
|
|
175
|
+
return topic > comma + 1 && wa !== undefined && isParticle(wa, "は") && lastOwnSubject(tokens, last) <= topic;
|
|
176
|
+
};
|
|
177
|
+
|
|
165
178
|
/**
|
|
166
179
|
* 当社は…を営んでおりますが、…の重要性が乏しいため、…の記載は行っておりません: after 〜ますが、 the words up to the next comma
|
|
167
180
|
* say something of a subject of their own (が) and a new topic takes what comes after, so the predicate before が was the
|
|
168
|
-
* topic's, when no other subject stands between the topic and it (需要の停滞がありましたが is not). A
|
|
169
|
-
*
|
|
181
|
+
* topic's, when no other subject stands between the topic and it (需要の停滞がありましたが is not). A clause with no subject of
|
|
182
|
+
* its own there is read to the end, unless a name stands as a new topic straight after the comma (〜ましたが、B大臣は…).
|
|
170
183
|
*/
|
|
171
184
|
const closesWithPoliteGa = (tokens: readonly Token[], topic: number, at: number, last: number): boolean => {
|
|
172
185
|
if (!isPoliteGa(tokens, at) || !isComma(tokens[at + 1]) || subjectBetween(tokens, topic, at)) return false;
|
|
186
|
+
if (newNameTopicRunsToEnd(tokens, at + 1, last)) return true;
|
|
173
187
|
const comma = tokens.findIndex((token, index) => index > at + 1 && index < last && isComma(token));
|
|
174
188
|
const clauseEnd = comma === -1 ? last : comma;
|
|
175
189
|
return ownGaSubjectBetween(tokens, at + 1, clauseEnd) && newTopicAfter(tokens, clauseEnd, last);
|