chaffjs 0.41.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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/bold-label.d.ts +2 -0
- package/dist/detectors/bold-label.d.ts.map +1 -1
- package/dist/detectors/bold-label.js +4 -0
- package/dist/detectors/bold-label.js.map +1 -1
- package/dist/detectors/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/clause-shape.d.ts +8 -2
- package/dist/detectors/clause-shape.d.ts.map +1 -1
- package/dist/detectors/clause-shape.js +14 -6
- package/dist/detectors/clause-shape.js.map +1 -1
- package/dist/detectors/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/document-shape.d.ts +6 -1
- package/dist/detectors/document-shape.d.ts.map +1 -1
- package/dist/detectors/document-shape.js +14 -4
- package/dist/detectors/document-shape.js.map +1 -1
- package/dist/detectors/doubled-word.d.ts.map +1 -1
- package/dist/detectors/doubled-word.js +5 -1
- package/dist/detectors/doubled-word.js.map +1 -1
- package/dist/detectors/en-shape.d.ts.map +1 -1
- package/dist/detectors/en-shape.js +12 -1
- package/dist/detectors/en-shape.js.map +1 -1
- package/dist/detectors/ending-refrain.d.ts +9 -0
- package/dist/detectors/ending-refrain.d.ts.map +1 -0
- package/dist/detectors/ending-refrain.js +52 -0
- package/dist/detectors/ending-refrain.js.map +1 -0
- package/dist/detectors/fact-consistency.d.ts.map +1 -1
- package/dist/detectors/fact-consistency.js +5 -1
- package/dist/detectors/fact-consistency.js.map +1 -1
- package/dist/detectors/gram-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 +31 -4
- 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/lexicon.d.ts.map +1 -1
- package/dist/detectors/lexicon.js +1 -0
- package/dist/detectors/lexicon.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/lookalike-character.d.ts +2 -0
- package/dist/detectors/lookalike-character.d.ts.map +1 -1
- package/dist/detectors/lookalike-character.js +36 -9
- package/dist/detectors/lookalike-character.js.map +1 -1
- package/dist/detectors/mark-shape.d.ts +1 -1
- package/dist/detectors/mark-shape.d.ts.map +1 -1
- package/dist/detectors/mark-shape.js +29 -12
- package/dist/detectors/mark-shape.js.map +1 -1
- package/dist/detectors/number-style.d.ts +7 -1
- package/dist/detectors/number-style.d.ts.map +1 -1
- package/dist/detectors/number-style.js +21 -1
- package/dist/detectors/number-style.js.map +1 -1
- package/dist/detectors/number-unit.d.ts +7 -1
- package/dist/detectors/number-unit.d.ts.map +1 -1
- package/dist/detectors/number-unit.js +20 -6
- package/dist/detectors/number-unit.js.map +1 -1
- package/dist/detectors/particle-run-long-forms.d.ts +7 -0
- package/dist/detectors/particle-run-long-forms.d.ts.map +1 -0
- package/dist/detectors/particle-run-long-forms.js +23 -0
- package/dist/detectors/particle-run-long-forms.js.map +1 -0
- package/dist/detectors/particle-run-quoted-names.d.ts +6 -0
- package/dist/detectors/particle-run-quoted-names.d.ts.map +1 -0
- package/dist/detectors/particle-run-quoted-names.js +18 -0
- package/dist/detectors/particle-run-quoted-names.js.map +1 -0
- package/dist/detectors/register-separate-part.d.ts +9 -1
- package/dist/detectors/register-separate-part.d.ts.map +1 -1
- package/dist/detectors/register-separate-part.js +23 -0
- package/dist/detectors/register-separate-part.js.map +1 -1
- package/dist/detectors/register-voice.d.ts +4 -3
- package/dist/detectors/register-voice.d.ts.map +1 -1
- package/dist/detectors/register-voice.js +11 -4
- package/dist/detectors/register-voice.js.map +1 -1
- package/dist/detectors/register.d.ts.map +1 -1
- package/dist/detectors/register.js +9 -6
- package/dist/detectors/register.js.map +1 -1
- package/dist/detectors/sentence-ending.d.ts +1 -0
- package/dist/detectors/sentence-ending.d.ts.map +1 -1
- package/dist/detectors/sentence-ending.js +7 -3
- package/dist/detectors/sentence-ending.js.map +1 -1
- package/dist/detectors/signals.d.ts.map +1 -1
- package/dist/detectors/signals.js +21 -6
- package/dist/detectors/signals.js.map +1 -1
- package/dist/detectors/stacked-hedge.d.ts +4 -2
- package/dist/detectors/stacked-hedge.d.ts.map +1 -1
- package/dist/detectors/stacked-hedge.js +16 -3
- package/dist/detectors/stacked-hedge.js.map +1 -1
- package/dist/detectors/token-shape.d.ts.map +1 -1
- package/dist/detectors/token-shape.js +13 -1
- package/dist/detectors/token-shape.js.map +1 -1
- package/dist/detectors/unknown-word-context.d.ts +5 -0
- package/dist/detectors/unknown-word-context.d.ts.map +1 -1
- package/dist/detectors/unknown-word-context.js +8 -0
- package/dist/detectors/unknown-word-context.js.map +1 -1
- package/dist/detectors/unknown-word.d.ts.map +1 -1
- package/dist/detectors/unknown-word.js +3 -3
- package/dist/detectors/unknown-word.js.map +1 -1
- package/dist/detectors/weasel-word.d.ts.map +1 -1
- package/dist/detectors/weasel-word.js +23 -4
- package/dist/detectors/weasel-word.js.map +1 -1
- package/dist/facts/era-year.d.ts +2 -0
- package/dist/facts/era-year.d.ts.map +1 -0
- package/dist/facts/era-year.js +7 -0
- package/dist/facts/era-year.js.map +1 -0
- package/dist/facts/fact-scope.d.ts +1 -1
- package/dist/facts/fact-scope.d.ts.map +1 -1
- package/dist/facts/fact-scope.js +18 -8
- package/dist/facts/fact-scope.js.map +1 -1
- package/dist/facts/table-facts.d.ts.map +1 -1
- package/dist/facts/table-facts.js +18 -2
- package/dist/facts/table-facts.js.map +1 -1
- package/dist/own-title-quote.d.ts +7 -0
- package/dist/own-title-quote.d.ts.map +1 -0
- package/dist/own-title-quote.js +19 -0
- package/dist/own-title-quote.js.map +1 -0
- package/dist/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/definition-use.d.ts.map +1 -1
- package/dist/structure/definition-use.js +3 -1
- package/dist/structure/definition-use.js.map +1 -1
- package/dist/structure-shape/features.d.ts.map +1 -1
- package/dist/structure-shape/features.js +15 -2
- package/dist/structure-shape/features.js.map +1 -1
- package/dist/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/dist/word-use.d.ts.map +1 -1
- package/dist/word-use.js +9 -1
- package/dist/word-use.js.map +1 -1
- package/package.json +3 -3
- package/rules/adverb-overuse.yaml +2 -2
- package/rules/ai-structure.yaml +2 -2
- package/rules/bracket-nesting.yaml +7 -2
- package/rules/bracket-width-consistency.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/doubled-word.yaml +2 -2
- package/rules/excessive-hedging.yaml +2 -1
- package/rules/fact-conflict.yaml +2 -2
- package/rules/lookalike-character.yaml +2 -2
- package/rules/max-kanji-continuous.yaml +4 -3
- package/rules/ngram-repetition.yaml +2 -2
- package/rules/no-doubled-joshi.yaml +2 -2
- package/rules/no-mixed-desumasu.yaml +3 -2
- package/rules/number-style-consistency.yaml +2 -2
- package/rules/number-without-unit.yaml +2 -2
- package/rules/orthographic-variant.yaml +2 -2
- package/rules/repeated-sentence-ending.yaml +2 -2
- package/rules/rule-of-three.yaml +2 -2
- package/rules/title-length.yaml +7 -2
- package/rules/topic-predicate-distance.yaml +2 -2
- package/rules/undefined-acronym.yaml +3 -2
- package/rules/unknown-word.yaml +2 -2
- package/rules/unused-definition.yaml +4 -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/bold-label.ts +6 -0
- package/src/detectors/char-shape.ts +12 -7
- package/src/detectors/clause-shape.ts +14 -12
- 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/document-shape.ts +17 -6
- package/src/detectors/doubled-word.ts +9 -1
- package/src/detectors/en-shape.ts +15 -1
- package/src/detectors/ending-refrain.ts +66 -0
- package/src/detectors/fact-consistency.ts +4 -1
- package/src/detectors/gram-furniture.ts +9 -0
- package/src/detectors/gram-heading.ts +27 -0
- package/src/detectors/gram-predicate.ts +38 -4
- 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/lexicon.ts +1 -0
- package/src/detectors/list-lead-in.ts +36 -3
- package/src/detectors/lookalike-character.ts +40 -10
- package/src/detectors/mark-shape.ts +31 -12
- package/src/detectors/number-style.ts +29 -2
- package/src/detectors/number-unit.ts +29 -8
- package/src/detectors/particle-run-long-forms.ts +34 -0
- package/src/detectors/particle-run-quoted-names.ts +27 -0
- package/src/detectors/register-separate-part.ts +32 -1
- package/src/detectors/register-voice.ts +17 -4
- package/src/detectors/register.ts +9 -6
- package/src/detectors/sentence-ending.ts +10 -4
- package/src/detectors/signals.ts +24 -6
- package/src/detectors/stacked-hedge.ts +24 -7
- package/src/detectors/token-shape.ts +14 -1
- package/src/detectors/unknown-word-context.ts +9 -0
- package/src/detectors/unknown-word.ts +4 -2
- package/src/detectors/weasel-word.ts +31 -5
- package/src/facts/era-year.ts +7 -0
- package/src/facts/fact-scope.ts +20 -6
- package/src/facts/table-facts.ts +31 -3
- package/src/own-title-quote.ts +28 -0
- package/src/rule-of-three.ts +16 -2
- package/src/structure/definition-use.ts +4 -1
- package/src/structure-shape/features.ts +18 -2
- package/src/structure-shape/template-outline.ts +12 -0
- package/src/topic-clause.ts +25 -1
- package/src/word-use.ts +10 -1
|
@@ -18,6 +18,15 @@ export const isClosedCompound = (word: string, speller: Speller): boolean => {
|
|
|
18
18
|
.some((split) => isKnownWord(word.slice(0, split), listed) && isKnownWord(word.slice(split), inflected));
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* A word spelled -nce where the dictionary spells it -nse (recompence, expence, suspence): the older or British spelling of
|
|
23
|
+
* that word, as licence and defence are, not a slip.
|
|
24
|
+
*/
|
|
25
|
+
export const isNceSpelling = (word: string, speller: Speller): boolean => {
|
|
26
|
+
const at = word.lastIndexOf("nce");
|
|
27
|
+
return at > 0 && isKnownWord(`${word.slice(0, at)}nse${word.slice(at + "nce".length)}`, speller);
|
|
28
|
+
};
|
|
29
|
+
|
|
21
30
|
/** Letters a name keeps before its drug stem: fewer, and the word is too short to be read as a drug by its ending alone. */
|
|
22
31
|
const MIN_DRUG_HEAD = 3;
|
|
23
32
|
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
inSearchTermList,
|
|
14
14
|
isClosedCompound,
|
|
15
15
|
isMention,
|
|
16
|
+
isNceSpelling,
|
|
16
17
|
usedOnce,
|
|
17
18
|
} from "./unknown-word-context.ts";
|
|
18
19
|
|
|
@@ -51,8 +52,9 @@ export const codeWordsOf = (source: string): Set<string> => {
|
|
|
51
52
|
return words;
|
|
52
53
|
};
|
|
53
54
|
|
|
54
|
-
/** 辞書の語か、派生した語に活用の語尾を付けた語(operationalises、rightsized)か、四字以上の辞書の語二つを続けた語(crowdwork)。 */
|
|
55
|
-
const isFormedWord = (word: string, speller: Speller): boolean =>
|
|
55
|
+
/** 辞書の語か、派生した語に活用の語尾を付けた語(operationalises、rightsized)か、四字以上の辞書の語二つを続けた語(crowdwork)か、-nse の語の -nce の綴り(recompence)。 */
|
|
56
|
+
const isFormedWord = (word: string, speller: Speller): boolean =>
|
|
57
|
+
isKnownWord(word, speller) || hasTwoEndings(word, speller) || isClosedCompound(word, speller) || isNceSpelling(word, speller);
|
|
56
58
|
|
|
57
59
|
/**
|
|
58
60
|
* 置かれた場所から、名前や用語と分かる語。名指した語("mailto"、(jchaplin))、検索語の並び(vaccin*)、外国語の句(bête noire)、
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { Detector, LexiconEntry, ProseDocument, Sentence } from "../plugin.ts";
|
|
1
|
+
import type { Detector, LexiconEntry, ProseDocument, Sentence, Span } from "../plugin.ts";
|
|
2
2
|
import { entryRanges } from "./lexicon-match.ts";
|
|
3
3
|
import { phraseMatchWhere } from "./phrase-match.ts";
|
|
4
4
|
import { followsToldQuote, type TellingCues } from "./reported-speech.ts";
|
|
5
|
+
import { citationMarks, citationWordsOf, referenceListsOf } from "./citation-marks.ts";
|
|
5
6
|
|
|
6
7
|
const cuesOf = (doc: ProseDocument): TellingCues => {
|
|
7
8
|
const entries = doc.lexicons["telling-cue"] ?? [];
|
|
@@ -9,16 +10,41 @@ const cuesOf = (doc: ProseDocument): TellingCues => {
|
|
|
9
10
|
return { occasion: inGroup("occasion"), sayer: inGroup("sayer") };
|
|
10
11
|
};
|
|
11
12
|
|
|
13
|
+
/** Where the document names its sources: its reference lists, and the in-text citations ([11, 49], Smith (2020)). */
|
|
14
|
+
type Sources = { readonly referenceLists: readonly Span[]; readonly citations: readonly Span[] };
|
|
15
|
+
|
|
16
|
+
const sourcesOf = (doc: ProseDocument): Sources => {
|
|
17
|
+
const words = citationWordsOf(doc);
|
|
18
|
+
const referenceLists = referenceListsOf(doc, words);
|
|
19
|
+
return { referenceLists, citations: citationMarks(doc.prose ?? doc.source, referenceLists, words) };
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const isInside = (spans: readonly Span[], at: number): boolean => spans.some((span) => span.start <= at && at < span.end);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A phrase that names its source: an entry of a reference list (a cited headline, "…, experts say") is the cited work's
|
|
26
|
+
* words, and a citation later in the sentence ("previous studies showing … [11, 49]") says which studies.
|
|
27
|
+
*/
|
|
28
|
+
const namesSource = (sources: Sources, sentence: Sentence, phraseStart: number): boolean =>
|
|
29
|
+
isInside(sources.referenceLists, sentence.span.start) ||
|
|
30
|
+
sources.citations.some((citation) => phraseStart <= citation.start && citation.start < sentence.span.end);
|
|
31
|
+
|
|
12
32
|
/**
|
|
13
33
|
* A weasel phrase counts unless every use of it in the sentence reports a quotation told on a named occasion or by a named
|
|
14
|
-
* sayer (申し込んだら、「…」と言われています). Without tokens the uses cannot be placed, so each one counts.
|
|
34
|
+
* sayer (申し込んだら、「…」と言われています), or names its source. Without tokens the uses cannot be placed, so each one counts.
|
|
15
35
|
*/
|
|
16
|
-
const isWeaselUse = (doc: ProseDocument, sentence: Sentence, entry: LexiconEntry): boolean => {
|
|
36
|
+
const isWeaselUse = (doc: ProseDocument, sources: Sources, sentence: Sentence, entry: LexiconEntry): boolean => {
|
|
17
37
|
const tokens = sentence.tokens ?? [];
|
|
18
38
|
const ranges = entryRanges(sentence, entry);
|
|
19
39
|
if (ranges.length === 0) return true;
|
|
20
40
|
const cues = cuesOf(doc);
|
|
21
|
-
return !ranges.every((range) =>
|
|
41
|
+
return !ranges.every((range) => {
|
|
42
|
+
const start = tokens[range.start]?.span.start ?? sentence.span.start;
|
|
43
|
+
return followsToldQuote(doc.source.slice(sentence.span.start, start), cues) || namesSource(sources, sentence, start);
|
|
44
|
+
});
|
|
22
45
|
};
|
|
23
46
|
|
|
24
|
-
export const weaselWord: Detector = (doc, options) =>
|
|
47
|
+
export const weaselWord: Detector = (doc, options) => {
|
|
48
|
+
const sources = sourcesOf(doc);
|
|
49
|
+
return phraseMatchWhere(doc, options, (sentence, entry) => isWeaselUse(doc, sources, sentence, entry));
|
|
50
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** 元号のすぐ後ろ(空白一つまで)の数。暦の年(平成29年、令和 3 年)で、年数という長さではない。元号は語彙表 calendar-era から。 */
|
|
2
|
+
const ERA_GAP = /[ \t\u3000]?$/u;
|
|
3
|
+
|
|
4
|
+
export const followsEra = (source: string, start: number, eras: readonly string[]): boolean => {
|
|
5
|
+
const head = source.slice(0, start).replace(ERA_GAP, "");
|
|
6
|
+
return eras.some((era) => era !== "" && head.endsWith(era));
|
|
7
|
+
};
|
package/src/facts/fact-scope.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { withoutEdgeMarks } from "./trim-marks.ts";
|
|
|
11
11
|
*/
|
|
12
12
|
export type FactPart = "opening" | "summary" | "body";
|
|
13
13
|
|
|
14
|
-
/** record:
|
|
14
|
+
/** record: 同じ範囲で、行の頭(か行の中の文の切れ目の後ろ)に何度も書かれた名前。催しや論文ごとの記録の欄で、値が違っても食い違いではない。 */
|
|
15
15
|
export type ScopedFact = Fact & { readonly scope: string; readonly part: FactPart; readonly record: boolean };
|
|
16
16
|
|
|
17
17
|
const CONTAINERS: ReadonlySet<string> = new Set(["section", "chapter", "article"]);
|
|
@@ -99,15 +99,29 @@ const partOf = (around: readonly StructureNode[], tree: StructureNode, offset: n
|
|
|
99
99
|
return isOpening(around.at(-1), tree, offset) ? "opening" : "body";
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
-
/**
|
|
102
|
+
/** 行の中の文の切れ目のすぐ後ろ。参考文献の項目は、書誌の文のあとに「External Links: …」と欄を続ける。 */
|
|
103
|
+
const INLINE_LABEL = /[.!?。.!?][ \t]+([^.!?。.!?::|]{1,24})[::]/gu;
|
|
104
|
+
|
|
105
|
+
/** 文の切れ目の後ろから始まる「名前:」の名前。行の頭の名前と同じ書き方に揃える。表の行は読まない。 */
|
|
106
|
+
const inlineLabelsOf = (line: Line): string[] =>
|
|
107
|
+
line.text.trimStart().startsWith("|")
|
|
108
|
+
? []
|
|
109
|
+
: [...line.text.matchAll(INLINE_LABEL)].flatMap((match) => {
|
|
110
|
+
const label = withoutEdgeMarks(match[1] ?? "");
|
|
111
|
+
return /\p{L}/u.test(label) ? [label.normalize("NFKC").toLowerCase()] : [];
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
/** 名前ごとに、その名前の欄を書いた行の番号。欄は行の頭か、行の中の文の切れ目の後ろ。 */
|
|
103
115
|
const headLines = (lines: readonly Line[]): ReadonlyMap<string, readonly number[]> => {
|
|
104
116
|
const found = new Map<string, number[]>();
|
|
105
117
|
lines.forEach((line, index) => {
|
|
106
118
|
const head = headLabelOf(line);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
119
|
+
const labels = new Set([...(head === undefined ? [] : [head]), ...inlineLabelsOf(line)]);
|
|
120
|
+
labels.forEach((label) => {
|
|
121
|
+
const indexes = found.get(label);
|
|
122
|
+
if (indexes === undefined) found.set(label, [index]);
|
|
123
|
+
else indexes.push(index);
|
|
124
|
+
});
|
|
111
125
|
});
|
|
112
126
|
return found;
|
|
113
127
|
};
|
package/src/facts/table-facts.ts
CHANGED
|
@@ -112,17 +112,44 @@ const groupsOf = <T>(items: readonly T[], width: number | undefined): T[][] =>
|
|
|
112
112
|
/** columnGroups: 見出しを繰り返す表を、並びごとに読む(並びの升には columnGroup が付く)。 */
|
|
113
113
|
export type TableReading = { readonly columnGroups?: boolean };
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
/** repeated: 並びの中で二つ以上の行に書いた行の見出し(groupLabelKey)。 */
|
|
116
|
+
type RowReading = {
|
|
117
|
+
readonly values: readonly FactValue[];
|
|
118
|
+
readonly source: string;
|
|
119
|
+
readonly repeated: ReadonlySet<string>;
|
|
120
|
+
readonly totals?: TotalColumns;
|
|
121
|
+
readonly counts?: CountLabelWords;
|
|
122
|
+
};
|
|
116
123
|
|
|
117
124
|
/** 一つの行の升の値。見出しを繰り返す表(width がある)は、並びごとに読んで columnGroup を付ける。 */
|
|
118
125
|
const groupedRowFacts = (row: Line, headings: readonly string[], width: number | undefined, at: RowReading): TableFact[] => {
|
|
119
126
|
const headingGroups = groupsOf(headings, width);
|
|
120
127
|
return groupsOf(cellsOf(row), width).flatMap((cells, group) => {
|
|
121
|
-
const
|
|
128
|
+
const read = rowFacts(cells, headingGroups[group] ?? [], at.values, at.source, at.totals, at.counts);
|
|
129
|
+
const facts = at.repeated.has(groupLabelKey(cells, group)) ? read.map((fact) => withRowCells(fact, cells)) : read;
|
|
122
130
|
return width === undefined ? facts : facts.map((fact) => ({ ...fact, columnGroup: group }));
|
|
123
131
|
});
|
|
124
132
|
};
|
|
125
133
|
|
|
134
|
+
const groupLabelKey = (cells: readonly Cell[], group: number): string => `${String(group)}\u0000${keyOf(plain(cells[0]?.text ?? ""))}`;
|
|
135
|
+
|
|
136
|
+
/** 一つの表の並びごとに、二つ以上の行に書いた行の見出し。 */
|
|
137
|
+
const repeatedRowLabels = (rows: readonly Line[], width: number | undefined): ReadonlySet<string> => {
|
|
138
|
+
const keys = rows.flatMap((row) =>
|
|
139
|
+
groupsOf(cellsOf(row), width).flatMap((cells, group) => (plain(cells[0]?.text ?? "") === "" ? [] : [groupLabelKey(cells, group)])),
|
|
140
|
+
);
|
|
141
|
+
return new Set(keys.filter((key, index) => keys.indexOf(key) !== index));
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 同じ見出しの行が二つある表の升は、ほかの升(行の見出しと自分の升を除く)も名前に入れる。状態や条件の列が違う二つの行
|
|
146
|
+
* (Enabled with at least 1 と at least 2)は別の行で、値の違いは食い違いではない。ほかの升がすべて同じ行どうしだけを比べる。
|
|
147
|
+
*/
|
|
148
|
+
const withRowCells = (fact: TableFact, cells: readonly Cell[]): TableFact => {
|
|
149
|
+
const others = cells.slice(1).filter((cell) => !inside(cell, fact.value));
|
|
150
|
+
return { ...fact, key: [fact.key, ...others.map((cell) => keyOf(plain(cell.text)))].join("\u0000") };
|
|
151
|
+
};
|
|
152
|
+
|
|
126
153
|
/** 文書の表すべての升の値。 */
|
|
127
154
|
export const tableFacts = (
|
|
128
155
|
source: string,
|
|
@@ -134,7 +161,8 @@ export const tableFacts = (
|
|
|
134
161
|
tablesOf(linesOf(source)).flatMap((table) => {
|
|
135
162
|
const headings = cellsOf(table.header).map((cell) => plain(cell.text));
|
|
136
163
|
const width = reading.columnGroups === true ? columnGroupWidth(headings) : undefined;
|
|
137
|
-
const
|
|
164
|
+
const repeated = repeatedRowLabels(table.rows, width);
|
|
165
|
+
const at: RowReading = { values, source, repeated, ...(totals === undefined ? {} : { totals }), ...(counts === undefined ? {} : { counts }) };
|
|
138
166
|
return table.rows.flatMap((row) => groupedRowFacts(row, headings, width, at));
|
|
139
167
|
});
|
|
140
168
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { MarkupHeading, Span } from "./plugin.ts";
|
|
2
|
+
import { escapeRegExp } from "./orthography.ts";
|
|
3
|
+
|
|
4
|
+
// Where a document quotes one of its own headings within a line of other words: an article citing itself
|
|
5
|
+
// (常川真央. Machine-actionable DMPs(maDMPs)の動向. カレントアウェアネス.).
|
|
6
|
+
|
|
7
|
+
/** A heading shorter than this is a word or two (概要, (1)), which the text repeats as a word, not as a quoted title. */
|
|
8
|
+
const MIN_TITLE_LENGTH = 8;
|
|
9
|
+
|
|
10
|
+
/** A line's list marker: a line that holds only one and the heading is a table of contents' entry. */
|
|
11
|
+
const LIST_MARKER = /^(?:[-*+]|\d+\.) /u;
|
|
12
|
+
|
|
13
|
+
const lineAround = (source: string, start: number, end: number): string =>
|
|
14
|
+
source.slice(source.lastIndexOf("\n", start - 1) + 1, source.indexOf("\n", end) === -1 ? source.length : source.indexOf("\n", end));
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The places in `source`, outside the heading itself and outside a line that is only the heading (a table of contents),
|
|
18
|
+
* where the text repeats a heading of MIN_TITLE_LENGTH or more that holds one of `marks`.
|
|
19
|
+
*/
|
|
20
|
+
export const ownTitleQuoteSpans = (source: string, headings: readonly MarkupHeading[], marks: ReadonlySet<string>): Span[] =>
|
|
21
|
+
headings
|
|
22
|
+
.filter((heading) => heading.text.length >= MIN_TITLE_LENGTH && heading.text.split("").some((char) => marks.has(char)))
|
|
23
|
+
.flatMap((heading) =>
|
|
24
|
+
[...source.matchAll(new RegExp(escapeRegExp(heading.text), "gu"))]
|
|
25
|
+
.map((match) => ({ start: match.index, end: match.index + heading.text.length }))
|
|
26
|
+
.filter((span) => span.start < heading.start || span.start >= heading.end)
|
|
27
|
+
.filter((span) => lineAround(source, span.start, span.end).trim().replace(LIST_MARKER, "").trim() !== heading.text),
|
|
28
|
+
);
|
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;
|
|
@@ -61,13 +61,16 @@ const SINGLE_KANJI = /^\p{Script=Han}$/u;
|
|
|
61
61
|
/** loose は最初の一字の大小を問わない(文頭の "Personal data")。exact は書いたとおりだけ("Access" は "early access" に当たらない)。 */
|
|
62
62
|
type CaseMatch = "loose" | "exact";
|
|
63
63
|
|
|
64
|
+
/** 語の間の空白は、続いた空白や改行でもよい(Normal Business\nHours、桁を揃えた写しの Normal Business Hours)。 */
|
|
65
|
+
const spacedLoosely = (escaped: string): string => escaped.replace(/ +/gu, String.raw`\s+`);
|
|
66
|
+
|
|
64
67
|
/**
|
|
65
68
|
* 語の現れを探す形。英字で始まる・終わる語は語の途中に当たらない("Term" は "Terms" には当たり、"Termination" には当たらない)。
|
|
66
69
|
* 複数形と所有の形(Services、Policies、Seller's)は同じ語の使用。
|
|
67
70
|
*/
|
|
68
71
|
const termPattern = (term: string, caseMatch: CaseMatch): RegExp => {
|
|
69
72
|
const first = term.charAt(0);
|
|
70
|
-
const rest = /\p{Ll}y$/u.test(term) ? `${escapeRegExp(term.slice(1, -1))}(?:y|ie)` : escapeRegExp(term.slice(1));
|
|
73
|
+
const rest = spacedLoosely(/\p{Ll}y$/u.test(term) ? `${escapeRegExp(term.slice(1, -1))}(?:y|ie)` : escapeRegExp(term.slice(1)));
|
|
71
74
|
const caseless = caseMatch === "exact" || first.toUpperCase() === first.toLowerCase();
|
|
72
75
|
const head = caseless ? escapeRegExp(first) : `[${escapeRegExp(first.toUpperCase())}${escapeRegExp(first.toLowerCase())}]`;
|
|
73
76
|
if (SINGLE_KANJI.test(term)) return new RegExp(String.raw`(?<!\p{Script=Han})${head}`, "gu");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { lengthOf } from "../measure.ts";
|
|
2
2
|
import type { Lexicon, ProseDocument, Section, Sentence } from "../plugin.ts";
|
|
3
3
|
import { coefficientOfVariation } from "../detectors/structure.ts";
|
|
4
|
-
import { boldLabelItems } from "../detectors/bold-label.ts";
|
|
4
|
+
import { boldLabelItems, isQuotedAt, standingBoldLabelOf } from "../detectors/bold-label.ts";
|
|
5
5
|
import { MIN_DOCUMENT_LENGTH } from "../detectors/signals.ts";
|
|
6
6
|
import { bookendOf, headingFormOf, headingWords, proConPairs } from "./heading-words.ts";
|
|
7
7
|
import { restatementPercent } from "./restatement.ts";
|
|
@@ -165,9 +165,25 @@ const threeItemLists = (doc: ProseDocument): FeatureValue => {
|
|
|
165
165
|
const emojiHeadings = (doc: ProseDocument): FeatureValue =>
|
|
166
166
|
measured("emoji-headings", doc.sections.filter((section) => section.depth > 0 && EMOJI.test(section.heading)).length);
|
|
167
167
|
|
|
168
|
+
/** The paragraphs and list items, as written, that are not quoted: where a bold label can stand in place of a heading. */
|
|
169
|
+
const blocksOf = (doc: ProseDocument): string[] =>
|
|
170
|
+
[...doc.paragraphs.map((paragraph) => paragraph.span), ...doc.lists.flatMap((list) => list.itemSpans)]
|
|
171
|
+
.filter((span) => !isQuotedAt(doc.source, span.start))
|
|
172
|
+
.map((span) => doc.source.slice(span.start, span.end));
|
|
173
|
+
|
|
174
|
+
/** Bold labels that are a side of a pair and nothing more (`**Pros:**`, `**デメリット:**`): a heading set in bold. */
|
|
175
|
+
const proConLabels = (doc: ProseDocument, lexicon: Lexicon): string[] => {
|
|
176
|
+
const sides = new Set(lexicon.flatMap((entry) => [entry.pattern, entry.instead_of ?? ""]).map((side) => side.toLowerCase()));
|
|
177
|
+
return blocksOf(doc).flatMap((block) => {
|
|
178
|
+
const label = standingBoldLabelOf(block);
|
|
179
|
+
return label !== undefined && sides.has(headingWords(label)) ? [headingWords(label)] : [];
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
|
|
168
183
|
const proCon = (doc: ProseDocument, words: readonly string[]): FeatureValue => {
|
|
169
184
|
if (words.length < MIN_BOOKEND_HEADINGS) return notMeasured("pro-con", "too-few-headings");
|
|
170
|
-
const
|
|
185
|
+
const lexicon = lexiconOf(doc, "pro-con-heading");
|
|
186
|
+
const pairs = proConPairs([...words, ...proConLabels(doc, lexicon)], lexicon);
|
|
171
187
|
return measured("pro-con", pairs.length, pairs.join(", "));
|
|
172
188
|
};
|
|
173
189
|
|
|
@@ -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
|
};
|
package/src/word-use.ts
CHANGED
|
@@ -140,9 +140,18 @@ const isCompoundVerbHead = ({ token, following }: InContext): boolean => {
|
|
|
140
140
|
/** A verb written straight onto the verb before it (貼り付ける, 書き込む): the tail of a compound verb, not the verb alone (番号をつける). */
|
|
141
141
|
const isCompoundVerbTail = ({ token, previous }: InContext): boolean => token.pos === "VERB" && previous?.pos === "VERB" && isTouching(previous, token);
|
|
142
142
|
|
|
143
|
+
/**
|
|
144
|
+
* A noun joined by や or と to a noun after it (物やサービス): it names a thing alongside the other, as the full noun does, even
|
|
145
|
+
* where the tokenizer reads it as the dependent noun (延長するもの).
|
|
146
|
+
*/
|
|
147
|
+
const isCoordinatedThing = ({ token, following }: InContext): boolean => {
|
|
148
|
+
const [joiner, partner] = following ?? [];
|
|
149
|
+
return token.pos === "NOUN" && joiner?.pos === "CCONJ" && partner?.pos === "NOUN" && partner.features?.["NounType"] !== "Dependent";
|
|
150
|
+
};
|
|
151
|
+
|
|
143
152
|
/** A word used freely, or as a helper: a bound noun after a word is a suffix, and anything else bound a helper. */
|
|
144
153
|
const helperUseOf = (word: InContext, lightVerbs: ReadonlySet<string>): string => {
|
|
145
|
-
if (!isHelper(word) && !isLightVerbAfterQuotative(word, lightVerbs)) return "free";
|
|
154
|
+
if ((!isHelper(word) && !isLightVerbAfterQuotative(word, lightVerbs)) || isCoordinatedThing(word)) return "free";
|
|
146
155
|
return word.token.pos === "NOUN" && word.token.features?.["NounType"] !== "Dependent" ? "suffix" : "bound";
|
|
147
156
|
};
|
|
148
157
|
|