chaffjs 0.39.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (434) hide show
  1. package/README.ja.md +3 -2
  2. package/README.md +2 -1
  3. package/dist/ai-score/human-shares.d.ts.map +1 -1
  4. package/dist/ai-score/human-shares.js +1 -0
  5. package/dist/ai-score/human-shares.js.map +1 -1
  6. package/dist/alternative-words.d.ts +6 -0
  7. package/dist/alternative-words.d.ts.map +1 -1
  8. package/dist/alternative-words.js +10 -0
  9. package/dist/alternative-words.js.map +1 -1
  10. package/dist/closing-code.d.ts +8 -0
  11. package/dist/closing-code.d.ts.map +1 -0
  12. package/dist/closing-code.js +18 -0
  13. package/dist/closing-code.js.map +1 -0
  14. package/dist/composite-signals.d.ts +6 -0
  15. package/dist/composite-signals.d.ts.map +1 -0
  16. package/dist/composite-signals.js +23 -0
  17. package/dist/composite-signals.js.map +1 -0
  18. package/dist/date-format.d.ts +19 -1
  19. package/dist/date-format.d.ts.map +1 -1
  20. package/dist/date-format.js +41 -5
  21. package/dist/date-format.js.map +1 -1
  22. package/dist/detectors/acronym-context.d.ts +5 -1
  23. package/dist/detectors/acronym-context.d.ts.map +1 -1
  24. package/dist/detectors/acronym-context.js +48 -2
  25. package/dist/detectors/acronym-context.js.map +1 -1
  26. package/dist/detectors/acronym-mention.d.ts +5 -0
  27. package/dist/detectors/acronym-mention.d.ts.map +1 -1
  28. package/dist/detectors/acronym-mention.js +16 -0
  29. package/dist/detectors/acronym-mention.js.map +1 -1
  30. package/dist/detectors/acronym-name.d.ts +5 -0
  31. package/dist/detectors/acronym-name.d.ts.map +1 -1
  32. package/dist/detectors/acronym-name.js +15 -0
  33. package/dist/detectors/acronym-name.js.map +1 -1
  34. package/dist/detectors/acronym-series.d.ts +5 -0
  35. package/dist/detectors/acronym-series.d.ts.map +1 -1
  36. package/dist/detectors/acronym-series.js +18 -3
  37. package/dist/detectors/acronym-series.js.map +1 -1
  38. package/dist/detectors/ai-phrasing.d.ts.map +1 -1
  39. package/dist/detectors/ai-phrasing.js +7 -1
  40. package/dist/detectors/ai-phrasing.js.map +1 -1
  41. package/dist/detectors/ai-structure.d.ts.map +1 -1
  42. package/dist/detectors/ai-structure.js +6 -2
  43. package/dist/detectors/ai-structure.js.map +1 -1
  44. package/dist/detectors/blank-runs.d.ts +12 -0
  45. package/dist/detectors/blank-runs.d.ts.map +1 -0
  46. package/dist/detectors/blank-runs.js +27 -0
  47. package/dist/detectors/blank-runs.js.map +1 -0
  48. package/dist/detectors/bold-label.d.ts +3 -1
  49. package/dist/detectors/bold-label.d.ts.map +1 -1
  50. package/dist/detectors/bold-label.js +16 -6
  51. package/dist/detectors/bold-label.js.map +1 -1
  52. package/dist/detectors/capitalised-term.d.ts.map +1 -1
  53. package/dist/detectors/capitalised-term.js +28 -9
  54. package/dist/detectors/capitalised-term.js.map +1 -1
  55. package/dist/detectors/citation-string.d.ts +6 -0
  56. package/dist/detectors/citation-string.d.ts.map +1 -1
  57. package/dist/detectors/citation-string.js +52 -0
  58. package/dist/detectors/citation-string.js.map +1 -1
  59. package/dist/detectors/contraction-emphasis.d.ts +3 -0
  60. package/dist/detectors/contraction-emphasis.d.ts.map +1 -0
  61. package/dist/detectors/contraction-emphasis.js +24 -0
  62. package/dist/detectors/contraction-emphasis.js.map +1 -0
  63. package/dist/detectors/contraction-mention.d.ts +12 -1
  64. package/dist/detectors/contraction-mention.d.ts.map +1 -1
  65. package/dist/detectors/contraction-mention.js +39 -6
  66. package/dist/detectors/contraction-mention.js.map +1 -1
  67. package/dist/detectors/contraction-mix.d.ts +3 -0
  68. package/dist/detectors/contraction-mix.d.ts.map +1 -0
  69. package/dist/detectors/contraction-mix.js +76 -0
  70. package/dist/detectors/contraction-mix.js.map +1 -0
  71. package/dist/detectors/contraction-set-apart.d.ts +14 -0
  72. package/dist/detectors/contraction-set-apart.d.ts.map +1 -0
  73. package/dist/detectors/contraction-set-apart.js +42 -0
  74. package/dist/detectors/contraction-set-apart.js.map +1 -0
  75. package/dist/detectors/date-format.d.ts.map +1 -1
  76. package/dist/detectors/date-format.js +13 -1
  77. package/dist/detectors/date-format.js.map +1 -1
  78. package/dist/detectors/densest-stretch.d.ts +11 -0
  79. package/dist/detectors/densest-stretch.d.ts.map +1 -0
  80. package/dist/detectors/densest-stretch.js +14 -0
  81. package/dist/detectors/densest-stretch.js.map +1 -0
  82. package/dist/detectors/doubled-word.d.ts.map +1 -1
  83. package/dist/detectors/doubled-word.js +8 -4
  84. package/dist/detectors/doubled-word.js.map +1 -1
  85. package/dist/detectors/duplicate-definition.d.ts +3 -0
  86. package/dist/detectors/duplicate-definition.d.ts.map +1 -0
  87. package/dist/detectors/duplicate-definition.js +16 -0
  88. package/dist/detectors/duplicate-definition.js.map +1 -0
  89. package/dist/detectors/final-period-captions.d.ts +15 -0
  90. package/dist/detectors/final-period-captions.d.ts.map +1 -0
  91. package/dist/detectors/final-period-captions.js +61 -0
  92. package/dist/detectors/final-period-captions.js.map +1 -0
  93. package/dist/detectors/fullwidth-alnum.d.ts +3 -0
  94. package/dist/detectors/fullwidth-alnum.d.ts.map +1 -1
  95. package/dist/detectors/fullwidth-alnum.js +11 -2
  96. package/dist/detectors/fullwidth-alnum.js.map +1 -1
  97. package/dist/detectors/gram-furniture.d.ts +8 -5
  98. package/dist/detectors/gram-furniture.d.ts.map +1 -1
  99. package/dist/detectors/gram-furniture.js +23 -13
  100. package/dist/detectors/gram-furniture.js.map +1 -1
  101. package/dist/detectors/gram-openers.d.ts +11 -0
  102. package/dist/detectors/gram-openers.d.ts.map +1 -1
  103. package/dist/detectors/gram-openers.js +42 -1
  104. package/dist/detectors/gram-openers.js.map +1 -1
  105. package/dist/detectors/gram-repetition.d.ts.map +1 -1
  106. package/dist/detectors/gram-repetition.js +18 -7
  107. package/dist/detectors/gram-repetition.js.map +1 -1
  108. package/dist/detectors/heading-sentences.d.ts +10 -0
  109. package/dist/detectors/heading-sentences.d.ts.map +1 -0
  110. package/dist/detectors/heading-sentences.js +32 -0
  111. package/dist/detectors/heading-sentences.js.map +1 -0
  112. package/dist/detectors/known-correction.d.ts.map +1 -1
  113. package/dist/detectors/known-correction.js +11 -9
  114. package/dist/detectors/known-correction.js.map +1 -1
  115. package/dist/detectors/lexicon.d.ts +2 -3
  116. package/dist/detectors/lexicon.d.ts.map +1 -1
  117. package/dist/detectors/lexicon.js +16 -56
  118. package/dist/detectors/lexicon.js.map +1 -1
  119. package/dist/detectors/list-lead-in.d.ts +1 -1
  120. package/dist/detectors/list-lead-in.d.ts.map +1 -1
  121. package/dist/detectors/list-lead-in.js +42 -11
  122. package/dist/detectors/list-lead-in.js.map +1 -1
  123. package/dist/detectors/list-run.d.ts.map +1 -1
  124. package/dist/detectors/list-run.js +16 -2
  125. package/dist/detectors/list-run.js.map +1 -1
  126. package/dist/detectors/missing-final-period.d.ts.map +1 -1
  127. package/dist/detectors/missing-final-period.js +3 -1
  128. package/dist/detectors/missing-final-period.js.map +1 -1
  129. package/dist/detectors/numbering-readings.d.ts +2 -2
  130. package/dist/detectors/numbering-readings.d.ts.map +1 -1
  131. package/dist/detectors/numbering-readings.js +7 -0
  132. package/dist/detectors/numbering-readings.js.map +1 -1
  133. package/dist/detectors/open-end-anaphor.d.ts +8 -0
  134. package/dist/detectors/open-end-anaphor.d.ts.map +1 -0
  135. package/dist/detectors/open-end-anaphor.js +22 -0
  136. package/dist/detectors/open-end-anaphor.js.map +1 -0
  137. package/dist/detectors/open-end-lead.d.ts +4 -0
  138. package/dist/detectors/open-end-lead.d.ts.map +1 -0
  139. package/dist/detectors/open-end-lead.js +34 -0
  140. package/dist/detectors/open-end-lead.js.map +1 -0
  141. package/dist/detectors/open-end-scope.d.ts.map +1 -1
  142. package/dist/detectors/open-end-scope.js +7 -1
  143. package/dist/detectors/open-end-scope.js.map +1 -1
  144. package/dist/detectors/ordinal-run-gaps.d.ts +1 -0
  145. package/dist/detectors/ordinal-run-gaps.d.ts.map +1 -1
  146. package/dist/detectors/ordinal-run-gaps.js +1 -1
  147. package/dist/detectors/ordinal-run-gaps.js.map +1 -1
  148. package/dist/detectors/orthographic-variant-open.d.ts +4 -2
  149. package/dist/detectors/orthographic-variant-open.d.ts.map +1 -1
  150. package/dist/detectors/orthographic-variant-open.js +5 -3
  151. package/dist/detectors/orthographic-variant-open.js.map +1 -1
  152. package/dist/detectors/orthography.d.ts.map +1 -1
  153. package/dist/detectors/orthography.js +14 -5
  154. package/dist/detectors/orthography.js.map +1 -1
  155. package/dist/detectors/oxford-comma.d.ts.map +1 -1
  156. package/dist/detectors/oxford-comma.js +17 -2
  157. package/dist/detectors/oxford-comma.js.map +1 -1
  158. package/dist/detectors/phrase-match.d.ts.map +1 -1
  159. package/dist/detectors/phrase-match.js +3 -2
  160. package/dist/detectors/phrase-match.js.map +1 -1
  161. package/dist/detectors/placeholder-text.d.ts.map +1 -1
  162. package/dist/detectors/placeholder-text.js +14 -2
  163. package/dist/detectors/placeholder-text.js.map +1 -1
  164. package/dist/detectors/quote-without-source.d.ts +6 -2
  165. package/dist/detectors/quote-without-source.d.ts.map +1 -1
  166. package/dist/detectors/quote-without-source.js +33 -8
  167. package/dist/detectors/quote-without-source.js.map +1 -1
  168. package/dist/detectors/quoted-pattern.d.ts +2 -0
  169. package/dist/detectors/quoted-pattern.d.ts.map +1 -0
  170. package/dist/detectors/quoted-pattern.js +13 -0
  171. package/dist/detectors/quoted-pattern.js.map +1 -0
  172. package/dist/detectors/reference-entry.d.ts +5 -0
  173. package/dist/detectors/reference-entry.d.ts.map +1 -1
  174. package/dist/detectors/reference-entry.js +6 -1
  175. package/dist/detectors/reference-entry.js.map +1 -1
  176. package/dist/detectors/register-separate-part.d.ts +7 -0
  177. package/dist/detectors/register-separate-part.d.ts.map +1 -0
  178. package/dist/detectors/register-separate-part.js +32 -0
  179. package/dist/detectors/register-separate-part.js.map +1 -0
  180. package/dist/detectors/registry/contraction-mix.js +1 -1
  181. package/dist/detectors/registry/contraction-mix.js.map +1 -1
  182. package/dist/detectors/registry/duplicate-definition.js +1 -1
  183. package/dist/detectors/registry/duplicate-definition.js.map +1 -1
  184. package/dist/detectors/relative-pronoun-mix.d.ts.map +1 -1
  185. package/dist/detectors/relative-pronoun-mix.js +7 -3
  186. package/dist/detectors/relative-pronoun-mix.js.map +1 -1
  187. package/dist/detectors/reproduced-text.d.ts +5 -0
  188. package/dist/detectors/reproduced-text.d.ts.map +1 -0
  189. package/dist/detectors/reproduced-text.js +19 -0
  190. package/dist/detectors/reproduced-text.js.map +1 -0
  191. package/dist/detectors/request-owner.d.ts +2 -1
  192. package/dist/detectors/request-owner.d.ts.map +1 -1
  193. package/dist/detectors/request-owner.js +31 -7
  194. package/dist/detectors/request-owner.js.map +1 -1
  195. package/dist/detectors/requirement-smell.d.ts.map +1 -1
  196. package/dist/detectors/requirement-smell.js +16 -5
  197. package/dist/detectors/requirement-smell.js.map +1 -1
  198. package/dist/detectors/sentence-counts.d.ts +2 -1
  199. package/dist/detectors/sentence-counts.d.ts.map +1 -1
  200. package/dist/detectors/sentence-counts.js +23 -7
  201. package/dist/detectors/sentence-counts.js.map +1 -1
  202. package/dist/detectors/sentence-ending.d.ts +1 -0
  203. package/dist/detectors/sentence-ending.d.ts.map +1 -1
  204. package/dist/detectors/sentence-ending.js +5 -2
  205. package/dist/detectors/sentence-ending.js.map +1 -1
  206. package/dist/detectors/sentence-length.d.ts.map +1 -1
  207. package/dist/detectors/sentence-length.js +13 -3
  208. package/dist/detectors/sentence-length.js.map +1 -1
  209. package/dist/detectors/sentence-parts.d.ts +7 -0
  210. package/dist/detectors/sentence-parts.d.ts.map +1 -1
  211. package/dist/detectors/sentence-parts.js +11 -1
  212. package/dist/detectors/sentence-parts.js.map +1 -1
  213. package/dist/detectors/signals.d.ts.map +1 -1
  214. package/dist/detectors/signals.js +31 -7
  215. package/dist/detectors/signals.js.map +1 -1
  216. package/dist/detectors/spelling-variety.d.ts.map +1 -1
  217. package/dist/detectors/spelling-variety.js +20 -2
  218. package/dist/detectors/spelling-variety.js.map +1 -1
  219. package/dist/detectors/structure-tree.d.ts +2 -1
  220. package/dist/detectors/structure-tree.d.ts.map +1 -1
  221. package/dist/detectors/structure-tree.js +2 -7
  222. package/dist/detectors/structure-tree.js.map +1 -1
  223. package/dist/detectors/structure.d.ts.map +1 -1
  224. package/dist/detectors/structure.js +19 -5
  225. package/dist/detectors/structure.js.map +1 -1
  226. package/dist/detectors/superlative-context.d.ts +2 -1
  227. package/dist/detectors/superlative-context.d.ts.map +1 -1
  228. package/dist/detectors/superlative-context.js +9 -2
  229. package/dist/detectors/superlative-context.js.map +1 -1
  230. package/dist/detectors/title-list.d.ts +7 -0
  231. package/dist/detectors/title-list.d.ts.map +1 -0
  232. package/dist/detectors/title-list.js +14 -0
  233. package/dist/detectors/title-list.js.map +1 -0
  234. package/dist/detectors/token-shape.d.ts.map +1 -1
  235. package/dist/detectors/token-shape.js +17 -7
  236. package/dist/detectors/token-shape.js.map +1 -1
  237. package/dist/detectors/undefined-term.d.ts +5 -0
  238. package/dist/detectors/undefined-term.d.ts.map +1 -1
  239. package/dist/detectors/undefined-term.js +22 -1
  240. package/dist/detectors/undefined-term.js.map +1 -1
  241. package/dist/detectors/unfilled-placeholder.d.ts.map +1 -1
  242. package/dist/detectors/unfilled-placeholder.js +15 -1
  243. package/dist/detectors/unfilled-placeholder.js.map +1 -1
  244. package/dist/detectors/unknown-word-context.d.ts +9 -0
  245. package/dist/detectors/unknown-word-context.d.ts.map +1 -1
  246. package/dist/detectors/unknown-word-context.js +15 -0
  247. package/dist/detectors/unknown-word-context.js.map +1 -1
  248. package/dist/detectors/unknown-word.d.ts.map +1 -1
  249. package/dist/detectors/unknown-word.js +12 -4
  250. package/dist/detectors/unknown-word.js.map +1 -1
  251. package/dist/latin-spacing-source.d.ts +12 -0
  252. package/dist/latin-spacing-source.d.ts.map +1 -0
  253. package/dist/latin-spacing-source.js +25 -0
  254. package/dist/latin-spacing-source.js.map +1 -0
  255. package/dist/name-separator.d.ts.map +1 -1
  256. package/dist/name-separator.js +4 -1
  257. package/dist/name-separator.js.map +1 -1
  258. package/dist/paragraph-length.d.ts +14 -0
  259. package/dist/paragraph-length.d.ts.map +1 -1
  260. package/dist/paragraph-length.js +25 -0
  261. package/dist/paragraph-length.js.map +1 -1
  262. package/dist/paragraph-runs.d.ts +2 -2
  263. package/dist/paragraph-runs.d.ts.map +1 -1
  264. package/dist/paragraph-runs.js +65 -14
  265. package/dist/paragraph-runs.js.map +1 -1
  266. package/dist/plugin.d.ts +2 -0
  267. package/dist/plugin.d.ts.map +1 -1
  268. package/dist/quote-echo.d.ts +6 -0
  269. package/dist/quote-echo.d.ts.map +1 -0
  270. package/dist/quote-echo.js +14 -0
  271. package/dist/quote-echo.js.map +1 -0
  272. package/dist/run.d.ts.map +1 -1
  273. package/dist/run.js +4 -2
  274. package/dist/run.js.map +1 -1
  275. package/dist/semantic.d.ts.map +1 -1
  276. package/dist/semantic.js +2 -2
  277. package/dist/semantic.js.map +1 -1
  278. package/dist/set-phrase-particles.d.ts +4 -0
  279. package/dist/set-phrase-particles.d.ts.map +1 -0
  280. package/dist/set-phrase-particles.js +26 -0
  281. package/dist/set-phrase-particles.js.map +1 -0
  282. package/dist/structure/alternative-clause.d.ts +7 -0
  283. package/dist/structure/alternative-clause.d.ts.map +1 -1
  284. package/dist/structure/alternative-clause.js +23 -8
  285. package/dist/structure/alternative-clause.js.map +1 -1
  286. package/dist/structure/cited-document-section.d.ts +2 -0
  287. package/dist/structure/cited-document-section.d.ts.map +1 -1
  288. package/dist/structure/cited-document-section.js +8 -0
  289. package/dist/structure/cited-document-section.js.map +1 -1
  290. package/dist/structure/issues.d.ts +3 -1
  291. package/dist/structure/issues.d.ts.map +1 -1
  292. package/dist/structure/issues.js +12 -8
  293. package/dist/structure/issues.js.map +1 -1
  294. package/dist/structure/numbering.d.ts +10 -1
  295. package/dist/structure/numbering.d.ts.map +1 -1
  296. package/dist/structure/numbering.js +41 -4
  297. package/dist/structure/numbering.js.map +1 -1
  298. package/dist/structure/unread-label.d.ts +13 -0
  299. package/dist/structure/unread-label.d.ts.map +1 -0
  300. package/dist/structure/unread-label.js +70 -0
  301. package/dist/structure/unread-label.js.map +1 -0
  302. package/dist/structure-shape/faq-sections.d.ts +7 -0
  303. package/dist/structure-shape/faq-sections.d.ts.map +1 -0
  304. package/dist/structure-shape/faq-sections.js +14 -0
  305. package/dist/structure-shape/faq-sections.js.map +1 -0
  306. package/dist/structure-shape/features.d.ts.map +1 -1
  307. package/dist/structure-shape/features.js +5 -3
  308. package/dist/structure-shape/features.js.map +1 -1
  309. package/dist/topic-clause.d.ts.map +1 -1
  310. package/dist/topic-clause.js +15 -2
  311. package/dist/topic-clause.js.map +1 -1
  312. package/package.json +3 -3
  313. package/rules/ai-generated-composite.yaml +3 -2
  314. package/rules/ai-structure.yaml +2 -2
  315. package/rules/ai-tell.yaml +8 -4
  316. package/rules/bold-label-list.yaml +6 -6
  317. package/rules/closing-cliche.yaml +2 -2
  318. package/rules/colon-lead-in.yaml +2 -2
  319. package/rules/contraction-consistency.yaml +4 -2
  320. package/rules/contrast-framing.yaml +3 -3
  321. package/rules/date-format-consistency.yaml +2 -2
  322. package/rules/duplicate-definition.yaml +2 -2
  323. package/rules/fullwidth-alnum-consistency.yaml +2 -2
  324. package/rules/honesty-marker.yaml +84 -0
  325. package/rules/latin-spacing.yaml +6 -4
  326. package/rules/max-paragraph-length.yaml +2 -2
  327. package/rules/max-sentence-length.yaml +4 -2
  328. package/rules/missing-final-period.yaml +2 -2
  329. package/rules/ngram-repetition.yaml +2 -2
  330. package/rules/no-doubled-joshi.yaml +2 -2
  331. package/rules/no-mixed-desumasu.yaml +2 -2
  332. package/rules/nominalization.yaml +1 -1
  333. package/rules/numbering-gap.yaml +2 -2
  334. package/rules/one-sentence-paragraph-run.yaml +2 -2
  335. package/rules/orthographic-variant.yaml +2 -2
  336. package/rules/oxford-comma-consistency.yaml +2 -2
  337. package/rules/quote-without-source.yaml +2 -2
  338. package/rules/request-without-deadline.yaml +2 -2
  339. package/rules/requirement-smell.yaml +2 -2
  340. package/rules/spelling-consistency.yaml +4 -4
  341. package/rules/teki-overuse.yaml +2 -2
  342. package/rules/topic-predicate-distance.yaml +2 -2
  343. package/rules/undefined-acronym.yaml +5 -2
  344. package/rules/undefined-term.yaml +2 -2
  345. package/rules/unfilled-placeholder.yaml +2 -2
  346. package/rules/unknown-word.yaml +2 -2
  347. package/rules/unqualified-superlative.yaml +1 -1
  348. package/skills/chaff/SKILL.md +2 -1
  349. package/src/ai-score/human-shares.ts +1 -0
  350. package/src/alternative-words.ts +15 -0
  351. package/src/closing-code.ts +21 -0
  352. package/src/composite-signals.ts +27 -0
  353. package/src/date-format.ts +54 -7
  354. package/src/detectors/acronym-context.ts +61 -2
  355. package/src/detectors/acronym-mention.ts +17 -0
  356. package/src/detectors/acronym-name.ts +18 -0
  357. package/src/detectors/acronym-series.ts +22 -3
  358. package/src/detectors/ai-phrasing.ts +7 -1
  359. package/src/detectors/ai-structure.ts +6 -2
  360. package/src/detectors/blank-runs.ts +30 -0
  361. package/src/detectors/bold-label.ts +22 -6
  362. package/src/detectors/capitalised-term.ts +36 -9
  363. package/src/detectors/citation-string.ts +57 -0
  364. package/src/detectors/contraction-emphasis.ts +46 -0
  365. package/src/detectors/contraction-mention.ts +52 -6
  366. package/src/detectors/contraction-mix.ts +104 -0
  367. package/src/detectors/contraction-set-apart.ts +52 -0
  368. package/src/detectors/date-format.ts +18 -2
  369. package/src/detectors/densest-stretch.ts +21 -0
  370. package/src/detectors/doubled-word.ts +10 -10
  371. package/src/detectors/duplicate-definition.ts +21 -0
  372. package/src/detectors/final-period-captions.ts +78 -0
  373. package/src/detectors/fullwidth-alnum.ts +19 -3
  374. package/src/detectors/gram-furniture.ts +27 -13
  375. package/src/detectors/gram-openers.ts +54 -1
  376. package/src/detectors/gram-repetition.ts +21 -7
  377. package/src/detectors/heading-sentences.ts +36 -0
  378. package/src/detectors/known-correction.ts +15 -8
  379. package/src/detectors/lexicon.ts +18 -62
  380. package/src/detectors/list-lead-in.ts +60 -11
  381. package/src/detectors/list-run.ts +16 -2
  382. package/src/detectors/missing-final-period.ts +9 -1
  383. package/src/detectors/numbering-readings.ts +10 -2
  384. package/src/detectors/open-end-anaphor.ts +31 -0
  385. package/src/detectors/open-end-lead.ts +46 -0
  386. package/src/detectors/open-end-scope.ts +8 -1
  387. package/src/detectors/ordinal-run-gaps.ts +1 -1
  388. package/src/detectors/orthographic-variant-open.ts +8 -3
  389. package/src/detectors/orthography.ts +20 -7
  390. package/src/detectors/oxford-comma.ts +17 -2
  391. package/src/detectors/phrase-match.ts +3 -2
  392. package/src/detectors/placeholder-text.ts +21 -4
  393. package/src/detectors/quote-without-source.ts +52 -10
  394. package/src/detectors/quoted-pattern.ts +14 -0
  395. package/src/detectors/reference-entry.ts +8 -1
  396. package/src/detectors/register-separate-part.ts +42 -0
  397. package/src/detectors/registry/contraction-mix.ts +1 -1
  398. package/src/detectors/registry/duplicate-definition.ts +1 -1
  399. package/src/detectors/relative-pronoun-mix.ts +5 -3
  400. package/src/detectors/reproduced-text.ts +33 -0
  401. package/src/detectors/request-owner.ts +31 -8
  402. package/src/detectors/requirement-smell.ts +21 -5
  403. package/src/detectors/sentence-counts.ts +27 -7
  404. package/src/detectors/sentence-ending.ts +6 -2
  405. package/src/detectors/sentence-length.ts +18 -3
  406. package/src/detectors/sentence-parts.ts +19 -1
  407. package/src/detectors/signals.ts +35 -7
  408. package/src/detectors/spelling-variety.ts +26 -2
  409. package/src/detectors/structure-tree.ts +2 -8
  410. package/src/detectors/structure.ts +22 -6
  411. package/src/detectors/superlative-context.ts +10 -2
  412. package/src/detectors/title-list.ts +21 -0
  413. package/src/detectors/token-shape.ts +35 -21
  414. package/src/detectors/undefined-term.ts +26 -1
  415. package/src/detectors/unfilled-placeholder.ts +20 -2
  416. package/src/detectors/unknown-word-context.ts +23 -0
  417. package/src/detectors/unknown-word.ts +23 -4
  418. package/src/latin-spacing-source.ts +33 -0
  419. package/src/name-separator.ts +4 -1
  420. package/src/paragraph-length.ts +31 -0
  421. package/src/paragraph-runs.ts +71 -13
  422. package/src/plugin.ts +2 -0
  423. package/src/quote-echo.ts +18 -0
  424. package/src/run.ts +4 -2
  425. package/src/semantic.ts +2 -3
  426. package/src/set-phrase-particles.ts +32 -0
  427. package/src/structure/alternative-clause.ts +32 -7
  428. package/src/structure/cited-document-section.ts +8 -0
  429. package/src/structure/issues.ts +19 -9
  430. package/src/structure/numbering.ts +50 -3
  431. package/src/structure/unread-label.ts +74 -0
  432. package/src/structure-shape/faq-sections.ts +24 -0
  433. package/src/structure-shape/features.ts +5 -3
  434. package/src/topic-clause.ts +16 -2
