chaffjs 0.44.0 → 0.45.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/detectors/abstract-length.d.ts +5 -1
- package/dist/detectors/abstract-length.d.ts.map +1 -1
- package/dist/detectors/abstract-length.js +13 -5
- package/dist/detectors/abstract-length.js.map +1 -1
- package/dist/detectors/adversative-ga.d.ts +1 -1
- package/dist/detectors/adversative-ga.d.ts.map +1 -1
- package/dist/detectors/adversative-ga.js +19 -2
- package/dist/detectors/adversative-ga.js.map +1 -1
- package/dist/detectors/bold-label.d.ts.map +1 -1
- package/dist/detectors/bold-label.js +56 -15
- package/dist/detectors/bold-label.js.map +1 -1
- package/dist/detectors/char-shape.d.ts +0 -6
- package/dist/detectors/char-shape.d.ts.map +1 -1
- package/dist/detectors/char-shape.js +4 -21
- package/dist/detectors/char-shape.js.map +1 -1
- package/dist/detectors/clause-shape.d.ts +2 -0
- package/dist/detectors/clause-shape.d.ts.map +1 -1
- package/dist/detectors/clause-shape.js +11 -2
- package/dist/detectors/clause-shape.js.map +1 -1
- package/dist/detectors/cleft-focus.d.ts +4 -0
- package/dist/detectors/cleft-focus.d.ts.map +1 -0
- package/dist/detectors/cleft-focus.js +31 -0
- package/dist/detectors/cleft-focus.js.map +1 -0
- package/dist/detectors/definition-use.d.ts.map +1 -1
- package/dist/detectors/definition-use.js +13 -3
- package/dist/detectors/definition-use.js.map +1 -1
- package/dist/detectors/empty-section.d.ts +1 -1
- package/dist/detectors/empty-section.d.ts.map +1 -1
- package/dist/detectors/empty-section.js +3 -2
- package/dist/detectors/empty-section.js.map +1 -1
- package/dist/detectors/fullwidth-alnum.d.ts +2 -2
- package/dist/detectors/fullwidth-alnum.d.ts.map +1 -1
- package/dist/detectors/fullwidth-alnum.js +19 -3
- package/dist/detectors/fullwidth-alnum.js.map +1 -1
- package/dist/detectors/heading-echo.d.ts.map +1 -1
- package/dist/detectors/heading-echo.js +20 -7
- package/dist/detectors/heading-echo.js.map +1 -1
- package/dist/detectors/heading-number.d.ts +7 -0
- package/dist/detectors/heading-number.d.ts.map +1 -0
- package/dist/detectors/heading-number.js +21 -0
- package/dist/detectors/heading-number.js.map +1 -0
- package/dist/detectors/lookalike-character.d.ts +2 -1
- package/dist/detectors/lookalike-character.d.ts.map +1 -1
- package/dist/detectors/lookalike-character.js +14 -1
- package/dist/detectors/lookalike-character.js.map +1 -1
- package/dist/detectors/mark-shape.d.ts +6 -1
- package/dist/detectors/mark-shape.d.ts.map +1 -1
- package/dist/detectors/mark-shape.js +31 -11
- package/dist/detectors/mark-shape.js.map +1 -1
- package/dist/detectors/middle-dot.d.ts +7 -0
- package/dist/detectors/middle-dot.d.ts.map +1 -1
- package/dist/detectors/middle-dot.js +19 -0
- package/dist/detectors/middle-dot.js.map +1 -1
- package/dist/detectors/named-by-context.d.ts +13 -0
- package/dist/detectors/named-by-context.d.ts.map +1 -0
- package/dist/detectors/named-by-context.js +10 -0
- package/dist/detectors/named-by-context.js.map +1 -0
- package/dist/detectors/placeholder-context.d.ts +16 -0
- package/dist/detectors/placeholder-context.d.ts.map +1 -0
- package/dist/detectors/placeholder-context.js +57 -0
- package/dist/detectors/placeholder-context.js.map +1 -0
- package/dist/detectors/placeholder-text.d.ts +2 -0
- package/dist/detectors/placeholder-text.d.ts.map +1 -1
- package/dist/detectors/placeholder-text.js +1 -1
- package/dist/detectors/placeholder-text.js.map +1 -1
- package/dist/detectors/registry/middle-dot.js +1 -1
- package/dist/detectors/sentence-counts.d.ts +2 -0
- package/dist/detectors/sentence-counts.d.ts.map +1 -1
- package/dist/detectors/sentence-counts.js +13 -4
- package/dist/detectors/sentence-counts.js.map +1 -1
- package/dist/detectors/signals.d.ts.map +1 -1
- package/dist/detectors/signals.js +10 -1
- package/dist/detectors/signals.js.map +1 -1
- package/dist/detectors/structure.d.ts.map +1 -1
- package/dist/detectors/structure.js +3 -2
- package/dist/detectors/structure.js.map +1 -1
- package/dist/detectors/template-sections.d.ts +1 -0
- package/dist/detectors/template-sections.d.ts.map +1 -1
- package/dist/detectors/template-sections.js +1 -1
- package/dist/detectors/template-sections.js.map +1 -1
- package/dist/detectors/unfilled-placeholder.d.ts.map +1 -1
- package/dist/detectors/unfilled-placeholder.js +18 -1
- package/dist/detectors/unfilled-placeholder.js.map +1 -1
- package/dist/detectors/verse-block.d.ts +4 -0
- package/dist/detectors/verse-block.d.ts.map +1 -0
- package/dist/detectors/verse-block.js +40 -0
- package/dist/detectors/verse-block.js.map +1 -0
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +1 -0
- package/dist/document.js.map +1 -1
- package/dist/email-parts.d.ts +2 -0
- package/dist/email-parts.d.ts.map +1 -1
- package/dist/email-parts.js +10 -7
- package/dist/email-parts.js.map +1 -1
- package/dist/eval.d.ts.map +1 -1
- package/dist/eval.js +3 -0
- package/dist/eval.js.map +1 -1
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/reasons.d.ts +2 -0
- package/dist/reasons.d.ts.map +1 -1
- package/dist/reasons.js +2 -0
- package/dist/reasons.js.map +1 -1
- package/dist/rule-of-three.d.ts +7 -2
- package/dist/rule-of-three.d.ts.map +1 -1
- package/dist/rule-of-three.js +11 -3
- package/dist/rule-of-three.js.map +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +4 -1
- package/dist/run.js.map +1 -1
- package/dist/structure/cited-elsewhere.d.ts +5 -2
- package/dist/structure/cited-elsewhere.d.ts.map +1 -1
- package/dist/structure/cited-elsewhere.js +16 -6
- package/dist/structure/cited-elsewhere.js.map +1 -1
- package/dist/structure/definition-use.d.ts +2 -1
- package/dist/structure/definition-use.d.ts.map +1 -1
- package/dist/structure/definition-use.js +10 -2
- package/dist/structure/definition-use.js.map +1 -1
- package/dist/structure/issues.js +1 -1
- package/dist/structure/issues.js.map +1 -1
- package/package.json +3 -3
- package/rules/abstract-length.yaml +2 -2
- package/rules/adversative-ga-repeat.yaml +2 -2
- package/rules/attachment-not-attached.yaml +11 -6
- package/rules/bold-label-list.yaml +22 -6
- package/rules/bracket-width-consistency.yaml +2 -2
- package/rules/demonstrative-opener-run.yaml +2 -2
- package/rules/emoji-density.yaml +2 -2
- package/rules/empty-section.yaml +2 -2
- package/rules/fullwidth-alnum-consistency.yaml +2 -2
- package/rules/lookalike-character.yaml +8 -5
- package/rules/max-kanji-continuous.yaml +4 -0
- package/rules/paragraph-length-variance.yaml +27 -3
- package/rules/repeated-sentence-ending.yaml +2 -2
- package/rules/rule-of-three.yaml +2 -2
- package/rules/sentence-spacing-consistency.yaml +2 -2
- package/rules/teki-overuse.yaml +2 -0
- package/rules/unfilled-placeholder.yaml +2 -2
- package/rules/use-before-definition.yaml +2 -2
- package/src/detectors/abstract-length.ts +16 -6
- package/src/detectors/adversative-ga.ts +24 -2
- package/src/detectors/bold-label.ts +63 -16
- package/src/detectors/char-shape.ts +8 -22
- package/src/detectors/clause-shape.ts +14 -3
- package/src/detectors/cleft-focus.ts +40 -0
- package/src/detectors/definition-use.ts +23 -4
- package/src/detectors/empty-section.ts +3 -2
- package/src/detectors/fullwidth-alnum.ts +24 -3
- package/src/detectors/heading-echo.ts +21 -8
- package/src/detectors/heading-number.ts +20 -0
- package/src/detectors/lookalike-character.ts +19 -2
- package/src/detectors/mark-shape.ts +33 -6
- package/src/detectors/middle-dot.ts +22 -0
- package/src/detectors/named-by-context.ts +15 -0
- package/src/detectors/placeholder-context.ts +72 -0
- package/src/detectors/placeholder-text.ts +1 -1
- package/src/detectors/registry/middle-dot.ts +1 -1
- package/src/detectors/sentence-counts.ts +16 -4
- package/src/detectors/signals.ts +11 -1
- package/src/detectors/structure.ts +3 -2
- package/src/detectors/template-sections.ts +1 -1
- package/src/detectors/unfilled-placeholder.ts +22 -1
- package/src/detectors/verse-block.ts +48 -0
- package/src/document.ts +1 -0
- package/src/email-parts.ts +16 -7
- package/src/eval.ts +2 -0
- package/src/plugin.ts +2 -0
- package/src/reasons.ts +4 -0
- package/src/rule-of-three.ts +22 -5
- package/src/run.ts +3 -1
- package/src/structure/cited-elsewhere.ts +18 -6
- package/src/structure/definition-use.ts +10 -1
- package/src/structure/issues.ts +1 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Lexicon } from "../plugin.ts";
|
|
2
|
+
import { holdsWordAt } from "./template-sections.ts";
|
|
3
|
+
|
|
4
|
+
/** Lexicon group of placeholder-word: a word that opens a line giving an example to copy (Example:, Helpful:, 例:). */
|
|
5
|
+
export const EXAMPLE_LEAD = "example-lead";
|
|
6
|
+
|
|
7
|
+
/** The text of a blank's line before it and after it. */
|
|
8
|
+
export type LineAround = { readonly before: string; readonly after: string };
|
|
9
|
+
|
|
10
|
+
export const lineAround = (source: string, start: number, end: number): LineAround => ({
|
|
11
|
+
before: source.slice(source.lastIndexOf("\n", start - 1) + 1, start),
|
|
12
|
+
after: source.slice(end).split("\n")[0] ?? "",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
/** A run of underscores is the line a form is signed or filled on; a bracket beside it is the caption of that line. */
|
|
16
|
+
const FILL_LINE = "___";
|
|
17
|
+
const SPACE_OR_EMPHASIS = /[\s*]/u;
|
|
18
|
+
|
|
19
|
+
/** text without the spaces and emphasis marks around it. */
|
|
20
|
+
const bare = (text: string): string => {
|
|
21
|
+
const chars = [...text];
|
|
22
|
+
const first = chars.findIndex((char) => !SPACE_OR_EMPHASIS.test(char));
|
|
23
|
+
const last = chars.findLastIndex((char) => !SPACE_OR_EMPHASIS.test(char));
|
|
24
|
+
return first < 0 ? "" : chars.slice(first, last + 1).join("");
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** The bracket names the blank a form leaves to fill by hand ("________ [Name of New Employer]"). */
|
|
28
|
+
export const captionsFillLine = (line: LineAround): boolean => bare(line.before).endsWith(FILL_LINE) || bare(line.after).startsWith(FILL_LINE);
|
|
29
|
+
|
|
30
|
+
/** A list mark or emphasis before the line's first word. */
|
|
31
|
+
const LINE_LEAD = /^\s*(?:[-*+]\s+|\d+[.)]\s+)?[*_]*/u;
|
|
32
|
+
const COLONS = /[::]/u;
|
|
33
|
+
const OPENING_QUOTES: ReadonlySet<string> = new Set(["“", '"', "「", "『"]);
|
|
34
|
+
const CLOSING_QUOTES = /[”"」』]/u;
|
|
35
|
+
|
|
36
|
+
/** After the lead: a colon, then a quotation that opens and has not closed yet before the blank. */
|
|
37
|
+
const opensQuoteAfterColon = (rest: string): boolean => {
|
|
38
|
+
const colon = rest.search(COLONS);
|
|
39
|
+
if (colon < 0) return false;
|
|
40
|
+
const quoted = rest.slice(colon + 1).trimStart();
|
|
41
|
+
return OPENING_QUOTES.has(quoted.charAt(0)) && !CLOSING_QUOTES.test(quoted.slice(1));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** The blank is inside a quotation a line offers as an example ("Helpful: “See the link [insert link name] …”"). */
|
|
45
|
+
export const insideQuotedExample = (line: LineAround, leads: Lexicon): boolean => {
|
|
46
|
+
const text = line.before.slice(LINE_LEAD.exec(line.before)?.[0].length ?? 0);
|
|
47
|
+
const lower = text.toLowerCase();
|
|
48
|
+
const lead = leads.find((word) => lower.startsWith(word.pattern.toLowerCase()) && holdsWordAt(lower, word.pattern.toLowerCase(), 0));
|
|
49
|
+
return lead !== undefined && opensQuoteAfterColon(text.slice(lead.pattern.length));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/** A field label of a filing form at the head of a line, and the value written after it on that line (【氏名】 followed by a name). */
|
|
53
|
+
const LIST_MARK = /^\s*(?:[-*+]\s+)?/u;
|
|
54
|
+
const FIELD_LABEL = /^(?:【[^【】\n]{1,30}】|[[^[]\n]{1,30}])/u;
|
|
55
|
+
const LEADING_SPACES = /^[ \t\u3000]+/u;
|
|
56
|
+
const VALUE_START = /^[\p{Script=Han}\p{Script=Katakana}\p{Script=Latin}\p{N}]/u;
|
|
57
|
+
const BLANK_MARK_START = /^[○〇◯△]/u;
|
|
58
|
+
|
|
59
|
+
const isFilledValue = (value: string, blankSuffixes: Lexicon): boolean =>
|
|
60
|
+
VALUE_START.test(value) && !BLANK_MARK_START.test(value) && !blankSuffixes.some((word) => value.startsWith(word.pattern));
|
|
61
|
+
|
|
62
|
+
/** The label at the head of a line, when a filled value follows it on that line. */
|
|
63
|
+
const filledLabelOf = (line: string, blankSuffixes: Lexicon): string[] => {
|
|
64
|
+
const rest = line.replace(LIST_MARK, "");
|
|
65
|
+
const label = FIELD_LABEL.exec(rest)?.[0];
|
|
66
|
+
if (label === undefined) return [];
|
|
67
|
+
return isFilledValue(rest.slice(label.length).replace(LEADING_SPACES, ""), blankSuffixes) ? [label] : [];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/** The labels a document fills in somewhere: elsewhere the same 【氏名】 names that field of the form, not a blank. */
|
|
71
|
+
export const filledFieldLabels = (source: string, blankSuffixes: Lexicon): ReadonlySet<string> =>
|
|
72
|
+
new Set(source.split("\n").flatMap((line) => filledLabelOf(line, blankSuffixes)));
|
|
@@ -87,7 +87,7 @@ const lineMarkerSpans = (text: string, markers: Lexicon, labels: Lexicon): Span[
|
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
/** Lexicon groups of placeholder-word for a run of blank marks (〇〇): the word after it, the word before it, and a unit after it. */
|
|
90
|
-
const BLANK_SUFFIX = "blank-suffix";
|
|
90
|
+
export const BLANK_SUFFIX = "blank-suffix";
|
|
91
91
|
const BLANK_PREFIX = "blank-prefix";
|
|
92
92
|
const BLANK_UNIT = "blank-unit";
|
|
93
93
|
|
|
@@ -196,7 +196,17 @@ export const openerRuns = (sentences: readonly Sentence[], lexicon: Lexicon, not
|
|
|
196
196
|
)
|
|
197
197
|
.filter((run) => run.length > 0);
|
|
198
198
|
|
|
199
|
-
|
|
199
|
+
/** The opening words that, repeated at the head of the next sentence, carry the same subject on (It … It …). */
|
|
200
|
+
export const CONTINUING_LEXICON = "demonstrative-continuing";
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* How many sentences of the run send the reader back: a sentence opening with the same continuing word as the one before
|
|
204
|
+
* keeps that sentence's subject, so a chain of them counts once.
|
|
205
|
+
*/
|
|
206
|
+
const runCount = (run: readonly Opened[], continuing: ReadonlySet<string>): number =>
|
|
207
|
+
run.filter((opened, at) => !(opened.opener !== undefined && continuing.has(opened.opener) && run[at - 1]?.opener === opened.opener)).length;
|
|
208
|
+
|
|
209
|
+
const runFinding = (run: readonly Opened[], count: number, options: DetectorOptions): Finding => {
|
|
200
210
|
const first = run[0];
|
|
201
211
|
return {
|
|
202
212
|
rule: "",
|
|
@@ -204,7 +214,7 @@ const runFinding = (run: readonly Opened[], options: DetectorOptions): Finding =
|
|
|
204
214
|
line: 0,
|
|
205
215
|
column: 0,
|
|
206
216
|
quote: run.map(({ sentence }) => sentence.text.trim()).join(""),
|
|
207
|
-
values: { word: first?.opener ?? "", count
|
|
217
|
+
values: { word: first?.opener ?? "", count, limit: options.limit, offset: first?.sentence.span.start ?? 0 },
|
|
208
218
|
};
|
|
209
219
|
};
|
|
210
220
|
|
|
@@ -212,9 +222,11 @@ const runFinding = (run: readonly Opened[], options: DetectorOptions): Finding =
|
|
|
212
222
|
export const openerRun: Detector = (doc, options): Finding[] => {
|
|
213
223
|
const lexicon = options.lexicon ?? [];
|
|
214
224
|
const notOpeners = doc.lexicons[NOT_OPENER_LEXICON] ?? [];
|
|
225
|
+
const continuing = new Set((doc.lexicons[CONTINUING_LEXICON] ?? []).map((entry) => entry.pattern));
|
|
215
226
|
return doc.paragraphs.flatMap((paragraph) =>
|
|
216
227
|
openerRuns(paragraph.sentences, lexicon, notOpeners)
|
|
217
|
-
.
|
|
218
|
-
.
|
|
228
|
+
.map((run) => ({ run, count: runCount(run, continuing) }))
|
|
229
|
+
.filter(({ count }) => count > options.limit)
|
|
230
|
+
.map(({ run, count }) => runFinding(run, count, options)),
|
|
219
231
|
);
|
|
220
232
|
};
|
package/src/detectors/signals.ts
CHANGED
|
@@ -49,9 +49,19 @@ const density = (doc: ProseDocument, count: number): number => {
|
|
|
49
49
|
* 件数ではなく密度で見る。長い文書ほど当たるのを避けるため(bold-density と同じ)。
|
|
50
50
|
*/
|
|
51
51
|
const EMOJI = /\p{Extended_Pictographic}|[←-⇿☀-➿]/gu;
|
|
52
|
+
const ARROW = /^[←-⇿]$/u;
|
|
53
|
+
const WORD_END = /[\p{L}\p{N}*_)\]"'’”]$/u;
|
|
54
|
+
const WORD_START = /^[\p{L}\p{N}*_(["'‘“]/u;
|
|
55
|
+
|
|
56
|
+
/** 語と語の間の矢印(Settings → Printers、A→B)。メニューの道筋や流れを示す区切りで、飾りではない。行頭の矢印(→ 詳しくはこちら)は飾り。 */
|
|
57
|
+
const isArrowBetween = (hit: Hit): boolean => {
|
|
58
|
+
const text = hit.sentence.text;
|
|
59
|
+
const at = hit.offset - hit.sentence.span.start;
|
|
60
|
+
return ARROW.test(text[at] ?? "") && WORD_END.test(text.slice(0, at).trimEnd()) && WORD_START.test(text.slice(at + 1).trimStart());
|
|
61
|
+
};
|
|
52
62
|
|
|
53
63
|
export const emojiDensity: Detector = (doc, options): Finding[] => {
|
|
54
|
-
const hits = findIn(doc, EMOJI);
|
|
64
|
+
const hits = findIn(doc, EMOJI).filter((hit) => !isArrowBetween(hit));
|
|
55
65
|
const first = hits[0];
|
|
56
66
|
const rate = density(doc, hits.length);
|
|
57
67
|
if (wordsOf(doc) < MIN_DOCUMENT_LENGTH[doc.lengthUnit] || first === undefined || rate <= options.limit) return [];
|
|
@@ -38,7 +38,7 @@ const minimumCount = (options: DetectorOptions, name: string, fallback: number):
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
const DEFAULT_MIN_SECTIONS = 5;
|
|
41
|
-
const DEFAULT_MIN_PARAGRAPHS =
|
|
41
|
+
const DEFAULT_MIN_PARAGRAPHS = 9;
|
|
42
42
|
|
|
43
43
|
const uniformity = (doc: ProseDocument, values: readonly number[], span: { start: number }, limit: number, rule: string): Finding[] => {
|
|
44
44
|
const cv = coefficientOfVariation(values);
|
|
@@ -137,7 +137,8 @@ export const sectionUniformity: Detector = (doc, options): Finding[] => {
|
|
|
137
137
|
*/
|
|
138
138
|
export const ruleOfThree: Detector = (doc, options): Finding[] => {
|
|
139
139
|
const openWords = (doc.lexicons["list-continues"] ?? []).map((entry) => entry.pattern);
|
|
140
|
-
const
|
|
140
|
+
const sentenceStarts = doc.sentences.map((sentence) => sentence.span.start);
|
|
141
|
+
const found = threeShare(doc.source, doc.lists, openWords, options.limit, sentenceStarts);
|
|
141
142
|
if (found === undefined) return [];
|
|
142
143
|
return [
|
|
143
144
|
{
|
|
@@ -11,7 +11,7 @@ const LATIN = /\p{Script=Latin}/u;
|
|
|
11
11
|
/** Does the character beside a match end the word? A Latin edge needs a non-letter next to it; a CJK word stands anywhere. */
|
|
12
12
|
const boundsWord = (edge: string, beside: string | undefined): boolean => !LATIN.test(edge) || beside === undefined || !/[\p{L}\p{N}]/u.test(beside);
|
|
13
13
|
|
|
14
|
-
const holdsWordAt = (text: string, pattern: string, index: number): boolean =>
|
|
14
|
+
export const holdsWordAt = (text: string, pattern: string, index: number): boolean =>
|
|
15
15
|
boundsWord(pattern[0] ?? "", text[index - 1]) && boundsWord(pattern.at(-1) ?? "", text[index + pattern.length]);
|
|
16
16
|
|
|
17
17
|
/** The heading names a template: one of the words appears in it as a whole word, in any case. */
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Detector, Finding, Lexicon, ProseDocument } from "../plugin.ts";
|
|
2
2
|
import { entriesForGenre } from "../lexicon-genres.ts";
|
|
3
3
|
import { unfilledPlaceholder } from "./ai-phrasing.ts";
|
|
4
|
-
import { placeholderSpans } from "./placeholder-text.ts";
|
|
4
|
+
import { BLANK_SUFFIX, placeholderSpans } from "./placeholder-text.ts";
|
|
5
5
|
import { TEMPLATE, isInside, templateSections } from "./template-sections.ts";
|
|
6
6
|
import { tableBodyCells } from "../facts/table-facts.ts";
|
|
7
7
|
import { proseAndTablesOf } from "../table-text.ts";
|
|
8
|
+
import { EXAMPLE_LEAD, captionsFillLine, filledFieldLabels, insideQuotedExample, lineAround } from "./placeholder-context.ts";
|
|
8
9
|
|
|
9
10
|
/** The prose covers tables, so a blank left in a cell (| Owner | [Name] |) is read from the cells themselves. */
|
|
10
11
|
const cellBlanks = (doc: ProseDocument, lexicon: Lexicon): Finding[] =>
|
|
@@ -19,6 +20,24 @@ const cellBlanks = (doc: ProseDocument, lexicon: Lexicon): Finding[] =>
|
|
|
19
20
|
})),
|
|
20
21
|
);
|
|
21
22
|
|
|
23
|
+
/**
|
|
24
|
+
* A bracket that is not a forgotten blank, read from the line around it: the caption of a form's fill line, a blank inside
|
|
25
|
+
* a quoted example, or a field label the document fills in elsewhere.
|
|
26
|
+
*/
|
|
27
|
+
const isNamedOrExample = (doc: ProseDocument, lexicon: Lexicon): ((finding: Finding) => boolean) => {
|
|
28
|
+
const leads = lexicon.filter((word) => word.group === EXAMPLE_LEAD);
|
|
29
|
+
const fields = filledFieldLabels(
|
|
30
|
+
doc.source,
|
|
31
|
+
lexicon.filter((word) => word.group === BLANK_SUFFIX),
|
|
32
|
+
);
|
|
33
|
+
return (finding) => {
|
|
34
|
+
const matched = String(finding.values["matched"]);
|
|
35
|
+
const start = Number(finding.values["offset"]);
|
|
36
|
+
const line = lineAround(doc.source, start, start + matched.length);
|
|
37
|
+
return fields.has(matched) || captionsFillLine(line) || insideQuotedExample(line, leads);
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
22
41
|
/**
|
|
23
42
|
* A blank under a heading that names a template (Template, 雛形) is what the template is for, so it is not reported.
|
|
24
43
|
* Words that hold in some genres only (〇〇様 in a letter) count in those genres.
|
|
@@ -27,7 +46,9 @@ export const unfilledPlaceholderOutsideTemplates: Detector = (doc, options) => {
|
|
|
27
46
|
const lexicon = entriesForGenre(options.lexicon ?? [], options.genre);
|
|
28
47
|
const words = lexicon.filter((word) => word.group === TEMPLATE);
|
|
29
48
|
const templates = templateSections(doc.markup?.headings ?? [], doc.source.length, words);
|
|
49
|
+
const named = isNamedOrExample(doc, lexicon);
|
|
30
50
|
return [...unfilledPlaceholder(doc, { ...options, lexicon }), ...cellBlanks(doc, lexicon)]
|
|
31
51
|
.filter((finding) => !isInside(templates, Number(finding.values["offset"])))
|
|
52
|
+
.filter((finding) => !named(finding))
|
|
32
53
|
.toSorted((left, right) => Number(left.values["offset"]) - Number(right.values["offset"]));
|
|
33
54
|
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Span } from "../plugin.ts";
|
|
2
|
+
|
|
3
|
+
// Stanzas: blocks of lines between blank lines where every line opens with a capital, as a verse line does, in a document
|
|
4
|
+
// where several such blocks also run a sentence on across a line into a capital ("How public, like a frog / To tell…").
|
|
5
|
+
// Prose wrapped at a column goes on in lower case, and prose with one sentence a line ends each line with its sentence.
|
|
6
|
+
|
|
7
|
+
const VERSE_LINE = /^[\t ]*["'“‘(]?\p{Lu}/u;
|
|
8
|
+
const SENTENCE_CLOSE = /[.!?]["'”’)\]]*[\t ]*$/u;
|
|
9
|
+
/** The run-on stanzas a document needs before its capitalised blocks are read as verse: one may be a list of names. */
|
|
10
|
+
const MIN_RUN_ON_STANZAS = 3;
|
|
11
|
+
const MIN_LINES = 2;
|
|
12
|
+
|
|
13
|
+
type Block = { start: number; end: number; readonly lines: string[] };
|
|
14
|
+
|
|
15
|
+
/** The runs of lines between blank lines, each with its span in the source. */
|
|
16
|
+
const blocksOf = (source: string): Block[] => {
|
|
17
|
+
const blocks: Block[] = [];
|
|
18
|
+
const state = { offset: 0, open: false };
|
|
19
|
+
source.split("\n").forEach((line) => {
|
|
20
|
+
const start = state.offset;
|
|
21
|
+
state.offset += line.length + 1;
|
|
22
|
+
if (line.trim() === "") {
|
|
23
|
+
state.open = false;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const last = blocks.at(-1);
|
|
27
|
+
if (state.open && last !== undefined) {
|
|
28
|
+
last.end = start + line.length;
|
|
29
|
+
last.lines.push(line);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
blocks.push({ start, end: start + line.length, lines: [line] });
|
|
33
|
+
state.open = true;
|
|
34
|
+
});
|
|
35
|
+
return blocks;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const isCapitalised = (lines: readonly string[]): boolean => lines.every((line) => VERSE_LINE.test(line));
|
|
39
|
+
|
|
40
|
+
/** A line inside the block, past its first, that runs on into the next: a first line alone may be a caption ("Article 1 Purpose"). */
|
|
41
|
+
const runsOn = (lines: readonly string[]): boolean => lines.slice(1, -1).some((line) => !SENTENCE_CLOSE.test(line));
|
|
42
|
+
|
|
43
|
+
/** The spans of the source's stanzas, sorted by start and never overlapping; none when the document is not verse. */
|
|
44
|
+
export const verseBlockSpans = (source: string): Span[] => {
|
|
45
|
+
const blocks = blocksOf(source).filter(({ lines }) => lines.length >= MIN_LINES && isCapitalised(lines));
|
|
46
|
+
const runOn = blocks.filter(({ lines }) => runsOn(lines)).length;
|
|
47
|
+
return runOn >= MIN_RUN_ON_STANZAS ? blocks.map(({ start, end }) => ({ start, end })) : [];
|
|
48
|
+
};
|
package/src/document.ts
CHANGED
|
@@ -370,6 +370,7 @@ const documentOf = (path: string, source: string, adapter: LanguageAdapter, team
|
|
|
370
370
|
namedDocument: adapter.structure?.namedDocument,
|
|
371
371
|
dictionary: adapter.dictionary,
|
|
372
372
|
replyQuotes: emailLayout.replyQuotes,
|
|
373
|
+
sentMessage: emailLayout.sent,
|
|
373
374
|
get markup(): Markup {
|
|
374
375
|
return documentMarkup(root, source, markdown, [...emailLayout.replyQuotes, ...syntax]);
|
|
375
376
|
},
|
package/src/email-parts.ts
CHANGED
|
@@ -25,6 +25,8 @@ export type EmailParts = {
|
|
|
25
25
|
readonly furniture: readonly Span[];
|
|
26
26
|
/** An attribution line and the quoted lines after it: someone else's words, so not this document's headings or structure. */
|
|
27
27
|
readonly replyQuotes: readonly Span[];
|
|
28
|
+
/** A header names a field the writer does not type (From, Date): a message as sent or kept, not a draft. */
|
|
29
|
+
readonly sent: boolean;
|
|
28
30
|
};
|
|
29
31
|
|
|
30
32
|
const lowerCased = (lexicon: Lexicon | undefined): ReadonlySet<string> => new Set((lexicon ?? []).map((entry) => entry.pattern.toLowerCase()));
|
|
@@ -142,12 +144,17 @@ const fieldMask = (field: readonly Line[], vocabulary: EmailVocabulary): Span |
|
|
|
142
144
|
return { start: first.start, end: first.start + label[0].length };
|
|
143
145
|
};
|
|
144
146
|
|
|
145
|
-
const
|
|
146
|
-
blocksOf(lines).
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
const headerBlocks = (lines: readonly Line[], vocabulary: EmailVocabulary): Line[][] =>
|
|
148
|
+
blocksOf(lines).filter((block) => block[0] !== undefined && isHeader(block, opensMessage(lines, block[0]), vocabulary));
|
|
149
|
+
|
|
150
|
+
const headerSpans = (headers: readonly Line[][], vocabulary: EmailVocabulary): Span[] =>
|
|
151
|
+
headers.flatMap((block) => fieldsOf(block).flatMap((field) => fieldMask(field, vocabulary) ?? []));
|
|
152
|
+
|
|
153
|
+
/** A header line the writer does not type: a known field outside the written ones (From, Date), or the envelope line. */
|
|
154
|
+
const isSentField = (line: Line, vocabulary: EmailVocabulary): boolean => {
|
|
155
|
+
const name = FIELD.exec(line.text)?.[1]?.toLowerCase();
|
|
156
|
+
return name === undefined ? ENVELOPE.test(line.text) : vocabulary.headerFields.has(name) && !vocabulary.writtenFields.has(name);
|
|
157
|
+
};
|
|
151
158
|
|
|
152
159
|
const isUrlField = (line: Line | undefined): boolean => {
|
|
153
160
|
const label = line === undefined ? null : FIELD.exec(line.text);
|
|
@@ -256,14 +263,16 @@ export const emailParts = (source: string, vocabulary: EmailVocabulary): EmailPa
|
|
|
256
263
|
const lines = linesOf(source);
|
|
257
264
|
const replies = repliesOf(lines, vocabulary);
|
|
258
265
|
const separators = lines.filter((line) => isSeparator(line)).map((line) => spanOfLines(line, line));
|
|
266
|
+
const headers = headerBlocks(lines, vocabulary);
|
|
259
267
|
return {
|
|
260
268
|
furniture: [
|
|
261
|
-
...headerSpans(
|
|
269
|
+
...headerSpans(headers, vocabulary),
|
|
262
270
|
...attachmentStubSpans(lines, vocabulary),
|
|
263
271
|
...separators,
|
|
264
272
|
...signatureSpans(lines),
|
|
265
273
|
...replies.map((reply) => reply.attribution),
|
|
266
274
|
].toSorted(bySpanStart),
|
|
267
275
|
replyQuotes: replies.map((reply) => reply.quote),
|
|
276
|
+
sent: headers.some((block) => block.some((line) => isSentField(line, vocabulary))),
|
|
268
277
|
};
|
|
269
278
|
};
|
package/src/eval.ts
CHANGED
|
@@ -77,6 +77,8 @@ const meets = (need: string, docs: readonly ProseDocument[]): boolean => {
|
|
|
77
77
|
if (need === "headings") return docs.some((doc) => bodySectionOf(doc.sections) !== undefined);
|
|
78
78
|
// 記法を読む rule は Markdown の文書でしか動かない。
|
|
79
79
|
if (need === "markdown") return docs.some((doc) => doc.markup?.markdown === true);
|
|
80
|
+
// 下書きでは lint が動かない。送ったメールが 1 つも無ければ、どの閾値でも 0 件になる。
|
|
81
|
+
if (need === "sent-message") return docs.some((doc) => doc.sentMessage === true);
|
|
80
82
|
return false;
|
|
81
83
|
};
|
|
82
84
|
|
package/src/plugin.ts
CHANGED
|
@@ -381,6 +381,8 @@ export type ProseDocument = {
|
|
|
381
381
|
readonly namedDocument?: DocumentNamer | undefined;
|
|
382
382
|
/** メールの引用した返信(前置きの行と「> 」の行)。ほかの人の言葉なので、見出しにも木にも入れない。 */
|
|
383
383
|
readonly replyQuotes?: readonly Span[] | undefined;
|
|
384
|
+
/** ヘッダーに書き手の打たない項目(From・Date)がある。送った・届いたメールで、下書きではない。下書きの添付は送るときに付くので本文から見えない。 */
|
|
385
|
+
readonly sentMessage?: boolean | undefined;
|
|
384
386
|
/** 記法の手がかり(見出し・画像・リンク)。記法を読む rule だけが触れ、触れたときに作る。 */
|
|
385
387
|
readonly markup?: Markup | undefined;
|
|
386
388
|
/** adapter の綴りの辞書。持たない言語では無い。 */
|
package/src/reasons.ts
CHANGED
|
@@ -20,6 +20,8 @@ export type Reasons = {
|
|
|
20
20
|
readonly noHeadings: string;
|
|
21
21
|
readonly patternTimeout: (budgetMs: number) => string;
|
|
22
22
|
readonly notMarkdown: string;
|
|
23
|
+
/** A rule that reads what a message carries, on a draft: its attachments are added when sending. */
|
|
24
|
+
readonly draftMessage: string;
|
|
23
25
|
/** A rule that compares documents, in a run of one: it runs when chaff is given two or more files, or a folder. */
|
|
24
26
|
readonly oneDocument: string;
|
|
25
27
|
};
|
|
@@ -57,6 +59,7 @@ export const REASONS: Texts<Reasons> = {
|
|
|
57
59
|
noHeadings: "表題より下の見出しが無いため",
|
|
58
60
|
patternTimeout: (budgetMs) => `正規表現が ${String(budgetMs)} ms で終わらなかったため(chaff.yaml の pattern を単純にしてください)`,
|
|
59
61
|
notMarkdown: "Markdown の文書ではないため",
|
|
62
|
+
draftMessage: "送る前の下書き(差出人や日時のヘッダーが無い)で、添付は送るときに付けるため本文からは見えないため",
|
|
60
63
|
oneDocument: "比べるほかの文書が無いため(ファイルを二つ以上かフォルダを渡すと動きます)",
|
|
61
64
|
},
|
|
62
65
|
en: {
|
|
@@ -80,6 +83,7 @@ export const REASONS: Texts<Reasons> = {
|
|
|
80
83
|
noHeadings: "the document has no headings below its title",
|
|
81
84
|
patternTimeout: (budgetMs) => `the pattern did not finish within ${String(budgetMs)} ms (simplify the pattern in chaff.yaml)`,
|
|
82
85
|
notMarkdown: "the document is not Markdown",
|
|
86
|
+
draftMessage: "the text is a draft (no From: or Date: header), and a draft's files are attached when sending, out of the text's sight",
|
|
83
87
|
oneDocument: "it compares documents, and there is only one to compare (it runs when chaff is given two or more files, or a folder)",
|
|
84
88
|
},
|
|
85
89
|
};
|
package/src/rule-of-three.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { BulletList } from "./plugin.ts";
|
|
|
6
6
|
* 箇条書きが少ないと、1 つで割合が大きく動く(4 つなら 25 ポイント)。そのときは全部が 3 項目のときだけ報告する。
|
|
7
7
|
* 2 つでも測る。生成文の報告書は「要因 3 つ」「提言 3 つ」の 2 つの箇条書きで終わることが多く、人の文書で 2 つとも 3 項目は少ない。
|
|
8
8
|
* 本文の最初の文より前の箇条書き(題・日付・見出しのすぐ下の要点や概要)は数えない。項目の数はサイトの型が決めている。
|
|
9
|
-
*
|
|
9
|
+
* どの項目も「札:数」の内訳も、どの項目も 3 文以上ある箇条書きも、ちょうど 3 項目とは数えない。
|
|
10
10
|
*/
|
|
11
11
|
export type ThreeShare = { readonly count: number; readonly total: number; readonly share: number; readonly first: BulletList };
|
|
12
12
|
|
|
@@ -74,14 +74,31 @@ const isLabelledFigure = (item: string): boolean => {
|
|
|
74
74
|
export const isFigureBreakdown = (source: string, list: BulletList): boolean =>
|
|
75
75
|
list.itemSpans.length > 0 && list.itemSpans.every((item) => isLabelledFigure(source.slice(item.start, item.end)));
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
/** 段落として書いた項目の文の数の下限。太字の見出しの文と、それを説く 2 文。 */
|
|
78
|
+
const MIN_ITEM_SENTENCES = 3;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* どの項目も 3 文以上ある箇条書き(太字の助言と、それを説く数文)。項目ごとに段落を書いた心得の一覧で、数は中身が決めている。
|
|
82
|
+
* 数を合わせるために足した項目は、1 文か 2 文の薄いものになる。
|
|
83
|
+
*/
|
|
84
|
+
export const isParagraphItems = (list: BulletList, sentenceStarts: readonly number[]): boolean =>
|
|
85
|
+
list.itemSpans.length > 0 &&
|
|
86
|
+
list.itemSpans.every((item) => sentenceStarts.filter((start) => start >= item.start && start < item.end).length >= MIN_ITEM_SENTENCES);
|
|
87
|
+
|
|
88
|
+
const isExactlyThree = (source: string, list: BulletList, openWords: readonly string[], sentenceStarts: readonly number[]): boolean =>
|
|
89
|
+
list.items.length === THREE && !continuesBeyond(source, list, openWords) && !isFigureBreakdown(source, list) && !isParagraphItems(list, sentenceStarts);
|
|
79
90
|
|
|
80
91
|
/** 報告するときの数。報告しないときは undefined。 */
|
|
81
|
-
export const threeShare = (
|
|
92
|
+
export const threeShare = (
|
|
93
|
+
source: string,
|
|
94
|
+
allLists: readonly BulletList[],
|
|
95
|
+
openWords: readonly string[],
|
|
96
|
+
limit: number,
|
|
97
|
+
sentenceStarts: readonly number[] = [],
|
|
98
|
+
): ThreeShare | undefined => {
|
|
82
99
|
const bodyStart = firstProseOffset(source);
|
|
83
100
|
const lists = allLists.filter((list) => list.span.start >= bodyStart);
|
|
84
|
-
const threes = lists.filter((list) => isExactlyThree(source, list, openWords));
|
|
101
|
+
const threes = lists.filter((list) => isExactlyThree(source, list, openWords, sentenceStarts));
|
|
85
102
|
const first = threes[0];
|
|
86
103
|
if (lists.length < MIN_LISTS || first === undefined) return undefined;
|
|
87
104
|
const share = Math.round((threes.length / lists.length) * PERCENT);
|
package/src/run.ts
CHANGED
|
@@ -103,11 +103,13 @@ const unreadOf = (doc: ProseDocument): Unread | undefined => {
|
|
|
103
103
|
/** 見出しを読む rule の要求。表題より下の見出しが無い文書では、本題の前を測れない。0 件を「前置きが短い」に見せない。 */
|
|
104
104
|
/** 記法を読む rule の要求(markdown)。.txt には見出しの記法も画像もリンクの記法も無いので、0 件を「問題なし」に見せない。 */
|
|
105
105
|
/** documents: a rule that compares the documents of one run (cross-run.ts). Run on one document, it says so instead of finding nothing. */
|
|
106
|
-
|
|
106
|
+
/** sent-message: a rule that reads what a message carries (its attachments). A draft's are added when sending, out of the text's sight. */
|
|
107
|
+
const DOCUMENT_NEEDS: ReadonlySet<string> = new Set(["headings", "markdown", "documents", "sent-message"]);
|
|
107
108
|
|
|
108
109
|
const documentNeed = (rule: RuleDefinition, doc: ProseDocument): string | undefined => {
|
|
109
110
|
if (rule.requires.includes("markdown") && !isMarkdownPath(doc.path)) return reasonsFor(doc).notMarkdown;
|
|
110
111
|
if (rule.requires.includes("headings") && bodySectionOf(doc.sections) === undefined) return reasonsFor(doc).noHeadings;
|
|
112
|
+
if (rule.requires.includes("sent-message") && doc.sentMessage !== true) return reasonsFor(doc).draftMessage;
|
|
111
113
|
if (!rule.requires.includes("documents")) return undefined;
|
|
112
114
|
// Set aside only what the cross pass can run: a missing word list is said here, as for any rule.
|
|
113
115
|
const absent = missingList(rule, doc.lexicons);
|
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
// An address the document cites to another document once ("Section 504 of the Rehabilitation Act") is that document's
|
|
2
2
|
// address wherever the document writes it bare ("In Section 504, …", "Section 504/501 complaints"): a reader who met the
|
|
3
|
-
// named form reads the bare one the same way.
|
|
3
|
+
// named form reads the bare one the same way. So is a part of that unit ("§111(a)" after "§111(c) of the Act") when the
|
|
4
|
+
// document has no unit of that number of its own. Pure.
|
|
4
5
|
import type { StructureNode } from "../plugin.ts";
|
|
5
6
|
|
|
6
7
|
/** The unit (section, article; 条) and the address. A reference without both takes no part. */
|
|
7
|
-
const keyOf = (node: StructureNode): string | undefined => {
|
|
8
|
+
const keyOf = (node: StructureNode, address: (target: string) => string = (target) => target): string | undefined => {
|
|
8
9
|
const unit = node.attrs["numbering"] ?? node.attrs["unitWord"];
|
|
9
10
|
const target = node.attrs["target"];
|
|
10
|
-
return unit === undefined || target === undefined || target === "" ? undefined : `${String(unit)}:${String(target)}`;
|
|
11
|
+
return unit === undefined || target === undefined || target === "" ? undefined : `${String(unit)}:${address(String(target))}`;
|
|
11
12
|
};
|
|
12
13
|
|
|
13
|
-
/**
|
|
14
|
+
/** The top unit of an address: 111 of 111.a.1. */
|
|
15
|
+
const topOf = (target: string): string => target.split(".")[0] ?? target;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Whether a bare reference names the same unit and address as a reference the document cites to another document, or a
|
|
19
|
+
* part of a unit cited there whose number the document does not hold itself (own says whether an address is the document's).
|
|
20
|
+
*/
|
|
14
21
|
export const citedElsewhereReader = (
|
|
15
22
|
references: readonly StructureNode[],
|
|
16
23
|
citesOther: (node: StructureNode) => boolean,
|
|
24
|
+
own: (address: string) => boolean = () => true,
|
|
17
25
|
): ((node: StructureNode) => boolean) => {
|
|
18
|
-
const
|
|
26
|
+
const named = references.filter(citesOther);
|
|
27
|
+
const cited = new Set(named.flatMap((node) => keyOf(node) ?? []));
|
|
28
|
+
const citedTops = new Set(named.flatMap((node) => keyOf(node, topOf) ?? []));
|
|
19
29
|
return (node) => {
|
|
20
30
|
const key = keyOf(node);
|
|
21
|
-
|
|
31
|
+
if (key === undefined) return false;
|
|
32
|
+
const top = topOf(String(node.attrs["target"]));
|
|
33
|
+
return cited.has(key) || (!own(top) && citedTops.has(keyOf(node, topOf) ?? ""));
|
|
22
34
|
};
|
|
23
35
|
};
|
|
@@ -346,6 +346,12 @@ const insideLongerNameIn = (texts: readonly BodyText[], terms: readonly DefinedT
|
|
|
346
346
|
};
|
|
347
347
|
};
|
|
348
348
|
|
|
349
|
+
/** 英語の語が、前の大文字の語から続く長い名前の終わりにあるか(The National Security Act of 1947 の Act)。 */
|
|
350
|
+
const endsNameAt = (texts: readonly BodyText[], term: string, offset: number): boolean => {
|
|
351
|
+
const sentence = sentenceAt(texts, offset);
|
|
352
|
+
return sentence !== undefined && endsLatinName(sentence, offset - sentence.start, term);
|
|
353
|
+
};
|
|
354
|
+
|
|
349
355
|
/**
|
|
350
356
|
* 前で書いても読み手が分かる所。文書自身の名前と定義した語(この就業規則(以下「規則」))を同じ頭を付けて書いた所(この規則は、…)と、
|
|
351
357
|
* すぐ後ろの括弧に定義の長い名前を書き添えた所(こども性暴力防止法(…に関する法律))。
|
|
@@ -378,7 +384,8 @@ const citesSource = (texts: readonly BodyText[], markers: readonly string[], off
|
|
|
378
384
|
* 文の途中で括弧に入れて定義した語((the "Seller")、以下「甲」という)を、その定義の文より前で使っている所。最初の一つだけ。
|
|
379
385
|
* 定義の文の中の現れ(株式会社GovTech東京(以下「GovTech東京」という。))は、定義する名前そのものなので数えない。札の文も、
|
|
380
386
|
* isTitle が言う題・見出し・目次の行も、漢字で終わる語にさらに漢字が続く長い語の一部も、定義の括弧の前の長い名前を写した所も、
|
|
381
|
-
* 語を含むもっと長い名前の中も、語の前に意味の出どころを書いた所(69条の3
|
|
387
|
+
* 語を含むもっと長い名前の中も、語の前に意味の出どころを書いた所(69条の3所定の小規模宅地等)も数えない。
|
|
388
|
+
* 英語の語を長い名前の終わりに書いた所(The National Security Act of 1947)より後ろの現れ(the Act)は、その名前を指すので数えない。文書自身の名前を定義した語は、selfPrefixes(この、本、this)を付けて前で書いても数えない。
|
|
382
389
|
* 定義の条("Seller" means、「甲」とは)は条の並びの頭にも終わりにも置く書き方があるので、前で使っても言わない。
|
|
383
390
|
* 定義の語の無い括弧の引用(("The key point is"))は例の引用と同じ形なので、その語を引用符で挙げただけの現れ
|
|
384
391
|
* (Its sentences open with "The key point is")は使用ではない。定義の語のある定義((the "Seller")、以下「買主」という)は、
|
|
@@ -400,8 +407,10 @@ export const usesBeforeDefinition = (
|
|
|
400
407
|
.flatMap(({ first: defined, spans }) => {
|
|
401
408
|
const defining = sentenceAt(texts, defined.span.start)?.start ?? defined.span.start;
|
|
402
409
|
const uses = usesOf(defined.term, texts, spans, "exact", defined.bare === true ? mentioned : NEVER_MENTIONED).filter((offset) => offset < defining);
|
|
410
|
+
const namedFirst = uses.find((offset) => endsNameAt(texts, defined.term, offset));
|
|
403
411
|
const first = uses.find(
|
|
404
412
|
(offset) =>
|
|
413
|
+
!(namedFirst !== undefined && namedFirst < offset) &&
|
|
405
414
|
!isLabel(sentenceAt(texts, offset), defined.term) &&
|
|
406
415
|
!insideCaption(sentenceAt(texts, offset), offset) &&
|
|
407
416
|
!isTitle(offset, defined.span.start) &&
|
package/src/structure/issues.ts
CHANGED
|
@@ -163,7 +163,7 @@ export const danglingReferences = (
|
|
|
163
163
|
const quoted = referencesInCitedDocuments(tree);
|
|
164
164
|
const references = nodes.filter((node) => node.kind === "reference");
|
|
165
165
|
const named = namedTargets(references, source, nameNouns);
|
|
166
|
-
const citedElsewhereToo = citedElsewhereReader(references, citesOther);
|
|
166
|
+
const citedElsewhereToo = citedElsewhereReader(references, citesOther, (address) => addresses.has(address));
|
|
167
167
|
const unresolved = references
|
|
168
168
|
.filter((node) => !citesOther(node) && !otherNumbering(node) && !pointsToNamedSection(node, named) && !citedElsewhereToo(node))
|
|
169
169
|
.filter((node) => !namesAbsentUnit(node, articleLabels) && !withinAbsentUnit(node, unitLabels) && !elsewhere.has(node))
|