chaffjs 0.51.0 → 0.52.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.
Files changed (153) hide show
  1. package/dist/clause-particles.d.ts +10 -2
  2. package/dist/clause-particles.d.ts.map +1 -1
  3. package/dist/clause-particles.js +15 -3
  4. package/dist/clause-particles.js.map +1 -1
  5. package/dist/detectors/address-blank.d.ts +14 -0
  6. package/dist/detectors/address-blank.d.ts.map +1 -0
  7. package/dist/detectors/address-blank.js +41 -0
  8. package/dist/detectors/address-blank.js.map +1 -0
  9. package/dist/detectors/bold-emphasis-form.d.ts +1 -0
  10. package/dist/detectors/bold-emphasis-form.d.ts.map +1 -1
  11. package/dist/detectors/bold-emphasis-form.js +7 -1
  12. package/dist/detectors/bold-emphasis-form.js.map +1 -1
  13. package/dist/detectors/char-shape.d.ts.map +1 -1
  14. package/dist/detectors/char-shape.js +7 -8
  15. package/dist/detectors/char-shape.js.map +1 -1
  16. package/dist/detectors/closing-cliche.d.ts +1 -1
  17. package/dist/detectors/closing-cliche.d.ts.map +1 -1
  18. package/dist/detectors/closing-cliche.js +16 -3
  19. package/dist/detectors/closing-cliche.js.map +1 -1
  20. package/dist/detectors/contraction-mix.d.ts.map +1 -1
  21. package/dist/detectors/contraction-mix.js +3 -1
  22. package/dist/detectors/contraction-mix.js.map +1 -1
  23. package/dist/detectors/currency-notation.d.ts.map +1 -1
  24. package/dist/detectors/currency-notation.js +9 -1
  25. package/dist/detectors/currency-notation.js.map +1 -1
  26. package/dist/detectors/definition-use.d.ts.map +1 -1
  27. package/dist/detectors/definition-use.js +1 -0
  28. package/dist/detectors/definition-use.js.map +1 -1
  29. package/dist/detectors/en-shape.d.ts.map +1 -1
  30. package/dist/detectors/en-shape.js +12 -1
  31. package/dist/detectors/en-shape.js.map +1 -1
  32. package/dist/detectors/gram-ending.d.ts +12 -0
  33. package/dist/detectors/gram-ending.d.ts.map +1 -0
  34. package/dist/detectors/gram-ending.js +27 -0
  35. package/dist/detectors/gram-ending.js.map +1 -0
  36. package/dist/detectors/gram-repetition.d.ts.map +1 -1
  37. package/dist/detectors/gram-repetition.js +19 -3
  38. package/dist/detectors/gram-repetition.js.map +1 -1
  39. package/dist/detectors/inline-item-label.d.ts.map +1 -1
  40. package/dist/detectors/inline-item-label.js +14 -3
  41. package/dist/detectors/inline-item-label.js.map +1 -1
  42. package/dist/detectors/kanji-run-pieces.d.ts +21 -6
  43. package/dist/detectors/kanji-run-pieces.d.ts.map +1 -1
  44. package/dist/detectors/kanji-run-pieces.js +23 -8
  45. package/dist/detectors/kanji-run-pieces.js.map +1 -1
  46. package/dist/detectors/list-item-own.d.ts +11 -0
  47. package/dist/detectors/list-item-own.d.ts.map +1 -0
  48. package/dist/detectors/list-item-own.js +31 -0
  49. package/dist/detectors/list-item-own.js.map +1 -0
  50. package/dist/detectors/list-item-phrase.d.ts +1 -1
  51. package/dist/detectors/list-item-phrase.d.ts.map +1 -1
  52. package/dist/detectors/list-item-phrase.js +18 -7
  53. package/dist/detectors/list-item-phrase.js.map +1 -1
  54. package/dist/detectors/list-joint.d.ts +6 -0
  55. package/dist/detectors/list-joint.d.ts.map +1 -1
  56. package/dist/detectors/list-joint.js +18 -2
  57. package/dist/detectors/list-joint.js.map +1 -1
  58. package/dist/detectors/list-parallel.d.ts +3 -8
  59. package/dist/detectors/list-parallel.d.ts.map +1 -1
  60. package/dist/detectors/list-parallel.js +18 -32
  61. package/dist/detectors/list-parallel.js.map +1 -1
  62. package/dist/detectors/open-end-scope.d.ts.map +1 -1
  63. package/dist/detectors/open-end-scope.js +2 -2
  64. package/dist/detectors/open-end-scope.js.map +1 -1
  65. package/dist/detectors/oxford-comma.d.ts.map +1 -1
  66. package/dist/detectors/oxford-comma.js +2 -1
  67. package/dist/detectors/oxford-comma.js.map +1 -1
  68. package/dist/detectors/pseudo-heading.d.ts +2 -0
  69. package/dist/detectors/pseudo-heading.d.ts.map +1 -1
  70. package/dist/detectors/pseudo-heading.js +63 -2
  71. package/dist/detectors/pseudo-heading.js.map +1 -1
  72. package/dist/detectors/register-label-note.d.ts +8 -0
  73. package/dist/detectors/register-label-note.d.ts.map +1 -0
  74. package/dist/detectors/register-label-note.js +31 -0
  75. package/dist/detectors/register-label-note.js.map +1 -0
  76. package/dist/detectors/run-in-title.d.ts +6 -0
  77. package/dist/detectors/run-in-title.d.ts.map +1 -0
  78. package/dist/detectors/run-in-title.js +32 -0
  79. package/dist/detectors/run-in-title.js.map +1 -0
  80. package/dist/detectors/sentence-ending.d.ts.map +1 -1
  81. package/dist/detectors/sentence-ending.js +5 -1
  82. package/dist/detectors/sentence-ending.js.map +1 -1
  83. package/dist/detectors/sentence-length.d.ts.map +1 -1
  84. package/dist/detectors/sentence-length.js +12 -3
  85. package/dist/detectors/sentence-length.js.map +1 -1
  86. package/dist/detectors/technical-docs.d.ts.map +1 -1
  87. package/dist/detectors/technical-docs.js +25 -6
  88. package/dist/detectors/technical-docs.js.map +1 -1
  89. package/dist/detectors/token-shape.d.ts.map +1 -1
  90. package/dist/detectors/token-shape.js +4 -3
  91. package/dist/detectors/token-shape.js.map +1 -1
  92. package/dist/detectors/unfilled-placeholder.d.ts.map +1 -1
  93. package/dist/detectors/unfilled-placeholder.js +11 -1
  94. package/dist/detectors/unfilled-placeholder.js.map +1 -1
  95. package/dist/structure/definition-use.d.ts +5 -3
  96. package/dist/structure/definition-use.d.ts.map +1 -1
  97. package/dist/structure/definition-use.js +10 -2
  98. package/dist/structure/definition-use.js.map +1 -1
  99. package/dist/structure/forward-reference.d.ts +8 -0
  100. package/dist/structure/forward-reference.d.ts.map +1 -0
  101. package/dist/structure/forward-reference.js +18 -0
  102. package/dist/structure/forward-reference.js.map +1 -0
  103. package/dist/topic-clause.d.ts.map +1 -1
  104. package/dist/topic-clause.js +18 -5
  105. package/dist/topic-clause.js.map +1 -1
  106. package/package.json +3 -3
  107. package/rules/bold-emphasis.yaml +2 -2
  108. package/rules/closing-cliche.yaml +2 -2
  109. package/rules/contraction-consistency.yaml +2 -2
  110. package/rules/expletive-construction.yaml +2 -2
  111. package/rules/internal-jargon.yaml +1 -0
  112. package/rules/list-item-form-mix.yaml +2 -2
  113. package/rules/max-kanji-continuous.yaml +5 -2
  114. package/rules/max-sentence-length.yaml +2 -2
  115. package/rules/ngram-repetition.yaml +2 -2
  116. package/rules/no-doubled-joshi.yaml +2 -2
  117. package/rules/no-mixed-desumasu.yaml +2 -2
  118. package/rules/obligation-without-deadline.yaml +2 -2
  119. package/rules/preferred-term.yaml +1 -0
  120. package/rules/step-statement-mix.yaml +2 -2
  121. package/rules/topic-predicate-distance.yaml +2 -2
  122. package/rules/unfilled-placeholder.yaml +2 -2
  123. package/rules/use-before-definition.yaml +2 -2
  124. package/src/clause-particles.ts +19 -3
  125. package/src/detectors/address-blank.ts +49 -0
  126. package/src/detectors/bold-emphasis-form.ts +10 -1
  127. package/src/detectors/char-shape.ts +10 -11
  128. package/src/detectors/closing-cliche.ts +19 -2
  129. package/src/detectors/contraction-mix.ts +3 -1
  130. package/src/detectors/currency-notation.ts +17 -6
  131. package/src/detectors/definition-use.ts +1 -0
  132. package/src/detectors/en-shape.ts +14 -1
  133. package/src/detectors/gram-ending.ts +40 -0
  134. package/src/detectors/gram-repetition.ts +28 -4
  135. package/src/detectors/inline-item-label.ts +18 -3
  136. package/src/detectors/kanji-run-pieces.ts +35 -8
  137. package/src/detectors/list-item-own.ts +38 -0
  138. package/src/detectors/list-item-phrase.ts +20 -8
  139. package/src/detectors/list-joint.ts +31 -2
  140. package/src/detectors/list-parallel.ts +25 -38
  141. package/src/detectors/open-end-scope.ts +3 -2
  142. package/src/detectors/oxford-comma.ts +2 -1
  143. package/src/detectors/pseudo-heading.ts +75 -3
  144. package/src/detectors/register-label-note.ts +37 -0
  145. package/src/detectors/run-in-title.ts +35 -0
  146. package/src/detectors/sentence-ending.ts +5 -1
  147. package/src/detectors/sentence-length.ts +18 -5
  148. package/src/detectors/technical-docs.ts +31 -6
  149. package/src/detectors/token-shape.ts +4 -3
  150. package/src/detectors/unfilled-placeholder.ts +13 -1
  151. package/src/structure/definition-use.ts +13 -3
  152. package/src/structure/forward-reference.ts +21 -0
  153. package/src/topic-clause.ts +24 -5