@@ -0,0 +1,104 @@
1
+ import { pairMinority, type PairUses } from "./contraction-minority.ts";
2
+ import { blankRanges, isTermList, withoutMentions } from "./contraction-mention.ts";
3
+ import { stressedWords } from "./contraction-emphasis.ts";
4
+ import { noticeSentences, talksAboutContractions, warningSentences } from "./contraction-set-apart.ts";
5
+ import { escapeRegExp, straightApostrophes } from "../orthography.ts";
6
+ import type { Detector, Finding, ProseDocument, Sentence, Span } from "../plugin.ts";
7
+
8
+ /**
9
+ * 同じことを言う 2 つの書きかたが、1 つの文書で混ざっているか。
10
+ *
11
+ * **どちらが正しいかは決めない。** 短縮形を使うかどうかは文体の選択で、
12
+ * 立場を取ると方針の違う書き手に rule ごと無視される。spec §12.3。
13
+ *
14
+ * 語彙表は対を持つ(`pattern` と `instead_of`)。比べるのは対の中だけで、別の語どうしは比べない。
15
+ * GOV.UK の文体は「you're」を使い否定は「do not」と書く。語ごとに決めた書きかたで、混在ではない。
16
+ * 否定と代名詞+動詞の族にもまとめない。「don't」と「does not」を書き分ける文書もある。
17
+ */
18
+
19
+ type Pair = { readonly short: string; readonly long: string };
20
+ type MixedPair = { readonly pair: Pair; readonly side: keyof PairUses; readonly minority: string; readonly majority: string; readonly count: number };
21
+
22
+ /**
23
+ * 語の境界で照合する。部分一致だと「it isn't」が「it is」を含んでしまい、
24
+ * 短縮形を使っている文が「使っていない」側に数えられる。
25
+ */
26
+ const wordUses = (text: string, word: string): number => [...text.matchAll(new RegExp(`\\b${escapeRegExp(word)}\\b`, "gu"))].length;
27
+
28
+ /**
29
+ * 書き手が選んだ形として数える文の字。引用で挙げた語句と語の一覧の中の形は、書き手の文体を語らないので空ける。
30
+ * アポストロフィの形(don’t と don't)は短縮形かどうかを変えない。折り返した行も、空白 1 つと同じに読む。
31
+ */
32
+ const comparableText = (text: string): string => {
33
+ const counted = withoutMentions(straightApostrophes(text));
34
+ return isTermList(counted) ? "" : counted.replace(/\s+/gu, " ").toLowerCase();
35
+ };
36
+
37
+ /**
38
+ * 指してよい字。一語だけ強調した形(does **not**)は強勢のために選んだ形なので指さない。
39
+ * 書き手がその形を書いたことには変わりないので、どちらが多いかを数えるときは数える。
40
+ */
41
+ const pointableText = (sentence: Sentence, stressed: readonly Span[]): string => comparableText(blankRanges(sentence.text, sentence.span.start, stressed));
42
+
43
+ /** 語のすぐ後ろが句読点か文の終わり。名前として挙げた語("Use cannot, instead of can't.")はそう並ぶ。 */
44
+ const bareUses = (text: string, word: string): number => [...text.matchAll(new RegExp(`\\b${escapeRegExp(word)}\\b(?=\\s*(?:\\p{P}|$))`, "gu"))].length;
45
+
46
+ /**
47
+ * 1 文の中の、対の 2 つの形の数。両方の形をそれぞれ単独で挙げた文("Use cannot, instead of can't.")は語を比べていて、
48
+ * どちらも使っていない。両方を文の中で使う文("It is important -- it's the most important")はそのまま数える。
49
+ */
50
+ const usesIn = (text: string, pair: Pair): PairUses => {
51
+ const named = bareUses(text, pair.short) > 0 && bareUses(text, pair.long) > 0;
52
+ return named ? { short: 0, long: 0 } : { short: wordUses(text, pair.short), long: wordUses(text, pair.long) };
53
+ };
54
+
55
+ const mixedPair = (texts: readonly string[], pair: Pair): MixedPair | undefined => {
56
+ const uses = texts.reduce<PairUses>(
57
+ (sum, text) => {
58
+ const here = usesIn(text, pair);
59
+ return { short: sum.short + here.short, long: sum.long + here.long };
60
+ },
61
+ { short: 0, long: 0 },
62
+ );
63
+ const side = pairMinority(uses);
64
+ if (side === undefined) return undefined;
65
+ return side === "short"
66
+ ? { pair, side, minority: pair.short, majority: pair.long, count: uses.short }
67
+ : { pair, side, minority: pair.long, majority: pair.short, count: uses.long };
68
+ };
69
+
70
+ const usesMinority = (text: string, mixed: MixedPair): boolean => usesIn(text, mixed.pair)[mixed.side] > 0;
71
+
72
+ const emphasisOf = (doc: ProseDocument): readonly Span[] => (doc.prose === undefined ? [] : stressedWords(doc.source, doc.prose));
73
+
74
+ export const contractionMix: Detector = (doc, options): Finding[] => {
75
+ const stressed = emphasisOf(doc);
76
+ const notices = noticeSentences(doc.paragraphs, doc.lexicons["notice-phrase"] ?? []);
77
+ const terms = doc.lexicons["contraction-term"] ?? [];
78
+ const warnings = warningSentences(
79
+ doc.paragraphs,
80
+ doc.source,
81
+ (doc.lexicons["warning-label"] ?? []).map((entry) => entry.pattern),
82
+ );
83
+ const isWriters = (sentence: Sentence): boolean => !notices.has(sentence) && !talksAboutContractions(sentence, terms);
84
+ // 文ごとに数える。文をつないで数えると、箇条書きの「What we do」と次の項目「not every…」が「do not」と数えられる。
85
+ const texts = doc.sentences.map((sentence) => (isWriters(sentence) ? comparableText(sentence.text) : ""));
86
+ const mixed = (options.lexicon ?? []).flatMap((entry) => {
87
+ const pair = entry.instead_of === undefined ? undefined : mixedPair(texts, { short: entry.pattern.toLowerCase(), long: entry.instead_of.toLowerCase() });
88
+ return pair === undefined || pair.count > options.limit ? [] : [pair];
89
+ });
90
+ const hits = doc.sentences.flatMap((sentence) => {
91
+ if (!isWriters(sentence) || warnings.has(sentence)) return [];
92
+ const pointable = pointableText(sentence, stressed);
93
+ const pair = mixed.find((candidate) => usesMinority(pointable, candidate));
94
+ return pair === undefined ? [] : [{ sentence, pair }];
95
+ });
96
+ return hits.map(({ sentence, pair }) => ({
97
+ rule: "contraction-consistency",
98
+ severity: "info",
99
+ line: 0,
100
+ column: 0,
101
+ quote: sentence.text.trim(),
102
+ values: { matched: pair.minority, majority: pair.majority, count: pair.count, limit: options.limit, offset: sentence.span.start },
103
+ }));
104
+ };
@@ -0,0 +1,52 @@
1
+ import { entryIn } from "./lexicon-match.ts";
2
+ import { warningTextStart } from "../warning-action.ts";
3
+ import type { LexiconEntry, Paragraph, Sentence } from "../plugin.ts";
4
+
5
+ // Sentences whose forms say nothing about the writer's choice of register. Pure: reads paragraphs, sentences and the source;
6
+ // the words come from the language's notice-phrase, contraction-term and warning-label lexicons.
7
+
8
+ /**
9
+ * The sentences of a paragraph of disclaimer wording (…does not constitute or imply its endorsement…). A publisher appends
10
+ * it to every page in its own fixed wording, so its forms are not the writer's: they are neither counted nor pointed at.
11
+ */
12
+ export const noticeSentences = (paragraphs: readonly Paragraph[], cues: readonly LexiconEntry[]): Set<Sentence> =>
13
+ new Set(paragraphs.flatMap((paragraph) => (paragraph.sentences.some((sentence) => cues.some((cue) => entryIn(sentence, cue))) ? paragraph.sentences : [])));
14
+
15
+ /** A sentence about contractions (Avoid negative contractions like can't and don't.) names its forms; it does not use them. */
16
+ export const talksAboutContractions = (sentence: Sentence, terms: readonly LexiconEntry[]): boolean => terms.some((term) => entryIn(sentence, term));
17
+
18
+ /** A Hugo shortcode ({{< warning >}}, {{< alert title="Warning" >}}) or a Docusaurus admonition (:::caution) opening a paragraph. */
19
+ const SHORTCODE_OPENERS = ["{{<", "{{%"];
20
+ const SHORTCODE_TITLE = /\btitle\s*=\s*["']([^"']+)["']/u;
21
+ const ADMONITION = /^:::\s*([\w-]+)/u;
22
+
23
+ /** The name and the attributes of the shortcode opening the text, or undefined when none does. */
24
+ const shortcodeAt = (text: string): { readonly name: string; readonly attributes: string } | undefined => {
25
+ const end = text.indexOf("}}");
26
+ if (!SHORTCODE_OPENERS.some((opener) => text.startsWith(opener)) || end < 0) return undefined;
27
+ const [name = "", ...attributes] = text
28
+ .slice(3, end - 1)
29
+ .trim()
30
+ .split(" ");
31
+ return { name, attributes: attributes.join(" ") };
32
+ };
33
+
34
+ const isLabel = (word: string | undefined, labels: readonly string[]): boolean =>
35
+ word !== undefined && labels.some((label) => label.toLowerCase() === word.trim().toLowerCase());
36
+
37
+ /** Whether a paragraph's text opens as a warning: a label (Warning:, > [!WARNING]), a shortcode or an admonition naming one. */
38
+ const opensWarning = (text: string, labels: readonly string[]): boolean => {
39
+ if (warningTextStart(text, labels) !== undefined) return true;
40
+ const shortcode = shortcodeAt(text);
41
+ if (shortcode !== undefined) return isLabel(shortcode.name, labels) || isLabel(SHORTCODE_TITLE.exec(shortcode.attributes)?.[1], labels);
42
+ return isLabel(ADMONITION.exec(text)?.[1], labels);
43
+ };
44
+
45
+ /**
46
+ * The sentences of a warning (Do not run this on an internet-facing cluster.). A warning spells the negative out for
47
+ * stress, as a writer bolds a word: counted, never pointed at.
48
+ */
49
+ export const warningSentences = (paragraphs: readonly Paragraph[], source: string, labels: readonly string[]): Set<Sentence> =>
50
+ new Set(
51
+ paragraphs.flatMap((paragraph) => (opensWarning(source.slice(paragraph.span.start, paragraph.span.end).trimStart(), labels) ? paragraph.sentences : [])),
52
+ );
@@ -1,10 +1,13 @@
1
- import type { Detector, Finding, ProseDocument } from "../plugin.ts";
1
+ import type { Detector, Finding, ProseDocument, Span } from "../plugin.ts";
2
2
  import { dateGroups, dateMinority, datesIn, type DateMinority } from "../date-format.ts";
