chaffjs 0.47.0 → 0.49.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 +1 -0
- package/README.md +1 -0
- package/dist/bound-word-particles.d.ts +1 -0
- package/dist/bound-word-particles.d.ts.map +1 -1
- package/dist/bound-word-particles.js +1 -1
- package/dist/bound-word-particles.js.map +1 -1
- package/dist/clause-particles.d.ts +11 -0
- package/dist/clause-particles.d.ts.map +1 -0
- package/dist/clause-particles.js +20 -0
- package/dist/clause-particles.js.map +1 -0
- package/dist/detectors/acronym-definition.d.ts.map +1 -1
- package/dist/detectors/acronym-definition.js +14 -6
- package/dist/detectors/acronym-definition.js.map +1 -1
- package/dist/detectors/acronym-expansion.d.ts +2 -0
- package/dist/detectors/acronym-expansion.d.ts.map +1 -1
- package/dist/detectors/acronym-expansion.js +18 -7
- package/dist/detectors/acronym-expansion.js.map +1 -1
- package/dist/detectors/acronym-mention.d.ts.map +1 -1
- package/dist/detectors/acronym-mention.js +3 -1
- package/dist/detectors/acronym-mention.js.map +1 -1
- package/dist/detectors/acronym-name.d.ts +2 -2
- package/dist/detectors/acronym-name.d.ts.map +1 -1
- package/dist/detectors/acronym-name.js +3 -3
- package/dist/detectors/acronym-name.js.map +1 -1
- package/dist/detectors/acronym-parent-item.d.ts +6 -0
- package/dist/detectors/acronym-parent-item.d.ts.map +1 -0
- package/dist/detectors/acronym-parent-item.js +50 -0
- package/dist/detectors/acronym-parent-item.js.map +1 -0
- package/dist/detectors/broken-link.d.ts.map +1 -1
- package/dist/detectors/broken-link.js +14 -0
- package/dist/detectors/broken-link.js.map +1 -1
- package/dist/detectors/char-shape.d.ts.map +1 -1
- package/dist/detectors/char-shape.js +11 -4
- package/dist/detectors/char-shape.js.map +1 -1
- package/dist/detectors/citation-sentence.d.ts +8 -0
- package/dist/detectors/citation-sentence.d.ts.map +1 -1
- package/dist/detectors/citation-sentence.js +24 -0
- package/dist/detectors/citation-sentence.js.map +1 -1
- package/dist/detectors/concrete-evidence-density.d.ts.map +1 -1
- package/dist/detectors/concrete-evidence-density.js +13 -6
- package/dist/detectors/concrete-evidence-density.js.map +1 -1
- package/dist/detectors/concrete-evidence.d.ts +14 -1
- package/dist/detectors/concrete-evidence.d.ts.map +1 -1
- package/dist/detectors/concrete-evidence.js +65 -0
- package/dist/detectors/concrete-evidence.js.map +1 -1
- package/dist/detectors/doubled-punctuation.d.ts.map +1 -1
- package/dist/detectors/doubled-punctuation.js +14 -4
- package/dist/detectors/doubled-punctuation.js.map +1 -1
- package/dist/detectors/en-shape.d.ts +1 -0
- package/dist/detectors/en-shape.d.ts.map +1 -1
- package/dist/detectors/en-shape.js +15 -6
- package/dist/detectors/en-shape.js.map +1 -1
- package/dist/detectors/kanji-name-edge.d.ts +10 -0
- package/dist/detectors/kanji-name-edge.d.ts.map +1 -1
- package/dist/detectors/kanji-name-edge.js +23 -0
- package/dist/detectors/kanji-name-edge.js.map +1 -1
- package/dist/detectors/law-governed.d.ts +10 -0
- package/dist/detectors/law-governed.d.ts.map +1 -0
- package/dist/detectors/law-governed.js +41 -0
- package/dist/detectors/law-governed.js.map +1 -0
- package/dist/detectors/name-variant-two-things.d.ts +2 -1
- package/dist/detectors/name-variant-two-things.d.ts.map +1 -1
- package/dist/detectors/name-variant-two-things.js +21 -3
- package/dist/detectors/name-variant-two-things.js.map +1 -1
- package/dist/detectors/open-end-names.d.ts +7 -2
- package/dist/detectors/open-end-names.d.ts.map +1 -1
- package/dist/detectors/open-end-names.js +14 -4
- package/dist/detectors/open-end-names.js.map +1 -1
- package/dist/detectors/reference-entry.d.ts.map +1 -1
- package/dist/detectors/reference-entry.js +35 -5
- package/dist/detectors/reference-entry.js.map +1 -1
- package/dist/detectors/register-set-apart.d.ts +1 -1
- package/dist/detectors/register-set-apart.js +4 -4
- package/dist/detectors/register-set-apart.js.map +1 -1
- package/dist/detectors/register-voice.d.ts +5 -0
- package/dist/detectors/register-voice.d.ts.map +1 -1
- package/dist/detectors/register-voice.js +17 -0
- package/dist/detectors/register-voice.js.map +1 -1
- package/dist/detectors/requirement-smell.d.ts.map +1 -1
- package/dist/detectors/requirement-smell.js +6 -2
- package/dist/detectors/requirement-smell.js.map +1 -1
- package/dist/detectors/sentence-counts.d.ts.map +1 -1
- package/dist/detectors/sentence-counts.js +2 -1
- package/dist/detectors/sentence-counts.js.map +1 -1
- package/dist/detectors/sentence-ending.d.ts +2 -2
- package/dist/detectors/sentence-ending.d.ts.map +1 -1
- package/dist/detectors/sentence-ending.js +3 -1
- 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 +7 -6
- package/dist/detectors/sentence-length.js.map +1 -1
- package/dist/detectors/sentence-parts.d.ts +8 -3
- package/dist/detectors/sentence-parts.d.ts.map +1 -1
- package/dist/detectors/sentence-parts.js +25 -7
- package/dist/detectors/sentence-parts.js.map +1 -1
- package/dist/detectors/signals.d.ts.map +1 -1
- package/dist/detectors/signals.js +3 -0
- package/dist/detectors/signals.js.map +1 -1
- package/dist/detectors/space-before-punctuation.js +3 -3
- package/dist/detectors/space-before-punctuation.js.map +1 -1
- package/dist/detectors/speaker-turns.d.ts +4 -0
- package/dist/detectors/speaker-turns.d.ts.map +1 -0
- package/dist/detectors/speaker-turns.js +28 -0
- package/dist/detectors/speaker-turns.js.map +1 -0
- package/dist/detectors/token-shape.d.ts.map +1 -1
- package/dist/detectors/token-shape.js +21 -5
- package/dist/detectors/token-shape.js.map +1 -1
- package/dist/detectors/topic-predicate-distance.d.ts.map +1 -1
- package/dist/detectors/topic-predicate-distance.js +3 -1
- package/dist/detectors/topic-predicate-distance.js.map +1 -1
- package/dist/detectors/unbalanced-bracket.d.ts.map +1 -1
- package/dist/detectors/unbalanced-bracket.js +31 -6
- package/dist/detectors/unbalanced-bracket.js.map +1 -1
- package/dist/detectors/vague-density.d.ts +4 -2
- package/dist/detectors/vague-density.d.ts.map +1 -1
- package/dist/detectors/vague-density.js +17 -9
- package/dist/detectors/vague-density.js.map +1 -1
- package/dist/document.js +2 -2
- package/dist/document.js.map +1 -1
- package/dist/name-variant-shapes.d.ts +32 -0
- package/dist/name-variant-shapes.d.ts.map +1 -1
- package/dist/name-variant-shapes.js +87 -0
- package/dist/name-variant-shapes.js.map +1 -1
- package/dist/paragraph-length.d.ts.map +1 -1
- package/dist/paragraph-length.js +5 -6
- package/dist/paragraph-length.js.map +1 -1
- package/dist/sentence-load.d.ts.map +1 -1
- package/dist/sentence-load.js +20 -6
- package/dist/sentence-load.js.map +1 -1
- package/dist/set-phrase-particles.js +2 -2
- package/dist/set-phrase-particles.js.map +1 -1
- package/dist/structure/definition-use.d.ts.map +1 -1
- package/dist/structure/definition-use.js +13 -0
- package/dist/structure/definition-use.js.map +1 -1
- package/dist/structure/universal.d.ts.map +1 -1
- package/dist/structure/universal.js +9 -1
- package/dist/structure/universal.js.map +1 -1
- package/dist/structure/unread-label.d.ts.map +1 -1
- package/dist/structure/unread-label.js +3 -1
- package/dist/structure/unread-label.js.map +1 -1
- package/dist/topic-clause.d.ts +2 -0
- package/dist/topic-clause.d.ts.map +1 -1
- package/dist/topic-clause.js +12 -5
- package/dist/topic-clause.js.map +1 -1
- package/package.json +3 -3
- package/rules/adverb-overuse.yaml +2 -2
- package/rules/bracket-nesting.yaml +2 -2
- package/rules/broken-link.yaml +2 -2
- package/rules/concrete-evidence-density.yaml +2 -2
- package/rules/doubled-punctuation.yaml +2 -2
- package/rules/expletive-construction.yaml +2 -2
- package/rules/max-kanji-continuous.yaml +5 -3
- package/rules/max-sentence-length.yaml +2 -2
- package/rules/name-variant.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/orthographic-variant.yaml +2 -2
- package/rules/requirement-smell.yaml +2 -2
- package/rules/space-before-punctuation.yaml +4 -4
- package/rules/taigen-dome-in-prose.yaml +2 -2
- package/rules/topic-predicate-distance.yaml +3 -3
- package/rules/unbalanced-bracket.yaml +4 -4
- package/rules/undefined-acronym.yaml +4 -2
- package/rules/vague-word-density.yaml +2 -2
- package/skills/chaff/SKILL.md +3 -1
- package/src/bound-word-particles.ts +2 -1
- package/src/clause-particles.ts +35 -0
- package/src/detectors/acronym-definition.ts +14 -6
- package/src/detectors/acronym-expansion.ts +26 -7
- package/src/detectors/acronym-mention.ts +6 -1
- package/src/detectors/acronym-name.ts +6 -3
- package/src/detectors/acronym-parent-item.ts +60 -0
- package/src/detectors/broken-link.ts +16 -0
- package/src/detectors/char-shape.ts +18 -3
- package/src/detectors/citation-sentence.ts +30 -0
- package/src/detectors/concrete-evidence-density.ts +18 -7
- package/src/detectors/concrete-evidence.ts +83 -1
- package/src/detectors/doubled-punctuation.ts +20 -4
- package/src/detectors/en-shape.ts +18 -9
- package/src/detectors/kanji-name-edge.ts +27 -0
- package/src/detectors/law-governed.ts +50 -0
- package/src/detectors/name-variant-two-things.ts +43 -3
- package/src/detectors/open-end-names.ts +21 -4
- package/src/detectors/reference-entry.ts +36 -6
- package/src/detectors/register-set-apart.ts +4 -4
- package/src/detectors/register-voice.ts +19 -0
- package/src/detectors/requirement-smell.ts +6 -2
- package/src/detectors/sentence-counts.ts +2 -1
- package/src/detectors/sentence-ending.ts +8 -4
- package/src/detectors/sentence-length.ts +10 -8
- package/src/detectors/sentence-parts.ts +33 -9
- package/src/detectors/signals.ts +3 -0
- package/src/detectors/space-before-punctuation.ts +3 -3
- package/src/detectors/speaker-turns.ts +37 -0
- package/src/detectors/token-shape.ts +27 -7
- package/src/detectors/topic-predicate-distance.ts +3 -1
- package/src/detectors/unbalanced-bracket.ts +39 -7
- package/src/detectors/vague-density.ts +25 -10
- package/src/document.ts +2 -2
- package/src/name-variant-shapes.ts +103 -0
- package/src/paragraph-length.ts +8 -9
- package/src/sentence-load.ts +29 -6
- package/src/set-phrase-particles.ts +2 -2
- package/src/structure/definition-use.ts +15 -0
- package/src/structure/universal.ts +10 -1
- package/src/structure/unread-label.ts +3 -1
- package/src/topic-clause.ts +19 -5
|
@@ -6,8 +6,10 @@ import { leadingPrefix, trailingTitle, type AddresseeWords } from "./addressee-t
|
|
|
6
6
|
import {
|
|
7
7
|
followsForm,
|
|
8
8
|
followsUnit,
|
|
9
|
+
fillsGloss,
|
|
9
10
|
holdsName,
|
|
10
11
|
isListItem,
|
|
12
|
+
labelsLines,
|
|
11
13
|
leadingDate,
|
|
12
14
|
leadingOrdinal,
|
|
13
15
|
leadingReference,
|
|
@@ -45,6 +47,8 @@ type KanjiRun = {
|
|
|
45
47
|
readonly text: string;
|
|
46
48
|
readonly span: Span | undefined;
|
|
47
49
|
readonly quoted: boolean;
|
|
50
|
+
/** 連なりが、下に番号や内容の行が続く一行の名前(labelsLines: 児童相談所虐待対応ダイヤル / 189)。 */
|
|
51
|
+
readonly label: boolean;
|
|
48
52
|
readonly placed: boolean;
|
|
49
53
|
readonly after: string | undefined;
|
|
50
54
|
readonly before: string;
|
|
@@ -78,7 +82,7 @@ const maskedProse = (prose: string, profile: DocumentProfile | undefined, names:
|
|
|
78
82
|
* 括弧でくくった名前は、書き手が 1 つの名前として示したもの(「登録業者情報検索入力ページ」)。
|
|
79
83
|
*/
|
|
80
84
|
const fillsQuote = (sentence: Sentence, start: number, end: number): boolean =>
|
|
81
|
-
quotedSpans(sentence.text, NAME_MARKS).some((span) => holdsName(sentence.text, span, start, end));
|
|
85
|
+
quotedSpans(sentence.text, NAME_MARKS).some((span) => holdsName(sentence.text, span, start, end)) || fillsGloss(sentence.text, start, end);
|
|
82
86
|
|
|
83
87
|
const runsOf = (sentence: Sentence, profile: DocumentProfile | undefined, names: readonly string[]): KanjiRun[] => {
|
|
84
88
|
const prose = proseText(sentence);
|
|
@@ -92,6 +96,7 @@ const runsOf = (sentence: Sentence, profile: DocumentProfile | undefined, names:
|
|
|
92
96
|
text: match[0],
|
|
93
97
|
span: undefined,
|
|
94
98
|
quoted: false,
|
|
99
|
+
label: false,
|
|
95
100
|
placed: false,
|
|
96
101
|
after: undefined,
|
|
97
102
|
before: "",
|
|
@@ -112,6 +117,7 @@ const runsOf = (sentence: Sentence, profile: DocumentProfile | undefined, names:
|
|
|
112
117
|
text: match[0],
|
|
113
118
|
span,
|
|
114
119
|
quoted,
|
|
120
|
+
label: labelsLines(sentence.text, start, last + 1),
|
|
115
121
|
placed: isTitlePosition(sentence.text, start, last + 1),
|
|
116
122
|
after,
|
|
117
123
|
before: sentence.text.slice(0, start),
|
|
@@ -251,13 +257,17 @@ const measuredOf = (tokens: readonly Token[], run: KanjiRun, span: Span, words:
|
|
|
251
257
|
return { rest: { start: head?.span.end ?? span.start, end: tail?.start ?? span.end }, text: name.slice(head?.surface.length ?? 0), keptHead };
|
|
252
258
|
};
|
|
253
259
|
|
|
260
|
+
/** 書き手が名前として示した連なり(括弧でくくった、一行に置いた、用語集の見出し語、文脈で名前と分かる)。 */
|
|
261
|
+
const isPresentedName = (run: KanjiRun, context: RunContext): boolean =>
|
|
262
|
+
run.quoted || run.label || (context.headwords && run.alone) || isNamedByContext(run, context.words);
|
|
263
|
+
|
|
254
264
|
/**
|
|
255
265
|
* 数えない連なりは空。頭の、数に付いた助数詞(2日日本弁護士連合会の「日」)と、尻の、数に付く接頭の語(施行令第172条の「第」)と
|
|
256
266
|
* 宛先に付く語(市政情報課宛ての「宛」)は数えない。宛名の「各」と、宛名の行の役職(各国公私立高等専門学校長の「各」と「長」)も数えない。
|
|
257
267
|
* 住所か名前かは、それを外した残りで決める(1日日本銀行の「日本銀行」)。品詞が無ければ判定しない。
|
|
258
268
|
*/
|
|
259
269
|
const measuredRun = (tokens: readonly Token[] | undefined, run: KanjiRun, context: RunContext): string => {
|
|
260
|
-
if (
|
|
270
|
+
if (isPresentedName(run, context)) return "";
|
|
261
271
|
if (tokens === undefined || run.span === undefined) return run.text;
|
|
262
272
|
const { rest, text, keptHead } = measuredOf(tokens, run, run.span, context.words);
|
|
263
273
|
if (context.presented.has(text) || inStatuteTitle(tokens, run.brackets, context.words.fixedName)) return "";
|
|
@@ -340,6 +350,10 @@ const statuteTerms = (runs: readonly DocumentRun[], fixedName: TitleWords, max:
|
|
|
340
350
|
return terms.filter((term) => [...term].length >= MIN_TERM_LENGTH && [...term].length <= max);
|
|
341
351
|
});
|
|
342
352
|
|
|
353
|
+
/** 文書が一行の名前として置いた連なり(labelsLines)のうち MIN_TERM_LENGTH 字からのもの。文の中の連なり(〜相談電話窓口)を、その名前の後ろで割る。 */
|
|
354
|
+
const labelNames = (runs: readonly DocumentRun[]): string[] =>
|
|
355
|
+
runs.flatMap(({ run }) => (run.label && [...run.text].length >= MIN_TERM_LENGTH ? [run.text] : []));
|
|
356
|
+
|
|
343
357
|
/** 文書の genre が、rule の headword_genres(見出し語の行を数えない genre: 用語集)にあるか。 */
|
|
344
358
|
const isHeadwordGenre = (options: DetectorOptions): boolean => {
|
|
345
359
|
const genres = options.settings?.["headword_genres"];
|
|
@@ -384,8 +398,9 @@ const contextOf = (doc: ProseDocument, options: DetectorOptions): RunContext =>
|
|
|
384
398
|
terms: new Set([
|
|
385
399
|
...standaloneNames([...inSentences, ...headingRuns(doc)], MIN_TERM_LENGTH, options.limit, words.organisation.units),
|
|
386
400
|
...statuteTerms(runs, words.fixedName, options.limit),
|
|
401
|
+
...labelNames(runs),
|
|
387
402
|
]),
|
|
388
|
-
presented: new Set(runs.flatMap(({ run }) => (run.quoted ? [run.text] : []))),
|
|
403
|
+
presented: new Set(runs.flatMap(({ run }) => (run.quoted || run.label ? [run.text] : []))),
|
|
389
404
|
headwords: isHeadwordGenre(options),
|
|
390
405
|
maxKnownWords: Math.max(options.limit, ...[...words.knownWords].map((word) => [...word].length)),
|
|
391
406
|
};
|
|
@@ -42,3 +42,33 @@ export const citationLead = (text: string, signals: readonly string[]): string |
|
|
|
42
42
|
const lastSignal = pattern === undefined ? undefined : [...beforeYear.matchAll(pattern)].at(-1);
|
|
43
43
|
return (lastSignal === undefined ? beforeYear : beforeYear.slice(0, lastSignal.index)).trim();
|
|
44
44
|
};
|
|
45
|
+
|
|
46
|
+
/** The same marks of a publication, every one of them: where an earlier reference in the text ends. */
|
|
47
|
+
const PUBLICATION_MARKS_ALL: readonly RegExp[] = PUBLICATION_MARKS.map((mark) => new RegExp(mark.source, "gu"));
|
|
48
|
+
|
|
49
|
+
const LEADING_SEPARATOR = /^[\s;,.]*(?:and\s+)?/u;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The lead without the tail of an earlier reference it begins inside (…Discussion Series 2020-069 (Washington: Board of
|
|
53
|
+
* Governors, August); and Ben S. Bernanke, …): a splitter that cut inside a reference list hands over the end of one
|
|
54
|
+
* reference before the next one's authors. What follows the last mark of a publication is kept.
|
|
55
|
+
*/
|
|
56
|
+
export const withoutEarlierReference = (lead: string): string => {
|
|
57
|
+
const ends = PUBLICATION_MARKS_ALL.flatMap((mark) => [...lead.matchAll(mark)].map((match) => match.index + match[0].length));
|
|
58
|
+
return ends.length === 0
|
|
59
|
+
? lead
|
|
60
|
+
: lead
|
|
61
|
+
.slice(Math.max(...ends))
|
|
62
|
+
.replace(LEADING_SEPARATOR, "")
|
|
63
|
+
.trim();
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** One author as a reference list in the Vancouver style writes them: a surname, then the initials (Kreimer AR, Gail MH, Cyr JT). */
|
|
67
|
+
const AUTHOR = String.raw`\p{Lu}[\p{L}'’-]*\p{Ll}[\p{L}'’-]*(?: \p{Lu}[\p{L}'’-]*\p{Ll}[\p{L}'’-]*)* \p{Lu}{1,3}`;
|
|
68
|
+
/** Fewer authors in a row than this are a sentence naming people, not the author list of a reference. */
|
|
69
|
+
const MIN_AUTHORS = 3;
|
|
70
|
+
const AUTHOR_LIST = new RegExp(String.raw`(?<!\p{L})${AUTHOR}(?:, ${AUTHOR}){${MIN_AUTHORS - 1},}(?!\p{L})`, "gu");
|
|
71
|
+
|
|
72
|
+
/** The words an author list (Kreimer AR, Porras C, Liu D, …) adds beyond one: the authors of a reference, not the writer's sentence. */
|
|
73
|
+
export const authorListSaving = (text: string): number =>
|
|
74
|
+
[...text.matchAll(AUTHOR_LIST)].reduce((saving, match) => saving + match[0].split(/\s+/u).length - 1, 0);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { nameSpans } from "../compare/proper-nouns.ts";
|
|
1
2
|
import { proseText } from "../measure.ts";
|
|
2
3
|
import type { Detector, Finding, ProseDocument, Section, Sentence } from "../plugin.ts";
|
|
3
4
|
import {
|
|
5
|
+
distinctiveNames,
|
|
4
6
|
evidenceSpans,
|
|
7
|
+
namesAsEvidence,
|
|
5
8
|
hasNumeral,
|
|
6
9
|
isClaim,
|
|
7
10
|
isConditionHeading,
|
|
@@ -9,6 +12,7 @@ import {
|
|
|
9
12
|
isNavigationLine,
|
|
10
13
|
startsWithin,
|
|
11
14
|
statesIntent,
|
|
15
|
+
familyWithSlots,
|
|
12
16
|
type AdviceWords,
|
|
13
17
|
type IntentWords,
|
|
14
18
|
} from "./concrete-evidence.ts";
|
|
@@ -18,7 +22,7 @@ import { letteredIndexEntries } from "./lettered-index.ts";
|
|
|
18
22
|
* 具体物の密度。数値・コード・リンク・引用が 1 つも無い節は、
|
|
19
23
|
* 読み終えても何も持ち帰れない。**少ないほうを指摘する**ので、他の密度 rule と向きが逆。
|
|
20
24
|
*/
|
|
21
|
-
const CONCRETE = /\d|`|https
|
|
25
|
+
const CONCRETE = /\d|`|https?:\/\/|(?<![/\\\w.-])[A-Za-z][A-Za-z\d-]+\.[a-z]{2,}\b/u;
|
|
22
26
|
|
|
23
27
|
/**
|
|
24
28
|
* 見出しのない導入部は、書き出しで呼ぶ。文書の言葉なので、message がどの言語でも混ざらない。
|
|
@@ -35,6 +39,10 @@ const openingOf = (sentence: Sentence | undefined, unit: ProseDocument["lengthUn
|
|
|
35
39
|
|
|
36
40
|
const hasNumeralIn = (section: Section): boolean => section.sentences.some((sentence) => hasNumeral(sentence.tokens ?? []));
|
|
37
41
|
|
|
42
|
+
/** 数字・コード・リンク・ドメイン名が書かれているか、数の語があるか。 */
|
|
43
|
+
const concreteIn = (doc: ProseDocument, section: Section): boolean =>
|
|
44
|
+
CONCRETE.test(doc.source.slice(section.span.start, section.span.end)) || hasNumeralIn(section) || startsWithin(section.span, doc.links);
|
|
45
|
+
|
|
38
46
|
/** これより短い節は、具体物があるべきか判断できない。 */
|
|
39
47
|
const MIN_SENTENCES = 3;
|
|
40
48
|
|
|
@@ -75,12 +83,15 @@ export const concreteEvidence: Detector = (doc, options): Finding[] => {
|
|
|
75
83
|
mostlyClaims(sentences, doc.language, advice, intent)
|
|
76
84
|
);
|
|
77
85
|
});
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
);
|
|
81
|
-
//
|
|
82
|
-
const
|
|
83
|
-
|
|
86
|
+
const families = new Map(sections.map((section) => [section, familyWithSlots(doc.sections, section)]));
|
|
87
|
+
const familyOf = (section: Section): Section[] => families.get(section) ?? [section];
|
|
88
|
+
const bare = sections.filter((section) => familyOf(section).every((member) => !concreteIn(doc, member)));
|
|
89
|
+
// 構造の木と名前は求めるのに手間がかかる。指摘に届かない文書では求めない。
|
|
90
|
+
const spans =
|
|
91
|
+
bare.length < options.limit
|
|
92
|
+
? []
|
|
93
|
+
: [...evidenceSpans(doc.structure), ...namesAsEvidence(distinctiveNames(doc.sentences, nameSpans(doc)), doc.source, doc.sections)];
|
|
94
|
+
const empty = bare.filter((section) => familyOf(section).every((member) => !startsWithin(member.span, spans)));
|
|
84
95
|
if (empty.length < options.limit) return [];
|
|
85
96
|
return empty.map((section) => ({
|
|
86
97
|
rule: "concrete-evidence-density",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Sentence, Span, StructureKind, StructureNode, Token } from "../plugin.ts";
|
|
1
|
+
import type { Section, Sentence, Span, StructureKind, StructureNode, Token } from "../plugin.ts";
|
|
2
2
|
import { preOrder } from "../tree-walk.ts";
|
|
3
3
|
import { isStatement } from "./technical-docs.ts";
|
|
4
4
|
|
|
@@ -146,3 +146,85 @@ export const isNavigationLine = (sentence: Pick<Sentence, "text">, lines: readon
|
|
|
146
146
|
|
|
147
147
|
/** 条件を並べる節の見出し(Requirements、応募資格)。並ぶのは条件で、裏づけを求める主張ではない。 */
|
|
148
148
|
export const isConditionHeading = (heading: string, headings: readonly string[]): boolean => headings.includes(bareLine(heading));
|
|
149
|
+
|
|
150
|
+
/** 節と、その下の節(続く、見出しがより深い節)。親の節の本文は短い導入で、中身は下の節にある。導入部(深さ 0)は親ではない。 */
|
|
151
|
+
export const withSubsections = <T extends Pick<Section, "depth">>(sections: readonly T[], section: T): T[] => {
|
|
152
|
+
const index = sections.indexOf(section);
|
|
153
|
+
const after = index === -1 ? [] : sections.slice(index + 1);
|
|
154
|
+
const next = section.depth === 0 ? 0 : after.findIndex((other) => other.depth <= section.depth);
|
|
155
|
+
return [section, ...(next === -1 ? after : after.slice(0, next))];
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
type SlotSection = Pick<Section, "depth" | "heading" | "unlabeledHeading">;
|
|
159
|
+
|
|
160
|
+
/** 同じ見出しの節がこの数の親の下にあれば、項目ごとに繰り返す型の欄(状況・解決策・備考)。 */
|
|
161
|
+
const MIN_SLOT_PARENTS = 3;
|
|
162
|
+
|
|
163
|
+
const titleOf = (section: SlotSection): string => (section.unlabeledHeading ?? section.heading).trim();
|
|
164
|
+
|
|
165
|
+
const parentOf = <T extends SlotSection>(sections: readonly T[], section: T): T | undefined => {
|
|
166
|
+
const index = sections.indexOf(section);
|
|
167
|
+
const parent = sections.slice(0, Math.max(index, 0)).findLast((other) => other.depth < section.depth);
|
|
168
|
+
return parent !== undefined && parent.depth > 0 ? parent : undefined;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* 型の欄の節は、その欄を持つ項目(親の節)と、項目の他の欄と合わせて読む。具体物を何欄目に書くかは項目ごとに違い、
|
|
173
|
+
* 一つの欄だけでは持ち帰るものを決められない。型の欄でなければ、その節と下の節。
|
|
174
|
+
*/
|
|
175
|
+
export const familyWithSlots = <T extends SlotSection>(sections: readonly T[], section: T): T[] => {
|
|
176
|
+
const parent = parentOf(sections, section);
|
|
177
|
+
if (parent === undefined || titleOf(section) === "") return withSubsections(sections, section);
|
|
178
|
+
const parentsOfSameTitle = new Set(
|
|
179
|
+
sections.filter((other) => other.depth === section.depth && titleOf(other) === titleOf(section)).map((other) => parentOf(sections, other)),
|
|
180
|
+
);
|
|
181
|
+
parentsOfSameTitle.delete(undefined);
|
|
182
|
+
return parentsOfSameTitle.size >= MIN_SLOT_PARENTS ? withSubsections(sections, parent) : withSubsections(sections, section);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/** 大文字だけの略語(API、PDFs)。どの文書にも出る技術の語で、名指しした物ではない。 */
|
|
186
|
+
const ACRONYM = /^\p{Lu}+s?$/u;
|
|
187
|
+
const CAPITAL_HEAD = /^\p{Lu}/u;
|
|
188
|
+
const WORD = /\p{L}/u;
|
|
189
|
+
|
|
190
|
+
/** 一字の語(e-Tax の e)は、名前の切れ端。 */
|
|
191
|
+
const MIN_NAME_CHARS = 2;
|
|
192
|
+
|
|
193
|
+
/** 名前と読んだ語のうち、ふつうの語の大文字書き(Timeline、Changes)・強調(NEVER)・略語・切れ端でないもの。 */
|
|
194
|
+
const isDistinctiveName = (token: Token): boolean =>
|
|
195
|
+
token.pos === "PROPN" &&
|
|
196
|
+
token.features?.["OrdinaryWord"] !== "Yes" &&
|
|
197
|
+
token.features?.["Emph"] !== "Yes" &&
|
|
198
|
+
!ACRONYM.test(token.surface) &&
|
|
199
|
+
Array.from(token.surface).length >= MIN_NAME_CHARS;
|
|
200
|
+
|
|
201
|
+
/** 大文字で始まる文頭の語は、名前と区別がつかない(Chimneys)。大文字の無い文字(日本語)の文頭は名前のまま読む。 */
|
|
202
|
+
const distinctiveIn = (sentence: Pick<Sentence, "tokens">): Span[] => {
|
|
203
|
+
const tokens = sentence.tokens ?? [];
|
|
204
|
+
const head = tokens.find((token) => WORD.test(token.surface));
|
|
205
|
+
const skipped = head !== undefined && CAPITAL_HEAD.test(head.surface) ? head : undefined;
|
|
206
|
+
return tokens.filter((token) => token !== skipped && isDistinctiveName(token)).map((token) => token.span);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/** 固有の名前(KubeCon、GitHub、大阪城ホール)の範囲。ふつうの語・略語・文頭の語だけでできた名前は除く。 */
|
|
210
|
+
export const distinctiveNames = (sentences: readonly Pick<Sentence, "tokens">[], names: readonly Span[]): Span[] => {
|
|
211
|
+
const distinctive = sentences.flatMap(distinctiveIn);
|
|
212
|
+
return names.filter((name) => startsWithin(name, distinctive));
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/** 名前が書かれた節の数がこの割合に届くなら、文書の主題(Kubernetes、Rust)で、その節が持ち帰らせる具体物ではない。 */
|
|
216
|
+
const SUBJECT_SHARE = 0.5;
|
|
217
|
+
|
|
218
|
+
const indexOfSection = (sections: readonly Pick<Section, "span">[], at: number): number =>
|
|
219
|
+
sections.findIndex((section) => at >= section.span.start && at < section.span.end);
|
|
220
|
+
|
|
221
|
+
/** 固有の名前(KubeCon、GitHub)のうち、節の具体物として数えるもの。文書の半分以上の節に書かれた名前は主題なので除く。 */
|
|
222
|
+
export const namesAsEvidence = (names: readonly Span[], source: string, sections: readonly Pick<Section, "span">[]): Span[] => {
|
|
223
|
+
const keyOf = (span: Span): string => source.slice(span.start, span.end).toLowerCase();
|
|
224
|
+
const sectionsOf = new Map<string, Set<number>>();
|
|
225
|
+
names.forEach((name) => {
|
|
226
|
+
const index = indexOfSection(sections, name.start);
|
|
227
|
+
if (index !== -1) sectionsOf.set(keyOf(name), (sectionsOf.get(keyOf(name)) ?? new Set<number>()).add(index));
|
|
228
|
+
});
|
|
229
|
+
return names.filter((name) => (sectionsOf.get(keyOf(name))?.size ?? 0) < sections.length * SUBJECT_SHARE);
|
|
230
|
+
};
|
|
@@ -42,12 +42,28 @@ const PAGE_ROMAN = /^x{0,3}(?:ix|iv|v?i{0,3})$/u;
|
|
|
42
42
|
|
|
43
43
|
const isPageNumber = (page: string): boolean => PAGE_DIGITS.test(page) || (page !== "" && PAGE_ROMAN.test(page));
|
|
44
44
|
|
|
45
|
-
/**
|
|
45
|
+
/** 点線の後ろの、揃えのための二つ以上の空白と次の欄(配役表の「NORA.. Emma Vernon」)。 */
|
|
46
|
+
const LEADER_THEN_GAP = /^[ \t]{2,}\S/u;
|
|
47
|
+
/** 同じ段落の、ほかの長い点線と揃えの空白(「MAURYA...... Honor Lavelle」)。 */
|
|
48
|
+
const LONG_LEADER_THEN_GAP = /\.{3}[ \t]{2,}\S/u;
|
|
49
|
+
|
|
50
|
+
const paragraphAround = (text: string, offset: number): string => {
|
|
51
|
+
const before = text.lastIndexOf("\n\n", offset);
|
|
52
|
+
const after = text.indexOf("\n\n", offset);
|
|
53
|
+
return text.slice(before === -1 ? 0 : before + 2, after === -1 ? text.length : after);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** 点線の後ろが揃えの空白で、同じ段落にほかの長い点線も揃えの空白に続く(点線で欄を揃えた表)。 */
|
|
57
|
+
const isLeaderColumn = (text: string, leaderEnd: number): boolean =>
|
|
58
|
+
LEADER_THEN_GAP.test(text.slice(leaderEnd)) && LONG_LEADER_THEN_GAP.test(paragraphAround(text, leaderEnd));
|
|
59
|
+
|
|
60
|
+
const isLeaderBefore = (text: string, leaderEnd: number): boolean =>
|
|
61
|
+
isPageNumber(LEADER_THEN_PAGE.exec(text.slice(leaderEnd))?.groups?.["page"] ?? "") || isLeaderColumn(text, leaderEnd);
|
|
62
|
+
|
|
63
|
+
/** 並びの終わりの点がページ番号の前の点線か、点線で欄を揃えた表の点線なら、その点は点線で、並びの印ではない。 */
|
|
46
64
|
const withoutLeader = (text: string, found: DoubledMarks): DoubledMarks => {
|
|
47
65
|
const kept = found.run.slice(0, Array.from(found.run).findLastIndex((mark) => mark !== ".") + 1);
|
|
48
|
-
return kept !== found.run &&
|
|
49
|
-
? { start: found.start, run: kept }
|
|
50
|
-
: found;
|
|
66
|
+
return kept !== found.run && isLeaderBefore(text, found.start + found.run.length) ? { start: found.start, run: kept } : found;
|
|
51
67
|
};
|
|
52
68
|
|
|
53
69
|
/**
|
|
@@ -5,6 +5,7 @@ import { namesWrittenMidSentence } from "./heading-names.ts";
|
|
|
5
5
|
import type { Detector, Finding, Lexicon, ProseDocument, Section, Sentence, Token } from "../plugin.ts";
|
|
6
6
|
import { entryOpens } from "./lexicon-match.ts";
|
|
7
7
|
import { opensWithPhrase } from "./opener-phrase.ts";
|
|
8
|
+
import { speakerTurns } from "./speaker-turns.ts";
|
|
8
9
|
|
|
9
10
|
const PER = 1000;
|
|
10
11
|
|
|
@@ -21,12 +22,15 @@ const CAPITALISED = /^\p{Lu}\p{Ll}/u;
|
|
|
21
22
|
const LETTER = /\p{L}/u;
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
25
|
+
* 頭だけ大文字の -ly の語は、文の途中なら解析器が語尾で副詞と当てた名前(July、Kelly)か題の語、文頭でも行全体が題の書き方なら
|
|
26
|
+
* 題の語(Frequently Asked Questions)。どちらも動詞に畳める副詞ではない。書き手の確かさを言う副詞(probably、apparently)も、畳む先の動詞が無い。
|
|
26
27
|
*/
|
|
27
|
-
const lyAdverbsOf = (
|
|
28
|
+
const lyAdverbsOf = (sentence: Sentence, stance: ReadonlySet<string>): Token[] => {
|
|
29
|
+
const tokens = sentence.tokens ?? [];
|
|
28
30
|
const first = tokens.findIndex((token) => LETTER.test(token.surface));
|
|
29
|
-
|
|
31
|
+
const titleLine = isTitleCase(sentence.text) === true;
|
|
32
|
+
const isTitleWord = (token: Token, at: number): boolean => CAPITALISED.test(token.surface) && (at > first || titleLine);
|
|
33
|
+
return tokens.filter((token, at) => isLyAdverb(token) && !stance.has(token.surface.toLowerCase()) && !isTitleWord(token, at));
|
|
30
34
|
};
|
|
31
35
|
|
|
32
36
|
/**
|
|
@@ -36,7 +40,7 @@ const lyAdverbsOf = (tokens: readonly Token[], stance: ReadonlySet<string>): Tok
|
|
|
36
40
|
export const adverbDensity: Detector = (doc, options): Finding[] => {
|
|
37
41
|
const words = wordsIn(doc);
|
|
38
42
|
const stance = new Set((doc.lexicons["stance-adverb"] ?? []).map((entry) => entry.pattern));
|
|
39
|
-
const hits = doc.sentences.flatMap((sentence) => lyAdverbsOf(sentence
|
|
43
|
+
const hits = doc.sentences.flatMap((sentence) => lyAdverbsOf(sentence, stance).map((token) => ({ sentence, token })));
|
|
40
44
|
const density = words === 0 ? 0 : Math.round((hits.length / words) * PER);
|
|
41
45
|
const first = hits[0];
|
|
42
46
|
if (words < MIN_WORDS || first === undefined || density <= options.limit) return [];
|
|
@@ -79,11 +83,16 @@ const expletiveAt = (tokens: readonly Token[]): Token | undefined => {
|
|
|
79
83
|
return head;
|
|
80
84
|
};
|
|
81
85
|
|
|
86
|
+
/** In minutes of who said what, a speaker's sentences are their own phrasing, recorded as said: not the writer's to recast. */
|
|
82
87
|
export const expletive: Detector = (doc, options): Finding[] => {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
const turns = speakerTurns(doc.source);
|
|
89
|
+
const spoken = (sentence: Sentence): boolean => turns.some((turn) => turn.start <= sentence.span.start && sentence.span.start < turn.end);
|
|
90
|
+
const hits = doc.sentences
|
|
91
|
+
.filter((sentence) => !spoken(sentence))
|
|
92
|
+
.flatMap((sentence) => {
|
|
93
|
+
const at = expletiveAt(sentence.tokens ?? []);
|
|
94
|
+
return at === undefined ? [] : [{ sentence, at }];
|
|
95
|
+
});
|
|
87
96
|
if (hits.length <= options.limit) return [];
|
|
88
97
|
return hits.map(({ sentence, at }) => ({
|
|
89
98
|
rule: "expletive-construction",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Span, Token } from "../plugin.ts";
|
|
2
|
+
import { quotedSpans } from "../quoted-span.ts";
|
|
2
3
|
|
|
3
4
|
/** 頭から外す語と、文書全体の座標でのその範囲。 */
|
|
4
5
|
export type Edge = { readonly surface: string; readonly span: Span };
|
|
@@ -15,6 +16,20 @@ const KANJI_OR_HIRAGANA = /[一-鿿ぁ-ゖ]/u;
|
|
|
15
16
|
export const holdsName = (text: string, span: Span, start: number, end: number): boolean =>
|
|
16
17
|
span.start <= start && end <= span.end && !KANJI_OR_HIRAGANA.test(text.slice(span.start, start) + text.slice(end, span.end));
|
|
17
18
|
|
|
19
|
+
const HIRAGANA_HEAD = /^\s*[ぁ-ゖ]/u;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 漢字の連なり [start, end) が、一行を漢字も平仮名も無い語(ダイヤル)とだけで埋め、その下に行が続くか。
|
|
23
|
+
* 番号や内容の上に置いた名前の行(児童相談所虐待対応ダイヤル / 189)。下の行が平仮名で始まれば、折り返した文の途中。
|
|
24
|
+
*/
|
|
25
|
+
export const labelsLines = (text: string, start: number, end: number): boolean => {
|
|
26
|
+
const lineStart = text.lastIndexOf("\n", start - 1) + 1;
|
|
27
|
+
const lineEnd = text.indexOf("\n", end);
|
|
28
|
+
if (start >= end || lineEnd < 0) return false;
|
|
29
|
+
const below = text.slice(lineEnd + 1);
|
|
30
|
+
return below.trim() !== "" && !HIRAGANA_HEAD.test(below) && holdsName(text, { start: lineStart, end: lineEnd }, start, end);
|
|
31
|
+
};
|
|
32
|
+
|
|
18
33
|
/** 連なりの前(before: 文の頭から連なりまで)が、空白を挟んだ法人格で終わるか(一般社団法人 全国銀行個人信用情報センター)。 */
|
|
19
34
|
export const followsForm = (before: string, forms: readonly string[]): boolean => {
|
|
20
35
|
const trimmed = before.trimEnd();
|
|
@@ -108,3 +123,15 @@ export const trailingConjunction = (tokens: readonly Token[], start: number, end
|
|
|
108
123
|
if (token === undefined || token.pos !== "CCONJ" || token.span.start <= start) return undefined;
|
|
109
124
|
return { surface: run.slice(run.length - (end - token.span.start)), start: token.span.start };
|
|
110
125
|
};
|
|
126
|
+
|
|
127
|
+
/** 丸括弧の補い。 */
|
|
128
|
+
const GLOSS_MARKS = { "(": ")", "(": ")" };
|
|
129
|
+
/** 補いの括弧のすぐ前に立つ、語の字(修士の学位(…)の「位」、EBITDA+(…)の「+」)。 */
|
|
130
|
+
const GLOSSED_WORD_END = /[\p{Script=Han}\p{Script=Katakana}\p{Script=Latin}\p{N}ー++]$/u;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 語のすぐ後ろの丸括弧の中身が、この連なりだけか(EBITDA+(減価償却他調整前営業利益)、修士の学位(大学院修士課程修了程度))。
|
|
134
|
+
* 前の語の言い換えや展開で、書き手が 1 つの名前として示したもの。
|
|
135
|
+
*/
|
|
136
|
+
export const fillsGloss = (text: string, start: number, end: number): boolean =>
|
|
137
|
+
quotedSpans(text, GLOSS_MARKS).some((span) => GLOSSED_WORD_END.test(text.slice(0, span.start - 1)) && holdsName(text, span, start, end));
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { escapeRegExp } from "../orthography.ts";
|
|
2
|
+
import type { Lexicon } from "../plugin.ts";
|
|
3
|
+
|
|
4
|
+
// A vague word that a law or a section governs: "as required by applicable law", "as required under 45 CFR §164.528".
|
|
5
|
+
// What the law requires is fixed by the law it names, so the word leaves nothing for the reader to decide. Pure: the
|
|
6
|
+
// governing words (by, under) and the words that name a law (law, Act, §, HIPAA) come from the language's lexicon.
|
|
7
|
+
|
|
8
|
+
/** The lexicon's groups: the words that govern a law, and the words that name one. */
|
|
9
|
+
const GOVERNOR = "governor";
|
|
10
|
+
const REFERENCE = "reference";
|
|
11
|
+
/** How many words after the governing word may hold the law's name: "the Food Safety Modernization Act". */
|
|
12
|
+
const MAX_OBJECT_WORDS = 6;
|
|
13
|
+
/** Where the governed phrase ends: a clause's punctuation or a bracket. A full stop counts only before a space. */
|
|
14
|
+
const OBJECT_END = /[,;:()()、。\n]|\.(?=\s|$)/u;
|
|
15
|
+
|
|
16
|
+
export type LawReference = { readonly governors: readonly string[]; readonly references: readonly string[] };
|
|
17
|
+
|
|
18
|
+
export const NO_LAW_REFERENCE: LawReference = { governors: [], references: [] };
|
|
19
|
+
|
|
20
|
+
export const lawReferenceOf = (lexicon: Lexicon): LawReference => ({
|
|
21
|
+
governors: lexicon.filter((entry) => entry.group === GOVERNOR).map((entry) => entry.pattern.toLowerCase()),
|
|
22
|
+
references: lexicon.filter((entry) => entry.group === REFERENCE).map((entry) => entry.pattern.toLowerCase()),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/** A word written whole: no letter or digit right before it, no letter right after it (§164 holds §, laws does not hold law). */
|
|
26
|
+
const wholeWord = (word: string): RegExp => new RegExp(`(?<![\\p{L}\\p{N}])${escapeRegExp(word)}(?!\\p{L})`, "u");
|
|
27
|
+
|
|
28
|
+
/** The governing word the text opens with, and the text after it; undefined when it opens with none. */
|
|
29
|
+
const afterGovernor = (text: string, governors: readonly string[]): string | undefined => {
|
|
30
|
+
const lower = text.trimStart().toLowerCase();
|
|
31
|
+
const governor = governors.find((word) => word !== "" && new RegExp(`^${escapeRegExp(word)}(?!\\p{L})`, "u").test(lower));
|
|
32
|
+
return governor === undefined ? undefined : lower.slice(governor.length);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** The words the governing word takes, up to the clause's end or the next governing word ("the customer under the law" stops at under). */
|
|
36
|
+
const objectOf = (text: string, governors: readonly string[]): string => {
|
|
37
|
+
const end = text.search(OBJECT_END);
|
|
38
|
+
const words = (end === -1 ? text : text.slice(0, end)).split(/\s+/u).filter((word) => word !== "");
|
|
39
|
+
const starts = new Set(governors.map((governor) => governor.split(/\s+/u)[0] ?? ""));
|
|
40
|
+
const next = words.findIndex((word) => starts.has(word));
|
|
41
|
+
return (next === -1 ? words : words.slice(0, next)).slice(0, MAX_OBJECT_WORDS).join(" ");
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** Whether the words right after end (an offset in text) govern the word by a law or a section: "… by applicable law". */
|
|
45
|
+
export const governedByLaw = (text: string, end: number, law: LawReference): boolean => {
|
|
46
|
+
const rest = afterGovernor(text.slice(end), law.governors);
|
|
47
|
+
if (rest === undefined) return false;
|
|
48
|
+
const object = objectOf(rest, law.governors);
|
|
49
|
+
return law.references.some((word) => word !== "" && wholeWord(word).test(object));
|
|
50
|
+
};
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import type { ProseDocument, Span, Token } from "../plugin.ts";
|
|
2
2
|
import { escapeRegExp } from "../orthography.ts";
|
|
3
3
|
import { isKnownWord, type Speller } from "../spelling.ts";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
isAcronymPair,
|
|
6
|
+
isAfterCountArticle,
|
|
7
|
+
isContractionPair,
|
|
8
|
+
isInFileName,
|
|
9
|
+
isInverseOrder,
|
|
10
|
+
isListedPair,
|
|
11
|
+
isMarkedWrong,
|
|
12
|
+
isNameAndWord,
|
|
13
|
+
isOtherEnding,
|
|
14
|
+
type WordEnding,
|
|
15
|
+
} from "../name-variant-shapes.ts";
|
|
5
16
|
import { titleSlipsIn } from "../name-title-slip.ts";
|
|
6
17
|
|
|
7
18
|
// name-variant が、似た二つの形を一つの名前の書き分けではなく別の二つと見る所。中黒で並べた二つの語、ある向きとその逆、語の別の
|
|
@@ -81,6 +92,19 @@ type Reading = {
|
|
|
81
92
|
readonly tokenAt: ReadonlyMap<number, Token>;
|
|
82
93
|
readonly speller: Speller | undefined;
|
|
83
94
|
readonly ordinary: ReadonlySet<string>;
|
|
95
|
+
readonly countArticles: readonly string[];
|
|
96
|
+
readonly wrongMarks: readonly string[];
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/** Where a form is written, as written, inside a longer run of letters too (RSpecで). */
|
|
100
|
+
const placesOf = (text: string, surface: string): number[] =>
|
|
101
|
+
surface === "" ? [] : [...text.matchAll(new RegExp(escapeRegExp(surface), "gu"))].map((found) => found.index ?? 0);
|
|
102
|
+
|
|
103
|
+
/** Whether one side of the pair is shown as wrong on purpose: the pointed form, or every place the usual form is written, after a wrong mark (× Rspec / ○ RSpec). */
|
|
104
|
+
const isShownWrong = (reading: Reading, found: Found): boolean => {
|
|
105
|
+
const isMarked = (offset: number): boolean => isMarkedWrong(reading.text, offset, reading.wrongMarks);
|
|
106
|
+
const usualPlaces = placesOf(reading.text, found.usual);
|
|
107
|
+
return isMarked(found.offset) || (usualPlaces.length > 0 && usualPlaces.every(isMarked));
|
|
84
108
|
};
|
|
85
109
|
|
|
86
110
|
const inOneSentence = (sentences: readonly Span[], offset: number, other: number): boolean =>
|
|
@@ -89,7 +113,8 @@ const inOneSentence = (sentences: readonly Span[], offset: number, other: number
|
|
|
89
113
|
/**
|
|
90
114
|
* A one-letter variant (near) that is two names: another form of the word (Texan), the usual form in the same sentence
|
|
91
115
|
* (Constantinus and Constantius, two sons), the differing word written twice or more (Bandle, of Richard Bandle and
|
|
92
|
-
* Mrs. Bandle),
|
|
116
|
+
* Mrs. Bandle), a word the document also writes in small letters (Stain, Vigil), two plural acronyms (SBLCs, SBDCs), a
|
|
117
|
+
* dictionary word after a or an (A Coiner), or a word capitalised by its place (Sprang).
|
|
93
118
|
*/
|
|
94
119
|
const isNearPair = (reading: Reading, found: Found): boolean => {
|
|
95
120
|
const word = differingWord(found.name, found.usual);
|
|
@@ -97,13 +122,23 @@ const isNearPair = (reading: Reading, found: Found): boolean => {
|
|
|
97
122
|
isOtherEnding(found.name, found.usual, reading.endings) ||
|
|
98
123
|
offsetsOf(reading.text, found.usual).some((offset) => inOneSentence(reading.sentences, found.offset, offset)) ||
|
|
99
124
|
(word !== undefined && offsetsOf(reading.text, word).length >= 2) ||
|
|
125
|
+
isNameAndWord(found.name, found.usual, reading.text, (word) => reading.speller !== undefined && isKnownWord(word, reading.speller)) ||
|
|
126
|
+
isAcronymPair(found.name, found.usual) ||
|
|
127
|
+
isAfterCountArticle(
|
|
128
|
+
reading.text,
|
|
129
|
+
found.offset,
|
|
130
|
+
found.name,
|
|
131
|
+
reading.countArticles,
|
|
132
|
+
(word) => reading.speller !== undefined && isKnownWord(word, reading.speller),
|
|
133
|
+
) ||
|
|
100
134
|
isCapitalisedByPlace(found, reading.text, reading.sentenceStarts, reading.speller, reading.ordinary)
|
|
101
135
|
);
|
|
102
136
|
};
|
|
103
137
|
|
|
104
138
|
/**
|
|
105
139
|
* The finding is not two forms of one name: a one-letter variant that is two names (isNearPair), ・ listing two words, a
|
|
106
|
-
* direction and its inverse, a title quoted in capitals, a
|
|
140
|
+
* direction and its inverse, a title quoted in capitals, a contraction printed with and without its apostrophe, a piece of
|
|
141
|
+
* a file name or URL, a form shown as wrong on purpose, a verb stem. ordinary holds the words read as names that are
|
|
107
142
|
* ordinary words in small letters (name-ordinary-word.ts).
|
|
108
143
|
*/
|
|
109
144
|
export const twoThingsIn = (
|
|
@@ -122,12 +157,17 @@ export const twoThingsIn = (
|
|
|
122
157
|
tokenAt: new Map(tokens.map((token) => [token.span.start, token])),
|
|
123
158
|
speller,
|
|
124
159
|
ordinary,
|
|
160
|
+
countArticles: patternsOf(doc, "name-count-article"),
|
|
161
|
+
wrongMarks: patternsOf(doc, "name-wrong-mark"),
|
|
125
162
|
};
|
|
126
163
|
return (found) =>
|
|
127
164
|
(found.kind === "near" && isNearPair(reading, found)) ||
|
|
128
165
|
isListedPair(found.name, found.usual) ||
|
|
129
166
|
(found.kind === "order" && isInverseOrder(found.name, found.usual, reading.directions)) ||
|
|
130
167
|
isQuotedTitleCase(found, reading.text) ||
|
|
168
|
+
(found.kind === "spelling" && isContractionPair(found.name, found.usual, reading.text)) ||
|
|
169
|
+
isInFileName(reading.text, found.offset, found.name.length) ||
|
|
170
|
+
isShownWrong(reading, found) ||
|
|
131
171
|
(found.kind === "reading" && isVerbStem(found, reading.tokenAt, reading.copulas));
|
|
132
172
|
};
|
|
133
173
|
|
|
@@ -52,6 +52,8 @@ export type OpenEndNames = {
|
|
|
52
52
|
readonly terms: ReadonlySet<string>;
|
|
53
53
|
/** The document's headings: a noun a heading names with the word (## 出願書類等の送付先) is the page's subject, not an open list. */
|
|
54
54
|
readonly headings: readonly string[];
|
|
55
|
+
/** Terms that law or usage fixes with the word (消費税等, 免許等), from the language's lexicon: no open list. */
|
|
56
|
+
readonly fixed: ReadonlySet<string>;
|
|
55
57
|
};
|
|
56
58
|
|
|
57
59
|
const attached = (left: Token | undefined, right: Token | undefined): boolean =>
|
|
@@ -145,13 +147,28 @@ const definedTerms = (doc: ProseDocument): Set<string> =>
|
|
|
145
147
|
: inDocumentOrder(doc.structure).flatMap((node) => (node.kind === "definition" && typeof node.attrs["term"] === "string" ? [node.attrs["term"]] : [])),
|
|
146
148
|
);
|
|
147
149
|
|
|
148
|
-
/**
|
|
149
|
-
|
|
150
|
+
/**
|
|
151
|
+
* The names a document gives that contain an open-end word. statements: the language's words of a definition (をいう, means);
|
|
152
|
+
* fixed: the terms law or usage fixes with the word (消費税等).
|
|
153
|
+
*/
|
|
154
|
+
export const openEndNames = (
|
|
155
|
+
doc: ProseDocument,
|
|
156
|
+
words: readonly LexiconEntry[],
|
|
157
|
+
statements: readonly string[],
|
|
158
|
+
fixed: readonly string[] = [],
|
|
159
|
+
): OpenEndNames => {
|
|
150
160
|
const occurrences = doc.sentences.flatMap((sentence) => words.flatMap((word) => occurrencesIn(sentence, word)));
|
|
151
161
|
const defined = occurrences.filter((occurrence) => definedInAside(doc.source, occurrence, statements)).map((occurrence) => nounOf(doc.source, occurrence));
|
|
152
162
|
const heads = occurrences.filter((occurrence) => headsItem(doc.source, occurrence, statements)).map((occurrence) => nounOf(doc.source, occurrence));
|
|
153
163
|
const headings = doc.sections.map((section) => section.heading).filter((heading) => heading.trim() !== "");
|
|
154
|
-
return {
|
|
164
|
+
return {
|
|
165
|
+
quoted: quotedNames(doc.source, words),
|
|
166
|
+
defined: new Set(defined),
|
|
167
|
+
heads: [...new Set(heads)],
|
|
168
|
+
terms: definedTerms(doc),
|
|
169
|
+
headings,
|
|
170
|
+
fixed: new Set(fixed),
|
|
171
|
+
};
|
|
155
172
|
};
|
|
156
173
|
|
|
157
174
|
/** Whether a quoted name holds this occurrence: the text around it reads the whole name (当該責任追及等 holds 「責任追及等」). */
|
|
@@ -183,7 +200,7 @@ const isNamed = (source: string, occurrence: Occurrence, names: OpenEndNames): b
|
|
|
183
200
|
inQuotedName(source, occurrence, names.quoted) ||
|
|
184
201
|
namedByHeading(source, occurrence, names.headings) ||
|
|
185
202
|
followsTerm(source, occurrence, names.terms) ||
|
|
186
|
-
partsHoldingWord(source, occurrence).some((part) => names.defined.has(part) || names.heads.some((head) => head.startsWith(part)));
|
|
203
|
+
partsHoldingWord(source, occurrence).some((part) => names.defined.has(part) || names.fixed.has(part) || names.heads.some((head) => head.startsWith(part)));
|
|
187
204
|
|
|
188
205
|
/** Whether the words around an occurrence bound its list; range: the tokens the word covers. */
|
|
189
206
|
export type BoundedAfter = (tokens: readonly Token[], range: TokenRange) => boolean;
|