chaffjs 0.49.0 → 0.50.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 (373) hide show
  1. package/dist/announced-count.d.ts.map +1 -1
  2. package/dist/announced-count.js +18 -1
  3. package/dist/announced-count.js.map +1 -1
  4. package/dist/announced-list.d.ts.map +1 -1
  5. package/dist/announced-list.js +6 -1
  6. package/dist/announced-list.js.map +1 -1
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +4 -2
  9. package/dist/cli.js.map +1 -1
  10. package/dist/composite-signals.d.ts +3 -1
  11. package/dist/composite-signals.d.ts.map +1 -1
  12. package/dist/composite-signals.js +7 -0
  13. package/dist/composite-signals.js.map +1 -1
  14. package/dist/detectors/agentless-passive.d.ts.map +1 -1
  15. package/dist/detectors/agentless-passive.js +39 -4
  16. package/dist/detectors/agentless-passive.js.map +1 -1
  17. package/dist/detectors/agreement-slip.d.ts +2 -0
  18. package/dist/detectors/agreement-slip.d.ts.map +1 -1
  19. package/dist/detectors/agreement-slip.js +10 -3
  20. package/dist/detectors/agreement-slip.js.map +1 -1
  21. package/dist/detectors/amount-scale.js +2 -2
  22. package/dist/detectors/amount-scale.js.map +1 -1
  23. package/dist/detectors/chat-citation.d.ts +2 -6
  24. package/dist/detectors/chat-citation.d.ts.map +1 -1
  25. package/dist/detectors/chat-citation.js +4 -2
  26. package/dist/detectors/chat-citation.js.map +1 -1
  27. package/dist/detectors/chat-mark-extent.d.ts +11 -0
  28. package/dist/detectors/chat-mark-extent.d.ts.map +1 -0
  29. package/dist/detectors/chat-mark-extent.js +53 -0
  30. package/dist/detectors/chat-mark-extent.js.map +1 -0
  31. package/dist/detectors/conjugated-entry.d.ts +2 -2
  32. package/dist/detectors/conjugated-entry.d.ts.map +1 -1
  33. package/dist/detectors/conjugated-entry.js +3 -5
  34. package/dist/detectors/conjugated-entry.js.map +1 -1
  35. package/dist/detectors/contrast-frame.d.ts.map +1 -1
  36. package/dist/detectors/contrast-frame.js +34 -1
  37. package/dist/detectors/contrast-frame.js.map +1 -1
  38. package/dist/detectors/currency-notation.js +2 -2
  39. package/dist/detectors/currency-notation.js.map +1 -1
  40. package/dist/detectors/defined-term-form.d.ts.map +1 -1
  41. package/dist/detectors/defined-term-form.js +15 -3
  42. package/dist/detectors/defined-term-form.js.map +1 -1
  43. package/dist/detectors/definition-use.d.ts.map +1 -1
  44. package/dist/detectors/definition-use.js +5 -1
  45. package/dist/detectors/definition-use.js.map +1 -1
  46. package/dist/detectors/ellipsis.js +2 -2
  47. package/dist/detectors/ellipsis.js.map +1 -1
  48. package/dist/detectors/email-letter.d.ts +2 -0
  49. package/dist/detectors/email-letter.d.ts.map +1 -1
  50. package/dist/detectors/email-letter.js +1 -1
  51. package/dist/detectors/email-letter.js.map +1 -1
  52. package/dist/detectors/en-shape.d.ts.map +1 -1
  53. package/dist/detectors/en-shape.js +34 -8
  54. package/dist/detectors/en-shape.js.map +1 -1
  55. package/dist/detectors/gram-furniture.d.ts +1 -0
  56. package/dist/detectors/gram-furniture.d.ts.map +1 -1
  57. package/dist/detectors/gram-furniture.js +6 -0
  58. package/dist/detectors/gram-furniture.js.map +1 -1
  59. package/dist/detectors/gram-repetition.d.ts.map +1 -1
  60. package/dist/detectors/gram-repetition.js +8 -2
  61. package/dist/detectors/gram-repetition.js.map +1 -1
  62. package/dist/detectors/heading-case.d.ts +1 -0
  63. package/dist/detectors/heading-case.d.ts.map +1 -1
  64. package/dist/detectors/heading-case.js +10 -3
  65. package/dist/detectors/heading-case.js.map +1 -1
  66. package/dist/detectors/kutoten-consistency.d.ts.map +1 -1
  67. package/dist/detectors/kutoten-consistency.js +27 -6
  68. package/dist/detectors/kutoten-consistency.js.map +1 -1
  69. package/dist/detectors/lexicon-match.d.ts +2 -0
  70. package/dist/detectors/lexicon-match.d.ts.map +1 -1
  71. package/dist/detectors/lexicon-match.js +14 -3
  72. package/dist/detectors/lexicon-match.js.map +1 -1
  73. package/dist/detectors/lexicon.d.ts.map +1 -1
  74. package/dist/detectors/lexicon.js +8 -1
  75. package/dist/detectors/lexicon.js.map +1 -1
  76. package/dist/detectors/list-item-clause.d.ts +4 -0
  77. package/dist/detectors/list-item-clause.d.ts.map +1 -0
  78. package/dist/detectors/list-item-clause.js +8 -0
  79. package/dist/detectors/list-item-clause.js.map +1 -0
  80. package/dist/detectors/list-parallel.d.ts.map +1 -1
  81. package/dist/detectors/list-parallel.js +6 -2
  82. package/dist/detectors/list-parallel.js.map +1 -1
  83. package/dist/detectors/list-sentence.d.ts +2 -0
  84. package/dist/detectors/list-sentence.d.ts.map +1 -1
  85. package/dist/detectors/list-sentence.js.map +1 -1
  86. package/dist/detectors/mark-shape.d.ts.map +1 -1
  87. package/dist/detectors/mark-shape.js +28 -8
  88. package/dist/detectors/mark-shape.js.map +1 -1
  89. package/dist/detectors/missing-final-period.d.ts.map +1 -1
  90. package/dist/detectors/missing-final-period.js +10 -1
  91. package/dist/detectors/missing-final-period.js.map +1 -1
  92. package/dist/detectors/nominalization.d.ts.map +1 -1
  93. package/dist/detectors/nominalization.js +11 -4
  94. package/dist/detectors/nominalization.js.map +1 -1
  95. package/dist/detectors/ordinal-suffix.js +2 -2
  96. package/dist/detectors/ordinal-suffix.js.map +1 -1
  97. package/dist/detectors/orthographic-variant.d.ts.map +1 -1
  98. package/dist/detectors/orthographic-variant.js +30 -6
  99. package/dist/detectors/orthographic-variant.js.map +1 -1
  100. package/dist/detectors/orthography.d.ts.map +1 -1
  101. package/dist/detectors/orthography.js +13 -7
  102. package/dist/detectors/orthography.js.map +1 -1
  103. package/dist/detectors/oxford-comma.d.ts.map +1 -1
  104. package/dist/detectors/oxford-comma.js +15 -1
  105. package/dist/detectors/oxford-comma.js.map +1 -1
  106. package/dist/detectors/paragraph-run.js +2 -2
  107. package/dist/detectors/paragraph-run.js.map +1 -1
  108. package/dist/detectors/phone-number-variant.d.ts.map +1 -1
  109. package/dist/detectors/phone-number-variant.js +2 -1
  110. package/dist/detectors/phone-number-variant.js.map +1 -1
  111. package/dist/detectors/phrase-context.d.ts +6 -0
  112. package/dist/detectors/phrase-context.d.ts.map +1 -0
  113. package/dist/detectors/phrase-context.js +12 -0
  114. package/dist/detectors/phrase-context.js.map +1 -0
  115. package/dist/detectors/phrase-match-all.d.ts +3 -0
  116. package/dist/detectors/phrase-match-all.d.ts.map +1 -0
  117. package/dist/detectors/phrase-match-all.js +47 -0
  118. package/dist/detectors/phrase-match-all.js.map +1 -0
  119. package/dist/detectors/phrase-match.d.ts +2 -1
  120. package/dist/detectors/phrase-match.d.ts.map +1 -1
  121. package/dist/detectors/phrase-match.js +25 -6
  122. package/dist/detectors/phrase-match.js.map +1 -1
  123. package/dist/detectors/placeholder-text.d.ts.map +1 -1
  124. package/dist/detectors/placeholder-text.js +14 -2
  125. package/dist/detectors/placeholder-text.js.map +1 -1
  126. package/dist/detectors/proper-noun-density.d.ts.map +1 -1
  127. package/dist/detectors/proper-noun-density.js +10 -6
  128. package/dist/detectors/proper-noun-density.js.map +1 -1
  129. package/dist/detectors/quote-around.d.ts +3 -0
  130. package/dist/detectors/quote-around.d.ts.map +1 -1
  131. package/dist/detectors/quote-around.js +2 -0
  132. package/dist/detectors/quote-around.js.map +1 -1
  133. package/dist/detectors/range-notation.js +2 -2
  134. package/dist/detectors/range-notation.js.map +1 -1
  135. package/dist/detectors/registry/phrase-match-all.d.ts +3 -0
  136. package/dist/detectors/registry/phrase-match-all.d.ts.map +1 -0
  137. package/dist/detectors/registry/phrase-match-all.js +3 -0
  138. package/dist/detectors/registry/phrase-match-all.js.map +1 -0
  139. package/dist/detectors/requirement-lists.d.ts.map +1 -1
  140. package/dist/detectors/requirement-lists.js +2 -0
  141. package/dist/detectors/requirement-lists.js.map +1 -1
  142. package/dist/detectors/sentence-counts.d.ts.map +1 -1
  143. package/dist/detectors/sentence-counts.js +5 -3
  144. package/dist/detectors/sentence-counts.js.map +1 -1
  145. package/dist/detectors/sentence-length.d.ts.map +1 -1
  146. package/dist/detectors/sentence-length.js +9 -2
  147. package/dist/detectors/sentence-length.js.map +1 -1
  148. package/dist/detectors/signals.d.ts.map +1 -1
  149. package/dist/detectors/signals.js +6 -1
  150. package/dist/detectors/signals.js.map +1 -1
  151. package/dist/detectors/team.d.ts.map +1 -1
  152. package/dist/detectors/team.js +42 -9
  153. package/dist/detectors/team.js.map +1 -1
  154. package/dist/detectors/unit-spacing.js +2 -2
  155. package/dist/detectors/unit-spacing.js.map +1 -1
  156. package/dist/detectors/vague-deadline.d.ts.map +1 -1
  157. package/dist/detectors/vague-deadline.js +2 -1
  158. package/dist/detectors/vague-deadline.js.map +1 -1
  159. package/dist/levels.d.ts +14 -0
  160. package/dist/levels.d.ts.map +1 -1
  161. package/dist/levels.js +8 -3
  162. package/dist/levels.js.map +1 -1
  163. package/dist/phone-numbers.d.ts +5 -2
  164. package/dist/phone-numbers.d.ts.map +1 -1
  165. package/dist/phone-numbers.js +17 -3
  166. package/dist/phone-numbers.js.map +1 -1
  167. package/dist/plugin.d.ts +2 -0
  168. package/dist/plugin.d.ts.map +1 -1
  169. package/dist/render/explain.d.ts +2 -0
  170. package/dist/render/explain.d.ts.map +1 -1
  171. package/dist/render/explain.js +38 -14
  172. package/dist/render/explain.js.map +1 -1
  173. package/dist/render/options.d.ts.map +1 -1
  174. package/dist/render/options.js +11 -6
  175. package/dist/render/options.js.map +1 -1
  176. package/dist/render/text.d.ts.map +1 -1
  177. package/dist/render/text.js +14 -4
  178. package/dist/render/text.js.map +1 -1
  179. package/dist/run.d.ts +3 -0
  180. package/dist/run.d.ts.map +1 -1
  181. package/dist/run.js +20 -13
  182. package/dist/run.js.map +1 -1
  183. package/dist/structure/deadline-after-event.d.ts +1 -1
  184. package/dist/structure/deadline-after-event.d.ts.map +1 -1
  185. package/dist/structure/deadline-after-event.js +36 -9
  186. package/dist/structure/deadline-after-event.js.map +1 -1
  187. package/dist/structure/definition-use.d.ts +10 -1
  188. package/dist/structure/definition-use.d.ts.map +1 -1
  189. package/dist/structure/definition-use.js +4 -4
  190. package/dist/structure/definition-use.js.map +1 -1
  191. package/dist/structure/leg-times.d.ts.map +1 -1
  192. package/dist/structure/leg-times.js +10 -2
  193. package/dist/structure/leg-times.js.map +1 -1
  194. package/dist/structure/requirement-lists.d.ts +3 -0
  195. package/dist/structure/requirement-lists.d.ts.map +1 -1
  196. package/dist/structure/requirement-lists.js +8 -2
  197. package/dist/structure/requirement-lists.js.map +1 -1
  198. package/dist/structure/time-marks.d.ts +10 -0
  199. package/dist/structure/time-marks.d.ts.map +1 -1
  200. package/dist/structure/time-marks.js +21 -0
  201. package/dist/structure/time-marks.js.map +1 -1
  202. package/package.json +3 -3
  203. package/rules/abstract-length.yaml +1 -1
  204. package/rules/adverb-overuse.yaml +1 -1
  205. package/rules/agentless-passive.yaml +3 -3
  206. package/rules/agreement-slip.yaml +5 -4
  207. package/rules/ai-generated-composite.yaml +3 -3
  208. package/rules/ai-structure.yaml +1 -1
  209. package/rules/all-caps-shouting.yaml +1 -1
  210. package/rules/announced-count-mismatch.yaml +2 -2
  211. package/rules/announcing-opener.yaml +1 -1
  212. package/rules/arrival-before-departure.yaml +1 -1
  213. package/rules/article-sound.yaml +1 -1
  214. package/rules/baito-keigo.yaml +1 -1
  215. package/rules/bold-density.yaml +1 -1
  216. package/rules/bold-emphasis.yaml +1 -1
  217. package/rules/bold-label-list.yaml +1 -1
  218. package/rules/bracket-width-consistency.yaml +1 -1
  219. package/rules/chat-citation-residue.yaml +1 -1
  220. package/rules/citation-style-mix.yaml +1 -1
  221. package/rules/clause-chain.yaml +1 -1
  222. package/rules/cliche.yaml +4 -4
  223. package/rules/closing-cliche.yaml +1 -1
  224. package/rules/closing-exhortation.yaml +1 -1
  225. package/rules/cold-open.yaml +1 -1
  226. package/rules/colloquial-opener.yaml +1 -1
  227. package/rules/concrete-evidence-density.yaml +1 -1
  228. package/rules/contraction-consistency.yaml +1 -1
  229. package/rules/cross-doc-term-variant.yaml +2 -2
  230. package/rules/cushion-phrase-density.yaml +1 -1
  231. package/rules/deadline-after-event.yaml +2 -2
  232. package/rules/demonstrative-opener-run.yaml +1 -1
  233. package/rules/double-keigo.yaml +1 -1
  234. package/rules/double-negative.yaml +11 -2
  235. package/rules/doubled-nado.yaml +1 -1
  236. package/rules/email-stock-courtesy.yaml +1 -1
  237. package/rules/email-subject-length.yaml +1 -1
  238. package/rules/emoji-heading.yaml +1 -1
  239. package/rules/empty-intensifier.yaml +1 -1
  240. package/rules/excessive-hedging.yaml +1 -1
  241. package/rules/exclamation-width-consistency.yaml +1 -1
  242. package/rules/expletive-construction.yaml +3 -3
  243. package/rules/figurative-density.yaml +3 -3
  244. package/rules/hiragana-fukushi.yaml +1 -1
  245. package/rules/homophone-slip.yaml +3 -3
  246. package/rules/honesty-marker.yaml +1 -1
  247. package/rules/humble-for-others.yaml +1 -1
  248. package/rules/hyphen-as-dash.yaml +1 -1
  249. package/rules/idiom-misuse.yaml +1 -1
  250. package/rules/internal-jargon.yaml +1 -1
  251. package/rules/kana-function-word.yaml +1 -1
  252. package/rules/katakana-long-vowel.yaml +1 -1
  253. package/rules/kutoten-consistency.yaml +7 -3
  254. package/rules/latin-abbreviation-form.yaml +1 -1
  255. package/rules/latin-spacing.yaml +1 -1
  256. package/rules/max-paragraph-length.yaml +1 -1
  257. package/rules/max-sentence-length.yaml +1 -1
  258. package/rules/max-ten.yaml +1 -1
  259. package/rules/misconversion.yaml +2 -2
  260. package/rules/ngram-repetition.yaml +3 -3
  261. package/rules/no-em-dash.yaml +3 -3
  262. package/rules/no-mixed-desumasu.yaml +1 -1
  263. package/rules/no-nakaguro-parallel.yaml +1 -1
  264. package/rules/nominalization.yaml +1 -1
  265. package/rules/nonstandard-word.yaml +2 -2
  266. package/rules/numbered-generic-heading.yaml +1 -1
  267. package/rules/numbering-gap.yaml +2 -2
  268. package/rules/one-sentence-paragraph-run.yaml +1 -1
  269. package/rules/orthographic-variant.yaml +2 -2
  270. package/rules/over-general-claim.yaml +1 -1
  271. package/rules/oxford-comma-consistency.yaml +4 -3
  272. package/rules/padded-intro.yaml +1 -1
  273. package/rules/phone-number-variant.yaml +1 -1
  274. package/rules/preamble-length.yaml +1 -1
  275. package/rules/preferred-term.yaml +1 -1
  276. package/rules/proper-noun-density.yaml +1 -1
  277. package/rules/q-fragment-answer.yaml +1 -1
  278. package/rules/quote-style-consistency.yaml +1 -1
  279. package/rules/quote-without-source.yaml +1 -1
  280. package/rules/redundant-expression.yaml +1 -1
  281. package/rules/repeated-conjunction.yaml +1 -1
  282. package/rules/repeated-sentence-ending.yaml +1 -1
  283. package/rules/repeated-sentence-head.yaml +5 -5
  284. package/rules/required-listed-as-preferred.yaml +2 -2
  285. package/rules/required-sections.yaml +1 -1
  286. package/rules/sasete-itadaku.yaml +1 -1
  287. package/rules/sentence-initial-conjunction-run.yaml +1 -1
  288. package/rules/sentence-initial-so.yaml +1 -1
  289. package/rules/sentence-spacing-consistency.yaml +1 -1
  290. package/rules/shell-prompt-mix.yaml +1 -1
  291. package/rules/stock-transition.yaml +1 -1
  292. package/rules/stray-space.yaml +1 -1
  293. package/rules/taigen-dome-in-prose.yaml +1 -1
  294. package/rules/teki-overuse.yaml +1 -1
  295. package/rules/title-case-consistency.yaml +1 -1
  296. package/rules/title-length.yaml +1 -1
  297. package/rules/topic-predicate-distance.yaml +1 -1
  298. package/rules/translationese-density.yaml +1 -1
  299. package/rules/uncomparable-graded.yaml +1 -1
  300. package/rules/undefined-acronym.yaml +1 -1
  301. package/rules/unfilled-placeholder.yaml +4 -4
  302. package/rules/unqualified-superlative.yaml +1 -1
  303. package/rules/use-before-definition.yaml +2 -2
  304. package/rules/vague-word-density.yaml +1 -1
  305. package/rules/weasel-word.yaml +1 -1
  306. package/rules/which-that-consistency.yaml +1 -1
  307. package/rules/wordy-phrase.yaml +1 -1
  308. package/src/announced-count.ts +22 -1
  309. package/src/announced-list.ts +7 -1
  310. package/src/cli.ts +4 -2
  311. package/src/composite-signals.ts +10 -1
  312. package/src/detectors/agentless-passive.ts +49 -5
  313. package/src/detectors/agreement-slip.ts +11 -3
  314. package/src/detectors/amount-scale.ts +2 -2
  315. package/src/detectors/chat-citation.ts +4 -5
  316. package/src/detectors/chat-mark-extent.ts +63 -0
  317. package/src/detectors/conjugated-entry.ts +3 -5
  318. package/src/detectors/contrast-frame.ts +37 -2
  319. package/src/detectors/currency-notation.ts +2 -2
  320. package/src/detectors/defined-term-form.ts +15 -4
  321. package/src/detectors/definition-use.ts +5 -8
  322. package/src/detectors/ellipsis.ts +2 -2
  323. package/src/detectors/email-letter.ts +1 -1
  324. package/src/detectors/en-shape.ts +40 -5
  325. package/src/detectors/gram-furniture.ts +8 -0
  326. package/src/detectors/gram-repetition.ts +8 -1
  327. package/src/detectors/heading-case.ts +11 -3
  328. package/src/detectors/kutoten-consistency.ts +37 -6
  329. package/src/detectors/lexicon-match.ts +17 -3
  330. package/src/detectors/lexicon.ts +10 -4
  331. package/src/detectors/list-item-clause.ts +9 -0
  332. package/src/detectors/list-parallel.ts +5 -2
  333. package/src/detectors/list-sentence.ts +2 -0
  334. package/src/detectors/mark-shape.ts +36 -8
  335. package/src/detectors/missing-final-period.ts +11 -1
  336. package/src/detectors/nominalization.ts +14 -4
  337. package/src/detectors/ordinal-suffix.ts +2 -2
  338. package/src/detectors/orthographic-variant.ts +44 -8
  339. package/src/detectors/orthography.ts +19 -9
  340. package/src/detectors/oxford-comma.ts +15 -1
  341. package/src/detectors/paragraph-run.ts +2 -2
  342. package/src/detectors/phone-number-variant.ts +2 -1
  343. package/src/detectors/phrase-context.ts +19 -0
  344. package/src/detectors/phrase-match-all.ts +57 -0
  345. package/src/detectors/phrase-match.ts +31 -6
  346. package/src/detectors/placeholder-text.ts +19 -3
  347. package/src/detectors/proper-noun-density.ts +14 -6
  348. package/src/detectors/quote-around.ts +6 -0
  349. package/src/detectors/range-notation.ts +2 -2
  350. package/src/detectors/registry/phrase-match-all.ts +4 -0
  351. package/src/detectors/requirement-lists.ts +2 -0
  352. package/src/detectors/sentence-counts.ts +7 -4
  353. package/src/detectors/sentence-length.ts +12 -2
  354. package/src/detectors/signals.ts +10 -1
  355. package/src/detectors/team.ts +50 -12
  356. package/src/detectors/unit-spacing.ts +2 -2
  357. package/src/detectors/vague-deadline.ts +2 -1
  358. package/src/levels.ts +9 -3
  359. package/src/phone-numbers.ts +19 -3
  360. package/src/plugin.ts +2 -0
  361. package/src/render/explain.ts +46 -16
  362. package/src/render/options.ts +12 -6
  363. package/src/render/text.ts +20 -7
  364. package/src/run.ts +32 -8
  365. package/src/structure/deadline-after-event.ts +49 -10
  366. package/src/structure/definition-use.ts +15 -5
  367. package/src/structure/leg-times.ts +16 -1
  368. package/src/structure/requirement-lists.ts +14 -2
  369. package/src/structure/time-marks.ts +25 -0
  370. package/dist/honorific-group.d.ts +0 -8
  371. package/dist/honorific-group.d.ts.map +0 -1
  372. package/dist/honorific-group.js +0 -15
  373. package/dist/honorific-group.js.map +0 -1
