chaffjs 0.41.0 → 0.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/dist/ai-score/human-shares.d.ts.map +1 -1
  2. package/dist/ai-score/human-shares.js +1 -0
  3. package/dist/ai-score/human-shares.js.map +1 -1
  4. package/dist/detectors/acronym-file-type.d.ts +14 -0
  5. package/dist/detectors/acronym-file-type.d.ts.map +1 -0
  6. package/dist/detectors/acronym-file-type.js +26 -0
  7. package/dist/detectors/acronym-file-type.js.map +1 -0
  8. package/dist/detectors/ai-structure.d.ts +2 -1
  9. package/dist/detectors/ai-structure.d.ts.map +1 -1
  10. package/dist/detectors/ai-structure.js +17 -6
  11. package/dist/detectors/ai-structure.js.map +1 -1
  12. package/dist/detectors/bibliography-entry.d.ts +3 -0
  13. package/dist/detectors/bibliography-entry.d.ts.map +1 -0
  14. package/dist/detectors/bibliography-entry.js +15 -0
  15. package/dist/detectors/bibliography-entry.js.map +1 -0
  16. package/dist/detectors/bold-label.d.ts +2 -0
  17. package/dist/detectors/bold-label.d.ts.map +1 -1
  18. package/dist/detectors/bold-label.js +4 -0
  19. package/dist/detectors/bold-label.js.map +1 -1
  20. package/dist/detectors/char-shape.d.ts +1 -0
  21. package/dist/detectors/char-shape.d.ts.map +1 -1
  22. package/dist/detectors/char-shape.js +13 -8
  23. package/dist/detectors/char-shape.js.map +1 -1
  24. package/dist/detectors/clause-shape.d.ts +8 -2
  25. package/dist/detectors/clause-shape.d.ts.map +1 -1
  26. package/dist/detectors/clause-shape.js +14 -6
  27. package/dist/detectors/clause-shape.js.map +1 -1
  28. package/dist/detectors/closing-cliche.d.ts.map +1 -1
  29. package/dist/detectors/closing-cliche.js +2 -1
  30. package/dist/detectors/closing-cliche.js.map +1 -1
  31. package/dist/detectors/contraction-mention.d.ts +2 -0
  32. package/dist/detectors/contraction-mention.d.ts.map +1 -1
  33. package/dist/detectors/contraction-mention.js +5 -2
  34. package/dist/detectors/contraction-mention.js.map +1 -1
  35. package/dist/detectors/contraction-mix.d.ts.map +1 -1
  36. package/dist/detectors/contraction-mix.js +4 -3
  37. package/dist/detectors/contraction-mix.js.map +1 -1
  38. package/dist/detectors/counter-edge.d.ts +11 -0
  39. package/dist/detectors/counter-edge.d.ts.map +1 -1
  40. package/dist/detectors/counter-edge.js +29 -0
  41. package/dist/detectors/counter-edge.js.map +1 -1
  42. package/dist/detectors/document-shape.d.ts +6 -1
  43. package/dist/detectors/document-shape.d.ts.map +1 -1
  44. package/dist/detectors/document-shape.js +14 -4
  45. package/dist/detectors/document-shape.js.map +1 -1
  46. package/dist/detectors/doubled-word.d.ts.map +1 -1
  47. package/dist/detectors/doubled-word.js +5 -1
  48. package/dist/detectors/doubled-word.js.map +1 -1
  49. package/dist/detectors/en-shape.d.ts.map +1 -1
  50. package/dist/detectors/en-shape.js +12 -1
  51. package/dist/detectors/en-shape.js.map +1 -1
  52. package/dist/detectors/ending-refrain.d.ts +9 -0
  53. package/dist/detectors/ending-refrain.d.ts.map +1 -0
  54. package/dist/detectors/ending-refrain.js +52 -0
  55. package/dist/detectors/ending-refrain.js.map +1 -0
  56. package/dist/detectors/fact-consistency.d.ts.map +1 -1
  57. package/dist/detectors/fact-consistency.js +5 -1
  58. package/dist/detectors/fact-consistency.js.map +1 -1
  59. package/dist/detectors/gram-furniture.d.ts +1 -0
  60. package/dist/detectors/gram-furniture.d.ts.map +1 -1
  61. package/dist/detectors/gram-furniture.js +7 -0
  62. package/dist/detectors/gram-furniture.js.map +1 -1
  63. package/dist/detectors/gram-heading.d.ts +9 -0
  64. package/dist/detectors/gram-heading.d.ts.map +1 -0
  65. package/dist/detectors/gram-heading.js +20 -0
  66. package/dist/detectors/gram-heading.js.map +1 -0
  67. package/dist/detectors/gram-predicate.d.ts.map +1 -1
  68. package/dist/detectors/gram-predicate.js +31 -4
  69. package/dist/detectors/gram-predicate.js.map +1 -1
  70. package/dist/detectors/gram-repetition.d.ts.map +1 -1
  71. package/dist/detectors/gram-repetition.js +18 -3
  72. package/dist/detectors/gram-repetition.js.map +1 -1
  73. package/dist/detectors/gram-spread.d.ts +6 -0
  74. package/dist/detectors/gram-spread.d.ts.map +1 -0
  75. package/dist/detectors/gram-spread.js +18 -0
  76. package/dist/detectors/gram-spread.js.map +1 -0
  77. package/dist/detectors/kanji-run-pieces.d.ts +4 -0
  78. package/dist/detectors/kanji-run-pieces.d.ts.map +1 -1
  79. package/dist/detectors/kanji-run-pieces.js +7 -0
  80. package/dist/detectors/kanji-run-pieces.js.map +1 -1
  81. package/dist/detectors/lexicon.d.ts.map +1 -1
  82. package/dist/detectors/lexicon.js +1 -0
  83. package/dist/detectors/lexicon.js.map +1 -1
  84. package/dist/detectors/list-lead-in.d.ts +2 -2
  85. package/dist/detectors/list-lead-in.d.ts.map +1 -1
  86. package/dist/detectors/list-lead-in.js +28 -3
  87. package/dist/detectors/list-lead-in.js.map +1 -1
  88. package/dist/detectors/lookalike-character.d.ts +2 -0
  89. package/dist/detectors/lookalike-character.d.ts.map +1 -1
  90. package/dist/detectors/lookalike-character.js +36 -9
  91. package/dist/detectors/lookalike-character.js.map +1 -1
  92. package/dist/detectors/mark-shape.d.ts +1 -1
  93. package/dist/detectors/mark-shape.d.ts.map +1 -1
  94. package/dist/detectors/mark-shape.js +29 -12
  95. package/dist/detectors/mark-shape.js.map +1 -1
  96. package/dist/detectors/number-style.d.ts +7 -1
  97. package/dist/detectors/number-style.d.ts.map +1 -1
  98. package/dist/detectors/number-style.js +21 -1
  99. package/dist/detectors/number-style.js.map +1 -1
  100. package/dist/detectors/number-unit.d.ts +7 -1
  101. package/dist/detectors/number-unit.d.ts.map +1 -1
  102. package/dist/detectors/number-unit.js +20 -6
  103. package/dist/detectors/number-unit.js.map +1 -1
  104. package/dist/detectors/particle-run-long-forms.d.ts +7 -0
  105. package/dist/detectors/particle-run-long-forms.d.ts.map +1 -0
  106. package/dist/detectors/particle-run-long-forms.js +23 -0
  107. package/dist/detectors/particle-run-long-forms.js.map +1 -0
  108. package/dist/detectors/particle-run-quoted-names.d.ts +6 -0
  109. package/dist/detectors/particle-run-quoted-names.d.ts.map +1 -0
  110. package/dist/detectors/particle-run-quoted-names.js +18 -0
  111. package/dist/detectors/particle-run-quoted-names.js.map +1 -0
  112. package/dist/detectors/register-separate-part.d.ts +9 -1
  113. package/dist/detectors/register-separate-part.d.ts.map +1 -1
  114. package/dist/detectors/register-separate-part.js +23 -0
  115. package/dist/detectors/register-separate-part.js.map +1 -1
  116. package/dist/detectors/register-voice.d.ts +4 -3
  117. package/dist/detectors/register-voice.d.ts.map +1 -1
  118. package/dist/detectors/register-voice.js +11 -4
  119. package/dist/detectors/register-voice.js.map +1 -1
  120. package/dist/detectors/register.d.ts.map +1 -1
  121. package/dist/detectors/register.js +9 -6
  122. package/dist/detectors/register.js.map +1 -1
  123. package/dist/detectors/sentence-ending.d.ts +1 -0
  124. package/dist/detectors/sentence-ending.d.ts.map +1 -1
  125. package/dist/detectors/sentence-ending.js +7 -3
  126. package/dist/detectors/sentence-ending.js.map +1 -1
  127. package/dist/detectors/signals.d.ts.map +1 -1
  128. package/dist/detectors/signals.js +21 -6
  129. package/dist/detectors/signals.js.map +1 -1
  130. package/dist/detectors/stacked-hedge.d.ts +4 -2
  131. package/dist/detectors/stacked-hedge.d.ts.map +1 -1
  132. package/dist/detectors/stacked-hedge.js +16 -3
  133. package/dist/detectors/stacked-hedge.js.map +1 -1
  134. package/dist/detectors/token-shape.d.ts.map +1 -1
  135. package/dist/detectors/token-shape.js +13 -1
  136. package/dist/detectors/token-shape.js.map +1 -1
  137. package/dist/detectors/unknown-word-context.d.ts +5 -0
  138. package/dist/detectors/unknown-word-context.d.ts.map +1 -1
  139. package/dist/detectors/unknown-word-context.js +8 -0
  140. package/dist/detectors/unknown-word-context.js.map +1 -1
  141. package/dist/detectors/unknown-word.d.ts.map +1 -1
  142. package/dist/detectors/unknown-word.js +3 -3
  143. package/dist/detectors/unknown-word.js.map +1 -1
  144. package/dist/detectors/weasel-word.d.ts.map +1 -1
  145. package/dist/detectors/weasel-word.js +23 -4
  146. package/dist/detectors/weasel-word.js.map +1 -1
  147. package/dist/facts/era-year.d.ts +2 -0
  148. package/dist/facts/era-year.d.ts.map +1 -0
  149. package/dist/facts/era-year.js +7 -0
  150. package/dist/facts/era-year.js.map +1 -0
  151. package/dist/facts/fact-scope.d.ts +1 -1
  152. package/dist/facts/fact-scope.d.ts.map +1 -1
  153. package/dist/facts/fact-scope.js +18 -8
  154. package/dist/facts/fact-scope.js.map +1 -1
  155. package/dist/facts/table-facts.d.ts.map +1 -1
  156. package/dist/facts/table-facts.js +18 -2
  157. package/dist/facts/table-facts.js.map +1 -1
  158. package/dist/own-title-quote.d.ts +7 -0
  159. package/dist/own-title-quote.d.ts.map +1 -0
  160. package/dist/own-title-quote.js +19 -0
  161. package/dist/own-title-quote.js.map +1 -0
  162. package/dist/rule-of-three.d.ts +5 -1
  163. package/dist/rule-of-three.d.ts.map +1 -1
  164. package/dist/rule-of-three.js +11 -2
  165. package/dist/rule-of-three.js.map +1 -1
  166. package/dist/structure/definition-use.d.ts.map +1 -1
  167. package/dist/structure/definition-use.js +3 -1
  168. package/dist/structure/definition-use.js.map +1 -1
  169. package/dist/structure-shape/features.d.ts.map +1 -1
  170. package/dist/structure-shape/features.js +15 -2
  171. package/dist/structure-shape/features.js.map +1 -1
  172. package/dist/structure-shape/template-outline.d.ts +7 -0
  173. package/dist/structure-shape/template-outline.d.ts.map +1 -1
  174. package/dist/structure-shape/template-outline.js +10 -0
  175. package/dist/structure-shape/template-outline.js.map +1 -1
  176. package/dist/topic-clause.d.ts.map +1 -1
  177. package/dist/topic-clause.js +23 -1
  178. package/dist/topic-clause.js.map +1 -1
  179. package/dist/word-use.d.ts.map +1 -1
  180. package/dist/word-use.js +9 -1
  181. package/dist/word-use.js.map +1 -1
  182. package/package.json +3 -3
  183. package/rules/adverb-overuse.yaml +2 -2
  184. package/rules/ai-structure.yaml +2 -2
  185. package/rules/bracket-nesting.yaml +7 -2
  186. package/rules/bracket-width-consistency.yaml +2 -2
  187. package/rules/closing-cliche.yaml +3 -3
  188. package/rules/colon-lead-in.yaml +3 -2
  189. package/rules/contraction-consistency.yaml +2 -2
  190. package/rules/doubled-word.yaml +2 -2
  191. package/rules/excessive-hedging.yaml +2 -1
  192. package/rules/fact-conflict.yaml +2 -2
  193. package/rules/lookalike-character.yaml +2 -2
  194. package/rules/max-kanji-continuous.yaml +4 -3
  195. package/rules/ngram-repetition.yaml +2 -2
  196. package/rules/no-doubled-joshi.yaml +2 -2
  197. package/rules/no-mixed-desumasu.yaml +3 -2
  198. package/rules/number-style-consistency.yaml +2 -2
  199. package/rules/number-without-unit.yaml +2 -2
  200. package/rules/orthographic-variant.yaml +2 -2
  201. package/rules/repeated-sentence-ending.yaml +2 -2
  202. package/rules/rule-of-three.yaml +2 -2
  203. package/rules/title-length.yaml +7 -2
  204. package/rules/topic-predicate-distance.yaml +2 -2
  205. package/rules/undefined-acronym.yaml +3 -2
  206. package/rules/unknown-word.yaml +2 -2
  207. package/rules/unused-definition.yaml +4 -2
  208. package/src/ai-score/human-shares.ts +1 -0
  209. package/src/detectors/acronym-file-type.ts +33 -0
  210. package/src/detectors/ai-structure.ts +18 -10
  211. package/src/detectors/bibliography-entry.ts +18 -0
  212. package/src/detectors/bold-label.ts +6 -0
  213. package/src/detectors/char-shape.ts +12 -7
  214. package/src/detectors/clause-shape.ts +14 -12
  215. package/src/detectors/closing-cliche.ts +6 -1
  216. package/src/detectors/contraction-mention.ts +6 -2
  217. package/src/detectors/contraction-mix.ts +5 -3
  218. package/src/detectors/counter-edge.ts +35 -0
  219. package/src/detectors/document-shape.ts +17 -6
  220. package/src/detectors/doubled-word.ts +9 -1
  221. package/src/detectors/en-shape.ts +15 -1
  222. package/src/detectors/ending-refrain.ts +66 -0
  223. package/src/detectors/fact-consistency.ts +4 -1
  224. package/src/detectors/gram-furniture.ts +9 -0
  225. package/src/detectors/gram-heading.ts +27 -0
  226. package/src/detectors/gram-predicate.ts +38 -4
  227. package/src/detectors/gram-repetition.ts +23 -2
  228. package/src/detectors/gram-spread.ts +19 -0
  229. package/src/detectors/kanji-run-pieces.ts +10 -0
  230. package/src/detectors/lexicon.ts +1 -0
  231. package/src/detectors/list-lead-in.ts +36 -3
  232. package/src/detectors/lookalike-character.ts +40 -10
  233. package/src/detectors/mark-shape.ts +31 -12
  234. package/src/detectors/number-style.ts +29 -2
  235. package/src/detectors/number-unit.ts +29 -8
  236. package/src/detectors/particle-run-long-forms.ts +34 -0
  237. package/src/detectors/particle-run-quoted-names.ts +27 -0
  238. package/src/detectors/register-separate-part.ts +32 -1
  239. package/src/detectors/register-voice.ts +17 -4
  240. package/src/detectors/register.ts +9 -6
  241. package/src/detectors/sentence-ending.ts +10 -4
  242. package/src/detectors/signals.ts +24 -6
  243. package/src/detectors/stacked-hedge.ts +24 -7
  244. package/src/detectors/token-shape.ts +14 -1
  245. package/src/detectors/unknown-word-context.ts +9 -0
  246. package/src/detectors/unknown-word.ts +4 -2
  247. package/src/detectors/weasel-word.ts +31 -5
  248. package/src/facts/era-year.ts +7 -0
  249. package/src/facts/fact-scope.ts +20 -6
  250. package/src/facts/table-facts.ts +31 -3
  251. package/src/own-title-quote.ts +28 -0
  252. package/src/rule-of-three.ts +16 -2
  253. package/src/structure/definition-use.ts +4 -1
  254. package/src/structure-shape/features.ts +18 -2
  255. package/src/structure-shape/template-outline.ts +12 -0
  256. package/src/topic-clause.ts +25 -1
  257. package/src/word-use.ts +10 -1