@@ -0,0 +1,37 @@
1
+ import type { Sentence } from "../plugin.ts";
2
+ import type { Register } from "./register.ts";
3
+
4
+ // A list item that opens with a bold label closed by a colon, then a short note in one register, then prose in the other
5
+ // (- **外付けHDDが見つからない**:誰かが抜いたか、マウントされていない。差し直すとたいてい直ります。). The note is written as a
6
+ // field's value, the way a list of troubles notes a cause, and the item's own prose is the writer's register. Pure.
7
+
8
+ /** The head of a list item: its mark, a bold label, the closing bold, and a colon. */
9
+ const LABEL_HEAD = /^[ \t]*(?:[-*+]|\d{1,9}[.)])[ \t]+(?:\*\*|__)[^*_\n]+(?:\*\*|__)[ \t]*[::]/u;
10
+
11
+ const lineStartOf = (source: string, offset: number): number => source.lastIndexOf("\n", offset - 1) + 1;
12
+
13
+ /** The sentence opens the item's line right after a bold label and a colon. */
14
+ const opensAfterLabel = (sentences: readonly Sentence[], index: number, source: string): boolean => {
15
+ const sentence = sentences[index];
16
+ if (sentence === undefined) return false;
17
+ const lineStart = lineStartOf(source, sentence.span.start);
18
+ const before = sentences[index - 1];
19
+ if (before !== undefined && before.span.end > lineStart) return false;
20
+ const head = LABEL_HEAD.exec(source.slice(lineStart, sentence.span.end));
21
+ return head !== null && lineStart + head[0].length > sentence.span.start;
22
+ };
23
+
24
+ /**
25
+ * The note sentences of such items: the first sentence after the label, when the next sentence goes on in the same item, on
26
+ * the same line, in the other register.
27
+ */
28
+ export const labelNoteSentences = (sentences: readonly Sentence[], source: string, registerAt: (sentence: Sentence) => Register | undefined): Set<Sentence> =>
29
+ new Set(
30
+ sentences.filter((sentence, index) => {
31
+ const next = sentences[index + 1];
32
+ if (next === undefined || source.slice(sentence.span.end, next.span.start).includes("\n")) return false;
33
+ const own = registerAt(sentence);
34
+ const following = registerAt(next);
35
+ return own !== undefined && following !== undefined && own !== following && opensAfterLabel(sentences, index, source);
36
+ }),
37
+ );
@@ -0,0 +1,35 @@
1
+ // A link title a converted page runs into the blurb after it on one line (「法令」×「デジタル」ハッカソン 「法令」×「デジタル」の
2
+ // 取組を…開催しました。). The title is a name, not part of the sentence, so the title and the blurb are measured apart. Pure.
3
+
4
+ /** The first run of the line before a space, and what follows the space. */
5
+ const HEAD_AND_REST = /^(\S+)\s+(\S.*)$/u;
6
+ /** A stop or a comma in the head: the head is already a sentence or a clause, not a title. */
7
+ const SENTENCE_MARK = /[。.、,!?!?]/u;
8
+ /** A title that opens with a bracket (「法令」×「デジタル」ハッカソン, 『白書』概要). */
9
+ const BRACKET_OPEN = /^[「『【〔[]/u;
10
+ /** The closed bracketed parts of a title, taken out before its own words are read. */
11
+ const BRACKETED = /「[^「」]*」|『[^『』]*』|【[^【】]*】|〔[^〔〕]*〕|[[^[]]*]/gu;
12
+ /** A bracket left open once the closed ones are out: the space is inside a bracketed name (「Technovation Girls」は…). */
13
+ const LONE_BRACKET = /[「」『』【】〔〕[]]/u;
14
+ /** Hiragana outside the brackets: a clause (「はい」と答えた), not the name of a page. */
15
+ const HIRAGANA = /\p{Script=Hiragana}/u;
16
+ /** A head shorter than this that recurs in the line is a word the sentence repeats (第, 法), not a title. */
17
+ const MIN_REPEATED_TITLE_CHARS = 4;
18
+
19
+ const isBracketedTitle = (head: string): boolean => BRACKET_OPEN.test(head) && !HIRAGANA.test(head.replace(BRACKETED, ""));
20
+
21
+ const isRepeatedTitle = (head: string, rest: string): boolean => [...head].length >= MIN_REPEATED_TITLE_CHARS && rest.includes(head);
22
+
23
+ const isWholeHead = (head: string): boolean => !SENTENCE_MARK.test(head) && !LONE_BRACKET.test(head.replace(BRACKETED, ""));
24
+
25
+ /**
26
+ * The title and the blurb of a line that opens with a title run into a sentence: the head before the first space holds no
27
+ * stop, comma or unclosed bracket, and it opens with a bracket or recurs in the sentence after it. Undefined for any other text.
28
+ */
29
+ export const runInTitleParts = (text: string): readonly string[] | undefined => {
30
+ const match = HEAD_AND_REST.exec(text.trim());
31
+ const head = match?.[1];
32
+ const rest = match?.[2];
33
+ if (head === undefined || rest === undefined || !isWholeHead(head)) return undefined;
34
+ return isBracketedTitle(head) || isRepeatedTitle(head, rest) ? [head, rest] : undefined;
35
+ };
@@ -2,6 +2,7 @@ import { endingTokens, isClosed } from "../sentence-shape.ts";
2
2
  import { enumeratedRuns, enumeratorStarts, numberedStarts } from "./enumerated-runs.ts";
3
3
  import { continuesThrough, groupOf, majorityOf, registerOf, slipsOf, type Register } from "./register.ts";
4
4
  import { isRunInLabel } from "./run-in-label.ts";
5
+ import { labelNoteSentences } from "./register-label-note.ts";
5
6
  import { noticeSentences } from "./notice-paragraph.ts";
6
7
  import { separatePartSentences, trailingPartSentences } from "./register-separate-part.ts";
7
8
  import { askerSentences } from "./asker-voice.ts";
@@ -151,7 +152,10 @@ export const judgedSentences = (doc: ProseDocument, polite: readonly LexiconEntr
151
152
  ...separatePartSentences(doc.sections, registerAt, majority),
152
153
  ...trailingPartSentences(doc.sentences, doc.paragraphs, registerAt, majority),
153
154
  ]);