3
3
  import { quoteAt } from "./structure-tree.ts";
4
+ import { referenceListSpans } from "../reference-lists.ts";
5
+ import { noteSentences } from "../note-paragraphs.ts";
4
6
 
5
7
  /**
6
8
  * 一つの文書で、日付を二通り以上の書き方で書いた所(2026-10-02 と 2026年10月2日、Oct 2, 2026 と 10/2/2026)。少ないほうを指す。
7
9
  * 行の頭の日付(予定表の行)と文の中の日付は別に比べる。月の名前は語彙表 month-name、元号は calendar-era が言う。コードの中の日付は読まない。
10
+ * 文献一覧(見出しは語彙表 reference-list-heading)と注の並びの中の日付は比べない。
8
11
  */
9
12
  const findingsOf = (doc: ProseDocument, minority: DateMinority): Finding[] =>
10
13
  minority.odd.map((date) => ({
@@ -16,6 +19,18 @@ const findingsOf = (doc: ProseDocument, minority: DateMinority): Finding[] =>
16
19
  values: { written: date.written, example: minority.majority.written, count: minority.count, total: minority.total, offset: date.offset },
17
20
  }));
18
21
 
22
+ /** 文献一覧と、番号の付いた注の並びの範囲。 */
23
+ const citedSpans = (doc: ProseDocument): Span[] => {
24
+ const notes = noteSentences(doc.source, doc.paragraphs);
25
+ return [
26
+ ...referenceListSpans(
27
+ doc.source,
28
+ (doc.lexicons["reference-list-heading"] ?? []).map((entry) => entry.pattern),
29
+ ),
30
+ ...doc.paragraphs.filter((paragraph) => paragraph.sentences.some((sentence) => notes.has(sentence))).map((paragraph) => paragraph.span),
31
+ ];
32
+ };
33
+
19
34
  export const dateFormat: Detector = (doc, options): Finding[] => {
20
35
  const words = {
21
36
  months: (doc.lexicons["month-name"] ?? []).map((entry) => entry.pattern),
@@ -23,7 +38,8 @@ export const dateFormat: Detector = (doc, options): Finding[] => {
23
38
  };
24
39
  const text = doc.prose ?? doc.source;
25
40
  const stampLabels = (doc.lexicons["date-stamp-label"] ?? []).map((entry) => entry.pattern);
26
- return dateGroups(text, datesIn(text, words), stampLabels).flatMap((group) => {
41
+ const places = { stampLabels, cited: citedSpans(doc), source: doc.source };
42
+ return dateGroups(text, datesIn(text, words), places).flatMap((group) => {
27
43
  const minority = dateMinority(group, options.limit);
28
44
  return minority === undefined ? [] : findingsOf(doc, minority);
29
45
  });
@@ -0,0 +1,21 @@
1
+ /** The keys of the densest stretch, and the index of its first item. */
2
+ export type Stretch<K> = { readonly keys: ReadonlySet<K>; readonly first: number };
3
+
4
+ const keysIn = <K>(hitsPerItem: readonly (readonly K[])[], start: number, window: number): Set<K> => new Set(hitsPerItem.slice(start, start + window).flat());
5
+
6
+ const scoreOf = <K>(keys: ReadonlySet<K>, weightOf: (key: K) => number): number => [...keys].reduce((sum, key) => sum + weightOf(key), 0);
7
+
8
+ /**
9
+ * The run of at most `window` consecutive items whose distinct keys weigh the most, starting at an item with a key.
10
+ * The earliest wins a tie. When every hit fits in one window, that is all of them, from the first hit.
11
+ */
12
+ export const densestStretch = <K>(hitsPerItem: readonly (readonly K[])[], window: number, weightOf: (key: K) => number): Stretch<K> | undefined =>
13
+ hitsPerItem.reduce<{ best: Stretch<K> | undefined; score: number }>(
14
+ (acc, hits, start) => {
15
+ if (hits.length === 0) return acc;
16
+ const keys = keysIn(hitsPerItem, start, window);
17
+ const score = scoreOf(keys, weightOf);
18
+ return acc.best !== undefined && score <= acc.score ? acc : { best: { keys, first: start }, score };
19
+ },
20
+ { best: undefined, score: -Infinity },
21
+ ).best;
@@ -1,4 +1,4 @@
1
- import type { Detector, Finding, Lexicon, Sentence, Token } from "../plugin.ts";
1
+ import type { Detector, Finding, Lexicon, Sentence, Span, Token } from "../plugin.ts";
2
2
  import { citedNamesOf, endsCitedName } from "./cited-name.ts";
3
3
  import { doubledAcrossAside } from "./doubled-across-aside.ts";
4
4
  import { furiganaSpans } from "../furigana.ts";
@@ -167,10 +167,8 @@ const DOCUMENT_KIND = "document-kind";
167
167
  const FIXED_PHRASE = "fixed-phrase";
168
168
 
169
169
  /** 語の読みの括弧(凛々(りり)しい)の中の重なり。読みは語の書き方ではなく、仮名を重ねて読む語もある。 */
170
- const inReading = (sentence: Sentence, doubled: Doubled): boolean =>
171
- furiganaSpans(sentence.text).some(
172
- (span) => sentence.span.start + span.start <= doubled.first.span.start && doubled.second.span.end <= sentence.span.start + span.end,
173
- );
170
+ const inReading = (sentence: Sentence, readings: readonly Span[], doubled: Doubled): boolean =>
171
+ readings.some((span) => sentence.span.start + span.start <= doubled.first.span.start && doubled.second.span.end <= sentence.span.start + span.end);
174
172
 
175
173
  export const doubledWord: Detector = (doc, options): Finding[] => {
176
174
  const spaced = doc.lengthUnit === "word";
@@ -178,9 +176,11 @@ export const doubledWord: Detector = (doc, options): Finding[] => {
178
176
  const cited = citedNamesOf(doc.structure);
179
177
  const kinds = new Set((doc.lexicons[DOCUMENT_KIND] ?? []).map((entry) => entry.pattern));
180
178
  const phrases = doc.lexicons[FIXED_PHRASE] ?? [];
181
- return doc.sentences.flatMap((sentence) =>
182
- [...doubledIn(doc.source, sentence.tokens ?? [], spaced, allowed, phrases), ...(spaced ? [] : doubledAcrossAside(doc.source, sentence.tokens ?? []))]
183
- .filter((doubled) => !endsCitedName(doubled.first, doubled.second, cited, kinds) && !inReading(sentence, doubled))
184
- .map((doubled) => findingOf(sentence, doubled, spaced)),
185
- );
179
+ return doc.sentences.flatMap((sentence) => {
180
+ // The readings are found once per sentence: once per doubled pair costs the pairs times the sentence's length.
181
+ const readings = furiganaSpans(sentence.text);
182
+ return [...doubledIn(doc.source, sentence.tokens ?? [], spaced, allowed, phrases), ...(spaced ? [] : doubledAcrossAside(doc.source, sentence.tokens ?? []))]
183
+ .filter((doubled) => !endsCitedName(doubled.first, doubled.second, cited, kinds) && !inReading(sentence, readings, doubled))
184
+ .map((doubled) => findingOf(sentence, doubled, spaced));
185
+ });
186
186
  };
@@ -0,0 +1,21 @@
1
+ import type { Detector, ProseDocument, StructureNode } from "../plugin.ts";
2
+ import { duplicateDefinitions } from "../structure/issues.ts";
3
+ import { attachedPartStarts } from "../structure/attached-parts.ts";
4
+ import { alternativeReader, choiceReader } from "../structure/alternative-clause.ts";
5
+ import { findingsOf } from "./structure-tree.ts";
6
+ import { patternsOf } from "./net-amount-mismatch.ts";
7
+
8
+ /** A clause to choose instead of another: named an alternative (alternative-clause-label) or one of numbered options (option-choice-label). */
9
+ const choicesOf = (doc: ProseDocument, source: string): ((node: StructureNode) => boolean) => {
10
+ const isAlternative = alternativeReader(source, patternsOf(doc, "alternative-clause-label"));
11
+ const isChoice = choiceReader(source, patternsOf(doc, "option-choice-label"));
12
+ return (node) => isAlternative(node) || isChoice(node);
13
+ };
14
+
15
+ export const duplicateDefinition: Detector = (doc, options) => {
16
+ const labels = patternsOf(doc, "attached-instrument-label");
17
+ return findingsOf("duplicate-definition", (tree, source) => duplicateDefinitions(tree, attachedPartStarts(source, labels), source, choicesOf(doc, source)))(
18
+ doc,
19
+ options,
20
+ );
21
+ };
@@ -0,0 +1,78 @@
1
+ // Paragraphs that stand in a repeated slot of the layout, where the document writes captions rather than sentences: a
2
+ // one-line summary right under each of several headings, the term line of a term-then-explanation run, and the lines of
3
+ // a run of one-line items. A slot is read as captions only when it repeats and none of its lines closes with the period,
4
+ // so a slot mixing both forms is still left to missing-final-period. Pure.
5
+ import type { Paragraph, Section } from "../plugin.ts";
6
+
7
+ /** How a paragraph looks to the slots: whether it is one line, and whether that line closes with the period. */
8
+ export type SlotParagraph = { readonly span: { readonly start: number; readonly end: number }; readonly oneLine: boolean; readonly closed: boolean };
9
+
10
+ /** A slot is a layout only when it repeats at least this often. */
11
+ const MIN_REPEATS = 3;
12
+
13
+ const isOpenLine = (paragraph: SlotParagraph | undefined): boolean => paragraph !== undefined && paragraph.oneLine && !paragraph.closed;
14
+
15
+ /** The indexes of a slot when it repeats and none of its paragraphs is closed. */
16
+ const captionsOf = (slot: readonly number[], paragraphs: readonly SlotParagraph[]): number[] =>
17
+ slot.length >= MIN_REPEATS && slot.every((index) => isOpenLine(paragraphs[index])) ? [...slot] : [];
18
+
19
+ /** The paragraph a section's body opens with, when nothing stands between the heading and it. */
20
+ const openingParagraph = (text: string, section: Section, paragraphs: readonly SlotParagraph[]): number | undefined => {
21
+ const index = paragraphs.findIndex((paragraph) => paragraph.span.start >= section.span.start && paragraph.span.start < section.span.end);
22
+ const paragraph = paragraphs[index];
23
+ return paragraph !== undefined && text.slice(section.span.start, paragraph.span.start).trim() === "" ? index : undefined;
24
+ };
25
+
26
+ /** Where a section sits: its depth, and the heading it stands under (the last section before it that is less deep). */
27
+ const siblingKey = (sections: readonly Section[], index: number): string => {
28
+ const depth = sections[index]?.depth ?? 0;
29
+ const parent = sections.slice(0, index).findLastIndex((section) => section.depth < depth);
30
+ return `${parent}:${depth}`;
31
+ };
32
+
33
+ /** The one-line paragraphs that open sibling sections: a summary under each heading (気づき / 家族の変化に気づいて、声をかける). */
34
+ const headingSlots = (text: string, sections: readonly Section[], paragraphs: readonly SlotParagraph[]): number[][] => {
35
+ const bySiblings = new Map<string, number[]>();
36
+ sections.forEach((section, sectionIndex) => {
37
+ const index = section.depth > 0 ? openingParagraph(text, section, paragraphs) : undefined;
38
+ if (index === undefined || paragraphs[index]?.oneLine !== true) return;
39
+ const key = siblingKey(sections, sectionIndex);
40
+ bySiblings.set(key, [...(bySiblings.get(key) ?? []), index]);
41
+ });
42
+ return [...bySiblings.values()];
43
+ };
44
+
45
+ /** Runs of an open one-line paragraph followed by a closed one: a term, then the sentence that explains it. */
46
+ const termSlots = (paragraphs: readonly SlotParagraph[]): number[][] =>
47
+ paragraphs.reduce<number[][]>((runs, paragraph, index) => {
48
+ if (!isOpenLine(paragraph) || paragraphs[index + 1]?.closed !== true) return runs;
49
+ const run = runs.at(-1);
50
+ if (run !== undefined && run.at(-1) === index - 2) run.push(index);
51
+ else runs.push([index]);
52
+ return runs;
53
+ }, []);
54
+
55
+ /** Runs of one-line paragraphs written on consecutive lines, with no blank line between: the items of a list or a table of contents. */
56
+ const lineSlots = (text: string, paragraphs: readonly SlotParagraph[]): number[][] =>
57
+ paragraphs.reduce<number[][]>((runs, paragraph, index) => {
58
+ if (!paragraph.oneLine) return runs;
59
+ const previous = paragraphs[index - 1];
60
+ const run = runs.at(-1);
61
+ const adjacent = previous !== undefined && previous.oneLine && !text.slice(previous.span.end, paragraph.span.start).includes("\n\n");
62
+ if (adjacent && run !== undefined && run.at(-1) === index - 1) run.push(index);
63
+ else runs.push([index]);
64
+ return runs;
65
+ }, []);
66
+
67
+ /** The indexes of the paragraphs that are captions in a repeated slot, not sentences left open. */
68
+ export const captionParagraphs = (text: string, sections: readonly Section[], paragraphs: readonly SlotParagraph[]): ReadonlySet<number> =>
69
+ new Set(
70
+ [...headingSlots(text, sections, paragraphs), ...termSlots(paragraphs), ...lineSlots(text, paragraphs)].flatMap((slot) => captionsOf(slot, paragraphs)),
71
+ );
72
+
73
+ /** The slot view of a document's paragraphs; closed says whether a paragraph's last line ends with the period. */
74
+ export const slotParagraphs = (text: string, paragraphs: readonly Paragraph[], closed: (line: string) => boolean): SlotParagraph[] =>
75
+ paragraphs.map((paragraph) => {
76
+ const body = text.slice(paragraph.span.start, paragraph.span.end).trim();
77
+ return { span: paragraph.span, oneLine: !body.includes("\n"), closed: closed(body.split("\n").at(-1)?.trim() ?? "") };
78
+ });
@@ -3,6 +3,7 @@ import { minorityWithin } from "../orthography.ts";
3
3
  import { QUOTATION_MARKS, isWithinAny, quotedSpans } from "../quoted-span.ts";
4
4
  import { isCitation } from "./kutoten-consistency.ts";
5
5
  import { ALNUM_RUN, FULLWIDTH, HALFWIDTH } from "./alnum-number.ts";
6
+ import { gluedNumberSpans } from "./sentence-parts.ts";
6
7
 
7
8
  const LETTER = /[A-Za-zA-Za-z]/u;
8
9
 
@@ -79,7 +80,14 @@ const continuesVersion = (text: string, start: number, run: string): boolean =>
79
80
 
80
81
  const isListItemNumber = (source: string, offset: number): boolean => LIST_ITEM_HEAD.test(source.slice(source.lastIndexOf("\n", offset - 1) + 1, offset));
81
82
 
82
- export type AlnumRun = { readonly kind: AlnumKind; readonly fullwidth: boolean; readonly written: string; readonly offset: number };
83
+ export type AlnumRun = {
84
+ readonly kind: AlnumKind;
85
+ readonly fullwidth: boolean;
86
+ readonly written: string;
87
+ readonly offset: number;
88
+ /** 表のセルを続けてしまった数字(8,457 と 95.7 の 8,45795.7)の中。幅は書き手のものだが、セルの切れ目が分からず桁の数は当てにならない。 */
89
+ readonly glued: boolean;
90
+ };
83
91
 
84
92
  /**
85
93
  * 文の中の英字・数字の並び。全角と半角が混ざった並び、鉤括弧で引いたものの中、項目と注の番号、箇条書きの頭の番号、版の番号の続き(TLS1.2 の 2)は数えない。
@@ -87,6 +95,7 @@ export type AlnumRun = { readonly kind: AlnumKind; readonly fullwidth: boolean;
87
95
  */
88
96
  export const alnumRunsIn = (sentence: Sentence, source: string): AlnumRun[] => {
89
97
  const quoted: readonly Span[] = quotedSpans(sentence.text, QUOTATION_MARKS);
98
+ const glued = gluedNumberSpans(sentence.text);
90
99
  return [...sentence.text.matchAll(ALNUM_RUN)]
91
100
  .filter((match) => FULLWIDTH.test(match[0]) || HALFWIDTH.test(match[0]))
92
101
  .filter((match) => !isWithinAny(quoted, { start: match.index, end: match.index + match[0].length }))
@@ -96,7 +105,13 @@ export const alnumRunsIn = (sentence: Sentence, source: string): AlnumRun[] => {
96
105
  .filter((match) => !isInApostropheWord(sentence.text, match.index, match.index + match[0].length))
97
106
  .filter((match) => !isNumberLabel(sentence.text, match.index + match[0].length, match[0]))
98
107
  .filter((match) => !continuesVersion(sentence.text, match.index, match[0]))
99
- .map((match) => ({ kind: kindOf(match[0]), fullwidth: FULLWIDTH.test(match[0]), written: match[0], offset: sentence.span.start + match.index }));
108
+ .map((match) => ({
109
+ kind: kindOf(match[0]),
110
+ fullwidth: FULLWIDTH.test(match[0]),
111
+ written: match[0],
112
+ offset: sentence.span.start + match.index,
113
+ glued: isWithinAny(glued, { start: match.index, end: match.index + match[0].length }),
114
+ }));
100
115
  };
101
116
 
102
117
  const KINDS: readonly AlnumKind[] = ["letter", "letters", "digit", "digits"];
@@ -157,6 +172,7 @@ const findingOf = ({ sentence, run }: Located, count: number, of: number, limit:
157
172
  /**
158
173
  * 英字・数字を全角で書くか半角で書くか。組(英字一字・英字の語・数字一字・数字の並び)ごとに、文書の中で少ないほうを指摘する。
159
174
  * 少ないほうが組の limit パーセントを超えるほど多いなら、文書が使い分けている(数え方の語や見出しの書き方)と見て言わない。
175
+ * 表のセルを続けてしまった数字の中の並びは、書き方の票には入れるが、少ないほうとしては指摘しない(8,45795.7 の 8 は一桁の数ではない)。
160
176
  * どちらが正しいかは決めない。
161
177
  */
162
178
  export const fullwidthAlnum: Detector = (doc, options): Finding[] => {
@@ -169,7 +185,7 @@ export const fullwidthAlnum: Detector = (doc, options): Finding[] => {
169
185
  const ofKind = located.filter(({ run }) => run.kind === kind);
170
186
  const odd = minorityWithin(ofKind, ({ run }) => run.fullwidth, options.limit);
171
187
  return odd
172
- .filter(({ run }) => !isHalfwidthEnglishWord(run))
188
+ .filter(({ run }) => !isHalfwidthEnglishWord(run) && !run.glued)
173
189
  .filter(departsFromHabit(ofKind, odd))
174
190
  .map((entry) => findingOf(entry, odd.length, ofKind.length, options.limit));
175
191
  });
@@ -59,22 +59,36 @@ const QUOTE_CLOSING_MAX = 12;
59
59
  */
60
60
  const QUOTE_CLOSING = new RegExp(String.raw`[」』]([をがにでへ][^「」『』、,。.をがにでへ]{1,${String(QUOTE_CLOSING_MAX - 1)}}[。.]?)\s*$`, "u");
61
61
 
62
- const closingAfterQuote = (text: string): Span | undefined => {
63
- const match = QUOTE_CLOSING.exec(text);
64
- return match === null ? undefined : { start: match.index + 1, end: match.index + match[0].length };
62
+ /** リンクの文字のすぐ後ろの結び([ノンス](…)を参照してください。)。題を受ける助詞と述語だけなのは引いた題の後ろと同じ。 */
63
+ const LINK_CLOSING = new RegExp(String.raw`[をがにでへ][^「」『』、,。.をがにでへ]{1,${String(QUOTE_CLOSING_MAX - 1)}}[。.]?\s*$`, "u");
64
+
65
+ /** 文の中の位置がリンクの文字か。リンクの無い文は、どの位置もリンクではない。 */
66
+ export type Linked = (index: number) => boolean;
67
+
68
+ const NOT_LINKED: Linked = () => false;
69
+
70
+ /** 引いた題か、リンクの文字の直後で結ぶ範囲。手引きや参照のページは、別のページを指すたびに同じ結びで指す。 */
71
+ const closingAfterReference = (text: string, linked: Linked): Span | undefined => {
72
+ const quoted = QUOTE_CLOSING.exec(text);
73
+ if (quoted !== null) return { start: quoted.index + 1, end: quoted.index + quoted[0].length };
74
+ const afterLink = LINK_CLOSING.exec(text);
75
+ return afterLink !== null && afterLink.index > 0 && linked(afterLink.index - 1)
76
+ ? { start: afterLink.index, end: afterLink.index + afterLink[0].length }
77
+ : undefined;
65
78
  };
66
79
 
67
- const closingTextOf = (text: string): string | undefined => {
68
- const span = closingAfterQuote(text);
80
+ const closingTextOf = (text: string, linked: Linked): string | undefined => {
81
+ const span = closingAfterReference(text, linked);
69
82
  return span === undefined ? undefined : text.slice(span.start, span.end).trimEnd();
70
83
  };
71
84
 
72
85
  /**
73
- * 文書が参照の書式として使う結び: 引いた題の直後で結ぶことが、その結びで終わる文の過半である結び(詳しくは「…」を確認してください。)。
74
- * 引いた名前の後ろにたまたま来た書き手の結び(「生涯活躍のまち」を推進している。のほかは整備を推進している。)は、ほとんどが題の後ろではない。
86
+ * 文書が参照の書式として使う結び: 引いた題かリンクの直後で結ぶことが、その結びで終わる文の過半である結び(詳しくは「…」を確認してください。
87
+ * 詳しくは[…](…)を参照してください。)。引いた名前の後ろにたまたま来た書き手の結び(「生涯活躍のまち」を推進している。のほかは整備を
88
+ * 推進している。)は、ほとんどが題の後ろではない。linked は texts と同じ順の、文ごとのリンクの位置。
75
89
  */
76
- export const referenceClosings = (texts: readonly string[]): ReadonlySet<string> => {
77
- const afterQuote = texts.flatMap((text) => closingTextOf(text) ?? []);
90
+ export const referenceClosings = (texts: readonly string[], linked: readonly Linked[] = []): ReadonlySet<string> => {
91
+ const afterQuote = texts.flatMap((text, index) => closingTextOf(text, linked[index] ?? NOT_LINKED) ?? []);
78
92
  return new Set(
79
93
  [...new Set(afterQuote)].filter((closing) => {
80
94
  const quoted = afterQuote.filter((each) => each === closing).length;
@@ -85,12 +99,12 @@ export const referenceClosings = (texts: readonly string[]): ReadonlySet<string>
85
99
  };
86
100
 
87
101
  /**
88
- * 引いた題で終わる文の結び(詳しくは「入力可能な文字」を確認してください。)の範囲。手引きは別のページを指すたびに同じ結びで指す。
102
+ * 引いた題かリンクで終わる文の結び(詳しくは「入力可能な文字」を確認してください。)の範囲。
89
103
  * closings(referenceClosings)にある結びだけを、参照の書式として数えない。
90
104
  */
91
- export const quotedClosingSpans = (text: string, closings: ReadonlySet<string>): Span[] => {
92
- const span = closingAfterQuote(text);
93
- const closing = closingTextOf(text);
105
+ export const quotedClosingSpans = (text: string, closings: ReadonlySet<string>, linked: Linked = NOT_LINKED): Span[] => {
106
+ const span = closingAfterReference(text, linked);
107
+ const closing = closingTextOf(text, linked);
94
108
  return span !== undefined && closing !== undefined && closings.has(closing) ? [span] : [];
95
109
  };
96
110
 
@@ -55,8 +55,13 @@ const IDENTIFIER_HEADING = /^(?:`[^`]+`|【[\w.:/-]+】|\[[\w.:/-]+\])$/u;
55
55
  const DEFINITION_LINE = /(?:^|\n)[ \t]*(?:[-*+][ \t]+)?:[ \t]*$/u;
56
56
  const DEFINITION_REACH = 12;
57
57
 
58
+ /** 平文の仕様書の定義の並び(「 qu: The OPTIONAL "qu" parameter …」)。行の頭の短い名前とコロンのあとに空白が 2 つ以上続く。 */
59
+ const PLAIN_DEFINITION = /^\s*[\p{L}\p{N}_.-]{1,24}:[ \t]{2,}\S/u;
60
+
58
61
  const opensDefinition = (sentence: Sentence, source: string): boolean =>
59
- /^\s*:\s/u.test(sentence.text) || DEFINITION_LINE.test(source.slice(Math.max(0, sentence.span.start - DEFINITION_REACH), sentence.span.start));
62
+ /^\s*:\s/u.test(sentence.text) ||
63
+ PLAIN_DEFINITION.test(sentence.text) ||
64
+ DEFINITION_LINE.test(source.slice(Math.max(0, sentence.span.start - DEFINITION_REACH), sentence.span.start));
60
65
 
61
66
  const BLANK_LINE = /\n[ \t]*\n/u;
62
67
 
@@ -119,3 +124,51 @@ export const rowEndCells = (sentences: readonly Sentence[], fragments: ReadonlyS
119
124
  sentences.slice(index - CELLS_BEFORE, index).every((cell) => fragments.has(cell)) &&
120
125
  LINE_END_NEXT.test(source.slice(sentence.span.end, sentence.span.end + LOOKAHEAD)),
121
126
  );
127
+
128
+ const LABEL_END = /[::]\s*$/u;
129
+ const LINE_START_BEFORE = /(?:^|\n)[ \t]*$/u;
130
+
131
+ /**
132
+ * 一行を占め、コロンで終わり、文書の中にまったく同じ形で 2 度以上出る文(The following rule has the force of law:)。後ろの枠や
133
+ * 一覧に付ける札で、項目ごとに同じ札を付けるのは書式。言い回しを変えた導入(When you join a meeting, follow these guidelines:)は札ではない。
134
+ */
135
+ export const labelLines = (sentences: readonly Sentence[], source: string): Sentence[] => {
136
+ const lines = sentences.filter(
137
+ (sentence) =>
138
+ LABEL_END.test(sentence.text) &&
139
+ LINE_START_BEFORE.test(source.slice(Math.max(0, sentence.span.start - LINE_START_REACH), sentence.span.start)) &&
140
+ LINE_END_NEXT.test(source.slice(sentence.span.end, sentence.span.end + LOOKAHEAD)),
141
+ );
142
+ const counts = new Map<string, number>();
143
+ lines.forEach((line) => counts.set(line.text.trim(), (counts.get(line.text.trim()) ?? 0) + 1));
144
+ return lines.filter((line) => (counts.get(line.text.trim()) ?? 0) > 1);
145
+ };
146
+
147
+ /** 数字を伏せた形。数字だけが違う文は、同じ書式に数を入れたもの。 */
148
+ const DIGITS = /[\d0-9]+/gu;
149
+ const HAS_DIGIT = /[\d0-9]/u;
150
+
151
+ /** 文の中の行(変換が報告の欄を一つの文につないでも、欄は行ごとに分かれている)。 */
152
+ const linesOf = (sentence: Sentence): string[] =>
153
+ sentence.text
154
+ .split("\n")
155
+ .map((line) => line.trim())
156
+ .filter((line) => HAS_DIGIT.test(line));
157
+
158
+ /** 文が行を独り占めしているか(行の頭か箇条書きの印の後ろから始まり、行の終わりで終わる)。段落の中の文は欄ではない。 */
159
+ const ownsLines = (sentence: Sentence, source: string): boolean =>
160
+ LINE_START.test(source.slice(Math.max(0, sentence.span.start - LINE_START_REACH), sentence.span.start)) &&
161
+ LINE_END_NEXT.test(source.slice(sentence.span.end, sentence.span.end + LOOKAHEAD));
162
+
163
+ /**
164
+ * 行を独り占めし、数字だけが違う行が 2 度以上あって入った数が違うもの(There are currently 17 committers and 17 PMC members in this
165
+ * project.)。報告の書式を機械が埋めた欄で、書き手の言い回しではない。まったく同じ文の繰り返し(同じ説明を項目ごとに写したもの)と、
166
+ * 段落の中で数だけ替えて言い直す文(In case 3, we will look into it again.)は書式ではない。
167
+ */
168
+ export const filledForms = (sentences: readonly Sentence[], source: string): Sentence[] => {
169
+ const formOf = (line: string): string => line.replace(DIGITS, "0");
170
+ const fillings = new Map<string, Set<string>>();
171
+ const owning = sentences.filter((sentence) => ownsLines(sentence, source));
172
+ owning.flatMap(linesOf).forEach((line) => fillings.set(formOf(line), (fillings.get(formOf(line)) ?? new Set()).add(line)));
173
+ return owning.filter((sentence) => linesOf(sentence).some((line) => (fillings.get(formOf(line))?.size ?? 0) > 1));
174
+ };
@@ -14,7 +14,7 @@ import {
14
14
  } from "./gram-furniture.ts";
15
15
  import { hasPredicateIn } from "./gram-predicate.ts";
16
16
  import { gramPassagesOf } from "./gram-passages.ts";
17
- import { entryOpeners, nounFragments, rowEndCells, sectionOpeners } from "./gram-openers.ts";
17
+ import { entryOpeners, filledForms, labelLines, nounFragments, rowEndCells, sectionOpeners } from "./gram-openers.ts";
18
18
  import { nameSpans, touchesAny } from "../team-names.ts";
19
19
  import type { Detector, Finding, LengthUnit, ProseDocument, Sentence, Span, StructureNode } from "../plugin.ts";
20
20
 
@@ -82,8 +82,9 @@ type Context = {
82
82
  const excludedIn = (context: Context, sentence: Sentence, text: string, source: ReturnType<typeof compacted>): { named: Span[]; mask: boolean[] } => {
83
83
  const unit = context.doc.lengthUnit;
84
84
  const named = [...nameSpans(text, context.names), ...fieldLabelSpans(text, unit), ...partReferenceSpans(text, unit)];
85
- const mask = furnitureMask(text, linkedIn(context.doc, sentence, source));
86
- [...fixedEndingSpans(text, context.endings), ...quotedSpans(text), ...quotedClosingSpans(text, context.closings)].forEach((span) =>
85
+ const linked = linkedIn(context.doc, sentence, source);
86
+ const mask = furnitureMask(text, linked);
87
+ [...fixedEndingSpans(text, context.endings), ...quotedSpans(text), ...quotedClosingSpans(text, context.closings, linked)].forEach((span) =>
87
88
  mask.fill(true, span.start, span.end),
88
89
  );
89
90
  return { named, mask };
@@ -127,14 +128,23 @@ const gramsOf = (context: Context, sentences: readonly Sentence[]): Tally => {
127
128
  */
128
129
  const templatesOf = (doc: ProseDocument): ReadonlySet<Sentence> => {
129
130
  const fragments = new Set(nounFragments(doc.sentences, doc.source));
130
- return new Set([...entryOpeners(doc.sections, doc.source), ...fragments, ...rowEndCells(doc.sentences, fragments, doc.source)]);
131
+ return new Set([
132
+ ...entryOpeners(doc.sections, doc.source),
133
+ ...fragments,
134
+ ...rowEndCells(doc.sentences, fragments, doc.source),
135
+ ...labelLines(doc.sentences, doc.source),
136
+ ...filledForms(doc.sentences, doc.source),
137
+ ]);
131
138
  };
132
139
 
133
- /** 文書の題(一番上の見出し)。題にある言い回しは文書の主題で、繰り返して当たり前(CCライセンスを付与する際の…)。 */
140
+ /**
141
+ * 文書の題と見出し。題や見出しにある言い回しは文書の主題で、繰り返して当たり前(CCライセンスを付与する際の…、題を小見出しに置いた
142
+ * Guidance on Lending to Individuals Not Legally Authorized to Work、節の名前の 高度専門職業人養成に特化した新たな大学院制度)。
143
+ */
134
144
  const titleOf = (doc: ProseDocument): string =>
135
145
  keyOf(
136
146
  doc.sections
137
- .filter((section) => section.depth === 1)
147
+ .filter((section) => section.depth >= 1)
138
148
  .map((section) => compacted(section.heading, doc.lengthUnit).text)
139
149
  .join("\n"),
140
150
  doc.lengthUnit,
@@ -147,7 +157,11 @@ type Repeat = { readonly key: string; readonly occurrences: readonly Occurrence[
147
157
  * 節の書き出しは書き手の地の文でもあるので、ほかの所にも出れば書き出しのぶんも数える(節ごとの口癖)。
148
158
  */
149
159
  const repeatsOf = (doc: ProseDocument, limit: number): Repeat[] => {
150
- const closings = referenceClosings(doc.sentences.map((sentence) => compacted(sentence.text, doc.lengthUnit).text));
160
+ const sources = doc.sentences.map((sentence) => compacted(sentence.text, doc.lengthUnit));
161
+ const closings = referenceClosings(
162
+ sources.map((source) => source.text),
163
+ doc.sentences.map((sentence, index) => linkedIn(doc, sentence, sources[index] ?? compacted(sentence.text, doc.lengthUnit))),
164
+ );
151
165
  const context = { doc, names: namesOf(doc), endings: fixedEndingsOf(doc), closings };
152
166
  const templates = templatesOf(doc);
153
167
  const openers = sectionOpeners(doc.sections, doc.source);