@@ -4,6 +4,7 @@ import { isConventionalPhrase } from "./caps-phrase.ts";
4
4
  import { minorityReport } from "../spacing-minority.ts";
5
5
  import { externalLinkTitleSpans } from "../link-title.ts";
6
6
  import { formulaBracketSpans } from "../formula-brackets.ts";
7
+ import { ownTitleQuoteSpans } from "../own-title-quote.ts";
7
8
  import { isWithinAny, quotedSpans } from "../quoted-span.ts";
8
9
  import { bracketPlaceholderSpans, capitalLineSpans, captionsOf, isCaptionAt, isWithinSorted } from "./caps-caption.ts";
9
10
  import { lineStarts } from "../position.ts";
@@ -93,32 +94,49 @@ const minorityFindings = <T extends Sided>(items: readonly T[], limit: number, v
93
94
  const ownSentences = (doc: ProseDocument): readonly Sentence[] => doc.sentences.filter((sentence) => sentence.embeddedLanguage === undefined);
94
95
 
95
96
  /**
96
- * A bracketed item number opening a line ((1)開催趣旨, (ア), (iv), a list bullet before it), both brackets of one width.
97
- * It numbers the line, a style of its own: the brackets of the prose around it may be written the other width. A
98
- * bracketed word at a line's head ((背景), (注)) is not a number, and an item number the prose refers to (次の(1)及び(2))
99
- * is written in the prose; both stay with the prose's brackets.
97
+ * A bracketed item number opening a line ((1)開催趣旨, (ア), (iv), a list bullet before it), both brackets of one width,
98
+ * or a tag in Latin letters opening a line ([Web]登録完了のお知らせ, a subject line's prefix). It labels the line, a style of
99
+ * its own: the brackets of the prose around it may be written the other width. A bracketed word in Japanese at a line's head
100
+ * ((背景), (注)) is not a label of that kind, and an item number the prose refers to (次の(1)及び(2)) is written in the prose;
101
+ * both stay with the prose's brackets.
100
102
  */
101
103
  const LINE_HEAD = /^\s*(?:[-*+] +)?/u;
102
- const BRACKETED = /^([(([[])([^))\]]]{1,4})([))\]]])/u;
104
+ const BRACKETED = /^([(([[])([^))\]]]{1,12})([))\]]])/u;
103
105
  const NUMBERING = /^(?:[0-90-9]{1,3}|[一二三四五六七八九十]{1,3}|[A-Za-zA-Za-zァ-ヶぁ-んヲ-ン])$/u;
