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
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import type { Detector, Finding, ProseDocument } from "../plugin.ts";
|
|
1
|
+
import type { Detector, Finding, ProseDocument, Span } from "../plugin.ts";
|
|
2
2
|
import { dateGroups, dateMinority, datesIn, type DateMinority } from "../date-format.ts";
|
|
3
3
|
import { quoteAt } from "./structure-tree.ts";
|
|
4
|
+
import { referenceListSpans } from "../reference-lists.ts";
|
|
5
|
+
import { noteSentences } from "../note-paragraphs.ts";
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* 一つの文書で、日付を二通り以上の書き方で書いた所(2026-10-02 と 2026年10月2日、Oct 2, 2026 と 10/2/2026)。少ないほうを指す。
|
|
7
9
|
* 行の頭の日付(予定表の行)と文の中の日付は別に比べる。月の名前は語彙表 month-name、元号は calendar-era が言う。コードの中の日付は読まない。
|
|
10
|
+
* 文献一覧(見出しは語彙表 reference-list-heading)と注の並びの中の日付は比べない。
|
|
8
11
|
*/
|
|
9
12
|
const findingsOf = (doc: ProseDocument, minority: DateMinority): Finding[] =>
|
|
10
13
|
minority.odd.map((date) => ({
|
|
@@ -16,6 +19,18 @@ const findingsOf = (doc: ProseDocument, minority: DateMinority): Finding[] =>
|
|
|
16
19
|
values: { written: date.written, example: minority.majority.written, count: minority.count, total: minority.total, offset: date.offset },
|
|
17
20
|
}));
|
|
18
21
|
|
|
22
|
+
/** 文献一覧と、番号の付いた注の並びの範囲。 */
|
|
23
|
+
const citedSpans = (doc: ProseDocument): Span[] => {
|
|
24
|
+
const notes = noteSentences(doc.source, doc.paragraphs);
|
|
25
|
+
return [
|
|
26
|
+
...referenceListSpans(
|
|
27
|
+
doc.source,
|
|
28
|
+
(doc.lexicons["reference-list-heading"] ?? []).map((entry) => entry.pattern),
|
|
29
|
+
),
|
|
30
|
+
...doc.paragraphs.filter((paragraph) => paragraph.sentences.some((sentence) => notes.has(sentence))).map((paragraph) => paragraph.span),
|
|
31
|
+
];
|
|
32
|
+
};
|
|
33
|
+
|
|
19
34
|
export const dateFormat: Detector = (doc, options): Finding[] => {
|
|
20
35
|
const words = {
|
|
21
36
|
months: (doc.lexicons["month-name"] ?? []).map((entry) => entry.pattern),
|
|
@@ -23,7 +38,8 @@ export const dateFormat: Detector = (doc, options): Finding[] => {
|
|
|
23
38
|
};
|
|
24
39
|
const text = doc.prose ?? doc.source;
|
|
25
40
|
const stampLabels = (doc.lexicons["date-stamp-label"] ?? []).map((entry) => entry.pattern);
|
|
26
|
-
|
|
41
|
+
const places = { stampLabels, cited: citedSpans(doc), source: doc.source };
|
|
42
|
+
return dateGroups(text, datesIn(text, words), places).flatMap((group) => {
|
|
27
43
|
const minority = dateMinority(group, options.limit);
|
|
28
44
|
return minority === undefined ? [] : findingsOf(doc, minority);
|
|
29
45
|
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Detector, ProseDocument, StructureNode } from "../plugin.ts";
|
|
2
|
+
import { duplicateDefinitions } from "../structure/issues.ts";
|
|
3
|
+
import { attachedPartStarts } from "../structure/attached-parts.ts";
|
|
4
|
+
import { alternativeReader, choiceReader } from "../structure/alternative-clause.ts";
|
|
5
|
+
import { findingsOf } from "./structure-tree.ts";
|
|
6
|
+
import { patternsOf } from "./net-amount-mismatch.ts";
|
|
7
|
+
|
|
8
|
+
/** A clause to choose instead of another: named an alternative (alternative-clause-label) or one of numbered options (option-choice-label). */
|
|
9
|
+
const choicesOf = (doc: ProseDocument, source: string): ((node: StructureNode) => boolean) => {
|
|
10
|
+
const isAlternative = alternativeReader(source, patternsOf(doc, "alternative-clause-label"));
|
|
11
|
+
const isChoice = choiceReader(source, patternsOf(doc, "option-choice-label"));
|
|
12
|
+
return (node) => isAlternative(node) || isChoice(node);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const duplicateDefinition: Detector = (doc, options) => {
|
|
16
|
+
const labels = patternsOf(doc, "attached-instrument-label");
|
|
17
|
+
return findingsOf("duplicate-definition", (tree, source) => duplicateDefinitions(tree, attachedPartStarts(source, labels), source, choicesOf(doc, source)))(
|
|
18
|
+
doc,
|
|
19
|
+
options,
|
|
20
|
+
);
|
|
21
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Paragraphs that stand in a repeated slot of the layout, where the document writes captions rather than sentences: a
|
|
2
|
+
// one-line summary right under each of several headings, the term line of a term-then-explanation run, and the lines of
|
|
3
|
+
// a run of one-line items. A slot is read as captions only when it repeats and none of its lines closes with the period,
|
|
4
|
+
// so a slot mixing both forms is still left to missing-final-period. Pure.
|
|
5
|
+
import type { Paragraph, Section } from "../plugin.ts";
|
|
6
|
+
|
|
7
|
+
/** How a paragraph looks to the slots: whether it is one line, and whether that line closes with the period. */
|
|
8
|
+
export type SlotParagraph = { readonly span: { readonly start: number; readonly end: number }; readonly oneLine: boolean; readonly closed: boolean };
|
|
9
|
+
|
|
10
|
+
/** A slot is a layout only when it repeats at least this often. */
|
|
11
|
+
const MIN_REPEATS = 3;
|
|
12
|
+
|
|
13
|
+
const isOpenLine = (paragraph: SlotParagraph | undefined): boolean => paragraph !== undefined && paragraph.oneLine && !paragraph.closed;
|
|
14
|
+
|
|
15
|
+
/** The indexes of a slot when it repeats and none of its paragraphs is closed. */
|
|
16
|
+
const captionsOf = (slot: readonly number[], paragraphs: readonly SlotParagraph[]): number[] =>
|
|
17
|
+
slot.length >= MIN_REPEATS && slot.every((index) => isOpenLine(paragraphs[index])) ? [...slot] : [];
|
|
18
|
+
|
|
19
|
+
/** The paragraph a section's body opens with, when nothing stands between the heading and it. */
|
|
20
|
+
const openingParagraph = (text: string, section: Section, paragraphs: readonly SlotParagraph[]): number | undefined => {
|
|
21
|
+
const index = paragraphs.findIndex((paragraph) => paragraph.span.start >= section.span.start && paragraph.span.start < section.span.end);
|
|
22
|
+
const paragraph = paragraphs[index];
|
|
23
|
+
return paragraph !== undefined && text.slice(section.span.start, paragraph.span.start).trim() === "" ? index : undefined;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Where a section sits: its depth, and the heading it stands under (the last section before it that is less deep). */
|
|
27
|
+
const siblingKey = (sections: readonly Section[], index: number): string => {
|
|
28
|
+
const depth = sections[index]?.depth ?? 0;
|
|
29
|
+
const parent = sections.slice(0, index).findLastIndex((section) => section.depth < depth);
|
|
30
|
+
return `${parent}:${depth}`;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** The one-line paragraphs that open sibling sections: a summary under each heading (気づき / 家族の変化に気づいて、声をかける). */
|
|
34
|
+
const headingSlots = (text: string, sections: readonly Section[], paragraphs: readonly SlotParagraph[]): number[][] => {
|
|
35
|
+
const bySiblings = new Map<string, number[]>();
|
|
36
|
+
sections.forEach((section, sectionIndex) => {
|
|
37
|
+
const index = section.depth > 0 ? openingParagraph(text, section, paragraphs) : undefined;
|
|
38
|
+
if (index === undefined || paragraphs[index]?.oneLine !== true) return;
|
|
39
|
+
const key = siblingKey(sections, sectionIndex);
|
|
40
|
+
bySiblings.set(key, [...(bySiblings.get(key) ?? []), index]);
|
|
41
|
+
});
|
|
42
|
+
return [...bySiblings.values()];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** Runs of an open one-line paragraph followed by a closed one: a term, then the sentence that explains it. */
|
|
46
|
+
const termSlots = (paragraphs: readonly SlotParagraph[]): number[][] =>
|
|
47
|
+
paragraphs.reduce<number[][]>((runs, paragraph, index) => {
|
|
48
|
+
if (!isOpenLine(paragraph) || paragraphs[index + 1]?.closed !== true) return runs;
|
|
49
|
+
const run = runs.at(-1);
|
|
50
|
+
if (run !== undefined && run.at(-1) === index - 2) run.push(index);
|
|
51
|
+
else runs.push([index]);
|
|
52
|
+
return runs;
|
|
53
|
+
}, []);
|
|
54
|
+
|
|
55
|
+
/** Runs of one-line paragraphs written on consecutive lines, with no blank line between: the items of a list or a table of contents. */
|
|
56
|
+
const lineSlots = (text: string, paragraphs: readonly SlotParagraph[]): number[][] =>
|
|
57
|
+
paragraphs.reduce<number[][]>((runs, paragraph, index) => {
|
|
58
|
+
if (!paragraph.oneLine) return runs;
|
|
59
|
+
const previous = paragraphs[index - 1];
|
|
60
|
+
const run = runs.at(-1);
|
|
61
|
+
const adjacent = previous !== undefined && previous.oneLine && !text.slice(previous.span.end, paragraph.span.start).includes("\n\n");
|
|
62
|
+
if (adjacent && run !== undefined && run.at(-1) === index - 1) run.push(index);
|
|
63
|
+
else runs.push([index]);
|
|
64
|
+
return runs;
|
|
65
|
+
}, []);
|
|
66
|
+
|
|
67
|
+
/** The indexes of the paragraphs that are captions in a repeated slot, not sentences left open. */
|
|
68
|
+
export const captionParagraphs = (text: string, sections: readonly Section[], paragraphs: readonly SlotParagraph[]): ReadonlySet<number> =>
|
|
69
|
+
new Set(
|
|
70
|
+
[...headingSlots(text, sections, paragraphs), ...termSlots(paragraphs), ...lineSlots(text, paragraphs)].flatMap((slot) => captionsOf(slot, paragraphs)),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
/** The slot view of a document's paragraphs; closed says whether a paragraph's last line ends with the period. */
|
|
74
|
+
export const slotParagraphs = (text: string, paragraphs: readonly Paragraph[], closed: (line: string) => boolean): SlotParagraph[] =>
|
|
75
|
+
paragraphs.map((paragraph) => {
|
|
76
|
+
const body = text.slice(paragraph.span.start, paragraph.span.end).trim();
|
|
77
|
+
return { span: paragraph.span, oneLine: !body.includes("\n"), closed: closed(body.split("\n").at(-1)?.trim() ?? "") };
|
|
78
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ProseDocument, Section, Sentence, Token } from "../plugin.ts";
|
|
2
|
+
|
|
3
|
+
const shifted = (tokens: readonly Token[], by: number): Token[] =>
|
|
4
|
+
tokens.map((token) => ({ ...token, span: { start: token.span.start + by, end: token.span.end + by } }));
|
|
5
|
+
|
|
6
|
+
/** Where the heading's text starts in the source: from the heading's line, which ends where its section starts. */
|
|
7
|
+
const textStartOf = (source: string, section: Section, headingStarts: ReadonlyMap<number, number>): number | undefined => {
|
|
8
|
+
const from = headingStarts.get(section.span.start);
|
|
9
|
+
if (from === undefined) return undefined;
|
|
10
|
+
const at = source.indexOf(section.heading, from);
|
|
11
|
+
return at < 0 || at >= section.span.start ? undefined : at;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const headingSentence = (source: string, section: Section, headingStarts: ReadonlyMap<number, number>): Sentence[] => {
|
|
15
|
+
if (section.depth === 0 || section.heading === "") return [];
|
|
16
|
+
const start = textStartOf(source, section, headingStarts);
|
|
17
|
+
if (start === undefined) return [];
|
|
18
|
+
const span = { start, end: start + section.heading.length };
|
|
19
|
+
return [
|
|
20
|
+
section.headingTokens === undefined ? { span, text: section.heading } : { span, text: section.heading, tokens: shifted(section.headingTokens, start) },
|
|
21
|
+
];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Each heading read as one sentence, placed where its text stands in the source, with its words. For a rule that reads
|
|
26
|
+
* the words a writer chose in titles as well as in body sentences. A heading whose text cannot be found in its line
|
|
27
|
+
* (inline markup in it) is left out rather than placed wrong.
|
|
28
|
+
*/
|
|
29
|
+
export const headingSentences = (doc: ProseDocument): Sentence[] => {
|
|
30
|
+
const headingStarts = new Map((doc.markup?.headings ?? []).map((heading) => [heading.end, heading.start]));
|
|
31
|
+
return doc.sections.flatMap((section) => headingSentence(doc.source, section, headingStarts));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Body sentences and headings together, in the order they stand in the source. */
|
|
35
|
+
export const sentencesWithHeadings = (doc: ProseDocument): Sentence[] =>
|
|
36
|
+
[...doc.sentences, ...headingSentences(doc)].toSorted((left, right) => left.span.start - right.span.start);
|
package/src/detectors/lexicon.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { joinWords } from "./word-list.ts";
|
|
2
|
-
import { pairMinority } from "./contraction-minority.ts";
|
|
3
|
-
import { withoutMentions } from "./contraction-mention.ts";
|
|
4
|
-
import { straightApostrophes } from "../orthography.ts";
|
|
5
2
|
import { wordsOf } from "./structure.ts";
|
|
6
3
|
import type { Detector, Finding, Lexicon, LexiconEntry, ProseDocument, Sentence, Span, Token } from "../plugin.ts";
|
|
7
4
|
import { entryIn, entryOpens, entryRanges, type TokenRange } from "./lexicon-match.ts";
|
|
5
|
+
import { sentencesWithHeadings } from "./heading-sentences.ts";
|
|
8
6
|
import { scoped, scopeMarkersOf, type ScopeMarkers } from "./superlative-scope.ts";
|
|
9
7
|
import { makesWord, namesQuantity } from "./superlative-name.ts";
|
|
10
8
|
import { namesAmount } from "./superlative-amount.ts";
|
|
@@ -257,14 +255,15 @@ const writtenIn = (sentence: Sentence, entry: LexiconEntry): boolean =>
|
|
|
257
255
|
: entryRanges(sentence, entry).some((range) => !quotedRange(sentence, range));
|
|
258
256
|
|
|
259
257
|
/**
|
|
260
|
-
* AI 生成の signal。1
|
|
258
|
+
* AI 生成の signal。1 つでは何も言えないので、重みを足し合わせて文書の点にする。見出しも読む(「〜をわかりやすく解説」のような題)。
|
|
261
259
|
* 単独で断じない。§20.2 の複合シグナルの入口で、これだけで「AI が書いた」とは言わない。
|
|
262
260
|
*/
|
|
263
261
|
export const aiTell: Detector = (doc, options): Finding[] => {
|
|
264
262
|
const entries = [...new Map((options.lexicon ?? []).map((entry) => [entry.pattern.toLowerCase(), entry])).values()];
|
|
265
|
-
const
|
|
263
|
+
const sentences = sentencesWithHeadings(doc);
|
|
264
|
+
const found = entries.filter((entry) => sentences.some((sentence) => writtenIn(sentence, entry)));
|
|
266
265
|
const score = Math.round(found.reduce((sum, entry) => sum + (entry.weight ?? 1), 0) * 10);
|
|
267
|
-
const first =
|
|
266
|
+
const first = sentences.find((sentence) => found.some((entry) => writtenIn(sentence, entry)));
|
|
268
267
|
if (first === undefined || score <= options.limit) return [];
|
|
269
268
|
return [
|
|
270
269
|
{
|
|
@@ -286,58 +285,3 @@ export const aiTell: Detector = (doc, options): Finding[] => {
|
|
|
286
285
|
},
|
|
287
286
|
];
|
|
288
287
|
};
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* 同じことを言う 2 つの書きかたが、1 つの文書で混ざっているか。
|
|
292
|
-
*
|
|
293
|
-
* **どちらが正しいかは決めない。** 短縮形を使うかどうかは文体の選択で、
|
|
294
|
-
* 立場を取ると方針の違う書き手に rule ごと無視される。spec §12.3。
|
|
295
|
-
*
|
|
296
|
-
* 語彙表は対を持つ(`pattern` と `instead_of`)。比べるのは対の中だけで、別の語どうしは比べない。
|
|
297
|
-
* GOV.UK の文体は「you're」を使い否定は「do not」と書く。語ごとに決めた書きかたで、混在ではない。
|
|
298
|
-
* 否定と代名詞+動詞の族にもまとめない。「don't」と「does not」を書き分ける文書もある。
|
|
299
|
-
*/
|
|
300
|
-
/**
|
|
301
|
-
* 語の境界で照合する。部分一致だと「it isn't」が「it is」を含んでしまい、
|
|
302
|
-
* 短縮形を使っている文が「使っていない」側に数えられる。
|
|
303
|
-
*/
|
|
304
|
-
const wordUses = (text: string, word: string): number => [...text.matchAll(new RegExp(`\\b${word.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")}\\b`, "gu"))].length;
|
|
305
|
-
|
|
306
|
-
const containsWord = (text: string, word: string): boolean => wordUses(text, word) > 0;
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* アポストロフィの形(don’t と don't)は短縮形かどうかを変えない。違うのは印刷の形で、文体ではない。
|
|
310
|
-
* 折り返した行(「do」で改行して「not」)も、空白 1 つと同じに読む。
|
|
311
|
-
*/
|
|
312
|
-
const comparableText = (sentence: Sentence): string => withoutMentions(straightApostrophes(sentence.text)).replace(/\s+/gu, " ").toLowerCase();
|
|
313
|
-
|
|
314
|
-
type MixedPair = { readonly minority: string; readonly majority: string; readonly count: number };
|
|
315
|
-
|
|
316
|
-
const mixedPair = (body: string, short: string, long: string): MixedPair | undefined => {
|
|
317
|
-
const uses = { short: wordUses(body, short), long: wordUses(body, long) };
|
|
318
|
-
const side = pairMinority(uses);
|
|
319
|
-
if (side === undefined) return undefined;
|
|
320
|
-
return side === "short" ? { minority: short, majority: long, count: uses.short } : { minority: long, majority: short, count: uses.long };
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
export const contractionMix: Detector = (doc, options): Finding[] => {
|
|
324
|
-
// 文は改行でつなぐ。空白でつなぐと、箇条書きの「What we do」と次の項目「not every…」が「do not」と数えられる。
|
|
325
|
-
const body = doc.sentences.map(comparableText).join("\n");
|
|
326
|
-
const mixed = (options.lexicon ?? []).flatMap((entry) => {
|
|
327
|
-
const pair = entry.instead_of === undefined ? undefined : mixedPair(body, entry.pattern.toLowerCase(), entry.instead_of.toLowerCase());
|
|
328
|
-
return pair === undefined || pair.count > options.limit ? [] : [pair];
|
|
329
|
-
});
|
|
330
|
-
const hits = doc.sentences.flatMap((sentence) => {
|
|
331
|
-
const text = comparableText(sentence);
|
|
332
|
-
const pair = mixed.find((candidate) => containsWord(text, candidate.minority));
|
|
333
|
-
return pair === undefined ? [] : [{ sentence, pair }];
|
|
334
|
-
});
|
|
335
|
-
return hits.map(({ sentence, pair }) => ({
|
|
336
|
-
rule: "contraction-consistency",
|
|
337
|
-
severity: "info",
|
|
338
|
-
line: 0,
|
|
339
|
-
column: 0,
|
|
340
|
-
quote: sentence.text.trim(),
|
|
341
|
-
values: { matched: pair.minority, majority: pair.majority, count: pair.count, limit: options.limit, offset: sentence.span.start },
|
|
342
|
-
}));
|
|
343
|
-
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { BulletList, Detector, DetectorOptions, Finding, ProseDocument, Sentence, Span } from "../plugin.ts";
|
|
2
2
|
import { densityFindings } from "./ai-phrasing.ts";
|
|
3
3
|
import { endsWithColon } from "./lead-in.ts";
|
|
4
|
+
import { isMarkdownPath } from "../structure/markdown-path.ts";
|
|
4
5
|
|
|
5
6
|
/** Between a lead-in and its list: only blank space. A thematic break (`***`) separates them; bold marks sit inside the sentence. */
|
|
6
7
|
const ONLY_BLANKS = /^\s*$/u;
|
|
@@ -37,20 +38,33 @@ const labelWords = (text: string): string => {
|
|
|
37
38
|
/** A noun with no kana inflection (参考, 注意点): a name, not a sentence (以下の通りです) and not a lone symbol (⚠️). */
|
|
38
39
|
const NOUN_LABEL = /^(?=.*\p{L})[^\p{Script=Hiragana}]+$/u;
|
|
39
40
|
|
|
40
|
-
/**
|
|
41
|
+
/** A label of a word or three is a name (See also, Pros) whatever its parts of speech. */
|
|
41
42
|
const MAX_LABEL_WORDS = 3;
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
/** A verb or a pronoun makes a clause: Here's what you need is a sentence, Community changes, past quarter a name. */
|
|
45
|
+
const CLAUSE_POS: ReadonlySet<string> = new Set(["VERB", "AUX", "PRON", "SCONJ"]);
|
|
46
|
+
const NAME_POS: ReadonlySet<string> = new Set(["NOUN", "PROPN"]);
|
|
47
|
+
|
|
48
|
+
/** A noun phrase of any length, read from the adapter's parts of speech. Without them, only the short label counts. */
|
|
49
|
+
const isNounPhrase = (sentence: Sentence): boolean => {
|
|
50
|
+
const tokens = sentence.tokens ?? [];
|
|
51
|
+
return tokens.some((token) => NAME_POS.has(token.pos)) && !tokens.some((token) => CLAUSE_POS.has(token.pos));
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const isNounLabel = (words: string, sentence: Sentence): boolean =>
|
|
55
|
+
NOUN_LABEL.test(words) && (words.split(/\s+/u).length <= MAX_LABEL_WORDS || isNounPhrase(sentence));
|
|
44
56
|
|
|
45
57
|
/**
|
|
46
58
|
* A field of an entry's template: the same noun label before the list of each entry (**参考:** before each entry's link).
|
|
47
59
|
* It names the field the way a table's column does; it does not lead into anything.
|
|
48
60
|
*/
|
|
49
61
|
const fieldLabels = (leadIns: readonly Sentence[]): ReadonlySet<string> => {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
const usesByLabel = leadIns.reduce((tally, sentence) => {
|
|
63
|
+
const words = labelWords(sentence.text);
|
|
64
|
+
return tally.set(words, [...(tally.get(words) ?? []), sentence]);
|
|
65
|
+
}, new Map<string, readonly Sentence[]>());
|
|
66
|
+
const isField = (words: string, [first, ...rest]: readonly Sentence[]): boolean => first !== undefined && rest.length > 0 && isNounLabel(words, first);
|
|
67
|
+
return new Set([...usesByLabel].filter(([words, uses]) => isField(words, uses)).map(([words]) => words));
|
|
54
68
|
};
|
|
55
69
|
|
|
56
70
|
/** A line that is only a bold label (**Pros:**, **参考**:), and the label inside the bold marks. */
|
|
@@ -64,20 +78,40 @@ const lineAround = (source: string, sentence: Sentence): string => {
|
|
|
64
78
|
/** A bold noun label on a line of its own names the list under it, as a heading does (**Pros:** then **Cons:**). */
|
|
65
79
|
const isBoldNounLabel = (sentence: Sentence, source: string): boolean => {
|
|
66
80
|
const label = BOLD_LINE.exec(lineAround(source, sentence).trim())?.groups?.["label"];
|
|
67
|
-
return label !== undefined && isNounLabel(labelWords(label));
|
|
81
|
+
return label !== undefined && isNounLabel(labelWords(label), sentence);
|
|
68
82
|
};
|
|
69
83
|
|
|
84
|
+
/** Plain text cannot write bold, so there a noun label alone on its line is the heading of its list (Releases:, New Features:). */
|
|
85
|
+
const isPlainNounLabel = (sentence: Sentence, source: string): boolean =>
|
|
86
|
+
lineAround(source, sentence).trim() === sentence.text.trim() && isNounLabel(labelWords(sentence.text), sentence);
|
|
87
|
+
|
|
88
|
+
/** An item's list marker and any emphasis before its first word (- **, 1. ). */
|
|
89
|
+
const ITEM_HEAD = /^\s*(?:[-*+]|\d+[.)])\s+(?:\*\*|__|\*|_)?/u;
|
|
90
|
+
|
|
91
|
+
const opensWithCode = (source: string, item: Span): boolean => source.slice(item.start, item.end).replace(ITEM_HEAD, "").startsWith("`");
|
|
92
|
+
|
|
93
|
+
/** A list whose every item opens with a code span names values, options or members (`omit`: never send …): a parts list, which can stay. */
|
|
94
|
+
const isValueList = (list: BulletList, source: string): boolean => list.itemSpans.length > 1 && list.itemSpans.every((item) => opensWithCode(source, item));
|
|
95
|
+
|
|
70
96
|
/**
|
|
71
97
|
* Prose sentences ending in a colon that hand the reader straight to a list (「以下の通りです:」, "Here's what you need:").
|
|
72
98
|
* An item of a list is not prose: 「例: `code`」 ends in a colon once its code is masked, and it leads nowhere.
|
|
73
99
|
*/
|
|
74
|
-
export const colonLeadIns = (
|
|
100
|
+
export const colonLeadIns = (
|
|
101
|
+
sentences: readonly Sentence[],
|
|
102
|
+
lists: readonly BulletList[],
|
|
103
|
+
listSpans: readonly Span[],
|
|
104
|
+
source: string,
|
|
105
|
+
markdown = true,
|
|
106
|
+
): Sentence[] => {
|
|
75
107
|
const leadIns = lists.flatMap((list) => {
|
|
108
|
+
if (isValueList(list, source)) return [];
|
|
76
109
|
const before = sentenceRightBefore(sentences, list, source);
|
|
77
110
|
return before !== undefined && endsWithColon(before.text) && !insideAny(listSpans, before.span.start) ? [before] : [];
|
|
78
111
|
});
|
|
79
112
|
const fields = fieldLabels(leadIns);
|
|
80
|
-
|
|
113
|
+
const namesItsList = (sentence: Sentence): boolean => (markdown ? isBoldNounLabel(sentence, source) : isPlainNounLabel(sentence, source));
|
|
114
|
+
return leadIns.filter((sentence) => !fields.has(labelWords(sentence.text)) && !namesItsList(sentence));
|
|
81
115
|
};
|
|
82
116
|
|
|
83
117
|
/** Lead-ins in one or two sections are a how-to's procedure or a pair of lists; the rule's why is section after section. */
|
|
@@ -101,7 +135,7 @@ const sectionsHolding = (doc: ProseDocument, leadIns: readonly Sentence[]): numb
|
|
|
101
135
|
*/
|
|
102
136
|
export const colonLeadIn: Detector = (doc, options): Finding[] => {
|
|
103
137
|
const inDocumentLanguage = doc.sentences.filter((sentence) => sentence.embeddedLanguage === undefined);
|
|
104
|
-
const leadIns = colonLeadIns(inDocumentLanguage, doc.lists, doc.listSpans, doc.source);
|
|
138
|
+
const leadIns = colonLeadIns(inDocumentLanguage, doc.lists, doc.listSpans, doc.source, isMarkdownPath(doc.path));
|
|
105
139
|
if (sectionsHolding(doc, leadIns) < minSections(options)) return [];
|
|
106
140
|
const hits = leadIns.map((sentence) => ({ sentence, matched: sentence.text.trim() }));
|
|
107
141
|
return densityFindings(doc, hits, options.limit);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Detector, Finding, LexiconEntry, Paragraph, ProseDocument, Token } from "../plugin.ts";
|
|
2
2
|
import { formMinority } from "./form-minority.ts";
|
|
3
|
+
import { captionParagraphs, slotParagraphs } from "./final-period-captions.ts";
|
|
3
4
|
|
|
4
5
|
// A paragraph whose last sentence stops without its closing mark, in a document whose other paragraphs end with one. It
|
|
5
6
|
// takes no side: a document that ends none of its paragraphs with the mark (slides, labels) is not reported. The marks
|
|
@@ -102,7 +103,14 @@ const marksOf = (lexicon: readonly LexiconEntry[]): PeriodMarks => ({
|
|
|
102
103
|
export const missingFinalPeriod: Detector = (doc: ProseDocument, options): Finding[] => {
|
|
103
104
|
const text = doc.prose ?? doc.source;
|
|
104
105
|
const marks = marksOf(doc.lexicons["final-period"] ?? []);
|
|
105
|
-
const
|
|
106
|
+
const captions = captionParagraphs(
|
|
107
|
+
text,
|
|
108
|
+
doc.sections,
|
|
109
|
+
slotParagraphs(text, doc.paragraphs, (line) => isClosed(line, marks.ends)),
|
|
110
|
+
);
|
|
111
|
+
const ends = doc.paragraphs.flatMap((paragraph, index) =>
|
|
112
|
+
captions.has(index) ? [] : (paragraphEnd(text, paragraph, marks, doc.paragraphs[index + 1], doc.paragraphs[index - 1]) ?? []),
|
|
113
|
+
);
|
|
106
114
|
const minority = formMinority(ends, options.limit);
|
|
107
115
|
if (minority === undefined || minority.usual.form !== "closed") return [];
|
|
108
116
|
return minority.odd.map((end) => ({
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { ProseDocument, Span, StructureNode } from "../plugin.ts";
|
|
2
2
|
import { alternativeReader, placeholderStarts } from "../structure/alternative-clause.ts";
|
|
3
3
|
import { htmlTextBlocks } from "../structure/html-text-blocks.ts";
|
|
4
|
-
import type { ClauseReadings } from "../structure/numbering.ts";
|
|
4
|
+
import type { ClauseReadings, SkipReadings } from "../structure/numbering.ts";
|
|
5
|
+
import { markerTest } from "./ordinal-run-gaps.ts";
|
|
5
6
|
import { sideStepReader } from "../structure/side-step.ts";
|
|
6
7
|
import { patternsOf } from "./net-amount-mismatch.ts";
|
|
7
8
|
|
|
9
|
+
/** A heading that says what is under it is only some (partial-listing-marker: 抜粋, excerpt). */
|
|
10
|
+
const partialHeadingTest = (markers: readonly string[]): ((heading: string) => boolean) => {
|
|
11
|
+
const tests = markers.filter((marker) => marker !== "").map(markerTest);
|
|
12
|
+
return (heading) => tests.some((names) => names(heading));
|
|
13
|
+
};
|
|
14
|
+
|
|
8
15
|
/**
|
|
9
16
|
* What numberingBreaks reads besides the tree, from the document and its word lists: the text the tree leaves out (an
|
|
10
17
|
* HTML block's, in Markdown), the steps labelled with a word, the alternative and blank-numbered clauses.
|
|
@@ -12,11 +19,12 @@ import { patternsOf } from "./net-amount-mismatch.ts";
|
|
|
12
19
|
export const numberingReadings = (
|
|
13
20
|
doc: ProseDocument,
|
|
14
21
|
source: string,
|
|
15
|
-
): [unread: Span[], isSideStep: (node: StructureNode) => boolean, clauses: ClauseReadings] => [
|
|
22
|
+
): [unread: Span[], isSideStep: (node: StructureNode) => boolean, clauses: ClauseReadings, skips: SkipReadings] => [
|
|
16
23
|
doc.markup?.markdown === true ? htmlTextBlocks(source) : [],
|
|
17
24
|
sideStepReader(patternsOf(doc, "side-step-label")),
|
|
18
25
|
{
|
|
19
26
|
isAlternative: alternativeReader(source, patternsOf(doc, "alternative-clause-label")),
|
|
20
27
|
restarts: placeholderStarts(source, patternsOf(doc, "placeholder-division")),
|
|
21
28
|
},
|
|
29
|
+
{ source, isPartialHeading: partialHeadingTest(patternsOf(doc, "partial-listing-marker")) },
|
|
22
30
|
];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { LexiconEntry, Token } from "../plugin.ts";
|
|
2
|
+
import { entryEndsAt, type TokenRange } from "./lexicon-match.ts";
|
|
3
|
+
|
|
4
|
+
// An open list that a word pointing back opens (当該改良、改善等 "the said improvements, etc."): it names a list the text
|
|
5
|
+
// gave before, so whatever it leaves open was left open there, and is reported there if anywhere. The pointing words come
|
|
6
|
+
// from the language's requirement-open-end lexicon, in the group below. Pure.
|
|
7
|
+
|
|
8
|
+
const ANAPHOR = "list-anaphor";
|
|
9
|
+
const NAME_POS: ReadonlySet<string> = new Set(["NOUN", "PROPN"]);
|
|
10
|
+
/** The marks that join the items of a list (改良、改善等, 信用・ブランド等). */
|
|
11
|
+
const ITEM_JOINS: ReadonlySet<string> = new Set(["、", ",", "・"]);
|
|
12
|
+
|
|
13
|
+
export const anaphorWordsOf = (entries: readonly LexiconEntry[]): readonly LexiconEntry[] => entries.filter((entry) => entry.group === ANAPHOR);
|
|
14
|
+
|
|
15
|
+
/** Whether an entry is a pointing word rather than an open-end word. */
|
|
16
|
+
export const isAnaphorCue = (entry: LexiconEntry): boolean => entry.group === ANAPHOR;
|
|
17
|
+
|
|
18
|
+
const inList = (token: Token | undefined): boolean => token !== undefined && (NAME_POS.has(token.pos) || ITEM_JOINS.has(token.surface));
|
|
19
|
+
|
|
20
|
+
/** Where the list that ends right before index starts: the nouns and the marks between them, walking back. */
|
|
21
|
+
const listStart = (tokens: readonly Token[], index: number): number => (index > 0 && inList(tokens[index - 1]) ? listStart(tokens, index - 1) : index);
|
|
22
|
+
|
|
23
|
+
/** The first word of the list, past any joining mark the walk took in at its head. */
|
|
24
|
+
const firstWord = (tokens: readonly Token[], index: number, end: number): number =>
|
|
25
|
+
index < end && ITEM_JOINS.has(tokens[index]?.surface ?? "") ? firstWord(tokens, index + 1, end) : index;
|
|
26
|
+
|
|
27
|
+
/** Whether the list the open word at range closes opens with a word that points back to one given before (当該). */
|
|
28
|
+
export const refersBack = (tokens: readonly Token[], range: TokenRange, words: readonly LexiconEntry[]): boolean => {
|
|
29
|
+
const first = firstWord(tokens, listStart(tokens, range.start), range.start);
|
|
30
|
+
return words.some((entry) => entryEndsAt(tokens, entry, first + (entry.tokens?.length ?? 0)));
|
|
31
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { BulletList, LexiconEntry, Sentence, Span } from "../plugin.ts";
|
|
2
|
+
import { entryCloses } from "./lexicon-match.ts";
|
|
3
|
+
|
|
4
|
+
// The items of a list under a sentence that forbids or permits them (次の行為をしてはならない。 1. 知的財産権等を侵害すること):
|
|
5
|
+
// each item names a forbidden or permitted act, and a list in it is left open on purpose, as it would be in the sentence
|
|
6
|
+
// itself. Pure: the sentences, the lists and the language's prohibition and permission words come in.
|
|
7
|
+
|
|
8
|
+
/** Between a lead and its list: only blank space. */
|
|
9
|
+
const ONLY_SPACE = /^\s*$/u;
|
|
10
|
+
|
|
11
|
+
/** The run of items, written with line marks (①, ・) rather than as a list, that the item at index starts. */
|
|
12
|
+
const itemRun = (sentences: readonly Sentence[], index: number): Span | undefined => {
|
|
13
|
+
const first = sentences[index];
|
|
14
|
+
if (first?.listItem !== true || sentences[index - 1]?.listItem === true) return undefined;
|
|
15
|
+
const after = sentences.slice(index).findIndex((sentence) => sentence.listItem !== true);
|
|
16
|
+
const last = sentences[after === -1 ? sentences.length - 1 : index + after - 1] ?? first;
|
|
17
|
+
return { start: first.span.start, end: last.span.end };
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Where each list stands: the lists, and the runs of items written with line marks. */
|
|
21
|
+
const listsIn = (sentences: readonly Sentence[], lists: readonly BulletList[]): Span[] => [
|
|
22
|
+
...lists.map((list) => list.span),
|
|
23
|
+
...sentences.flatMap((_sentence, index) => itemRun(sentences, index) ?? []),
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
/** The last sentence that ends before the list, when only blank space stands between them. */
|
|
27
|
+
const leadOf = (source: string, sentences: readonly Sentence[], list: Span): Sentence | undefined => {
|
|
28
|
+
const lead = sentences.findLast((sentence) => sentence.span.end <= list.start);
|
|
29
|
+
return lead !== undefined && ONLY_SPACE.test(source.slice(lead.span.end, list.start)) ? lead : undefined;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** The sentences, by index, in a list led by a sentence ending in a prohibition or a permission (…してはならない。). */
|
|
33
|
+
export const itemsOpenOnPurpose = (
|
|
34
|
+
source: string,
|
|
35
|
+
sentences: readonly Sentence[],
|
|
36
|
+
lists: readonly BulletList[],
|
|
37
|
+
onPurpose: readonly LexiconEntry[],
|
|
38
|
+
): ReadonlySet<number> => {
|
|
39
|
+
const led = listsIn(sentences, lists).filter((list) => {
|
|
40
|
+
const lead = leadOf(source, sentences, list);
|
|
41
|
+
return lead !== undefined && onPurpose.some((entry) => entryCloses(lead, entry));
|
|
42
|
+
});
|
|
43
|
+
return new Set(
|
|
44
|
+
sentences.flatMap((sentence, index) => (led.some((list) => list.start <= sentence.span.start && sentence.span.start < list.end) ? [index] : [])),
|
|
45
|
+
);
|
|
46
|
+
};
|
|
@@ -41,8 +41,15 @@ export const scopeWordsOf = (entries: readonly LexiconEntry[]): ScopeWords => ({
|
|
|
41
41
|
/** Whether an entry is one of the scope cues rather than an open-end word. */
|
|
42
42
|
export const isScopeCue = (entry: LexiconEntry): boolean => SCOPE_GROUPS.has(entry.group ?? "");
|
|
43
43
|
|
|
44
|
+
/** Only marks from here to the end of the sentence. */
|
|
45
|
+
const closesSentence = (tokens: readonly Token[], index: number): boolean => tokens.slice(index).every((token) => token.pos === PUNCT);
|
|
46
|
+
|
|
47
|
+
/** A cue with position after counts only where it closes the sentence (使用しないこと。, not 不備がないことを確認する). */
|
|
44
48
|
const startsAt = (tokens: readonly Token[], entries: readonly LexiconEntry[], index: number): boolean =>
|
|
45
|
-
entries.some((entry) =>
|
|
49
|
+
entries.some((entry) => {
|
|
50
|
+
const end = index + (entry.tokens?.length ?? 0);
|
|
51
|
+
return entryEndsAt(tokens, entry, end) && (entry.position !== "after" || closesSentence(tokens, end));
|
|
52
|
+
});
|
|
46
53
|
|
|
47
54
|
/** A comma right after a predicate closes the clause the list stands in (消去し、). */
|
|
48
55
|
const closesClause = (tokens: readonly Token[], index: number): boolean => tokens[index]?.pos === PUNCT && PREDICATE_POS.has(tokens[index - 1]?.pos ?? "");
|
|
@@ -68,7 +68,7 @@ const lineBlocks = (doc: ProseDocument, text: string, frames: readonly OrdinalFr
|
|
|
68
68
|
const LINES_ABOVE = 3;
|
|
69
69
|
const LATIN_WORD = /^[A-Za-z][A-Za-z ]*$/u;
|
|
70
70
|
|
|
71
|
-
const markerTest = (marker: string): ((text: string) => boolean) => {
|
|
71
|
+
export const markerTest = (marker: string): ((text: string) => boolean) => {
|
|
72
72
|
if (!LATIN_WORD.test(marker)) return (text) => text.includes(marker);
|
|
73
73
|
const word = new RegExp(String.raw`(?<![A-Za-z])${marker}(?![A-Za-z])`, "iu");
|
|
74
74
|
return (text) => word.test(text);
|
|
@@ -18,6 +18,7 @@ import { citationLead } from "./citation-sentence.ts";
|
|
|
18
18
|
import { acronymExpansionSpans } from "../acronym-expansion.ts";
|
|
19
19
|
import { nameEndingRuns, namesWrittenOneWay } from "../name-ending-run.ts";
|
|
20
20
|
import { entriesForGenre } from "../lexicon-genres.ts";
|
|
21
|
+
import { echoesQuotation, quotationsIn } from "../quote-echo.ts";
|
|
21
22
|
|
|
22
23
|
export type IsOpen = (start: number, end: number) => boolean;
|
|
23
24
|
|
|
@@ -56,6 +57,8 @@ export type Names = {
|
|
|
56
57
|
readonly nameEndings: readonly string[];
|
|
57
58
|
/** The facilities' and organisations' names the document writes one way only (こども動物園). */
|
|
58
59
|
readonly oneWayNames: ReadonlySet<string>;
|
|
60
|
+
/** What the document quotes, every quotation's inside: a phrase the writer repeats from one keeps its spelling. */
|
|
61
|
+
readonly quotations: readonly string[];
|
|
59
62
|
};
|
|
60
63
|
|
|
61
64
|
export const namesOf = (doc: ProseDocument, genre: string | undefined): Names => ({
|
|
@@ -70,6 +73,7 @@ export const namesOf = (doc: ProseDocument, genre: string | undefined): Names =>
|
|
|
70
73
|
oneWayNames: namesWrittenOneWay(
|
|
71
74
|
[...doc.sentences, ...(doc.tableCells?.() ?? [])].flatMap(({ tokens }) => nameEndingRuns(tokens ?? [], patternsOf(doc, NAME_ENDING, genre))),
|
|
72
75
|
),
|
|
76
|
+
quotations: doc.sentences.flatMap(({ text }) => quotationsIn(text, quotedSpans(text, QUOTATION_MARKS))),
|
|
73
77
|
});
|
|
74
78
|
|
|
75
79
|
/** Spans placed in the source, placed in a sentence's text instead. */
|
|
@@ -99,8 +103,8 @@ const ownSpellingSpans = (sentence: Sentence, names: Names): Span[] => [
|
|
|
99
103
|
/**
|
|
100
104
|
* Whether a stretch of the sentence is outside a quotation, the team's names, a company's name (関東珪曹硝子㈱), a reading in
|
|
101
105
|
* brackets (HTTP(えいちてぃーてぃーぴー)), a label opening the sentence ((答)), a spelling mentioned ((曇)とも書く), a
|
|
102
|
-
* contact's name beside its phone number
|
|
103
|
-
* fixed short form, a mention is the subject, and the rest keep their own spelling.
|
|
106
|
+
* contact's name beside its phone number, what keeps a spelling of its own and a phrase repeated from a quotation: a reading is
|
|
107
|
+
* not a spelling at all, a label is a fixed short form, a mention is the subject, and the rest keep their own spelling.
|
|
104
108
|
*/
|
|
105
109
|
export const isOpenIn = (sentence: Sentence, names: Names): IsOpen => {
|
|
106
110
|
const closed = [
|
|
@@ -115,5 +119,6 @@ export const isOpenIn = (sentence: Sentence, names: Names): IsOpen => {
|
|
|
115
119
|
...ownSpellingSpans(sentence, names),
|
|
116
120
|
];
|
|
117
121
|
const named = nameSpans(sentence.text, names.team);
|
|
118
|
-
return (start, end) =>
|
|
122
|
+
return (start, end) =>
|
|
123
|
+
!isWithinAny(closed, { start, end }) && !touchesAny(named, start, end) && !echoesQuotation(sentence.text, { start, end }, names.quotations);
|
|
119
124
|
};
|