chaffjs 0.38.0 → 0.39.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 (675) hide show
  1. package/README.ja.md +20 -4
  2. package/README.md +19 -2
  3. package/checks/ai-tells.yaml +153 -0
  4. package/dist/acronym-expansion.d.ts +4 -0
  5. package/dist/acronym-expansion.d.ts.map +1 -0
  6. package/dist/acronym-expansion.js +46 -0
  7. package/dist/acronym-expansion.js.map +1 -0
  8. package/dist/ai-score/human-shares.d.ts.map +1 -1
  9. package/dist/ai-score/human-shares.js +53 -12
  10. package/dist/ai-score/human-shares.js.map +1 -1
  11. package/dist/ai-score/of-document.d.ts.map +1 -1
  12. package/dist/ai-score/of-document.js +4 -2
  13. package/dist/ai-score/of-document.js.map +1 -1
  14. package/dist/body-section.d.ts +3 -1
  15. package/dist/body-section.d.ts.map +1 -1
  16. package/dist/body-section.js +9 -2
  17. package/dist/body-section.js.map +1 -1
  18. package/dist/capitals-with-small.d.ts +5 -0
  19. package/dist/capitals-with-small.d.ts.map +1 -1
  20. package/dist/capitals-with-small.js +15 -0
  21. package/dist/capitals-with-small.js.map +1 -1
  22. package/dist/checks.d.ts +11 -0
  23. package/dist/checks.d.ts.map +1 -1
  24. package/dist/checks.js +27 -1
  25. package/dist/checks.js.map +1 -1
  26. package/dist/cli-args.js +1 -1
  27. package/dist/cli-args.js.map +1 -1
  28. package/dist/cli-text.d.ts.map +1 -1
  29. package/dist/cli-text.js +4 -0
  30. package/dist/cli-text.js.map +1 -1
  31. package/dist/commands/fix-plan.d.ts.map +1 -1
  32. package/dist/commands/fix-plan.js +64 -4
  33. package/dist/commands/fix-plan.js.map +1 -1
  34. package/dist/commands/test.d.ts.map +1 -1
  35. package/dist/commands/test.js +16 -2
  36. package/dist/commands/test.js.map +1 -1
  37. package/dist/detectors/acronym-context.d.ts +4 -1
  38. package/dist/detectors/acronym-context.d.ts.map +1 -1
  39. package/dist/detectors/acronym-context.js +16 -2
  40. package/dist/detectors/acronym-context.js.map +1 -1
  41. package/dist/detectors/acronym-expansion.d.ts.map +1 -1
  42. package/dist/detectors/acronym-expansion.js +25 -0
  43. package/dist/detectors/acronym-expansion.js.map +1 -1
  44. package/dist/detectors/acronym-gloss.d.ts +19 -0
  45. package/dist/detectors/acronym-gloss.d.ts.map +1 -1
  46. package/dist/detectors/acronym-gloss.js +115 -0
  47. package/dist/detectors/acronym-gloss.js.map +1 -1
  48. package/dist/detectors/acronym-name.d.ts +9 -2
  49. package/dist/detectors/acronym-name.d.ts.map +1 -1
  50. package/dist/detectors/acronym-name.js +13 -3
  51. package/dist/detectors/acronym-name.js.map +1 -1
  52. package/dist/detectors/acronym-series.d.ts +7 -0
  53. package/dist/detectors/acronym-series.d.ts.map +1 -0
  54. package/dist/detectors/acronym-series.js +25 -0
  55. package/dist/detectors/acronym-series.js.map +1 -0
  56. package/dist/detectors/ai-phrasing.d.ts +3 -6
  57. package/dist/detectors/ai-phrasing.d.ts.map +1 -1
  58. package/dist/detectors/ai-phrasing.js +17 -16
  59. package/dist/detectors/ai-phrasing.js.map +1 -1
  60. package/dist/detectors/ai-structure.d.ts +1 -0
  61. package/dist/detectors/ai-structure.d.ts.map +1 -1
  62. package/dist/detectors/ai-structure.js +15 -4
  63. package/dist/detectors/ai-structure.js.map +1 -1
  64. package/dist/detectors/alnum-number.d.ts +1 -0
  65. package/dist/detectors/alnum-number.d.ts.map +1 -1
  66. package/dist/detectors/alnum-number.js +7 -3
  67. package/dist/detectors/alnum-number.js.map +1 -1
  68. package/dist/detectors/bare-comparative.d.ts +6 -0
  69. package/dist/detectors/bare-comparative.d.ts.map +1 -1
  70. package/dist/detectors/bare-comparative.js +31 -12
  71. package/dist/detectors/bare-comparative.js.map +1 -1
  72. package/dist/detectors/bold-emphasis-form.d.ts +8 -0
  73. package/dist/detectors/bold-emphasis-form.d.ts.map +1 -0
  74. package/dist/detectors/bold-emphasis-form.js +40 -0
  75. package/dist/detectors/bold-emphasis-form.js.map +1 -0
  76. package/dist/detectors/bold-emphasis.d.ts +0 -1
  77. package/dist/detectors/bold-emphasis.d.ts.map +1 -1
  78. package/dist/detectors/bold-emphasis.js +14 -12
  79. package/dist/detectors/bold-emphasis.js.map +1 -1
  80. package/dist/detectors/caps-caption.d.ts +5 -0
  81. package/dist/detectors/caps-caption.d.ts.map +1 -1
  82. package/dist/detectors/caps-caption.js +20 -2
  83. package/dist/detectors/caps-caption.js.map +1 -1
  84. package/dist/detectors/char-shape.d.ts.map +1 -1
  85. package/dist/detectors/char-shape.js +86 -27
  86. package/dist/detectors/char-shape.js.map +1 -1
  87. package/dist/detectors/chat-log-line.d.ts +8 -0
  88. package/dist/detectors/chat-log-line.d.ts.map +1 -0
  89. package/dist/detectors/chat-log-line.js +13 -0
  90. package/dist/detectors/chat-log-line.js.map +1 -0
  91. package/dist/detectors/citation-string.d.ts +3 -0
  92. package/dist/detectors/citation-string.d.ts.map +1 -0
  93. package/dist/detectors/citation-string.js +34 -0
  94. package/dist/detectors/citation-string.js.map +1 -0
  95. package/dist/detectors/closing-cliche.d.ts +18 -0
  96. package/dist/detectors/closing-cliche.d.ts.map +1 -0
  97. package/dist/detectors/closing-cliche.js +58 -0
  98. package/dist/detectors/closing-cliche.js.map +1 -0
  99. package/dist/detectors/closing-exhortation.d.ts +18 -0
  100. package/dist/detectors/closing-exhortation.d.ts.map +1 -0
  101. package/dist/detectors/closing-exhortation.js +55 -0
  102. package/dist/detectors/closing-exhortation.js.map +1 -0
  103. package/dist/detectors/cold-open.d.ts +25 -0
  104. package/dist/detectors/cold-open.d.ts.map +1 -0
  105. package/dist/detectors/cold-open.js +121 -0
  106. package/dist/detectors/cold-open.js.map +1 -0
  107. package/dist/detectors/comparative-context.d.ts +21 -0
  108. package/dist/detectors/comparative-context.d.ts.map +1 -0
  109. package/dist/detectors/comparative-context.js +57 -0
  110. package/dist/detectors/comparative-context.js.map +1 -0
  111. package/dist/detectors/concrete-evidence-density.d.ts +3 -0
  112. package/dist/detectors/concrete-evidence-density.d.ts.map +1 -0
  113. package/dist/detectors/concrete-evidence-density.js +75 -0
  114. package/dist/detectors/concrete-evidence-density.js.map +1 -0
  115. package/dist/detectors/concrete-evidence.d.ts +14 -0
  116. package/dist/detectors/concrete-evidence.d.ts.map +1 -1
  117. package/dist/detectors/concrete-evidence.js +24 -0
  118. package/dist/detectors/concrete-evidence.js.map +1 -1
  119. package/dist/detectors/contrast-frame.d.ts +5 -0
  120. package/dist/detectors/contrast-frame.d.ts.map +1 -1
  121. package/dist/detectors/contrast-frame.js +53 -6
  122. package/dist/detectors/contrast-frame.js.map +1 -1
  123. package/dist/detectors/coordinate-adjective.d.ts +2 -1
  124. package/dist/detectors/coordinate-adjective.d.ts.map +1 -1
  125. package/dist/detectors/coordinate-adjective.js +4 -2
  126. package/dist/detectors/coordinate-adjective.js.map +1 -1
  127. package/dist/detectors/duplicate-heading.d.ts +4 -2
  128. package/dist/detectors/duplicate-heading.d.ts.map +1 -1
  129. package/dist/detectors/duplicate-heading.js +35 -11
  130. package/dist/detectors/duplicate-heading.js.map +1 -1
  131. package/dist/detectors/email-frame-words.d.ts +10 -0
  132. package/dist/detectors/email-frame-words.d.ts.map +1 -0
  133. package/dist/detectors/email-frame-words.js +34 -0
  134. package/dist/detectors/email-frame-words.js.map +1 -0
  135. package/dist/detectors/email-letter.d.ts +3 -7
  136. package/dist/detectors/email-letter.d.ts.map +1 -1
  137. package/dist/detectors/email-letter.js +13 -21
  138. package/dist/detectors/email-letter.js.map +1 -1
  139. package/dist/detectors/fullwidth-alnum.d.ts.map +1 -1
  140. package/dist/detectors/fullwidth-alnum.js +20 -4
  141. package/dist/detectors/fullwidth-alnum.js.map +1 -1
  142. package/dist/detectors/gram-furniture.d.ts +18 -1
  143. package/dist/detectors/gram-furniture.d.ts.map +1 -1
  144. package/dist/detectors/gram-furniture.js +71 -0
  145. package/dist/detectors/gram-furniture.js.map +1 -1
  146. package/dist/detectors/gram-openers.d.ts +16 -0
  147. package/dist/detectors/gram-openers.d.ts.map +1 -1
  148. package/dist/detectors/gram-openers.js +52 -0
  149. package/dist/detectors/gram-openers.js.map +1 -1
  150. package/dist/detectors/gram-predicate.d.ts.map +1 -1
  151. package/dist/detectors/gram-predicate.js +40 -7
  152. package/dist/detectors/gram-predicate.js.map +1 -1
  153. package/dist/detectors/gram-repetition.d.ts +3 -0
  154. package/dist/detectors/gram-repetition.d.ts.map +1 -0
  155. package/dist/detectors/gram-repetition.js +158 -0
  156. package/dist/detectors/gram-repetition.js.map +1 -0
  157. package/dist/detectors/heading-level-skip.d.ts +6 -0
  158. package/dist/detectors/heading-level-skip.d.ts.map +1 -1
  159. package/dist/detectors/heading-level-skip.js +24 -1
  160. package/dist/detectors/heading-level-skip.js.map +1 -1
  161. package/dist/detectors/heading-numbering.js +2 -2
  162. package/dist/detectors/heading-numbering.js.map +1 -1
  163. package/dist/detectors/hyphen-copied-text.d.ts +3 -0
  164. package/dist/detectors/hyphen-copied-text.d.ts.map +1 -0
  165. package/dist/detectors/hyphen-copied-text.js +49 -0
  166. package/dist/detectors/hyphen-copied-text.js.map +1 -0
  167. package/dist/detectors/kanji-name-edge.d.ts +15 -0
  168. package/dist/detectors/kanji-name-edge.d.ts.map +1 -1
  169. package/dist/detectors/kanji-name-edge.js +30 -0
  170. package/dist/detectors/kanji-name-edge.js.map +1 -1
  171. package/dist/detectors/kanji-run-pieces.d.ts +7 -0
  172. package/dist/detectors/kanji-run-pieces.d.ts.map +1 -1
  173. package/dist/detectors/kanji-run-pieces.js +14 -4
  174. package/dist/detectors/kanji-run-pieces.js.map +1 -1
  175. package/dist/detectors/kutoten-consistency.d.ts.map +1 -1
  176. package/dist/detectors/kutoten-consistency.js +22 -4
  177. package/dist/detectors/kutoten-consistency.js.map +1 -1
  178. package/dist/detectors/lead-in-dash.d.ts +5 -0
  179. package/dist/detectors/lead-in-dash.d.ts.map +1 -1
  180. package/dist/detectors/lead-in-dash.js +9 -0
  181. package/dist/detectors/lead-in-dash.js.map +1 -1
  182. package/dist/detectors/letter-joined-name.d.ts +2 -0
  183. package/dist/detectors/letter-joined-name.d.ts.map +1 -1
  184. package/dist/detectors/letter-joined-name.js +8 -0
  185. package/dist/detectors/letter-joined-name.js.map +1 -1
  186. package/dist/detectors/lexicon.d.ts.map +1 -1
  187. package/dist/detectors/lexicon.js +11 -2
  188. package/dist/detectors/lexicon.js.map +1 -1
  189. package/dist/detectors/list-item.d.ts +14 -0
  190. package/dist/detectors/list-item.d.ts.map +1 -1
  191. package/dist/detectors/list-item.js +30 -1
  192. package/dist/detectors/list-item.js.map +1 -1
  193. package/dist/detectors/list-items.d.ts +1 -1
  194. package/dist/detectors/list-items.d.ts.map +1 -1
  195. package/dist/detectors/list-items.js +2 -0
  196. package/dist/detectors/list-items.js.map +1 -1
  197. package/dist/detectors/list-joint.d.ts +18 -0
  198. package/dist/detectors/list-joint.d.ts.map +1 -0
  199. package/dist/detectors/list-joint.js +42 -0
  200. package/dist/detectors/list-joint.js.map +1 -0
  201. package/dist/detectors/list-layout.d.ts +14 -0
  202. package/dist/detectors/list-layout.d.ts.map +1 -0
  203. package/dist/detectors/list-layout.js +29 -0
  204. package/dist/detectors/list-layout.js.map +1 -0
  205. package/dist/detectors/list-lead-in.d.ts +6 -1
  206. package/dist/detectors/list-lead-in.d.ts.map +1 -1
  207. package/dist/detectors/list-lead-in.js +42 -2
  208. package/dist/detectors/list-lead-in.js.map +1 -1
  209. package/dist/detectors/list-parallel.d.ts +6 -0
  210. package/dist/detectors/list-parallel.d.ts.map +1 -1
  211. package/dist/detectors/list-parallel.js +106 -13
  212. package/dist/detectors/list-parallel.js.map +1 -1
  213. package/dist/detectors/list-run.d.ts +13 -0
  214. package/dist/detectors/list-run.d.ts.map +1 -0
  215. package/dist/detectors/list-run.js +80 -0
  216. package/dist/detectors/list-run.js.map +1 -0
  217. package/dist/detectors/list-sentence.d.ts +11 -0
  218. package/dist/detectors/list-sentence.d.ts.map +1 -1
  219. package/dist/detectors/list-sentence.js +1 -0
  220. package/dist/detectors/list-sentence.js.map +1 -1
  221. package/dist/detectors/mark-shape.d.ts +2 -1
  222. package/dist/detectors/mark-shape.d.ts.map +1 -1
  223. package/dist/detectors/mark-shape.js +10 -6
  224. package/dist/detectors/mark-shape.js.map +1 -1
  225. package/dist/detectors/name-run.d.ts +2 -0
  226. package/dist/detectors/name-run.d.ts.map +1 -1
  227. package/dist/detectors/name-run.js +1 -1
  228. package/dist/detectors/name-run.js.map +1 -1
  229. package/dist/detectors/name-variant-two-things.d.ts +18 -0
  230. package/dist/detectors/name-variant-two-things.d.ts.map +1 -0
  231. package/dist/detectors/name-variant-two-things.js +84 -0
  232. package/dist/detectors/name-variant-two-things.js.map +1 -0
  233. package/dist/detectors/name-variant.d.ts.map +1 -1
  234. package/dist/detectors/name-variant.js +14 -15
  235. package/dist/detectors/name-variant.js.map +1 -1
  236. package/dist/detectors/organisation-run.d.ts +6 -0
  237. package/dist/detectors/organisation-run.d.ts.map +1 -1
  238. package/dist/detectors/organisation-run.js +26 -2
  239. package/dist/detectors/organisation-run.js.map +1 -1
  240. package/dist/detectors/orthographic-variant-open.d.ts +35 -0
  241. package/dist/detectors/orthographic-variant-open.d.ts.map +1 -0
  242. package/dist/detectors/orthographic-variant-open.js +79 -0
  243. package/dist/detectors/orthographic-variant-open.js.map +1 -0
  244. package/dist/detectors/orthographic-variant.d.ts.map +1 -1
  245. package/dist/detectors/orthographic-variant.js +55 -59
  246. package/dist/detectors/orthographic-variant.js.map +1 -1
  247. package/dist/detectors/over-general-claim.d.ts.map +1 -1
  248. package/dist/detectors/over-general-claim.js +82 -4
  249. package/dist/detectors/over-general-claim.js.map +1 -1
  250. package/dist/detectors/oxford-comma.d.ts.map +1 -1
  251. package/dist/detectors/oxford-comma.js +61 -27
  252. package/dist/detectors/oxford-comma.js.map +1 -1
  253. package/dist/detectors/particle-run-names.d.ts +8 -0
  254. package/dist/detectors/particle-run-names.d.ts.map +1 -0
  255. package/dist/detectors/particle-run-names.js +17 -0
  256. package/dist/detectors/particle-run-names.js.map +1 -0
  257. package/dist/detectors/proper-noun-density.d.ts +13 -0
  258. package/dist/detectors/proper-noun-density.d.ts.map +1 -0
  259. package/dist/detectors/proper-noun-density.js +97 -0
  260. package/dist/detectors/proper-noun-density.js.map +1 -0
  261. package/dist/detectors/quoted-excerpt.d.ts +13 -0
  262. package/dist/detectors/quoted-excerpt.d.ts.map +1 -0
  263. package/dist/detectors/quoted-excerpt.js +53 -0
  264. package/dist/detectors/quoted-excerpt.js.map +1 -0
  265. package/dist/detectors/reference-entry.d.ts +7 -0
  266. package/dist/detectors/reference-entry.d.ts.map +1 -0
  267. package/dist/detectors/reference-entry.js +35 -0
  268. package/dist/detectors/reference-entry.js.map +1 -0
  269. package/dist/detectors/register-neutral-shape.d.ts +5 -2
  270. package/dist/detectors/register-neutral-shape.d.ts.map +1 -1
  271. package/dist/detectors/register-neutral-shape.js +21 -4
  272. package/dist/detectors/register-neutral-shape.js.map +1 -1
  273. package/dist/detectors/register-set-apart.d.ts +24 -0
  274. package/dist/detectors/register-set-apart.d.ts.map +1 -0
  275. package/dist/detectors/register-set-apart.js +102 -0
  276. package/dist/detectors/register-set-apart.js.map +1 -0
  277. package/dist/detectors/register-voice.d.ts +14 -0
  278. package/dist/detectors/register-voice.d.ts.map +1 -0
  279. package/dist/detectors/register-voice.js +47 -0
  280. package/dist/detectors/register-voice.js.map +1 -0
  281. package/dist/detectors/register.d.ts +5 -0
  282. package/dist/detectors/register.d.ts.map +1 -1
  283. package/dist/detectors/register.js +13 -0
  284. package/dist/detectors/register.js.map +1 -1
  285. package/dist/detectors/registry/closing-cliche.d.ts +3 -0
  286. package/dist/detectors/registry/closing-cliche.d.ts.map +1 -0
  287. package/dist/detectors/registry/closing-cliche.js +3 -0
  288. package/dist/detectors/registry/closing-cliche.js.map +1 -0
  289. package/dist/detectors/registry/closing-exhortation.d.ts +3 -0
  290. package/dist/detectors/registry/closing-exhortation.d.ts.map +1 -0
  291. package/dist/detectors/registry/closing-exhortation.js +3 -0
  292. package/dist/detectors/registry/closing-exhortation.js.map +1 -0
  293. package/dist/detectors/registry/cold-open.d.ts +3 -0
  294. package/dist/detectors/registry/cold-open.d.ts.map +1 -0
  295. package/dist/detectors/registry/cold-open.js +3 -0
  296. package/dist/detectors/registry/cold-open.js.map +1 -0
  297. package/dist/detectors/registry/colon-lead-in.js +1 -1
  298. package/dist/detectors/registry/colon-lead-in.js.map +1 -1
  299. package/dist/detectors/registry/concrete-evidence.js +1 -1
  300. package/dist/detectors/registry/concrete-evidence.js.map +1 -1
  301. package/dist/detectors/registry/ngram-repetition.js +1 -1
  302. package/dist/detectors/registry/ngram-repetition.js.map +1 -1
  303. package/dist/detectors/registry/proper-noun-density.js +1 -1
  304. package/dist/detectors/registry/proper-noun-density.js.map +1 -1
  305. package/dist/detectors/registry/topic-predicate-distance.js +1 -1
  306. package/dist/detectors/registry/topic-predicate-distance.js.map +1 -1
  307. package/dist/detectors/registry/unprompted-denial.d.ts +3 -0
  308. package/dist/detectors/registry/unprompted-denial.d.ts.map +1 -0
  309. package/dist/detectors/registry/unprompted-denial.js +3 -0
  310. package/dist/detectors/registry/unprompted-denial.js.map +1 -0
  311. package/dist/detectors/sentence-ending.d.ts +6 -1
  312. package/dist/detectors/sentence-ending.d.ts.map +1 -1
  313. package/dist/detectors/sentence-ending.js +42 -9
  314. package/dist/detectors/sentence-ending.js.map +1 -1
  315. package/dist/detectors/sentence-length.d.ts.map +1 -1
  316. package/dist/detectors/sentence-length.js +25 -10
  317. package/dist/detectors/sentence-length.js.map +1 -1
  318. package/dist/detectors/sentence-load.d.ts +5 -3
  319. package/dist/detectors/sentence-load.d.ts.map +1 -1
  320. package/dist/detectors/sentence-load.js +3 -5
  321. package/dist/detectors/sentence-load.js.map +1 -1
  322. package/dist/detectors/sentence-parts.d.ts +9 -0
  323. package/dist/detectors/sentence-parts.d.ts.map +1 -0
  324. package/dist/detectors/sentence-parts.js +62 -0
  325. package/dist/detectors/sentence-parts.js.map +1 -0
  326. package/dist/detectors/sentence-title.d.ts +3 -0
  327. package/dist/detectors/sentence-title.d.ts.map +1 -1
  328. package/dist/detectors/sentence-title.js +10 -0
  329. package/dist/detectors/sentence-title.js.map +1 -1
  330. package/dist/detectors/signals.d.ts +0 -2
  331. package/dist/detectors/signals.d.ts.map +1 -1
  332. package/dist/detectors/signals.js +12 -163
  333. package/dist/detectors/signals.js.map +1 -1
  334. package/dist/detectors/structure-tree.d.ts.map +1 -1
  335. package/dist/detectors/structure-tree.js +1 -1
  336. package/dist/detectors/structure-tree.js.map +1 -1
  337. package/dist/detectors/structure.d.ts +9 -1
  338. package/dist/detectors/structure.d.ts.map +1 -1
  339. package/dist/detectors/structure.js +24 -11
  340. package/dist/detectors/structure.js.map +1 -1
  341. package/dist/detectors/superlative-clause.d.ts.map +1 -1
  342. package/dist/detectors/superlative-clause.js +19 -2
  343. package/dist/detectors/superlative-clause.js.map +1 -1
  344. package/dist/detectors/superlative-context.d.ts +35 -0
  345. package/dist/detectors/superlative-context.d.ts.map +1 -0
  346. package/dist/detectors/superlative-context.js +71 -0
  347. package/dist/detectors/superlative-context.js.map +1 -0
  348. package/dist/detectors/superlative-scope.d.ts +6 -2
  349. package/dist/detectors/superlative-scope.d.ts.map +1 -1
  350. package/dist/detectors/superlative-scope.js +20 -6
  351. package/dist/detectors/superlative-scope.js.map +1 -1
  352. package/dist/detectors/team.d.ts +0 -1
  353. package/dist/detectors/team.d.ts.map +1 -1
  354. package/dist/detectors/team.js +0 -46
  355. package/dist/detectors/team.js.map +1 -1
  356. package/dist/detectors/titled-code-citation.d.ts +12 -0
  357. package/dist/detectors/titled-code-citation.d.ts.map +1 -0
  358. package/dist/detectors/titled-code-citation.js +11 -0
  359. package/dist/detectors/titled-code-citation.js.map +1 -0
  360. package/dist/detectors/titled-run.d.ts +8 -1
  361. package/dist/detectors/titled-run.d.ts.map +1 -1
  362. package/dist/detectors/titled-run.js +14 -4
  363. package/dist/detectors/titled-run.js.map +1 -1
  364. package/dist/detectors/token-shape.d.ts.map +1 -1
  365. package/dist/detectors/token-shape.js +22 -11
  366. package/dist/detectors/token-shape.js.map +1 -1
  367. package/dist/detectors/topic-predicate-distance.d.ts +4 -0
  368. package/dist/detectors/topic-predicate-distance.d.ts.map +1 -0
  369. package/dist/detectors/topic-predicate-distance.js +22 -0
  370. package/dist/detectors/topic-predicate-distance.js.map +1 -0
  371. package/dist/detectors/unknown-word-context.d.ts +28 -0
  372. package/dist/detectors/unknown-word-context.d.ts.map +1 -0
  373. package/dist/detectors/unknown-word-context.js +89 -0
  374. package/dist/detectors/unknown-word-context.js.map +1 -0
  375. package/dist/detectors/unknown-word.d.ts +0 -5
  376. package/dist/detectors/unknown-word.d.ts.map +1 -1
  377. package/dist/detectors/unknown-word.js +16 -19
  378. package/dist/detectors/unknown-word.js.map +1 -1
  379. package/dist/detectors/unprompted-denial.d.ts +25 -0
  380. package/dist/detectors/unprompted-denial.d.ts.map +1 -0
  381. package/dist/detectors/unprompted-denial.js +100 -0
  382. package/dist/detectors/unprompted-denial.js.map +1 -0
  383. package/dist/document-sections.d.ts.map +1 -1
  384. package/dist/document-sections.js +3 -1
  385. package/dist/document-sections.js.map +1 -1
  386. package/dist/fix-plan/all-signs.d.ts +17 -0
  387. package/dist/fix-plan/all-signs.d.ts.map +1 -0
  388. package/dist/fix-plan/all-signs.js +26 -0
  389. package/dist/fix-plan/all-signs.js.map +1 -0
  390. package/dist/fix-plan/plan.d.ts +31 -0
  391. package/dist/fix-plan/plan.d.ts.map +1 -1
  392. package/dist/fix-plan/plan.js +23 -3
  393. package/dist/fix-plan/plan.js.map +1 -1
  394. package/dist/fix-plan/render.d.ts.map +1 -1
  395. package/dist/fix-plan/render.js +31 -2
  396. package/dist/fix-plan/render.js.map +1 -1
  397. package/dist/fix-plan/risen.d.ts +10 -0
  398. package/dist/fix-plan/risen.d.ts.map +1 -0
  399. package/dist/fix-plan/risen.js +7 -0
  400. package/dist/fix-plan/risen.js.map +1 -0
  401. package/dist/fix-plan/text.d.ts +15 -0
  402. package/dist/fix-plan/text.d.ts.map +1 -1
  403. package/dist/fix-plan/text.js +38 -2
  404. package/dist/fix-plan/text.js.map +1 -1
  405. package/dist/heading-numbering.d.ts +2 -1
  406. package/dist/heading-numbering.d.ts.map +1 -1
  407. package/dist/heading-numbering.js +40 -10
  408. package/dist/heading-numbering.js.map +1 -1
  409. package/dist/html/html-site-chrome.d.ts.map +1 -1
  410. package/dist/html/html-site-chrome.js +7 -2
  411. package/dist/html/html-site-chrome.js.map +1 -1
  412. package/dist/law-title.d.ts +7 -0
  413. package/dist/law-title.d.ts.map +1 -0
  414. package/dist/law-title.js +29 -0
  415. package/dist/law-title.js.map +1 -0
  416. package/dist/name-ending-run.d.ts +11 -0
  417. package/dist/name-ending-run.d.ts.map +1 -0
  418. package/dist/name-ending-run.js +37 -0
  419. package/dist/name-ending-run.js.map +1 -0
  420. package/dist/name-title-slip.d.ts +11 -0
  421. package/dist/name-title-slip.d.ts.map +1 -0
  422. package/dist/name-title-slip.js +51 -0
  423. package/dist/name-title-slip.js.map +1 -0
  424. package/dist/name-variant-shapes.d.ts +14 -0
  425. package/dist/name-variant-shapes.d.ts.map +1 -0
  426. package/dist/name-variant-shapes.js +43 -0
  427. package/dist/name-variant-shapes.js.map +1 -0
  428. package/dist/name-word-use.d.ts +5 -0
  429. package/dist/name-word-use.d.ts.map +1 -0
  430. package/dist/name-word-use.js +12 -0
  431. package/dist/name-word-use.js.map +1 -0
  432. package/dist/opening-passage.d.ts +8 -0
  433. package/dist/opening-passage.d.ts.map +1 -0
  434. package/dist/opening-passage.js +24 -0
  435. package/dist/opening-passage.js.map +1 -0
  436. package/dist/plugin.d.ts +2 -0
  437. package/dist/plugin.d.ts.map +1 -1
  438. package/dist/quote-gloss.d.ts +4 -0
  439. package/dist/quote-gloss.d.ts.map +1 -0
  440. package/dist/quote-gloss.js +7 -0
  441. package/dist/quote-gloss.js.map +1 -0
  442. package/dist/quoted-spelling.d.ts +17 -0
  443. package/dist/quoted-spelling.d.ts.map +1 -0
  444. package/dist/quoted-spelling.js +27 -0
  445. package/dist/quoted-spelling.js.map +1 -0
  446. package/dist/render/semantic.d.ts +1 -1
  447. package/dist/render/semantic.d.ts.map +1 -1
  448. package/dist/render/semantic.js +2 -1
  449. package/dist/render/semantic.js.map +1 -1
  450. package/dist/rule-of-three.d.ts +19 -0
  451. package/dist/rule-of-three.d.ts.map +1 -0
  452. package/dist/rule-of-three.js +33 -0
  453. package/dist/rule-of-three.js.map +1 -0
  454. package/dist/run-semantic.d.ts.map +1 -1
  455. package/dist/run-semantic.js +2 -2
  456. package/dist/run-semantic.js.map +1 -1
  457. package/dist/section-levels.d.ts +18 -0
  458. package/dist/section-levels.d.ts.map +1 -0
  459. package/dist/section-levels.js +80 -0
  460. package/dist/section-levels.js.map +1 -0
  461. package/dist/semantic.d.ts +2 -0
  462. package/dist/semantic.d.ts.map +1 -1
  463. package/dist/semantic.js +13 -0
  464. package/dist/semantic.js.map +1 -1
  465. package/dist/sentence-load.d.ts +2 -1
  466. package/dist/sentence-load.d.ts.map +1 -1
  467. package/dist/sentence-load.js +4 -2
  468. package/dist/sentence-load.js.map +1 -1
  469. package/dist/spelling.d.ts +11 -0
  470. package/dist/spelling.d.ts.map +1 -1
  471. package/dist/spelling.js +19 -5
  472. package/dist/spelling.js.map +1 -1
  473. package/dist/structure/cited-document-section.d.ts.map +1 -1
  474. package/dist/structure/cited-document-section.js +15 -1
  475. package/dist/structure/cited-document-section.js.map +1 -1
  476. package/dist/structure/issues.d.ts +1 -1
  477. package/dist/structure/issues.d.ts.map +1 -1
  478. package/dist/structure/issues.js +5 -1
  479. package/dist/structure/issues.js.map +1 -1
  480. package/dist/structure-shape/template-outline.d.ts +11 -0
  481. package/dist/structure-shape/template-outline.d.ts.map +1 -0
  482. package/dist/structure-shape/template-outline.js +25 -0
  483. package/dist/structure-shape/template-outline.js.map +1 -0
  484. package/dist/title-case-name.d.ts +12 -0
  485. package/dist/title-case-name.d.ts.map +1 -0
  486. package/dist/title-case-name.js +37 -0
  487. package/dist/title-case-name.js.map +1 -0
  488. package/dist/topic-clause.d.ts +6 -1
  489. package/dist/topic-clause.d.ts.map +1 -1
  490. package/dist/topic-clause.js +77 -3
  491. package/dist/topic-clause.js.map +1 -1
  492. package/dist/word-use.d.ts +12 -4
  493. package/dist/word-use.d.ts.map +1 -1
  494. package/dist/word-use.js +47 -5
  495. package/dist/word-use.js.map +1 -1
  496. package/package.json +4 -3
  497. package/rules/ai-generated-composite.yaml +11 -3
  498. package/rules/ai-structure.yaml +7 -6
  499. package/rules/ai-tell.yaml +4 -4
  500. package/rules/all-caps-shouting.yaml +2 -2
  501. package/rules/bold-emphasis.yaml +5 -4
  502. package/rules/closing-cliche.yaml +4 -5
  503. package/rules/closing-exhortation.yaml +74 -0
  504. package/rules/cold-open.yaml +95 -0
  505. package/rules/colon-lead-in.yaml +68 -10
  506. package/rules/comparative-without-baseline.yaml +2 -2
  507. package/rules/concrete-evidence-density.yaml +2 -2
  508. package/rules/contrast-framing.yaml +16 -13
  509. package/rules/dangling-reference.yaml +2 -2
  510. package/rules/duplicate-heading.yaml +5 -2
  511. package/rules/email-greeting-closing.yaml +2 -2
  512. package/rules/email-stock-courtesy.yaml +62 -0
  513. package/rules/fullwidth-alnum-consistency.yaml +2 -2
  514. package/rules/generic-opening.yaml +63 -0
  515. package/rules/heading-level-skip.yaml +2 -2
  516. package/rules/heading-numbering-mix.yaml +20 -20
  517. package/rules/hyphen-as-dash.yaml +2 -2
  518. package/rules/kutoten-consistency.yaml +4 -4
  519. package/rules/list-item-form-mix.yaml +2 -2
  520. package/rules/max-kanji-continuous.yaml +7 -3
  521. package/rules/max-sentence-length.yaml +4 -2
  522. package/rules/name-variant.yaml +5 -2
  523. package/rules/ngram-repetition.yaml +2 -2
  524. package/rules/no-doubled-joshi.yaml +2 -2
  525. package/rules/no-em-dash.yaml +2 -2
  526. package/rules/no-mixed-desumasu.yaml +16 -3
  527. package/rules/orthographic-variant.yaml +2 -2
  528. package/rules/over-general-claim.yaml +2 -2
  529. package/rules/oxford-comma-consistency.yaml +15 -3
  530. package/rules/proper-noun-density.yaml +14 -7
  531. package/rules/rule-of-three.yaml +3 -3
  532. package/rules/section-length-uniformity.yaml +2 -2
  533. package/rules/topic-predicate-distance.yaml +3 -2
  534. package/rules/undefined-acronym.yaml +8 -2
  535. package/rules/unknown-word.yaml +2 -2
  536. package/rules/unprompted-denial.yaml +88 -0
  537. package/rules/unqualified-superlative.yaml +8 -2
  538. package/skills/chaff/SKILL.md +38 -6
  539. package/src/acronym-expansion.ts +57 -0
  540. package/src/ai-score/human-shares.ts +53 -12
  541. package/src/ai-score/of-document.ts +5 -2
  542. package/src/body-section.ts +11 -2
  543. package/src/capitals-with-small.ts +16 -0
  544. package/src/checks.ts +32 -1
  545. package/src/cli-args.ts +1 -1
  546. package/src/cli-text.ts +4 -0
  547. package/src/commands/fix-plan.ts +72 -5
  548. package/src/commands/test.ts +18 -2
  549. package/src/detectors/acronym-context.ts +20 -2
  550. package/src/detectors/acronym-expansion.ts +26 -0
  551. package/src/detectors/acronym-gloss.ts +123 -0
  552. package/src/detectors/acronym-name.ts +22 -3
  553. package/src/detectors/acronym-series.ts +27 -0
  554. package/src/detectors/ai-phrasing.ts +18 -17
  555. package/src/detectors/ai-structure.ts +23 -6
  556. package/src/detectors/alnum-number.ts +8 -3
  557. package/src/detectors/bare-comparative.ts +41 -13
  558. package/src/detectors/bold-emphasis-form.ts +58 -0
  559. package/src/detectors/bold-emphasis.ts +16 -17
  560. package/src/detectors/caps-caption.ts +24 -2
  561. package/src/detectors/char-shape.ts +118 -29
  562. package/src/detectors/chat-log-line.ts +17 -0
  563. package/src/detectors/citation-string.ts +36 -0
  564. package/src/detectors/closing-cliche.ts +74 -0
  565. package/src/detectors/closing-exhortation.ts +74 -0
  566. package/src/detectors/cold-open.ts +145 -0
  567. package/src/detectors/comparative-context.ts +74 -0
  568. package/src/detectors/concrete-evidence-density.ts +99 -0
  569. package/src/detectors/concrete-evidence.ts +40 -0
  570. package/src/detectors/contrast-frame.ts +65 -7
  571. package/src/detectors/coordinate-adjective.ts +4 -2
  572. package/src/detectors/duplicate-heading.ts +44 -15
  573. package/src/detectors/email-frame-words.ts +39 -0
  574. package/src/detectors/email-letter.ts +15 -20
  575. package/src/detectors/fullwidth-alnum.ts +24 -4
  576. package/src/detectors/gram-furniture.ts +87 -1
  577. package/src/detectors/gram-openers.ts +71 -0
  578. package/src/detectors/gram-predicate.ts +49 -6
  579. package/src/detectors/gram-repetition.ts +199 -0
  580. package/src/detectors/heading-level-skip.ts +31 -1
  581. package/src/detectors/heading-numbering.ts +2 -2
  582. package/src/detectors/hyphen-copied-text.ts +65 -0
  583. package/src/detectors/kanji-name-edge.ts +31 -0
  584. package/src/detectors/kanji-run-pieces.ts +26 -0
  585. package/src/detectors/kutoten-consistency.ts +24 -4
  586. package/src/detectors/lead-in-dash.ts +11 -0
  587. package/src/detectors/letter-joined-name.ts +14 -0
  588. package/src/detectors/lexicon.ts +15 -2
  589. package/src/detectors/list-item.ts +37 -1
  590. package/src/detectors/list-items.ts +4 -1
  591. package/src/detectors/list-joint.ts +44 -0
  592. package/src/detectors/list-layout.ts +39 -0
  593. package/src/detectors/list-lead-in.ts +50 -3
  594. package/src/detectors/list-parallel.ts +119 -13
  595. package/src/detectors/list-run.ts +86 -0
  596. package/src/detectors/list-sentence.ts +11 -0
  597. package/src/detectors/mark-shape.ts +12 -7
  598. package/src/detectors/name-run.ts +2 -1
  599. package/src/detectors/name-variant-two-things.ts +136 -0
  600. package/src/detectors/name-variant.ts +14 -19
  601. package/src/detectors/organisation-run.ts +26 -2
  602. package/src/detectors/orthographic-variant-open.ts +119 -0
  603. package/src/detectors/orthographic-variant.ts +82 -82
  604. package/src/detectors/over-general-claim.ts +106 -5
  605. package/src/detectors/oxford-comma.ts +68 -28
  606. package/src/detectors/particle-run-names.ts +17 -0
  607. package/src/detectors/proper-noun-density.ts +109 -0
  608. package/src/detectors/quoted-excerpt.ts +68 -0
  609. package/src/detectors/reference-entry.ts +42 -0
  610. package/src/detectors/register-neutral-shape.ts +26 -6
  611. package/src/detectors/register-set-apart.ts +124 -0
  612. package/src/detectors/register-voice.ts +63 -0
  613. package/src/detectors/register.ts +15 -0
  614. package/src/detectors/registry/closing-cliche.ts +4 -0
  615. package/src/detectors/registry/closing-exhortation.ts +4 -0
  616. package/src/detectors/registry/cold-open.ts +4 -0
  617. package/src/detectors/registry/colon-lead-in.ts +1 -1
  618. package/src/detectors/registry/concrete-evidence.ts +1 -1
  619. package/src/detectors/registry/ngram-repetition.ts +1 -1
  620. package/src/detectors/registry/proper-noun-density.ts +1 -1
  621. package/src/detectors/registry/topic-predicate-distance.ts +1 -1
  622. package/src/detectors/registry/unprompted-denial.ts +4 -0
  623. package/src/detectors/sentence-ending.ts +60 -12
  624. package/src/detectors/sentence-length.ts +26 -9
  625. package/src/detectors/sentence-load.ts +3 -6
  626. package/src/detectors/sentence-parts.ts +70 -0
  627. package/src/detectors/sentence-title.ts +14 -0
  628. package/src/detectors/signals.ts +13 -198
  629. package/src/detectors/structure-tree.ts +3 -1
  630. package/src/detectors/structure.ts +25 -13
  631. package/src/detectors/superlative-clause.ts +21 -2
  632. package/src/detectors/superlative-context.ts +99 -0
  633. package/src/detectors/superlative-scope.ts +27 -9
  634. package/src/detectors/team.ts +1 -50
  635. package/src/detectors/titled-code-citation.ts +19 -0
  636. package/src/detectors/titled-run.ts +22 -5
  637. package/src/detectors/token-shape.ts +25 -13
  638. package/src/detectors/topic-predicate-distance.ts +25 -0
  639. package/src/detectors/unknown-word-context.ts +112 -0
  640. package/src/detectors/unknown-word.ts +18 -20
  641. package/src/detectors/unprompted-denial.ts +133 -0
  642. package/src/document-sections.ts +3 -1
  643. package/src/fix-plan/all-signs.ts +35 -0
  644. package/src/fix-plan/plan.ts +50 -3
  645. package/src/fix-plan/render.ts +41 -3
  646. package/src/fix-plan/risen.ts +13 -0
  647. package/src/fix-plan/text.ts +56 -2
  648. package/src/heading-numbering.ts +44 -10
  649. package/src/html/html-site-chrome.ts +9 -2
  650. package/src/law-title.ts +38 -0
  651. package/src/name-ending-run.ts +49 -0
  652. package/src/name-title-slip.ts +59 -0
  653. package/src/name-variant-shapes.ts +58 -0
  654. package/src/name-word-use.ts +17 -0
  655. package/src/opening-passage.ts +31 -0
  656. package/src/plugin.ts +2 -0
  657. package/src/quote-gloss.ts +11 -0
  658. package/src/quoted-spelling.ts +48 -0
  659. package/src/render/semantic.ts +2 -2
  660. package/src/rule-of-three.ts +50 -0
  661. package/src/run-semantic.ts +2 -2
  662. package/src/section-levels.ts +98 -0
  663. package/src/semantic.ts +14 -0
  664. package/src/sentence-load.ts +5 -3
  665. package/src/spelling.ts +37 -7
  666. package/src/structure/cited-document-section.ts +16 -1
  667. package/src/structure/issues.ts +10 -1
  668. package/src/structure-shape/template-outline.ts +34 -0
  669. package/src/title-case-name.ts +55 -0
  670. package/src/topic-clause.ts +96 -5
  671. package/src/word-use.ts +57 -6
  672. package/dist/legal-address.d.ts +0 -2
  673. package/dist/legal-address.d.ts.map +0 -1
  674. package/dist/legal-address.js +0 -16
  675. package/dist/legal-address.js.map +0 -1