154
- const found = all.filter((entry) => !notices.has(entry.sentence) && !parts.has(entry.sentence));
155
+ const labelNotes = labelNoteSentences(doc.sentences, doc.source, registerAt);
156
+ const found = all
157
+ .filter((entry) => !notices.has(entry.sentence) && !parts.has(entry.sentence))
158
+ .map((entry) => (labelNotes.has(entry.sentence) ? { ...entry, quiet: true } : entry));
155
159
  const runs = runsOf(
156
160
  doc,
157
161
  found.map((entry) => entry.register),
@@ -7,13 +7,15 @@ import { isNameList } from "./name-list-sentence.ts";
7
7
  import { pageMarkerPattern, pageMarkerSize } from "./page-marker.ts";
8
8
  import { quotedSentenceParts } from "./quoted-sentences.ts";
9
9
  import { isReproduced, reproducedSpans } from "./reproduced-text.ts";
10
+ import { runInTitleParts } from "./run-in-title.ts";
10
11
  import { colonQuotationParts, flattenedTableParts, isGrammarBlock, labelLineParts, parentheticalSentenceParts } from "./sentence-parts.ts";
11
12
  import { isInListItem, isReferenceLine, isTitleLine, quotedTitleWords, remarkAfterTitle, termSeriesSaving } from "./sentence-title.ts";
12
13
 
13
14
  type Measure = { readonly size: number; readonly limit: number; readonly variant?: string };
14
15
 
15
- /** The page markers' pattern, the citation signals ("see"), the era names and the spans of the list items, read once per document. */
16
+ /** The source, the page markers' pattern, the citation signals ("see"), the era names and the spans of the list items, read once per document. */
16
17
  type SentenceWords = {
18
+ readonly source: string;
17
19
  readonly markers: RegExp | undefined;
18
20
  readonly citationSignals: readonly string[];
19
21
  readonly eras: readonly string[];
@@ -66,9 +68,19 @@ const measureOf = (sentence: Sentence, unit: LengthUnit, options: DetectorOption
66
68
  const isUnwritten = (sentence: Sentence, text: string, unit: LengthUnit, words: SentenceWords): boolean =>
67
69
  isGrammarBlock(sentence.text) || isCitationString(text, words.citationSignals) || (unit === "word" && isTitleLine(text));
68
70
 
69
- /** The parts measured one by one when the splitter ran several things into one sentence (label lines, table cells, a quotation). */
70
- const partsOf = (sentence: Sentence, text: string, eras: readonly string[]): readonly string[] | undefined =>
71
- labelLineParts(sentence.text) ?? flattenedTableParts(text, eras) ?? colonQuotationParts(text) ?? parentheticalSentenceParts(text);
71
+ const startsLine = (sentence: Sentence, source: string): boolean => sentence.span.start === 0 || source[sentence.span.start - 1] === "\n";
72
+
73
+ /** A link title run into its blurb, where characters are the unit and the sentence opens a line. */
74
+ const titleParts = (sentence: Sentence, text: string, unit: LengthUnit, source: string): readonly string[] | undefined =>
75
+ unit === "char" && startsLine(sentence, source) ? runInTitleParts(text) : undefined;
76
+
77
+ /** The parts measured one by one when the splitter ran several things into one sentence (label lines, table cells, a quotation, a title). */
78
+ const partsOf = (sentence: Sentence, text: string, unit: LengthUnit, words: SentenceWords): readonly string[] | undefined =>
79
+ labelLineParts(sentence.text) ??
80
+ flattenedTableParts(text, words.eras) ??
81
+ colonQuotationParts(text) ??
82
+ parentheticalSentenceParts(text) ??
83
+ titleParts(sentence, text, unit, words.source);
72
84
 
73
85
  /** The length of a sentence in the document's language, without what the writer did not write as one. */
74
86
  const ownSize = (sentence: Sentence, unit: LengthUnit, words: SentenceWords): number => {
@@ -76,7 +88,7 @@ const ownSize = (sentence: Sentence, unit: LengthUnit, words: SentenceWords): nu
76
88
  if (isUnwritten(sentence, text, unit, words)) return 0;
77
89
  const aroundCitation = unit === "word" ? wordsAroundCitation(text, words.citationSignals) : undefined;
78
90
  if (aroundCitation !== undefined) return sizeOf(aroundCitation, unit);
79
- const parts = partsOf(sentence, text, words.eras);
91
+ const parts = partsOf(sentence, text, unit, words);
80
92
  if (parts !== undefined) return Math.max(0, ...parts.map((part) => sizeOf(part, unit) - pageMarkerSize(part, words.markers, unit)));
81
93
  const remark = unit === "word" ? remarkAfterTitle(text) : undefined;
82
94
  if (remark !== undefined) return sizeOf(remark, unit);
@@ -99,6 +111,7 @@ const subjectTexts = (doc: ProseDocument): ReadonlySet<string> =>
99
111
 
100
112
  export const sentenceLength: Detector = (doc, options): Finding[] => {
101
113
  const words: SentenceWords = {
114
+ source: doc.source,
102
115
  markers: pageMarkerPattern((options.lexicon ?? []).map((entry) => entry.pattern)),
103
116
  citationSignals: (doc.lexicons["citation-signal"] ?? []).map((entry) => entry.pattern),
104
117
  eras: (doc.lexicons["calendar-era"] ?? []).map((entry) => entry.pattern),
@@ -262,8 +262,21 @@ type Step = { readonly start: number; readonly kind: "statement" | "instruction"
262
262
  export const isInstruction = (tokens: readonly Token[]): boolean =>
263
263
  INSTRUCTION_OPENER.has(tokens.find((token) => !SKIPPED.has(token.pos))?.pos ?? "") && !opensAsNounPhrase(tokens);
264
264
 
265
- const kindOf = (tokens: readonly Token[]): Step["kind"] => {
266
- if (isStatement(tokens)) return "statement";
265
+ /**
266
+ * A later sentence that gives an order: it opens with a verb in its base form (Throw that label away). Stricter than
267
+ * isInstruction, whose noun openers (Data is central) are a paragraph's statements once they are not the step's head.
268
+ */
269
+ const givesOrder = (tokens: readonly Token[]): boolean => {
270
+ const head = tokens.find((token) => !SKIPPED.has(token.pos));
271
+ return head?.pos === "VERB" && head.surface.toLowerCase() === head.lemma;
272
+ };
273
+
274
+ /**
275
+ * A step read by its first sentence. One that states what the machine does and then gives the order in a later sentence
276
+ * (The printer feeds a blank label. Throw that label away.) is an instruction: the reader still has something to do.
277
+ */
278
+ const kindOf = (tokens: readonly Token[], later: readonly (readonly Token[])[]): Step["kind"] => {
279
+ if (isStatement(tokens)) return later.some(givesOrder) ? "instruction" : "statement";
267
280
  return isInstruction(tokens) ? "instruction" : "other";
268
281
  };
269
282
 
@@ -273,10 +286,22 @@ const stepLists = (doc: ProseDocument): Step[][] =>
273
286
  .filter((list) => ORDERED_ITEM.test(doc.source.slice(list.span.start, list.span.end)))
274
287
  .map((list) =>
275
288
  list.itemSpans.flatMap((item): Step[] => {
276
- const sentence = doc.sentences.find((candidate) => candidate.span.start >= item.start && candidate.span.start < item.end);
277
- // Only the sentence on the item's own line: a note paragraph under it (**NOTE:** …) is not the step.
278
- const onItemLine = sentence !== undefined && !doc.source.slice(item.start, sentence.span.start).includes("\n");
279
- return sentence?.tokens === undefined || !onItemLine ? [] : [{ start: sentence.span.start, kind: kindOf(sentence.tokens) }];
289
+ // Only the sentences on the item's own line: a note paragraph under it (**NOTE:** …) is not the step.
290
+ const onItemLine = doc.sentences.filter(
291
+ (candidate) =>
292
+ candidate.span.start >= item.start && candidate.span.start < item.end && !doc.source.slice(item.start, candidate.span.start).includes("\n"),
293
+ );
294
+ const [sentence, ...later] = onItemLine;
295
+ if (sentence?.tokens === undefined) return [];
296
+ return [
297
+ {
298
+ start: sentence.span.start,
299
+ kind: kindOf(
300
+ sentence.tokens,
301
+ later.map((next) => next.tokens ?? []),
302
+ ),
303
+ },
304
+ ];
280
305
  }),
281
306
  )
282
307
  .filter((steps) => steps.length >= MIN_STEPS);
@@ -7,7 +7,7 @@ import type { Detector, Finding, ProseDocument, Sentence, Span, Token } from "..
7
7
  import { countedTokens, uncountedWordsOf, type UncountedWords } from "../uncounted-particles.ts";
8
8
  import { boundWordParticles } from "../bound-word-particles.ts";
9
9
  import { setPhraseParticles } from "../set-phrase-particles.ts";
10
- import { clauseEnds, determinerParticles, longestClausePart } from "../clause-particles.ts";
10
+ import { clauseEnds, copulaEnds, determinerParticles, longestClausePart } from "../clause-particles.ts";
11
11
  import { noteSentences } from "../note-paragraphs.ts";
12
12
  import { labelledNoteSentences } from "../labelled-note-paragraphs.ts";
13
13
  import { listLeadSentences } from "../list-lead-sentence.ts";
@@ -175,9 +175,10 @@ export const doubledParticle: Detector = (doc, options): Finding[] => {
175
175
  ...namedLongForms(sentence.text, sentence.span.start, sentence.tokens ?? [], namingMarkers, continuesName),
176
176
  ...quotedNameSpans(sentence.text, sentence.span.start, names),
177
177
  ];
178
- // 「の」で主語を示した節(番号のついた版)の前と後ろは別の句。どちらかの句の中で上限を超える連なりだけを、連なり全体で言う。
178
+ // 「の」で主語を示した節(番号のついた版)や、一つの「の」だけの「である」の節(当社の子会社である法人)の前と後ろは別の句。どちらかの句の中で上限を超える連なりだけを、連なり全体で言う。
179
179
  const ends = clauseEnds(tokens, nesting);
180
- const isLong = (run: Run): boolean => run.tokens.length > options.limit && longestClausePart(run.tokens, ends) > options.limit;
180
+ const copulas = copulaEnds(tokens);
181
+ const isLong = (run: Run): boolean => run.tokens.length > options.limit && longestClausePart(run.tokens, ends, copulas) > options.limit;
181
182
  const longRuns = (skipped: readonly Span[]): Run[] => runsOf(tokens, nesting, breaks, skipped).filter(isLong);
182
183
  const found = longRuns(quoted);
183
184
  // 文書の名前を読むのは長い連なりのある文だけ。名前は位置ごとに読むので、全部の文で読むと遅い。
@@ -2,6 +2,7 @@ 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
4
  import { BLANK_SUFFIX, placeholderSpans } from "./placeholder-text.ts";
5
+ import { addressBlankSpans } from "./address-blank.ts";
5
6
  import { TEMPLATE, isInside, templateSections } from "./template-sections.ts";
6
7
  import { tableBodyCells } from "../facts/table-facts.ts";
7
8
  import { proseAndTablesOf } from "../table-text.ts";
@@ -20,6 +21,17 @@ const cellBlanks = (doc: ProseDocument, lexicon: Lexicon): Finding[] =>
20
21
  })),
21
22
  );
22
23
 
24
+ /** A template's word left as a segment of a web address, read from the whole source: a clone command sits in a code block. */
25
+ const addressBlanks = (doc: ProseDocument, lexicon: Lexicon): Finding[] =>
26
+ addressBlankSpans(doc.source, lexicon).map((span) => ({
27
+ rule: "",
28
+ severity: "info" as const,
29
+ line: 0,
30
+ column: 0,
31
+ quote: (doc.source.slice(doc.source.lastIndexOf("\n", span.start - 1) + 1).split("\n")[0] ?? "").trim(),
32
+ values: { matched: doc.source.slice(span.start, span.end), offset: span.start },
33
+ }));
34
+
23
35
  /**
24
36
  * 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
37
  * a quoted example, or a field label the document fills in elsewhere.
@@ -47,7 +59,7 @@ export const unfilledPlaceholderOutsideTemplates: Detector = (doc, options) => {
47
59
  const words = lexicon.filter((word) => word.group === TEMPLATE);
48
60
  const templates = templateSections(doc.markup?.headings ?? [], doc.source.length, words);
49
61
  const named = isNamedOrExample(doc, lexicon);
50
- return [...unfilledPlaceholder(doc, { ...options, lexicon }), ...cellBlanks(doc, lexicon)]
62
+ return [...unfilledPlaceholder(doc, { ...options, lexicon }), ...cellBlanks(doc, lexicon), ...addressBlanks(doc, lexicon)]
51
63
  .filter((finding) => !isInside(templates, Number(finding.values["offset"])))
52
64
  .filter((finding) => !named(finding))
53
65
  .toSorted((left, right) => Number(left.values["offset"]) - Number(right.values["offset"]));
@@ -3,6 +3,7 @@ import { escapeRegExp } from "../orthography.ts";
3
3
  import { inDocumentOrder } from "./issues.ts";
4
4
  import { isTitleWords } from "./contents-lines.ts";
5
5
  import { verbFormsOf } from "./gerund-phrase.ts";
6
+ import { pointsAhead, type ForwardReference } from "./forward-reference.ts";
6
7
  import {
7
8
  definingNameOf,
8
9
  echoesName,
@@ -395,13 +396,20 @@ const citesSource = (texts: readonly BodyText[], markers: readonly string[], off
395
396
  return markers.some((marker) => before.endsWith(marker) && SOURCE_END.test(before.slice(0, -marker.length)));
396
397
  };
397
398
 
399
+ /** 語に、後ろで定義することを先に断る言葉(下記パブリック・ライセンス)が付いているか。 */
400
+ const pointsAheadAt = (texts: readonly BodyText[], words: readonly ForwardReference[], term: string, offset: number): boolean => {
401
+ const sentence = sentenceAt(texts, offset);
402
+ return sentence !== undefined && pointsAhead(sentence.text, offset - sentence.start, term, words);
403
+ };
404
+
398
405
  /**
399
406
  * 言語の語の一覧。selfPrefixes は文書自身の名前の頭(この、本、this)、sourceMarkers は語の意味の出どころを言う言葉(所定の)、
400
- * singleKanjiNames は前の使用を探す一字の漢字の語(当事者の呼び名の甲・乙)。
407
+ * forwardReferences は読み手を後ろの本文へ向ける言葉(下記、below)、singleKanjiNames は前の使用を探す一字の漢字の語(当事者の呼び名の甲・乙)。
401
408
  */
402
409
  export type EarlyUseWords = {
403
410
  readonly selfPrefixes?: readonly string[];
404
411
  readonly sourceMarkers?: readonly string[];
412
+ readonly forwardReferences?: readonly ForwardReference[];
405
413
  readonly singleKanjiNames?: ReadonlySet<string>;
406
414
  };
407
415
 
@@ -409,7 +417,7 @@ export type EarlyUseWords = {
409
417
  * 文の途中で括弧に入れて定義した語((the "Seller")、以下「甲」という)を、その定義の文より前で使っている所。最初の一つだけ。
410
418
  * 定義の文の中の現れ(株式会社GovTech東京(以下「GovTech東京」という。))は、定義する名前そのものなので数えない。札の文も、
411
419
  * isTitle が言う題・見出し・目次の行も、漢字で終わる語にさらに漢字が続く長い語の一部も、定義の括弧の前の長い名前を写した所も、
412
- * 語を含むもっと長い名前の中も、語の前に意味の出どころを書いた所(69条の3所定の小規模宅地等)も数えない。
420
+ * 語を含むもっと長い名前の中も、語の前に意味の出どころを書いた所(69条の3所定の小規模宅地等)も、後ろで定義することを先に断った所(下記パブリック・ライセンス)とそれより後ろも数えない。
413
421
  * 英語の語を長い名前の終わりに書いた所(The National Security Act of 1947)より後ろの現れ(the Act)は、その名前を指すので数えない。文書自身の名前を定義した語は、selfPrefixes(この、本、this)を付けて前で書いても数えない。
414
422
  * 定義の条("Seller" means、「甲」とは)は条の並びの頭にも終わりにも置く書き方があるので、前で使っても言わない。
415
423
  * 定義の語の無い括弧の引用(("The key point is"))は例の引用と同じ形なので、その語を引用符で挙げただけの現れ
@@ -421,7 +429,7 @@ export const usesBeforeDefinition = (
421
429
  texts: readonly BodyText[],
422
430
  mentioned: Mentioned = NEVER_MENTIONED,
423
431
  isTitle: IsTitle = NEVER_TITLE,
424
- { selfPrefixes = [], sourceMarkers = [], singleKanjiNames = new Set() }: EarlyUseWords = {},
432
+ { selfPrefixes = [], sourceMarkers = [], forwardReferences = [], singleKanjiNames = new Set() }: EarlyUseWords = {},
425
433
  ): TermUse[] => {
426
434
  const inline = terms.filter((term) => term.inline);
427
435
  const names = definingNames(terms, texts);
@@ -432,9 +440,11 @@ export const usesBeforeDefinition = (
432
440
  const defining = sentenceAt(texts, defined.span.start)?.start ?? defined.span.start;
433
441
  const uses = usesOf(defined.term, texts, spans, "exact", defined.bare === true ? mentioned : NEVER_MENTIONED).filter((offset) => offset < defining);
434
442
  const namedFirst = uses.find((offset) => endsNameAt(texts, defined.term, offset));
443
+ const announced = uses.find((offset) => pointsAheadAt(texts, forwardReferences, defined.term, offset));
435
444
  const first = uses.find(
436
445
  (offset) =>
437
446
  !(namedFirst !== undefined && namedFirst < offset) &&
447
+ !(announced !== undefined && announced <= offset) &&
438
448
  !isLabel(sentenceAt(texts, offset), defined.term) &&
439
449
  !headsDefiningSentence(sentenceAt(texts, offset), defining) &&
440
450
  !insideCaption(sentenceAt(texts, offset), offset) &&
@@ -0,0 +1,21 @@
1
+ /** 読み手を後ろの本文へ向ける言葉と、それが語のどちら側に立つか(下記、the following は前、below は後ろ)。 */
2
+ export type ForwardReference = { readonly pattern: string; readonly position?: "before" | "after" | undefined };
3
+
4
+ const LATIN_LETTER = /\p{Script=Latin}/u;
5
+
6
+ /** 言葉の端の字と、その外の字が、英語の一つの語に続いていないか(below は belowground の頭ではない)。 */
7
+ const meetsAtWordEdge = (edge: string, outside: string): boolean => !LATIN_LETTER.test(edge) || !LATIN_LETTER.test(outside);
8
+
9
+ /** 文の中の語に、後ろで定義することを先に断る言葉(下記パブリック・ライセンス、the Licence below)が付いているか。 */
10
+ export const pointsAhead = (sentence: string, at: number, term: string, words: readonly ForwardReference[]): boolean => {
11
+ const before = sentence.slice(0, at).trimEnd().toLowerCase();
12
+ const after = sentence
13
+ .slice(at + term.length)
14
+ .trimStart()
15
+ .toLowerCase();
16
+ return words.some(({ pattern, position }) => {
17
+ const word = pattern.toLowerCase();
18
+ if (position === "after") return after.startsWith(word) && meetsAtWordEdge(word.slice(-1), after.charAt(word.length));
19
+ return before.endsWith(word) && meetsAtWordEdge(word.charAt(0), before.charAt(before.length - word.length - 1));
20
+ });
21
+ };
@@ -184,6 +184,20 @@ const closesIfNewSubject = (tokens: readonly Token[], at: number): boolean => {
184
184
  return token?.pos === "VERB" && token.lemma === "おる" && token.features?.["Bound"] === "Yes";
185
185
  };
186
186
 
187
+ /** Verbs of receiving a favour (〜していただく, 〜してもらう): their doer is the one asked, not the speaker. */
188
+ const BENEFACTIVE = new Set(["いただく", "いただける", "くださる", "もらう", "もらえる"]);
189
+
190
+ /** The forms that make a favour a request or a hope: 〜いただけると, 〜いただければ, 〜いただきたい. The tagger reads と as either. */
191
+ const isRequestForm = (token: Token | undefined): boolean =>
192
+ ((token?.pos === "SCONJ" || token?.pos === "ADP") && (token.surface === "と" || token.surface === "ば")) || (token?.pos === "AUX" && token.lemma === "たい");
193
+
194
+ /**
195
+ * 〜を示していただけると…つながるのではないか: past at, the speaker asks for a favour. What follows is the speaker's request, so a
196
+ * clause that may close the topic's predicate does close it, though no subject of its own is spelt out.
197
+ */
198
+ const requestAfter = (tokens: readonly Token[], at: number, last: number): boolean =>
199
+ tokens.some((token, index) => index > at && index < last && BENEFACTIVE.has(token.lemma ?? "") && isRequestForm(tokens[index + 1]));
200
+
187
201
  /** The words a document's language gives for the shapes below (lang-ja's lexicons). Without them, only the shapes that need none. */
188
202
  export type TopicClauseWords = {
189
203
  /** Words that end a clause right after its predicate (ことから, つつ, としても): the topic-clause-close lexicon. */
@@ -246,14 +260,19 @@ const frameTopicAfter = (tokens: readonly Token[], at: number, last: number): bo
246
260
  /** A word of a name (赤澤, 大臣), not a noun that sets the time or the case (今後, 当日). */
247
261
  const isNameWord = (token: Token): boolean => NOMINAL.has(token.pos) && token.features?.["Adverbial"] !== "Yes";
248
262
 
263
+ /** A prefix bound to the noun after it (本事業, 同社, 各部): the tagger reads it as a bound adjective. */
264
+ const isNounPrefix = (token: Token | undefined): boolean => token?.pos === "ADJ" && token.features?.["Bound"] === "Yes";
265
+
249
266
  /**
250
- * 石破総理大臣は…明らかにしましたが、赤澤大臣は…どう考えているか: a name and は straight after the comma is a topic of its own
251
- * that the rest of the sentence is said of, when no subject of its own (が) follows it. A phrase before は (〜した行為は) is not one.
267
+ * 石破総理大臣は…明らかにしましたが、赤澤大臣は…どう考えているか / 〜しておりますが、本事業は、…: a noun (a prefix may stand before
268
+ * it) and は straight after the comma is a topic of its own that the rest of the sentence is said of, when no subject of its own
269
+ * (が) follows it. A phrase before は (〜した行為は) is not one.
252
270
  */
253
271
  const newNameTopicRunsToEnd = (tokens: readonly Token[], comma: number, last: number): boolean => {
254
- const topic = tokens.findIndex((token, index) => index > comma && !isNameWord(token));
272
+ const start = isNounPrefix(tokens[comma + 1]) ? comma + 2 : comma + 1;
273
+ const topic = tokens.findIndex((token, index) => index >= start && !isNameWord(token));
255
274
  const wa = tokens[topic];
256
- return topic > comma + 1 && wa !== undefined && isParticle(wa, "は") && lastOwnSubject(tokens, last) <= topic;
275
+ return topic > start && wa !== undefined && isParticle(wa, "は") && lastOwnSubject(tokens, last) <= topic;
257
276
  };
258
277
 
259
278
  /** A topic on the nominaliser こと after a predicate (公表することは): an act made a noun. */
@@ -338,7 +357,7 @@ export const topicClauseEnd = (tokens: readonly Token[], topic: number, last: nu
338
357
  const subject = lastOwnSubject(tokens, last);
339
358
  const closes = (at: number): boolean =>
340
359
  closesSurely(tokens, at, last) ||
341
- (closesIfNewSubject(tokens, at) && subject > at) ||
360
+ (closesIfNewSubject(tokens, at) && (subject > at || requestAfter(tokens, at, last))) ||
342
361
  closesWithCopulaContinuing(tokens, topic, at, last, subject) ||
343
362
  closesFirstClauseWithNoun(tokens, topic, at, last) ||
344
363
  closesWithPoliteGa(tokens, topic, at, last, subject) ||