@@ -29,6 +29,7 @@ import { bracketedTitleRuns, titleCaseNameRuns } from "../title-case-name.ts";
29
29
  import { withoutQuotedSpellings, type Quoted } from "../quoted-spelling.ts";
30
30
  import { teFormOf, withTeFormFullVerbs, type TeForm } from "../te-form-helper.ts";
31
31
  import { citedSpans, isOpenIn, namesOf, patternsOf, type IsOpen, type Names } from "./orthographic-variant-open.ts";
32
+ import { headingSentences } from "./heading-sentences.ts";
32
33
 
33
34
  /**
34
35
  * A word found in the document: where it is, which sentence it is in, its key and spelling, how it is written when that differs, and
@@ -302,8 +303,17 @@ const findingOf = (words: readonly Placed[], odd: OddSpelling<Placed>): Finding
302
303
  /** A cell that is one Latin word in lower case (openapi, contentType): a field name or a value, spelled by the data and not by the writer. */
303
304
  const DATA_KEY_CELL = /^\p{Ll}[A-Za-z0-9]*$/u;
304
305
 
305
- /** A sentence or a table cell, where its words are the writer's, whether its Latin words are read, and its cited works. */
306
- type Place = { readonly sentence: Sentence; readonly isOpen: IsOpen; readonly readsLatin: boolean; readonly cited: readonly Span[] };
306
+ /**
307
+ * A sentence, a heading or a table cell, where its words are the writer's, whether its Latin and its Japanese words are
308
+ * read, and its cited works.
309
+ */
310
+ type Place = {
311
+ readonly sentence: Sentence;
312
+ readonly isOpen: IsOpen;
313
+ readonly readsLatin: boolean;
314
+ readonly readsJapanese: boolean;
315
+ readonly cited: readonly Span[];
316
+ };
307
317
 