@@ -1,11 +1,13 @@
1
1
  import { charLength, lengthOf, proseText } from "../measure.ts";
2
2
  import { contractionExtraWords } from "../contraction-words.ts";
3
- import type { BulletList, Detector, DetectorOptions, Finding, LengthUnit, Paragraph, ProseDocument, Section, Sentence, Span } from "../plugin.ts";
3
+ import type { Detector, DetectorOptions, Finding, LengthUnit, Paragraph, ProseDocument, Section, Sentence, Span } from "../plugin.ts";
4
4
  import { dateStampIndexes, stampCandidates } from "../date-stamp.ts";
5
5
  import { inDocumentOrder } from "../structure/issues.ts";
6
6
  import { preambleParagraphs } from "../preamble-paragraphs.ts";
7
7
  import { isTooLongParagraph } from "../paragraph-length.ts";
8
8
  import { bodySectionOf } from "../body-section.ts";
9
+ import { threeShare } from "../rule-of-three.ts";
10
+ import { isInterview, sectionLevels } from "../section-levels.ts";
9
11
 
10
12
  /**
11
13
  * ばらつきは変動係数(標準偏差 ÷ 平均)で測る。
@@ -91,34 +93,44 @@ export const paragraphVariance: Detector = (doc, options): Finding[] => {
91
93
 
92
94
  const sectionChars = (section: Section): number => section.sentences.reduce((sum, sentence) => sum + charLength(sentence), 0);
93
95
 
94
- /** 節の長さが揃いすぎている。見出しごとに機械的に埋めた文書で起きる。 */
96
+ const isEven = (lengths: readonly number[], least: number, limit: number): boolean => {
97
+ const cv = lengths.length < least ? undefined : coefficientOfVariation(lengths);
98
+ return cv !== undefined && asPercent(cv) < limit;
99
+ };
100
+
101
+ /**
102
+ * 節の長さが揃いすぎている。見出しごとに機械的に埋めた文書で起きる。
103
+ * 節を一つずつ数えて揃っていても、読み手が並べて比べる節(小見出しを含めた節どうし、まとめ見出しの下の小見出しどうし)でも
104
+ * 揃っていなければ指摘しない。短い小見出しが 4 つあるだけで、揃った節が 4 つあるように見えるから。
105
+ */
95
106
  export const sectionUniformity: Detector = (doc, options): Finding[] => {
107
+ const marks = (doc.lexicons["interviewer-mark"] ?? []).map((entry) => entry.pattern);
108
+ const starts = doc.paragraphs.map((paragraph) => paragraph.span.start);
109
+ if (isInterview(doc.source, doc.sections, starts, marks)) return [];
110
+ const least = minimumCount(options, "min_sections", DEFAULT_MIN_SECTIONS);
96
111
  const lengths = doc.sections.map(sectionChars).filter((length) => length > 0);
97
112
  const first = doc.sections[0];
98
- if (first === undefined || lengths.length < minimumCount(options, "min_sections", DEFAULT_MIN_SECTIONS)) return [];
99
- return uniformity(doc, lengths, first.span, options.limit, "section-length-uniformity");
113
+ if (first === undefined || lengths.length < least) return [];
114
+ const compared = sectionLevels(doc.sections, sectionChars).some((level) => isEven(level.lengths, least, options.limit));
115
+ return compared ? uniformity(doc, lengths, first.span, options.limit, "section-length-uniformity") : [];
100
116
  };
