chaffjs 0.48.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/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/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/concrete-evidence-density.js +2 -2
- package/dist/detectors/concrete-evidence.d.ts +7 -0
- package/dist/detectors/concrete-evidence.d.ts.map +1 -1
- package/dist/detectors/concrete-evidence.js +20 -0
- package/dist/detectors/concrete-evidence.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 +7 -1
- 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/name-variant-two-things.d.ts +1 -1
- package/dist/detectors/name-variant-two-things.d.ts.map +1 -1
- package/dist/detectors/name-variant-two-things.js +16 -4
- package/dist/detectors/name-variant-two-things.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/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 +3 -2
- package/dist/detectors/sentence-length.js.map +1 -1
- package/dist/detectors/sentence-parts.d.ts +6 -3
- package/dist/detectors/sentence-parts.d.ts.map +1 -1
- package/dist/detectors/sentence-parts.js +15 -7
- package/dist/detectors/sentence-parts.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/name-variant-shapes.d.ts +10 -0
- package/dist/name-variant-shapes.d.ts.map +1 -1
- package/dist/name-variant-shapes.js +24 -0
- package/dist/name-variant-shapes.js.map +1 -1
- package/dist/set-phrase-particles.js +2 -2
- package/dist/set-phrase-particles.js.map +1 -1
- 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/concrete-evidence-density.yaml +2 -2
- package/rules/expletive-construction.yaml +2 -2
- package/rules/max-kanji-continuous.yaml +5 -3
- 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/topic-predicate-distance.yaml +2 -2
- package/rules/undefined-acronym.yaml +2 -2
- package/rules/vague-word-density.yaml +2 -2
- package/skills/chaff/SKILL.md +3 -1
- package/src/detectors/acronym-name.ts +6 -3
- package/src/detectors/char-shape.ts +18 -3
- package/src/detectors/concrete-evidence-density.ts +2 -2
- package/src/detectors/concrete-evidence.ts +27 -0
- package/src/detectors/en-shape.ts +10 -4
- package/src/detectors/kanji-name-edge.ts +27 -0
- package/src/detectors/name-variant-two-things.ts +28 -3
- 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/sentence-counts.ts +2 -1
- package/src/detectors/sentence-ending.ts +8 -4
- package/src/detectors/sentence-length.ts +6 -4
- package/src/detectors/sentence-parts.ts +21 -9
- package/src/detectors/speaker-turns.ts +37 -0
- package/src/name-variant-shapes.ts +29 -0
- package/src/set-phrase-particles.ts +2 -2
- package/src/topic-clause.ts +17 -5
|
@@ -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));
|
|
@@ -3,10 +3,12 @@ import { escapeRegExp } from "../orthography.ts";
|
|
|
3
3
|
import { isKnownWord, type Speller } from "../spelling.ts";
|
|
4
4
|
import {
|
|
5
5
|
isAcronymPair,
|
|
6
|
+
isAfterCountArticle,
|
|
6
7
|
isContractionPair,
|
|
7
8
|
isInFileName,
|
|
8
9
|
isInverseOrder,
|
|
9
10
|
isListedPair,
|
|
11
|
+
isMarkedWrong,
|
|
10
12
|
isNameAndWord,
|
|
11
13
|
isOtherEnding,
|
|
12
14
|
type WordEnding,
|
|
@@ -90,6 +92,19 @@ type Reading = {
|
|
|
90
92
|
readonly tokenAt: ReadonlyMap<number, Token>;
|
|
91
93
|
readonly speller: Speller | undefined;
|
|
92
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));
|
|
93
108
|
};
|
|
94
109
|
|
|
95
110
|
const inOneSentence = (sentences: readonly Span[], offset: number, other: number): boolean =>
|
|
@@ -98,8 +113,8 @@ const inOneSentence = (sentences: readonly Span[], offset: number, other: number
|
|
|
98
113
|
/**
|
|
99
114
|
* A one-letter variant (near) that is two names: another form of the word (Texan), the usual form in the same sentence
|
|
100
115
|
* (Constantinus and Constantius, two sons), the differing word written twice or more (Bandle, of Richard Bandle and
|
|
101
|
-
* Mrs. Bandle), a word the document also writes in small letters (Stain, Vigil), two plural acronyms (SBLCs, SBDCs),
|
|
102
|
-
* word capitalised by its place (Sprang).
|
|
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).
|
|
103
118
|
*/
|
|
104
119
|
const isNearPair = (reading: Reading, found: Found): boolean => {
|
|
105
120
|
const word = differingWord(found.name, found.usual);
|
|
@@ -109,6 +124,13 @@ const isNearPair = (reading: Reading, found: Found): boolean => {
|
|
|
109
124
|
(word !== undefined && offsetsOf(reading.text, word).length >= 2) ||
|
|
110
125
|
isNameAndWord(found.name, found.usual, reading.text, (word) => reading.speller !== undefined && isKnownWord(word, reading.speller)) ||
|
|
111
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
|
+
) ||
|
|
112
134
|
isCapitalisedByPlace(found, reading.text, reading.sentenceStarts, reading.speller, reading.ordinary)
|
|
113
135
|
);
|
|
114
136
|
};
|
|
@@ -116,7 +138,7 @@ const isNearPair = (reading: Reading, found: Found): boolean => {
|
|
|
116
138
|
/**
|
|
117
139
|
* The finding is not two forms of one name: a one-letter variant that is two names (isNearPair), ・ listing two words, a
|
|
118
140
|
* direction and its inverse, a title quoted in capitals, a contraction printed with and without its apostrophe, a piece of
|
|
119
|
-
* a file name or URL, a verb stem. ordinary holds the words read as names that are
|
|
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
|
|
120
142
|
* ordinary words in small letters (name-ordinary-word.ts).
|
|
121
143
|
*/
|
|
122
144
|
export const twoThingsIn = (
|
|
@@ -135,6 +157,8 @@ export const twoThingsIn = (
|
|
|
135
157
|
tokenAt: new Map(tokens.map((token) => [token.span.start, token])),
|
|
136
158
|
speller,
|
|
137
159
|
ordinary,
|
|
160
|
+
countArticles: patternsOf(doc, "name-count-article"),
|
|
161
|
+
wrongMarks: patternsOf(doc, "name-wrong-mark"),
|
|
138
162
|
};
|
|
139
163
|
return (found) =>
|
|
140
164
|
(found.kind === "near" && isNearPair(reading, found)) ||
|
|
@@ -143,6 +167,7 @@ export const twoThingsIn = (
|
|
|
143
167
|
isQuotedTitleCase(found, reading.text) ||
|
|
144
168
|
(found.kind === "spelling" && isContractionPair(found.name, found.usual, reading.text)) ||
|
|
145
169
|
isInFileName(reading.text, found.offset, found.name.length) ||
|
|
170
|
+
isShownWrong(reading, found) ||
|
|
146
171
|
(found.kind === "reading" && isVerbStem(found, reading.tokenAt, reading.copulas));
|
|
147
172
|
};
|
|
148
173
|
|
|
@@ -3,12 +3,26 @@
|
|
|
3
3
|
// [FETCH] WHATWG, "Fetch - Living Standard",
|
|
4
4
|
// <https://fetch.spec.whatwg.org/>.
|
|
5
5
|
//
|
|
6
|
+
// A label too long for its column leaves one space, or stands alone on its line, before the entry's indented lines:
|
|
7
|
+
//
|
|
8
|
+
// [CERT.CVD] Software Engineering Institute, "The CERT Guide to
|
|
9
|
+
// Coordinated Vulnerability Disclosure", August 2017.
|
|
10
|
+
//
|
|
11
|
+
// [ISO.29147.2018]
|
|
12
|
+
// ISO, "Information technology - Security techniques -
|
|
13
|
+
//
|
|
6
14
|
// The entry is written in the cited work's words. Pure.
|
|
7
15
|
|
|
8
16
|
type Span = { readonly start: number; readonly end: number };
|
|
9
17
|
|
|
18
|
+
const LABEL = String.raw`^(?<indent>[ \t]*)\[(?<label>[A-Za-z0-9][\w.:+-]*)\]`;
|
|
10
19
|
/** A label in square brackets opening a line, then a wide gap: two spaces or a tab. A link definition ([x]: url) has a colon. */
|
|
11
|
-
const ENTRY_START =
|
|
20
|
+
const ENTRY_START = new RegExp(String.raw`${LABEL}(?: {2,}|\t)\S`, "u");
|
|
21
|
+
/**
|
|
22
|
+
* A label followed by one space or by the end of its line. Prose opens a line with a bracketed citation too ("[JSON] and XML
|
|
23
|
+
* [XML] document formats"), so this starts an entry only when the next line is indented deeper than the label.
|
|
24
|
+
*/
|
|
25
|
+
const LONG_LABEL_START = new RegExp(String.raw`${LABEL}(?: \S|$)`, "u");
|
|
12
26
|
|
|
13
27
|
type Line = { readonly text: string; readonly start: number };
|
|
14
28
|
|
|
@@ -31,12 +45,26 @@ const entryEnd = (lines: readonly Line[], at: number, indent: number): number =>
|
|
|
31
45
|
return lines.length;
|
|
32
46
|
};
|
|
33
47
|
|
|
48
|
+
type EntryStart = { readonly indent: number; readonly label: string };
|
|
49
|
+
|
|
50
|
+
/** The entry that opens at this line, if one does. */
|
|
51
|
+
const entryStartAt = (lines: readonly Line[], at: number): EntryStart | undefined => {
|
|
52
|
+
const text = lines[at]?.text ?? "";
|
|
53
|
+
const wide = ENTRY_START.exec(text)?.groups;
|
|
54
|
+
if (wide !== undefined) return { indent: (wide["indent"] ?? "").length, label: wide["label"] ?? "" };
|
|
55
|
+
const long = LONG_LABEL_START.exec(text)?.groups;
|
|
56
|
+
if (long === undefined) return undefined;
|
|
57
|
+
const indent = (long["indent"] ?? "").length;
|
|
58
|
+
const next = lines[at + 1]?.text ?? "";
|
|
59
|
+
return next.trim() !== "" && indentOf(next) > indent ? { indent, label: long["label"] ?? "" } : undefined;
|
|
60
|
+
};
|
|
61
|
+
|
|
34
62
|
export const referenceEntrySpans = (source: string): Span[] => {
|
|
35
63
|
const lines = linesOf(source);
|
|
36
64
|
return lines.flatMap((line, at) => {
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
39
|
-
const last = lines[entryEnd(lines, at, indent
|
|
65
|
+
const entry = entryStartAt(lines, at);
|
|
66
|
+
if (entry === undefined) return [];
|
|
67
|
+
const last = lines[entryEnd(lines, at, entry.indent) - 1] ?? line;
|
|
40
68
|
return [{ start: line.start, end: last.start + last.text.length }];
|
|
41
69
|
});
|
|
42
70
|
};
|
|
@@ -45,5 +73,7 @@ export const referenceEntrySpans = (source: string): Span[] => {
|
|
|
45
73
|
* The labels of the entries ([UNIX] The Open Group, "The Single UNIX Specification"). The entry says what the label names,
|
|
46
74
|
* so the label written in prose (a UNIX timestamp) is explained by it.
|
|
47
75
|
*/
|
|
48
|
-
export const referenceEntryLabels = (source: string): ReadonlySet<string> =>
|
|
49
|
-
|
|
76
|
+
export const referenceEntryLabels = (source: string): ReadonlySet<string> => {
|
|
77
|
+
const lines = linesOf(source);
|
|
78
|
+
return new Set(lines.flatMap((_, at) => entryStartAt(lines, at)?.label ?? []));
|
|
79
|
+
};
|
|
@@ -3,7 +3,7 @@ import type { LexiconEntry, Paragraph, Sentence, Span } from "../plugin.ts";
|
|
|
3
3
|
|
|
4
4
|
// Sentences that are not the writer's running prose and so are not compared for register: wording quoted under a label
|
|
5
5
|
// (例:…, Q: …, a paragraph under a lone 用例), the value of a field set out under a marked label line (■ 調査目的\n…) and a contact
|
|
6
|
-
// block (a paragraph with a 〒 or 電話: line). A note on a ※ line and a cell of a table laid out as lines are set apart too, but
|
|
6
|
+
// block (a paragraph with a 〒 or 電話: line). A note on a ※ or * line and a cell of a table laid out as lines are set apart too, but
|
|
7
7
|
// stay counted: only some of a table's cells take the shape, and dropping those would leave the rest a smaller minority. Pure.
|
|
8
8
|
|
|
9
9
|
/** A label, a number after it (Q1, 例2), then the mark that ends it. */
|
|
@@ -78,13 +78,13 @@ export const fieldValueSentences = (sentences: readonly Sentence[], source: stri
|
|
|
78
78
|
return new Set(sentences.filter((sentence) => values.some((value) => sentence.span.start >= value.start && sentence.span.start < value.end)));
|
|
79
79
|
};
|
|
80
80
|
|
|
81
|
-
/** A line that opens with a reference mark (※PDF
|
|
82
|
-
const NOTE_LINE = /^[ \t\u3000]
|
|
81
|
+
/** A line that opens with a reference mark, ※ or the full-width asterisk * (※PDFファイルが開けない…, *図は圧縮しているため…): a note set beside the text. */
|
|
82
|
+
const NOTE_LINE = /^[ \t\u3000]*[※*]/u;
|
|
83
83
|
|
|
84
84
|
const lineStartOf = (source: string, offset: number): number => source.lastIndexOf("\n", offset - 1) + 1;
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
|
-
* The sentences on a line that opens with
|
|
87
|
+
* The sentences on a line that opens with ※ or *. A note (※…の場合はこちらをご覧ください。) is the page's aside to the reader, written in
|
|
88
88
|
* its own register whatever the text around it uses.
|
|
89
89
|
*/
|
|
90
90
|
export const referenceNoteSentences = (sentences: readonly Sentence[], source: string): Set<Sentence> =>
|
|
@@ -70,6 +70,25 @@ export const isTakenUp = (next: Sentence | undefined, between: string, openers:
|
|
|
70
70
|
return openers.some((opener) => opening.has(opener.pattern));
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
+
/** The particles a sentence closes with, joined (か/な → かな), after its last word and before its marks. */
|
|
74
|
+
const closingParticles = (tokens: readonly Token[]): string => {
|
|
75
|
+
const words = tokens.filter((token) => token.pos !== "PUNCT" && !TRAILING_MARKS.has(token.surface));
|
|
76
|
+
const start = words.findLastIndex((token) => token.pos !== "PART") + 1;
|
|
77
|
+
return words
|
|
78
|
+
.slice(start)
|
|
79
|
+
.map((token) => token.surface)
|
|
80
|
+
.join("");
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A sentence that closes with a particle of address from address-particle (…含まれているよ。…違うんだよ。…のかな?): the writer speaks
|
|
85
|
+
* to the reader on purpose, in a voice a polite page sets among its sentences, not a slip into the plain register.
|
|
86
|
+
*/
|
|
87
|
+
export const isAddressed = (sentence: Sentence, particles: readonly LexiconEntry[]): boolean => {
|
|
88
|
+
const closing = closingParticles(sentence.tokens ?? []);
|
|
89
|
+
return closing !== "" && particles.some((particle) => closing.endsWith(particle.pattern));
|
|
90
|
+
};
|
|
91
|
+
|
|
73
92
|
const EXCLAMATION = /[!!][\s」』))]*$/u;
|
|
74
93
|
|
|
75
94
|
/** A sentence closed by an exclamation mark (わかるかっ!!!): a cry in the writer's voice, said plainly in either register. */
|
|
@@ -163,7 +163,8 @@ export const sentenceCommaCount: Detector = (doc, options): Finding[] => {
|
|
|
163
163
|
return known;
|
|
164
164
|
};
|
|
165
165
|
const counts: TokenTest = (token, at, tokens) => isComma(token) && !separatesItems(at, tokens) && !listedIn(tokens).has(at);
|
|
166
|
-
|
|
166
|
+
const eras = (doc.lexicons["calendar-era"] ?? []).map((entry) => entry.pattern);
|
|
167
|
+
return sentencesOver({ ...doc, sentences: doc.sentences.filter((sentence) => !isFlattenedTable(sentence.text, eras)) }, options.limit, counts);
|
|
167
168
|
};
|
|
168
169
|
|
|
169
170
|
const CONJUNCTIVE = "SCONJ";
|
|
@@ -11,7 +11,7 @@ import { chronologyRows } from "../chronology-rows.ts";
|
|
|
11
11
|
import { isNeutralPlainShape } from "./register-neutral-shape.ts";
|
|
12
12
|
import { spokenAnswerSentences } from "./register-interview.ts";
|
|
13
13
|
import { contactBlockSentences, fieldValueSentences, labelledQuoteSentences, referenceNoteSentences, tableCellSentences } from "./register-set-apart.ts";
|
|
14
|
-
import { endsInSetGreeting, isDeclaration, isExclamation, isTakenUp } from "./register-voice.ts";
|
|
14
|
+
import { endsInSetGreeting, isAddressed, isDeclaration, isExclamation, isTakenUp } from "./register-voice.ts";
|
|
15
15
|
import { entriesForGenre } from "../lexicon-genres.ts";
|
|
16
16
|
import type { Detector, Finding, LexiconEntry, ProseDocument, Sentence, Span, Token } from "../plugin.ts";
|
|
17
17
|
|
|
@@ -34,15 +34,16 @@ import type { Detector, Finding, LexiconEntry, ProseDocument, Sentence, Span, To
|
|
|
34
34
|
/**
|
|
35
35
|
* quiet: 常体と読めるが、願い・問い・言いさしの形(register-neutral-shape.ts)の文。どちらの調子の文書にも現れるので指さない。
|
|
36
36
|
* 丁寧な形でしか言わない挨拶(お疲れ様でした。)、演説の決意の言い切り(二度と繰り返さない。)、
|
|
37
|
-
*
|
|
38
|
-
*
|
|
37
|
+
* 次の文が「そんな」「これだけ」で受ける場面の書き出し、「!」で終わる叫び(わかるかっ!)、読み手に呼びかける終助詞で終わる文(…いるよ。)も quiet(register-voice.ts)。
|
|
38
|
+
* ※や*で始まる行の注記と、行に並べ直した表のセル(制限なし。)は、どちらの調子でも quiet(register-set-apart.ts)。
|
|
39
39
|
* インタビューの答え(聞き手の「――」の後の段落)は話した言葉なので quiet(register-interview.ts)。
|
|
40
40
|
* 数には入れる。数から外すと、常体を何度も使う文書(演説)で少数派が閾値を下回り、残りの常体の文が新たに指されてしまう。
|
|
41
41
|
*/
|
|
42
42
|
type Entry = { readonly sentence: Sentence; readonly register: Register; readonly group: number | undefined; readonly quiet: boolean };
|
|
43
43
|
|
|
44
44
|
/** 文の調子と quiet を決める語彙表。polite は polite-ending、neutral は neutral-ending、requests は neutral-request、wishes は neutral-wish、
|
|
45
|
-
* greetings は set-polite-phrase、declaration と resolves は declaration-particle と declaration-ending を文書の genre で絞ったもの、openers は takeup-opener
|
|
45
|
+
* greetings は set-polite-phrase、declaration と resolves は declaration-particle と declaration-ending を文書の genre で絞ったもの、openers は takeup-opener、
|
|
46
|
+
* address は address-particle。 */
|
|
46
47
|
type EndingWords = {
|
|
47
48
|
readonly polite: readonly LexiconEntry[];
|
|
48
49
|
readonly neutral: readonly LexiconEntry[];
|
|
@@ -52,6 +53,7 @@ type EndingWords = {
|
|
|
52
53
|
readonly declaration: readonly LexiconEntry[];
|
|
53
54
|
readonly resolves: readonly LexiconEntry[];
|
|
54
55
|
readonly openers: readonly LexiconEntry[];
|
|
56
|
+
readonly address: readonly LexiconEntry[];
|
|
55
57
|
};
|
|
56
58
|
|
|
57
59
|
type Read = { readonly register: Register; readonly quiet: boolean };
|
|
@@ -65,6 +67,7 @@ const endingWords = (doc: ProseDocument, polite: readonly LexiconEntry[], genre:
|
|
|
65
67
|
declaration: entriesForGenre(doc.lexicons["declaration-particle"] ?? [], genre),
|
|
66
68
|
resolves: entriesForGenre(doc.lexicons["declaration-ending"] ?? [], genre),
|
|
67
69
|
openers: doc.lexicons["takeup-opener"] ?? [],
|
|
70
|
+
address: doc.lexicons["address-particle"] ?? [],
|
|
68
71
|
});
|
|
69
72
|
|
|
70
73
|
/** 調子を持つ文のうち、指さない形か。next は同じ文書の次の文、between はその間の文字列。 */
|
|
@@ -74,6 +77,7 @@ const isQuiet = (sentence: Sentence, ending: readonly Token[], register: Registe
|
|
|
74
77
|
: isNeutralPlainShape(sentence, ending, words.requests, words.wishes) ||
|
|
75
78
|
isDeclaration(sentence, ending, words.declaration, words.resolves) ||
|
|
76
79
|
isExclamation(sentence) ||
|
|
80
|
+
isAddressed(sentence, words.address) ||
|
|
77
81
|
isTakenUp(next, between, words.openers);
|
|
78
82
|
|
|
79
83
|
const registerOfSentence = (doc: ProseDocument, index: number, words: EndingWords): Read | undefined => {
|
|
@@ -11,10 +11,11 @@ import { isInListItem, isReferenceLine, isTitleLine, quotedTitleWords, remarkAft
|
|
|
11
11
|
|
|
12
12
|
type Measure = { readonly size: number; readonly limit: number; readonly variant?: string };
|
|
13
13
|
|
|
14
|
-
/** The page markers' pattern, the citation signals ("see") and the spans of the list items, read once per document. */
|
|
14
|
+
/** The page markers' pattern, the citation signals ("see"), the era names and the spans of the list items, read once per document. */
|
|
15
15
|
type SentenceWords = {
|
|
16
16
|
readonly markers: RegExp | undefined;
|
|
17
17
|
readonly citationSignals: readonly string[];
|
|
18
|
+
readonly eras: readonly string[];
|
|
18
19
|
readonly listItems: readonly { readonly start: number; readonly end: number }[];
|
|
19
20
|
};
|
|
20
21
|
|
|
@@ -55,8 +56,8 @@ const isUnwritten = (sentence: Sentence, text: string, unit: LengthUnit, words:
|
|
|
55
56
|
isGrammarBlock(sentence.text) || isCitationString(text, words.citationSignals) || (unit === "word" && isTitleLine(text));
|
|
56
57
|
|
|
57
58
|
/** The parts measured one by one when the splitter ran several things into one sentence (label lines, table cells, a quotation). */
|
|
58
|
-
const partsOf = (sentence: Sentence, text: string): readonly string[] | undefined =>
|
|
59
|
-
labelLineParts(sentence.text) ?? flattenedTableParts(text) ?? colonQuotationParts(text) ?? parentheticalSentenceParts(text);
|
|
59
|
+
const partsOf = (sentence: Sentence, text: string, eras: readonly string[]): readonly string[] | undefined =>
|
|
60
|
+
labelLineParts(sentence.text) ?? flattenedTableParts(text, eras) ?? colonQuotationParts(text) ?? parentheticalSentenceParts(text);
|
|
60
61
|
|
|
61
62
|
/** The length of a sentence in the document's language, without what the writer did not write as one. */
|
|
62
63
|
const ownSize = (sentence: Sentence, unit: LengthUnit, words: SentenceWords): number => {
|
|
@@ -64,7 +65,7 @@ const ownSize = (sentence: Sentence, unit: LengthUnit, words: SentenceWords): nu
|
|
|
64
65
|
if (isUnwritten(sentence, text, unit, words)) return 0;
|
|
65
66
|
const aroundCitation = unit === "word" ? wordsAroundCitation(text, words.citationSignals) : undefined;
|
|
66
67
|
if (aroundCitation !== undefined) return sizeOf(aroundCitation, unit);
|
|
67
|
-
const parts = partsOf(sentence, text);
|
|
68
|
+
const parts = partsOf(sentence, text, words.eras);
|
|
68
69
|
if (parts !== undefined) return Math.max(0, ...parts.map((part) => sizeOf(part, unit) - pageMarkerSize(part, words.markers, unit)));
|
|
69
70
|
const remark = unit === "word" ? remarkAfterTitle(text) : undefined;
|
|
70
71
|
if (remark !== undefined) return sizeOf(remark, unit);
|
|
@@ -77,6 +78,7 @@ export const sentenceLength: Detector = (doc, options): Finding[] => {
|
|
|
77
78
|
const words: SentenceWords = {
|
|
78
79
|
markers: pageMarkerPattern((options.lexicon ?? []).map((entry) => entry.pattern)),
|
|
79
80
|
citationSignals: (doc.lexicons["citation-signal"] ?? []).map((entry) => entry.pattern),
|
|
81
|
+
eras: (doc.lexicons["calendar-era"] ?? []).map((entry) => entry.pattern),
|
|
80
82
|
listItems: doc.lists.flatMap((list) => list.itemSpans),
|
|
81
83
|
};
|
|
82
84
|
const long = doc.sentences
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// a converter ran together (…設立1945年7月日染興業…, 39,0439,677…), and a quotation the writer introduces with a colon.
|
|
4
4
|
// Each is measured part by part, or not at all. Pure: the text in, the parts out.
|
|
5
5
|
|
|
6
|
+
import { escapeRegExp } from "../orthography.ts";
|
|
6
7
|
import type { Span } from "../plugin.ts";
|
|
7
8
|
|
|
8
9
|
const LINE_BREAK = /\n/u;
|
|
@@ -46,11 +47,19 @@ const GLUED_NUMBER = /\d[,,]\d{4}|\d(?:[..]\d+){4}/u;
|
|
|
46
47
|
/** A run of numbers, signs and empty-cell dashes (39,0439,6773,503…△0.6); it is cut out when it holds glued cells. */
|
|
47
48
|
const NUMBER_RUN = /[\d,,..△▲-−%%-]+/gu;
|
|
48
49
|
const CUT = "\n";
|
|
49
|
-
/**
|
|
50
|
-
const
|
|
51
|
-
|
|
50
|
+
/** The year of a date that opens a row: four digits, or an era name and its year (昭和59年, 令和元年). */
|
|
51
|
+
const rowYear = (eras: readonly string[]): string =>
|
|
52
|
+
eras.length === 0 ? "[0-90-9]{4}" : `(?:[0-90-9]{4}|(?:${eras.map(escapeRegExp).join("|")})(?:[0-90-9]{1,2}|元))`;
|
|
53
|
+
/** A date that opens a row, run into the cell before it and the cell after it (…設立1945年7月日染興業…, …を開始昭和59年4月東京…). */
|
|
54
|
+
const gluedDate = (eras: readonly string[]): RegExp =>
|
|
55
|
+
new RegExp(
|
|
56
|
+
`(?<=[\\p{Script=Han}\\p{Script=Katakana}\\p{Script=Hiragana}ー])(?=${rowYear(eras)}年[0-90-9]{1,2}月[\\p{Script=Han}\\p{Script=Katakana}\\p{L}])`,
|
|
57
|
+
"gu",
|
|
58
|
+
);
|
|
52
59
|
/** Fewer glued dates than this are a sentence that names a date or two, not the rows of a chronology. */
|
|
53
60
|
const MIN_GLUED_DATES = 3;
|
|
61
|
+
/** A space between Japanese words inside a flattened table: where the converter kept a cell apart (…に開設 (注)1.…). */
|
|
62
|
+
const CELL_SPACE = /(?<=[\p{Script=Han}\p{Script=Katakana}\p{Script=Hiragana}ー)」])\s+(?=[\p{Script=Han}\p{Script=Katakana}\p{Script=Hiragana}(「])/u;
|
|
54
63
|
|
|
55
64
|
const nonEmpty = (parts: readonly string[]): string[] => parts.map((part) => part.trim()).filter((part) => part !== "");
|
|
56
65
|
|
|
@@ -61,11 +70,14 @@ export const hasGluedNumbers = (text: string): boolean => GLUED_NUMBER.test(text
|
|
|
61
70
|
export const gluedNumberSpans = (text: string): Span[] =>
|
|
62
71
|
[...text.matchAll(NUMBER_RUN)].filter((run) => GLUED_NUMBER.test(run[0])).map((run) => ({ start: run.index, end: run.index + run[0].length }));
|
|
63
72
|
|
|
64
|
-
/**
|
|
65
|
-
|
|
73
|
+
/**
|
|
74
|
+
* The cells of a table a converter flattened into one sentence, cut at the glued numbers or at each row's date. eras are
|
|
75
|
+
* the era names a row's year may be written with (the calendar-era lexicon).
|
|
76
|
+
*/
|
|
77
|
+
export const flattenedTableParts = (text: string, eras: readonly string[] = []): readonly string[] | undefined => {
|
|
66
78
|
if (hasGluedNumbers(text)) return nonEmpty(text.replace(NUMBER_RUN, (run) => (GLUED_NUMBER.test(run) ? CUT : run)).split(CUT));
|
|
67
|
-
const rows = text.split(
|
|
68
|
-
return rows.length > MIN_GLUED_DATES ? nonEmpty(rows) : undefined;
|
|
79
|
+
const rows = text.split(gluedDate(eras));
|
|
80
|
+
return rows.length > MIN_GLUED_DATES ? nonEmpty(rows.flatMap((row) => row.split(CELL_SPACE))) : undefined;
|
|
69
81
|
};
|
|
70
82
|
|
|
71
83
|
/** A quotation the writer opens after a colon (has observed: "The credibility of money …"), in straight or curly quotes. */
|
|
@@ -102,8 +114,8 @@ const DITTO_CELLS = /〃\s*〃/u;
|
|
|
102
114
|
* Whether a sentence is a table a converter flattened: glued numbers, rows opened by dates, a header row of cells closed by
|
|
103
115
|
* units, or ditto cells.
|
|
104
116
|
*/
|
|
105
|
-
export const isFlattenedTable = (text: string): boolean =>
|
|
106
|
-
flattenedTableParts(text) !== undefined || (text.match(UNIT_HEADER)?.length ?? 0) >= MIN_UNIT_HEADERS || DITTO_CELLS.test(text);
|
|
117
|
+
export const isFlattenedTable = (text: string, eras: readonly string[] = []): boolean =>
|
|
118
|
+
flattenedTableParts(text, eras) !== undefined || (text.match(UNIT_HEADER)?.length ?? 0) >= MIN_UNIT_HEADERS || DITTO_CELLS.test(text);
|
|
107
119
|
|
|
108
120
|
/** A decimal cell run in between a bracketed cell and the next cell's word ((日本)100.0自動車関連): where one row's cells meet. */
|
|
109
121
|
const GLUED_DECIMAL_CELL = /[))]\d{1,3}\.\d+(?=\p{L})/gu;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// The paragraphs of near-verbatim minutes that open with a speaker's name ("Mara: There's some history ..."). What
|
|
2
|
+
// follows the name is that person's own phrasing as the note-taker recorded it, not the writer's. Pure.
|
|
3
|
+
import type { Span } from "../plugin.ts";
|
|
4
|
+
|
|
5
|
+
/** How many names must each open MIN_TURNS paragraphs: one or two repeated labels are fields (Status:, Comments:). */
|
|
6
|
+
const MIN_SPEAKERS = 3;
|
|
7
|
+
const MIN_TURNS = 3;
|
|
8
|
+
/** The share of the paragraphs the names must open, so a few labelled lines in a report do not make it minutes. */
|
|
9
|
+
const MIN_TURN_SHARE = 0.2;
|
|
10
|
+
|
|
11
|
+
/** A name of up to three words, written at the very start of the paragraph, a colon, then the words said. */
|
|
12
|
+
const TURN = /^(?<name>\p{L}[\p{L}'’.-]*(?: \p{Lu}[\p{L}'’.-]*){0,2}): +\S/u;
|
|
13
|
+
const BLANK_LINES = /\n[ \t\r]*(?:\n[ \t\r]*)+/gu;
|
|
14
|
+
|
|
15
|
+
type Paragraph = { readonly span: Span; readonly name: string | undefined };
|
|
16
|
+
|
|
17
|
+
const paragraphsOf = (source: string): Paragraph[] => {
|
|
18
|
+
const breaks = [...source.matchAll(BLANK_LINES)];
|
|
19
|
+
const starts = [0, ...breaks.map((found) => found.index + found[0].length)];
|
|
20
|
+
const ends = [...breaks.map((found) => found.index), source.length];
|
|
21
|
+
return starts
|
|
22
|
+
.map((start, index) => ({ start, end: ends[index] ?? source.length }))
|
|
23
|
+
.filter(({ start, end }) => source.slice(start, end).trim() !== "")
|
|
24
|
+
.map((span) => ({ span, name: TURN.exec(source.slice(span.start, span.end))?.groups?.["name"] }));
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const turnCounts = (paragraphs: readonly Paragraph[]): Map<string, number> =>
|
|
28
|
+
paragraphs.reduce((counts, { name }) => (name === undefined ? counts : counts.set(name, (counts.get(name) ?? 0) + 1)), new Map<string, number>());
|
|
29
|
+
|
|
30
|
+
/** The spans of the paragraphs a speaker's name opens, when the document reads as minutes of who said what; else none. */
|
|
31
|
+
export const speakerTurns = (source: string): Span[] => {
|
|
32
|
+
const paragraphs = paragraphsOf(source);
|
|
33
|
+
const turns = paragraphs.filter((paragraph) => paragraph.name !== undefined);
|
|
34
|
+
const speakers = [...turnCounts(turns).values()].filter((count) => count >= MIN_TURNS).length;
|
|
35
|
+
if (speakers < MIN_SPEAKERS || turns.length < paragraphs.length * MIN_TURN_SHARE) return [];
|
|
36
|
+
return turns.map((turn) => turn.span);
|
|
37
|
+
};
|
|
@@ -130,3 +130,32 @@ export const isInFileName = (text: string, offset: number, length: number): bool
|
|
|
130
130
|
const run = withoutTrailingMarks(text.slice(start, offset + length + (after < 0 ? rest.length : after)));
|
|
131
131
|
return run.replace(EXTENSION, "").length > length && FILE_OR_URL.test(run);
|
|
132
132
|
};
|
|
133
|
+
|
|
134
|
+
/** The word just before a form, with spaces or an opening quotation mark between (A in “A Coiner). */
|
|
135
|
+
const WORD_BEFORE = /(?<!\p{L})(\p{L}+)[\s"“‘']*$/u;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Whether the one-word form at offset follows an article from the lexicon name-count-article (a, an) and is a dictionary
|
|
139
|
+
* word ("A Coiner, a very good workman" beside Mrs. Coiler): a count noun, not a name.
|
|
140
|
+
*/
|
|
141
|
+
export const isAfterCountArticle = (text: string, offset: number, name: string, articles: readonly string[], isKnown: (word: string) => boolean): boolean => {
|
|
142
|
+
const before = WORD_BEFORE.exec(text.slice(text.lastIndexOf("\n", offset - 1) + 1, offset))?.[1]?.toLowerCase();
|
|
143
|
+
return ONE_WORD.test(name) && before !== undefined && articles.includes(before) && isKnown(name.toLowerCase());
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/** What may stand between a wrong mark and the form it marks: spaces, a colon. */
|
|
147
|
+
const MARK_GAP = /[\s::]/u;
|
|
148
|
+
|
|
149
|
+
const withoutTrailingGap = (text: string): string => {
|
|
150
|
+
const chars = [...text];
|
|
151
|
+
return chars.slice(0, chars.findLastIndex((char) => !MARK_GAP.test(char)) + 1).join("");
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Whether the form at offset follows a wrong mark from the lexicon name-wrong-mark on its own line (× Rspec beside ○ RSpec):
|
|
156
|
+
* a list showing a wrong spelling on purpose, not a use of the name.
|
|
157
|
+
*/
|
|
158
|
+
export const isMarkedWrong = (text: string, offset: number, marks: readonly string[]): boolean => {
|
|
159
|
+
const before = withoutTrailingGap(text.slice(text.lastIndexOf("\n", offset - 1) + 1, offset));
|
|
160
|
+
return marks.some((mark) => before.endsWith(mark));
|
|
161
|
+
};
|
|
@@ -18,13 +18,13 @@ const headBefore = (tokens: readonly Token[], at: number): string => {
|
|
|
18
18
|
.join("");
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
/** Whether the particle at `at`, the words before it and the dictionary form of the word after it spell one of phrases (おそれのある). */
|
|
21
|
+
/** Whether the particle at `at`, the words before it and the dictionary form of the word after it spell one of phrases (おそれのある). A phrase that starts with the particle (のよう) takes any word before it. */
|
|
22
22
|
const isInPhrase = (tokens: readonly Token[], at: number, phrases: readonly string[]): boolean => {
|
|
23
23
|
const [particle, after] = [tokens[at], tokens[at + 1]];
|
|
24
24
|
if (particle === undefined || after === undefined || !touches(particle, after)) return false;
|
|
25
25
|
const tail = `${particle.surface}${after.lemma ?? after.surface}`;
|
|
26
26
|
const head = headBefore(tokens, at);
|
|
27
|
-
return phrases.some((phrase) => phrase.endsWith(tail) &&
|
|
27
|
+
return phrases.some((phrase) => phrase.endsWith(tail) && head.endsWith(phrase.slice(0, -tail.length)));
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
/** The counted particles (particles) of a sentence that stand inside one of phrases, each written whole (おそれのある). */
|
package/src/topic-clause.ts
CHANGED
|
@@ -154,11 +154,17 @@ const subjectBetween = (tokens: readonly Token[], from: number, to: number): boo
|
|
|
154
154
|
|
|
155
155
|
const isPoliteMasu = (token: Token | undefined): boolean => token?.pos === "AUX" && token.lemma === "ます";
|
|
156
156
|
|
|
157
|
-
/**
|
|
157
|
+
/** The auxiliaries a polite predicate may end on after ます: past (ました), negative (ません), negative past (ませんでした). */
|
|
158
|
+
const POLITE_TAILS: readonly (readonly string[])[] = [[], ["た"], ["ん"], ["ん", "でし", "た"]];
|
|
159
|
+
|
|
160
|
+
const endsPolite = (tokens: readonly Token[], at: number, tail: readonly string[]): boolean =>
|
|
161
|
+
isPoliteMasu(tokens[at - tail.length - 1]) &&
|
|
162
|
+
tail.every((surface, index) => tokens[at - tail.length + index]?.pos === "AUX" && tokens[at - tail.length + index]?.surface === surface);
|
|
163
|
+
|
|
164
|
+
/** 〜ておりますが / 〜しましたが / 〜できませんでしたが: a polite predicate and the contrastive が. */
|
|
158
165
|
const isPoliteGa = (tokens: readonly Token[], at: number): boolean => {
|
|
159
166
|
if (tokens[at]?.surface !== "が" || tokens[at]?.pos !== "SCONJ") return false;
|
|
160
|
-
|
|
161
|
-
return isPoliteMasu(before) || (before?.pos === "AUX" && before.surface === "た" && isPoliteMasu(tokens[at - 2]));
|
|
167
|
+
return POLITE_TAILS.some((tail) => endsPolite(tokens, at, tail));
|
|
162
168
|
};
|
|
163
169
|
|
|
164
170
|
const ownGaSubjectBetween = (tokens: readonly Token[], from: number, to: number): boolean =>
|
|
@@ -177,15 +183,21 @@ const newNameTopicRunsToEnd = (tokens: readonly Token[], comma: number, last: nu
|
|
|
177
183
|
return topic > comma + 1 && wa !== undefined && isParticle(wa, "は") && lastOwnSubject(tokens, last) <= topic;
|
|
178
184
|
};
|
|
179
185
|
|
|
186
|
+
/** A topic on the nominaliser こと after a predicate (公表することは): an act made a noun. */
|
|
187
|
+
const isActTopic = (tokens: readonly Token[], topic: number): boolean =>
|
|
188
|
+
tokens[topic - 1]?.surface === "こと" && tokens[topic - 1]?.pos === "NOUN" && PREDICATE.has(tokens[topic - 2]?.pos ?? "");
|
|
189
|
+
|
|
180
190
|
/**
|
|
181
191
|
* 当社は…を営んでおりますが、…の重要性が乏しいため、…の記載は行っておりません: after 〜ますが、 the words up to the next comma
|
|
182
192
|
* say something of a subject of their own (が) and a new topic takes what comes after, so the predicate before が was the
|
|
183
193
|
* topic's, when no other subject stands between the topic and it (需要の停滞がありましたが is not). A clause with no subject of
|
|
184
|
-
* its own there is read to the end, unless a name stands as a new topic straight after the comma (〜ましたが、B大臣は…)
|
|
194
|
+
* its own there is read to the end, unless a name stands as a new topic straight after the comma (〜ましたが、B大臣は…), or the
|
|
195
|
+
* topic is an act made a noun (つまびらかにすることは差し控えますが、…): what is said of an act ends there, and the rest is the
|
|
196
|
+
* speaker's.
|
|
185
197
|
*/
|
|
186
198
|
const closesWithPoliteGa = (tokens: readonly Token[], topic: number, at: number, last: number): boolean => {
|
|
187
199
|
if (!isPoliteGa(tokens, at) || !isComma(tokens[at + 1]) || subjectBetween(tokens, topic, at)) return false;
|
|
188
|
-
if (newNameTopicRunsToEnd(tokens, at + 1, last)) return true;
|
|
200
|
+
if (isActTopic(tokens, topic) || newNameTopicRunsToEnd(tokens, at + 1, last)) return true;
|
|
189
201
|
const comma = tokens.findIndex((token, index) => index > at + 1 && index < last && isComma(token));
|
|
190
202
|
const clauseEnd = comma === -1 ? last : comma;
|
|
191
203
|
return ownGaSubjectBetween(tokens, at + 1, clauseEnd) && newTopicAfter(tokens, clauseEnd, last);
|