104
106
  /** Roman numerals i to x, either case. */
105
107
  const ROMAN = /^(?:i{2,3}|iv|vi{1,3}|ix|I{2,3}|IV|VI{1,3}|IX)$/u;
108
+ /** A word in Latin letters with a capital, digits, dots or hyphens after its first letter (Web, e-Gov); not a numeral (iiii). */
109
+ const LATIN_TAG = /^(?=.*[A-Z])[A-Za-z][A-Za-z0-9.-]+$/u;
106
110
  const CLOSER_OF: Readonly<Record<string, string>> = { "(": ")", "(": ")", "[": "]", "[": "]" };
107
111
 
108
- const isItemNumber = (text: string): boolean => NUMBERING.test(text) || ROMAN.test(text);
112
+ const isLineLabel = (text: string): boolean => NUMBERING.test(text) || ROMAN.test(text) || LATIN_TAG.test(text);
109
113
 
110
- /** The offsets in a line of its item number's opening and closing bracket, or none. */
114
+ /** The offsets in a line of its label's opening and closing bracket, or none. */
111
115
  const enumeratorIn = (line: string): readonly number[] => {
112
116
  const head = LINE_HEAD.exec(line)?.[0].length ?? 0;
113
117
  const found = BRACKETED.exec(line.slice(head));
114
- if (found === null || CLOSER_OF[found[1] ?? ""] !== found[3] || !isItemNumber(found[2] ?? "")) return [];
118
+ if (found === null || CLOSER_OF[found[1] ?? ""] !== found[3] || !isLineLabel(found[2] ?? "")) return [];
115
119
  return [head, head + found[0].length - 1];
116
120
  };
117
121
 