101
117
 
102
118
  /**
103
119
  * 3 項目の箇条書きばかりになっている。
104
120
  * 3 つ並べると収まりがよいので、言いたいことが 2 つでも 4 つでも 3 つにされる。
105
121
  */
106
- const isThree = (list: BulletList): boolean => list.items.length === 3;
107
-
108
122
  export const ruleOfThree: Detector = (doc, options): Finding[] => {
109
- const lists = doc.lists;
110
- const threes = lists.filter(isThree);
111
- const share = lists.length === 0 ? 0 : Math.round((threes.length / lists.length) * PERCENT);
112
- const first = threes[0];
113
- if (lists.length < 3 || first === undefined || share <= options.limit) return [];
123
+ const openWords = (doc.lexicons["list-continues"] ?? []).map((entry) => entry.pattern);
124
+ const found = threeShare(doc.source, doc.lists, openWords, options.limit);
125
+ if (found === undefined) return [];
114
126
  return [
115
127
  {
116
128
  rule: "rule-of-three",
117
129
  severity: "info",
118
130
  line: 0,
119
131
  column: 0,
120
- quote: doc.source.slice(first.span.start, first.span.start + 80).trim(),
121
- values: { count: threes.length, total: lists.length, share, limit: options.limit, offset: first.span.start },
132
+ quote: doc.source.slice(found.first.span.start, found.first.span.start + 80).trim(),
133
+ values: { count: found.count, total: found.total, share: found.share, limit: options.limit, offset: found.first.span.start },
122
134
  },
123
135
  ];
124
136
  };
