chaffjs 0.42.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/detectors/bold-label.d.ts +2 -0
- package/dist/detectors/bold-label.d.ts.map +1 -1
- package/dist/detectors/bold-label.js +4 -0
- package/dist/detectors/bold-label.js.map +1 -1
- package/dist/detectors/clause-shape.d.ts +8 -2
- package/dist/detectors/clause-shape.d.ts.map +1 -1
- package/dist/detectors/clause-shape.js +14 -6
- package/dist/detectors/clause-shape.js.map +1 -1
- package/dist/detectors/document-shape.d.ts +6 -1
- package/dist/detectors/document-shape.d.ts.map +1 -1
- package/dist/detectors/document-shape.js +14 -4
- package/dist/detectors/document-shape.js.map +1 -1
- package/dist/detectors/doubled-word.d.ts.map +1 -1
- package/dist/detectors/doubled-word.js +5 -1
- package/dist/detectors/doubled-word.js.map +1 -1
- package/dist/detectors/en-shape.d.ts.map +1 -1
- package/dist/detectors/en-shape.js +12 -1
- package/dist/detectors/en-shape.js.map +1 -1
- package/dist/detectors/ending-refrain.d.ts +9 -0
- package/dist/detectors/ending-refrain.d.ts.map +1 -0
- package/dist/detectors/ending-refrain.js +52 -0
- package/dist/detectors/ending-refrain.js.map +1 -0
- package/dist/detectors/fact-consistency.d.ts.map +1 -1
- package/dist/detectors/fact-consistency.js +5 -1
- package/dist/detectors/fact-consistency.js.map +1 -1
- package/dist/detectors/gram-predicate.d.ts.map +1 -1
- package/dist/detectors/gram-predicate.js +12 -3
- package/dist/detectors/gram-predicate.js.map +1 -1
- package/dist/detectors/lexicon.d.ts.map +1 -1
- package/dist/detectors/lexicon.js +1 -0
- package/dist/detectors/lexicon.js.map +1 -1
- package/dist/detectors/lookalike-character.d.ts +2 -0
- package/dist/detectors/lookalike-character.d.ts.map +1 -1
- package/dist/detectors/lookalike-character.js +36 -9
- package/dist/detectors/lookalike-character.js.map +1 -1
- package/dist/detectors/mark-shape.d.ts +1 -1
- package/dist/detectors/mark-shape.d.ts.map +1 -1
- package/dist/detectors/mark-shape.js +29 -12
- package/dist/detectors/mark-shape.js.map +1 -1
- package/dist/detectors/number-style.d.ts +7 -1
- package/dist/detectors/number-style.d.ts.map +1 -1
- package/dist/detectors/number-style.js +21 -1
- package/dist/detectors/number-style.js.map +1 -1
- package/dist/detectors/number-unit.d.ts +7 -1
- package/dist/detectors/number-unit.d.ts.map +1 -1
- package/dist/detectors/number-unit.js +20 -6
- package/dist/detectors/number-unit.js.map +1 -1
- package/dist/detectors/particle-run-long-forms.d.ts +7 -0
- package/dist/detectors/particle-run-long-forms.d.ts.map +1 -0
- package/dist/detectors/particle-run-long-forms.js +23 -0
- package/dist/detectors/particle-run-long-forms.js.map +1 -0
- package/dist/detectors/particle-run-quoted-names.d.ts +6 -0
- package/dist/detectors/particle-run-quoted-names.d.ts.map +1 -0
- package/dist/detectors/particle-run-quoted-names.js +18 -0
- package/dist/detectors/particle-run-quoted-names.js.map +1 -0
- package/dist/detectors/register-separate-part.d.ts +9 -1
- package/dist/detectors/register-separate-part.d.ts.map +1 -1
- package/dist/detectors/register-separate-part.js +23 -0
- package/dist/detectors/register-separate-part.js.map +1 -1
- package/dist/detectors/register-voice.d.ts +4 -3
- package/dist/detectors/register-voice.d.ts.map +1 -1
- package/dist/detectors/register-voice.js +11 -4
- package/dist/detectors/register-voice.js.map +1 -1
- package/dist/detectors/register.d.ts.map +1 -1
- package/dist/detectors/register.js +9 -6
- package/dist/detectors/register.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 +7 -3
- package/dist/detectors/sentence-ending.js.map +1 -1
- package/dist/detectors/signals.d.ts.map +1 -1
- package/dist/detectors/signals.js +5 -2
- package/dist/detectors/signals.js.map +1 -1
- package/dist/detectors/stacked-hedge.d.ts +4 -2
- package/dist/detectors/stacked-hedge.d.ts.map +1 -1
- package/dist/detectors/stacked-hedge.js +16 -3
- package/dist/detectors/stacked-hedge.js.map +1 -1
- package/dist/detectors/token-shape.d.ts.map +1 -1
- package/dist/detectors/token-shape.js +13 -1
- package/dist/detectors/token-shape.js.map +1 -1
- package/dist/detectors/unknown-word-context.d.ts +5 -0
- package/dist/detectors/unknown-word-context.d.ts.map +1 -1
- package/dist/detectors/unknown-word-context.js +8 -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 +3 -3
- package/dist/detectors/unknown-word.js.map +1 -1
- package/dist/detectors/weasel-word.d.ts.map +1 -1
- package/dist/detectors/weasel-word.js +23 -4
- package/dist/detectors/weasel-word.js.map +1 -1
- package/dist/facts/era-year.d.ts +2 -0
- package/dist/facts/era-year.d.ts.map +1 -0
- package/dist/facts/era-year.js +7 -0
- package/dist/facts/era-year.js.map +1 -0
- package/dist/facts/fact-scope.d.ts +1 -1
- package/dist/facts/fact-scope.d.ts.map +1 -1
- package/dist/facts/fact-scope.js +18 -8
- package/dist/facts/fact-scope.js.map +1 -1
- package/dist/facts/table-facts.d.ts.map +1 -1
- package/dist/facts/table-facts.js +18 -2
- package/dist/facts/table-facts.js.map +1 -1
- package/dist/own-title-quote.d.ts +7 -0
- package/dist/own-title-quote.d.ts.map +1 -0
- package/dist/own-title-quote.js +19 -0
- package/dist/own-title-quote.js.map +1 -0
- package/dist/structure/definition-use.d.ts.map +1 -1
- package/dist/structure/definition-use.js +3 -1
- package/dist/structure/definition-use.js.map +1 -1
- package/dist/structure-shape/features.d.ts.map +1 -1
- package/dist/structure-shape/features.js +15 -2
- package/dist/structure-shape/features.js.map +1 -1
- package/dist/word-use.d.ts.map +1 -1
- package/dist/word-use.js +9 -1
- package/dist/word-use.js.map +1 -1
- package/package.json +3 -3
- package/rules/adverb-overuse.yaml +2 -2
- package/rules/bracket-nesting.yaml +7 -2
- package/rules/bracket-width-consistency.yaml +2 -2
- package/rules/doubled-word.yaml +2 -2
- package/rules/excessive-hedging.yaml +2 -1
- package/rules/fact-conflict.yaml +2 -2
- package/rules/lookalike-character.yaml +2 -2
- package/rules/ngram-repetition.yaml +2 -2
- package/rules/no-doubled-joshi.yaml +2 -2
- package/rules/no-mixed-desumasu.yaml +3 -2
- package/rules/number-style-consistency.yaml +2 -2
- package/rules/number-without-unit.yaml +2 -2
- package/rules/orthographic-variant.yaml +2 -2
- package/rules/repeated-sentence-ending.yaml +2 -2
- package/rules/title-length.yaml +7 -2
- package/rules/undefined-acronym.yaml +2 -2
- package/rules/unknown-word.yaml +2 -2
- package/rules/unused-definition.yaml +4 -2
- package/src/detectors/bold-label.ts +6 -0
- package/src/detectors/clause-shape.ts +14 -12
- package/src/detectors/document-shape.ts +17 -6
- package/src/detectors/doubled-word.ts +9 -1
- package/src/detectors/en-shape.ts +15 -1
- package/src/detectors/ending-refrain.ts +66 -0
- package/src/detectors/fact-consistency.ts +4 -1
- package/src/detectors/gram-predicate.ts +14 -3
- package/src/detectors/lexicon.ts +1 -0
- package/src/detectors/lookalike-character.ts +40 -10
- package/src/detectors/mark-shape.ts +31 -12
- package/src/detectors/number-style.ts +29 -2
- package/src/detectors/number-unit.ts +29 -8
- package/src/detectors/particle-run-long-forms.ts +34 -0
- package/src/detectors/particle-run-quoted-names.ts +27 -0
- package/src/detectors/register-separate-part.ts +32 -1
- package/src/detectors/register-voice.ts +17 -4
- package/src/detectors/register.ts +9 -6
- package/src/detectors/sentence-ending.ts +10 -4
- package/src/detectors/signals.ts +5 -2
- package/src/detectors/stacked-hedge.ts +24 -7
- package/src/detectors/token-shape.ts +14 -1
- package/src/detectors/unknown-word-context.ts +9 -0
- package/src/detectors/unknown-word.ts +4 -2
- package/src/detectors/weasel-word.ts +31 -5
- package/src/facts/era-year.ts +7 -0
- package/src/facts/fact-scope.ts +20 -6
- package/src/facts/table-facts.ts +31 -3
- package/src/own-title-quote.ts +28 -0
- package/src/structure/definition-use.ts +4 -1
- package/src/structure-shape/features.ts +18 -2
- package/src/word-use.ts +10 -1
package/src/detectors/lexicon.ts
CHANGED
|
@@ -110,6 +110,7 @@ export const hedging: Detector = (doc, options): Finding[] => {
|
|
|
110
110
|
hedges: options.lexicon ?? [],
|
|
111
111
|
frames: doc.lexicons["hedge-frame"] ?? [],
|
|
112
112
|
scope: doc.lexicons["hedge-scope"] ?? [],
|
|
113
|
+
complements: doc.lexicons["hedge-complement"] ?? [],
|
|
113
114
|
});
|
|
114
115
|
const reported = new Set(stacked.map((entry) => entry.sentence.span.start));
|
|
115
116
|
const density = hedgingDensity(doc, options).filter((finding) => !reported.has(Number(finding.values["offset"])));
|
|
@@ -53,6 +53,32 @@ export const lookalikesIn = (source: string): Lookalike[] =>
|
|
|
53
53
|
(left, right) => left.span.start - right.span.start,
|
|
54
54
|
);
|
|
55
55
|
|
|
56
|
+
/** Words naming the characters themselves (濁点, NFD, Kangxi). A look-alike next to one is an example shown on purpose. */
|
|
57
|
+
const MENTION_LEXICON = "lookalike-mention";
|
|
58
|
+
|
|
59
|
+
const lineStartBefore = (source: string, at: number): number => source.lastIndexOf("\n", at - 1) + 1;
|
|
60
|
+
|
|
61
|
+
const lineEndAfter = (source: string, at: number): number => {
|
|
62
|
+
const end = source.indexOf("\n", at);
|
|
63
|
+
return end === -1 ? source.length : end;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** The look-alike's line with the line before and the line after it: an example and its explanation may sit on neighbouring lines (a code comment). */
|
|
67
|
+
const linesAround = (source: string, span: Span): string => {
|
|
68
|
+
const lineStart = lineStartBefore(source, span.start);
|
|
69
|
+
const lineEnd = lineEndAfter(source, span.end);
|
|
70
|
+
const start = lineStart === 0 ? 0 : lineStartBefore(source, lineStart - 1);
|
|
71
|
+
const end = lineEnd === source.length ? lineEnd : lineEndAfter(source, lineEnd + 1);
|
|
72
|
+
return source.slice(start, end).toLowerCase();
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/** Whether a word that names these characters stands on or next to the look-alike's line (ホ゜ケット のような…濁点のチェック). */
|
|
76
|
+
export const isShownExample = (source: string, span: Span, mentions: readonly string[]): boolean => {
|
|
77
|
+
if (mentions.length === 0) return false;
|
|
78
|
+
const around = linesAround(source, span);
|
|
79
|
+
return mentions.some((mention) => around.includes(mention.toLowerCase()));
|
|
80
|
+
};
|
|
81
|
+
|
|
56
82
|
const QUOTE_REACH = 20;
|
|
57
83
|
|
|
58
84
|
const quoteOf = (source: string, span: Span): string =>
|
|
@@ -63,13 +89,17 @@ const quoteOf = (source: string, span: Span): string =>
|
|
|
63
89
|
|
|
64
90
|
const codesOf = (text: string): string => Array.from(text).map(codePointName).join(" ");
|
|
65
91
|
|
|
66
|
-
export const lookalikeCharacter: Detector = (doc): Finding[] =>
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
92
|
+
export const lookalikeCharacter: Detector = (doc): Finding[] => {
|
|
93
|
+
const mentions = (doc.lexicons[MENTION_LEXICON] ?? []).map((entry) => entry.pattern);
|
|
94
|
+
return lookalikesIn(doc.source)
|
|
95
|
+
.filter((lookalike) => !isShownExample(doc.source, lookalike.span, mentions))
|
|
96
|
+
.map((lookalike) => ({
|
|
97
|
+
rule: "",
|
|
98
|
+
severity: "warning",
|
|
99
|
+
line: 0,
|
|
100
|
+
column: 0,
|
|
101
|
+
quote: quoteOf(doc.source, lookalike.span),
|
|
102
|
+
values: { written: lookalike.written, usual: lookalike.usual, code: codesOf(lookalike.written), offset: lookalike.span.start },
|
|
103
|
+
variant: lookalike.kind,
|
|
104
|
+
}));
|
|
105
|
+
};
|
|
@@ -4,6 +4,7 @@ import { isConventionalPhrase } from "./caps-phrase.ts";
|
|
|
4
4
|
import { minorityReport } from "../spacing-minority.ts";
|
|
5
5
|
import { externalLinkTitleSpans } from "../link-title.ts";
|
|
6
6
|
import { formulaBracketSpans } from "../formula-brackets.ts";
|
|
7
|
+
import { ownTitleQuoteSpans } from "../own-title-quote.ts";
|
|
7
8
|
import { isWithinAny, quotedSpans } from "../quoted-span.ts";
|
|
8
9
|
import { bracketPlaceholderSpans, capitalLineSpans, captionsOf, isCaptionAt, isWithinSorted } from "./caps-caption.ts";
|
|
9
10
|
import { lineStarts } from "../position.ts";
|
|
@@ -93,32 +94,49 @@ const minorityFindings = <T extends Sided>(items: readonly T[], limit: number, v
|
|
|
93
94
|
const ownSentences = (doc: ProseDocument): readonly Sentence[] => doc.sentences.filter((sentence) => sentence.embeddedLanguage === undefined);
|
|
94
95
|
|
|
95
96
|
/**
|
|
96
|
-
* A bracketed item number opening a line ((1)開催趣旨, (ア), (iv), a list bullet before it), both brackets of one width
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* is
|
|
97
|
+
* A bracketed item number opening a line ((1)開催趣旨, (ア), (iv), a list bullet before it), both brackets of one width,
|
|
98
|
+
* or a tag in Latin letters opening a line ([Web]登録完了のお知らせ, a subject line's prefix). It labels the line, a style of
|
|
99
|
+
* its own: the brackets of the prose around it may be written the other width. A bracketed word in Japanese at a line's head
|
|
100
|
+
* ((背景), (注)) is not a label of that kind, and an item number the prose refers to (次の(1)及び(2)) is written in the prose;
|
|
101
|
+
* both stay with the prose's brackets.
|
|
100
102
|
*/
|
|
101
103
|
const LINE_HEAD = /^\s*(?:[-*+] +)?/u;
|
|
102
|
-
const BRACKETED = /^([(([[])([^))\]]]{1,
|
|
104
|
+
const BRACKETED = /^([(([[])([^))\]]]{1,12})([))\]]])/u;
|
|
103
105
|
const NUMBERING = /^(?:[0-90-9]{1,3}|[一二三四五六七八九十]{1,3}|[A-Za-zA-Za-zァ-ヶぁ-んヲ-ン])$/u;
|
|
104
106
|
/** Roman numerals i to x, either case. */
|
|
105
107
|
const ROMAN = /^(?:i{2,3}|iv|vi{1,3}|ix|I{2,3}|IV|VI{1,3}|IX)$/u;
|
|
108
|
+
/** A word in Latin letters with a capital, digits, dots or hyphens after its first letter (Web, e-Gov); not a numeral (iiii). */
|
|
109
|
+
const LATIN_TAG = /^(?=.*[A-Z])[A-Za-z][A-Za-z0-9.-]+$/u;
|
|
106
110
|
const CLOSER_OF: Readonly<Record<string, string>> = { "(": ")", "(": ")", "[": "]", "[": "]" };
|
|
107
111
|
|
|
108
|
-
const
|
|
112
|
+
const isLineLabel = (text: string): boolean => NUMBERING.test(text) || ROMAN.test(text) || LATIN_TAG.test(text);
|
|
109
113
|
|
|
110
|
-
/** The offsets in a line of its
|
|
114
|
+
/** The offsets in a line of its label's opening and closing bracket, or none. */
|
|
111
115
|
const enumeratorIn = (line: string): readonly number[] => {
|
|
112
116
|
const head = LINE_HEAD.exec(line)?.[0].length ?? 0;
|
|
113
117
|
const found = BRACKETED.exec(line.slice(head));
|
|
114
|
-
if (found === null || CLOSER_OF[found[1] ?? ""] !== found[3] || !
|
|
118
|
+
if (found === null || CLOSER_OF[found[1] ?? ""] !== found[3] || !isLineLabel(found[2] ?? "")) return [];
|
|
115
119
|
return [head, head + found[0].length - 1];
|
|
116
120
|
};
|
|
117
121
|
|
|
118
|
-
/**
|
|
122
|
+
/**
|
|
123
|
+
* An item's address in the prose: a section's number and its item's bracketed number (上記4(2)で), as the lines number them.
|
|
124
|
+
* Not after a digit, a comma or a point, so a figure and its bracketed figure in a table (1,054(47)) is not one.
|
|
125
|
+
*/
|
|
126
|
+
const ITEM_ADDRESS = /(?<![0-90-9,,..])[0-90-9]{1,2}(?:\([0-90-9]{1,2}\)|([0-90-9]{1,2}))(?=[\p{Script=Han}\p{Script=Hiragana}])/gu;
|
|
127
|
+
|
|
128
|
+
const addressBrackets = (match: RegExpMatchArray & { index: number }): number[] => {
|
|
129
|
+
const end = match.index + match[0].length - 1;
|
|
130
|
+
return [match.index + match[0].search(/[((]/u), end];
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/** The offsets in `source` of each line's label's opening and closing bracket, and of the brackets of an item's address. */
|
|
119
134
|
export const enumeratorBracketOffsets = (source: string): ReadonlySet<number> => {
|
|
120
135
|
const starts = lineStarts(source);
|
|
121
|
-
return new Set(
|
|
136
|
+
return new Set([
|
|
137
|
+
...source.split("\n").flatMap((line, index) => enumeratorIn(line).map((at) => (starts[index] ?? 0) + at)),
|
|
138
|
+
...[...source.matchAll(ITEM_ADDRESS)].flatMap(addressBrackets),
|
|
139
|
+
]);
|
|
122
140
|
};
|
|
123
141
|
|
|
124
142
|
/** Appended to a mark's kind for an item number's bracket. A lexicon's group, a word from YAML, never holds a NUL. */
|
|
@@ -174,9 +192,10 @@ const withNoteKind = (mark: Mark, notes: ReadonlySet<number>): Mark =>
|
|
|
174
192
|
export const markConsistency: Detector = (doc, options): Finding[] => {
|
|
175
193
|
const script = SCRIPT[doc.language];
|
|
176
194
|
if (script === undefined) return [];
|
|
177
|
-
// A link that quotes an outside page's title keeps that page's marks ((コンテキスト内) in a WCAG title).
|
|
178
|
-
const titles = externalLinkTitleSpans(doc.source, doc.links);
|
|
179
195
|
const forms = formsOf(options.lexicon ?? []);
|
|
196
|
+
// A link that quotes an outside page's title keeps that page's marks ((コンテキスト内) in a WCAG title), and a quotation
|
|
197
|
+
// of the document's own heading keeps the heading's.
|
|
198
|
+
const titles = [...externalLinkTitleSpans(doc.source, doc.links), ...ownTitleQuoteSpans(doc.source, doc.markup?.headings ?? [], new Set(forms.keys()))];
|
|
180
199
|
const enumerators = enumeratorBracketOffsets(doc.source);
|
|
181
200
|
const doubled = doubledParenOffsets(doc.source);
|
|
182
201
|
const notes = noteMarkerOffsets(doc.source);
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
import { escapeRegExp } from "../orthography.ts";
|
|
5
5
|
import { QUOTATION_MARKS, isWithinAny, quotedSpans } from "../quoted-span.ts";
|
|
6
6
|
import { isCitation } from "./kutoten-consistency.ts";
|
|
7
|
-
import
|
|
7
|
+
import { inDocumentOrder } from "../structure/issues.ts";
|
|
8
|
+
import type { Detector, Finding, ProseDocument, Sentence, Span, StructureNode, Token } from "../plugin.ts";
|
|
8
9
|
|
|
9
10
|
export type NumberKind = "count" | "grouping" | "percent" | "count-small" | "count-large";
|
|
10
11
|
|
|
@@ -253,12 +254,38 @@ const findingOf = (mark: NumberMark, usual: NumberMark, count: number, of: numbe
|
|
|
253
254
|
variant: mark.kind,
|
|
254
255
|
});
|
|
255
256
|
|
|
257
|
+
const isInArticle = (mark: NumberMark, articles: readonly Span[]): boolean =>
|
|
258
|
+
isWithinAny(articles, { start: mark.offset, end: mark.offset + mark.written.length });
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* The marks of the document's own text. A document that is not a statute and sets out articles where most of its numbers are
|
|
262
|
+
* outside them (a manual quoting the order its fees rest on) quotes the law there, and the law keeps its own numerals
|
|
263
|
+
* (二千四百円). A document whose numbers are mostly inside its articles (work rules) is written in articles itself.
|
|
264
|
+
*/
|
|
265
|
+
export const ownMarks = (marks: readonly NumberMark[], articles: readonly Span[]): readonly NumberMark[] => {
|
|
266
|
+
const outside = marks.filter((mark) => !isInArticle(mark, articles));
|
|
267
|
+
return outside.length > marks.length - outside.length ? outside : marks;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
/** A numbered heading of the document's own outline (2.1 Corpus) is read as an article too; a law's article names its unit (第5条, Article 5). */
|
|
271
|
+
const OUTLINE_NUMBER = /^[\d.]+$/u;
|
|
272
|
+
|
|
273
|
+
const isLawArticle = (node: StructureNode): boolean => node.kind === "article" && !OUTLINE_NUMBER.test(String(node.attrs["label"] ?? ""));
|
|
274
|
+
|
|
275
|
+
const lawArticleSpans = (doc: ProseDocument): Span[] =>
|
|
276
|
+
doc.structure === undefined ? [] : inDocumentOrder(doc.structure).flatMap((node) => (isLawArticle(node) ? [node.span] : []));
|
|
277
|
+
|
|
278
|
+
const isMixed = (marks: readonly NumberMark[]): boolean => new Set(marks.map((mark) => mark.style)).size > 1;
|
|
279
|
+
|
|
256
280
|
/** For each kind of number, the marks written in the document's less common style. */
|
|
257
281
|
export const numberStyleConsistency: Detector = (doc, options): Finding[] => {
|
|
258
282
|
const words = wordsOf(doc);
|
|
259
|
-
const
|
|
283
|
+
const written = doc.sentences
|
|
260
284
|
.filter((sentence) => sentence.embeddedLanguage === undefined && !isCitation(sentence, doc.source))
|
|
261
285
|
.flatMap((sentence) => numberMarksIn(sentence, words, doc.language, doc.source));
|
|
286
|
+
// doc.structure builds the tree when first read: a document with one style in every kind has nothing to report either way.
|
|
287
|
+
if (!KINDS.some((kind) => isMixed(written.filter((mark) => mark.kind === kind)))) return [];
|
|
288
|
+
const marks = ownMarks(written, lawArticleSpans(doc));
|
|
262
289
|
return KINDS.flatMap((kind) => {
|
|
263
290
|
const ofKind = marks.filter((mark) => mark.kind === kind);
|
|
264
291
|
const { odd, usual } = minorityStyles(ofKind, options.limit);
|
|
@@ -9,8 +9,15 @@ import { quoteAt } from "./structure-tree.ts";
|
|
|
9
9
|
import { formsOf } from "./currency-notation.ts";
|
|
10
10
|
import { scaledFiguresIn, scaleGaps, type ScaleWords } from "./scaled-figure-unit.ts";
|
|
11
11
|
|
|
12
|
-
/** One value of a kind: where its number starts, as written, and its unit ("" when bare). */
|
|
13
|
-
export type Measured = {
|
|
12
|
+
/** One value of a kind: where its number starts, as written, and its unit ("" when bare). row: the table row of a cell. */
|
|
13
|
+
export type Measured = {
|
|
14
|
+
readonly kind: string;
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly offset: number;
|
|
17
|
+
readonly written: string;
|
|
18
|
+
readonly unit: string;
|
|
19
|
+
readonly row?: string;
|
|
20
|
+
};
|
|
14
21
|
|
|
15
22
|
export type UnitGap = { readonly value: Measured; readonly unit: string };
|
|
16
23
|
|
|
@@ -50,10 +57,11 @@ export const unitOf = (text: string, units: ReadonlySet<string>): string | undef
|
|
|
50
57
|
return currency === "" && UNIT_SHAPE.test(suffix) && isUnit(suffix, units) ? suffix : undefined;
|
|
51
58
|
};
|
|
52
59
|
|
|
53
|
-
const measured = (kind: string, name: string, text: string, offset: number, units: ReadonlySet<string
|
|
60
|
+
const measured = (kind: string, name: string, text: string, offset: number, units: ReadonlySet<string>, row?: string): Measured[] => {
|
|
54
61
|
const written = text.trim();
|
|
55
62
|
const unit = unitOf(written, units);
|
|
56
|
-
|
|
63
|
+
const placed = row === undefined ? {} : { row };
|
|
64
|
+
return unit === undefined ? [] : [{ kind, name, offset: offset + Math.max(0, text.indexOf(written)), written, unit, ...placed }];
|
|
57
65
|
};
|
|
58
66
|
|
|
59
67
|
type LabelLine = { readonly label: string; readonly value: string; readonly at: number };
|
|
@@ -83,9 +91,10 @@ const tableValues = (source: string, table: MarkdownNode, index: number, units:
|
|
|
83
91
|
const [header, ...body] = table.children ?? [];
|
|
84
92
|
return (header?.children ?? []).flatMap((headCell, column) => {
|
|
85
93
|
const name = cellText(source, headCell)?.text.trim() ?? "";
|
|
86
|
-
return body.flatMap((row) => {
|
|
94
|
+
return body.flatMap((row, rowIndex) => {
|
|
87
95
|
const cell = cellText(source, row.children?.[column]);
|
|
88
|
-
|
|
96
|
+
const place = `table ${String(index)} row ${String(rowIndex)}`;
|
|
97
|
+
return cell === undefined || name === "" ? [] : measured(`table ${String(index)}: ${name}`, name, cell.text, cell.start, units, place);
|
|
89
98
|
});
|
|
90
99
|
});
|
|
91
100
|
};
|
|
@@ -134,6 +143,17 @@ export const unitGaps = (values: readonly Measured[]): UnitGap[] => {
|
|
|
134
143
|
return [...kinds.values()].flatMap(gapsOfKind).toSorted((left, right) => left.value.offset - right.value.offset);
|
|
135
144
|
};
|
|
136
145
|
|
|
146
|
+
/**
|
|
147
|
+
* A bare cell whose row gives another column, one that carries a unit elsewhere, a bare number too: the row counts a
|
|
148
|
+
* thing of its own (| Website visits | 412,000 | 486,000 | +18% |), in a table whose rows are different measures.
|
|
149
|
+
*/
|
|
150
|
+
export const isBareRow = (gap: UnitGap, values: readonly Measured[]): boolean => {
|
|
151
|
+
const { row, kind } = gap.value;
|
|
152
|
+
if (row === undefined) return false;
|
|
153
|
+
const measuredKinds = new Set(values.filter((value) => value.unit !== "").map((value) => value.kind));
|
|
154
|
+
return values.some((value) => value.row === row && value.kind !== kind && value.unit === "" && measuredKinds.has(value.kind));
|
|
155
|
+
};
|
|
156
|
+
|
|
137
157
|
const unitsOf = (doc: ProseDocument): Set<string> =>
|
|
138
158
|
new Set(UNIT_LEXICONS.flatMap((name) => (doc.lexicons[name] ?? []).flatMap((entry) => [entry.pattern, entry.pattern.toLowerCase()])));
|
|
139
159
|
|
|
@@ -184,8 +204,9 @@ const scaleFindings = (doc: ProseDocument): Finding[] => {
|
|
|
184
204
|
|
|
185
205
|
const columnFindings = (doc: ProseDocument): Finding[] => {
|
|
186
206
|
const count = pieceCountOf(doc);
|
|
187
|
-
|
|
188
|
-
|
|
207
|
+
const values = measuredValues(doc.source, doc.prose ?? doc.source, unitsOf(doc));
|
|
208
|
+
return unitGaps(values)
|
|
209
|
+
.filter((gap) => !isPieceCount(gap, count) && !isBareRow(gap, values))
|
|
189
210
|
.map((gap) => ({
|
|
190
211
|
rule: "number-without-unit",
|
|
191
212
|
severity: "warning",
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Span, Token } from "../plugin.ts";
|
|
2
|
+
|
|
3
|
+
// The long form a writer gives a short name to (性犯罪・性暴力の被害者のためのワンストップ支援センター(以下「ワンストップ支援センター」
|
|
4
|
+
// という)): the long form is a name the writer cannot rephrase, so its particles are read as one noun, like a quoted title.
|
|
5
|
+
// Pure: the words that open such an aside (以下) and what keeps a phrase going come in.
|
|
6
|
+
|
|
7
|
+
const OPENING = /[((]\s*/gu;
|
|
8
|
+
|
|
9
|
+
/** Where the asides that give a short name open in text (the bracket's offset), each opened by one of markers. */
|
|
10
|
+
const namingAsides = (text: string, markers: readonly string[]): number[] =>
|
|
11
|
+
[...text.matchAll(OPENING)]
|
|
12
|
+
.filter((open) => markers.some((marker) => marker !== "" && text.startsWith(marker, open.index + open[0].length)))
|
|
13
|
+
.map((open) => open.index);
|
|
14
|
+
|
|
15
|
+
/** The words written straight before at, back to the first one that does not continue the phrase. */
|
|
16
|
+
const phraseBefore = (tokens: readonly Token[], at: number, continues: (token: Token) => boolean): Span | undefined => {
|
|
17
|
+
const last = tokens.findLastIndex((token) => token.span.end <= at);
|
|
18
|
+
if (last === -1 || tokens[last]?.span.end !== at) return undefined;
|
|
19
|
+
const stop = tokens.slice(0, last + 1).findLastIndex((token) => !continues(token));
|
|
20
|
+
const first = tokens[stop + 1];
|
|
21
|
+
return first === undefined || stop === last ? undefined : { start: first.span.start, end: at };
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The long forms named by an aside in a sentence (text starting at offset in the document, tokens in document offsets).
|
|
26
|
+
* markers: the words that open a naming aside (以下). continues: whether a word belongs to the phrase (a noun, the nesting の).
|
|
27
|
+
*/
|
|
28
|
+
export const namedLongForms = (
|
|
29
|
+
text: string,
|
|
30
|
+
offset: number,
|
|
31
|
+
tokens: readonly Token[],
|
|
32
|
+
markers: readonly string[],
|
|
33
|
+
continues: (token: Token) => boolean,
|
|
34
|
+
): Span[] => namingAsides(text, markers).flatMap((at) => phraseBefore(tokens, offset + at, continues) ?? []);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { quotedSpans } from "../quoted-span.ts";
|
|
2
|
+
import type { Span } from "../plugin.ts";
|
|
3
|
+
|
|
4
|
+
// A name the document quotes once (「maDMPsのための共通データモデル」) and then writes without the brackets: still the same
|
|
5
|
+
// name, so its particles are read as one noun wherever it stands. Pure: the particles a name must hold come in.
|
|
6
|
+
|
|
7
|
+
/** Whether name holds one of particles inside it. One that ends in the particle (「実際の」) quotes words, not a name. */
|
|
8
|
+
const holdsParticle = (name: string, particles: readonly string[]): boolean =>
|
|
9
|
+
particles.some((particle) => particle !== "" && name.includes(particle) && !name.endsWith(particle));
|
|
10
|
+
|
|
11
|
+
/** The names quoted in 「」『』 anywhere in source that hold one of particles inside them, each once. */
|
|
12
|
+
export const quotedNames = (source: string, particles: readonly string[]): string[] => [
|
|
13
|
+
...new Set(
|
|
14
|
+
quotedSpans(source)
|
|
15
|
+
.map((span) => source.slice(span.start, span.end))
|
|
16
|
+
.filter((name) => holdsParticle(name, particles)),
|
|
17
|
+
),
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const placesOf = (text: string, name: string, from = 0): number[] => {
|
|
21
|
+
const at = text.indexOf(name, from);
|
|
22
|
+
return at === -1 ? [] : [at, ...placesOf(text, name, at + name.length)];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** Where names stand in text (starting at offset in the document), with or without brackets. */
|
|
26
|
+
export const quotedNameSpans = (text: string, offset: number, names: readonly string[]): Span[] =>
|
|
27
|
+
names.flatMap((name) => placesOf(text, name).map((at) => ({ start: offset + at, end: offset + at + name.length })));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Section, Sentence } from "../plugin.ts";
|
|
1
|
+
import type { Paragraph, Section, Sentence } from "../plugin.ts";
|
|
2
2
|
|
|
3
3
|
// A document that holds two texts under two top-level headings (a directive, then the agency's page about it) may write each in
|
|
4
4
|
// its own register. A part whose sentences all share the register the rest of the document does not use is a text of its own,
|
|
@@ -40,3 +40,34 @@ export const separatePartSentences = <R>(
|
|
|
40
40
|
return own ? sentences : [];
|
|
41
41
|
}),
|
|
42
42
|
);
|
|
43
|
+
|
|
44
|
+
/** A paragraph that holds no sentence with a register: a line of links or labels (第1, 第2), as a page lays out under the text it carries. */
|
|
45
|
+
const isRegisterless = <R>(paragraph: Paragraph, registerOf: (sentence: Sentence) => R | undefined): boolean =>
|
|
46
|
+
paragraph.sentences.length > 0 && paragraph.sentences.every((sentence) => registerOf(sentence) === undefined);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The page's own note after the text it carries, without a heading of its own (a directive in である, then ※…ご覧ください。, a line of
|
|
50
|
+
* links, and なお、…ありません。): every counted sentence after the last one in the majority register, when they are MIN_SENTENCES or
|
|
51
|
+
* more, all in one other register that no sentence before them uses, and a paragraph between the first and the last of them holds no counted sentence. Without
|
|
52
|
+
* that line the end of the document is the text's own closing; sentences are the document's in order, lists included; with the other register used earlier too, the end is not a part of its
|
|
53
|
+
* own, and setting it apart would leave the earlier sentences a smaller minority to be pointed at.
|
|
54
|
+
*/
|
|
55
|
+
export const trailingPartSentences = <R>(
|
|
56
|
+
sentences: readonly Sentence[],
|
|
57
|
+
paragraphs: readonly Paragraph[],
|
|
58
|
+
registerOf: (sentence: Sentence) => R | undefined,
|
|
59
|
+
majority: R | undefined,
|
|
60
|
+
): Set<Sentence> => {
|
|
61
|
+
const counted = sentences.filter((sentence) => registerOf(sentence) !== undefined);
|
|
62
|
+
const lastMajority = counted.findLastIndex((sentence) => registerOf(sentence) === majority);
|
|
63
|
+
if (majority === undefined || lastMajority < 0) return new Set();
|
|
64
|
+
const tail = counted.slice(lastMajority + 1);
|
|
65
|
+
const registers = tail.map(registerOf);
|
|
66
|
+
const before = counted.slice(0, lastMajority + 1);
|
|
67
|
+
const ownRegister =
|
|
68
|
+
tail.length >= MIN_SENTENCES && registers.every((register) => register === registers[0]) && before.every((sentence) => registerOf(sentence) === majority);
|
|
69
|
+
const from = tail[0]?.span.end ?? 0;
|
|
70
|
+
const to = tail.at(-1)?.span.start ?? 0;
|
|
71
|
+
const setOff = paragraphs.some((paragraph) => paragraph.span.start >= from && paragraph.span.end <= to && isRegisterless(paragraph, registerOf));
|
|
72
|
+
return ownRegister && setOff ? new Set(tail) : new Set();
|
|
73
|
+
};
|
|
@@ -21,18 +21,31 @@ const PAST = new Set(["た", "だ"]);
|
|
|
21
21
|
const hasParticle = (tokens: readonly Token[], particles: readonly LexiconEntry[]): boolean =>
|
|
22
22
|
tokens.some((token) => token.pos === "ADP" && particles.some((particle) => particle.pattern === token.surface));
|
|
23
23
|
|
|
24
|
+
/** The sentence ends in a forward-looking form from declaration-ending (…形にしていく。). */
|
|
25
|
+
const endsInResolve = (sentence: Sentence, endings: readonly LexiconEntry[]): boolean => {
|
|
26
|
+
const text = withoutTrailingMarks(sentence.text);
|
|
27
|
+
return endings.some((ending) => text.endsWith(ending.pattern));
|
|
28
|
+
};
|
|
29
|
+
|
|
24
30
|
/**
|
|
25
31
|
* A speaker's declaration (負担軽減を、目に見える形で実現する。二度と繰り返さない。): an object particle, no subject particle, and a
|
|
26
|
-
* verb in the present at the end.
|
|
27
|
-
*
|
|
32
|
+
* verb in the present at the end. A sentence ending in a forward-looking form (現場の気づきを、幹部の皆さんが形にしていく。) declares even
|
|
33
|
+
* with its subject said. particles and endings are the declaration-particle and declaration-ending word lists already narrowed to the
|
|
34
|
+
* document's genre; without an object particle for the genre the shape does not hold.
|
|
28
35
|
*/
|
|
29
|
-
export const isDeclaration = (
|
|
36
|
+
export const isDeclaration = (
|
|
37
|
+
sentence: Sentence,
|
|
38
|
+
ending: readonly Token[],
|
|
39
|
+
particles: readonly LexiconEntry[],
|
|
40
|
+
endings: readonly LexiconEntry[] = [],
|
|
41
|
+
): boolean => {
|
|
30
42
|
const objects = particles.filter((particle) => particle.group === "object");
|
|
31
43
|
const subjects = particles.filter((particle) => particle.group === "subject");
|
|
32
44
|
const tokens = sentence.tokens ?? [];
|
|
33
45
|
const last = ending.at(-1);
|
|
34
46
|
if (objects.length === 0 || last === undefined || PAST.has(last.surface)) return false;
|
|
35
|
-
|
|
47
|
+
const subjectAllowed = !hasParticle(tokens, subjects) || endsInResolve(sentence, endings);
|
|
48
|
+
return ending.some((token) => token.pos === "VERB") && hasParticle(tokens, objects) && subjectAllowed;
|
|
36
49
|
};
|
|
37
50
|
|
|
38
51
|
/** The most tokens an opener in takeup-opener spans (これ/だけ). */
|
|
@@ -94,11 +94,14 @@ export const majorityOf = (judged: readonly Judged[]): Register | undefined => {
|
|
|
94
94
|
return difference > 0 ? "polite" : "plain";
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
/**
|
|
98
|
+
* 少ないほう。同数なら文書全体で少ないほう。文書全体でも同数なら、揃える先の多いほうが無いので undefined(どちらも指さない)。
|
|
99
|
+
* 半々に書いた文書(くだけたメールの「お願いしたい。…です。…助かる。…送ります。」)は、書き損じではなく混ぜた書き方。
|
|
100
|
+
*/
|
|
101
|
+
const minorityOf = (group: readonly Judged[], whole: readonly Judged[]): Register | undefined => {
|
|
102
|
+
const majority = majorityOf(group) ?? majorityOf(whole);
|
|
103
|
+
if (majority === undefined) return undefined;
|
|
104
|
+
return majority === "polite" ? "plain" : "polite";
|
|
102
105
|
};
|
|
103
106
|
|
|
104
107
|
/**
|
|
@@ -111,7 +114,7 @@ export const followsDocument = (group: number | undefined, minority: Register, w
|
|
|
111
114
|
const slipsInGroup = <T extends Judged>(judged: readonly T[], group: number | undefined, limit: number): Slip<T>[] => {
|
|
112
115
|
const members = judged.filter((entry) => entry.group === group);
|
|
113
116
|
const minority = minorityOf(members, judged);
|
|
114
|
-
if (followsDocument(group, minority, judged)) return [];
|
|
117
|
+
if (minority === undefined || followsDocument(group, minority, judged)) return [];
|
|
115
118
|
const slips = members.filter((entry) => entry.register === minority);
|
|
116
119
|
// 片方しか無ければ揃っている。少数派が閾値を超えて多ければ、混在ではなく別の文体。
|
|
117
120
|
if (slips.length === 0 || slips.length > limit) return [];
|
|
@@ -3,7 +3,7 @@ import { enumeratedRuns, enumeratorStarts, numberedStarts } from "./enumerated-r
|
|
|
3
3
|
import { continuesThrough, groupOf, majorityOf, registerOf, slipsOf, type Register } from "./register.ts";
|
|
4
4
|
import { isRunInLabel } from "./run-in-label.ts";
|
|
5
5
|
import { noticeSentences } from "./notice-paragraph.ts";
|
|
6
|
-
import { separatePartSentences } from "./register-separate-part.ts";
|
|
6
|
+
import { separatePartSentences, trailingPartSentences } from "./register-separate-part.ts";
|
|
7
7
|
import { askerSentences } from "./asker-voice.ts";
|
|
8
8
|
import { licenceNoticeSentences } from "./licence-notice.ts";
|
|
9
9
|
import { chronologyRows } from "../chronology-rows.ts";
|
|
@@ -26,6 +26,7 @@ import type { Detector, Finding, LexiconEntry, ProseDocument, Sentence, Span, To
|
|
|
26
26
|
* 札を付けて引いた言葉(例:…。Q: …?)、印を付けた札の行の下の記入欄の値(■ 調査目的\n…とする。)、
|
|
27
27
|
* 〒や電話の行のある問い合わせ先の段落も数えない(register-set-apart.ts)。
|
|
28
28
|
* 一番上の見出しで分けた部分のうち、2 文以上がみな文書の多いほうと違う同じ調子のものは、別の文書として数えない(register-separate-part.ts)。
|
|
29
|
+
* 多いほうの最後の文より後ろの 2 文以上が、みな前に無い違う同じ調子で、間に調子を持たない行(リンクの並び)を挟むものも、ページの注記として数えない。
|
|
29
30
|
*/
|
|
30
31
|
/**
|
|
31
32
|
* quiet: 常体と読めるが、願い・問い・言いさしの形(register-neutral-shape.ts)の文。どちらの調子の文書にも現れるので指さない。
|
|
@@ -37,7 +38,7 @@ import type { Detector, Finding, LexiconEntry, ProseDocument, Sentence, Span, To
|
|
|
37
38
|
type Entry = { readonly sentence: Sentence; readonly register: Register; readonly group: number | undefined; readonly quiet: boolean };
|
|
38
39
|
|
|
39
40
|
/** 文の調子と quiet を決める語彙表。polite は polite-ending、neutral は neutral-ending、requests は neutral-request、wishes は neutral-wish、
|
|
40
|
-
* greetings は set-polite-phrase、declaration は declaration-particle を文書の genre で絞ったもの、openers は takeup-opener。 */
|
|
41
|
+
* greetings は set-polite-phrase、declaration と resolves は declaration-particle と declaration-ending を文書の genre で絞ったもの、openers は takeup-opener。 */
|
|
41
42
|
type EndingWords = {
|
|
42
43
|
readonly polite: readonly LexiconEntry[];
|
|
43
44
|
readonly neutral: readonly LexiconEntry[];
|
|
@@ -45,6 +46,7 @@ type EndingWords = {
|
|
|
45
46
|
readonly wishes: readonly LexiconEntry[];
|
|
46
47
|
readonly greetings: readonly LexiconEntry[];
|
|
47
48
|
readonly declaration: readonly LexiconEntry[];
|
|
49
|
+
readonly resolves: readonly LexiconEntry[];
|
|
48
50
|
readonly openers: readonly LexiconEntry[];
|
|
49
51
|
};
|
|
50
52
|
|
|
@@ -57,6 +59,7 @@ const endingWords = (doc: ProseDocument, polite: readonly LexiconEntry[], genre:
|
|
|
57
59
|
wishes: doc.lexicons["neutral-wish"] ?? [],
|
|
58
60
|
greetings: doc.lexicons["set-polite-phrase"] ?? [],
|
|
59
61
|
declaration: entriesForGenre(doc.lexicons["declaration-particle"] ?? [], genre),
|
|
62
|
+
resolves: entriesForGenre(doc.lexicons["declaration-ending"] ?? [], genre),
|
|
60
63
|
openers: doc.lexicons["takeup-opener"] ?? [],
|
|
61
64
|
});
|
|
62
65
|
|
|
@@ -65,7 +68,7 @@ const isQuiet = (sentence: Sentence, ending: readonly Token[], register: Registe
|
|
|
65
68
|
register === "polite"
|
|
66
69
|
? endsInSetGreeting(sentence, words.greetings)
|
|
67
70
|
: isNeutralPlainShape(sentence, ending, words.requests, words.wishes) ||
|
|
68
|
-
isDeclaration(sentence, ending, words.declaration) ||
|
|
71
|
+
isDeclaration(sentence, ending, words.declaration, words.resolves) ||
|
|
69
72
|
isExclamation(sentence) ||
|
|
70
73
|
isTakenUp(next, between, words.openers);
|
|
71
74
|
|
|
@@ -124,7 +127,10 @@ export const judgedSentences = (doc: ProseDocument, polite: readonly LexiconEntr
|
|
|
124
127
|
const majority = majorityOf(all.map((entry) => ({ register: entry.register, group: undefined })));
|
|
125
128
|
const registerAt = (sentence: Sentence): Register | undefined => registers.get(sentence);
|
|
126
129
|
const notices = noticeSentences(doc.paragraphs, doc.lexicons["notice-phrase"] ?? [], registerAt, majority);
|
|
127
|
-
const parts =
|
|
130
|
+
const parts = new Set([
|
|
131
|
+
...separatePartSentences(doc.sections, registerAt, majority),
|
|
132
|
+
...trailingPartSentences(doc.sentences, doc.paragraphs, registerAt, majority),
|
|
133
|
+
]);
|
|
128
134
|
const found = all.filter((entry) => !notices.has(entry.sentence) && !parts.has(entry.sentence));
|
|
129
135
|
const runs = runsOf(
|
|
130
136
|
doc,
|
package/src/detectors/signals.ts
CHANGED
|
@@ -89,15 +89,18 @@ const ACRONYM = new RegExp(String.raw`${EDGE_BEFORE}${ACRONYM_PART}(?:-${ACRONYM
|
|
|
89
89
|
* 強調は読点や括弧をまたいで続くので(THE AUTHOR, THE COMPANY (IF ANY))、そういう続きを含む
|
|
90
90
|
* 「大文字以外の文字を含まない一続き」を丸ごと強調と見なす。小文字の語が挟まれば切れるので、
|
|
91
91
|
* 「SRE, SLO, MTTR」のような略語の並びは残る。引用符に包まれた大文字の句(“AS IS”)も強調。
|
|
92
|
-
* 2 語でも、片方が略語にしては長い語なら強調(BILLING CODE
|
|
92
|
+
* 2 語でも、片方が略語にしては長い語なら強調(BILLING CODE)。どちらも 5 字以上の 2 語(MIRAI SCHOOL、UNITED STATES)は
|
|
93
|
+
* 大文字で書いた名前や語で、略語がそう並ぶことはない。略語 2 つの並び(NIST SP、FEMA NFIP)は残る。
|
|
93
94
|
*/
|
|
94
95
|
const CAPS_WORD = String.raw`[A-Z]+(?:&[A-Z]+)*`;
|
|
95
96
|
const LONG_CAPS_WORD = String.raw`[A-Z]{${ACRONYM_MAX + 1},}`;
|
|
97
|
+
const WORD_PAIR_MIN = 5;
|
|
98
|
+
const WORD_PAIR_PART = String.raw`[A-Z]{${WORD_PAIR_MIN},}`;
|
|
96
99
|
const CAPS_GAP = String.raw`[\s"“”'‘’]+`;
|
|
97
100
|
const SHOUTED_RUN = new RegExp(String.raw`${EDGE_BEFORE}${CAPS_WORD}(?:${CAPS_GAP}${CAPS_WORD}){2,}${EDGE_AFTER}`, "u");
|
|
98
101
|
/** 2 語の強調は、その 2 語だけを外す。続きまで外すと、区切りの後ろの略語(NEW GUIDELINES: SRE)まで消える。 */
|
|
99
102
|
const SHOUTED_PAIR = new RegExp(
|
|
100
|
-
String.raw`${EDGE_BEFORE}(?:${LONG_CAPS_WORD}${CAPS_GAP}${CAPS_WORD}|${CAPS_WORD}${CAPS_GAP}${LONG_CAPS_WORD})${EDGE_AFTER}`,
|
|
103
|
+
String.raw`${EDGE_BEFORE}(?:${LONG_CAPS_WORD}${CAPS_GAP}${CAPS_WORD}|${CAPS_WORD}${CAPS_GAP}${LONG_CAPS_WORD}|${WORD_PAIR_PART}${CAPS_GAP}${WORD_PAIR_PART})${EDGE_AFTER}`,
|
|
101
104
|
"gu",
|
|
102
105
|
);
|
|
103
106
|
const UNCASED_STRETCH = /(?:[A-Z]|\P{L})+/gu;
|
|
@@ -6,10 +6,11 @@ import { isWithinAny, quotedIn, QUOTATION_MARKS } from "../quoted-span.ts";
|
|
|
6
6
|
const STACKED_AT = 2;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* 語彙表
|
|
10
|
-
* scope は hedges
|
|
9
|
+
* 語彙表 4 つ。hedges は逃げの表現そのもの、frames はそれだけでは逃げていない包む言い方(「という状況です」、may)、
|
|
10
|
+
* scope は hedges のうち、書き手の確かさを下げないもの(「場合がある」、「と思われている」)、
|
|
11
|
+
* complements は動詞の後ろで中身の節を始める語(knowing that の that)。
|
|
11
12
|
*/
|
|
12
|
-
export type HedgeWords = { readonly hedges: Lexicon; readonly frames: Lexicon; readonly scope: Lexicon };
|
|
13
|
+
export type HedgeWords = { readonly hedges: Lexicon; readonly frames: Lexicon; readonly scope: Lexicon; readonly complements: Lexicon };
|
|
13
14
|
|
|
14
15
|
type Device = { readonly range: TokenRange; readonly hedge: boolean };
|
|
15
16
|
|
|
@@ -41,10 +42,25 @@ const spanOf = (tokens: readonly Token[], range: TokenRange): Span | undefined =
|
|
|
41
42
|
/** 句読点と等位接続詞(and、but、及び)は節を切る。別の節の逃げは、同じ主張を二重にぼかしていない。 */
|
|
42
43
|
const CLAUSE_BREAK = new Set(["PUNCT", "CCONJ"]);
|
|
43
44
|
|
|
45
|
+
/**
|
|
46
|
+
* 動詞の後ろで中身の節を始める語の位置(knowing that の that)。その節の may は知っていることの中身で、
|
|
47
|
+
* 前の perhaps と同じ主張をぼかしていない。逃げの表現の動詞(it seems that)の後ろは、その逃げが包む節なので切らない。
|
|
48
|
+
*/
|
|
49
|
+
const complementOpens = (sentence: Sentence, complements: Lexicon, devices: readonly Device[]): Set<number> => {
|
|
50
|
+
const tokens = sentence.tokens ?? [];
|
|
51
|
+
const inDevice = (at: number): boolean => devices.some((device) => device.range.start <= at && at < device.range.end);
|
|
52
|
+
const opensAfterVerb = (range: TokenRange): boolean => tokens[range.start - 1]?.pos === "VERB" && !inDevice(range.start - 1);
|
|
53
|
+
return new Set(
|
|
54
|
+
rangesOf(sentence, complements)
|
|
55
|
+
.filter(opensAfterVerb)
|
|
56
|
+
.map((range) => range.start),
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
44
60
|
/** 語ごとの、文の頭から数えた節の番号。 */
|
|
45
|
-
const clauseOf = (tokens: readonly Token[]): number[] =>
|
|
46
|
-
tokens.reduce<number[]>((clauses, token) => {
|
|
47
|
-
clauses.push((clauses.at(-1) ?? 0) + (CLAUSE_BREAK.has(token.pos) ? 1 : 0));
|
|
61
|
+
const clauseOf = (tokens: readonly Token[], opens: ReadonlySet<number>): number[] =>
|
|
62
|
+
tokens.reduce<number[]>((clauses, token, at) => {
|
|
63
|
+
clauses.push((clauses.at(-1) ?? 0) + (CLAUSE_BREAK.has(token.pos) || opens.has(at) ? 1 : 0));
|
|
48
64
|
return clauses;
|
|
49
65
|
}, []);
|
|
50
66
|
|
|
@@ -84,7 +100,8 @@ const stackedClause = (devices: readonly Device[], clauses: readonly number[]):
|
|
|
84
100
|
*/
|
|
85
101
|
const stackedHedgeIn = (sentence: Sentence, words: HedgeWords): Span[] => {
|
|
86
102
|
const tokens = sentence.tokens ?? [];
|
|
87
|
-
|
|
103
|
+
const devices = devicesIn(sentence, words);
|
|
104
|
+
return stackedClause(devices, clauseOf(tokens, complementOpens(sentence, words.complements, devices)))
|
|
88
105
|
.toSorted((left, right) => left.range.start - right.range.start)
|
|
89
106
|
.flatMap((device) => spanOf(tokens, { start: device.range.start, end: shownEnd(tokens, device.range) }) ?? []);
|
|
90
107
|
};
|
|
@@ -8,6 +8,8 @@ import { honorificGroupParticles } from "../honorific-group.ts";
|
|
|
8
8
|
import { setPhraseParticles } from "../set-phrase-particles.ts";
|
|
9
9
|
import { noteSentences } from "../note-paragraphs.ts";
|
|
10
10
|
import { documentNameSpans } from "./particle-run-names.ts";
|
|
11
|
+
import { namedLongForms } from "./particle-run-long-forms.ts";
|
|
12
|
+
import { quotedNameSpans, quotedNames } from "./particle-run-quoted-names.ts";
|
|
11
13
|
import { isFlattenedTable } from "./sentence-parts.ts";
|
|
12
14
|
|
|
13
15
|
/**
|
|
@@ -89,6 +91,9 @@ const runsOf = (tokens: readonly Token[], nesting: readonly string[], breaks: re
|
|
|
89
91
|
return acc;
|
|
90
92
|
}, []);
|
|
91
93
|
|
|
94
|
+
/** 括弧の中で、前の語句に短い呼び名を付ける語(以下「…」という)。前の語句は名前なので、題名と同じく中の助詞を数えない。 */
|
|
95
|
+
const NAMING_LEXICON = "definition-marker";
|
|
96
|
+
|
|
92
97
|
/** 句と句の間の記号(制限=タグの制限、A→B)。半角の = や : は名詞として読まれ、句読点のようには切れない。 */
|
|
93
98
|
const RUN_BREAK_LEXICON = "particle-run-break";
|
|
94
99
|
|
|
@@ -118,12 +123,20 @@ export const doubledParticle: Detector = (doc, options): Finding[] => {
|
|
|
118
123
|
setPhrases: (doc.lexicons[SET_PHRASE_LEXICON] ?? []).map((entry) => entry.pattern),
|
|
119
124
|
};
|
|
120
125
|
const prose = doc.prose ?? doc.source;
|
|
126
|
+
const namingMarkers = (doc.lexicons[NAMING_LEXICON] ?? []).map((entry) => entry.pattern);
|
|
127
|
+
const names = quotedNames(doc.source, nesting);
|
|
128
|
+
const continuesName = (token: Token): boolean => nesting.includes(token.surface) || !breaksRun(token, breaks);
|
|
121
129
|
// 平らにした表の文は、見出しのセル(役員の兼任等・営業上の取引・設備の賃貸借)の切れ目が見えず、別のセルの「の」が一つの連なりに見える。
|
|
122
130
|
return doc.sentences
|
|
123
131
|
.filter((sentence) => !isFlattenedTable(sentence.text))
|
|
124
132
|
.flatMap((sentence) => {
|
|
125
133
|
const tokens = chainTokens(sentence.tokens ?? [], numbering, phrases);
|
|
126
|
-
const quoted = [
|
|
134
|
+
const quoted = [
|
|
135
|
+
...quotedIn(sentence),
|
|
136
|
+
...titles,
|
|
137
|
+
...namedLongForms(sentence.text, sentence.span.start, sentence.tokens ?? [], namingMarkers, continuesName),
|
|
138
|
+
...quotedNameSpans(sentence.text, sentence.span.start, names),
|
|
139
|
+
];
|
|
127
140
|
const longRuns = (skipped: readonly Span[]): Run[] => runsOf(tokens, nesting, breaks, skipped).filter((run) => run.tokens.length > options.limit);
|
|
128
141
|
const found = longRuns(quoted);
|
|
129
142
|
// 文書の名前を読むのは長い連なりのある文だけ。名前は位置ごとに読むので、全部の文で読むと遅い。
|