308
318
  /** What the words of a document are read with besides the lexicons of uses: the dictionary, and the small words inside a name (of). */
309
319
  type Reading = { readonly isWord: (word: string) => boolean; readonly nameJoiners: readonly string[] };
@@ -317,16 +327,41 @@ const withoutLinkChrome = (text: string): string => text.replaceAll(LINK_CHROME,
317
327
  const cellPlace = (cell: TableCell, names: Names): Place => {
318
328
  const text = withoutLinkChrome(cell.text);
319
329
  const sentence: Sentence = { span: { start: cell.start, end: cell.end }, text, tokens: cell.tokens ?? [] };
320
- return { sentence, isOpen: isOpenIn(sentence, names), readsLatin: !DATA_KEY_CELL.test(text.trim()), cited: citedSpans(sentence, names) };
330
+ return {
331
+ sentence,
332
+ isOpen: isOpenIn(sentence, names),
333
+ readsLatin: !DATA_KEY_CELL.test(text.trim()),
334
+ readsJapanese: true,
335
+ cited: citedSpans(sentence, names),
336
+ };
321
337
  };
322
338
 
339
+ /**
340
+ * A body sentence, read whole; or a heading, read for its Latin words only. An English heading spells its words as the
341
+ * body does (e-mail, email); a Japanese heading is a label, whose compound nouns drop okurigana (申込受付期間 beside 申込み)
342
+ * and whose category word (コーヒー) stands beside names in the body (大坊珈琲店).
343
+ */
344
+ const textPlace = (written: Sentence, names: Names, heading: boolean): Place => {
345
+ const sentence = heading ? withoutInlineCode(written) : written;
346
+ return { sentence, isOpen: isOpenIn(sentence, names), readsLatin: true, readsJapanese: !heading, cited: citedSpans(sentence, names) };
347
+ };
348
+
349
+ const INLINE_CODE = /`[^`]*`/gu;
350
+
351
+ /** A heading with its code blanked out (`kubectl create configmap`): the body's prose masks code, a heading's text keeps it. */
352
+ const withoutInlineCode = (sentence: Sentence): Sentence => ({
353
+ ...sentence,
354
+ text: sentence.text.replaceAll(INLINE_CODE, (code) => " ".repeat(code.length)),
355
+ });
356
+
323
357
  /** The odd spellings among places that speak in one voice. */
324
358
  const findingsIn = (placed: readonly Place[], skips: Skips, { isWord, nameJoiners }: Reading, limit: number): Finding[] => {
359
+ const japanese = placed.filter((place) => place.readsJapanese);
325
360
  const reading = byKanji(
326
- withTeFormFullVerbs(placed.flatMap(({ sentence, isOpen }) => readingWords(withCutNounsJoined(sentence, skips.nouns), isOpen, skips))),
361
+ withTeFormFullVerbs(japanese.flatMap(({ sentence, isOpen }) => readingWords(withCutNounsJoined(sentence, skips.nouns), isOpen, skips))),
327
362
  );
328
- const katakana = placed.flatMap(({ sentence, isOpen }) => katakanaWords(sentence, isOpen));
329
- const runs = placed.flatMap(({ sentence, isOpen }) => katakanaRunWords(sentence, isOpen));
363
+ const katakana = japanese.flatMap(({ sentence, isOpen }) => katakanaWords(sentence, isOpen));
364
+ const runs = japanese.flatMap(({ sentence, isOpen }) => katakanaRunWords(sentence, isOpen));
330
365
  const latin = withoutQuotedSpellings(
331
366
  withoutCoinedNames(
332
367
  placed.flatMap((place) => (place.readsLatin ? latinWords(place, skips.skip, nameJoiners) : [])),
@@ -349,7 +384,8 @@ const findingsIn = (placed: readonly Place[], skips: Skips, { isWord, nameJoiner
349
384
  export const orthographicVariant: Detector = (doc, options): Finding[] => {
350
385
  const names = namesOf(doc, options.genre);
351
386
  const placed: Place[] = [
352
- ...doc.sentences.map((sentence) => ({ sentence, isOpen: isOpenIn(sentence, names), readsLatin: true, cited: citedSpans(sentence, names) })),
387
+ ...doc.sentences.map((sentence) => textPlace(sentence, names, false)),
388
+ ...headingSentences(doc).map((sentence) => textPlace(sentence, names, true)),
353
389
  ...(doc.tableCells?.() ?? []).map((cell) => cellPlace(cell, names)),
354
390
  ];
355
391
  const phraseSuffixes = new Set(patternsOf(doc, PHRASE_SUFFIX, options.genre));
@@ -366,7 +402,7 @@ export const orthographicVariant: Detector = (doc, options): Finding[] => {
366
402
  phraseSuffixes,
367
403
  twoReadings: new Map(entriesForGenre(doc.lexicons[TWO_READINGS] ?? [], options.genre).map((entry) => [entry.pattern, entry.group ?? ""])),
368
404
  nouns: documentNounKeys(
369
- placed.map(({ sentence }) => sentence.tokens ?? []),
405
+ placed.flatMap(({ sentence, readsJapanese }) => (readsJapanese ? [sentence.tokens ?? []] : [])),
370
406
  phraseSuffixes,
371
407
  ),
372
408
  };
@@ -1,5 +1,5 @@
1
1
  import type { Detector, Finding, LexiconEntry, ProseDocument, Sentence, Span } from "../plugin.ts";
2
- import { conjugatedStartsOutside } from "./conjugated-entry.ts";
2
+ import { conjugatedSpansOutside } from "./conjugated-entry.ts";
3
3
  import { calendarRuns, calendarUnitsOf, type CalendarUnits } from "../calendar-number.ts";
4
4
  import { escapeRegExp, latinBoundaries, occurrencesOutside, type Boundary, type SpacingKind } from "../orthography.ts";
5
5
  import { minorityReport, withoutSideOnTie } from "../spacing-minority.ts";
@@ -13,18 +13,28 @@ import { licenceNoticeSentences } from "./licence-notice.ts";
13
13
  import { followsCaptionLabel, isCitedEntryLine, isNumberTableBoundary, lineAt } from "../latin-spacing-source.ts";
14
14
 
15
15
  /** 書いた形の出現に、動詞の活用した形(行う → 行います)を足したもの。同じ位置は一度だけ。 */
16
- const avoidedStarts = (sentence: Sentence, entry: LexiconEntry, use: string): number[] => {
17
- const written = occurrencesOutside(sentence.text, entry.pattern, use);
18
- const conjugated = conjugatedStartsOutside(sentence, entry, use).filter((at) => !written.includes(at));
19
- return [...written, ...conjugated].toSorted((left, right) => left - right);
16
+ const avoidedSpans = (sentence: Sentence, entry: LexiconEntry, use: string): Span[] => {
17
+ const written = occurrencesOutside(sentence.text, entry.pattern, use).map((start) => ({ start, end: start + entry.pattern.length }));
18
+ const conjugated = conjugatedSpansOutside(sentence, entry, use).filter((span) => !written.some((other) => other.start === span.start));
19
+ return [...written, ...conjugated].toSorted((left, right) => left.start - right.start);
20
+ };
21
+
22
+ type PreferPair = { readonly entry: LexiconEntry; readonly avoid: string; readonly use: string };
23
+ type PreferHit = { readonly sentence: Sentence; readonly span: Span; readonly pair: PreferPair };
24
+
25
+ const isInsideLonger = (hit: PreferHit, other: PreferHit): boolean =>
26
+ other.span.end - other.span.start > hit.span.end - hit.span.start && other.span.start <= hit.span.start && hit.span.end <= other.span.end;
27
+
28
+ /** 並べた書き方が重なれば(e-mail の中の mail)、長い方だけ。短い方は長い方の一部で、別の書き方ではない。 */
29
+ const sentenceHits = (sentence: Sentence, pairs: readonly PreferPair[]): PreferHit[] => {
30
+ const hits = pairs.flatMap((pair) => avoidedSpans(sentence, pair.entry, pair.use).map((span) => ({ sentence, span, pair })));
31
+ return hits.filter((hit) => !hits.some((other) => isInsideLonger(hit, other))).toSorted((left, right) => left.span.start - right.span.start);
20
32
  };
21
33
 
22
34
  /** チームが chaff.yaml の prefer に書いた「使わない書き方」。書いていなければ何も言わない。 */
23
35
  export const preferredTerm: Detector = (doc, options): Finding[] => {
24
36
  const pairs = (options.lexicon ?? []).flatMap((entry) => (entry.instead_of === undefined ? [] : [{ entry, avoid: entry.pattern, use: entry.instead_of }]));
25
- const hits = doc.sentences.flatMap((sentence) =>
26
- pairs.flatMap((pair) => avoidedStarts(sentence, pair.entry, pair.use).map((at) => ({ sentence, at, pair }))),
27
- );
37
+ const hits = doc.sentences.flatMap((sentence) => sentenceHits(sentence, pairs));
28
38
  if (hits.length === 0 || hits.length < options.limit) return [];
29
39
  return hits.map((hit) => ({
30
40
  rule: "",
@@ -32,7 +42,7 @@ export const preferredTerm: Detector = (doc, options): Finding[] => {
32
42
  line: 0,
33
43
  column: 0,
34
44
  quote: hit.sentence.text.trim(),
35
- values: { matched: hit.pair.avoid, preferred: hit.pair.use, count: hits.length, limit: options.limit, offset: hit.sentence.span.start + hit.at },
45
+ values: { matched: hit.pair.avoid, preferred: hit.pair.use, count: hits.length, limit: options.limit, offset: hit.sentence.span.start + hit.span.start },
36
46
  }));
37
47
  };
38
48
 
@@ -167,6 +167,19 @@ const opensAsNoun = (scope: ItemScope, item: TokenRange): boolean => {
167
167
  /** 項目が読点で閉じず、節の終わり(文の終わりか ; : —)まで続く。 */
168
168
  const runsToClauseEnd = (scope: ItemScope, item: TokenRange): boolean => scope.sentence.tokens[item.end]?.surface !== ",";
169
169
 
170
+ /**
171
+ * 名前のすぐ後ろの、関係詞(who / which)で始まる項目は、読点で挟んで名前に添えた節(Tom, who repaired radios for forty years
172
+ * before he retired, gently opened the back and quickly found a loose wire)。名前も節も並びの項目ではなく、並びがあるなら節の後ろから
173
+ * (Alice, who leads design, Bob, Carol, and Dan は Bob からの 3 つ)。関係詞の語は語彙表 aside-relative が言う。
174
+ */
175
+ const afterRelativeAside = (view: View): View => {
176
+ const { scope } = view.list;
177
+ const [name, aside] = [firstOf(view), secondOf(view)];
178
+ if (name === undefined || aside === undefined || !opensAsNoun(scope, name.item)) return view;
179
+ const opening = openingOf(scope, aside.item)?.surface.toLowerCase() ?? "";
180
+ return scope.sentence.words.asideRelative?.has(opening) === true ? after(view, aside) : view;
181
+ };
182
+
170
183
  const opensAsPredicate = (scope: ItemScope, item: TokenRange): boolean => {
171
184
  const opening = openingOf(scope, item);
172
185
  return opening !== undefined && VERBAL.has(opening.pos) && !isParticiple(opening);
@@ -360,7 +373,7 @@ const listAt = (list: ItemList, at: number, walk: Walk): boolean | undefined =>
360
373
  const { scope } = list;
361
374
  if (closesExampleAside(wholeList(list), at)) return undefined;
362
375
  const afterItem = itemAfter(scope, at);
363
- const opened = afterClosedList(withoutLead(afterVerbAside(afterClauseTurn(withoutCoordinateAdjective(wholeList(list)), afterItem))));
376
+ const opened = afterClosedList(withoutLead(afterRelativeAside(afterVerbAside(afterClauseTurn(withoutCoordinateAdjective(wholeList(list)), afterItem)))));
364
377
  const items = fromParticiplePhrase(fromExample(opened, afterItem), afterItem);
365
378
  if (listContinues(scope, afterItem, walk) || isAppositive(scope, at, items, afterItem) || insideLastItem(scope, at, items, afterItem)) return undefined;
366
379
  if (namesDivision(items) || qualifiesPrevious(items)) return undefined;
@@ -420,6 +433,7 @@ export const oxfordComma: Detector = (doc, options): Finding[] => {
420
433
  indefinite: patternsOf(doc.lexicons["indefinite-article"]),
421
434
  elision: (doc.lexicons["elision-mark"] ?? []).map((entry) => entry.pattern),
422
435
  openListEnd: patternsOf(doc.lexicons["open-list-end"]),
436
+ asideRelative: patternsOf(doc.lexicons["aside-relative"]),
423
437
  };
424
438
  const judged = doc.sentences.flatMap((sentence) => {
425
439
  const oxford = oxfordIn(sentence.tokens ?? [], words, doc.source);
@@ -2,7 +2,7 @@ import type { Detector, Finding } from "../plugin.ts";
2
2
  import { oneSentenceRuns } from "../paragraph-runs.ts";
3
3
  import { referenceListSpans } from "../reference-lists.ts";
4
4
 
5
- /** How much of the run's first paragraph the finding quotes. */
5
+ /** How much of the run's first paragraph the finding quotes when it holds no sentence; it never runs past the paragraph. */
6
6
  const QUOTE_LENGTH = 80;
7
7
 
8
8
  /**
@@ -29,7 +29,7 @@ export const oneSentenceParagraphRun: Detector = (doc, options): Finding[] =>
29
29
  severity: "info",
30
30
  line: 0,
31
31
  column: 0,
32
- quote: doc.source.slice(first.span.start, first.span.start + QUOTE_LENGTH).trim(),
32
+ quote: first.sentences[0]?.text.trim() ?? doc.source.slice(first.span.start, Math.min(first.span.start + QUOTE_LENGTH, first.span.end)).trim(),
33
33
  values: { count: run.length, limit: options.limit, offset: first.span.start },
34
34
  },
35
35
  ];
@@ -7,7 +7,8 @@ import type { Detector, Finding } from "../plugin.ts";
7
7
  export const phoneNumberVariant: Detector = (doc, options): Finding[] => {
8
8
  const labels = options.lexicon ?? [];
9
9
  if (labels.length === 0) return [];
10
- return phoneVariants(labelledPhoneNumbers(doc.prose ?? doc.source, labels)).map(({ number, other }) => ({
10
+ const links = (doc.lexicons["phone-label-link"] ?? []).map((entry) => entry.pattern);
11
+ return phoneVariants(labelledPhoneNumbers(doc.prose ?? doc.source, labels, links)).map(({ number, other }) => ({
11
12
  rule: "",
12
13
  severity: "info",
13
14
  line: 0,
@@ -0,0 +1,19 @@
1
+ // A worn phrase whose words also have a plain sense ("Empty the tray at the end of the day", "Every version is on the
2
+ // same page") counts only where its sentence reads it as the figure. The language's word list gives, for each such
3
+ // phrase (group), regular expressions of the figurative use; a phrase without any counts everywhere. Pure.
4
+ import type { LexiconEntry, Sentence } from "../plugin.ts";
5
+
6
+ export type PhraseContexts = ReadonlyMap<string, readonly RegExp[]>;
7
+
8
+ export const phraseContextsOf = (entries: readonly LexiconEntry[]): PhraseContexts =>
9
+ entries.reduce((contexts, entry) => {
10
+ const phrase = entry.group?.toLowerCase();
11
+ if (phrase === undefined) return contexts;
12
+ return new Map([...contexts, [phrase, [...(contexts.get(phrase) ?? []), new RegExp(entry.pattern, "iu")]]]);
13
+ }, new Map<string, readonly RegExp[]>());
14
+
15
+ /** Whether the sentence uses the entry as the figure: no context listed for it, or one of its contexts matches. */
16
+ export const inFigurativeContext = (sentence: Sentence, entry: LexiconEntry, contexts: PhraseContexts): boolean => {
17
+ const patterns = contexts.get(entry.pattern.toLowerCase());
18
+ return patterns === undefined || patterns.some((pattern) => pattern.test(sentence.text));
19
+ };
@@ -0,0 +1,57 @@
1
+ import type { Detector, Finding, Lexicon, Sentence } from "../plugin.ts";
2
+ import { entryEnds } from "./lexicon-match.ts";
3
+ import { quotedPattern } from "./quoted-pattern.ts";
4
+
5
+ /**
6
+ * phrase-match の、文の中の違う言い回しをみな名指す版。指摘は phrase-match と同じく文ごとに一つで、位置も文の頭。
7
+ * 一つの文に「ないわけではありません」と「ないとは限りません」があれば、一つ目だけを言うと二つ目を直し忘れる。
8
+ * 重なる二つの語が同じ位置で終われば一回で、名指すのは語彙表で先に書いた語。並びは文の中で終わる順。
9
+ */
10
+ type Named = { readonly sentence: Sentence; readonly phrases: readonly string[] };
11
+
12
+ const firstEnds = (sentence: Sentence, lexicon: Lexicon): { readonly phrase: string; readonly end: number }[] =>
13
+ lexicon.flatMap((entry) => {
14
+ const ends = entryEnds(sentence, entry);
15
+ return ends.length === 0 ? [] : [{ phrase: quotedPattern(entry.pattern), end: Math.min(...ends) }];
16
+ });
17
+
18
+ const phrasesIn = (sentence: Sentence, lexicon: Lexicon): string[] => {
19
+ const byEnd = new Map<number, string>();
20
+ firstEnds(sentence, lexicon).forEach(({ phrase, end }) => {
21
+ if (!byEnd.has(end)) byEnd.set(end, phrase);
22
+ });
23
+ const ordered = [...byEnd].toSorted(([left], [right]) => left - right).map(([, phrase]) => phrase);
24
+ return [...new Set(ordered)];
25
+ };
26
+
27
+ /** 違う言い回しが二つなら both、三つ以上なら many の文言。 */
28
+ const variantOf = (kinds: number): Pick<Finding, "variant"> => {
29
+ if (kinds === 2) return { variant: "both" };
30
+ return kinds > 2 ? { variant: "many" } : {};
31
+ };
32
+
33
+ const findingOf = ({ sentence, phrases }: Named, count: number, limit: number): Finding => ({
34
+ rule: "",
35
+ severity: "warning",
36
+ line: 0,
37
+ column: 0,
38
+ quote: sentence.text.trim(),
39
+ ...variantOf(phrases.length),
40
+ values: {
41
+ matched: phrases[0] ?? "",
42
+ ...(phrases.length > 1 ? { other: phrases[1] ?? "", kinds: phrases.length } : {}),
43
+ count,
44
+ limit,
45
+ offset: sentence.span.start,
46
+ },
47
+ });
48
+
49
+ export const phraseMatchAll: Detector = (doc, options): Finding[] => {
50
+ const lexicon = options.lexicon ?? [];
51
+ if (lexicon.length === 0) return [];
52
+ const named = doc.sentences.flatMap((sentence) => {
53
+ const phrases = phrasesIn(sentence, lexicon);
54
+ return phrases.length === 0 ? [] : [{ sentence, phrases }];
55
+ });
56
+ return named.length < options.limit ? [] : named.map((item) => findingOf(item, named.length, options.limit));
57
+ };
@@ -1,7 +1,9 @@
1
1
  import type { Detector, DetectorOptions, Finding, Lexicon, LexiconEntry, ProseDocument, Sentence } from "../plugin.ts";
2
- import { entryEnds, entryIn, entryOpens } from "./lexicon-match.ts";
2
+ import { entryEnds, entryIn, entryOpens, entryRanges, entryWrittenIn } from "./lexicon-match.ts";
3
3
  import { externalLinkTitleSpans } from "../link-title.ts";
4
+ import { referenceListSpans } from "../reference-lists.ts";
4
5
  import { mentionCuesOf, onlyInTitles, onlyMentioned } from "./mentioned-phrase.ts";
6
+ import { inFigurativeContext, phraseContextsOf } from "./phrase-context.ts";
5
7
  import { closingSentences } from "../closing-paragraph.ts";
6
8
  import { quotedPattern } from "./quoted-pattern.ts";
7
9
 
@@ -23,12 +25,28 @@ type Hit = { readonly sentence: Sentence; readonly matched: string };
23
25
  /** Whether the entry's words in the sentence count as a use. phrase-match counts every one. */
24
26
  type IsUsed = (sentence: Sentence, entry: LexiconEntry) => boolean;
25
27
 
28
+ /** Some place of the entry in the sentence is not followed by a word of a part of speech the entry names in not_before_pos. Without tokens every place counts. */
29
+ const freeOfNextWord = (sentence: Sentence, entry: LexiconEntry): boolean => {
30
+ const blocked = entry.not_before_pos;
31
+ const tokens = sentence.tokens;
32
+ const ranges = entryRanges(sentence, entry);
33
+ if (blocked === undefined || tokens === undefined || ranges.length === 0) return true;
34
+ return ranges.some((range) => !blocked.includes(tokens[range.end]?.pos ?? ""));
35
+ };
36
+
26
37
  /** An entry marked opens counts only at the head of the sentence: 「近年、」 opens a stock opening, 「その後、近年の」 is a plain word. */
27
- const writtenIn = (sentence: Sentence, entry: LexiconEntry): boolean => (entry.opens === true ? entryOpens(sentence, entry) : entryIn(sentence, entry));
38
+ const writtenIn = (sentence: Sentence, entry: LexiconEntry): boolean =>
39
+ (entry.opens === true ? entryOpens(sentence, entry) : entryIn(sentence, entry)) && freeOfNextWord(sentence, entry);
40
+
41
+ /** The entry the sentence holds; one written in the very form (reverted back) wins over one met through its base form (revert back). */
42
+ const entryHeldBy = (sentence: Sentence, lexicon: Lexicon, isUsed: IsUsed): LexiconEntry | undefined => {
43
+ const held = lexicon.filter((entry) => writtenIn(sentence, entry) && isUsed(sentence, entry));
44
+ return held.find((entry) => entryWrittenIn(sentence, entry)) ?? held[0];
45
+ };
28
46
 
29
47
  const hitsIn = (sentences: readonly Sentence[], lexicon: Lexicon, isUsed: IsUsed = () => true): Hit[] =>
30
48
  sentences.flatMap((sentence) => {
31
- const matched = lexicon.find((entry) => writtenIn(sentence, entry) && isUsed(sentence, entry));
49
+ const matched = entryHeldBy(sentence, lexicon, isUsed);
32
50
  return matched === undefined ? [] : [{ sentence, matched: quotedPattern(matched.pattern) }];
33
51
  });
34
52
 
@@ -64,12 +82,19 @@ export const phraseMatchWhere = (doc: ProseDocument, options: DetectorOptions, i
64
82
 
65
83
  /**
66
84
  * phrase-match の、言葉として名指しただけの言い回し(the phrase "…", 「…」という言い方)を数えない版(mentioned-phrase.ts)。
67
- * 参考文献のリンクに写した外のページの題名([文章の極意は…](https://…))の言い回しも、書き手の言葉ではないので数えない。
85
+ * 参考文献のリンクに写した外のページの題名([文章の極意は…](https://…))と、文献一覧に写した著作の題の言い回しも、書き手の言葉ではないので数えない。
86
+ * 字どおりの意味にも読める言い回し(at the end of the day)は、cliche-figurative が言う比喩の文脈の文だけで数える(phrase-context.ts)。
68
87
  */
69
88
  export const phraseInUse: Detector = (doc, options): Finding[] => {
70
89
  const cues = mentionCuesOf(doc.lexicons["mention-cue"] ?? []);
71
- const titles = externalLinkTitleSpans(doc.source, doc.links);
72
- const hits = phraseHits(doc, options, (sentence, entry) => !onlyMentioned(sentence, entry, cues) && !onlyInTitles(sentence, entry, titles));
90
+ const headings = (doc.lexicons["reference-list-heading"] ?? []).map((entry) => entry.pattern);
91
+ const titles = [...externalLinkTitleSpans(doc.source, doc.links), ...referenceListSpans(doc.source, headings)];
92
+ const figurative = phraseContextsOf(doc.lexicons["cliche-figurative"] ?? []);
93
+ const hits = phraseHits(
94
+ doc,
95
+ options,
96
+ (sentence, entry) => !onlyMentioned(sentence, entry, cues) && !onlyInTitles(sentence, entry, titles) && inFigurativeContext(sentence, entry, figurative),
97
+ );
73
98
  return hits.length < options.limit ? [] : findingsOf(hits, options.limit);
74
99
  };
75
100
 
@@ -31,6 +31,7 @@ const withoutClosers = (text: string): string => {
31
31
  const MARKER = "marker";
32
32
  const INSTRUCTION = "instruction";
33
33
  const LABEL = "label";
34
+ const CLOSING = "closing";
34
35
 
35
36
  const innerOf = (match: RegExpExecArray): string => (match[1] ?? match[2] ?? match[3] ?? "").trim().toLowerCase();
36
37
 
@@ -41,13 +42,27 @@ const holdsWord = (inner: string, words: Lexicon): boolean =>
41
42
  return inner === pattern || (inner.startsWith(pattern) && /^[\s'’]/u.test(inner.slice(pattern.length)));
42
43
  });
43
44
 
45
+ /** A bracket a closing word ends: two to four words, each opening with a capital ([Candidate Name], [Start Date]). */
46
+ const TITLED_BLANK = /^(?:\p{Lu}[\p{L}'’-]*\s+){1,3}\p{Lu}\p{L}*$/u;
47
+
48
+ const rawInnerOf = (match: RegExpExecArray): string => (match[1] ?? match[2] ?? match[3] ?? "").trim();
49
+
50
+ /**
51
+ * 括弧の中身が、語彙表の closing の語で終わる、語の頭がみな大文字の二語から四語か([Candidate Name]、[Start Date])。
52
+ * 小文字の語を挟む編者の補い([the defendant's name])や一語の注記([sic])は空欄ではない。
53
+ */
54
+ const endsWithWord = (inner: string, words: Lexicon): boolean =>
55
+ TITLED_BLANK.test(inner) && words.some((word) => inner.toLowerCase().endsWith(` ${word.pattern.toLowerCase()}`));
56
+
44
57
  /** 括弧の中身が指示の書き出しで始まるか(ここに会社名を書く)。 */
45
58
  const opensWith = (inner: string, words: Lexicon): boolean => words.some((word) => inner.startsWith(word.pattern.toLowerCase()));
46
59
 
47
60
  const spanOf = (match: RegExpExecArray): Span => ({ start: match.index, end: match.index + match[0].length });
48
61
 
49
- const bracketedSpans = (text: string, pattern: RegExp, holds: (inner: string) => boolean): Span[] =>
50
- [...text.matchAll(pattern)].filter((match) => !FILLED_AFTER.test(text.slice(match.index + match[0].length)) && holds(innerOf(match))).map(spanOf);
62
+ const bracketedSpans = (text: string, pattern: RegExp, holds: (inner: string, raw: string) => boolean): Span[] =>
63
+ [...text.matchAll(pattern)]
64
+ .filter((match) => !FILLED_AFTER.test(text.slice(match.index + match[0].length)) && holds(innerOf(match), rawInnerOf(match)))
65
+ .map(spanOf);
51
66
 
52
67
  /**
53
68
  * A value left as a marker: the whole text is the marker ("TBD", 「未定」), or the marker opens it before a colon
@@ -163,13 +178,14 @@ export const placeholderSpans = (text: string, words: Lexicon): Span[] => {
163
178
  const instructions = words.filter((word) => word.group === INSTRUCTION);
164
179
  const markers = words.filter((word) => word.group === MARKER);
165
180
  const labels = words.filter((word) => word.group === LABEL);
181
+ const closings = words.filter((word) => word.group === CLOSING);
166
182
  const blankWords = {
167
183
  suffixes: words.filter((word) => word.group === BLANK_SUFFIX),
168
184
  prefixes: words.filter((word) => word.group === BLANK_PREFIX),
169
185
  units: words.filter((word) => word.group === BLANK_UNIT),
170
186
  };
171
187
  return [
172
- ...bracketedSpans(text, BRACKETED, (inner) => holdsWord(inner, bracketWords)),
188
+ ...bracketedSpans(text, BRACKETED, (inner, raw) => holdsWord(inner, bracketWords) || endsWithWord(raw, closings)),
173
189
  ...(instructions.length === 0 ? [] : bracketedSpans(text, PARENTHESIZED, (inner) => opensWith(inner, instructions))),
174
190
  ...lineMarkerSpans(text, markers, labels),
175
191
  ...blankMarkSpans(text, blankWords),
@@ -88,22 +88,30 @@ export const namesIn = (sentence: Sentence, listed: readonly string[], everyday:
88
88
 
89
89
  const everydayNamesOf = (doc: ProseDocument): string[] => (doc.lexicons[EVERYDAY_NAME] ?? []).map((entry) => entry.pattern);
90
90
 
91
+ type Named = { readonly sentence: Sentence; readonly names: readonly Token[] };
92
+
93
+ /** The sentence holding the most names, the first of equals: where the reader loses the sentence's shape, not where the first name is. */
94
+ const densest = (named: readonly Named[]): Named | undefined =>
95
+ named.reduce<Named | undefined>((best, entry) => (best === undefined || entry.names.length > best.names.length ? entry : best), undefined);
96
+
91
97
  export const properNounDensity: Detector = (doc, options): Finding[] => {
92
98
  const prose = doc.sentences.filter(isProse);
93
99
  const everyday = everydayNamesOf(doc);
94
- const hits = prose.flatMap((sentence) => namesIn(sentence, doc.names ?? [], everyday).map((token) => ({ sentence, token })));
100
+ const named = prose.map((sentence) => ({ sentence, names: namesIn(sentence, doc.names ?? [], everyday) })).filter((entry) => entry.names.length > 0);
101
+ const count = named.reduce((sum, entry) => sum + entry.names.length, 0);
95
102
  const length = prose.reduce((sum, sentence) => sum + lengthOf(sentence, doc.lengthUnit), 0);
96
- const rate = length === 0 ? 0 : Math.round((hits.length / length) * PER);
97
- const first = hits[0];
98
- if (length < FLOOR[doc.lengthUnit] || first === undefined || rate <= options.limit) return [];
103
+ const rate = length === 0 ? 0 : Math.round((count / length) * PER);
104
+ const at = densest(named);
105
+ const first = at?.names[0];
106
+ if (length < FLOOR[doc.lengthUnit] || at === undefined || first === undefined || rate <= options.limit) return [];
99
107
  return [
100
108
  {
101
109
  rule: "proper-noun-density",
102
110
  severity: "info",
103
111
  line: 0,
104
112
  column: 0,
105
- quote: proseText(first.sentence),
106
- values: { count: hits.length, density: rate, limit: options.limit, offset: first.token.span.start },
113
+ quote: proseText(at.sentence),
114
+ values: { count, density: rate, limit: options.limit, offset: first.span.start },
107
115
  },
108
116
  ];
109
117
  };
@@ -1,3 +1,5 @@
1
+ import type { Sentence } from "../plugin.ts";
2
+
1
3
  /** 見せる前後の字数。記号 1 つの指摘は、周りの言葉が無いとどこか分からない。 */
2
4
  const QUOTE_REACH = 20;
3
5
 
@@ -7,3 +9,7 @@ export const quoteAround = (text: string, start: number, end: number = start + 1
7
9
  .slice(Math.max(0, start - QUOTE_REACH), end + QUOTE_REACH)
8
10
  .replace(/\s+/gu, " ")
9
11
  .trim();
12
+
13
+ /** The sentence holding offset, trimmed: a reader sees whole words, as for the rules that quote their sentence. undefined outside every sentence. */
14
+ export const sentenceQuoteAt = (sentences: readonly Sentence[], offset: number): string | undefined =>
15
+ sentences.find((sentence) => sentence.span.start <= offset && offset < sentence.span.end)?.text.trim();
@@ -1,7 +1,7 @@
1
1
  import type { Detector, Finding } from "../plugin.ts";
2
2
  import { escapeRegExp } from "../orthography.ts";
3
3
  import { formMinority } from "./form-minority.ts";
4
- import { quoteAround } from "./quote-around.ts";
4
+ import { quoteAround, sentenceQuoteAt } from "./quote-around.ts";
5
5
 
6
6
  // 一つの文書で、数の範囲を二通りの記号で書いた所(10〜20 と 10-20、10–20 と 10-20)。どちらが正しいかは決めず、少ないほうを指す。
7
7
  // 範囲の記号は語彙表 range-notation が言う。
@@ -90,7 +90,7 @@ export const rangeNotation: Detector = (doc, options): Finding[] => {
90
90
  severity: "info",
91
91
  line: 0,
92
92
  column: 0,
93
- quote: quoteAround(text, range.offset, range.offset + range.written.length),
93
+ quote: sentenceQuoteAt(doc.sentences, range.offset) ?? quoteAround(text, range.offset, range.offset + range.written.length),
94
94
  values: { written: range.written, mark: range.form, usual: minority.usual.written, count: minority.odd.length, of: ranges.length, offset: range.offset },
95
95
  }));
96
96
  };
@@ -0,0 +1,4 @@
1
+ import type { Detector } from "../../plugin.ts";
2
+ import { phraseMatchAll } from "../phrase-match-all.ts";
3
+
4
+ export const detector: Detector = phraseMatchAll;
@@ -16,6 +16,8 @@ const valuedOf = (doc: ProseDocument, lexicon: string, group?: string): ValuedWo
16
16
  const wordsOf = (doc: ProseDocument): RequirementWords => ({
17
17
  required: patternsOf(doc, "requirement-heading", "required"),
18
18
  preferred: patternsOf(doc, "requirement-heading", "preferred"),
19
+ subjects: patternsOf(doc, "requirement-heading", "subject"),
20
+ joiners: patternsOf(doc, "requirement-heading", "joiner"),
19
21
  units: valuedOf(doc, "requirement-length-unit"),
20
22
  before: patternsOf(doc, "requirement-length-word", "before"),
21
23
  after: patternsOf(doc, "requirement-length-word", "after"),
@@ -1,4 +1,4 @@
1
- import type { Detector, DetectorOptions, Finding, Lexicon, ProseDocument, Sentence, Span, Token } from "../plugin.ts";
1
+ import type { Detector, DetectorOptions, Finding, LengthUnit, Lexicon, ProseDocument, Sentence, Span, Token } from "../plugin.ts";
2
2
  import { escapeRegExp } from "../orthography.ts";
3
3
  import { isWithinAny, quotedIn } from "../quoted-span.ts";
4
4
  import { entryOpens } from "./lexicon-match.ts";
@@ -222,14 +222,17 @@ export const CONTINUING_LEXICON = "demonstrative-continuing";
222
222
  const runCount = (run: readonly Opened[], continuing: ReadonlySet<string>): number =>
223
223
  run.filter((opened, at) => !(opened.opener !== undefined && continuing.has(opened.opener) && run[at - 1]?.opener === opened.opener)).length;
224
224
 
225
- const runFinding = (run: readonly Opened[], count: number, options: DetectorOptions): Finding => {
225
+ /** Words are set apart by spaces, so sentences quoted together are too (…small purchases. This means …); characters are not. */
226
+ const joinerOf = (unit: LengthUnit): string => (unit === "char" ? "" : " ");
227
+
228
+ const runFinding = (run: readonly Opened[], count: number, options: DetectorOptions, unit: LengthUnit): Finding => {
226
229
  const first = run[0];
227
230
  return {
228
231
  rule: "",
229
232
  severity: "info",
230
233
  line: 0,
231
234
  column: 0,
232
- quote: run.map(({ sentence }) => sentence.text.trim()).join(""),
235
+ quote: run.map(({ sentence }) => sentence.text.trim()).join(joinerOf(unit)),
233
236
  values: { word: first?.opener ?? "", count, limit: options.limit, offset: first?.sentence.span.start ?? 0 },
234
237
  };
235
238
  };
@@ -243,6 +246,6 @@ export const openerRun: Detector = (doc, options): Finding[] => {
243
246
  openerRuns(paragraph.sentences, lexicon, notOpeners)
244
247
  .map((run) => ({ run, count: runCount(run, continuing) }))
245
248
  .filter(({ count }) => count > options.limit)
246
- .map(({ run, count }) => runFinding(run, count, options)),
249
+ .map(({ run, count }) => runFinding(run, count, options, doc.lengthUnit)),
247
250
  );
248
251
  };
@@ -28,6 +28,16 @@ type SentenceWords = {
28
28
  const unwrittenWords = (sentence: Sentence, text: string, listItems: SentenceWords["listItems"]): number =>
29
29
  termSeriesSaving(text) + authorListSaving(text) + (isInListItem(sentence.span, listItems) || isReferenceLine(text) ? quotedTitleWords(text) : 0);
30
30
 
31
+ /**
32
+ * A comma or a stop typed with one space before it ("the same brick , and"). It is no word of its own. One space only:
33
+ * the spaces that hide markup ("**TITLE**.", "[link](url),") are left counted, as the measure has always read them.
34
+ */
35
+ const TYPED_LOOSE_STOP = /(?<=[\p{L}\p{N}]) [,.;:!?]+(?=\s|$)/gu;
36
+
37
+ /** A sentence's length; where words are the unit, a typed loose comma or stop is not counted. */
38
+ const sentenceSize = (sentence: Sentence, unit: LengthUnit): number =>
39
+ lengthOf(sentence, unit) - (unit === "word" ? [...sentence.text.matchAll(TYPED_LOOSE_STOP)].length : 0);
40
+
31
41
  const sizeOf = (text: string, unit: LengthUnit): number =>
32
42
  unit === "word" ? text.split(/\s+/u).filter((word) => word.length > 0).length : text.replace(/\s+/gu, "").length;
33
43
 
@@ -48,7 +58,7 @@ const measureOf = (sentence: Sentence, unit: LengthUnit, options: DetectorOption
48
58
  const embedded = sentence.embeddedLanguage;
49
59
  const limit = embedded === undefined ? undefined : options.embeddedLimits?.[embedded.id];
50
60
  if (embedded === undefined || limit === undefined) return { size: ownSize(sentence, unit, words), limit: options.limit };
51
- return { size: lengthOf(sentence, embedded.lengthUnit), limit, variant: `embedded-${embedded.id}` };
61
+ return { size: sentenceSize(sentence, embedded.lengthUnit), limit, variant: `embedded-${embedded.id}` };
52
62
  };
53
63
 
54
64
  /** Code or a citation string: nothing in it is the writer's sentence. A title line too, where words are the unit. */
@@ -70,7 +80,7 @@ const ownSize = (sentence: Sentence, unit: LengthUnit, words: SentenceWords): nu
70
80
  const remark = unit === "word" ? remarkAfterTitle(text) : undefined;
71
81
  if (remark !== undefined) return sizeOf(remark, unit);
72
82
  const unwritten = unit === "word" ? unwrittenWords(sentence, text, words.listItems) : 0;
73
- const size = lengthOf(sentence, unit) - pageMarkerSize(text, words.markers, unit) - unwritten;
83
+ const size = sentenceSize(sentence, unit) - pageMarkerSize(text, words.markers, unit) - unwritten;
74
84
  return unit === "char" ? longestQuotedPart(text, size, words.markers) : size;
75
85
  };
76
86
 
@@ -322,12 +322,21 @@ export const undefinedAcronym: Detector = (doc, options): Finding[] => {
322
322
  return alone.map(([acronym, hit]) => acronymFinding(acronym, hit, alone.length, options.limit));
323
323
  };
324
324
 
325
+ /** 二つ重ねて一本に組むダッシュ(——、――)。重ねた二つ目からは、同じ一本の続き。 */
326
+ const DOUBLED_DASH = /[—―]/u;
327
+ const continuesDash = (source: string, offset: number): boolean => DOUBLED_DASH.test(source[offset] ?? "") && DOUBLED_DASH.test(source[offset - 1] ?? "");
328
+
329
+ /** 重ねたダッシュの最後の字の位置。段落の終わりで箇条を導くかは、そこから後ろで見る。 */
330
+ const dashEnd = (source: string, offset: number): number => (continuesDash(source, offset + 1) ? dashEnd(source, offset + 1) : offset);
331
+
325
332
  /**
326
333
  * ダッシュの多用。英語では正当な用法が多いが、2026 年時点で最も知られた生成文のシグナルでもある。
327
334
  * 日本語の組版ではそもそも扱いが難しい。どちらが正しいかは severity の言語別指定で分ける。spec §12.4。
328
335
  */
329
336
  export const dashDensity: Detector = (doc, options): Finding[] => {
330
- const hits = findIn(doc, DASH).filter((hit) => !introducesList(doc.source, hit.offset) && !opensLine(doc.source, hit.offset));
337
+ const hits = findIn(doc, DASH).filter(
338
+ (hit) => !continuesDash(doc.source, hit.offset) && !introducesList(doc.source, dashEnd(doc.source, hit.offset)) && !opensLine(doc.source, hit.offset),
339
+ );
331
340
  const first = hits[0];
332
341
  const rate = density(doc, hits.length);
333
342
  if (wordsOf(doc) < MIN_DOCUMENT_LENGTH[doc.lengthUnit] || first === undefined || rate <= options.limit) return [];