@@ -27,6 +27,16 @@ const verbAfterSubject = (tokens: readonly Token[], at: number, subjects: Lexico
27
27
  return isVerbal(tokens[phraseEnd(tokens, at)]);
28
28
  };
29
29
 
30
+ /**
31
+ * 代名詞の後ろの一語で節が終わる(the files you own.)。品詞の読みが own を形容詞とすることがあるので、品詞でなく
32
+ * 節の終わりで読む。代名詞と一語だけの節は、名詞句を限る節のほかにない。
33
+ */
34
+ const closingWord = (tokens: readonly Token[], at: number): boolean => {
35
+ const word = tokens[at];
36
+ const next = tokens[at + 1];
37
+ return word !== undefined && word.pos !== "PUNCT" && (next === undefined || next.pos === "PUNCT");
38
+ };
39
+
30
40
  const isArticle = (token: Token | undefined): boolean => token?.features?.["PronType"] === "Art";
31
41
 
32
42
  /**
@@ -34,7 +44,7 @@ const isArticle = (token: Token | undefined): boolean => token?.features?.["Pron
34
44
  * each・all のような限定詞(The best teams all adapt)や、冠詞の無い名詞(The best teams adapt)は節の始まりと読まない。
35
45
  */
36
46
  const contactClause = (tokens: readonly Token[], at: number, subjects: Lexicon): boolean => {
37
- if (isWord(tokens[at], subjects)) return isVerbal(tokens[at + 1]);
47
+ if (isWord(tokens[at], subjects)) return isVerbal(tokens[at + 1]) || closingWord(tokens, at + 1);
38
48
  return isArticle(tokens[at]) && isVerbal(tokens[phraseEnd(tokens, at + 1)]);
39
49
  };
