chaffjs 0.46.0 → 0.48.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 (192) hide show
  1. package/dist/bound-word-particles.d.ts +1 -0
  2. package/dist/bound-word-particles.d.ts.map +1 -1
  3. package/dist/bound-word-particles.js +1 -1
  4. package/dist/bound-word-particles.js.map +1 -1
  5. package/dist/clause-particles.d.ts +11 -0
  6. package/dist/clause-particles.d.ts.map +1 -0
  7. package/dist/clause-particles.js +20 -0
  8. package/dist/clause-particles.js.map +1 -0
  9. package/dist/detectors/acronym-definition.d.ts.map +1 -1
  10. package/dist/detectors/acronym-definition.js +14 -6
  11. package/dist/detectors/acronym-definition.js.map +1 -1
  12. package/dist/detectors/acronym-expansion.d.ts +2 -0
  13. package/dist/detectors/acronym-expansion.d.ts.map +1 -1
  14. package/dist/detectors/acronym-expansion.js +18 -7
  15. package/dist/detectors/acronym-expansion.js.map +1 -1
  16. package/dist/detectors/acronym-mention.d.ts.map +1 -1
  17. package/dist/detectors/acronym-mention.js +3 -1
  18. package/dist/detectors/acronym-mention.js.map +1 -1
  19. package/dist/detectors/acronym-parent-item.d.ts +6 -0
  20. package/dist/detectors/acronym-parent-item.d.ts.map +1 -0
  21. package/dist/detectors/acronym-parent-item.js +50 -0
  22. package/dist/detectors/acronym-parent-item.js.map +1 -0
  23. package/dist/detectors/bold-label.d.ts +6 -1
  24. package/dist/detectors/bold-label.d.ts.map +1 -1
  25. package/dist/detectors/bold-label.js +12 -1
  26. package/dist/detectors/bold-label.js.map +1 -1
  27. package/dist/detectors/broken-link.d.ts.map +1 -1
  28. package/dist/detectors/broken-link.js +14 -0
  29. package/dist/detectors/broken-link.js.map +1 -1
  30. package/dist/detectors/char-shape.js +1 -1
  31. package/dist/detectors/char-shape.js.map +1 -1
  32. package/dist/detectors/citation-sentence.d.ts +8 -0
  33. package/dist/detectors/citation-sentence.d.ts.map +1 -1
  34. package/dist/detectors/citation-sentence.js +24 -0
  35. package/dist/detectors/citation-sentence.js.map +1 -1
  36. package/dist/detectors/closing-cliche.d.ts +2 -1
  37. package/dist/detectors/closing-cliche.d.ts.map +1 -1
  38. package/dist/detectors/closing-cliche.js +10 -2
  39. package/dist/detectors/closing-cliche.js.map +1 -1
  40. package/dist/detectors/concrete-evidence-density.d.ts.map +1 -1
  41. package/dist/detectors/concrete-evidence-density.js +13 -6
  42. package/dist/detectors/concrete-evidence-density.js.map +1 -1
  43. package/dist/detectors/concrete-evidence.d.ts +7 -1
  44. package/dist/detectors/concrete-evidence.d.ts.map +1 -1
  45. package/dist/detectors/concrete-evidence.js +45 -0
  46. package/dist/detectors/concrete-evidence.js.map +1 -1
  47. package/dist/detectors/doubled-punctuation.d.ts.map +1 -1
  48. package/dist/detectors/doubled-punctuation.js +14 -4
  49. package/dist/detectors/doubled-punctuation.js.map +1 -1
  50. package/dist/detectors/en-shape.d.ts.map +1 -1
  51. package/dist/detectors/en-shape.js +9 -5
  52. package/dist/detectors/en-shape.js.map +1 -1
  53. package/dist/detectors/fullwidth-alnum.d.ts +4 -0
  54. package/dist/detectors/fullwidth-alnum.d.ts.map +1 -1
  55. package/dist/detectors/fullwidth-alnum.js +31 -9
  56. package/dist/detectors/fullwidth-alnum.js.map +1 -1
  57. package/dist/detectors/law-governed.d.ts +10 -0
  58. package/dist/detectors/law-governed.d.ts.map +1 -0
  59. package/dist/detectors/law-governed.js +41 -0
  60. package/dist/detectors/law-governed.js.map +1 -0
  61. package/dist/detectors/lexicon.d.ts.map +1 -1
  62. package/dist/detectors/lexicon.js +17 -3
  63. package/dist/detectors/lexicon.js.map +1 -1
  64. package/dist/detectors/name-variant-two-things.d.ts +2 -1
  65. package/dist/detectors/name-variant-two-things.d.ts.map +1 -1
  66. package/dist/detectors/name-variant-two-things.js +9 -3
  67. package/dist/detectors/name-variant-two-things.js.map +1 -1
  68. package/dist/detectors/open-end-names.d.ts +7 -2
  69. package/dist/detectors/open-end-names.d.ts.map +1 -1
  70. package/dist/detectors/open-end-names.js +14 -4
  71. package/dist/detectors/open-end-names.js.map +1 -1
  72. package/dist/detectors/requirement-smell.d.ts.map +1 -1
  73. package/dist/detectors/requirement-smell.js +6 -2
  74. package/dist/detectors/requirement-smell.js.map +1 -1
  75. package/dist/detectors/sentence-length.js +5 -5
  76. package/dist/detectors/sentence-length.js.map +1 -1
  77. package/dist/detectors/sentence-parts.d.ts +2 -0
  78. package/dist/detectors/sentence-parts.d.ts.map +1 -1
  79. package/dist/detectors/sentence-parts.js +10 -0
  80. package/dist/detectors/sentence-parts.js.map +1 -1
  81. package/dist/detectors/signals.d.ts.map +1 -1
  82. package/dist/detectors/signals.js +3 -0
  83. package/dist/detectors/signals.js.map +1 -1
  84. package/dist/detectors/space-before-punctuation.js +3 -3
  85. package/dist/detectors/space-before-punctuation.js.map +1 -1
  86. package/dist/detectors/token-shape.d.ts.map +1 -1
  87. package/dist/detectors/token-shape.js +21 -5
  88. package/dist/detectors/token-shape.js.map +1 -1
  89. package/dist/detectors/topic-predicate-distance.d.ts.map +1 -1
  90. package/dist/detectors/topic-predicate-distance.js +3 -1
  91. package/dist/detectors/topic-predicate-distance.js.map +1 -1
  92. package/dist/detectors/unbalanced-bracket.d.ts.map +1 -1
  93. package/dist/detectors/unbalanced-bracket.js +31 -6
  94. package/dist/detectors/unbalanced-bracket.js.map +1 -1
  95. package/dist/detectors/unknown-word-context.d.ts +8 -0
  96. package/dist/detectors/unknown-word-context.d.ts.map +1 -1
  97. package/dist/detectors/unknown-word-context.js +38 -6
  98. package/dist/detectors/unknown-word-context.js.map +1 -1
  99. package/dist/detectors/unknown-word.d.ts.map +1 -1
  100. package/dist/detectors/unknown-word.js +11 -4
  101. package/dist/detectors/unknown-word.js.map +1 -1
  102. package/dist/detectors/vague-density.d.ts +4 -2
  103. package/dist/detectors/vague-density.d.ts.map +1 -1
  104. package/dist/detectors/vague-density.js +17 -9
  105. package/dist/detectors/vague-density.js.map +1 -1
  106. package/dist/document.js +2 -2
  107. package/dist/document.js.map +1 -1
  108. package/dist/name-variant-shapes.d.ts +22 -0
  109. package/dist/name-variant-shapes.d.ts.map +1 -1
  110. package/dist/name-variant-shapes.js +63 -0
  111. package/dist/name-variant-shapes.js.map +1 -1
  112. package/dist/paragraph-length.d.ts.map +1 -1
  113. package/dist/paragraph-length.js +5 -6
  114. package/dist/paragraph-length.js.map +1 -1
  115. package/dist/sentence-load.d.ts.map +1 -1
  116. package/dist/sentence-load.js +20 -6
  117. package/dist/sentence-load.js.map +1 -1
  118. package/dist/structure/definition-use.d.ts.map +1 -1
  119. package/dist/structure/definition-use.js +13 -0
  120. package/dist/structure/definition-use.js.map +1 -1
  121. package/dist/structure/universal.d.ts.map +1 -1
  122. package/dist/structure/universal.js +9 -1
  123. package/dist/structure/universal.js.map +1 -1
  124. package/dist/structure/unread-label.d.ts.map +1 -1
  125. package/dist/structure/unread-label.js +3 -1
  126. package/dist/structure/unread-label.js.map +1 -1
  127. package/dist/topic-clause.d.ts +2 -0
  128. package/dist/topic-clause.d.ts.map +1 -1
  129. package/dist/topic-clause.js.map +1 -1
  130. package/package.json +3 -3
  131. package/rules/adverb-overuse.yaml +2 -2
  132. package/rules/ai-tell.yaml +2 -2
  133. package/rules/bold-label-list.yaml +2 -2
  134. package/rules/bracket-nesting.yaml +2 -2
  135. package/rules/broken-link.yaml +2 -2
  136. package/rules/closing-cliche.yaml +2 -2
  137. package/rules/concrete-evidence-density.yaml +2 -2
  138. package/rules/date-outside-period.yaml +1 -1
  139. package/rules/doubled-punctuation.yaml +2 -2
  140. package/rules/fullwidth-alnum-consistency.yaml +2 -2
  141. package/rules/max-kanji-continuous.yaml +4 -3
  142. package/rules/max-sentence-length.yaml +2 -2
  143. package/rules/name-variant.yaml +2 -2
  144. package/rules/ngram-repetition.yaml +2 -2
  145. package/rules/no-doubled-joshi.yaml +2 -2
  146. package/rules/requirement-smell.yaml +2 -2
  147. package/rules/space-before-punctuation.yaml +4 -4
  148. package/rules/taigen-dome-in-prose.yaml +2 -2
  149. package/rules/topic-predicate-distance.yaml +3 -3
  150. package/rules/unbalanced-bracket.yaml +4 -4
  151. package/rules/undefined-acronym.yaml +2 -0
  152. package/rules/unknown-word.yaml +2 -2
  153. package/rules/vague-word-density.yaml +2 -2
  154. package/src/bound-word-particles.ts +2 -1
  155. package/src/clause-particles.ts +35 -0
  156. package/src/detectors/acronym-definition.ts +14 -6
  157. package/src/detectors/acronym-expansion.ts +26 -7
  158. package/src/detectors/acronym-mention.ts +6 -1
  159. package/src/detectors/acronym-parent-item.ts +60 -0
  160. package/src/detectors/bold-label.ts +17 -2
  161. package/src/detectors/broken-link.ts +16 -0
  162. package/src/detectors/char-shape.ts +2 -2
  163. package/src/detectors/citation-sentence.ts +30 -0
  164. package/src/detectors/closing-cliche.ts +19 -3
  165. package/src/detectors/concrete-evidence-density.ts +18 -7
  166. package/src/detectors/concrete-evidence.ts +56 -1
  167. package/src/detectors/doubled-punctuation.ts +20 -4
  168. package/src/detectors/en-shape.ts +9 -5
  169. package/src/detectors/fullwidth-alnum.ts +39 -10
  170. package/src/detectors/law-governed.ts +50 -0
  171. package/src/detectors/lexicon.ts +19 -4
  172. package/src/detectors/name-variant-two-things.ts +18 -3
  173. package/src/detectors/open-end-names.ts +21 -4
  174. package/src/detectors/requirement-smell.ts +6 -2
  175. package/src/detectors/sentence-length.ts +5 -5
  176. package/src/detectors/sentence-parts.ts +12 -0
  177. package/src/detectors/signals.ts +3 -0
  178. package/src/detectors/space-before-punctuation.ts +3 -3
  179. package/src/detectors/token-shape.ts +27 -7
  180. package/src/detectors/topic-predicate-distance.ts +3 -1
  181. package/src/detectors/unbalanced-bracket.ts +39 -7
  182. package/src/detectors/unknown-word-context.ts +44 -6
  183. package/src/detectors/unknown-word.ts +16 -3
  184. package/src/detectors/vague-density.ts +25 -10
  185. package/src/document.ts +2 -2
  186. package/src/name-variant-shapes.ts +74 -0
  187. package/src/paragraph-length.ts +8 -9
  188. package/src/sentence-load.ts +29 -6
  189. package/src/structure/definition-use.ts +15 -0
  190. package/src/structure/universal.ts +10 -1
  191. package/src/structure/unread-label.ts +3 -1
  192. package/src/topic-clause.ts +2 -0