118
- /** The offsets in `source` of each line's item number's opening and closing bracket. */
122
+ /**
123
+ * An item's address in the prose: a section's number and its item's bracketed number (上記4(2)で), as the lines number them.
124
+ * Not after a digit, a comma or a point, so a figure and its bracketed figure in a table (1,054(47)) is not one.
125
+ */
126
+ const ITEM_ADDRESS = /(?<![0-90-9,,..])[0-90-9]{1,2}(?:\([0-90-9]{1,2}\)|([0-90-9]{1,2}))(?=[\p{Script=Han}\p{Script=Hiragana}])/gu;
127
+
128
+ const addressBrackets = (match: RegExpMatchArray & { index: number }): number[] => {
129
+ const end = match.index + match[0].length - 1;
130
+ return [match.index + match[0].search(/[((]/u), end];
131
+ };
132
+
133
+ /** The offsets in `source` of each line's label's opening and closing bracket, and of the brackets of an item's address. */
119
134
  export const enumeratorBracketOffsets = (source: string): ReadonlySet<number> => {
120
135
  const starts = lineStarts(source);
121
- return new Set(source.split("\n").flatMap((line, index) => enumeratorIn(line).map((at) => (starts[index] ?? 0) + at)));
136
+ return new Set([
137
+ ...source.split("\n").flatMap((line, index) => enumeratorIn(line).map((at) => (starts[index] ?? 0) + at)),
138
+ ...[...source.matchAll(ITEM_ADDRESS)].flatMap(addressBrackets),
139
+ ]);
122
140
  };
123
141
 
124
142
  /** Appended to a mark's kind for an item number's bracket. A lexicon's group, a word from YAML, never holds a NUL. */
@@ -174,9 +192,10 @@ const withNoteKind = (mark: Mark, notes: ReadonlySet<number>): Mark =>
174
192
  export const markConsistency: Detector = (doc, options): Finding[] => {
175
193
  const script = SCRIPT[doc.language];
176
194
  if (script === undefined) return [];
177
- // A link that quotes an outside page's title keeps that page's marks ((コンテキスト内) in a WCAG title).
178
- const titles = externalLinkTitleSpans(doc.source, doc.links);
179
195
  const forms = formsOf(options.lexicon ?? []);
196
+ // A link that quotes an outside page's title keeps that page's marks ((コンテキスト内) in a WCAG title), and a quotation
197
+ // of the document's own heading keeps the heading's.
198
+ const titles = [...externalLinkTitleSpans(doc.source, doc.links), ...ownTitleQuoteSpans(doc.source, doc.markup?.headings ?? [], new Set(forms.keys()))];
180
199
  const enumerators = enumeratorBracketOffsets(doc.source);
181
200
  const doubled = doubledParenOffsets(doc.source);
182
201
  const notes = noteMarkerOffsets(doc.source);
@@ -4,7 +4,8 @@
4
4
  import { escapeRegExp } from "../orthography.ts";
5
5
  import { QUOTATION_MARKS, isWithinAny, quotedSpans } from "../quoted-span.ts";
6
6
  import { isCitation } from "./kutoten-consistency.ts";
7
- import type { Detector, Finding, ProseDocument, Sentence, Span, Token } from "../plugin.ts";
7
+ import { inDocumentOrder } from "../structure/issues.ts";
8
+ import type { Detector, Finding, ProseDocument, Sentence, Span, StructureNode, Token } from "../plugin.ts";
8
9
 
9
10
  export type NumberKind = "count" | "grouping" | "percent" | "count-small" | "count-large";
10
11
 
@@ -253,12 +254,38 @@ const findingOf = (mark: NumberMark, usual: NumberMark, count: number, of: numbe
253
254
  variant: mark.kind,
254
255
  });
255
256
 
257
+ const isInArticle = (mark: NumberMark, articles: readonly Span[]): boolean =>
258
+ isWithinAny(articles, { start: mark.offset, end: mark.offset + mark.written.length });
259
+
260
+ /**
261
+ * The marks of the document's own text. A document that is not a statute and sets out articles where most of its numbers are
262
+ * outside them (a manual quoting the order its fees rest on) quotes the law there, and the law keeps its own numerals
263
+ * (二千四百円). A document whose numbers are mostly inside its articles (work rules) is written in articles itself.
264
+ */
265
+ export const ownMarks = (marks: readonly NumberMark[], articles: readonly Span[]): readonly NumberMark[] => {
266
+ const outside = marks.filter((mark) => !isInArticle(mark, articles));
267
+ return outside.length > marks.length - outside.length ? outside : marks;
268
+ };
269
+
270
+ /** A numbered heading of the document's own outline (2.1 Corpus) is read as an article too; a law's article names its unit (第5条, Article 5). */
271
+ const OUTLINE_NUMBER = /^[\d.]+$/u;
272
+
273
+ const isLawArticle = (node: StructureNode): boolean => node.kind === "article" && !OUTLINE_NUMBER.test(String(node.attrs["label"] ?? ""));
274
+
275
+ const lawArticleSpans = (doc: ProseDocument): Span[] =>
276
+ doc.structure === undefined ? [] : inDocumentOrder(doc.structure).flatMap((node) => (isLawArticle(node) ? [node.span] : []));
277
+
278
+ const isMixed = (marks: readonly NumberMark[]): boolean => new Set(marks.map((mark) => mark.style)).size > 1;
279
+
256
280
  /** For each kind of number, the marks written in the document's less common style. */
257
281
  export const numberStyleConsistency: Detector = (doc, options): Finding[] => {
258
282
  const words = wordsOf(doc);
259
- const marks = doc.sentences
283
+ const written = doc.sentences
260
284
  .filter((sentence) => sentence.embeddedLanguage === undefined && !isCitation(sentence, doc.source))
261
285
  .flatMap((sentence) => numberMarksIn(sentence, words, doc.language, doc.source));
286
+ // doc.structure builds the tree when first read: a document with one style in every kind has nothing to report either way.
287
+ if (!KINDS.some((kind) => isMixed(written.filter((mark) => mark.kind === kind)))) return [];
288
+ const marks = ownMarks(written, lawArticleSpans(doc));
262
289
  return KINDS.flatMap((kind) => {
263
290
  const ofKind = marks.filter((mark) => mark.kind === kind);
264
291
  const { odd, usual } = minorityStyles(ofKind, options.limit);
@@ -9,8 +9,15 @@ import { quoteAt } from "./structure-tree.ts";
9
9
  import { formsOf } from "./currency-notation.ts";
10
10
  import { scaledFiguresIn, scaleGaps, type ScaleWords } from "./scaled-figure-unit.ts";
11
11
 
12
- /** One value of a kind: where its number starts, as written, and its unit ("" when bare). */
13
- export type Measured = { readonly kind: string; readonly name: string; readonly offset: number; readonly written: string; readonly unit: string };
12
+ /** One value of a kind: where its number starts, as written, and its unit ("" when bare). row: the table row of a cell. */
13
+ export type Measured = {
14
+ readonly kind: string;
15
+ readonly name: string;
16
+ readonly offset: number;
17
+ readonly written: string;
18
+ readonly unit: string;
19
+ readonly row?: string;
20
+ };
14
21
 
15
22
  export type UnitGap = { readonly value: Measured; readonly unit: string };
16
23
 
@@ -50,10 +57,11 @@ export const unitOf = (text: string, units: ReadonlySet<string>): string | undef
50
57
  return currency === "" && UNIT_SHAPE.test(suffix) && isUnit(suffix, units) ? suffix : undefined;
51
58
  };
52
59
 
53
- const measured = (kind: string, name: string, text: string, offset: number, units: ReadonlySet<string>): Measured[] => {
60
+ const measured = (kind: string, name: string, text: string, offset: number, units: ReadonlySet<string>, row?: string): Measured[] => {
54
61
  const written = text.trim();
55
62
  const unit = unitOf(written, units);
56
- return unit === undefined ? [] : [{ kind, name, offset: offset + Math.max(0, text.indexOf(written)), written, unit }];
63
+ const placed = row === undefined ? {} : { row };
64
+ return unit === undefined ? [] : [{ kind, name, offset: offset + Math.max(0, text.indexOf(written)), written, unit, ...placed }];
57
65
  };
58
66
 
59
67
  type LabelLine = { readonly label: string; readonly value: string; readonly at: number };
@@ -83,9 +91,10 @@ const tableValues = (source: string, table: MarkdownNode, index: number, units:
83
91
  const [header, ...body] = table.children ?? [];
84
92
  return (header?.children ?? []).flatMap((headCell, column) => {
85
93
  const name = cellText(source, headCell)?.text.trim() ?? "";
86
- return body.flatMap((row) => {
94
+ return body.flatMap((row, rowIndex) => {
87
95
  const cell = cellText(source, row.children?.[column]);
88
- return cell === undefined || name === "" ? [] : measured(`table ${String(index)}: ${name}`, name, cell.text, cell.start, units);
96
+ const place = `table ${String(index)} row ${String(rowIndex)}`;
97
+ return cell === undefined || name === "" ? [] : measured(`table ${String(index)}: ${name}`, name, cell.text, cell.start, units, place);
89
98
  });
90
99
  });
91
100
  };
@@ -134,6 +143,17 @@ export const unitGaps = (values: readonly Measured[]): UnitGap[] => {
134
143
  return [...kinds.values()].flatMap(gapsOfKind).toSorted((left, right) => left.value.offset - right.value.offset);
135
144
  };
136
145
 
146
+ /**
147
+ * A bare cell whose row gives another column, one that carries a unit elsewhere, a bare number too: the row counts a
148
+ * thing of its own (| Website visits | 412,000 | 486,000 | +18% |), in a table whose rows are different measures.
149
+ */
150
+ export const isBareRow = (gap: UnitGap, values: readonly Measured[]): boolean => {
151
+ const { row, kind } = gap.value;
152
+ if (row === undefined) return false;
153
+ const measuredKinds = new Set(values.filter((value) => value.unit !== "").map((value) => value.kind));
154
+ return values.some((value) => value.row === row && value.kind !== kind && value.unit === "" && measuredKinds.has(value.kind));
155
+ };
156
+
137
157
  const unitsOf = (doc: ProseDocument): Set<string> =>
138
158
  new Set(UNIT_LEXICONS.flatMap((name) => (doc.lexicons[name] ?? []).flatMap((entry) => [entry.pattern, entry.pattern.toLowerCase()])));
139
159
 
@@ -184,8 +204,9 @@ const scaleFindings = (doc: ProseDocument): Finding[] => {
184
204
 
185
205
  const columnFindings = (doc: ProseDocument): Finding[] => {
186
206
  const count = pieceCountOf(doc);
187
- return unitGaps(measuredValues(doc.source, doc.prose ?? doc.source, unitsOf(doc)))
188
- .filter((gap) => !isPieceCount(gap, count))
207
+ const values = measuredValues(doc.source, doc.prose ?? doc.source, unitsOf(doc));
208
+ return unitGaps(values)
209
+ .filter((gap) => !isPieceCount(gap, count) && !isBareRow(gap, values))
189
210
  .map((gap) => ({
190
211
  rule: "number-without-unit",
191
212
  severity: "warning",
@@ -0,0 +1,34 @@
1
+ import type { Span, Token } from "../plugin.ts";
2
+
3
+ // The long form a writer gives a short name to (性犯罪・性暴力の被害者のためのワンストップ支援センター(以下「ワンストップ支援センター」
4
+ // という)): the long form is a name the writer cannot rephrase, so its particles are read as one noun, like a quoted title.
5
+ // Pure: the words that open such an aside (以下) and what keeps a phrase going come in.
6
+
7
+ const OPENING = /[((]\s*/gu;
8
+
9
+ /** Where the asides that give a short name open in text (the bracket's offset), each opened by one of markers. */
10
+ const namingAsides = (text: string, markers: readonly string[]): number[] =>
11
+ [...text.matchAll(OPENING)]
12
+ .filter((open) => markers.some((marker) => marker !== "" && text.startsWith(marker, open.index + open[0].length)))
13
+ .map((open) => open.index);
14
+
15
+ /** The words written straight before at, back to the first one that does not continue the phrase. */
16
+ const phraseBefore = (tokens: readonly Token[], at: number, continues: (token: Token) => boolean): Span | undefined => {
17
+ const last = tokens.findLastIndex((token) => token.span.end <= at);
18
+ if (last === -1 || tokens[last]?.span.end !== at) return undefined;
19
+ const stop = tokens.slice(0, last + 1).findLastIndex((token) => !continues(token));
20
+ const first = tokens[stop + 1];
21
+ return first === undefined || stop === last ? undefined : { start: first.span.start, end: at };
22
+ };
23
+
24
+ /**
25
+ * The long forms named by an aside in a sentence (text starting at offset in the document, tokens in document offsets).
26
+ * markers: the words that open a naming aside (以下). continues: whether a word belongs to the phrase (a noun, the nesting の).
27
+ */
28
+ export const namedLongForms = (
29
+ text: string,
30
+ offset: number,
31
+ tokens: readonly Token[],
32
+ markers: readonly string[],
33
+ continues: (token: Token) => boolean,
34
+ ): Span[] => namingAsides(text, markers).flatMap((at) => phraseBefore(tokens, offset + at, continues) ?? []);
@@ -0,0 +1,27 @@
1
+ import { quotedSpans } from "../quoted-span.ts";
2
+ import type { Span } from "../plugin.ts";
3
+
4
+ // A name the document quotes once (「maDMPsのための共通データモデル」) and then writes without the brackets: still the same
5
+ // name, so its particles are read as one noun wherever it stands. Pure: the particles a name must hold come in.
6
+
7
+ /** Whether name holds one of particles inside it. One that ends in the particle (「実際の」) quotes words, not a name. */
8
+ const holdsParticle = (name: string, particles: readonly string[]): boolean =>
9
+ particles.some((particle) => particle !== "" && name.includes(particle) && !name.endsWith(particle));
10
+
11
+ /** The names quoted in 「」『』 anywhere in source that hold one of particles inside them, each once. */
12
+ export const quotedNames = (source: string, particles: readonly string[]): string[] => [
13
+ ...new Set(
14
+ quotedSpans(source)
15
+ .map((span) => source.slice(span.start, span.end))
16
+ .filter((name) => holdsParticle(name, particles)),
17
+ ),
18
+ ];
19
+
20
+ const placesOf = (text: string, name: string, from = 0): number[] => {
21
+ const at = text.indexOf(name, from);
22
+ return at === -1 ? [] : [at, ...placesOf(text, name, at + name.length)];
23
+ };
24
+
25
+ /** Where names stand in text (starting at offset in the document), with or without brackets. */
26
+ export const quotedNameSpans = (text: string, offset: number, names: readonly string[]): Span[] =>
27
+ names.flatMap((name) => placesOf(text, name).map((at) => ({ start: offset + at, end: offset + at + name.length })));
@@ -1,4 +1,4 @@
1
- import type { Section, Sentence } from "../plugin.ts";
1
+ import type { Paragraph, Section, Sentence } from "../plugin.ts";
2
2
 
3
3
  // A document that holds two texts under two top-level headings (a directive, then the agency's page about it) may write each in
4
4
  // its own register. A part whose sentences all share the register the rest of the document does not use is a text of its own,
@@ -40,3 +40,34 @@ export const separatePartSentences = <R>(
40
40
  return own ? sentences : [];
41
41
  }),
42
42
  );
43
+
44
+ /** A paragraph that holds no sentence with a register: a line of links or labels (第1, 第2), as a page lays out under the text it carries. */
45
+ const isRegisterless = <R>(paragraph: Paragraph, registerOf: (sentence: Sentence) => R | undefined): boolean =>
46
+ paragraph.sentences.length > 0 && paragraph.sentences.every((sentence) => registerOf(sentence) === undefined);
47
+
48
+ /**
49
+ * The page's own note after the text it carries, without a heading of its own (a directive in である, then ※…ご覧ください。, a line of
50
+ * links, and なお、…ありません。): every counted sentence after the last one in the majority register, when they are MIN_SENTENCES or
51
+ * more, all in one other register that no sentence before them uses, and a paragraph between the first and the last of them holds no counted sentence. Without
52
+ * that line the end of the document is the text's own closing; sentences are the document's in order, lists included; with the other register used earlier too, the end is not a part of its
53
+ * own, and setting it apart would leave the earlier sentences a smaller minority to be pointed at.
54
+ */
55
+ export const trailingPartSentences = <R>(
56
+ sentences: readonly Sentence[],
57
+ paragraphs: readonly Paragraph[],
58
+ registerOf: (sentence: Sentence) => R | undefined,
59
+ majority: R | undefined,
60
+ ): Set<Sentence> => {
61
+ const counted = sentences.filter((sentence) => registerOf(sentence) !== undefined);
62
+ const lastMajority = counted.findLastIndex((sentence) => registerOf(sentence) === majority);
63
+ if (majority === undefined || lastMajority < 0) return new Set();
64
+ const tail = counted.slice(lastMajority + 1);
65
+ const registers = tail.map(registerOf);
66
+ const before = counted.slice(0, lastMajority + 1);
67
+ const ownRegister =
68
+ tail.length >= MIN_SENTENCES && registers.every((register) => register === registers[0]) && before.every((sentence) => registerOf(sentence) === majority);
69
+ const from = tail[0]?.span.end ?? 0;
70
+ const to = tail.at(-1)?.span.start ?? 0;
71
+ const setOff = paragraphs.some((paragraph) => paragraph.span.start >= from && paragraph.span.end <= to && isRegisterless(paragraph, registerOf));
72
+ return ownRegister && setOff ? new Set(tail) : new Set();
73
+ };
@@ -21,18 +21,31 @@ const PAST = new Set(["た", "だ"]);
21
21
  const hasParticle = (tokens: readonly Token[], particles: readonly LexiconEntry[]): boolean =>
22
22
  tokens.some((token) => token.pos === "ADP" && particles.some((particle) => particle.pattern === token.surface));
23
23
 
24
+ /** The sentence ends in a forward-looking form from declaration-ending (…形にしていく。). */
25
+ const endsInResolve = (sentence: Sentence, endings: readonly LexiconEntry[]): boolean => {
26
+ const text = withoutTrailingMarks(sentence.text);
27
+ return endings.some((ending) => text.endsWith(ending.pattern));
28
+ };
29
+
24
30
  /**
25
31
  * A speaker's declaration (負担軽減を、目に見える形で実現する。二度と繰り返さない。): an object particle, no subject particle, and a
26
- * verb in the present at the end. particles is the declaration-particle word list already narrowed to the document's genre; without
27
- * an object particle for the genre the shape does not hold.
32
+ * verb in the present at the end. A sentence ending in a forward-looking form (現場の気づきを、幹部の皆さんが形にしていく。) declares even
33
+ * with its subject said. particles and endings are the declaration-particle and declaration-ending word lists already narrowed to the
34
+ * document's genre; without an object particle for the genre the shape does not hold.
28
35
  */
29
- export const isDeclaration = (sentence: Sentence, ending: readonly Token[], particles: readonly LexiconEntry[]): boolean => {
36
+ export const isDeclaration = (
37
+ sentence: Sentence,
38
+ ending: readonly Token[],
39
+ particles: readonly LexiconEntry[],
40
+ endings: readonly LexiconEntry[] = [],
41
+ ): boolean => {
30
42
  const objects = particles.filter((particle) => particle.group === "object");
31
43
  const subjects = particles.filter((particle) => particle.group === "subject");
32
44
  const tokens = sentence.tokens ?? [];
33
45
  const last = ending.at(-1);
34
46
  if (objects.length === 0 || last === undefined || PAST.has(last.surface)) return false;
35
- return ending.some((token) => token.pos === "VERB") && hasParticle(tokens, objects) && !hasParticle(tokens, subjects);
47
+ const subjectAllowed = !hasParticle(tokens, subjects) || endsInResolve(sentence, endings);
48
+ return ending.some((token) => token.pos === "VERB") && hasParticle(tokens, objects) && subjectAllowed;
36
49
  };
37
50
 
38
51
  /** The most tokens an opener in takeup-opener spans (これ/だけ). */
@@ -94,11 +94,14 @@ export const majorityOf = (judged: readonly Judged[]): Register | undefined => {
94
94
  return difference > 0 ? "polite" : "plain";
95
95
  };
96
96
 
97
- /** 少ないほう。同数なら文書全体で少ないほう、それも同数なら丁寧体。 */
98
- const minorityOf = (group: readonly Judged[], whole: readonly Judged[]): Register => {
99
- const majority = majorityOf(group);
100
- if (majority !== undefined) return majority === "polite" ? "plain" : "polite";
101
- return countIn(whole, "polite") <= countIn(whole, "plain") ? "polite" : "plain";
97
+ /**
98
+ * 少ないほう。同数なら文書全体で少ないほう。文書全体でも同数なら、揃える先の多いほうが無いので undefined(どちらも指さない)。
99
+ * 半々に書いた文書(くだけたメールの「お願いしたい。…です。…助かる。…送ります。」)は、書き損じではなく混ぜた書き方。
100
+ */
101
+ const minorityOf = (group: readonly Judged[], whole: readonly Judged[]): Register | undefined => {
102
+ const majority = majorityOf(group) ?? majorityOf(whole);
103
+ if (majority === undefined) return undefined;
104
+ return majority === "polite" ? "plain" : "polite";
102
105
  };
103
106
 
104
107
  /**
@@ -111,7 +114,7 @@ export const followsDocument = (group: number | undefined, minority: Register, w
111
114
  const slipsInGroup = <T extends Judged>(judged: readonly T[], group: number | undefined, limit: number): Slip<T>[] => {
112
115
  const members = judged.filter((entry) => entry.group === group);
113
116
  const minority = minorityOf(members, judged);
114
- if (followsDocument(group, minority, judged)) return [];
117
+ if (minority === undefined || followsDocument(group, minority, judged)) return [];
115
118
  const slips = members.filter((entry) => entry.register === minority);
116
119
  // 片方しか無ければ揃っている。少数派が閾値を超えて多ければ、混在ではなく別の文体。
117
120
  if (slips.length === 0 || slips.length > limit) return [];
@@ -3,7 +3,7 @@ import { enumeratedRuns, enumeratorStarts, numberedStarts } from "./enumerated-r
3
3
  import { continuesThrough, groupOf, majorityOf, registerOf, slipsOf, type Register } from "./register.ts";
4
4
  import { isRunInLabel } from "./run-in-label.ts";
5
5
  import { noticeSentences } from "./notice-paragraph.ts";
6
- import { separatePartSentences } from "./register-separate-part.ts";
6
+ import { separatePartSentences, trailingPartSentences } from "./register-separate-part.ts";
7
7
  import { askerSentences } from "./asker-voice.ts";
8
8
  import { licenceNoticeSentences } from "./licence-notice.ts";
9
9
  import { chronologyRows } from "../chronology-rows.ts";
@@ -26,6 +26,7 @@ import type { Detector, Finding, LexiconEntry, ProseDocument, Sentence, Span, To
26
26
  * 札を付けて引いた言葉(例:…。Q: …?)、印を付けた札の行の下の記入欄の値(■ 調査目的\n…とする。)、
27
27
  * 〒や電話の行のある問い合わせ先の段落も数えない(register-set-apart.ts)。
28
28
  * 一番上の見出しで分けた部分のうち、2 文以上がみな文書の多いほうと違う同じ調子のものは、別の文書として数えない(register-separate-part.ts)。
29
+ * 多いほうの最後の文より後ろの 2 文以上が、みな前に無い違う同じ調子で、間に調子を持たない行(リンクの並び)を挟むものも、ページの注記として数えない。
29
30
  */
30
31
  /**
31
32
  * quiet: 常体と読めるが、願い・問い・言いさしの形(register-neutral-shape.ts)の文。どちらの調子の文書にも現れるので指さない。
@@ -37,7 +38,7 @@ import type { Detector, Finding, LexiconEntry, ProseDocument, Sentence, Span, To
37
38
  type Entry = { readonly sentence: Sentence; readonly register: Register; readonly group: number | undefined; readonly quiet: boolean };
38
39
 
39
40
  /** 文の調子と quiet を決める語彙表。polite は polite-ending、neutral は neutral-ending、requests は neutral-request、wishes は neutral-wish、
40
- * greetings は set-polite-phrase、declaration は declaration-particle を文書の genre で絞ったもの、openers は takeup-opener。 */
41
+ * greetings は set-polite-phrase、declaration と resolves は declaration-particle と declaration-ending を文書の genre で絞ったもの、openers は takeup-opener。 */
41
42
  type EndingWords = {
42
43
  readonly polite: readonly LexiconEntry[];
43
44
  readonly neutral: readonly LexiconEntry[];
@@ -45,6 +46,7 @@ type EndingWords = {
45
46
  readonly wishes: readonly LexiconEntry[];
46
47
  readonly greetings: readonly LexiconEntry[];
47
48
  readonly declaration: readonly LexiconEntry[];
49
+ readonly resolves: readonly LexiconEntry[];
48
50
  readonly openers: readonly LexiconEntry[];
49
51
  };
50
52
 
@@ -57,6 +59,7 @@ const endingWords = (doc: ProseDocument, polite: readonly LexiconEntry[], genre:
57
59
  wishes: doc.lexicons["neutral-wish"] ?? [],
58
60
  greetings: doc.lexicons["set-polite-phrase"] ?? [],
59
61
  declaration: entriesForGenre(doc.lexicons["declaration-particle"] ?? [], genre),
62
+ resolves: entriesForGenre(doc.lexicons["declaration-ending"] ?? [], genre),
60
63
  openers: doc.lexicons["takeup-opener"] ?? [],
61
64
  });
62
65
 
@@ -65,7 +68,7 @@ const isQuiet = (sentence: Sentence, ending: readonly Token[], register: Registe
65
68
  register === "polite"
66
69
  ? endsInSetGreeting(sentence, words.greetings)
67
70
  : isNeutralPlainShape(sentence, ending, words.requests, words.wishes) ||
68
- isDeclaration(sentence, ending, words.declaration) ||
71
+ isDeclaration(sentence, ending, words.declaration, words.resolves) ||
69
72
  isExclamation(sentence) ||
70
73
  isTakenUp(next, between, words.openers);
71
74
 
@@ -124,7 +127,10 @@ export const judgedSentences = (doc: ProseDocument, polite: readonly LexiconEntr
124
127
  const majority = majorityOf(all.map((entry) => ({ register: entry.register, group: undefined })));
125
128
  const registerAt = (sentence: Sentence): Register | undefined => registers.get(sentence);
126
129
  const notices = noticeSentences(doc.paragraphs, doc.lexicons["notice-phrase"] ?? [], registerAt, majority);
127
- const parts = separatePartSentences(doc.sections, registerAt, majority);
130
+ const parts = new Set([
131
+ ...separatePartSentences(doc.sections, registerAt, majority),
132
+ ...trailingPartSentences(doc.sentences, doc.paragraphs, registerAt, majority),
133
+ ]);
128
134
  const found = all.filter((entry) => !notices.has(entry.sentence) && !parts.has(entry.sentence));
129
135
  const runs = runsOf(
130
136
  doc,
@@ -14,6 +14,7 @@ import { caseVariantsIn, spelledOutAcronyms, writtenAsWordIn } from "./acronym-m
14
14
  import { conjugatedForms } from "./conjugated-form.ts";
15
15
  import { knownByDocument } from "./acronym-known.ts";
16
16
  import { explainedInText, headingsSpellingOut } from "./acronym-gloss.ts";
17
+ import { fileTypeNames, type AcronymUse } from "./acronym-file-type.ts";
17
18
  import { nameSpans } from "../team-names.ts";
18
19
  import { DASH, introducesList, opensLine } from "./lead-in-dash.ts";
19
20
  import type { Detector, Finding, ProseDocument, Sentence } from "../plugin.ts";
@@ -88,15 +89,18 @@ const ACRONYM = new RegExp(String.raw`${EDGE_BEFORE}${ACRONYM_PART}(?:-${ACRONYM
88
89
  * 強調は読点や括弧をまたいで続くので(THE AUTHOR, THE COMPANY (IF ANY))、そういう続きを含む
89
90
  * 「大文字以外の文字を含まない一続き」を丸ごと強調と見なす。小文字の語が挟まれば切れるので、
90
91
  * 「SRE, SLO, MTTR」のような略語の並びは残る。引用符に包まれた大文字の句(“AS IS”)も強調。
91
- * 2 語でも、片方が略語にしては長い語なら強調(BILLING CODE)。略語 2 つの並び(NIST SP)は残る。
92
+ * 2 語でも、片方が略語にしては長い語なら強調(BILLING CODE)。どちらも 5 字以上の 2 語(MIRAI SCHOOL、UNITED STATES)は
93
+ * 大文字で書いた名前や語で、略語がそう並ぶことはない。略語 2 つの並び(NIST SP、FEMA NFIP)は残る。
92
94
  */
93
95
  const CAPS_WORD = String.raw`[A-Z]+(?:&[A-Z]+)*`;
94
96
  const LONG_CAPS_WORD = String.raw`[A-Z]{${ACRONYM_MAX + 1},}`;
97
+ const WORD_PAIR_MIN = 5;
98
+ const WORD_PAIR_PART = String.raw`[A-Z]{${WORD_PAIR_MIN},}`;
95
99
  const CAPS_GAP = String.raw`[\s"“”'‘’]+`;
96
100
  const SHOUTED_RUN = new RegExp(String.raw`${EDGE_BEFORE}${CAPS_WORD}(?:${CAPS_GAP}${CAPS_WORD}){2,}${EDGE_AFTER}`, "u");
97
101
  /** 2 語の強調は、その 2 語だけを外す。続きまで外すと、区切りの後ろの略語(NEW GUIDELINES: SRE)まで消える。 */
98
102
  const SHOUTED_PAIR = new RegExp(
99
- String.raw`${EDGE_BEFORE}(?:${LONG_CAPS_WORD}${CAPS_GAP}${CAPS_WORD}|${CAPS_WORD}${CAPS_GAP}${LONG_CAPS_WORD})${EDGE_AFTER}`,
103
+ String.raw`${EDGE_BEFORE}(?:${LONG_CAPS_WORD}${CAPS_GAP}${CAPS_WORD}|${CAPS_WORD}${CAPS_GAP}${LONG_CAPS_WORD}|${WORD_PAIR_PART}${CAPS_GAP}${WORD_PAIR_PART})${EDGE_AFTER}`,
100
104
  "gu",
101
105
  );
102
106
  const UNCASED_STRETCH = /(?:[A-Z]|\P{L})+/gu;
@@ -150,6 +154,14 @@ const acronymsOf = (doc: ProseDocument, notation: NotAcronymSpans): AcronymHit[]
150
154
  .filter(({ hit }) => !isEmphasised(hit.sentence, hit.offset));
151
155
  });
152
156
 
157
+ /** 略語のすぐ前と後ろの文字列と、後ろに始まる語の品詞。 */
158
+ const fileUseOf = ({ word, hit }: AcronymHit): AcronymUse => {
159
+ const start = hit.offset - hit.sentence.span.start;
160
+ const next = (hit.sentence.tokens ?? []).find((token) => token.span.start >= hit.offset + word.length);
161
+ const { text } = hit.sentence;
162
+ return { word, preceding: text.slice(Math.max(0, start - 2), start), following: text.slice(start + word.length), nextPos: next?.pos };
163
+ };
164
+
153
165
  /** 略語ごとの、最初に現れた所。 */
154
166
  const firstHits = (hits: readonly AcronymHit[]): Map<string, Hit> => {
155
167
  const seen = new Map<string, Hit>();
@@ -199,6 +211,13 @@ const definitionWordsOf = (doc: ProseDocument): DefinitionWords => {
199
211
  return { markers: patternsOf(doc, "definition-marker"), verbs: [...verbs, ...conjugatedForms(doc.sentences, verbs)], alternatives };
200
212
  };
201
213
 
214
+ /** 数える略語のすべての所。文書全体で読む書き方の範囲(所在地、文献一覧)と、編と区分で引く法令集(21 CFR subpart J)の中は外す。 */
215
+ const countedHitsOf = (doc: ProseDocument): AcronymHit[] =>
216
+ outsideSpans(acronymsOf(doc, notationOf(doc)), [
217
+ ...sourceNotAcronymSpans(doc.source, (id) => patternsOf(doc, id)),
218
+ ...titledCodeSpans(doc.source, patternsOf(doc, "citation-series")),
219
+ ]);
220
+
202
221
  const acronymFinding = (acronym: string, hit: Hit, count: number, limit: number): Finding => ({
203
222
  rule: "undefined-acronym",
204
223
  severity: "info",
@@ -240,7 +259,10 @@ export const undefinedAcronym: Detector = (doc, options): Finding[] => {
240
259
  // 2 つ以上の番号で引く続き物の名前(BCP 78、BCP 14)も、略語の説明と読む。
241
260
  // 文献一覧の見出し語([UNIX] The Open Group, "The Single UNIX Specification")と、見出しに番号で立てた書簡の続き物(### SR 26-8: …)も。
242
261
  const headings = doc.sections.map((section) => halfWidth(section.heading));
262
+ const counted = countedHitsOf(doc);
263
+ // ファイルの種類の名前としてだけ書いた大文字(the MAP files、MAPファイル)も、展開を待つ略語ではない。
243
264
  const entries = new Set([
265
+ ...fileTypeNames(counted.map(fileUseOf), patternsOf(doc, "file-noun")),
244
266
  ...termEntryAcronyms(doc.source),
245
267
  ...stated,
246
268
  ...linkedListTerms(doc.source),
@@ -267,10 +289,6 @@ export const undefinedAcronym: Detector = (doc, options): Finding[] => {
267
289
  explained.set(word, known);
268
290
  return known;
269
291
  };
270
- const counted = outsideSpans(acronymsOf(doc, notationOf(doc)), [
271
- ...sourceNotAcronymSpans(doc.source, (id) => patternsOf(doc, id)),
272
- ...titledCodeSpans(doc.source, patternsOf(doc, "citation-series")),
273
- ]);
274
292
  const hits = outsideSpans(
275
293
  counted,
276
294
  unreportedAcronymSpans(doc.source, doc.sentences, doc.links, (id) => patternsOf(doc, id)),
@@ -6,10 +6,11 @@ import { isWithinAny, quotedIn, QUOTATION_MARKS } from "../quoted-span.ts";
6
6
  const STACKED_AT = 2;
7
7
 
8
8
  /**
9
- * 語彙表 3 つ。hedges は逃げの表現そのもの、frames はそれだけでは逃げていない包む言い方(「という状況です」、may)、
10
- * scope は hedges のうち、どれだけ確かかではなくどこで成り立つかを言うもの(「場合がある」、in some cases)。
9
+ * 語彙表 4 つ。hedges は逃げの表現そのもの、frames はそれだけでは逃げていない包む言い方(「という状況です」、may)、
10
+ * scope は hedges のうち、書き手の確かさを下げないもの(「場合がある」、「と思われている」)、
11
+ * complements は動詞の後ろで中身の節を始める語(knowing that の that)。
11
12
  */
12
- export type HedgeWords = { readonly hedges: Lexicon; readonly frames: Lexicon; readonly scope: Lexicon };
13
+ export type HedgeWords = { readonly hedges: Lexicon; readonly frames: Lexicon; readonly scope: Lexicon; readonly complements: Lexicon };
13
14
 
14
15
  type Device = { readonly range: TokenRange; readonly hedge: boolean };
15
16
 
@@ -41,10 +42,25 @@ const spanOf = (tokens: readonly Token[], range: TokenRange): Span | undefined =
41
42
  /** 句読点と等位接続詞(and、but、及び)は節を切る。別の節の逃げは、同じ主張を二重にぼかしていない。 */
42
43
  const CLAUSE_BREAK = new Set(["PUNCT", "CCONJ"]);
43
44
 
45
+ /**
46
+ * 動詞の後ろで中身の節を始める語の位置(knowing that の that)。その節の may は知っていることの中身で、
47
+ * 前の perhaps と同じ主張をぼかしていない。逃げの表現の動詞(it seems that)の後ろは、その逃げが包む節なので切らない。
48
+ */
49
+ const complementOpens = (sentence: Sentence, complements: Lexicon, devices: readonly Device[]): Set<number> => {
50
+ const tokens = sentence.tokens ?? [];
51
+ const inDevice = (at: number): boolean => devices.some((device) => device.range.start <= at && at < device.range.end);
52
+ const opensAfterVerb = (range: TokenRange): boolean => tokens[range.start - 1]?.pos === "VERB" && !inDevice(range.start - 1);
53
+ return new Set(
54
+ rangesOf(sentence, complements)
55
+ .filter(opensAfterVerb)
56
+ .map((range) => range.start),
57
+ );
58
+ };
59
+
44
60
  /** 語ごとの、文の頭から数えた節の番号。 */
45
- const clauseOf = (tokens: readonly Token[]): number[] =>
46
- tokens.reduce<number[]>((clauses, token) => {
47
- clauses.push((clauses.at(-1) ?? 0) + (CLAUSE_BREAK.has(token.pos) ? 1 : 0));
61
+ const clauseOf = (tokens: readonly Token[], opens: ReadonlySet<number>): number[] =>
62
+ tokens.reduce<number[]>((clauses, token, at) => {
63
+ clauses.push((clauses.at(-1) ?? 0) + (CLAUSE_BREAK.has(token.pos) || opens.has(at) ? 1 : 0));
48
64
  return clauses;
49
65
  }, []);
50
66
 
@@ -84,7 +100,8 @@ const stackedClause = (devices: readonly Device[], clauses: readonly number[]):
84
100
  */
85
101
  const stackedHedgeIn = (sentence: Sentence, words: HedgeWords): Span[] => {
86
102
  const tokens = sentence.tokens ?? [];
87
- return stackedClause(devicesIn(sentence, words), clauseOf(tokens))
103
+ const devices = devicesIn(sentence, words);
104
+ return stackedClause(devices, clauseOf(tokens, complementOpens(sentence, words.complements, devices)))
88
105
  .toSorted((left, right) => left.range.start - right.range.start)
89
106
  .flatMap((device) => spanOf(tokens, { start: device.range.start, end: shownEnd(tokens, device.range) }) ?? []);
90
107
  };
@@ -8,6 +8,8 @@ import { honorificGroupParticles } from "../honorific-group.ts";
8
8
  import { setPhraseParticles } from "../set-phrase-particles.ts";
9
9
  import { noteSentences } from "../note-paragraphs.ts";
10
10
  import { documentNameSpans } from "./particle-run-names.ts";
11
+ import { namedLongForms } from "./particle-run-long-forms.ts";
12
+ import { quotedNameSpans, quotedNames } from "./particle-run-quoted-names.ts";
11
13
  import { isFlattenedTable } from "./sentence-parts.ts";
12
14
 
13
15
  /**
@@ -89,6 +91,9 @@ const runsOf = (tokens: readonly Token[], nesting: readonly string[], breaks: re
89
91
  return acc;
90
92
  }, []);
91
93
 
94
+ /** 括弧の中で、前の語句に短い呼び名を付ける語(以下「…」という)。前の語句は名前なので、題名と同じく中の助詞を数えない。 */
95
+ const NAMING_LEXICON = "definition-marker";
96
+
92
97
  /** 句と句の間の記号(制限=タグの制限、A→B)。半角の = や : は名詞として読まれ、句読点のようには切れない。 */
93
98
  const RUN_BREAK_LEXICON = "particle-run-break";
94
99
 
@@ -118,12 +123,20 @@ export const doubledParticle: Detector = (doc, options): Finding[] => {
118
123
  setPhrases: (doc.lexicons[SET_PHRASE_LEXICON] ?? []).map((entry) => entry.pattern),
119
124
  };
120
125
  const prose = doc.prose ?? doc.source;
126
+ const namingMarkers = (doc.lexicons[NAMING_LEXICON] ?? []).map((entry) => entry.pattern);
127
+ const names = quotedNames(doc.source, nesting);
128
+ const continuesName = (token: Token): boolean => nesting.includes(token.surface) || !breaksRun(token, breaks);
121
129
  // 平らにした表の文は、見出しのセル(役員の兼任等・営業上の取引・設備の賃貸借)の切れ目が見えず、別のセルの「の」が一つの連なりに見える。
122
130
  return doc.sentences
123
131
  .filter((sentence) => !isFlattenedTable(sentence.text))
124
132
  .flatMap((sentence) => {
125
133
  const tokens = chainTokens(sentence.tokens ?? [], numbering, phrases);
126
- const quoted = [...quotedIn(sentence), ...titles];
134
+ const quoted = [
135
+ ...quotedIn(sentence),
136
+ ...titles,
137
+ ...namedLongForms(sentence.text, sentence.span.start, sentence.tokens ?? [], namingMarkers, continuesName),
138
+ ...quotedNameSpans(sentence.text, sentence.span.start, names),
139
+ ];
127
140
  const longRuns = (skipped: readonly Span[]): Run[] => runsOf(tokens, nesting, breaks, skipped).filter((run) => run.tokens.length > options.limit);
128
141
  const found = longRuns(quoted);
129
142
  // 文書の名前を読むのは長い連なりのある文だけ。名前は位置ごとに読むので、全部の文で読むと遅い。