40
50
 
@@ -64,10 +74,19 @@ const participle = (tokens: readonly Token[], range: TokenRange, at: number): bo
64
74
  const bounded = (tokens: readonly Token[], range: TokenRange, at: number, bounds: Lexicon): boolean =>
65
75
  isWord(tokens[range.end], bounds) || isWord(tokens[at], bounds);
66
76
 
77
+ /**
78
+ * 修飾の語の並びが動詞で終わって、その後ろに代名詞の主語が来る(the most irreplaceable files you own)。修飾の動詞の後ろには
79
+ * 名詞が要るので、終わりの「動詞」は名詞を動詞と読んだもの。分詞(the most watched)は Part なので除く。
80
+ */
81
+ const headReadAsVerb = (tokens: readonly Token[], range: TokenRange, at: number, subjects: Lexicon): boolean => {
82
+ const last = tokens[at - 1];
83
+ return at > range.end && last?.pos === "VERB" && last.features?.["VerbForm"] !== "Part" && isWord(tokens[at], subjects);
84
+ };
85
+
67
86
  /** 修飾の語は名詞の前に来るので、句の後ろで止まった分詞は名詞の後ろにある。 */
68
87
  const clauseOrParticiple = (tokens: readonly Token[], range: TokenRange, at: number, restrictors: Restrictors): boolean => {
69
88
  const last = tokens[at - 1];
70
- const endsPhrase = at === range.end || (last !== undefined && PHRASE_END.has(last.pos));
89
+ const endsPhrase = at === range.end || (last !== undefined && (PHRASE_END.has(last.pos) || headReadAsVerb(tokens, range, at, restrictors.subjects)));
71
90
  return (endsPhrase && clause(tokens, at, restrictors)) || participle(tokens, range, at);
72
91
  };
73
92
 
