chaffjs 0.40.0 → 0.41.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/composite-signals.d.ts +6 -0
- package/dist/composite-signals.d.ts.map +1 -0
- package/dist/composite-signals.js +23 -0
- package/dist/composite-signals.js.map +1 -0
- package/dist/detectors/acronym-context.d.ts +4 -0
- package/dist/detectors/acronym-context.d.ts.map +1 -1
- package/dist/detectors/acronym-context.js +45 -0
- package/dist/detectors/acronym-context.js.map +1 -1
- package/dist/detectors/acronym-series.d.ts +5 -0
- package/dist/detectors/acronym-series.d.ts.map +1 -1
- package/dist/detectors/acronym-series.js +18 -3
- package/dist/detectors/acronym-series.js.map +1 -1
- package/dist/detectors/ai-phrasing.d.ts.map +1 -1
- package/dist/detectors/ai-phrasing.js +7 -1
- package/dist/detectors/ai-phrasing.js.map +1 -1
- package/dist/detectors/ai-structure.d.ts.map +1 -1
- package/dist/detectors/ai-structure.js +6 -2
- package/dist/detectors/ai-structure.js.map +1 -1
- package/dist/detectors/contraction-mix.d.ts.map +1 -1
- package/dist/detectors/contraction-mix.js +8 -1
- package/dist/detectors/contraction-mix.js.map +1 -1
- package/dist/detectors/contraction-set-apart.d.ts +14 -0
- package/dist/detectors/contraction-set-apart.d.ts.map +1 -0
- package/dist/detectors/contraction-set-apart.js +42 -0
- package/dist/detectors/contraction-set-apart.js.map +1 -0
- package/dist/detectors/densest-stretch.d.ts +11 -0
- package/dist/detectors/densest-stretch.d.ts.map +1 -0
- package/dist/detectors/densest-stretch.js +14 -0
- package/dist/detectors/densest-stretch.js.map +1 -0
- package/dist/detectors/doubled-word.d.ts.map +1 -1
- package/dist/detectors/doubled-word.js +8 -4
- package/dist/detectors/doubled-word.js.map +1 -1
- package/dist/detectors/fullwidth-alnum.d.ts +3 -0
- package/dist/detectors/fullwidth-alnum.d.ts.map +1 -1
- package/dist/detectors/fullwidth-alnum.js +11 -2
- package/dist/detectors/fullwidth-alnum.js.map +1 -1
- package/dist/detectors/gram-furniture.d.ts +8 -5
- package/dist/detectors/gram-furniture.d.ts.map +1 -1
- package/dist/detectors/gram-furniture.js +23 -13
- package/dist/detectors/gram-furniture.js.map +1 -1
- package/dist/detectors/gram-openers.d.ts +11 -0
- package/dist/detectors/gram-openers.d.ts.map +1 -1
- package/dist/detectors/gram-openers.js +42 -1
- package/dist/detectors/gram-openers.js.map +1 -1
- package/dist/detectors/gram-repetition.d.ts.map +1 -1
- package/dist/detectors/gram-repetition.js +18 -7
- package/dist/detectors/gram-repetition.js.map +1 -1
- package/dist/detectors/known-correction.d.ts.map +1 -1
- package/dist/detectors/known-correction.js +11 -9
- package/dist/detectors/known-correction.js.map +1 -1
- package/dist/detectors/lexicon.d.ts +2 -2
- package/dist/detectors/lexicon.d.ts.map +1 -1
- package/dist/detectors/lexicon.js +15 -5
- package/dist/detectors/lexicon.js.map +1 -1
- package/dist/detectors/list-lead-in.d.ts.map +1 -1
- package/dist/detectors/list-lead-in.js +18 -8
- package/dist/detectors/list-lead-in.js.map +1 -1
- package/dist/detectors/list-run.d.ts.map +1 -1
- package/dist/detectors/list-run.js +16 -2
- package/dist/detectors/list-run.js.map +1 -1
- package/dist/detectors/oxford-comma.d.ts.map +1 -1
- package/dist/detectors/oxford-comma.js +17 -2
- package/dist/detectors/oxford-comma.js.map +1 -1
- package/dist/detectors/phrase-match.d.ts.map +1 -1
- package/dist/detectors/phrase-match.js +3 -2
- package/dist/detectors/phrase-match.js.map +1 -1
- package/dist/detectors/quoted-pattern.d.ts +2 -0
- package/dist/detectors/quoted-pattern.d.ts.map +1 -0
- package/dist/detectors/quoted-pattern.js +13 -0
- package/dist/detectors/quoted-pattern.js.map +1 -0
- package/dist/detectors/reference-entry.d.ts +5 -0
- package/dist/detectors/reference-entry.d.ts.map +1 -1
- package/dist/detectors/reference-entry.js +6 -1
- package/dist/detectors/reference-entry.js.map +1 -1
- package/dist/detectors/relative-pronoun-mix.d.ts.map +1 -1
- package/dist/detectors/relative-pronoun-mix.js +7 -3
- package/dist/detectors/relative-pronoun-mix.js.map +1 -1
- package/dist/detectors/sentence-parts.d.ts +5 -0
- package/dist/detectors/sentence-parts.d.ts.map +1 -1
- package/dist/detectors/sentence-parts.js +8 -0
- package/dist/detectors/sentence-parts.js.map +1 -1
- package/dist/detectors/signals.d.ts.map +1 -1
- package/dist/detectors/signals.js +25 -3
- package/dist/detectors/signals.js.map +1 -1
- package/dist/detectors/superlative-context.d.ts +2 -1
- package/dist/detectors/superlative-context.d.ts.map +1 -1
- package/dist/detectors/superlative-context.js +9 -2
- package/dist/detectors/superlative-context.js.map +1 -1
- package/dist/detectors/title-list.d.ts +7 -0
- package/dist/detectors/title-list.d.ts.map +1 -0
- package/dist/detectors/title-list.js +14 -0
- package/dist/detectors/title-list.js.map +1 -0
- package/dist/detectors/token-shape.d.ts.map +1 -1
- package/dist/detectors/token-shape.js +5 -1
- package/dist/detectors/token-shape.js.map +1 -1
- package/dist/detectors/unknown-word-context.d.ts +2 -0
- package/dist/detectors/unknown-word-context.d.ts.map +1 -1
- package/dist/detectors/unknown-word-context.js +4 -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 +10 -3
- package/dist/detectors/unknown-word.js.map +1 -1
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +4 -2
- package/dist/run.js.map +1 -1
- package/dist/structure-shape/faq-sections.d.ts +7 -0
- package/dist/structure-shape/faq-sections.d.ts.map +1 -0
- package/dist/structure-shape/faq-sections.js +14 -0
- package/dist/structure-shape/faq-sections.js.map +1 -0
- package/dist/structure-shape/features.d.ts.map +1 -1
- package/dist/structure-shape/features.js +5 -3
- package/dist/structure-shape/features.js.map +1 -1
- package/package.json +3 -3
- package/rules/ai-generated-composite.yaml +2 -2
- package/rules/ai-structure.yaml +2 -2
- package/rules/ai-tell.yaml +2 -2
- package/rules/colon-lead-in.yaml +2 -2
- package/rules/contraction-consistency.yaml +4 -2
- package/rules/contrast-framing.yaml +3 -3
- package/rules/fullwidth-alnum-consistency.yaml +2 -2
- package/rules/ngram-repetition.yaml +2 -2
- package/rules/no-doubled-joshi.yaml +2 -2
- package/rules/no-mixed-desumasu.yaml +2 -2
- package/rules/oxford-comma-consistency.yaml +2 -2
- package/rules/undefined-acronym.yaml +4 -2
- package/rules/unknown-word.yaml +2 -2
- package/rules/unqualified-superlative.yaml +1 -1
- package/src/composite-signals.ts +27 -0
- package/src/detectors/acronym-context.ts +58 -0
- package/src/detectors/acronym-series.ts +22 -3
- package/src/detectors/ai-phrasing.ts +7 -1
- package/src/detectors/ai-structure.ts +6 -2
- package/src/detectors/contraction-mix.ts +11 -1
- package/src/detectors/contraction-set-apart.ts +52 -0
- package/src/detectors/densest-stretch.ts +21 -0
- package/src/detectors/doubled-word.ts +10 -10
- package/src/detectors/fullwidth-alnum.ts +19 -3
- package/src/detectors/gram-furniture.ts +27 -13
- package/src/detectors/gram-openers.ts +54 -1
- package/src/detectors/gram-repetition.ts +21 -7
- package/src/detectors/known-correction.ts +15 -8
- package/src/detectors/lexicon.ts +17 -5
- package/src/detectors/list-lead-in.ts +23 -8
- package/src/detectors/list-run.ts +16 -2
- package/src/detectors/oxford-comma.ts +17 -2
- package/src/detectors/phrase-match.ts +3 -2
- package/src/detectors/quoted-pattern.ts +14 -0
- package/src/detectors/reference-entry.ts +8 -1
- package/src/detectors/relative-pronoun-mix.ts +5 -3
- package/src/detectors/sentence-parts.ts +15 -0
- package/src/detectors/signals.ts +28 -3
- package/src/detectors/superlative-context.ts +10 -2
- package/src/detectors/title-list.ts +21 -0
- package/src/detectors/token-shape.ts +20 -16
- package/src/detectors/unknown-word-context.ts +6 -0
- package/src/detectors/unknown-word.ts +10 -2
- package/src/plugin.ts +2 -0
- package/src/run.ts +4 -2
- package/src/structure-shape/faq-sections.ts +24 -0
- package/src/structure-shape/features.ts +5 -3
|
@@ -8,6 +8,7 @@ import { honorificGroupParticles } from "../honorific-group.ts";
|
|
|
8
8
|
import { setPhraseParticles } from "../set-phrase-particles.ts";
|
|
9
9
|
import { noteSentences } from "../note-paragraphs.ts";
|
|
10
10
|
import { documentNameSpans } from "./particle-run-names.ts";
|
|
11
|
+
import { isFlattenedTable } from "./sentence-parts.ts";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* 文末が名詞で終わる(体言止め)。箇条書きでは普通だが、本文では文が途中で切れて読める。
|
|
@@ -117,20 +118,23 @@ export const doubledParticle: Detector = (doc, options): Finding[] => {
|
|
|
117
118
|
setPhrases: (doc.lexicons[SET_PHRASE_LEXICON] ?? []).map((entry) => entry.pattern),
|
|
118
119
|
};
|
|
119
120
|
const prose = doc.prose ?? doc.source;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
121
|
+
// 平らにした表の文は、見出しのセル(役員の兼任等・営業上の取引・設備の賃貸借)の切れ目が見えず、別のセルの「の」が一つの連なりに見える。
|
|
122
|
+
return doc.sentences
|
|
123
|
+
.filter((sentence) => !isFlattenedTable(sentence.text))
|
|
124
|
+
.flatMap((sentence) => {
|
|
125
|
+
const tokens = chainTokens(sentence.tokens ?? [], numbering, phrases);
|
|
126
|
+
const quoted = [...quotedIn(sentence), ...titles];
|
|
127
|
+
const longRuns = (skipped: readonly Span[]): Run[] => runsOf(tokens, nesting, breaks, skipped).filter((run) => run.tokens.length > options.limit);
|
|
128
|
+
const found = longRuns(quoted);
|
|
129
|
+
// 文書の名前を読むのは長い連なりのある文だけ。名前は位置ごとに読むので、全部の文で読むと遅い。
|
|
130
|
+
const runs = found.length === 0 ? found : longRuns([...quoted, ...documentNameSpans(prose, sentence.span, doc.namedDocument)]);
|
|
131
|
+
return runs.map((run) => ({
|
|
132
|
+
rule: "no-doubled-joshi",
|
|
133
|
+
severity: "warning" as const,
|
|
134
|
+
line: 0,
|
|
135
|
+
column: 0,
|
|
136
|
+
quote: sentence.text.trim(),
|
|
137
|
+
values: { word: run.surface, count: run.tokens.length, limit: options.limit, offset: run.tokens[0]?.span.start ?? sentence.span.start },
|
|
138
|
+
}));
|
|
139
|
+
});
|
|
136
140
|
};
|
|
@@ -117,6 +117,12 @@ const VERSION_AFTER = /^[ \t]+v?\d+\.\d+\.\d+/u;
|
|
|
117
117
|
/** The word names what a release number follows (golang 1.21.5): a product or a tool, written as its makers write it. */
|
|
118
118
|
export const beforeVersion = (source: string, offset: number, word: string): boolean => VERSION_AFTER.test(source.slice(offset + word.length));
|
|
119
119
|
|
|
120
|
+
/** A journal's volume and issue (22 (3), 5(2)), after spaces. */
|
|
121
|
+
const VOLUME_AFTER = /^[ \t]+\d+[ \t]*\(\d+\)/u;
|
|
122
|
+
|
|
123
|
+
/** The word ends a journal's title before its volume and issue (Biochemia medica 22 (3)): the title as the journal writes it, often Latin. */
|
|
124
|
+
export const beforeVolume = (source: string, offset: number, word: string): boolean => VOLUME_AFTER.test(source.slice(offset + word.length));
|
|
125
|
+
|
|
120
126
|
/** Two words of one length that differ in one letter only. */
|
|
121
127
|
const oneLetterApart = (left: string, right: string): boolean =>
|
|
122
128
|
left.length === right.length && [...left].filter((letter, index) => letter !== right.charAt(index)).length === 1;
|
|
@@ -6,6 +6,7 @@ import { quoteAt } from "./structure-tree.ts";
|
|
|
6
6
|
import {
|
|
7
7
|
addressWordsOf,
|
|
8
8
|
beforeVersion,
|
|
9
|
+
beforeVolume,
|
|
9
10
|
besideForeignWord,
|
|
10
11
|
hasDrugStem,
|
|
11
12
|
hasSiblingName,
|
|
@@ -53,9 +54,16 @@ export const codeWordsOf = (source: string): Set<string> => {
|
|
|
53
54
|
/** 辞書の語か、派生した語に活用の語尾を付けた語(operationalises、rightsized)か、四字以上の辞書の語二つを続けた語(crowdwork)。 */
|
|
54
55
|
const isFormedWord = (word: string, speller: Speller): boolean => isKnownWord(word, speller) || hasTwoEndings(word, speller) || isClosedCompound(word, speller);
|
|
55
56
|
|
|
56
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* 置かれた場所から、名前や用語と分かる語。名指した語("mailto"、(jchaplin))、検索語の並び(vaccin*)、外国語の句(bête noire)、
|
|
59
|
+
* 版の番号の前(golang 1.21.5)、誌の巻と号の前(Biochemia medica 22 (3))。
|
|
60
|
+
*/
|
|
57
61
|
const isTermByPlace = (source: string, offset: number, word: string): boolean =>
|
|
58
|
-
isMention(source, offset, word) ||
|
|
62
|
+
isMention(source, offset, word) ||
|
|
63
|
+
inSearchTermList(source, offset) ||
|
|
64
|
+
besideForeignWord(source, offset, word) ||
|
|
65
|
+
beforeVersion(source, offset, word) ||
|
|
66
|
+
beforeVolume(source, offset, word);
|
|
59
67
|
|
|
60
68
|
/**
|
|
61
69
|
* 辞書に無い英語の語で、一字違いの辞書の語があるもの(recieve → receive)。辞書は adapter が持ち、無い言語では動かない。
|
package/src/plugin.ts
CHANGED
|
@@ -75,6 +75,8 @@ export type LexiconEntry = {
|
|
|
75
75
|
readonly first_year?: number | undefined;
|
|
76
76
|
/** The genres or groups the entry holds in (legal, blog/tech). Without them, every genre. A detector reads them with entriesForGenre. */
|
|
77
77
|
readonly genres?: readonly string[] | undefined;
|
|
78
|
+
/** The entry counts only in a heading: a title phrase that body text uses plainly. A detector that reads headings honours it. */
|
|
79
|
+
readonly heading_only?: boolean | undefined;
|
|
78
80
|
/** pattern を adapter が語に分けたもの。品詞が読めるときだけ core が入れる。語彙表を書く側は書かない。 */
|
|
79
81
|
readonly tokens?: readonly Token[] | undefined;
|
|
80
82
|
};
|
package/src/run.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { PatternTimeout } from "./custom/pattern-timeout.ts";
|
|
|
19
19
|
import { PluginRuleFailure } from "./extension/module-detector.ts";
|
|
20
20
|
import { failureReason } from "./extension/failure-text.ts";
|
|
21
21
|
import { tagCoverage } from "./tag-coverage.ts";
|
|
22
|
+
import { compositeSignals } from "./composite-signals.ts";
|
|
22
23
|
|
|
23
24
|
export type Skipped = {
|
|
24
25
|
readonly rule: string;
|
|
@@ -210,9 +211,10 @@ export const place = (starts: readonly number[], finding: Finding): Finding => {
|
|
|
210
211
|
* まとめるために消すと本物の指摘が見えなくなる。
|
|
211
212
|
*/
|
|
212
213
|
const compositeOf = (rule: RuleDefinition, found: readonly Finding[], limit: number, starts: readonly number[], language: string): Finding[] => {
|
|
213
|
-
const fired = rule.from
|
|
214
|
+
const fired = compositeSignals(rule.from, found);
|
|
214
215
|
if (fired.length < limit) return [];
|
|
215
|
-
|
|
216
|
+
// 数えなかった signal も含めて、最初に出た所に置く。同じ形を 1 種に数えても、指摘の位置は動かない。
|
|
217
|
+
const first = found.find((finding) => rule.from.includes(finding.rule));
|
|
216
218
|
return [
|
|
217
219
|
place(starts, {
|
|
218
220
|
rule: rule.id,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Lexicon, Section } from "../plugin.ts";
|
|
2
|
+
import { containsWord, headingWords } from "./heading-words.ts";
|
|
3
|
+
|
|
4
|
+
/** A heading still open at a point of the outline: its depth, and whether it is a question-and-answer heading. */
|
|
5
|
+
type Open = { readonly depth: number; readonly faq: boolean };
|
|
6
|
+
|
|
7
|
+
const isFaqHeading = (heading: string, faqHeadings: Lexicon): boolean =>
|
|
8
|
+
faqHeadings.some((entry) => containsWord(headingWords(heading), entry.pattern.toLowerCase()));
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Whether each section stands under a question-and-answer heading (FAQ, よくある質問), at any depth below it. An FAQ's
|
|
12
|
+
* headings are its readers' questions, so the form they take is not the writer's.
|
|
13
|
+
*/
|
|
14
|
+
export const underFaq = (headed: readonly Section[], faqHeadings: Lexicon): boolean[] =>
|
|
15
|
+
headed
|
|
16
|
+
.reduce<{ readonly open: readonly Open[]; readonly under: readonly boolean[] }>(
|
|
17
|
+
(outline, section) => {
|
|
18
|
+
const ancestors = outline.open.filter((open) => open.depth < section.depth);
|
|
19
|
+
const faq = isFaqHeading(section.heading, faqHeadings);
|
|
20
|
+
return { open: [...ancestors, { depth: section.depth, faq }], under: [...outline.under, ancestors.some((open) => open.faq)] };
|
|
21
|
+
},
|
|
22
|
+
{ open: [], under: [] },
|
|
23
|
+
)
|
|
24
|
+
.under.slice();
|
|
@@ -5,6 +5,7 @@ import { boldLabelItems } 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";
|
|
8
|
+
import { underFaq } from "./faq-sections.ts";
|
|
8
9
|
|
|
9
10
|
/** The structure measures, in the order they are shown. */
|
|
10
11
|
export const FEATURE_IDS = [
|
|
@@ -116,9 +117,10 @@ const mostCommon = (forms: readonly string[]): string | undefined => {
|
|
|
116
117
|
return [...counts.entries()].toSorted((left, right) => right[1] - left[1])[0]?.[0];
|
|
117
118
|
};
|
|
118
119
|
|
|
119
|
-
const headingForms = (doc: ProseDocument, words: readonly string[]): FeatureValue => {
|
|
120
|
+
const headingForms = (doc: ProseDocument, headed: readonly Section[], words: readonly string[]): FeatureValue => {
|
|
120
121
|
const bookends = lexiconOf(doc, "bookend-heading");
|
|
121
|
-
const
|
|
122
|
+
const asked = underFaq(headed, lexiconOf(doc, "faq-heading"));
|
|
123
|
+
const body = words.filter((heading, index) => asked[index] !== true && bookendOf(heading, bookends) === undefined);
|
|
122
124
|
if (body.length < MIN_HEADINGS) return notMeasured("heading-forms", "too-few-headings");
|
|
123
125
|
const forms = body.flatMap((heading) => headingFormOf(heading, lexiconOf(doc, "heading-form"))?.pattern ?? []);
|
|
124
126
|
return measured("heading-forms", percentOf(forms.length, body.length), mostCommon(forms));
|
|
@@ -177,7 +179,7 @@ export const structureFeaturesOf = (doc: ProseDocument): FeatureValue[] => {
|
|
|
177
179
|
headingDensity(doc, headed),
|
|
178
180
|
shortSections(doc, headed),
|
|
179
181
|
sectionUniformity(doc),
|
|
180
|
-
headingForms(doc, words),
|
|
182
|
+
headingForms(doc, headed, words),
|
|
181
183
|
threeSubsections(headed),
|
|
182
184
|
bookends(doc, words),
|
|
183
185
|
closingRestatement(doc, headed),
|