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
@@ -0,0 +1,86 @@
1
+ // Whether a list goes on past an and / or. Then that and / or is inside an item, not the list's last joint, and it casts no
2
+ // vote on the serial comma. Pure.
3
+ import { hasAdposition, hasVerb, isClause, itemAfter, leadShape } from "./list-item.ts";
4
+ import { isListConjunction, type ItemScope } from "./list-sentence.ts";
5
+ import type { TokenRange } from "./token-column.ts";
6
+
7
+ /**
8
+ * and の後ろの項目のあとも同じ並びが続くなら、この and は項目の中にある。読点ごとに同じ頭の形で動詞の無い項目を読み進め、
9
+ * 同じ形の項目を連れた and / or に着けば並びの最後の継ぎ目はそちら(searches and seizures, and the Eighth's ban /
10
+ * homeownership counseling and financial literacy, commercial conversions to housing, and support for manufactured housing)。
11
+ * and / or に着かずにダッシュかセミコロンで閉じれば、and / or の無い並びの項目の中(interests—psychological integrity,
12
+ * autonomous judgment, time and attention, emotional investment—that)。文の終わりで閉じるのは並びのあとの同格
13
+ * (apples, pears and plums, the fruit we sell)とも、コロンで閉じるのは題名の副題とも読めるので、続きと読まない。
14
+ * 途中の項目を挟まずに and / or が続き、頭の形か節かどうかが違えば、別の節をつなぐ and で、この and までが並び
15
+ * (apples, pears and plums, and went home / and figs fell)。
16
+ */
17
+ const ENCLOSING_BREAK: ReadonlySet<string> = new Set(["—", ";"]);
18
+
19
+ /** 位置 end の記号が、and / or と同じ深さの読点か。 */
20
+ const levelComma = (scope: ItemScope, end: number): boolean => scope.sentence.tokens[end]?.surface === "," && scope.sentence.depths[end] === scope.level;
21
+
22
+ /** 項目の語を小文字でつないだもの。読点や引用符は除く。 */
23
+ const wordsOf = (scope: ItemScope, item: TokenRange): string =>
24
+ scope.sentence.tokens
25
+ .slice(item.start, item.end)
26
+ .filter((token) => token.pos !== "PUNCT" && token.pos !== "X")
27
+ .map((token) => token.surface.toLowerCase())
28
+ .join(" ");
29
+
30
+ /** 並びの残りを言う語だけの項目(and so forth / or the like)。 */
31
+ const endsOpenList = (scope: ItemScope, item: TokenRange): boolean => scope.sentence.words.openListEnd?.has(wordsOf(scope, item)) ?? false;
32
+
33
+ /**
34
+ * 読点のあとに、頭の形が shape の and / or の項目か、並びの残りを言う語(and so forth)が来るか。and / or が来なければ undefined。
35
+ */
36
+ const conjunctionAfter = (scope: ItemScope, end: number, shape: string): boolean | undefined => {
37
+ if (!isListConjunction(scope.sentence.tokens[end + 1])) return undefined;
38
+ const following = itemAfter(scope, end + 1);
39
+ return leadShape(scope, following) === shape || endsOpenList(scope, following);
40
+ };
41
+
42
+ const QUOTE_MARKS: ReadonlySet<string> = new Set(['"', "“", "”", "'", "‘", "’"]);
43
+
44
+ /** 読点の後ろの項目が引用符で始まる。引用した題名の始まりで、並びの続きではない(Bundick, Cairó, and Petrosky-Nadeau (2025), "Labor Market Dynamics, …)。 */
45
+ const opensQuotation = (scope: ItemScope, comma: number): boolean => QUOTE_MARKS.has(scope.sentence.tokens[comma + 1]?.surface ?? "");
46
+
47
+ /** 読点 start から、頭の形が shape で動詞の無い項目を 1 つ以上読み進めた先の答え。 */
48
+ export type Walk = (scope: ItemScope, start: number, shape: string) => boolean;
49
+
50
+ /** 1 つの文の Walk。and / or ごとに同じ読点を読み直すと語数の二乗になるので、通った読点の答えを覚える。 */
51
+ export const walker = (): Walk => {
52
+ const known = new Map<string, boolean>();
53
+ const keyOf = (scope: ItemScope, end: number, shape: string): string => `${String(scope.level)}:${String(end)}:${shape}`;
54
+ return (scope, start, shape) => {
55
+ const passed: number[] = [];
56
+ let end = start;
57
+ let answer: boolean | undefined;
58
+ while (answer === undefined) {
59
+ const next = itemAfter(scope, end);
60
+ passed.push(end);
61
+ answer = known.get(keyOf(scope, end, shape));
62
+ if (answer !== undefined) break;
63
+ if (leadShape(scope, next) !== shape || hasVerb(scope, next) || opensQuotation(scope, end)) answer = false;
64
+ else if (!levelComma(scope, next.end)) answer = ENCLOSING_BREAK.has(scope.sentence.tokens[next.end]?.surface ?? "");
65
+ else answer = conjunctionAfter(scope, next.end, shape);
66
+ end = next.end;
67
+ }
68
+ const settled = answer;
69
+ passed.forEach((comma) => known.set(keyOf(scope, comma, shape), settled));
70
+ return settled;
71
+ };
72
+ };
73
+
74
+ /**
75
+ * 項目を挟んで読み進めるのは、and の後ろが前置詞も動詞も連れない短い項目のときだけ。長い項目の尻からは次の並びが始まりうる
76
+ * (the duties of loyalty, care, good faith, and candour into criteria governing engagement optimisation, aggregate harm
77
+ * monitoring, and revision authority は 2 つの並び)。
78
+ */
79
+ export const listContinues = (scope: ItemScope, afterItem: TokenRange, walk: Walk): boolean => {
80
+ const shape = leadShape(scope, afterItem);
81
+ if (shape === undefined || !levelComma(scope, afterItem.end)) return false;
82
+ const following = conjunctionAfter(scope, afterItem.end, shape);
83
+ const next = itemAfter(scope, afterItem.end + 1);
84
+ if (following !== undefined) return following && (endsOpenList(scope, next) || isClause(scope, next) === isClause(scope, afterItem));
85
+ return !hasAdposition(scope, afterItem) && !hasVerb(scope, afterItem) && walk(scope, afterItem.end, shape);
86
+ };
@@ -18,6 +18,16 @@ export type ListWords = {
18
18
  readonly sequence?: ReadonlySet<string>;
19
19
  /** 番号を付けて呼ぶ法典の区分(title, chapter)。Title 44, Public Printing and Documents の読点は区分の名前を続ける読点。 */
20
20
  readonly unit?: ReadonlySet<string>;
21
+ /** 文頭で前の文とつなぐ一語(However, / Therefore,)。順番の語と同じく導入の語。 */
22
+ readonly connective?: ReadonlySet<string>;
23
+ /** 節だけをつなぐ接続詞(but / yet)。これで始まる項目は並びの項目ではなく、並びはその後ろから。 */
24
+ readonly clauseConjunction?: ReadonlySet<string>;
25
+ /** 不定冠詞(a / an)。冠詞と形容詞だけの項目(a simple)は、次の名詞にかかる語。 */
26
+ readonly indefinite?: ReadonlySet<string>;
27
+ /** 引用の中の省略の印(... / * * *)。省略を示す引用はほかの文書の抜き書き。 */
28
+ readonly elision?: readonly string[];
29
+ /** 並びの残りを言う語(so forth / the like)。and so forth の前まで並びが続く。 */
30
+ readonly openListEnd?: ReadonlySet<string>;
21
31
  };