@@ -0,0 +1,99 @@
1
+ import type { Lexicon, LexiconEntry, Sentence, Token } from "../plugin.ts";
2
+ import { entryEndsAt, entryRanges, type TokenRange } from "./lexicon-match.ts";
3
+ import { phraseEnd } from "./superlative-scope.ts";
4
+
5
+ /** 最上級の周りで、比べて言い切ってはいないことを示す語。どれも言語パッケージの語彙表が持つ。 */
6
+ export type Context = {
7
+ /** 求める・選ぶ動詞(achieve・decide・求める)。position は最上級のどちら側に立つか。 */
8
+ readonly goals: Lexicon;
9
+ /** 述語の後ろで、どれが最もなのかを指す語(the one・the second)。 */
10
+ readonly referents: Lexicon;
11
+ /** 誰にとっての最もなのかを言う語(にとって)。 */
12
+ readonly viewpoints: Lexicon;
13
+ /** 全体の部分を言う名詞(part・role・step)。 */
14
+ readonly parts: Lexicon;
15
+ };
16
+
17
+ /** 語彙表の語が最上級まで届く語の数。これより離れた動詞は、間に別の目的語や節がある。 */
18
+ const GOAL_REACH = 4;
19
+
20
+ /** 文の終わりの記号の後ろに付く、閉じの記号と強調の印(?」・?**)。 */
21
+ const CLOSING = new Set(" \t\n*_\"'”’」』))]");
22
+ const QUESTION = new Set(["?", "?"]);
23
+
24
+ /** 問いの文(What takes the longest?・最も良い道は何か?)。問う文は何かが一番だと言い切っていない。 */
25
+ export const asked = (sentence: Sentence): boolean => {
26
+ const chars = [...sentence.text];
27
+ return QUESTION.has(chars[chars.findLastIndex((char) => !CLOSING.has(char))] ?? "");
28
+ };
29
+
30
+ /** 語彙表から、最上級の周りを読む語を集める。 */
31
+ export const contextOf = (lexicons: Readonly<Record<string, Lexicon>>): Context => ({
32
+ goals: lexicons["superlative-goal"] ?? [],
33
+ referents: lexicons["superlative-referent"] ?? [],
34
+ viewpoints: lexicons["superlative-viewpoint"] ?? [],
35
+ parts: lexicons["superlative-part"] ?? [],
36
+ });
37
+
38
+ const isPunct = (token: Token | undefined): boolean => token === undefined || token.pos === "PUNCT";
39
+
40
+ /** from 番目から to 番目の手前までに句読点が無いか。句読点を越えた語は別の節にかかる。 */
41
+ const sameClause = (tokens: readonly Token[], from: number, to: number): boolean => !tokens.slice(from, to).some((token) => isPunct(token));
42
+
43
+ /** 語彙の語が、最上級の手前 reach 語までのどこかで終わり、間に句読点が無いか。 */
44
+ const endsBefore = (tokens: readonly Token[], range: TokenRange, entry: LexiconEntry, reach: number): boolean => {
45
+ const ends = Array.from({ length: Math.min(reach, range.start) + 1 }, (_unused, back) => range.start - back);
46
+ return ends.some((end) => entryEndsAt(tokens, entry, end) && sameClause(tokens, end, range.start));
47
+ };
48
+
49
+ /** 語彙の語が最上級より後ろにあるか。 */
50
+ const after = (sentence: Sentence, range: TokenRange, entry: LexiconEntry): boolean => entryRanges(sentence, entry).some((found) => found.start >= range.end);
51
+
52
+ /**
53
+ * 最上級が、求めるか選ぶものとして書かれているか(achieve the best results・decide the best way・最高の規律が求められる)。
54
+ * 目指す先や選ぶ基準を言っていて、何かが一番だという主張ではない。英語の動詞は最上級の前に、日本語の述語は後ろに来る。
55
+ */
56
+ export const sought = (sentence: Sentence, range: TokenRange, goals: Lexicon): boolean => {
57
+ const tokens = sentence.tokens ?? [];
58
+ return goals.some((entry) => (entry.position === "after" ? after(sentence, range, entry) : endsBefore(tokens, range, entry, GOAL_REACH)));
59
+ };
60
+
61
+ const isWord = (token: Token | undefined, words: Lexicon): boolean =>
62
+ token !== undefined && words.some((entry) => entry.pattern.toLowerCase() === token.surface.toLowerCase());
63
+
64
+ const VERBAL = new Set(["VERB", "AUX"]);
65
+
66
+ const isVerbal = (token: Token | undefined): boolean => VERBAL.has(token?.pos ?? "");
67
+
68
+ /**
69
+ * 名詞句の後ろの述語の動詞。数(the best one is)の後ろの動詞は修飾として句に読み込まれるので、句の最後の語も見る。
70
+ */
71
+ const verbAt = (tokens: readonly Token[], range: TokenRange, end: number): number | undefined => {
72
+ if (isVerbal(tokens[end])) return end;
73
+ return end - 1 > range.end && isVerbal(tokens[end - 1]) ? end - 1 : undefined;
74
+ };
75
+
76
+ /**
77
+ * 最上級の名詞句が主語で、述語がどれかを指しているか(The best plan is the one you keep・The most important divergence is
78
+ * the second)。どれが一番なのかを決める言い方で、一番だという主張ではない。
79
+ */
80
+ export const pointsAtReferent = (tokens: readonly Token[], range: TokenRange, referents: Lexicon): boolean => {
81
+ const end = phraseEnd(tokens, range.end);
82
+ const at = verbAt(tokens, range, end);
83
+ if (at === undefined) return false;
84
+ const next = tokens[at + 1]?.pos === "DET" ? at + 2 : at + 1;
85
+ return isWord(tokens[next], referents);
86
+ };
87
+
88
+ /** 誰にとっての最もなのかが、同じ節の最上級より前にあるか(俺にとって今日は最高の日だ)。 */
89
+ export const viewpointBefore = (tokens: readonly Token[], range: TokenRange, viewpoints: Lexicon): boolean =>
90
+ viewpoints.some((entry) => endsBefore(tokens, range, entry, range.start));
91
+
92
+ /**
93
+ * 最上級の名詞が全体の部分を言うか(the most important part・the most important role)。比べているのは、文章が述べている
94
+ * 全体の部分どうしで、世の中のものと比べた主張ではない。名詞は最上級の修飾の後ろに来る(英語)。
95
+ */
96
+ export const ranksParts = (tokens: readonly Token[], range: TokenRange, parts: Lexicon): boolean => {
97
+ const at = phraseEnd(tokens, range.end);
98
+ return at > range.end && isWord(tokens[at - 1], parts);
99
+ };
@@ -8,14 +8,20 @@ import type { TokenRange } from "./lexicon-match.ts";
8
8
  export type ScopeMarkers = {
9
9
  /** 最上級の直前に置く語(で)。その前に固有名詞か地名が要る。 */
10
10
  readonly before: Lexicon;
11
- /** 最上級の名詞句の直後に置く語(in・of)。その後ろに名詞句が要る。 */
11
+ /** 最上級の名詞句の直後に置く語(in・of)。その後ろに名詞句か動名詞が要る。 */
12
12
  readonly after: Lexicon;
13
+ /** 名詞句の直後で、動名詞が続くときだけ範囲を言う語(the best tool for creating)。for + 名詞(the best opportunity for government)は受け手。 */
14
+ readonly purposes: Lexicon;
15
+ /** 名前でなくても、範囲の「で」の前で範囲になる名詞(世界で唯一の・業界で最も)。 */
16
+ readonly realms: Lexicon;
13
17
  };
14
18
 
15
19
  /** 語彙表の position で分ける。position の無い語は、どちら側の語か分からないので使わない。 */