@@ -120,7 +120,13 @@ const isNamedBeforeAt = (body: string, acronym: string, at: number): boolean =>
120
120
  */
121
121
  export type DefinitionWords = { readonly markers: readonly string[]; readonly verbs: readonly string[]; readonly alternatives?: readonly string[] };
122
122
 
123
- type DefinitionPatterns = { readonly opened: RegExp; readonly closes: RegExp; readonly alternative: RegExp; readonly otherName: RegExp };
123
+ type DefinitionPatterns = {
124
+ readonly opened: RegExp;
125
+ readonly closes: RegExp;
126
+ readonly alternative: RegExp;
127
+ readonly quotedAlternative: RegExp;
128
+ readonly otherName: RegExp;
129
+ };
124
130
 
125
131
  const oneOf = (words: readonly string[]): string => (words.length === 0 ? "(?!)" : words.map(escapeRegExp).join("|"));
126
132
 
@@ -128,6 +134,7 @@ const definitionPatterns = (words: DefinitionWords): DefinitionPatterns => ({
128
134
  opened: new RegExp(String.raw`[((]\s*(?<markers>(?:(?:${oneOf(words.markers)})${MARKER_GAP})*)${WRAP}(?<![A-Za-z])$`, "iu"),
129
135
  closes: new RegExp(String.raw`^${WRAP}(?<verb>(?:${oneOf(words.verbs)})[。.]?)?${WRAP}[))]`, "iu"),
130
136
  alternative: new RegExp(String.raw`[,,、]\s*(?:${oneOf(words.alternatives ?? [])})\s*["“'‘]?$`, "iu"),
137
+ quotedAlternative: new RegExp(String.raw`(?<=["”'’])\s(?:${oneOf(words.alternatives ?? [])})\s*["“'‘]?$`, "iu"),
131
138
  otherName: new RegExp(String.raw`^${WRAP}[,,、]?\s*(?:${oneOf(words.alternatives ?? [])})\s[^()()\n]{1,${String(DEFINITION_REACH)}}[))]`, "iu"),
132
139
  });
133
140
 
@@ -244,13 +251,25 @@ const isPrefixedAt = (body: string, acronym: string, at: number): boolean => {
244
251
  /** 引用符で囲んで書き終えた名前(‘abstract syntax tree’)。小文字の語でも、囲みが名前の始まりと終わりを決める。 */
245
252
  const QUOTED_NAME_END = /(?:“(?<curly>[^“”\n]{1,60})”|‘(?<single>[^‘’\n]{1,60})’|"(?<straight>[^"\n]{1,60})")$/u;
