chaffjs 0.41.0 → 0.42.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/ai-score/human-shares.d.ts.map +1 -1
- package/dist/ai-score/human-shares.js +1 -0
- package/dist/ai-score/human-shares.js.map +1 -1
- package/dist/detectors/acronym-file-type.d.ts +14 -0
- package/dist/detectors/acronym-file-type.d.ts.map +1 -0
- package/dist/detectors/acronym-file-type.js +26 -0
- package/dist/detectors/acronym-file-type.js.map +1 -0
- package/dist/detectors/ai-structure.d.ts +2 -1
- package/dist/detectors/ai-structure.d.ts.map +1 -1
- package/dist/detectors/ai-structure.js +17 -6
- package/dist/detectors/ai-structure.js.map +1 -1
- package/dist/detectors/bibliography-entry.d.ts +3 -0
- package/dist/detectors/bibliography-entry.d.ts.map +1 -0
- package/dist/detectors/bibliography-entry.js +15 -0
- package/dist/detectors/bibliography-entry.js.map +1 -0
- package/dist/detectors/char-shape.d.ts +1 -0
- package/dist/detectors/char-shape.d.ts.map +1 -1
- package/dist/detectors/char-shape.js +13 -8
- package/dist/detectors/char-shape.js.map +1 -1
- package/dist/detectors/closing-cliche.d.ts.map +1 -1
- package/dist/detectors/closing-cliche.js +2 -1
- package/dist/detectors/closing-cliche.js.map +1 -1
- package/dist/detectors/contraction-mention.d.ts +2 -0
- package/dist/detectors/contraction-mention.d.ts.map +1 -1
- package/dist/detectors/contraction-mention.js +5 -2
- package/dist/detectors/contraction-mention.js.map +1 -1
- package/dist/detectors/contraction-mix.d.ts.map +1 -1
- package/dist/detectors/contraction-mix.js +4 -3
- package/dist/detectors/contraction-mix.js.map +1 -1
- package/dist/detectors/counter-edge.d.ts +11 -0
- package/dist/detectors/counter-edge.d.ts.map +1 -1
- package/dist/detectors/counter-edge.js +29 -0
- package/dist/detectors/counter-edge.js.map +1 -1
- package/dist/detectors/gram-furniture.d.ts +1 -0
- package/dist/detectors/gram-furniture.d.ts.map +1 -1
- package/dist/detectors/gram-furniture.js +7 -0
- package/dist/detectors/gram-furniture.js.map +1 -1
- package/dist/detectors/gram-heading.d.ts +9 -0
- package/dist/detectors/gram-heading.d.ts.map +1 -0
- package/dist/detectors/gram-heading.js +20 -0
- package/dist/detectors/gram-heading.js.map +1 -0
- package/dist/detectors/gram-predicate.d.ts.map +1 -1
- package/dist/detectors/gram-predicate.js +19 -1
- package/dist/detectors/gram-predicate.js.map +1 -1
- package/dist/detectors/gram-repetition.d.ts.map +1 -1
- package/dist/detectors/gram-repetition.js +18 -3
- package/dist/detectors/gram-repetition.js.map +1 -1
- package/dist/detectors/gram-spread.d.ts +6 -0
- package/dist/detectors/gram-spread.d.ts.map +1 -0
- package/dist/detectors/gram-spread.js +18 -0
- package/dist/detectors/gram-spread.js.map +1 -0
- package/dist/detectors/kanji-run-pieces.d.ts +4 -0
- package/dist/detectors/kanji-run-pieces.d.ts.map +1 -1
- package/dist/detectors/kanji-run-pieces.js +7 -0
- package/dist/detectors/kanji-run-pieces.js.map +1 -1
- package/dist/detectors/list-lead-in.d.ts +2 -2
- package/dist/detectors/list-lead-in.d.ts.map +1 -1
- package/dist/detectors/list-lead-in.js +28 -3
- package/dist/detectors/list-lead-in.js.map +1 -1
- package/dist/detectors/signals.d.ts.map +1 -1
- package/dist/detectors/signals.js +16 -4
- package/dist/detectors/signals.js.map +1 -1
- package/dist/rule-of-three.d.ts +5 -1
- package/dist/rule-of-three.d.ts.map +1 -1
- package/dist/rule-of-three.js +11 -2
- package/dist/rule-of-three.js.map +1 -1
- package/dist/structure-shape/template-outline.d.ts +7 -0
- package/dist/structure-shape/template-outline.d.ts.map +1 -1
- package/dist/structure-shape/template-outline.js +10 -0
- package/dist/structure-shape/template-outline.js.map +1 -1
- package/dist/topic-clause.d.ts.map +1 -1
- package/dist/topic-clause.js +23 -1
- package/dist/topic-clause.js.map +1 -1
- package/package.json +3 -3
- package/rules/ai-structure.yaml +2 -2
- package/rules/closing-cliche.yaml +3 -3
- package/rules/colon-lead-in.yaml +3 -2
- package/rules/contraction-consistency.yaml +2 -2
- package/rules/max-kanji-continuous.yaml +4 -3
- package/rules/ngram-repetition.yaml +2 -2
- package/rules/rule-of-three.yaml +2 -2
- package/rules/topic-predicate-distance.yaml +2 -2
- package/rules/undefined-acronym.yaml +3 -2
- package/src/ai-score/human-shares.ts +1 -0
- package/src/detectors/acronym-file-type.ts +33 -0
- package/src/detectors/ai-structure.ts +18 -10
- package/src/detectors/bibliography-entry.ts +18 -0
- package/src/detectors/char-shape.ts +12 -7
- package/src/detectors/closing-cliche.ts +6 -1
- package/src/detectors/contraction-mention.ts +6 -2
- package/src/detectors/contraction-mix.ts +5 -3
- package/src/detectors/counter-edge.ts +35 -0
- package/src/detectors/gram-furniture.ts +9 -0
- package/src/detectors/gram-heading.ts +27 -0
- package/src/detectors/gram-predicate.ts +24 -1
- package/src/detectors/gram-repetition.ts +23 -2
- package/src/detectors/gram-spread.ts +19 -0
- package/src/detectors/kanji-run-pieces.ts +10 -0
- package/src/detectors/list-lead-in.ts +36 -3
- package/src/detectors/signals.ts +19 -4
- package/src/rule-of-three.ts +16 -2
- package/src/structure-shape/template-outline.ts +12 -0
- package/src/topic-clause.ts +25 -1
package/src/detectors/signals.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { caseVariantsIn, spelledOutAcronyms, writtenAsWordIn } from "./acronym-m
|
|
|
14
14
|
import { conjugatedForms } from "./conjugated-form.ts";
|
|
15
15
|
import { knownByDocument } from "./acronym-known.ts";
|
|
16
16
|
import { explainedInText, headingsSpellingOut } from "./acronym-gloss.ts";
|
|
17
|
+
import { fileTypeNames, type AcronymUse } from "./acronym-file-type.ts";
|
|
17
18
|
import { nameSpans } from "../team-names.ts";
|
|
18
19
|
import { DASH, introducesList, opensLine } from "./lead-in-dash.ts";
|
|
19
20
|
import type { Detector, Finding, ProseDocument, Sentence } from "../plugin.ts";
|
|
@@ -150,6 +151,14 @@ const acronymsOf = (doc: ProseDocument, notation: NotAcronymSpans): AcronymHit[]
|
|
|
150
151
|
.filter(({ hit }) => !isEmphasised(hit.sentence, hit.offset));
|
|
151
152
|
});
|
|
152
153
|
|
|
154
|
+
/** 略語のすぐ前と後ろの文字列と、後ろに始まる語の品詞。 */
|
|
155
|
+
const fileUseOf = ({ word, hit }: AcronymHit): AcronymUse => {
|
|
156
|
+
const start = hit.offset - hit.sentence.span.start;
|
|
157
|
+
const next = (hit.sentence.tokens ?? []).find((token) => token.span.start >= hit.offset + word.length);
|
|
158
|
+
const { text } = hit.sentence;
|
|
159
|
+
return { word, preceding: text.slice(Math.max(0, start - 2), start), following: text.slice(start + word.length), nextPos: next?.pos };
|
|
160
|
+
};
|
|
161
|
+
|
|
153
162
|
/** 略語ごとの、最初に現れた所。 */
|
|
154
163
|
const firstHits = (hits: readonly AcronymHit[]): Map<string, Hit> => {
|
|
155
164
|
const seen = new Map<string, Hit>();
|
|
@@ -199,6 +208,13 @@ const definitionWordsOf = (doc: ProseDocument): DefinitionWords => {
|
|
|
199
208
|
return { markers: patternsOf(doc, "definition-marker"), verbs: [...verbs, ...conjugatedForms(doc.sentences, verbs)], alternatives };
|
|
200
209
|
};
|
|
201
210
|
|
|
211
|
+
/** 数える略語のすべての所。文書全体で読む書き方の範囲(所在地、文献一覧)と、編と区分で引く法令集(21 CFR subpart J)の中は外す。 */
|
|
212
|
+
const countedHitsOf = (doc: ProseDocument): AcronymHit[] =>
|
|
213
|
+
outsideSpans(acronymsOf(doc, notationOf(doc)), [
|
|
214
|
+
...sourceNotAcronymSpans(doc.source, (id) => patternsOf(doc, id)),
|
|
215
|
+
...titledCodeSpans(doc.source, patternsOf(doc, "citation-series")),
|
|
216
|
+
]);
|
|
217
|
+
|
|
202
218
|
const acronymFinding = (acronym: string, hit: Hit, count: number, limit: number): Finding => ({
|
|
203
219
|
rule: "undefined-acronym",
|
|
204
220
|
severity: "info",
|
|
@@ -240,7 +256,10 @@ export const undefinedAcronym: Detector = (doc, options): Finding[] => {
|
|
|
240
256
|
// 2 つ以上の番号で引く続き物の名前(BCP 78、BCP 14)も、略語の説明と読む。
|
|
241
257
|
// 文献一覧の見出し語([UNIX] The Open Group, "The Single UNIX Specification")と、見出しに番号で立てた書簡の続き物(### SR 26-8: …)も。
|
|
242
258
|
const headings = doc.sections.map((section) => halfWidth(section.heading));
|
|
259
|
+
const counted = countedHitsOf(doc);
|
|
260
|
+
// ファイルの種類の名前としてだけ書いた大文字(the MAP files、MAPファイル)も、展開を待つ略語ではない。
|
|
243
261
|
const entries = new Set([
|
|
262
|
+
...fileTypeNames(counted.map(fileUseOf), patternsOf(doc, "file-noun")),
|
|
244
263
|
...termEntryAcronyms(doc.source),
|
|
245
264
|
...stated,
|
|
246
265
|
...linkedListTerms(doc.source),
|
|
@@ -267,10 +286,6 @@ export const undefinedAcronym: Detector = (doc, options): Finding[] => {
|
|
|
267
286
|
explained.set(word, known);
|
|
268
287
|
return known;
|
|
269
288
|
};
|
|
270
|
-
const counted = outsideSpans(acronymsOf(doc, notationOf(doc)), [
|
|
271
|
-
...sourceNotAcronymSpans(doc.source, (id) => patternsOf(doc, id)),
|
|
272
|
-
...titledCodeSpans(doc.source, patternsOf(doc, "citation-series")),
|
|
273
|
-
]);
|
|
274
289
|
const hits = outsideSpans(
|
|
275
290
|
counted,
|
|
276
291
|
unreportedAcronymSpans(doc.source, doc.sentences, doc.links, (id) => patternsOf(doc, id)),
|
package/src/rule-of-three.ts
CHANGED
|
@@ -4,13 +4,15 @@ import type { BulletList } from "./plugin.ts";
|
|
|
4
4
|
* rule-of-three の数え方。箇条書きのうち、ちょうど 3 項目のものがどれだけあるか。
|
|
5
5
|
* すぐ下の行が「など」「etc.」で始まる箇条書きは、書いた 3 つより多くあると書き手が言っている。ちょうど 3 項目とは数えない。
|
|
6
6
|
* 箇条書きが少ないと、1 つで割合が大きく動く(4 つなら 25 ポイント)。そのときは全部が 3 項目のときだけ報告する。
|
|
7
|
+
* 2 つでも測る。生成文の報告書は「要因 3 つ」「提言 3 つ」の 2 つの箇条書きで終わることが多く、人の文書で 2 つとも 3 項目は少ない。
|
|
8
|
+
* 本文の最初の文より前の箇条書き(題・日付・見出しのすぐ下の要点や概要)は数えない。項目の数はサイトの型が決めている。
|
|
7
9
|
*/
|
|
8
10
|
export type ThreeShare = { readonly count: number; readonly total: number; readonly share: number; readonly first: BulletList };
|
|
9
11
|
|
|
10
12
|
const PERCENT = 100;
|
|
11
13
|
const THREE = 3;
|
|
12
14
|
/** これより少ない箇条書きは測らない。 */
|
|
13
|
-
const MIN_LISTS =
|
|
15
|
+
const MIN_LISTS = 2;
|
|
14
16
|
/** これより少ない箇条書きでは、割合では判断せず、全部が 3 項目のときだけ報告する。 */
|
|
15
17
|
export const MIN_LISTS_FOR_SHARE = 5;
|
|
16
18
|
|
|
@@ -36,11 +38,23 @@ export const continuesBeyond = (source: string, list: BulletList, openWords: rea
|
|
|
36
38
|
return openWords.some((word) => startsWithWord(next, word));
|
|
37
39
|
};
|
|
38
40
|
|
|
41
|
+
/** 見出し・箇条書きの項目・表の行。本文の文ではない。 */
|
|
42
|
+
const NOT_PROSE_LINE = /^\s*(?:#{1,6}\s|[=-]{3,}\s*$|(?:[-*+]|\d+[.)])\s|\|)/u;
|
|
43
|
+
/** 文の終わり(句点・ピリオド・コロン)で閉じる行。閉じ括弧や強調の記号が後ろに付いてもよい。 */
|
|
44
|
+
const SENTENCE_END = /[.。!?!?::][\s"'”’」』))*_]*$/u;
|
|
45
|
+
|
|
46
|
+
const isProseLine = (line: string): boolean => !NOT_PROSE_LINE.test(line) && SENTENCE_END.test(line.trim());
|
|
47
|
+
|
|
48
|
+
/** 本文の最初の文がある行の頭。それより前は題・日付・見出しだけ。文が無ければ文書の終わり。 */
|
|
49
|
+
export const firstProseOffset = (source: string): number => [...source.matchAll(/^.*$/gmu)].find(([line]) => isProseLine(line))?.index ?? source.length;
|
|
50
|
+
|
|
39
51
|
const isExactlyThree = (source: string, list: BulletList, openWords: readonly string[]): boolean =>
|
|
40
52
|
list.items.length === THREE && !continuesBeyond(source, list, openWords);
|
|
41
53
|
|
|
42
54
|
/** 報告するときの数。報告しないときは undefined。 */
|
|
43
|
-
export const threeShare = (source: string,
|
|
55
|
+
export const threeShare = (source: string, allLists: readonly BulletList[], openWords: readonly string[], limit: number): ThreeShare | undefined => {
|
|
56
|
+
const bodyStart = firstProseOffset(source);
|
|
57
|
+
const lists = allLists.filter((list) => list.span.start >= bodyStart);
|
|
44
58
|
const threes = lists.filter((list) => isExactlyThree(source, list, openWords));
|
|
45
59
|
const first = threes[0];
|
|
46
60
|
if (lists.length < MIN_LISTS || first === undefined) return undefined;
|
|
@@ -32,3 +32,15 @@ export const templateSectionsOf = (headings: readonly string[], lexicon: Lexicon
|
|
|
32
32
|
|
|
33
33
|
/** Whether the outline is the template: enough of its sections stand as headings. */
|
|
34
34
|
export const isTemplateOutline = (sections: readonly string[]): boolean => sections.length >= TEMPLATE_SECTIONS;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The share of the headings that must be template sections before the template is the whole outline. A real proposal
|
|
38
|
+
* that uses the template's sections keeps them among headings of its own; a generated one has little else.
|
|
39
|
+
*/
|
|
40
|
+
export const WHOLE_TEMPLATE_SHARE = 0.75;
|
|
41
|
+
|
|
42
|
+
/** Whether the template outline is the whole outline: nearly every heading is one of its sections, the writer's own words nearly absent. */
|
|
43
|
+
export const isWholeTemplateOutline = (headings: readonly string[], lexicon: Lexicon): boolean => {
|
|
44
|
+
const inTemplate = headings.filter((words) => sectionOf(words, lexicon) !== undefined).length;
|
|
45
|
+
return isTemplateOutline(templateSectionsOf(headings, lexicon)) && inTemplate >= headings.length * WHOLE_TEMPLATE_SHARE;
|
|
46
|
+
};
|
package/src/topic-clause.ts
CHANGED
|
@@ -215,6 +215,29 @@ const closesWithItemMark = (tokens: readonly Token[], at: number): boolean => {
|
|
|
215
215
|
return next !== -1 && CIRCLED.test(tokens[next]?.surface ?? "");
|
|
216
216
|
};
|
|
217
217
|
|
|
218
|
+
/** A copula, past or not, just before at: 日本であった, 日本だ, 日本です. */
|
|
219
|
+
const copulaEndsBefore = (tokens: readonly Token[], at: number): boolean => {
|
|
220
|
+
const end = tokens[at - 1]?.surface === "た" && tokens[at - 1]?.pos === "AUX" ? at - 1 : at;
|
|
221
|
+
const before = tokens[end - 1];
|
|
222
|
+
return copulaBefore(tokens, end) || (before?.surface === "だ" && before.lemma === "だ");
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
/** The nominaliser の a cleft's topic stands on (来てほしいのは). */
|
|
226
|
+
const isCleftTopic = (tokens: readonly Token[], topic: number): boolean =>
|
|
227
|
+
tokens[topic - 1]?.surface === "の" && tokens[topic - 1]?.features?.["NounType"] === "Dependent";
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 来てほしいのは…日本であったというような調査の結果、…: a cleft whose focus the copula names, with no subject of its own between,
|
|
231
|
+
* inside a clause that という makes a noun's content, and that noun phrase ends at a comma. The cleft is said within the
|
|
232
|
+
* phrase; the rest of the sentence is about something else. という followed by a comma (〜であるという、…考えです) goes on.
|
|
233
|
+
*/
|
|
234
|
+
const closesCleftInNounPhrase = (tokens: readonly Token[], topic: number, at: number, last: number): boolean => {
|
|
235
|
+
if (tokens[at]?.surface !== "という" || !isCleftTopic(tokens, topic) || !copulaEndsBefore(tokens, at)) return false;
|
|
236
|
+
if (subjectBetween(tokens, topic, at)) return false;
|
|
237
|
+
const comma = tokens.findIndex((token, index) => index > at && index < last && isComma(token));
|
|
238
|
+
return comma > at + 1 && isOwnNoun(tokens[comma - 1]);
|
|
239
|
+
};
|
|
240
|
+
|
|
218
241
|
/**
|
|
219
242
|
* The index of the word that ends the topic's own clause, between the topic and the sentence's last word, or undefined when the
|
|
220
243
|
* topic's predicate is the one the sentence ends on.
|
|
@@ -227,7 +250,8 @@ export const topicClauseEnd = (tokens: readonly Token[], topic: number, last: nu
|
|
|
227
250
|
closesFirstClauseWithNoun(tokens, topic, at, last) ||
|
|
228
251
|
closesWithPoliteGa(tokens, topic, at, last) ||
|
|
229
252
|
closesAfterPredicate(tokens, topic, at, words) ||
|
|
230
|
-
closesWithItemMark(tokens, at)
|
|
253
|
+
closesWithItemMark(tokens, at) ||
|
|
254
|
+
closesCleftInNounPhrase(tokens, topic, at, last);
|
|
231
255
|
const end = tokens.findIndex((_, at) => at > topic && at < last && closes(at));
|
|
232
256
|
return end === -1 ? undefined : end;
|
|
233
257
|
};
|