22
32
 
23
33
  const LIST_CONJUNCTION: ReadonlySet<string> = new Set(["and", "or"]);
@@ -116,6 +126,7 @@ const columnsOf = (tokens: readonly Token[], depths: readonly number[]) => {
116
126
  verbal: of((token) => VERBAL.has(token.pos)),
117
127
  adposition: of((token) => token.pos === "ADP"),
118
128
  determiner: of((token) => token.pos === "DET"),
129
+ adjective: of((token) => token.pos === "ADJ"),
119
130
  conjunction: of((token) => LIST_CONJUNCTION.has(token.surface.toLowerCase())),
120
131
  gerund: of((token) => verbFormOf(token) === "Ger"),
121
132
  participle: of((token) => verbFormOf(token) === "Part"),
@@ -5,10 +5,11 @@ import { minorityReport } from "../spacing-minority.ts";
5
5
  import { externalLinkTitleSpans } from "../link-title.ts";
6
6
  import { formulaBracketSpans } from "../formula-brackets.ts";
7
7
  import { isWithinAny, quotedSpans } from "../quoted-span.ts";
8
- import { capitalLineSpans, captionsOf, isCaptionAt, isWithinSorted } from "./caps-caption.ts";
8
+ import { bracketPlaceholderSpans, capitalLineSpans, captionsOf, isCaptionAt, isWithinSorted } from "./caps-caption.ts";
9
9
  import { lineStarts } from "../position.ts";
10
10
  import { isTypewritten } from "./typewritten.ts";
11
11
  import { divisionLabelPattern, isDivisionSeparator } from "./division-label-separator.ts";
12
+ import { isInCopiedText } from "./hyphen-copied-text.ts";
12
13
 
13
14
  /** The letters a mark must touch to count as part of the document's text, by language. */
14
15
  const SCRIPT: Readonly<Record<string, RegExp>> = {
@@ -257,7 +258,9 @@ export const hyphenDash: Detector = (doc, options): Finding[] => {
257
258
  const setsDashes = sentences.some((sentence) => TRUE_DASH.test(sentence.text));
258
259
  const divisionLabel = divisionLabelPattern((doc.lexicons["numbered-division"] ?? []).map((entry) => entry.pattern));
259
260
  return reportFrom(
260
- hitsOf(sentences, HYPHEN_DASH).filter((hit) => !isTypedDash(hit, setsDashes) && !isDivisionSeparator(doc.source, hit.offset, divisionLabel)),
261
+ hitsOf(sentences, HYPHEN_DASH).filter(
262
+ (hit) => !isTypedDash(hit, setsDashes) && !isDivisionSeparator(doc.source, hit.offset, divisionLabel) && !isInCopiedText(doc.source, hit.offset),
263
+ ),
261
264
  options.limit,
262
265
  );
263
266
  };
@@ -310,17 +313,19 @@ export const isShouting = (run: string, known: ReadonlySet<string>, conventional
310
313
 
311
314
  /**
312
315
  * Runs of three or more all-capital words that are ordinary words, not acronyms ("DO NOT DELETE THIS"), and not a
313
- * caption, a mention of one, a paragraph of capital lines that ends no sentence (a letterhead, a heading), or a roster name.
316
+ * caption, a mention of one, a paragraph of capital lines that ends no sentence (a letterhead, a heading), a roster name, or a
317
+ * placeholder in square brackets.
314
318
  */
315
319
  export const capsShouting: Detector = (doc, options): Finding[] => {
316
320
  const known = lowerCaseWords(doc.prose ?? doc.source);
317
321
  const conventional = new Set((options.lexicon ?? []).map((entry) => entry.pattern));
318
322
  const captions = captionsOf(doc.source);
319
323
  const capitalLines = capitalLineSpans(doc.source);
320
- const isCaptionOrLetterhead = (hit: Hit): boolean =>
321
- captions.has(hit.matched) ||
322
- isCaptionAt(doc.source, hit.offset, hit.offset + hit.matched.length) ||
323
- isWithinSorted(capitalLines, { start: hit.offset, end: hit.offset + hit.matched.length });
324
+ const placeholders = bracketPlaceholderSpans(doc.source);
325
+ const isCaptionOrLetterhead = (hit: Hit): boolean => {
326
+ const span = { start: hit.offset, end: hit.offset + hit.matched.length };
327
+ return captions.has(hit.matched) || isCaptionAt(doc.source, span.start, span.end) || isWithinSorted(capitalLines, span) || isWithinAny(placeholders, span);
328
+ };
324
329
  const hits = hitsOf(ownSentences(doc), CAPS_RUN).filter((hit) => isShouting(hit.matched, known, conventional) && !isCaptionOrLetterhead(hit));
325
330
  return reportFrom(hits, options.limit);
326
331
  };
@@ -3,7 +3,8 @@ import type { Token } from "../plugin.ts";
3
3
  const nameType = (token: Token | undefined): string | undefined => token?.features?.["NameType"];
4
4
 
5
5
  /** 人の姓と名(田中太郎)。姓が 2 つ続けば(田中山田)、名前の並び。 */
6
- const isFullName = (named: readonly (Token | undefined)[]): boolean => named.length === 2 && nameType(named[0]) === "Sur" && nameType(named[1]) === "Giv";
6
+ export const isFullName = (named: readonly (Token | undefined)[]): boolean =>
7
+ named.length === 2 && nameType(named[0]) === "Sur" && nameType(named[1]) === "Giv";
7
8
 
8
9
  /**
9
10
  * 漢字の連なりの語(covering: tokens の添字)が 1 つの名前か。辞書が固有名詞と読む 1 語(日本銀行)か、人の姓と名。
@@ -0,0 +1,136 @@
1
+ import type { ProseDocument, Span, Token } from "../plugin.ts";
2
+ import { escapeRegExp } from "../orthography.ts";
3
+ import { isKnownWord, type Speller } from "../spelling.ts";
4
+ import { isInverseOrder, isListedPair, isOtherEnding, type WordEnding } from "../name-variant-shapes.ts";
5
+ import { titleSlipsIn } from "../name-title-slip.ts";
6
+
7
+ // name-variant が、似た二つの形を一つの名前の書き分けではなく別の二つと見る所。中黒で並べた二つの語、ある向きとその逆、語の別の
8
+ // 形(Texan と Texas)、同じ文に並べた一字違いの二つの名前、文書が二度以上使う名前の語、文や行の頭で大文字になったふつうの語、
9
+ // 引用した題の大文字、動詞の語幹。
10
+
11
+ /** A finding before it is rendered: where, the pointed form, the usual form and how they differ. */
12
+ export type Found = { readonly offset: number; readonly name: string; readonly usual: string; readonly kind: string };
13
+
14
+ const patternsOf = (doc: ProseDocument, id: string): string[] => (doc.lexicons[id] ?? []).map((entry) => entry.pattern);
15
+
16
+ const wordEndingsOf = (doc: ProseDocument): WordEnding[] =>
17
+ (doc.lexicons["name-word-ending"] ?? []).flatMap((entry) => (entry.instead_of === undefined ? [] : [{ ending: entry.pattern, insteadOf: entry.instead_of }]));
18
+
19
+ /** Where a whole word or name is written, as written. */
20
+ const offsetsOf = (text: string, surface: string): number[] =>
21
+ [...text.matchAll(new RegExp(`(?<![\\p{L}\\p{N}])${escapeRegExp(surface)}(?![\\p{L}\\p{N}])`, "gu"))].map((found) => found.index ?? 0);
22
+
23
+ /** The word in which a one-letter variant differs from its usual form. */
24
+ const differingWord = (name: string, usual: string): string | undefined => {
25
+ const [words, others] = [name.split(/\s+/u), usual.split(/\s+/u)];
26
+ return words.find((word, index) => word !== others[index]);
27
+ };
28
+
29
+ /** Marks a line may start with before its first word (indent, quote, list, heading). */
30
+ const LINE_MARKS = /^[ \t>*#+-]*$/u;
31
+
32
+ const startsLine = (text: string, offset: number): boolean => LINE_MARKS.test(text.slice(text.lastIndexOf("\n", offset - 1) + 1, offset));
33
+ const ONE_WORD = /^\p{L}+$/u;
34
+
35
+ /**
36
+ * Whether a one-word form stands where any word takes a capital, at the start of a sentence or of a line (a verse line),
37
+ * the form is a dictionary word in small letters, and the tagger reads the usual form as an ordinary word too (Sprang beside
38
+ * Spring): two words, not a name. A usual form the tagger reads as a name only (Friedman) keeps its slips (Freedman).
39
+ */
40
+ const isCapitalisedByPlace = (
41
+ found: Found,
42
+ text: string,
43
+ sentenceStarts: ReadonlySet<number>,
44
+ speller: Speller | undefined,
45
+ ordinary: ReadonlySet<string>,
46
+ ): boolean =>
47
+ speller !== undefined &&
48
+ ONE_WORD.test(found.name) &&
49
+ (sentenceStarts.has(found.offset) || startsLine(text, found.offset)) &&
50
+ isKnownWord(found.name.toLowerCase(), speller) &&
51
+ ordinary.has(found.usual.toLowerCase());
52
+
53
+ /** A word of three capitals or more: a title set in capitals as published (TRIDENT). */
54
+ const CAPITALS_WORD = /(?<!\p{L})\p{Lu}{3,}(?!\p{L})/u;
55
+ const QUOTES = /["“”]/gu;
56
+
57
+ /** Whether a case-only variant holding a word in capitals stands inside quotation marks on its line: a cited title as published. */
58
+ const isQuotedTitleCase = (found: Found, text: string): boolean => {
59
+ if (found.name.toLowerCase() !== found.usual.toLowerCase() || !CAPITALS_WORD.test(found.name)) return false;
60
+ const lineStart = text.lastIndexOf("\n", found.offset) + 1;
61
+ const before = text.slice(lineStart, found.offset);
62
+ const lineEnd = text.indexOf("\n", found.offset);
63
+ const after = text.slice(found.offset + found.name.length, lineEnd < 0 ? text.length : lineEnd);
64
+ return (before.match(QUOTES)?.length ?? 0) % 2 === 1 && (after.match(QUOTES)?.length ?? 0) > 0;
65
+ };
66
+
67
+ /** Whether a Japanese name is followed at once by an auxiliary that does not follow names (咲けり の けり): a verb stem, not a name. */
68
+ const isVerbStem = (found: Found, tokenAt: ReadonlyMap<number, Token>, copulas: ReadonlySet<string>): boolean => {
69
+ const next = tokenAt.get(found.offset + found.name.length);
70
+ return copulas.size > 0 && next?.pos === "AUX" && !copulas.has(next.surface);
71
+ };
72
+
73
+ /** What the checks read from the document, built once. */
74
+ type Reading = {
75
+ readonly text: string;
76
+ readonly sentences: readonly Span[];
77
+ readonly sentenceStarts: ReadonlySet<number>;
78
+ readonly endings: readonly WordEnding[];
79
+ readonly directions: readonly string[];
80
+ readonly copulas: ReadonlySet<string>;
81
+ readonly tokenAt: ReadonlyMap<number, Token>;
82
+ readonly speller: Speller | undefined;
83
+ readonly ordinary: ReadonlySet<string>;
84
+ };
85
+
86
+ const inOneSentence = (sentences: readonly Span[], offset: number, other: number): boolean =>
87
+ sentences.some((span) => span.start <= offset && offset < span.end && span.start <= other && other < span.end);
88
+
89
+ /**
90
+ * A one-letter variant (near) that is two names: another form of the word (Texan), the usual form in the same sentence
91
+ * (Constantinus and Constantius, two sons), the differing word written twice or more (Bandle, of Richard Bandle and
92
+ * Mrs. Bandle), or a word capitalised by its place (Sprang).
93
+ */
94
+ const isNearPair = (reading: Reading, found: Found): boolean => {
95
+ const word = differingWord(found.name, found.usual);
96
+ return (
97
+ isOtherEnding(found.name, found.usual, reading.endings) ||
98
+ offsetsOf(reading.text, found.usual).some((offset) => inOneSentence(reading.sentences, found.offset, offset)) ||
99
+ (word !== undefined && offsetsOf(reading.text, word).length >= 2) ||
100
+ isCapitalisedByPlace(found, reading.text, reading.sentenceStarts, reading.speller, reading.ordinary)
101
+ );
102
+ };
103
+
104
+ /**
105
+ * The finding is not two forms of one name: a one-letter variant that is two names (isNearPair), ・ listing two words, a
106
+ * direction and its inverse, a title quoted in capitals, a verb stem. ordinary holds the words read as names that are
107
+ * ordinary words in small letters (name-ordinary-word.ts).
108
+ */
109
+ export const twoThingsIn = (
110
+ doc: ProseDocument,
111
+ tokens: readonly Token[],
112
+ speller: Speller | undefined,
113
+ ordinary: ReadonlySet<string>,
114
+ ): ((found: Found) => boolean) => {
115
+ const reading: Reading = {
116
+ text: doc.prose ?? doc.source,
117
+ sentences: doc.sentences.map((sentence) => sentence.span),
118
+ sentenceStarts: new Set(doc.sentences.flatMap((sentence) => sentence.tokens?.[0]?.span.start ?? [])),
119
+ endings: wordEndingsOf(doc),
120
+ directions: patternsOf(doc, "name-direction-word"),
121
+ copulas: new Set(patternsOf(doc, "name-copula")),
122
+ tokenAt: new Map(tokens.map((token) => [token.span.start, token])),
123
+ speller,
124
+ ordinary,
125
+ };
126
+ return (found) =>
127
+ (found.kind === "near" && isNearPair(reading, found)) ||
128
+ isListedPair(found.name, found.usual) ||
129
+ (found.kind === "order" && isInverseOrder(found.name, found.usual, reading.directions)) ||
130
+ isQuotedTitleCase(found, reading.text) ||
131
+ (found.kind === "reading" && isVerbStem(found, reading.tokenAt, reading.copulas));
132
+ };
133
+
134
+ /** A title written once with one word a letter away from a title written twice or more (name-title-slip.ts). heads ends a title. */
135
+ export const titleFindingsOf = (text: string, heads: readonly string[]): Found[] =>
136
+ titleSlipsIn(text, heads).map(({ offset, surface, usual }) => ({ offset, name: surface, usual, kind: "title" }));
@@ -1,6 +1,5 @@
1
1
  import type { Detector, Finding, ProseDocument } from "../plugin.ts";
2
2
  import { cuedNamesIn, mentionsIn, nameVariants, suffixedNamesIn, type NameMention, type VariantChars } from "../name-variants.ts";
3
- import type { WordUse } from "../name-end-letter.ts";
4
3
  import { withKnownNeighbours } from "../name-neighbours.ts";
5
4
  import type { SpellingInput } from "../name-spelling-chars.ts";
6
5
  import { lookalikeSlipsIn, type LookalikeChars } from "../name-lookalike-chars.ts";
@@ -27,6 +26,9 @@ import { isGroupPairOf, notDefinedTerms, outsideCapitals, sentenceIndexOf, withG
27
26
  import { isDictionaryPair } from "../name-word-form.ts";
28
27
  import { spellerOf } from "./unknown-word.ts";
29
28
  import { notAnotherAuthorIn } from "./name-variant-reference-list.ts";
29
+ import { titleFindingsOf, twoThingsIn } from "./name-variant-two-things.ts";
30
+ import { isSetInCapitals } from "../name-variant-shapes.ts";
31
+ import { wordUseOf } from "../name-word-use.ts";
30
32
 
31
33
  // 人の名前と読ませる敬称(様、さん)は語彙表 person-suffix、人を指す前置き(担当の)は person-lead、名前のすぐ後ろに来る語
32
34
  // (です、まで)は name-particle、字体の違う同じ字(斎・斉・齋)は name-variant-char が組(group)ごとに言う。
@@ -297,7 +299,10 @@ const nameMentionsOf = (doc: ProseDocument, prose: string, chars: VariantChars):
297
299
  const outside = joined.filter(
298
300
  (mention) => !spaced.some((name) => name.offset < mention.offset + mention.surface.length && mention.offset < name.offset + name.surface.length),
299
301
  );
300
- return outsideCapitals(prose, withKnownNeighbours([...outside, ...spaced], prose)).toSorted((left, right) => left.offset - right.offset);
302
+ const prefixes = patternsOf(doc, "name-capitals-prefix");
303
+ return outsideCapitals(prose, withKnownNeighbours([...outside, ...spaced], prose))
304
+ .filter((mention) => !isSetInCapitals(mention.surface, prefixes))
305
+ .toSorted((left, right) => left.offset - right.offset);
301
306
  };
302
307
 
303
308
  /** 人の名前で形の似た別の字(太 と 大)は語彙表 name-lookalike-char が組(group)ごとに言う。 */
@@ -349,21 +354,6 @@ const labelledNamesOf = (doc: ProseDocument, mentions: readonly NameMention[]):
349
354
  );
350
355
  };
351
356
 
352
- const LATIN_WORD = /^[A-Za-z]+$/u;
353
- const LOWERCASE_WORD = /^[a-z]+$/u;
354
-
355
- /** 文書が小文字で書くか、品詞解析が普通名詞と読む英字の語(文頭の Hurricane)。 */
356
- const isCommonToken = (token: Token): boolean => LOWERCASE_WORD.test(token.surface) || (token.pos === "NOUN" && LATIN_WORD.test(token.surface));
357
-
358
- /** 文書での英字の語の使い方。名前と読んだ語のうち小文字で書けばふつうの語と、普通名詞として書いた語。 */
359
- const wordUseOf = (doc: ProseDocument): WordUse => {
360
- const tokens = tokensOf(doc);
361
- return {
362
- ordinary: new Set(tokens.flatMap((token) => (isOrdinaryToken(token) ? [token.surface.toLowerCase()] : []))),
363
- common: new Set(tokens.flatMap((token) => (isCommonToken(token) ? [token.surface.toLowerCase()] : []))),
364
- };
365
- };
366
-
367
357
  /** 同じ名前を、文書の中で少しだけ違う形に書いた所(GitHub と Github、山田太郎 と 山田太朗)。少ないほうを指す。 */
368
358
  export const nameVariant: Detector = (doc): Finding[] => {
369
359
  const prose = doc.prose ?? doc.source;
@@ -374,7 +364,8 @@ export const nameVariant: Detector = (doc): Finding[] => {
374
364
  companies,
375
365
  companyFormsOf(doc).map((form) => form.pattern),
376
366
  );
377
- const variants = nameVariants(mentions, chars, spellingInputOf(doc), wordUseOf(doc))
367
+ const use = wordUseOf(tokensOf(doc));
368
+ const variants = nameVariants(mentions, chars, spellingInputOf(doc), use)
378
369
  .map(({ mention, usual, kind }): Reported => ({ offset: mention.offset, name: mention.surface, usual, kind }))
379
370
  .filter((found) => notSpacingOnly(found) && !inGroup(found));
380
371
  const lookalikes = lookalikeSlipsIn(mentions, lookalikeCharsOf(doc)).map(({ mention, usual }) => ({
@@ -390,10 +381,14 @@ export const nameVariant: Detector = (doc): Finding[] => {
390
381
  const withProducts = [...withPlaces, ...productFindings(doc, prose, withPlaces)];
391
382
  const withOrder = [...withProducts, ...orderFindings(doc, prose, withProducts)];
392
383
  const codes = modelCodeFindings(doc, prose).filter((code) => !overlapsAny(withOrder, code.offset, code.name.length));
384
+ const withCodes = [...withOrder, ...codes];
385
+ const titles = titleFindingsOf(prose, patternsOf(doc, "name-title-head")).filter((title) => !overlapsAny(withCodes, title.offset, title.name.length));
393
386
  const dictionary = doc.dictionary?.();
394
387
  const speller = dictionary === undefined ? undefined : spellerOf(doc, dictionary);
395
- return [...withOrder, ...codes]
388
+ const isTwoThings = twoThingsIn(doc, tokensOf(doc), speller, use.ordinary);
389
+ return [...withCodes, ...titles]
396
390
  .filter(({ name, usual }) => speller === undefined || !isDictionaryPair(name, usual, speller))
391
+ .filter((found) => !isTwoThings(found))
397
392
  .filter(notAnotherAuthorIn(doc))
398
393
  .toSorted((left, right) => left.offset - right.offset)
399
394
  .map(({ offset, name, usual, kind }) => ({
@@ -49,11 +49,23 @@ const properLength = (run: readonly Token[]): number => {
49
49
  return run.slice(0, stretch).some((token) => token.pos === "PROPN") ? stretch : 0;
50
50
  };
51
51
 
52
- /** 1 つの区切り(総務課、産業技術総合研究所)か。組織の語で閉じ、その前に 2 字以上の語があり、数を含まない。 */
52
+ const isOrdinalPrefix = (token: Token | undefined): boolean => token?.pos === "ADJ" && token.features?.["Bound"] === "Yes";
53
+
54
+ /** 頭の「第」と数(第三担当の「第三」、第一原子力発電所の「第一」)の語数。無ければ 0。 */
55
+ const ordinalLength = (part: readonly Token[]): number => {
56
+ if (!isOrdinalPrefix(part[0])) return 0;
57
+ const digits = part.slice(1).findIndex((token) => !isNumber(token));
58
+ return digits > 0 ? 1 + digits : 0;
59
+ };
60
+
61
+ /**
62
+ * 1 つの区切り(総務課、産業技術総合研究所、第三担当)か。組織の語で閉じ、その前に 2 字以上の語があり、
63
+ * 数を含まない。頭の序数(第三担当の「第三」)だけは、同じ種類の単位の何番目かを言う名前の一部。
64
+ */
53
65
  const isSegment = (part: readonly Token[], units: readonly string[]): boolean => {
54
66
  const text = [...surfaceOf(part)];
55
67
  const closing = units.filter((unit) => text.join("").endsWith(unit));
56
- return !part.some(isNumber) && closing.some((unit) => text.length - [...unit].length >= MIN_BODY_LENGTH);
68
+ return !part.slice(ordinalLength(part)).some(isNumber) && closing.some((unit) => text.length - [...unit].length >= MIN_BODY_LENGTH);
57
69
  };
58
70
 
59
71
  /**
@@ -101,3 +113,15 @@ export const isOrganisationRun = (tokens: readonly Token[], covering: readonly n
101
113
  const segments = segmentCount(run.slice(head), words.units);
102
114
  return head > 0 || formBefore ? segments >= 1 : segments >= 2;
103
115
  };
116
+
117
+ /**
118
+ * 連なりの語(covering)が、中黒の後ろへ続いて組織の語で閉じる名前(中央環境審議会地球環境部会気候変動影響評価・適応小委員会)の前半か。
119
+ * 前半は、法人格か地名・固有名詞で始まるか、組織の語で閉じる区切りで始まるか、前に法人格か組織の区切りが立つ(formBefore)。
120
+ * 名前が中黒の後ろで閉じるかは呼び出し側が決める。
121
+ */
122
+ export const isOrganisationHead = (tokens: readonly Token[], covering: readonly number[], words: OrganisationWords, formBefore = false): boolean => {
123
+ const run = contiguous(tokens, covering);
124
+ if (run === undefined || run.length === 0) return false;
125
+ if (formBefore || formLength(run, new Set(words.forms)) > 0 || properLength(run) > 0) return true;
126
+ return run.some((_, at) => at > 0 && segmentCount(run.slice(0, at), words.units) >= 1);
127
+ };
@@ -0,0 +1,119 @@
1
+ // Where in a sentence orthographic-variant reads the writer's own spelling: outside what keeps a spelling of its own (a
2
+ // quotation, a name, a cited title) and outside what is not a spelling at all (a reading in brackets, a label).
3
+
4
+ import type { ProseDocument, Sentence, Span } from "../plugin.ts";
5
+ import { externalLinkTitleSpans } from "../link-title.ts";
6
+ import { QUOTATION_MARKS, isWithinAny, quotedSpans } from "../quoted-span.ts";
7
+ import { singleQuotedSpans } from "../single-quoted-span.ts";
8
+ import { nameSpans, touchesAny } from "../team-names.ts";
9
+ import { furiganaSpans } from "../furigana.ts";
10
+ import { contactEntrySpans } from "../contact-entry.ts";
11
+ import { japaneseCompanyNameSpans } from "../company-name-run.ts";
12
+ import { leadingLabelSpans } from "../leading-label.ts";
13
+ import { mentionedSpellingSpans } from "../spelling-mention.ts";
14
+ import { quoteGlossSpans } from "../quote-gloss.ts";
15
+ import { lawTitleSpans } from "../law-title.ts";
16
+ import { referenceListSpans } from "../reference-lists.ts";
17
+ import { citationLead } from "./citation-sentence.ts";
18
+ import { acronymExpansionSpans } from "../acronym-expansion.ts";
19
+ import { nameEndingRuns, namesWrittenOneWay } from "../name-ending-run.ts";
20
+ import { entriesForGenre } from "../lexicon-genres.ts";
21
+
22
+ export type IsOpen = (start: number, end: number) => boolean;
23
+
24
+ const SPELLING_MENTION = "spelling-mention";
25
+ const COMPANY_FORM = "company-form";
26
+ /** Lexicon: words that close a facility's or an organisation's name (動物園, センター): the nouns before them are the name's. */
27
+ const NAME_ENDING = "orthographic-variant-name-ending";
28
+ /** Lexicon: a statute's number in brackets ((平成20年法律第83号)), as regular expressions: the title before it is the statute's. */
29
+ const LAW_NUMBER = "orthographic-variant-law-number";
30
+ /** Lexicon shared with other rules: the headings of a reference list. */
31
+ const REFERENCE_LIST_HEADING = "reference-list-heading";
32
+
33
+ /** A lexicon's entries that hold for the genre. */
34
+ export const patternsOf = (doc: ProseDocument, id: string, genre: string | undefined): string[] =>
35
+ entriesForGenre(doc.lexicons[id] ?? [], genre).map((entry) => entry.pattern);
36
+
37
+ /** Every entry of a lexicon, whatever its genres. */
38
+ const allPatternsOf = (doc: ProseDocument, id: string): string[] => (doc.lexicons[id] ?? []).map((entry) => entry.pattern);
39
+
40
+ /**
41
+ * The team's names, the company forms (株式会社, ㈱) a registered company name is written next to, the links that quote an
42
+ * outside page's title (link-title.ts) and the reference lists, placed in the source, and the words that close a name or
43
+ * number a statute.
44
+ */
45
+ export type Names = {
46
+ readonly team: readonly string[];
47
+ readonly companyForms: readonly string[];
48
+ readonly linkTitles: readonly Span[];
49
+ /** Quotations in single quotation marks (an opinion quoting a statute), placed in the source: they can span sentences. */
50
+ readonly singleQuoted: readonly Span[];
51
+ /** Phrases that say a word is also spelled another way (とも書く): the bracketed words before them are spellings mentioned. */
52
+ readonly mentions: readonly string[];
53
+ /** Reference lists: their entries are cited works, spelled as their authors spelled them. */
54
+ readonly referenceLists: readonly Span[];
55
+ readonly lawNumbers: readonly RegExp[];
56
+ readonly nameEndings: readonly string[];
57
+ /** The facilities' and organisations' names the document writes one way only (こども動物園). */
58
+ readonly oneWayNames: ReadonlySet<string>;
59
+ };
60
+
61
+ export const namesOf = (doc: ProseDocument, genre: string | undefined): Names => ({
62
+ team: doc.names ?? [],
63
+ companyForms: allPatternsOf(doc, COMPANY_FORM),
64
+ linkTitles: externalLinkTitleSpans(doc.source, doc.links),
65
+ singleQuoted: singleQuotedSpans(doc.source),
66
+ mentions: allPatternsOf(doc, SPELLING_MENTION),
67
+ referenceLists: referenceListSpans(doc.source, allPatternsOf(doc, REFERENCE_LIST_HEADING)),
68
+ lawNumbers: patternsOf(doc, LAW_NUMBER, genre).map((pattern) => new RegExp(pattern, "u")),
69
+ nameEndings: patternsOf(doc, NAME_ENDING, genre),
70
+ oneWayNames: namesWrittenOneWay(
71
+ [...doc.sentences, ...(doc.tableCells?.() ?? [])].flatMap(({ tokens }) => nameEndingRuns(tokens ?? [], patternsOf(doc, NAME_ENDING, genre))),
72
+ ),
73
+ });
74
+
75
+ /** Spans placed in the source, placed in a sentence's text instead. */
76
+ const inSentence = (sentence: Sentence, spans: readonly Span[]): Span[] =>
77
+ spans.map((span) => ({ start: span.start - sentence.span.start, end: span.end - sentence.span.start }));
78
+
79
+ /** The reference a sentence cites (See John Kay and Mervyn King (2020), Radical Uncertainty: …): from its year on, the cited work's words. */
80
+ const citationSpans = (text: string): Span[] => {
81
+ const lead = citationLead(text, []);
82
+ return lead === undefined ? [] : [{ start: text.indexOf(lead) + lead.length, end: text.length }];
83
+ };
84
+
85
+ /** A sentence's cited works: a reference list's entry, and the reference a sentence cites. Their Latin words are read with care (quoted-spelling.ts). */
86
+ export const citedSpans = (sentence: Sentence, names: Names): Span[] => [...inSentence(sentence, names.referenceLists), ...citationSpans(sentence.text)];
87
+
88
+ /** What keeps a spelling of its own: a quotation's gloss, a statute's title, an acronym's expansion, a facility's name. */
89
+ const ownSpellingSpans = (sentence: Sentence, names: Names): Span[] => [
90
+ ...quoteGlossSpans(sentence.text),
91
+ ...lawTitleSpans(sentence.text, names.lawNumbers),
92
+ ...acronymExpansionSpans(sentence.text),
93
+ ...inSentence(
94
+ sentence,
95
+ nameEndingRuns(sentence.tokens ?? [], names.nameEndings).filter((name) => names.oneWayNames.has(name.written)),
96
+ ),
97
+ ];
98
+
99
+ /**
100
+ * Whether a stretch of the sentence is outside a quotation, the team's names, a company's name (関東珪曹硝子㈱), a reading in
101
+ * brackets (HTTP(えいちてぃーてぃーぴー)), a label opening the sentence ((答)), a spelling mentioned ((曇)とも書く), a
102
+ * contact's name beside its phone number and what keeps a spelling of its own: a reading is not a spelling at all, a label is a
103
+ * fixed short form, a mention is the subject, and the rest keep their own spelling.
104
+ */
105
+ export const isOpenIn = (sentence: Sentence, names: Names): IsOpen => {
106
+ const closed = [
107
+ ...quotedSpans(sentence.text, QUOTATION_MARKS),
108
+ ...furiganaSpans(sentence.text),
109
+ ...contactEntrySpans(sentence.text),
110
+ ...japaneseCompanyNameSpans(sentence.text, names.companyForms),
111
+ ...inSentence(sentence, names.linkTitles),
112
+ ...inSentence(sentence, names.singleQuoted),
113
+ ...leadingLabelSpans(sentence.text),
114
+ ...mentionedSpellingSpans(sentence.text, names.mentions),
115
+ ...ownSpellingSpans(sentence, names),
116
+ ];
117
+ const named = nameSpans(sentence.text, names.team);
118
+ return (start, end) => !isWithinAny(closed, { start, end }) && !touchesAny(named, start, end);
119
+ };