16
- export const scopeMarkersOf = (lexicon: Lexicon): ScopeMarkers => ({
20
+ export const scopeMarkersOf = (lexicon: Lexicon, purposes: Lexicon = [], realms: Lexicon = []): ScopeMarkers => ({
17
21
  before: lexicon.filter((entry) => entry.position === "before"),
18
22
  after: lexicon.filter((entry) => entry.position === "after"),
23
+ purposes,
24
+ realms,
19
25
  });
20
26
 
21
27
  const NOMINAL = new Set(["NOUN", "PROPN"]);
@@ -54,9 +60,12 @@ const clauseBefore = (tokens: readonly Token[], range: TokenRange): boolean => {
54
60
  return before !== undefined && first !== undefined && CLAUSE_END.has(before.pos) && before.surface === before.lemma && before.span.end === first.span.start;
55
61
  };
56
62
 
57
- /** 名前 + 範囲の語 + 最上級(日本で最も・トヨタで最も・東京都で最大)。「費用で最大の効果」の「費用」は名前ではないので範囲にしない。 */
58
- const namedBefore = (tokens: readonly Token[], range: TokenRange, markers: Lexicon): boolean =>
59
- isMarker(tokens[range.start - 1], markers) && isNamed(tokens[range.start - 2]);
63
+ /**
64
+ * 名前 + 範囲の語 + 最上級(日本で最も・トヨタで最も・東京都で最大)。「費用で最大の効果」の「費用」は名前ではないので範囲にしない。
65
+ * 名前でなくても、場や分野を言う名詞(世界で唯一の)は範囲。その名詞は言語パッケージの語彙表 superlative-realm が持つ。
66
+ */
67
+ const namedBefore = (tokens: readonly Token[], range: TokenRange, markers: ScopeMarkers): boolean =>
68
+ isMarker(tokens[range.start - 1], markers.before) && (isNamed(tokens[range.start - 2]) || isMarker(tokens[range.start - 2], markers.realms));
60
69
 
61
70
  const HYPHENS = new Set(["-", "\u2010", "\u2011"]);
62
71
 
@@ -85,14 +94,23 @@ export const phraseEnd = (tokens: readonly Token[], at: number, nounSeen = false
85
94
  }
86
95
  };
87
96
 
88
- /** 最上級 + 名詞句 + 範囲の語 + 名詞句(the best pizza in Chicago・the most famous of the sculptures)。 */
89
- const phraseAfter = (tokens: readonly Token[], range: TokenRange, markers: Lexicon): boolean => {
97
+ const isGerund = (token: Token | undefined): boolean => token?.features?.["VerbForm"] === "Ger";
98
+
99
+ /**
100
+ * 最上級 + 名詞句 + 範囲の語 + 名詞句か動名詞(the best pizza in Chicago・the most famous of the sculptures・the most common
101
+ * form of debunking)。目的の語(for)は動名詞が続くときだけ(the most important tool for creating the culture)。
102
+ * 動名詞は、最上級に名詞が付いているときだけ範囲を言う。名詞の無い the best in helping teams は何の中で一番なのかを言っていない。
103
+ */
104
+ const phraseAfter = (tokens: readonly Token[], range: TokenRange, markers: ScopeMarkers): boolean => {
90
105
  const at = phraseEnd(tokens, range.end);
91
106
  const last = tokens[at - 1];
92
107
  const endsPhrase = at === range.end || (last !== undefined && PHRASE_END.has(last.pos));
93
108
  const opens = tokens[at + 1];
94
- return endsPhrase && isMarker(tokens[at], markers) && opens !== undefined && PHRASE_START.has(opens.pos);
109
+ if (!endsPhrase || opens === undefined) return false;
110
+ const gerund = at > range.end && isGerund(opens);
111
+ const scope = isMarker(tokens[at], markers.after) && (PHRASE_START.has(opens.pos) || gerund);
112
+ return scope || (isMarker(tokens[at], markers.purposes) && gerund);
95
113
  };
96
114
 
97
115
  export const scoped = (tokens: readonly Token[], range: TokenRange, markers: ScopeMarkers): boolean =>
98
- compound(tokens, range) || clauseBefore(tokens, range) || namedBefore(tokens, range, markers.before) || phraseAfter(tokens, range, markers.after);
116
+ compound(tokens, range) || clauseBefore(tokens, range) || namedBefore(tokens, range, markers) || phraseAfter(tokens, range, markers);
@@ -1,9 +1,6 @@
1
- import { proseText } from "../measure.ts";
2
1
  import { joinWords } from "./word-list.ts";
3
- import { wordsOf } from "./structure.ts";
4
- import { nameSpans } from "../team-names.ts";
5
2
  import { conjugatedSpans } from "./conjugated-entry.ts";
6
- import type { Detector, Finding, LexiconEntry, ProseDocument, Sentence, Span, Token } from "../plugin.ts";
3
+ import type { Detector, Finding, LexiconEntry, ProseDocument, Sentence } from "../plugin.ts";
7
4
 
8
5
  /**
9
6
  * チームの言葉。社内でしか通じない語を、チームが chaff.yaml に自分で並べる。
@@ -77,49 +74,3 @@ export const requiredSections: Detector = (doc, options): Finding[] => {
77
74
  },
78
75
  ];
79
76
  };
80
-
81
- const PER = 1000;
82
-
83
- /** 密度を見る rule は短い文書を測らない。単位は言語で違うので床も分ける。 */
84
- const FLOOR = { word: 200, char: 500 };
85
-
86
- const isProperNoun = (token: Token): boolean => token.pos === "PROPN";
87
-
88
- /**
89
- * 固有名詞の密度。製品名・社名・人名が続くと、知らない読者は文の骨組みを見失う。
90
- *
91
- * spec は未知語率としていたが、**品詞解析があれば PROPN を数えるだけで足りる**。
92
- * 辞書を別に持つ必要はない。
93
- */
94
- const within = (spans: readonly Span[], token: Token): Span | undefined => spans.find((span) => token.span.start >= span.start && token.span.end <= span.end);
95
-
96
- /** 並べた名前は、何語に割れても 1 つの固有名詞(Bank of England は 2 つでなく 1 つ)。名前の中の 2 語目からを落とす。 */
97
- const properNounsOf = (sentence: Sentence, names: readonly string[]): Token[] => {
98
- const named = nameSpans(sentence.text, names).map((span) => ({ start: sentence.span.start + span.start, end: sentence.span.start + span.end }));
99
- const counted = new Set<Span>();
100
- return (sentence.tokens ?? []).filter(isProperNoun).filter((token) => {
101
- const name = within(named, token);
102
- if (name === undefined) return true;
103
- if (counted.has(name)) return false;
104
- counted.add(name);
105
- return true;
106
- });
107
- };
108
-
109
- export const properNounDensity: Detector = (doc, options): Finding[] => {
110
- const hits = doc.sentences.flatMap((sentence) => properNounsOf(sentence, doc.names ?? []).map((token) => ({ sentence, token })));
111
- const length = wordsOf(doc);
112
- const rate = length === 0 ? 0 : Math.round((hits.length / length) * PER);
113
- const first = hits[0];
114
- if (length < FLOOR[doc.lengthUnit] || first === undefined || rate <= options.limit) return [];
115
- return [
116
- {
117
- rule: "proper-noun-density",
118
- severity: "info",
119
- line: 0,
120
- column: 0,
121
- quote: proseText(first.sentence),
122
- values: { count: hits.length, density: rate, limit: options.limit, offset: first.token.span.start },
123
- },
124
- ];
125
- };
@@ -0,0 +1,19 @@
1
+ import { oneOf } from "./acronym-name.ts";
2
+
3
+ /**
4
+ * 巻の番号と区分で引く法令集の名前(21 CFR subpart J、21 CFR chapter I、40 CFR subchapter C)。巻の番号の後ろの名前に、
5
+ * 区分の語と、その番号(数字、ローマ数字、1 文字の大文字)が続く形だけ。語は語彙表 citation-series から読む。区分の番号が続かない所
6
+ * (The 2 CFR export was generated)は法令集そのものを言うので、略語のまま数える。
7
+ */
8
+
9
+ type Span = { readonly start: number; readonly end: number };
10
+
11
+ const TITLE_NUMBER = String.raw`(?<![\p{L}\p{N}_.,])\d{1,3}[ \t]+`;
12
+ const DIVISION = String.raw`[ \t]+\p{L}+\.?[ \t]+`;
13
+ const DESIGNATOR = String.raw`(?:\d|[IVXLC]+(?![\p{L}\p{N}])|\p{Lu}(?![\p{L}\p{N}]))`;
14
+
15
+ export const titledCodeSpans = (text: string, series: readonly string[]): Span[] => {
16
+ if (series.length === 0) return [];
17
+ const pattern = new RegExp(String.raw`(?<=${TITLE_NUMBER})${oneOf(series)}(?=${DIVISION}${DESIGNATOR})`, "gu");
18
+ return [...text.matchAll(pattern)].map((match) => ({ start: match.index, end: match.index + match[0].length }));
19
+ };
@@ -1,4 +1,4 @@
1
- import type { Token } from "../plugin.ts";
1
+ import type { Span, Token } from "../plugin.ts";
2
2
  import { quotedSpans } from "../quoted-span.ts";
3
3
 
4
4
  /** 題の付いたものの名前を閉じる語(語彙表 title-ending: 〜要綱、〜試験、〜事業、〜法)。 */
@@ -22,11 +22,16 @@ const surfaceOf = (tokens: readonly Token[]): string => tokens.map((token) => to
22
22
  * 連なりの語(run: 隙間なく並ぶ語)が、題の名前を閉じる語で終わるか。閉じる語は語の切れ目で始まる
23
23
  * (地方自治法の「法」は語、解決方法の「法」は方法の一部)。閉じる語の前に 2 字以上の語が要る。
24
24
  */
25
- export const endsInTitle = (run: readonly Token[], words: TitleWords): boolean =>
26
- run.some((_, at) => {
27
- const tail = surfaceOf(run.slice(at));
28
- return words.endings.includes(tail) && [...surfaceOf(run.slice(0, at))].length >= MIN_BODY_LENGTH;
25
+ export const endsInTitle = (run: readonly Token[], words: TitleWords): boolean => titleBody(run, words) !== undefined;
26
+
27
+ /** endsInTitle のときの、閉じる語の前の字(愛玩動物看護師法の「愛玩動物看護師」)。閉じなければ undefined。 */
28
+ export const titleBody = (run: readonly Token[], words: TitleWords): string | undefined => {
29
+ const at = run.findIndex((_, index) => {
30
+ const tail = surfaceOf(run.slice(index));
31
+ return words.endings.includes(tail) && [...surfaceOf(run.slice(0, index))].length >= MIN_BODY_LENGTH;
29
32
  });
33
+ return at < 0 ? undefined : surfaceOf(run.slice(0, at));
34
+ };
30
35
 
31
36
  /**
32
37
  * 文(text)の start から end までの連なりが、題の名前の置き方をしているか。
@@ -55,3 +60,15 @@ export const repeatedRuns = (runs: readonly string[]): Set<string> => {
55
60
  const counts = runs.reduce((seen, run) => seen.set(run, (seen.get(run) ?? 0) + 1), new Map<string, number>());
56
61
  return new Set([...counts].flatMap(([run, count]) => (count >= MIN_REPEATS ? [run] : [])));
57
62
  };
63
+
64
+ /**
65
+ * 連なりを含む括弧(brackets: 中身の範囲、文書全体の座標)のどれかが、法令の題(「〜に関する法律」、(〜法))か。
66
+ * 中身の語(tokens のうち括弧の中のもの)が法令の名前を閉じる語(fixedName)で終われば題。題は、中の語ごと変えられない名前。
67
+ */
68
+ export const inStatuteTitle = (tokens: readonly Token[], brackets: readonly Span[], fixedName: TitleWords): boolean =>
69
+ brackets.some((bracket) =>
70
+ endsInTitle(
71
+ tokens.filter((token) => bracket.start <= token.span.start && token.span.end <= bracket.end),
72
+ fixedName,
73
+ ),
74
+ );
@@ -6,6 +6,7 @@ import type { Detector, Finding, Span, Token } from "../plugin.ts";
6
6
  import { countedTokens, uncountedWordsOf, type UncountedWords } from "../uncounted-particles.ts";
7
7
  import { honorificGroupParticles } from "../honorific-group.ts";
8
8
  import { noteSentences } from "../note-paragraphs.ts";
9
+ import { documentNameSpans } from "./particle-run-names.ts";
9
10
 
10
11
  /**
11
12
  * 文末が名詞で終わる(体言止め)。箇条書きでは普通だが、本文では文が途中で切れて読める。
@@ -64,6 +65,12 @@ const PARTICLE = new Set(["ADP", "SCONJ", "PART", "CCONJ"]);
64
65
 
65
66
  const BREAK: Run = { surface: "", tokens: [] };
66
67
 
68
+ /** 括弧だけの語。解析器が括弧の続き(「分析】(1)経営成績」の「】(」)を名詞と読んでも、句読点と同じく句を閉じる。%や半角の・は句を閉じない。 */
69
+ const BRACKETS_ONLY = /^[\p{Ps}\p{Pe}]+$/u;
70
+
71
+ const breaksRun = (token: Token, breaks: readonly string[]): boolean =>
72
+ token.pos === "PUNCT" || PARTICLE.has(token.pos) || breaks.includes(token.surface) || BRACKETS_ONLY.test(token.surface);
73
+
67
74
  /**
68
75
  * 名詞は連なりの中身なので飛ばす。読点と、語彙表に無い助詞は連なりを切る。
69
76
  * 「弊社のAはBの」を 2 回続いたと数えないため。「は」でいちど句が閉じている。
@@ -76,7 +83,7 @@ const runsOf = (tokens: readonly Token[], nesting: readonly string[], breaks: re
76
83
  tokens.reduce<Run[]>((acc, token) => {
77
84
  if (isWithinAny(quoted, token.span)) return acc;
78
85
  if (nesting.includes(token.surface)) return extend(acc, token);
79
- if (token.pos === "PUNCT" || PARTICLE.has(token.pos) || breaks.includes(token.surface)) acc.push(BREAK);
86
+ if (breaksRun(token, breaks)) acc.push(BREAK);
80
87
  return acc;
81
88
  }, []);
82
89
 
@@ -99,16 +106,21 @@ export const doubledParticle: Detector = (doc, options): Finding[] => {
99
106
  const breaks = (doc.lexicons[RUN_BREAK_LEXICON] ?? []).map((entry) => entry.pattern);
100
107
  const numbering = uncountedWordsOf(doc.lexicons, nesting);
101
108
  const groups = (doc.lexicons[HONORIFIC_GROUP_LEXICON] ?? []).map((entry) => entry.pattern);
102
- return doc.sentences.flatMap((sentence) =>
103
- runsOf(chainTokens(sentence.tokens ?? [], numbering, groups), nesting, breaks, [...quotedIn(sentence), ...titles])
104
- .filter((run) => run.tokens.length > options.limit)
105
- .map((run) => ({
106
- rule: "no-doubled-joshi",
107
- severity: "warning" as const,
108
- line: 0,
109
- column: 0,
110
- quote: sentence.text.trim(),
111
- values: { word: run.surface, count: run.tokens.length, limit: options.limit, offset: run.tokens[0]?.span.start ?? sentence.span.start },
112
- })),
113
- );
109
+ const prose = doc.prose ?? doc.source;
110
+ return doc.sentences.flatMap((sentence) => {
111
+ const tokens = chainTokens(sentence.tokens ?? [], numbering, groups);
112
+ const quoted = [...quotedIn(sentence), ...titles];
113
+ const longRuns = (skipped: readonly Span[]): Run[] => runsOf(tokens, nesting, breaks, skipped).filter((run) => run.tokens.length > options.limit);
114
+ const found = longRuns(quoted);
115
+ // 文書の名前を読むのは長い連なりのある文だけ。名前は位置ごとに読むので、全部の文で読むと遅い。
116
+ const runs = found.length === 0 ? found : longRuns([...quoted, ...documentNameSpans(prose, sentence.span, doc.namedDocument)]);
117
+ return runs.map((run) => ({
118
+ rule: "no-doubled-joshi",
119
+ severity: "warning" as const,
120
+ line: 0,
121
+ column: 0,
122
+ quote: sentence.text.trim(),
123
+ values: { word: run.surface, count: run.tokens.length, limit: options.limit, offset: run.tokens[0]?.span.start ?? sentence.span.start },
124
+ }));
125
+ });
114
126
  };
@@ -0,0 +1,25 @@
1
+ import type { Detector, ProseDocument, Sentence } from "../plugin.ts";
2
+ import { topicDistance } from "../sentence-load.ts";
3
+ import type { TopicClauseWords } from "../topic-clause.ts";
4
+ import { isIn } from "../lexicon-genres.ts";
5
+ import { overLimit, ownTokens } from "./sentence-load.ts";
6
+
7
+ const CLOSER_LEXICON = "topic-clause-close";
8
+ const ARTICLE_LEXICON = "statute-article-opener";
9
+
10
+ /**
11
+ * Whether the sentence is an article of a statute quoted in another kind of document (第7条 … in a manual): the law's wording,
12
+ * which the writer cannot change. In a statute or a contract (its genre, or a profile chaff reads it by) the articles are its own.
13
+ */
14
+ const quotesArticle = (doc: ProseDocument, genre: string | undefined): ((sentence: Sentence) => boolean) => {
15
+ if (doc.profile !== undefined || genre === undefined || isIn(genre, "legal")) return () => false;
16
+ const openers = (doc.lexicons[ARTICLE_LEXICON] ?? []).map((entry) => new RegExp(entry.pattern, "u"));
17
+ return (sentence) => openers.some((opener) => opener.test(sentence.text.trimStart()));
18
+ };
19
+
20
+ /** The distance from the sentence's topic (〜は) to the end, where its predicate is. Needs the language's tokens. */
21
+ export const topicPredicateDistance: Detector = (doc, options) => {
22
+ const words: TopicClauseWords = { closers: (doc.lexicons[CLOSER_LEXICON] ?? []).map((entry) => entry.pattern) };
23
+ const quoted = quotesArticle(doc, options.genre);
24
+ return overLimit((sentence) => (sentence.tokens === undefined || quoted(sentence) ? undefined : topicDistance(ownTokens(sentence), words)))(doc, options);
25
+ };
@@ -0,0 +1,112 @@
1
+ // Where a word stands, for unknown-word: places in a document where a word not in the dictionary is a name or a term the
2
+ // writer means as written, not a slip. Pure functions over the Markdown source and an offset into it.
3
+ import { isAddress, isKnownWord, stemsOf, type CheckedWord, type Speller } from "../spelling.ts";
4
+
5
+ /** Each half of a closed compound keeps this many letters: a shorter half (open + end, pip + line) is more often a slip at the joint. */
6
+ const MIN_COMPOUND_PART = 4;
7
+
8
+ /**
9
+ * Two dictionary words of four letters or more written as one (crowdwork, crowdworkers): a closed compound, not a slip. The
10
+ * head is a word as listed and the tail takes only an inflection: a prefix or a derived ending on a half (misre + presenation)
11
+ * reads too many slips as words.
12
+ */
13
+ export const isClosedCompound = (word: string, speller: Speller): boolean => {
14
+ const listed: Speller = { ...speller, suffixes: [], prefixes: [] };
15
+ const inflected: Speller = { ...listed, suffixes: speller.suffixes.filter(({ inflection }) => inflection === true) };
16
+ return [...Array(Math.max(0, word.length - 2 * MIN_COMPOUND_PART + 1)).keys()]
17
+ .map((index) => index + MIN_COMPOUND_PART)
18
+ .some((split) => isKnownWord(word.slice(0, split), listed) && isKnownWord(word.slice(split), inflected));
19
+ };
20
+
21
+ /** Letters a name keeps before its drug stem: fewer, and the word is too short to be read as a drug by its ending alone. */
22
+ const MIN_DRUG_HEAD = 3;
23
+
24
+ /** A drug's international name, read by its stem (paroxetine by -oxetine, as fluoxetine): stems from the drug-stem lexicon. */
25
+ export const hasDrugStem = (word: string, stems: readonly string[]): boolean =>
26
+ stems.some((stem) => word.endsWith(stem) && word.length >= stem.length + MIN_DRUG_HEAD);
27
+
28
+ /** How far back or ahead to look for a neighbouring word or a search stem. */
29
+ const NEIGHBOUR_REACH = 40;
30
+
31
+ const CLOSER: Readonly<Record<string, string>> = { '"': '"', "“": "”", "(": ")" };
32
+
33
+ /** The word alone between quotes or brackets ("mailto", (jchaplin)): a word the writer names as such, or an account handle. */
34
+ export const isMention = (source: string, offset: number, word: string): boolean => {
35
+ const closer = CLOSER[source.charAt(offset - 1)];
36
+ return closer !== undefined && source.charAt(offset + word.length) === closer;
37
+ };
38
+
39
+ /**
40
+ * A search stem with a wildcard in a list of terms (ukrain*, vaccin*): the word ends in a * that closes no emphasis
41
+ * (nothing opens one before the word), and a separator or the line's end follows it, not a word as after a footnote's *.
42
+ */
43
+ export const isSearchStem = (source: string, offset: number, word: string): boolean => {
44
+ const end = offset + word.length;
45
+ return source[end] === "*" && source[offset - 1] !== "*" && /^[ \t]*(?:[,;|)\]]|\r?\n|$)/u.test(source.slice(end + 1));
46
+ };
47
+
48
+ const LETTER = /\p{L}/u;
49
+
50
+ /** The stem a * at index of source closes: the letters right before it, or "" when none come before. */
51
+ const stemBefore = (source: string, index: number): string => {
52
+ const head = Array.from(source.slice(Math.max(0, index - NEIGHBOUR_REACH), index));
53
+ return head.slice(head.findLastIndex((character) => !LETTER.test(character)) + 1).join("");
54
+ };
55
+
56
+ /** The word stands in a line with a search stem (president, maga, biden, democrat*): every item of that list is a term. */
57
+ export const inSearchTermList = (source: string, offset: number): boolean => {
58
+ const start = source.lastIndexOf("\n", offset - 1) + 1;
59
+ const end = source.indexOf("\n", offset);
60
+ const line = source.slice(start, end === -1 ? source.length : end);
61
+ return [...line.matchAll(/\*/gu)].some((star) => {
62
+ const stem = stemBefore(source, start + star.index);
63
+ return stem !== "" && isSearchStem(source, start + star.index - stem.length, stem);
64
+ });
65
+ };
66
+
67
+ /** A Latin letter outside English's a–z (ê, é, ñ, ß): a word of another language. */
68
+ const isForeignWord = (token: string): boolean => [...token].some((letter) => letter > "\u007f" && /\p{Script=Latin}/u.test(letter));
69
+
70
+ const SPACE = /\s/u;
71
+
72
+ /** The last space-separated token of text when a space ends it ("old bête " gives "bête"), or "". */
73
+ const lastToken = (text: string): string => (SPACE.test(text.at(-1) ?? "") ? (text.trimEnd().split(SPACE).at(-1) ?? "") : "");
74
+
75
+ /** The first space-separated token of text when a space starts it (" noire for" gives "noire"), or "". */
76
+ const firstToken = (text: string): string => (SPACE.test(text.charAt(0)) ? (text.trimStart().split(SPACE)[0] ?? "") : "");
77
+
78
+ /** The word stands beside a word of another language written in Latin letters (bête noire): it belongs to that phrase. */
79
+ export const besideForeignWord = (source: string, offset: number, word: string): boolean => {
80
+ const end = offset + word.length;
81
+ return (
82
+ isForeignWord(lastToken(source.slice(Math.max(0, offset - NEIGHBOUR_REACH), offset))) || isForeignWord(firstToken(source.slice(end, end + NEIGHBOUR_REACH)))
83
+ );
84
+ };
85
+
86
+ /** The letters of every URL and email address in the source, lower-cased: a word also in an address names what it points at. */
87
+ export const addressWordsOf = (source: string): Set<string> =>
88
+ new Set((source.match(/\S+/gu) ?? []).filter(isAddress).flatMap((chunk) => chunk.toLowerCase().match(/\p{L}+/gu) ?? []));
89
+
90
+ const countsOf = (keys: readonly string[]): Map<string, number> => {
91
+ const counts = new Map<string, number>();
92
+ keys.forEach((key) => counts.set(key, (counts.get(key) ?? 0) + 1));
93
+ return counts;
94
+ };
95
+
96
+ /**
97
+ * The word and its stems, the forms another word of its family shares (rightsized and rightsizing share rightsize), for a
98
+ * word the dictionary does not know. A known word is in no such family: "refactored" does not make "refactore" a form of
99
+ * it, nor "tools" "toolss".
100
+ */
101
+ const familyOf = (word: string, speller: Speller): string[] => (isKnownWord(word, speller) ? [] : [...new Set([word, ...stemsOf(word, speller)])]);
102
+
103
+ /**
104
+ * Words the document uses once, counting a word's other forms as uses (rightsize, rightsized, rightsizing): a word used
105
+ * twice or more, in any form, is more often the document's own term than a slip.
106
+ */
107
+ export const usedOnce = (words: readonly CheckedWord[], speller: Speller): CheckedWord[] => {
108
+ const uses = countsOf(words.map(({ word }) => word));
109
+ const families = new Map([...uses.keys()].map((word) => [word, familyOf(word, speller)]));
110
+ const shared = countsOf([...families.values()].flat());
111
+ return words.filter(({ word }) => uses.get(word) === 1 && (families.get(word) ?? []).every((key) => shared.get(key) === 1));
112
+ };