246
253
 
247
- /** 名前の後ろの読点と言い換えの語に続く略語(Special Interest Groups, or SIGs、‘abstract syntax tree’, or ‘AST’)。名前の頭文字が略語と揃うときだけ。 */
254
+ const quotedNameBefore = (name: string): string | undefined => {
255
+ const groups = QUOTED_NAME_END.exec(name)?.groups;
256
+ return groups?.["curly"] ?? groups?.["single"] ?? groups?.["straight"];
257
+ };
258
+
259
+ /**
260
+ * 名前の後ろの読点と言い換えの語に続く略語(Special Interest Groups, or SIGs、‘abstract syntax tree’, or ‘AST’)。名前の頭文字が略語と揃うときだけ。
261
+ * 引用符で囲んだ名前なら読点が無くてもよい(“subject matter experts” or SME)。囲みが名前の終わりを決める。
262
+ */
248
263
  const isAlternativeAt = (patterns: DefinitionPatterns, body: string, acronym: string, at: number): boolean => {
249
- const joined = patterns.alternative.exec(body.slice(Math.max(0, at - DEFINITION_REACH), at));
250
- if (joined === null) return false;
264
+ const before = body.slice(Math.max(0, at - DEFINITION_REACH), at);
265
+ const joined = patterns.alternative.exec(before);
266
+ if (joined === null) {
267
+ const quotedJoin = patterns.quotedAlternative.exec(before);
268
+ const quoted = quotedJoin === null ? undefined : quotedNameBefore(body.slice(0, at - quotedJoin[0].length));
269
+ return quoted !== undefined && namesAcronym(quoted, acronym);
270
+ }
251
271
  const name = body.slice(0, at - joined[0].length);
252
- const groups = QUOTED_NAME_END.exec(name)?.groups;
253
- const quoted = groups?.["curly"] ?? groups?.["single"] ?? groups?.["straight"];
272
+ const quoted = quotedNameBefore(name);
254
273
  return spellsOut(name, acronym) || (quoted !== undefined && namesAcronym(quoted, acronym));
255
274
  };
256
275
 
@@ -363,7 +382,7 @@ const CLOSING_FENCE = /^ {0,3}(?<fence>`{3,}|~{3,})\s*$/u;
363
382
  const closes = (line: string, open: string): boolean => CLOSING_FENCE.exec(line)?.groups?.["fence"]?.startsWith(open) === true;
364
383
 
365
384
  /** コードの囲みの中の行(開き・閉じの行も)を空にする。閉じるのは同じ記号で、開きと同じか長い並び。 */
366
- const withoutFences = (lines: readonly string[]): string[] =>
385
+ export const withoutFences = (lines: readonly string[]): string[] =>
367
386
  lines.reduce<FenceScan>(
368
387
  (scan, line) => {
369
388
  const fence = FENCE.exec(line)?.groups?.["fence"];
@@ -36,11 +36,16 @@ export const spelledOutAcronyms = (sentences: readonly string[], mentions: reado
36
36
  .flatMap((sentence) => (sentence.match(ACRONYM) ?? []).filter((acronym) => spellsOutInWords(sentence, acronym))),
37
37
  );
38
38
 
39
+ /** Capitals and a plural s (CRs): the plural of a shorter acronym (CR), not the longer one (CRS) set in other capitals. */
40
+ const PLURAL_OF_CAPITALS = /^\p{Lu}+s$/u;
41
+
39
42
  /** The other ways the text capitalises an acronym (TCoP for TCOP, TCOP for TCoP), each with two capitals or more. */
40
43
  export const caseVariantsIn = (text: string, acronym: string): string[] => {
41
44
  const written = new RegExp(String.raw`(?<![\p{L}\p{N}])${escapeRegExp(acronym)}(?![\p{L}\p{N}])`, "giu");
42
45
  const variants = [...text.matchAll(written)].map((match) => match[0]);
43
- return [...new Set(variants)].filter((variant) => variant !== acronym && (variant.match(CAPITAL) ?? []).length >= MIN_CAPITALS);
46
+ return [...new Set(variants)].filter(
47
+ (variant) => variant !== acronym && (variant.match(CAPITAL) ?? []).length >= MIN_CAPITALS && !PLURAL_OF_CAPITALS.test(variant),
48
+ );
44
49
  };
45
50
 
46
51
  /** A name in capitals that the text also writes as a word is that word set in capitals; short capitals (IT, It) are left alone. */
@@ -0,0 +1,60 @@
1
+ import { withoutFences } from "./acronym-expansion.ts";
2
+
3
+ /** 箇条書きの項目の行。字下げの幅と、印の後ろの文。 */
4
+ const LIST_ITEM = /^(?<indent>[ \t]*)(?:[-*+]|\d+[.)])\s+(?<text>(?:\S.*)?)$/u;
5
+ const ITEM_ACRONYM = /(?<![\p{L}\p{N}_&])(?<acronym>[A-Z]{2,10})s?(?![\p{L}\p{N}_&])/gu;
6
+ /** 親の項目の名前の語の短さの下限。of や to の頭文字は、2 字の略語にたまたま揃いやすい。 */
7
+ const MIN_PARENT_WORD = 3;
8
+
9
+ type ListItem = { readonly text: string; readonly children: string };
10
+
11
+ const indentOf = (line: string): number => (/^[ \t]*/u.exec(line)?.[0] ?? "").length;
12
+
13
+ /** at から始まる項目の、自分の文(続きの行も)と、それより深く字下げした子の項目の文。 */
14
+ const itemAt = (lines: readonly string[], at: number): ListItem | undefined => {
15
+ const item = LIST_ITEM.exec(lines[at] ?? "")?.groups;
16
+ if (item === undefined) return undefined;
17
+ const indent = (item["indent"] ?? "").length;
18
+ const endIndex = lines.findIndex((line, index) => index > at && line.trim() !== "" && indentOf(line) <= indent);
19
+ const block = lines.slice(at + 1, endIndex === -1 ? lines.length : endIndex);
20
+ const firstChild = block.findIndex((line) => LIST_ITEM.test(line));
21
+ const own = firstChild === -1 ? block : block.slice(0, firstChild);
22
+ const children = firstChild === -1 ? [] : block.slice(firstChild);
23
+ return { text: [item["text"] ?? "", ...own].join(" "), children: children.join("\n") };
24
+ };
25
+
26
+ /** リンクの行き先と URL。アドレスの語(…/cross-project-council/…)は、書き手が書いた名前ではない。 */
27
+ const LINK_TARGET = /\]\([^()\s]*\)/gu;
28
+ const BARE_URL = /\bhttps?:\/\/\S+/gu;
29
+
30
+ const withoutAddresses = (text: string): string => text.replace(LINK_TARGET, "]").replace(BARE_URL, " ");
31
+
32
+ /** 文の中に、略語の文字を頭文字に持つ語が続けて並ぶか(product owner → PO)。大文字小文字を問わず、短い語は数えない。 */
33
+ const spelledByRun = (text: string, acronym: string): boolean => {
34
+ const letters = [...acronym.toLowerCase()];
35
+ const words =
36
+ withoutAddresses(text)
37
+ .toLowerCase()
38
+ .match(/\p{L}+/gu) ?? [];
39
+ const runStartsAt = (start: number): boolean =>
40
+ letters.every((letter, offset) => {
41
+ const word = words[start + offset] ?? "";
42
+ return word.length >= MIN_PARENT_WORD && word.startsWith(letter);
43
+ });
44
+ return words.some((_, start) => runStartsAt(start));
45
+ };
46
+
47
+ /**
48
+ * 子の項目で使う略語のうち、親の項目がその名前を書き出しているもの(- **No product owner:** … の下の - Unavailable PO: …)。
49
+ * 入れ子の箇条書きでは、親の項目が子の項目の話題を名指すので、親の語の頭文字が略語と揃えば展開と読む。
50
+ */
51
+ export const parentItemAcronyms = (source: string): ReadonlySet<string> => {
52
+ const lines = withoutFences(source.split(/\r?\n/u));
53
+ return new Set(
54
+ lines.flatMap((_, index) => {
55
+ const item = itemAt(lines, index);
56
+ if (item === undefined || item.children === "") return [];
57
+ return [...item.children.matchAll(ITEM_ACRONYM)].map((match) => match.groups?.["acronym"] ?? "").filter((acronym) => spelledByRun(item.text, acronym));
58
+ }),
59
+ );
60
+ };
@@ -1,4 +1,4 @@
1
- import type { Detector, DetectorOptions, Finding, Paragraph, ProseDocument, Span, Token } from "../plugin.ts";
1
+ import type { Detector, DetectorOptions, Finding, Lexicon, Paragraph, ProseDocument, Span, Token } from "../plugin.ts";
2
2
 
3
3
  /** A bold run longer than this is a bold sentence, not a label. */
4
4
  const MAX_LABEL_CHARS = 40;
@@ -161,6 +161,17 @@ const boldStatementOf = (doc: ProseDocument, paragraph: Paragraph): string | und
161
161
  return isStatement(tokens) || (run.stopped && isImperativeSentence(tokens)) ? run.words.replace(/[.!。!]$/u, "") : undefined;
162
162
  };
163
163
 
164
+ /**
165
+ * A label that states a gain (**More timely:**, **Less work:**, **作業時間の削減**:): a claim, like a bold lead sentence, not
166
+ * the name of a step or a field. The lexicon says whether its word stands before the quality (More) or after it (削減).
167
+ */
168
+ export const isBenefitLabel = (label: string, words: Lexicon): boolean =>
169
+ words.some((entry) =>
170
+ entry.position === "after"
171
+ ? label.length > entry.pattern.length && label.endsWith(entry.pattern)
172
+ : label.toLowerCase().split(/\s+/u)[0] === entry.pattern.toLowerCase() && label.includes(" "),
173
+ );
174
+
164
175
  /** The count reported and the limit it reached: all the labelled items, or else the bold lead sentences alone, or undefined. */
165
176
  const reached = (items: readonly Span[], leads: number, options: DetectorOptions): { count: number; limit: number } | undefined => {
166
177
  if (items.length >= options.limit) return { count: items.length, limit: options.limit };
@@ -202,7 +213,11 @@ const statementParagraphs = (doc: ProseDocument, options: DetectorOptions): Find
202
213
  export const boldLabelList: Detector = (doc, options): Finding[] => {
203
214
  const items = captionItems(doc, labelOrLeadOf);
204
215
  const first = items[0];
205
- const leads = items.filter((span) => boldLabelOf(doc.source.slice(span.start, span.end)) === undefined).length;
216
+ const benefitWords = doc.lexicons["benefit-label"] ?? [];
217
+ const leads = items.filter((span) => {
218
+ const label = boldLabelOf(doc.source.slice(span.start, span.end));
219
+ return label === undefined || isBenefitLabel(label, benefitWords);
220
+ }).length;
206
221
  const found = reached(items, leads, options);
207
222
  const paragraphs = statementParagraphs(doc, options);
208
223
  if (first === undefined || found === undefined) return paragraphs;
@@ -68,6 +68,21 @@ const REFERENCE_LIKE = /(?<![\\A-Za-z0-9_\]])\[([^[\]\n]+)\]\[([^[\]\n]*)\]/gu;
68
68
  /** 数だけの括弧([1][2]、[3, 4])は、参照の記法ではなく文献の番号を並べたもの。 */
69
69
  const CITATION_NUMBERS = /^[\d\s,,、–-]+$/u;
70
70
 
71
+ /**
72
+ * ファイルの種類と大きさの札([PDF:47KB]、[PDFファイル/269KB]、[Excel 28 KB])。役所のページがリンクの後ろに書く添え書きで、
73
+ * 写すと字のまま残る。名前の定義で呼ぶ参照の記法ではない。
74
+ */
75
+ const FILE_SIZE = /^\d[\d.,]*\s*(?:[KMGT]i?B|bytes?|バイト)$/iu;
76
+ const FILE_TYPE_PREFIX = /^\p{L}[\p{L}\p{N}]*(?:\s*[:://、,,]\s*|\s+)/u;
77
+
78
+ const isFileSizeLabel = (text: string): boolean => {
79
+ if (FILE_SIZE.test(text)) return true;
80
+ const prefix = FILE_TYPE_PREFIX.exec(text)?.[0];
81
+ return prefix !== undefined && FILE_SIZE.test(text.slice(prefix.length));
82
+ };
83
+
84
+ const fileSizeLabel = (match: RegExpMatchArray): boolean => isFileSizeLabel(match[1] ?? "") || isFileSizeLabel(match[2] ?? "");
85
+
71
86
  /** 画像の参照(`![alt][label]`)の頭の印。指摘の範囲に含める。 */
72
87
  const IMAGE_MARK = "!";
73
88
 
@@ -118,6 +133,7 @@ export const unresolvedReferences = (source: string, markup: Markup): Span[] =>
118
133
  return markup.texts.flatMap((text) =>
119
134
  [...source.slice(text.start, text.end).matchAll(REFERENCE_LIKE)]
120
135
  .filter((match) => !CITATION_NUMBERS.test(match[1] ?? "") && !siteDefinedImage(source, text.start + match.index, match[2] ?? ""))
136
+ .filter((match) => !fileSizeLabel(match))
121
137
  .filter((match) => !CHARACTER_CLASS.test(match[1] ?? "") && !CHARACTER_CLASS.test(match[2] ?? "") && !bookDefined(match[2] ?? ""))
122
138
  .map((match) => ({ start: text.start + match.index, end: text.start + match.index + match[0].length }))
123
139
  .map((span) => (imageAt(source, span.start) ? { start: span.start - 1, end: span.end } : span)),
@@ -138,7 +138,7 @@ type NameWords = {
138
138
  readonly addressees: AddresseeWords;
139
139
  /** 前に書いたものを指す語(上記、当該)。連なりの頭にあれば、後ろの語に付いた指示の語。 */
140
140
  readonly references: readonly string[];
141
- /** 並べた物の後ろに付く語(等)。連なりの尻にあれば、名前の後ろに付いた語。 */
141
+ /** 並べた物の後ろに付く語(等)と、範囲の端や除くものを示す語(以外、以上)。連なりの尻にあれば、名前の後ろに付いた語。 */
142
142
  readonly listSuffixes: readonly string[];
143
143
  /** 連なりを閉じる、読み手が一つの語と知っている長い語(内閣総理大臣、許可事業者)。その前で連なりを割る。 */
144
144
  readonly knownWords: ReadonlySet<string>;
@@ -363,7 +363,7 @@ const nameWordsOf = (doc: ProseDocument): NameWords => {
363
363
  addressee: patterns("addressee-suffix"),
364
364
  addressees: { prefixes: patterns("addressee-prefix"), titles: patterns("addressee-title"), endings: organisation.units, forms: organisation.closingForms },
365
365
  references: patterns("reference-prefix"),
366
- listSuffixes: patterns("list-suffix"),
366
+ listSuffixes: [...patterns("list-suffix"), ...patterns("range-suffix")],
367
367
  knownWords: new Set(patterns("kanji-known-word")),
368
368
  designations: patterns("designation-phrase"),
369
369
  noticeEndings: patterns("notice-title-ending"),
@@ -42,3 +42,33 @@ export const citationLead = (text: string, signals: readonly string[]): string |
42
42
  const lastSignal = pattern === undefined ? undefined : [...beforeYear.matchAll(pattern)].at(-1);
43
43
  return (lastSignal === undefined ? beforeYear : beforeYear.slice(0, lastSignal.index)).trim();
44
44
  };
45
+
46
+ /** The same marks of a publication, every one of them: where an earlier reference in the text ends. */
47
+ const PUBLICATION_MARKS_ALL: readonly RegExp[] = PUBLICATION_MARKS.map((mark) => new RegExp(mark.source, "gu"));
48
+
49
+ const LEADING_SEPARATOR = /^[\s;,.]*(?:and\s+)?/u;
50
+
51
+ /**
52
+ * The lead without the tail of an earlier reference it begins inside (…Discussion Series 2020-069 (Washington: Board of
53
+ * Governors, August); and Ben S. Bernanke, …): a splitter that cut inside a reference list hands over the end of one
54
+ * reference before the next one's authors. What follows the last mark of a publication is kept.
55
+ */
56
+ export const withoutEarlierReference = (lead: string): string => {
57
+ const ends = PUBLICATION_MARKS_ALL.flatMap((mark) => [...lead.matchAll(mark)].map((match) => match.index + match[0].length));
58
+ return ends.length === 0
59
+ ? lead
60
+ : lead
61
+ .slice(Math.max(...ends))
62
+ .replace(LEADING_SEPARATOR, "")
63
+ .trim();
64
+ };
65
+
66
+ /** One author as a reference list in the Vancouver style writes them: a surname, then the initials (Kreimer AR, Gail MH, Cyr JT). */
67
+ const AUTHOR = String.raw`\p{Lu}[\p{L}'’-]*\p{Ll}[\p{L}'’-]*(?: \p{Lu}[\p{L}'’-]*\p{Ll}[\p{L}'’-]*)* \p{Lu}{1,3}`;
68
+ /** Fewer authors in a row than this are a sentence naming people, not the author list of a reference. */
69
+ const MIN_AUTHORS = 3;
70
+ const AUTHOR_LIST = new RegExp(String.raw`(?<!\p{L})${AUTHOR}(?:, ${AUTHOR}){${MIN_AUTHORS - 1},}(?!\p{L})`, "gu");
71
+
72
+ /** The words an author list (Kreimer AR, Porras C, Liu D, …) adds beyond one: the authors of a reference, not the writer's sentence. */
73
+ export const authorListSaving = (text: string): number =>
74
+ [...text.matchAll(AUTHOR_LIST)].reduce((saving, match) => saving + match[0].split(/\s+/u).length - 1, 0);
@@ -9,9 +9,11 @@ import { comparableText, entryIn, entryOpens } from "./lexicon-match.ts";
9
9
  // last 最後の段落にあるときだけ当たる言い回し(てみてほしい)。本文の途中なら普通の勧め
10
10
  // lead:/open:/end:<name> 前の語と文の終わりの語の組(気軽に〜ください)。closing-exhortation と同じ書き方
11
11
  // signoff 最後の段落の、この語で始まり「!」で終わる短い一行(Happy brewing!)
12
+ // stacked 結びにほかの定型があるときだけ当たる言い回し(feel free to)。一つなら普通の礼儀
12
13
 
13
14
  const LAST = "last";
14
15
  const SIGNOFF = "signoff";
16
+ const STACKED = "stacked";
15
17
 
16
18
  /** 一行の結びの挨拶と読む語の数の上限。「Happy brewing!」は二語、「Happy holidays, everyone!」は三語。 */
17
19
  const SIGNOFF_WORDS = 3;
@@ -36,7 +38,12 @@ const lastParagraphSentences = (sentences: readonly Sentence[], paragraphs: read
36
38
  return paragraph === undefined ? [final] : sentences.filter((sentence) => sentence.span.start >= paragraph.span.start);
37
39
  };
38
40
 
39
- type Words = { readonly closing: ReturnType<typeof exhortationWords>; readonly last: readonly LexiconEntry[]; readonly signoff: readonly LexiconEntry[] };
41
+ type Words = {
42
+ readonly closing: ReturnType<typeof exhortationWords>;
43
+ readonly last: readonly LexiconEntry[];
44
+ readonly signoff: readonly LexiconEntry[];
45
+ readonly stacked: readonly LexiconEntry[];
46
+ };
40
47
 
41
48
  /** 最後の段落でだけ当たる語。言い回しなら語彙の語、挨拶の一行なら文そのもの。 */
42
49
  const lastIn = (sentence: Sentence, words: Words): string | undefined =>
@@ -45,11 +52,19 @@ const lastIn = (sentence: Sentence, words: Words): string | undefined =>
45
52
 
46
53
  type Hit = { readonly sentence: Sentence; readonly matched: string };
47
54
 
48
- /** 結びの、定型の言い回しのある文。一文に一つ。 */
55
+ /** 結びの、定型の言い回しのある文。一文に一つ。stacked の語は、ほかの定型が結びにあるときだけ数える。 */
49
56
  export const closingClicheHits = (sentences: readonly Sentence[], paragraphs: readonly Paragraph[], words: Words): Hit[] => {
50
57
  const last = new Set(lastParagraphSentences(sentences, paragraphs));
58
+ const stock = new Map<Sentence, string>(
59
+ sentences.flatMap((sentence): [Sentence, string][] => {
60
+ const matched = exhortationIn(sentence, words.closing) ?? (last.has(sentence) ? lastIn(sentence, words) : undefined);
61
+ return matched === undefined ? [] : [[sentence, matched]];
62
+ }),
63
+ );
64
+ const stackedIn = (sentence: Sentence): string | undefined =>
65
+ stock.size === 0 ? undefined : words.stacked.find((entry) => entryIn(sentence, entry))?.pattern;
51
66
  return sentences.flatMap((sentence) => {
52
- const matched = exhortationIn(sentence, words.closing) ?? (last.has(sentence) ? lastIn(sentence, words) : undefined);
67
+ const matched = stock.get(sentence) ?? stackedIn(sentence);
53
68
  return matched === undefined ? [] : [{ sentence, matched }];
54
69
  });
55
70
  };
@@ -58,6 +73,7 @@ export const closingClicheWords = (lexicon: readonly LexiconEntry[]): Words => (
58
73
  closing: exhortationWords(lexicon),
59
74
  last: lexicon.filter((entry) => entry.group === LAST),
60
75
  signoff: lexicon.filter((entry) => entry.group === SIGNOFF),
76
+ stacked: lexicon.filter((entry) => entry.group === STACKED),
61
77
  });
62
78
 
63
79
  /** 結び(最後の節の終わりの段落)の定型の言い回し。limit は指摘に要る文の数。 */
@@ -1,7 +1,10 @@
1
+ import { nameSpans } from "../compare/proper-nouns.ts";
1
2
  import { proseText } from "../measure.ts";
2
3
  import type { Detector, Finding, ProseDocument, Section, Sentence } from "../plugin.ts";
3
4
  import {
5
+ distinctiveNames,
4
6
  evidenceSpans,
7
+ namesAsEvidence,
5
8
  hasNumeral,
6
9
  isClaim,
7
10
  isConditionHeading,
@@ -9,6 +12,7 @@ import {
9
12
  isNavigationLine,
10
13
  startsWithin,
11
14
  statesIntent,
15
+ withSubsections,
12
16
  type AdviceWords,
13
17
  type IntentWords,
14
18
  } from "./concrete-evidence.ts";
@@ -18,7 +22,7 @@ import { letteredIndexEntries } from "./lettered-index.ts";
18
22
  * 具体物の密度。数値・コード・リンク・引用が 1 つも無い節は、
19
23
  * 読み終えても何も持ち帰れない。**少ないほうを指摘する**ので、他の密度 rule と向きが逆。
20
24
  */
21
- const CONCRETE = /\d|`|https?:\/\//u;
25
+ const CONCRETE = /\d|`|https?:\/\/|(?<![/\\\w.-])[A-Za-z][A-Za-z\d-]+\.[a-z]{2,}\b/u;
22
26
 
23
27
  /**
24
28
  * 見出しのない導入部は、書き出しで呼ぶ。文書の言葉なので、message がどの言語でも混ざらない。
@@ -35,6 +39,10 @@ const openingOf = (sentence: Sentence | undefined, unit: ProseDocument["lengthUn
35
39
 
36
40
  const hasNumeralIn = (section: Section): boolean => section.sentences.some((sentence) => hasNumeral(sentence.tokens ?? []));
37
41
 
42
+ /** 数字・コード・リンク・ドメイン名が書かれているか、数の語があるか。 */
43
+ const concreteIn = (doc: ProseDocument, section: Section): boolean =>
44
+ CONCRETE.test(doc.source.slice(section.span.start, section.span.end)) || hasNumeralIn(section) || startsWithin(section.span, doc.links);
45
+
38
46
  /** これより短い節は、具体物があるべきか判断できない。 */
39
47
  const MIN_SENTENCES = 3;
40
48
 
@@ -75,12 +83,15 @@ export const concreteEvidence: Detector = (doc, options): Finding[] => {
75
83
  mostlyClaims(sentences, doc.language, advice, intent)
76
84
  );
77
85
  });
78
- const bare = sections.filter(
79
- (section) => !CONCRETE.test(doc.source.slice(section.span.start, section.span.end)) && !hasNumeralIn(section) && !startsWithin(section.span, doc.links),
80
- );
81
- // 構造の木は作るのに手間がかかる。指摘に届かない文書では作らない。
82
- const nodes = bare.length < options.limit ? [] : evidenceSpans(doc.structure);
83
- const empty = bare.filter((section) => !startsWithin(section.span, nodes));
86
+ const families = new Map(sections.map((section) => [section, withSubsections(doc.sections, section)]));
87
+ const familyOf = (section: Section): Section[] => families.get(section) ?? [section];
88
+ const bare = sections.filter((section) => familyOf(section).every((member) => !concreteIn(doc, member)));
89
+ // 構造の木と名前は求めるのに手間がかかる。指摘に届かない文書では求めない。
90
+ const spans =
91
+ bare.length < options.limit
92
+ ? []
93
+ : [...evidenceSpans(doc.structure), ...namesAsEvidence(distinctiveNames(doc.sentences, nameSpans(doc)), doc.source, doc.sections)];
94
+ const empty = bare.filter((section) => familyOf(section).every((member) => !startsWithin(member.span, spans)));
84
95
  if (empty.length < options.limit) return [];
85
96
  return empty.map((section) => ({
86
97
  rule: "concrete-evidence-density",
@@ -1,4 +1,4 @@
1
- import type { Sentence, Span, StructureKind, StructureNode, Token } from "../plugin.ts";
1
+ import type { Section, Sentence, Span, StructureKind, StructureNode, Token } from "../plugin.ts";
2
2
  import { preOrder } from "../tree-walk.ts";
3
3
  import { isStatement } from "./technical-docs.ts";
4
4
 
@@ -146,3 +146,58 @@ export const isNavigationLine = (sentence: Pick<Sentence, "text">, lines: readon
146
146
 
147
147
  /** 条件を並べる節の見出し(Requirements、応募資格)。並ぶのは条件で、裏づけを求める主張ではない。 */
148
148
  export const isConditionHeading = (heading: string, headings: readonly string[]): boolean => headings.includes(bareLine(heading));
149
+
150
+ /** 節と、その下の節(続く、見出しがより深い節)。親の節の本文は短い導入で、中身は下の節にある。導入部(深さ 0)は親ではない。 */
151
+ export const withSubsections = <T extends Pick<Section, "depth">>(sections: readonly T[], section: T): T[] => {
152
+ const index = sections.indexOf(section);
153
+ const after = index === -1 ? [] : sections.slice(index + 1);
154
+ const next = section.depth === 0 ? 0 : after.findIndex((other) => other.depth <= section.depth);
155
+ return [section, ...(next === -1 ? after : after.slice(0, next))];
156
+ };
157
+
158
+ /** 大文字だけの略語(API、PDFs)。どの文書にも出る技術の語で、名指しした物ではない。 */
159
+ const ACRONYM = /^\p{Lu}+s?$/u;
160
+ const CAPITAL_HEAD = /^\p{Lu}/u;
161
+ const WORD = /\p{L}/u;
162
+
163
+ /** 一字の語(e-Tax の e)は、名前の切れ端。 */
164
+ const MIN_NAME_CHARS = 2;
165
+
166
+ /** 名前と読んだ語のうち、ふつうの語の大文字書き(Timeline、Changes)・強調(NEVER)・略語・切れ端でないもの。 */
167
+ const isDistinctiveName = (token: Token): boolean =>
168
+ token.pos === "PROPN" &&
169
+ token.features?.["OrdinaryWord"] !== "Yes" &&
170
+ token.features?.["Emph"] !== "Yes" &&
171
+ !ACRONYM.test(token.surface) &&
172
+ Array.from(token.surface).length >= MIN_NAME_CHARS;
173
+
174
+ /** 大文字で始まる文頭の語は、名前と区別がつかない(Chimneys)。大文字の無い文字(日本語)の文頭は名前のまま読む。 */
175
+ const distinctiveIn = (sentence: Pick<Sentence, "tokens">): Span[] => {
176
+ const tokens = sentence.tokens ?? [];
177
+ const head = tokens.find((token) => WORD.test(token.surface));
178
+ const skipped = head !== undefined && CAPITAL_HEAD.test(head.surface) ? head : undefined;
179
+ return tokens.filter((token) => token !== skipped && isDistinctiveName(token)).map((token) => token.span);
180
+ };
181
+
182
+ /** 固有の名前(KubeCon、GitHub、大阪城ホール)の範囲。ふつうの語・略語・文頭の語だけでできた名前は除く。 */
183
+ export const distinctiveNames = (sentences: readonly Pick<Sentence, "tokens">[], names: readonly Span[]): Span[] => {
184
+ const distinctive = sentences.flatMap(distinctiveIn);
185
+ return names.filter((name) => startsWithin(name, distinctive));
186
+ };
187
+
188
+ /** 名前が書かれた節の数がこの割合に届くなら、文書の主題(Kubernetes、Rust)で、その節が持ち帰らせる具体物ではない。 */
189
+ const SUBJECT_SHARE = 0.5;
190
+
191
+ const indexOfSection = (sections: readonly Pick<Section, "span">[], at: number): number =>
192
+ sections.findIndex((section) => at >= section.span.start && at < section.span.end);
193
+
194
+ /** 固有の名前(KubeCon、GitHub)のうち、節の具体物として数えるもの。文書の半分以上の節に書かれた名前は主題なので除く。 */
195
+ export const namesAsEvidence = (names: readonly Span[], source: string, sections: readonly Pick<Section, "span">[]): Span[] => {
196
+ const keyOf = (span: Span): string => source.slice(span.start, span.end).toLowerCase();
197
+ const sectionsOf = new Map<string, Set<number>>();
198
+ names.forEach((name) => {
199
+ const index = indexOfSection(sections, name.start);
200
+ if (index !== -1) sectionsOf.set(keyOf(name), (sectionsOf.get(keyOf(name)) ?? new Set<number>()).add(index));
201
+ });
202
+ return names.filter((name) => (sectionsOf.get(keyOf(name))?.size ?? 0) < sections.length * SUBJECT_SHARE);
203
+ };
@@ -42,12 +42,28 @@ const PAGE_ROMAN = /^x{0,3}(?:ix|iv|v?i{0,3})$/u;
42
42
 
43
43
  const isPageNumber = (page: string): boolean => PAGE_DIGITS.test(page) || (page !== "" && PAGE_ROMAN.test(page));
44
44
 
45
- /** 並びの終わりの点がページ番号の前の点線なら、その点は目次の点線で、並びの印ではない。 */
45
+ /** 点線の後ろの、揃えのための二つ以上の空白と次の欄(配役表の「NORA.. Emma Vernon」)。 */
46
+ const LEADER_THEN_GAP = /^[ \t]{2,}\S/u;
47
+ /** 同じ段落の、ほかの長い点線と揃えの空白(「MAURYA...... Honor Lavelle」)。 */
48
+ const LONG_LEADER_THEN_GAP = /\.{3}[ \t]{2,}\S/u;
49
+
50
+ const paragraphAround = (text: string, offset: number): string => {
51
+ const before = text.lastIndexOf("\n\n", offset);
52
+ const after = text.indexOf("\n\n", offset);
53
+ return text.slice(before === -1 ? 0 : before + 2, after === -1 ? text.length : after);
54
+ };
55
+
56
+ /** 点線の後ろが揃えの空白で、同じ段落にほかの長い点線も揃えの空白に続く(点線で欄を揃えた表)。 */
57
+ const isLeaderColumn = (text: string, leaderEnd: number): boolean =>
58
+ LEADER_THEN_GAP.test(text.slice(leaderEnd)) && LONG_LEADER_THEN_GAP.test(paragraphAround(text, leaderEnd));
59
+
60
+ const isLeaderBefore = (text: string, leaderEnd: number): boolean =>
61
+ isPageNumber(LEADER_THEN_PAGE.exec(text.slice(leaderEnd))?.groups?.["page"] ?? "") || isLeaderColumn(text, leaderEnd);
62
+
63
+ /** 並びの終わりの点がページ番号の前の点線か、点線で欄を揃えた表の点線なら、その点は点線で、並びの印ではない。 */
46
64
  const withoutLeader = (text: string, found: DoubledMarks): DoubledMarks => {
47
65
  const kept = found.run.slice(0, Array.from(found.run).findLastIndex((mark) => mark !== ".") + 1);
48
- return kept !== found.run && isPageNumber(LEADER_THEN_PAGE.exec(text.slice(found.start + found.run.length))?.groups?.["page"] ?? "")
49
- ? { start: found.start, run: kept }
50
- : found;
66
+ return kept !== found.run && isLeaderBefore(text, found.start + found.run.length) ? { start: found.start, run: kept } : found;
51
67
  };
52
68
 
53
69
  /**
@@ -21,12 +21,15 @@ const CAPITALISED = /^\p{Lu}\p{Ll}/u;
21
21
  const LETTER = /\p{L}/u;
22
22
 
23
23
  /**
24
- * 文の途中の頭だけ大文字の -ly の語は、解析器が語尾で副詞と当てた名前(July、Kelly)か、題の語(Frequently Asked Questions)。
25
- * どちらも動詞に畳める副詞ではない。
24
+ * 頭だけ大文字の -ly の語は、文の途中なら解析器が語尾で副詞と当てた名前(July、Kelly)か題の語、文頭でも行全体が題の書き方なら
25
+ * 題の語(Frequently Asked Questions)。どちらも動詞に畳める副詞ではない。書き手の確かさを言う副詞(probably、apparently)も、畳む先の動詞が無い。
26
26
  */
27
- const lyAdverbsOf = (tokens: readonly Token[]): Token[] => {
27
+ const lyAdverbsOf = (sentence: Sentence, stance: ReadonlySet<string>): Token[] => {
28
+ const tokens = sentence.tokens ?? [];
28
29
  const first = tokens.findIndex((token) => LETTER.test(token.surface));
29
- return tokens.filter((token, at) => isLyAdverb(token) && !(at > first && CAPITALISED.test(token.surface)));
30
+ const titleLine = isTitleCase(sentence.text) === true;
31
+ const isTitleWord = (token: Token, at: number): boolean => CAPITALISED.test(token.surface) && (at > first || titleLine);
32
+ return tokens.filter((token, at) => isLyAdverb(token) && !stance.has(token.surface.toLowerCase()) && !isTitleWord(token, at));
30
33
  };
31
34
 
32
35
  /**
@@ -35,7 +38,8 @@ const lyAdverbsOf = (tokens: readonly Token[]): Token[] => {
35
38
  */
36
39
  export const adverbDensity: Detector = (doc, options): Finding[] => {
37
40
  const words = wordsIn(doc);
38
- const hits = doc.sentences.flatMap((sentence) => lyAdverbsOf(sentence.tokens ?? []).map((token) => ({ sentence, token })));
41
+ const stance = new Set((doc.lexicons["stance-adverb"] ?? []).map((entry) => entry.pattern));
42
+ const hits = doc.sentences.flatMap((sentence) => lyAdverbsOf(sentence, stance).map((token) => ({ sentence, token })));
39
43
  const density = words === 0 ? 0 : Math.round((hits.length / words) * PER);
40
44
  const first = hits[0];
41
45
  if (words < MIN_WORDS || first === undefined || density <= options.limit) return [];
@@ -78,6 +78,11 @@ const continuesVersion = (text: string, start: number, run: string): boolean =>
78
78
  FULLWIDTH.test(run) === FULLWIDTH.test(text.charAt(start - 2)) &&
79
79
  VERSION_SO_FAR.test(text.slice(Math.max(0, start - 1 - VERSION_REACH), start - 1));
80
80
 
81
+ /** 電話番号(03-3581-1101、0570 - 064 - 556)。0 で始まり、ハイフンで三つの組につなぐ。三つの組を一つの幅で書いた一つの番号。 */
82
+ const PHONE_NUMBER = /(?<![0-90-9])[00][0-90-9]{1,4}(?:\s?[--‐−ー]\s?[0-90-9]{1,4}){2}(?![0-90-9])/gu;
83
+
84
+ const phoneSpans = (text: string): Span[] => [...text.matchAll(PHONE_NUMBER)].map((match) => ({ start: match.index, end: match.index + match[0].length }));
85
+
81
86
  const isListItemNumber = (source: string, offset: number): boolean => LIST_ITEM_HEAD.test(source.slice(source.lastIndexOf("\n", offset - 1) + 1, offset));
82
87
 
83
88
  export type AlnumRun = {
@@ -87,9 +92,13 @@ export type AlnumRun = {
87
92
  readonly offset: number;
88
93
  /** 表のセルを続けてしまった数字(8,457 と 95.7 の 8,45795.7)の中。幅は書き手のものだが、セルの切れ目が分からず桁の数は当てにならない。 */
89
94
  readonly glued: boolean;
95
+ /** 一つの書き物として書いたまとまりの位置。電話番号の組はその番号の頭、ほかは並び自身の位置。 */
96
+ readonly unit: number;
97
+ /** 英字一字と数字を違う幅で書いた並び(Q5)を分けた片方。 */
98
+ readonly split: boolean;
90
99
  };
91
100
 
92
- type Piece = { readonly 0: string; readonly index: number };
101
+ type Piece = { readonly 0: string; readonly index: number; readonly split?: boolean };
93
102
 
94
103
  /** 一つの幅で書いた部分。 */
95
104
  const SAME_WIDTH = /[A-Za-z0-9]+|[A-Za-z0-9]+/gu;
@@ -106,7 +115,7 @@ const isLetterAndNumber = (parts: readonly Piece[]): boolean =>
106
115
  */
107
116
  const widthPieces = (match: RegExpExecArray): Piece[] => {
108
117
  if (FULLWIDTH.test(match[0]) || HALFWIDTH.test(match[0])) return [match];
109
- const parts = [...match[0].matchAll(SAME_WIDTH)].map((part) => ({ 0: part[0], index: match.index + part.index }));
118
+ const parts = [...match[0].matchAll(SAME_WIDTH)].map((part) => ({ 0: part[0], index: match.index + part.index, split: true }));
110
119
  return isLetterAndNumber(parts) ? parts : [];
111
120
  };
112
121
 
@@ -117,6 +126,7 @@ const widthPieces = (match: RegExpExecArray): Piece[] => {
117
126
  export const alnumRunsIn = (sentence: Sentence, source: string): AlnumRun[] => {
118
127
  const quoted: readonly Span[] = quotedSpans(sentence.text, QUOTATION_MARKS);
119
128
  const glued = gluedNumberSpans(sentence.text);
129
+ const phones = phoneSpans(sentence.text);
120
130
  return [...sentence.text.matchAll(ALNUM_RUN)]
121
131
  .flatMap(widthPieces)
122
132
  .filter((match) => !isWithinAny(quoted, { start: match.index, end: match.index + match[0].length }))
@@ -132,6 +142,8 @@ export const alnumRunsIn = (sentence: Sentence, source: string): AlnumRun[] => {
132
142
  written: match[0],
133
143
  offset: sentence.span.start + match.index,
134
144
  glued: isWithinAny(glued, { start: match.index, end: match.index + match[0].length }),
145
+ unit: sentence.span.start + (phones.find((phone) => phone.start <= match.index && match.index < phone.end)?.start ?? match.index),
146
+ split: "split" in match && match.split === true,
135
147
  }));
136
148
  };
137
149
 
@@ -163,20 +175,34 @@ const datelineOf = (doc: ProseDocument): Span | undefined => {
163
175
  return first !== undefined && DATELINE.test(doc.source.slice(first.span.start, first.span.end).trim()) ? first.span : undefined;
164
176
  };
165
177
 
178
+ /**
179
+ * 見出しの文字(### Q5:…の Q5:…)を、文と同じに読む一続き。文書の頭の題(# ノロウイルスに関するQ&A)は載せたページの名前なので読まない。
180
+ * 見出しから数えるのは、英字一字と数字を違う幅で書いた並び(Q5)だけ。見出しはほかの数を本文と別の幅で書くことが多いが(## 1 概要)、
181
+ * 一つの並びの中で幅が変わるのは書き損じ。
182
+ */
183
+ const headingSentences = (doc: ProseDocument): Sentence[] =>
184
+ (doc.markup?.headings ?? []).flatMap((heading, index) => {
185
+ if (index === 0 && heading.depth === 1) return [];
186
+ const start = doc.source.indexOf(heading.text, heading.start);
187
+ return start < 0 || start >= heading.end || heading.text === "" ? [] : [{ span: { start, end: start + heading.text.length }, text: heading.text }];
188
+ });
189
+
166
190
  /** 多いほうの英字の語が何種類あれば、文書の書き方と見るか。BAR を二度書いただけなら、それはその語の書き方。 */
167
191
  const HABIT_WORDS = 2;
168
192
 
169
193
  const wordOf = (run: AlnumRun): string => run.written.normalize("NFKC").toUpperCase();
170
194
 
171
195
  /**
172
- * 英字の語の少ないほうを、文書の書き方からはずれたと言えるか。多いほうが二種類以上の語か、少ないほうと同じ語(URL と URL)のとき。
173
- * 全角の BAR だけの文書の DELICATE は、別の語を別の書き方で書いただけ。
196
+ * 少ないほうを、文書の書き方からはずれたと言えるか。英字の語は、多いほうが二種類以上の語か、少ないほうと同じ語(URL と URL)のとき。
197
+ * 全角の BAR だけの文書の DELICATE は、別の語を別の書き方で書いただけ。ほかの組は、多いほうが二つ以上のまとまりにわたるとき。
198
+ * 多いほうが電話番号一つの組(0570 - 064 - 556)だけなら、それはその番号の書き方で、文書の書き方ではない。
174
199
  */
175
200
  const departsFromHabit =
176
201
  (ofKind: readonly Located[], odd: readonly Located[]) =>
177
202
  ({ run }: Located): boolean => {
178
- if (run.kind !== "letters") return true;
179
- const usual = new Set(ofKind.filter((entry) => !odd.includes(entry)).map((entry) => wordOf(entry.run)));
203
+ const usualRuns = ofKind.filter((entry) => !odd.includes(entry)).map((entry) => entry.run);
204
+ if (run.kind !== "letters") return new Set(usualRuns.map((usual) => usual.unit)).size >= HABIT_WORDS;
205
+ const usual = new Set(usualRuns.map(wordOf));
180
206
  return usual.size >= HABIT_WORDS || usual.has(wordOf(run));
181
207
  };
182
208
 
@@ -198,10 +224,13 @@ const findingOf = ({ sentence, run }: Located, count: number, of: number, limit:
198
224
  */
199
225
  export const fullwidthAlnum: Detector = (doc, options): Finding[] => {
200
226
  const dateline = datelineOf(doc);
201
- const located: Located[] = doc.sentences
202
- .filter((sentence) => sentence.embeddedLanguage === undefined && !isCitation(sentence, doc.source))
203
- .filter((sentence) => dateline === undefined || !isWithinAny([dateline], sentence.span))
204
- .flatMap((sentence) => alnumRunsIn(sentence, doc.source).map((run) => ({ sentence, run })));
227
+ const located: Located[] = [
228
+ ...doc.sentences
229
+ .filter((sentence) => sentence.embeddedLanguage === undefined && !isCitation(sentence, doc.source))
230
+ .filter((sentence) => dateline === undefined || !isWithinAny([dateline], sentence.span))
231
+ .flatMap((sentence) => alnumRunsIn(sentence, doc.source).map((run) => ({ sentence, run }))),
232
+ ...headingSentences(doc).flatMap((sentence) => alnumRunsIn(sentence, doc.source).flatMap((run) => (run.split ? [{ sentence, run }] : []))),
233
+ ];
205
234
  return KINDS.flatMap((kind) => {
206
235
  const ofKind = located.filter(({ run }) => run.kind === kind);
207
236
  const odd = minorityWithin(ofKind, ({ run }) => run.fullwidth, options.limit);