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
@@ -2,7 +2,7 @@ import type { Detector, Finding, ProseDocument } from "../plugin.ts";
2
2
  import { escapeRegExp } from "../orthography.ts";
3
3
  import { formMinority } from "./form-minority.ts";
4
4
  import { proseAndTablesOf } from "../table-text.ts";
5
- import { quoteAround } from "./quote-around.ts";
5
+ import { quoteAround, sentenceQuoteAt } from "./quote-around.ts";
6
6
 
7
7
  // 一つの文書で、同じ通貨の金額を二通りに書いた所(1,000円 と ¥1,000、$20 と 20 dollars)。どちらが正しいかは決めず、少ないほうを指す。
8
8
  // 通貨の書き方、それを金額のどちら側に書くか、どの通貨か(group)は語彙表 currency-notation、桁の語は amount-multiplier が言う。
@@ -85,7 +85,7 @@ export const currencyNotation: Detector = (doc, options): Finding[] => {
85
85
  severity: "info",
86
86
  line: 0,
87
87
  column: 0,
88
- quote: quoteAround(text, odd.offset, odd.offset + odd.written.length),
88
+ quote: sentenceQuoteAt(doc.sentences, odd.offset) ?? quoteAround(text, odd.offset, odd.offset + odd.written.length),
89
89
  values: { written: odd.written.trim(), usual: usual.trim(), count, of, offset: odd.offset },
90
90
  }));
91
91
  };
@@ -267,9 +267,20 @@ const isLongName = (name: string): boolean => {
267
267
  return !LATIN.test(name) || JAPANESE.test(name) || (words.length >= MIN_NAME_WORDS && words.some((word) => UPPER_START.test(word)));
268
268
  };
269
269
 
270
- /** A conjunction that joins the run to a name before it (書面または電磁的記録(以下「書面等」)): the bracket names them all. */
271
- const joinsList = (token: Token | undefined, joiners: readonly string[]): boolean =>
272
- token !== undefined && token.pos === "CCONJ" && joiners.includes(token.surface.toLowerCase());
270
+ const CLOSING_BRACKETS = new Set([")", ")"]);
271
+ const COMMAS = new Set([",", "、", ","]);
272
+
273
+ /**
274
+ * A conjunction that joins the run to a name before it (書面または電磁的記録(以下「書面等」)): the bracket names them all.
275
+ * Right after another definition's bracket (Brookside Ltd (the "Client") and Harbour Works Ltd (the "Supplier")) it joins
276
+ * two parties, each given its own short name.
277
+ */
278
+ const joinsList = (tokens: readonly Token[], at: number, joiners: readonly string[]): boolean => {
279
+ const token = tokens[at];
280
+ if (token === undefined || token.pos !== "CCONJ" || !joiners.includes(token.surface.toLowerCase())) return false;
281
+ const before = tokens.slice(0, at).findLast((candidate) => !COMMAS.has(candidate.surface));
282
+ return before === undefined || !CLOSING_BRACKETS.has(before.surface);
283
+ };
273
284
 
274
285
  /**
275
286
  * The long name written right before an inline definition: the run of name words that ends at its opening bracket. A run
@@ -279,7 +290,7 @@ export const nameBefore = (sentence: Sentence, bracket: number, joiners: readonl
279
290
  if (LABELS_THE_CLAUSE.test(sentence.text.slice(bracket - sentence.span.start))) return undefined;
280
291
  const tokens = (sentence.tokens ?? []).filter((token) => token.span.end <= bracket);
281
292
  const firstOfRun = tokens.findLastIndex((token) => !isNamePart(token)) + 1;
282
- if (isModifier(tokens[firstOfRun - 1]) || joinsList(tokens[firstOfRun - 1], joiners)) return undefined;
293
+ if (isModifier(tokens[firstOfRun - 1]) || joinsList(tokens, firstOfRun - 1, joiners)) return undefined;
283
294
  const run = tokens.slice(firstOfRun).filter((token, index, all) => index > 0 || !NAME_MARKS.has(token.surface) || all.length === 1);
284
295
  const first = run[0];
285
296
  const end = run.at(-1);
@@ -80,14 +80,11 @@ const ownDefinitions = (tree: StructureNode): DefinedTerm[] => {
80
80
  export const useBeforeDefinition: Detector = (doc): Finding[] =>
81
81
  doc.structure === undefined
82
82
  ? []
83
- : usesBeforeDefinition(
84
- ownDefinitions(doc.structure),
85
- bodyOf(doc),
86
- mentionedIn(doc),
87
- titleIn(doc),
88
- patternsOf(doc, "self-prefix"),
89
- patternsOf(doc, "term-source-marker"),
90
- ).map((use) => findingAt(doc, use.offset, { term: use.term.term, defined: use.term.line }));
83
+ : usesBeforeDefinition(ownDefinitions(doc.structure), bodyOf(doc), mentionedIn(doc), titleIn(doc), {
84
+ selfPrefixes: patternsOf(doc, "self-prefix"),
85
+ sourceMarkers: patternsOf(doc, "term-source-marker"),
86
+ singleKanjiNames: new Set(patternsOf(doc, "party-short-name")),
87
+ }).map((use) => findingAt(doc, use.offset, { term: use.term.term, defined: use.term.line }));
91
88
 
92
89
  /** 同じ略語を、文書の中で二通りに展開している所。 */
93
90
  export const acronymExpansionConflict: Detector = (doc): Finding[] => {
@@ -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
  // One document writing an ellipsis two ways ("..." and "…", "……" and "・・・"). Neither is called right; the less common is
7
7
  // reported. The forms come from each language's lexicon "ellipsis".
@@ -83,7 +83,7 @@ export const ellipsisConsistency: Detector = (doc, options): Finding[] => {
83
83
  severity: "info",
84
84
  line: 0,
85
85
  column: 0,
86
- quote: quoteAround(text, ellipsis.offset, ellipsis.offset + ellipsis.form.length),
86
+ quote: sentenceQuoteAt(doc.sentences, ellipsis.offset) ?? quoteAround(text, ellipsis.offset, ellipsis.offset + ellipsis.form.length),
87
87
  values: { written: ellipsis.form, usual: minority.usual.form, count: minority.odd.length, of: ellipses.length, offset: ellipsis.offset },
88
88
  }));
89
89
  };
@@ -283,7 +283,7 @@ const nextText = (lines: readonly SourceLine[], index: number): string => {
283
283
  };
284
284
 
285
285
  /** A header field's line (From: Ann). Not any colon: a subject may hold one (Re: Lunch, 10:00 meeting, Q3: budget). */
286
- const isHeaderField = (line: string, headerFields: readonly string[]): boolean => {
286
+ export const isHeaderField = (line: string, headerFields: readonly string[]): boolean => {
287
287
  const name = fieldOf(line)?.name.toLowerCase();
288
288
  return name !== undefined && headerFields.some((field) => field.toLowerCase() === name);
289
289
  };
@@ -67,20 +67,55 @@ export const beforeConcession = (tokens: readonly Token[]): readonly Token[] =>
67
67
  return at === -1 ? tokens : tokens.slice(0, at);
68
68
  };
69
69
 
70
+ /** The words a be can follow in the same verb: a modal (There will be), a perfect's have (There have been), a negation (There has never been). */
71
+ const BEFORE_BE = new Set([
72
+ "will",
73
+ "would",
74
+ "may",
75
+ "might",
76
+ "can",
77
+ "could",
78
+ "should",
79
+ "must",
80
+ "shall",
81
+ "'ll",
82
+ "wo",
83
+ "ca",
84
+ "has",
85
+ "have",
86
+ "had",
87
+ "'ve",
88
+ "'d",
89
+ "not",
90
+ "n't",
91
+ "never",
92
+ ]);
93
+
94
+ /** The be of the verb right after head, past the modal, have and negation before it: There were / There have been / There will not be. */
95
+ const beAfter = (tokens: readonly Token[], head: Token): Token | undefined => {
96
+ const words = tokens.filter((token) => token.span.start >= head.span.end && token.pos !== "PUNCT");
97
+ const at = words.findIndex((token) => !BEFORE_BE.has(token.surface.toLowerCase()));
98
+ const verb = words[at];
99
+ return verb !== undefined && BE.has(verb.lemma ?? verb.surface.toLowerCase()) ? verb : undefined;
100
+ };
101
+
70
102
  /**
71
103
  * There is / It is ... that は、主語を後ろへ押しやって誰が何をするのかを消す。
72
104
  * 「There is a need to review」は、誰が必要としているのかを言っていない。
73
105
  */
74
- const expletiveAt = (tokens: readonly Token[]): Token | undefined => {
106
+ /** The sentence's opening, from There / It through its be: the finding names the form this sentence uses (There were, It was). */
107
+ type Opening = { readonly head: Token; readonly be: Token };
108
+
109
+ const expletiveAt = (tokens: readonly Token[]): Opening | undefined => {
75
110
  const head = tokens.find((token) => token.pos !== "PUNCT");
76
111
  if (head === undefined) return undefined;
77
112
  const lead = head.surface.toLowerCase();
78
113
  if (lead !== "there" && lead !== "it") return undefined;
79
- const next = tokens.find((token) => token.span.start >= head.span.end && token.pos !== "PUNCT");
80
- if (next === undefined || !BE.has(next.lemma ?? next.surface.toLowerCase())) return undefined;
114
+ const be = beAfter(tokens, head);
115
+ if (be === undefined) return undefined;
81
116
  // "it is" は "it is raining" のような正当な用法があるので、that 節を伴うときだけ数える。
82
117
  if (lead === "it" && !beforeConcession(tokens).some((token) => token.surface.toLowerCase() === "that")) return undefined;
83
- return head;
118
+ return { head, be };
84
119
  };
85
120
 
86
121
  /** In minutes of who said what, a speaker's sentences are their own phrasing, recorded as said: not the writer's to recast. */
@@ -100,7 +135,7 @@ export const expletive: Detector = (doc, options): Finding[] => {
100
135
  line: 0,
101
136
  column: 0,
102
137
  quote: sentence.text.trim(),
103
- values: { word: at.surface, count: hits.length, limit: options.limit, offset: at.span.start },
138
+ values: { form: doc.source.slice(at.head.span.start, at.be.span.end), count: hits.length, limit: options.limit, offset: at.head.span.start },
104
139
  }));
105
140
  };
106
141
 
@@ -138,6 +138,14 @@ const JA_PART_REFERENCE = /[表図][\d0-9]+(?:[--..][\d0-9]+)*|第[\
138
138
  export const partReferenceSpans = (text: string, unit: LengthUnit): Span[] =>
139
139
  unit === "word" ? spansOf(text, LABEL_AND_NUMBER, (match) => PART_LABELS.has((match[1] ?? "").toLowerCase())) : spansOf(text, JA_PART_REFERENCE, () => true);
140
140
 
141
+ /**
142
+ * 日本語の、数を入れた短い括弧の注((前期比99.6%)、(同101.6%)、(前期は営業損失3,887千円))の範囲。報告は数ごとに比べた数を括弧で
143
+ * 添え、同じ結び(〜となりました。)で閉じる。中身は数で、注に触れる語句は数を並べる書式。長い注は書き手の文なので外さない。
144
+ */
145
+ const JA_FIGURE_ASIDE = /[((][^()()\n]{0,20}[\d0-9][^()()\n]{0,20}[))]/gu;
146
+
147
+ export const figureAsideSpans = (text: string, unit: LengthUnit): Span[] => (unit === "char" ? spansOf(text, JA_FIGURE_ASIDE, () => true) : []);
148
+
141
149
  /**
142
150
  * 角括弧でくくった画面の部品の名前([許可]、[ブックマーク]、[内容を確認]リンク)と、それに付く助詞一つの範囲。画面の手引きは手順ごとに
143
151
  * 違う部品を指して同じ形で書く([…]をクリックすると)。名前にかかる語句と同じく、部品の名前に付いた所からの語句は数えない。
@@ -4,6 +4,7 @@ import { compacted, linkedIn, placeAt } from "./gram-place.ts";
4
4
  import { charWindows, wordWindows } from "./gram-windows.ts";
5
5
  import {
6
6
  fieldLabelSpans,
7
+ figureAsideSpans,
7
8
  fixedEndingSpans,
8
9
  furnitureMask,
9
10
  isFurniture,
@@ -84,7 +85,13 @@ type Context = {
84
85
  /** 数えない範囲: 名前(触れる窓を外す)と、飾り(過半を覆う窓を外す)。 */
85
86
  const excludedIn = (context: Context, sentence: Sentence, text: string, source: ReturnType<typeof compacted>): { named: Span[]; mask: boolean[] } => {
86
87
  const unit = context.doc.lengthUnit;
87
- const named = [...nameSpans(text, context.names), ...fieldLabelSpans(text, unit), ...partReferenceSpans(text, unit), ...screenLabelSpans(text, unit)];
88
+ const named = [
89
+ ...nameSpans(text, context.names),
90
+ ...fieldLabelSpans(text, unit),
91
+ ...partReferenceSpans(text, unit),
92
+ ...figureAsideSpans(text, unit),
93
+ ...screenLabelSpans(text, unit),
94
+ ];
88
95
  const linked = linkedIn(context.doc, sentence, source);
89
96
  const mask = furnitureMask(text, linked);
90
97
  [...fixedEndingSpans(text, context.endings), ...quotedSpans(text), ...quotedClosingSpans(text, context.closings, linked)].forEach((span) =>
@@ -36,9 +36,17 @@ const TITLE_DEPTH = 1;
36
36
 
37
37
  /**
38
38
  * 見出しの頭の番号の札(Section 3. / Day 1: / Part II:)。札の語は流儀によらず大文字で始まり、続く題の語数にも数えない。
39
- * 番号は 3 桁までで、後ろに「.」「:」「)」か ダッシュがあるものだけ(Windows 11 Setup も Budget 2026: も札ではない)。
39
+ * 番号は 3 桁までで、後ろに「.」「:」「)」か ダッシュ、または括弧に入れた題(Rule 1 (Labels))があるものだけ(Windows 11 Setup も Budget 2026: も札ではない)。
40
40
  */
41
- const LEADING_LABEL = /^\s*\p{Lu}\p{Ll}+\s+(?:\d{1,3}(?:\.\d{1,3})*|[IVXLC]+)\s*[.:)\-\u2013\u2014]\s+/u;
41
+ const LABEL_HEAD = /^\s*\p{Lu}\p{Ll}+\s+(?:\d{1,3}(?:\.\d{1,3})*|[IVXLC]+)/u;
42
+ /** What closes the label: a mark and a space, or a space before a bracketed title. */
43
+ const LABEL_END = /^(?:\s*[.:)\-\u2013\u2014]\s+|\s+(?=\())/u;
44
+
45
+ export const withoutLeadingLabel = (heading: string): string => {
46
+ const head = LABEL_HEAD.exec(heading)?.[0];
47
+ const end = head === undefined ? undefined : LABEL_END.exec(heading.slice(head.length))?.[0];
48
+ return head === undefined || end === undefined ? heading : heading.slice(head.length + end.length);
49
+ };
42
50
 
43
51
  /**
44
52
  * 見出しの頭の字や小さいローマ数字の札(a. / b) / iv. / (c))。札は流儀によらず小文字か大文字のまま書くので、語に数えない。
@@ -51,7 +59,7 @@ const LETTER_LABEL = /^\s*\(?(?:[A-Za-z]|[ivxlc]{2,6}|[IVXLC]{2,6})[.)]\s+/u;
51
59
  * どちらの流儀の証拠にもならないので数えない。
52
60
  */
53
61
  export const isTitleCase = (heading: string, fixedCase: ReadonlySet<string> = new Set()): boolean | undefined => {
54
- const words = [...withoutCodeWords(straightApostrophes(heading.replace(LEADING_LABEL, "").replace(LETTER_LABEL, ""))).matchAll(WORD)]
62
+ const words = [...withoutCodeWords(straightApostrophes(withoutLeadingLabel(heading).replace(LETTER_LABEL, ""))).matchAll(WORD)]
55
63
  .map((match) => match[0])
56
64
  .filter((word) => !MINOR_WORDS.has(word.toLowerCase()) && !ACRONYM.test(word) && !fixedCase.has(word));
57
65
  // 1 語の見出しは、どちらの流儀でも先頭が大文字になる。判定できない。
@@ -175,16 +175,40 @@ export const isCitation = (sentence: Sentence, source: string): boolean =>
175
175
 
176
176
  type Tally = { readonly count: number; readonly of: number; readonly limit: number };
177
177
 
178
- const findingOf = (sentence: Sentence, entry: Mark, kind: Kind, tally: Tally): Finding => ({
178
+ /** 少ないほうの書き方の一つの印と、その種類の文書の中の数。 */
179
+ type Odd = { readonly sentence: Sentence; readonly entry: Mark; readonly kind: Kind; readonly tally: Tally };
180
+
181
+ const usualOf = (odd: Odd): string => (odd.entry.western ? odd.kind.usual : odd.kind.western);
182
+
183
+ /** 一つの種類の印。同じ文に同じ書き方が二つあっても、書き方は一つずつ並べる(「,」)。 */
184
+ const markOf = (odds: readonly Odd[]): string => [...new Set(odds.map((odd) => odd.entry.mark))].join("」「");
185
+
186
+ const sentenceFinding = (sentence: Sentence, values: Finding["values"], variant: string): Finding => ({
179
187
  rule: "",
180
188
  severity: "warning",
181
189
  line: 0,
182
190
  column: 0,
183
191
  quote: sentence.text.trim(),
184
- values: { mark: entry.mark, usual: entry.western ? kind.usual : kind.western, ...tally, offset: entry.offset },
185
- variant: entry.kind,
192
+ values,
193
+ variant,
186
194
  });
187
195
 
196
+ /** 一つの文の少ないほうの印。読点と句点の両方なら、一件で両方を言う(貼り付けた文が一つの書き違い)。 */
197
+ const findingOf = (sentence: Sentence, odds: readonly Odd[]): Finding[] => {
198
+ const commas = odds.filter((odd) => odd.kind.id === "comma");
199
+ const periods = odds.filter((odd) => odd.kind.id === "period");
200
+ const [first] = odds;
201
+ const [comma] = commas;
202
+ const [period] = periods;
203
+ if (first === undefined) return [];
204
+ const offset = first.entry.offset;
205
+ if (comma === undefined || period === undefined) {
206
+ return [sentenceFinding(sentence, { mark: markOf(odds), usual: usualOf(first), ...first.tally, offset }, first.kind.id)];
207
+ }
208
+ const periodValues = { periodMark: markOf(periods), periodUsual: usualOf(period), periodCount: period.tally.count, periodOf: period.tally.of };
209
+ return [sentenceFinding(sentence, { mark: markOf(commas), usual: usualOf(comma), ...comma.tally, ...periodValues, offset }, "both")];
210
+ };
211
+
188
212
  const exceptionsOf = (doc: ProseDocument): MarkExceptions => {
189
213
  const patterns = (name: string): string[] => (doc.lexicons[name] ?? []).map((entry) => entry.pattern);
190
214
  return {
@@ -202,13 +226,20 @@ export const kutotenConsistency: Detector = (doc, options): Finding[] => {
202
226
  const located = doc.sentences
203
227
  .filter((sentence) => !isCitation(sentence, doc.source))
204
228
  .flatMap((sentence) => marksIn(sentence, doc.source, exceptions).map((entry) => ({ sentence, entry })));
205
- return KINDS.flatMap((kind) => {
229
+ const odds = KINDS.flatMap((kind): Odd[] => {
206
230
  const ofKind = located.filter(({ entry }) => entry.kind === kind.id);
207
231
  const minority = minorityOf(ofKind.map(({ entry }) => entry.western));
208
232
  if (minority === undefined) return [];
209
233
  const odd = ofKind.filter(({ entry }) => entry.western === minority);
210
234
  if (odd.length < options.limit) return [];
211
235
  const tally = { count: odd.length, of: ofKind.length, limit: options.limit };
212
- return odd.map(({ sentence, entry }) => findingOf(sentence, entry, kind, tally));
213
- });
236
+ return odd.map(({ sentence, entry }) => ({ sentence, entry, kind, tally }));
237
+ }).toSorted((left, right) => left.entry.offset - right.entry.offset);
238
+ const sentences = [...new Set(odds.map((odd) => odd.sentence))];
239
+ return sentences.flatMap((sentence) =>
240
+ findingOf(
241
+ sentence,
242
+ odds.filter((odd) => odd.sentence === sentence),
243
+ ),
244
+ );
214
245
  };
@@ -9,13 +9,16 @@ const INFLECTING = new Set(["VERB", "AUX"]);
9
9
  * 語彙表が原形で書いた語(いただく)だけが、活用した形(いただきます・いただいた)に当たる。
10
10
  * 活用した形で書いた語(could・かもしれません)はその形だけ。"could" は "can" と言っていることが違う。
11
11
  */
12
- const sameWord = (written: Token, entry: Token): boolean => {
12
+ const sameWord = (written: Token, entry: Token, headsPhrase: boolean): boolean => {
13
13
  const surface = entry.surface.toLowerCase();
14
14
  if (written.surface.toLowerCase() === surface) return true;
15
- const inflects = INFLECTING.has(written.pos) && INFLECTING.has(entry.pos);
15
+ const inflects = INFLECTING.has(written.pos) && (INFLECTING.has(entry.pos) || (headsPhrase && entry.pos === "NOUN"));
16
16
  return inflects && entry.lemma?.toLowerCase() === surface && written.lemma?.toLowerCase() === surface;
17
17
  };
18
18
 
19
+ /** A phrase read on its own has no subject, so its head verb is often tagged a noun ("move the needle", "conduct an analysis"). */
20
+ const headsPhrase = (entry: readonly Token[], offset: number): boolean => offset === 0 && entry.length > 1;
21
+
19
22
  /** 品詞が無いときに照らす形。大文字小文字と、アポストロフィの形(it’s と it's)は語を変えない。 */
20
23
  export const comparableWords = (text: string): string => straightApostrophes(text).toLowerCase();
21
24
 
@@ -25,7 +28,7 @@ export const comparableText = (sentence: Sentence): string => comparableWords(pr
25
28
  const runsAt = (tokens: readonly Token[], entry: readonly Token[], start: number): boolean =>
26
29
  entry.every((word, offset) => {
27
30
  const written = tokens[start + offset];
28
- return written !== undefined && sameWord(written, word);
31
+ return written !== undefined && sameWord(written, word, headsPhrase(entry, offset));
29
32
  });
30
33
 
31
34
  /**
@@ -39,6 +42,17 @@ export const entryIn = (sentence: Sentence, entry: LexiconEntry): boolean => {
39
42
  return tokens.some((_token, start) => runsAt(tokens, words, start));
40
43
  };
41
44
 
45
+ const writtenAsIs = (tokens: readonly Token[], entry: readonly Token[], start: number): boolean =>
46
+ entry.every((word, offset) => tokens[start + offset]?.surface.toLowerCase() === word.surface.toLowerCase());
47
+
48
+ /** Whether the lexicon's words stand in the sentence in the very form the lexicon writes them ("reverted back", not "revert back"). */
49
+ export const entryWrittenIn = (sentence: Sentence, entry: LexiconEntry): boolean => {
50
+ const tokens = sentence.tokens;
51
+ const words = entry.tokens;
52
+ if (tokens === undefined || words === undefined || words.length === 0) return entryIn(sentence, entry);
53
+ return tokens.some((_token, start) => writtenAsIs(tokens, words, start));
54
+ };
55
+
42
56
  export type TokenRange = { readonly start: number; readonly end: number };
43
57
 
44
58
  /** 語彙の語が文のどの語の並びに当たったか(始まりと、終わった次の位置)。品詞が無ければ位置を言えないので空。 */
@@ -22,10 +22,16 @@ const FLOOR = { word: 200, char: 500 };
22
22
 
23
23
  type Hit = { readonly sentence: Sentence; readonly matched: string; readonly group?: string | undefined };
24
24
 
25
- const hitsFor = (doc: ProseDocument, lexicon: Lexicon): Hit[] =>
26
- doc.sentences.flatMap((sentence) =>
27
- lexicon.filter((entry) => entryIn(sentence, entry)).map((entry) => ({ sentence, matched: entry.pattern, group: entry.group })),
28
- );
25
+ /** 後ろの語を導く語(まるで)。同じ文にほかの語が当たれば、それと合わせて一つ(まるで魔法のように)と数える。 */
26
+ const OPENER_GROUP = "opener";
27
+
28
+ const sentenceHits = (sentence: Sentence, lexicon: Lexicon): Hit[] => {
29
+ const hits = lexicon.filter((entry) => entryIn(sentence, entry)).map((entry) => ({ sentence, matched: entry.pattern, group: entry.group }));
30
+ const closed = hits.some((hit) => hit.group !== OPENER_GROUP);
31
+ return closed ? hits.filter((hit) => hit.group !== OPENER_GROUP) : hits;
32
+ };
33
+
34
+ const hitsFor = (doc: ProseDocument, lexicon: Lexicon): Hit[] => doc.sentences.flatMap((sentence) => sentenceHits(sentence, lexicon));
29
35
 
30
36
  /**
31
37
  * A lexicon word in group address says how the document speaks to its reader (あなたの). Alone it is the writer's chosen
@@ -0,0 +1,9 @@
1
+ import type { Token } from "../plugin.ts";
2
+ import { isFiniteVerb } from "./list-item-phrase.ts";
3
+
4
+ /** Words opening with a subject pronoun and its finite verb (you will also need a change of clothes): a sentence, closed or not. */
5
+ export const opensWithClause = (words: readonly Token[], isSubject: (token: Token) => boolean): boolean => {
6
+ const [subject, ...rest] = words;
7
+ const verb = rest.find((token) => token.pos !== "ADV");
8
+ return subject !== undefined && verb !== undefined && isSubject(subject) && isFiniteVerb(verb);
9
+ };
@@ -8,6 +8,7 @@ import type { BulletList, Detector, Finding, ProseDocument, Sentence, Span, Toke
8
8
  import { isLinkLabel } from "./link-label.ts";
9
9
  import { itemLayout, splitAtLeadIns } from "./list-layout.ts";
10
10
  import { closesAsSentence, isFiniteVerb, isNounPhraseWithVerbs, isPastForm, isVerb, NOMINAL, NOUN_HEAD, opensObject } from "./list-item-phrase.ts";
11
+ import { opensWithClause } from "./list-item-clause.ts";
11
12
 
12
13
  /** What an item is made of: a phrase or a sentence (ending), and the word it opens with (head, English only). */
13
14
  export type Axis = "ending" | "head";
@@ -113,7 +114,7 @@ const japaneseEnding = (item: readonly Sentence[], headlineEndings: ReadonlySet<
113
114
  * English: a sentence closes with a full stop and has a finite verb outside a noun phrase; a phrase has neither, nor any
114
115
  * verb but those of its noun phrase. Anything between is not judged.
115
116
  */
116
- const englishEnding = (item: readonly Sentence[]): string | undefined => {
117
+ const englishEnding = (item: readonly Sentence[], context: HeadContext): string | undefined => {
117
118
  const sentences = ownEnding(item);
118
119
  const tokens = sentences.flatMap((sentence) => sentence.tokens ?? []);
119
120
  if (tokens.length === 0) return undefined;
@@ -122,6 +123,8 @@ const englishEnding = (item: readonly Sentence[]): string | undefined => {
122
123
  // A noun phrase with a stray full stop (Shelter – a charity who offer advice.) says nothing: neither form.
123
124
  const nounPhrase = isNounPhraseWithVerbs(tokens);
124
125
  if (closed) return tokens.some(isFiniteVerb) && !nounPhrase ? "sentence" : undefined;
126
+ const words = tokens.filter((token) => !SKIPPED_AT_END.has(token.pos));
127
+ if (opensWithClause(words, (token) => isSubjectPronoun(token, context))) return "sentence";
125
128
  return (nounPhrase || !tokens.some(isVerb)) && !isUnsure(tokens[0]) ? "phrase" : undefined;
126
129
  };
127
130
 
@@ -316,7 +319,7 @@ const leadsIn = (sentences: readonly Sentence[]): boolean => LEAD_IN.test(senten
316
319
  export const formOf = (axis: Axis, sentences: readonly Sentence[], language: string, context: HeadContext = NO_HEAD_CONTEXT): string | undefined => {
317
320
  if (axis === "ending" && leadsIn(sentences)) return undefined;
318
321
  if (language === "ja") return axis === "ending" ? japaneseEnding(sentences, context.headlineEndings) : undefined;
319
- return axis === "ending" ? englishEnding(sentences) : englishHead(sentences, context);
322
+ return axis === "ending" ? englishEnding(sentences, context) : englishHead(sentences, context);
320
323
  };
321
324
 
322
325
  const within = (inner: Span, outer: Span): boolean => inner.start >= outer.start && inner.end <= outer.end;
@@ -28,6 +28,8 @@ export type ListWords = {
28
28
  readonly elision?: readonly string[];
29
29
  /** 並びの残りを言う語(so forth / the like)。and so forth の前まで並びが続く。 */
30
30
  readonly openListEnd?: ReadonlySet<string>;
31
+ /** 読点で挟んで名前に添える関係節を始める語(who / which)。Tom, who repaired radios, opened … の節は並びの項目ではない。 */
32
+ readonly asideRelative?: ReadonlySet<string>;
31
33
  };
32
34
 
33
35
  const LIST_CONJUNCTION: ReadonlySet<string> = new Set(["and", "or"]);
@@ -82,15 +82,36 @@ const sidedFinding = (item: Sided, values: Finding["values"], variant?: string):
82
82
  values: { ...values, offset: item.offset },
83
83
  });
84
84
 
85
- /** The less common way, one finding each, or one finding for a document written both ways (spacing-minority.ts). */
86
- const minorityFindings = <T extends Sided>(items: readonly T[], limit: number, valuesOf: (item: T) => Finding["values"]): Finding[] => {
85
+ /** The odd items, each its own slip, or with the one before it when joins says they are one slip. */
86
+ const slipsOf = <T>(odd: readonly T[], joins: (previous: T, item: T) => boolean): T[][] =>
87
+ odd.reduce<T[][]>((slips, item) => {
88
+ const last = slips.at(-1);
89
+ const previous = last?.at(-1);
90
+ if (last !== undefined && previous !== undefined && last.length === 1 && joins(previous, item)) last.push(item);
91
+ else slips.push([item]);
92
+ return slips;
93
+ }, []);
94
+
95
+ /**
96
+ * The less common way, one finding per slip, or one finding for a document written both ways (spacing-minority.ts). The
97
+ * counts stay in items: a slip of two items is two of the places that differ.
98
+ */
99
+ const minorityFindings = <T extends Sided>(
100
+ items: readonly T[],
101
+ limit: number,
102
+ valuesOf: (slip: readonly T[]) => Finding["values"],
103
+ joins: (previous: T, item: T) => boolean = () => false,
104
+ ): Finding[] => {
87
105
  const report = minorityReport(items, limit);
88
106
  if (report === undefined) return [];
89
107
  if (report.mode === "mixed") {
90
108
  const { first, odd, spaced, touching } = report;
91
- return [sidedFinding(first, { ...valuesOf(first), spaced, touching, count: odd, of: items.length, limit }, "mixed")];
109
+ return [sidedFinding(first, { ...valuesOf([first]), spaced, touching, count: odd, of: items.length, limit }, "mixed")];
92
110
  }
93
- return report.odd.map((item) => sidedFinding(item, { ...valuesOf(item), count: report.odd.length, of: items.length, limit }));
111
+ return slipsOf(report.odd, joins).flatMap((slip) => {
112
+ const first = slip[0];
113
+ return first === undefined ? [] : [sidedFinding(first, { ...valuesOf(slip), count: report.odd.length, of: items.length, limit })];
114
+ });
94
115
  };
95
116
 
96
117
  /** Sentences written in the document's own language; a quoted sentence in another language follows its own marks. */
@@ -203,6 +224,12 @@ const withNoteAddressKind = (mark: Mark, addresses: ReadonlySet<number>): Mark =
203
224
  const withNoteKind = (mark: Mark, notes: ReadonlySet<number>): Mark =>
204
225
  notes.has(mark.offset) && !mark.form.kind.endsWith(ENUMERATOR_KIND) ? { ...mark, form: { ...mark.form, kind: `${mark.form.kind}${NOTE_KIND}` } } : mark;
205
226
 
227
+ /** A closing bracket of the same width right after its opening one, with no bracket between (資料(案)): one slip, not two. */
228
+ const closesPair = (source: string, opening: Mark, closing: Mark): boolean =>
229
+ opening.sentence === closing.sentence &&
230
+ CLOSER_OF[opening.char] === closing.char &&
231
+ !/[()()[\][]]/u.test(source.slice(opening.offset + 1, closing.offset));
232
+
206
233
  /**
207
234
  * A mark written two ways in one document (( and (, “ and "), the less common way reported. The two ways come from the
208
235
  * lexicon; neither is called right. Only marks next to a letter of the document's script count, so a bracket in code-like
@@ -229,7 +256,8 @@ export const markConsistency: Detector = (doc, options): Finding[] => {
229
256
  minorityFindings(
230
257
  marks.filter((mark) => mark.form.kind === kind && !isWithinAny(titles, { start: mark.offset, end: mark.offset + 1 })),
231
258
  options.limit,
232
- (mark) => ({ mark: mark.char, usual: mark.form.other }),
259
+ (slip) => ({ mark: slip.map((mark) => mark.char).join(""), usual: slip.map((mark) => mark.form.other).join("") }),
260
+ (opening, closing) => closesPair(doc.source, opening, closing),
233
261
  ),
234
262
  );
235
263
  };
@@ -263,9 +291,9 @@ export const sentenceGaps = (doc: ProseDocument): Sided[] => {
263
291
 
264
292
  /** One space between sentences and two, mixed in one document: the less common is reported. */
265
293
  export const sentenceSpacing: Detector = (doc, options): Finding[] =>
266
- minorityFindings(sentenceGaps(doc), options.limit, (gap) => ({
267
- spaces: gap.spaced ? TWO_SPACES.length : ONE_SPACE.length,
268
- usual: gap.spaced ? ONE_SPACE.length : TWO_SPACES.length,
294
+ minorityFindings(sentenceGaps(doc), options.limit, ([gap]) => ({
295
+ spaces: gap?.spaced === true ? TWO_SPACES.length : ONE_SPACE.length,
296
+ usual: gap?.spaced === true ? ONE_SPACE.length : TWO_SPACES.length,
269
297
  }));
270
298
 
271
299
  type Hit = { readonly sentence: Sentence; readonly matched: string; readonly offset: number };
@@ -1,6 +1,7 @@
1
1
  import type { Detector, Finding, LexiconEntry, Paragraph, ProseDocument, Token } from "../plugin.ts";
2
2
  import { formMinority } from "./form-minority.ts";
3
3
  import { captionParagraphs, slotParagraphs } from "./final-period-captions.ts";
4
+ import { isHeaderField } from "./email-letter.ts";
4
5
 
5
6
  // A paragraph whose last sentence stops without its closing mark, in a document whose other paragraphs end with one. It
6
7
  // takes no side: a document that ends none of its paragraphs with the mark (slides, labels) is not reported. The marks
@@ -113,16 +114,25 @@ const marksOf = (lexicon: readonly LexiconEntry[]): PeriodMarks => ({
113
114
  labels: lexicon.filter((entry) => entry.group === "label").map((entry) => entry.pattern),
114
115
  });
115
116
 
117
+ /** A paragraph of one line opened by a header field (件名:…, Subject: …): a label and its value, not a sentence. Read from the source line, since the paragraph may start past the label. */
118
+ const isFieldLine = (source: string, paragraph: Paragraph, fields: readonly string[]): boolean => {
119
+ const line = source.slice(source.lastIndexOf("\n", paragraph.span.start - 1) + 1, paragraph.span.end).trim();
120
+ return !line.includes("\n") && isHeaderField(line, fields);
121
+ };
122
+
116
123
  export const missingFinalPeriod: Detector = (doc: ProseDocument, options): Finding[] => {
117
124
  const text = doc.prose ?? doc.source;
118
125
  const marks = marksOf(doc.lexicons["final-period"] ?? []);
126
+ const fields = (doc.lexicons["email-header-field"] ?? []).map((entry) => entry.pattern);
119
127
  const captions = captionParagraphs(
120
128
  text,
121
129
  doc.sections,
122
130
  slotParagraphs(text, doc.paragraphs, (line) => isClosed(line, marks.ends)),
123
131
  );
124
132
  const ends = doc.paragraphs.flatMap((paragraph, index) =>
125
- captions.has(index) ? [] : (paragraphEnd(text, paragraph, marks, doc.paragraphs[index + 1], doc.paragraphs[index - 1]) ?? []),
133
+ captions.has(index) || isFieldLine(doc.source, paragraph, fields)
134
+ ? []
135
+ : (paragraphEnd(text, paragraph, marks, doc.paragraphs[index + 1], doc.paragraphs[index - 1]) ?? []),
126
136
  );
127
137
  const minority = formMinority(ends, options.limit);
128
138
  if (minority === undefined || minority.usual.form !== "closed") return [];
@@ -32,17 +32,27 @@ const phrasesIn = (sentence: Sentence, source: string, phrases: Lexicon): Hidden
32
32
  })),
33
33
  );
34
34
 
35
+ const touches = (left: Token | undefined, right: Token | undefined): boolean => left !== undefined && right !== undefined && left.span.end === right.span.start;
36
+
37
+ /**
38
+ * The first token of the compound noun the verbal noun ends: 塗り + 直し is 塗り直し, and 直しする is not a verb to write.
39
+ * Nouns written straight before it, with no space, are one word.
40
+ */
41
+ const compoundStart = (tokens: readonly Token[], at: number): number =>
42
+ tokens[at - 1]?.pos === "NOUN" && touches(tokens[at - 1], tokens[at]) ? compoundStart(tokens, at - 1) : at;
43
+
35
44
  /**
36
- * A carrying verb right after a verbal noun: 調査 + を実施した. Both sides are named in the dictionary form, the noun and the
45
+ * A carrying verb right after a verbal noun: 調査 + を実施した, the noun read with the compound it ends (塗り直し). Both sides are named in the dictionary form, the noun and the
37
46
  * entry (調査を実施する), and the verb to write is the noun and the entry's instead_of (調査 + する).
38
47
  */
39
- const lightVerbsIn = (sentence: Sentence, lightVerbs: Lexicon, eventNouns: ReadonlySet<string>): Hidden[] => {
48
+ const lightVerbsIn = (sentence: Sentence, source: string, lightVerbs: Lexicon, eventNouns: ReadonlySet<string>): Hidden[] => {
40
49
  const tokens = sentence.tokens ?? [];
41
50
  return lightVerbs.flatMap((entry) =>
42
51
  entryRanges(sentence, entry).flatMap((range): Hidden[] => {
43
52
  const noun = tokens[range.start - 1];
44
53
  if (!isVerbalNoun(noun) || eventNouns.has(noun.surface)) return [];
45
- return [{ sentence, offset: noun.span.start, matched: `${noun.surface}${entry.pattern}`, preferred: `${noun.surface}${entry.instead_of ?? ""}` }];
54
+ const compound = source.slice(tokens[compoundStart(tokens, range.start - 1)]?.span.start ?? noun.span.start, noun.span.end);
55
+ return [{ sentence, offset: noun.span.start, matched: `${compound}${entry.pattern}`, preferred: `${compound}${entry.instead_of ?? ""}` }];
46
56
  }),
47
57
  );
48
58
  };
@@ -53,7 +63,7 @@ export const hiddenVerbs = (doc: Pick<ProseDocument, "sentences" | "source" | "l
53
63
  return doc.sentences
54
64
  .flatMap((sentence) => [
55
65
  ...phrasesIn(sentence, doc.source, doc.lexicons[PHRASES] ?? []),
56
- ...lightVerbsIn(sentence, doc.lexicons[LIGHT_VERBS] ?? [], eventNouns),
66
+ ...lightVerbsIn(sentence, doc.source, doc.lexicons[LIGHT_VERBS] ?? [], eventNouns),
57
67
  ])
58
68
  .toSorted((left, right) => left.offset - right.offset);
59
69
  };
@@ -1,6 +1,6 @@
1
1
  import type { Detector, Finding, Lexicon } from "../plugin.ts";
2
2
  import { escapeRegExp } from "../orthography.ts";
3
- import { quoteAround } from "./quote-around.ts";
3
+ import { quoteAround, sentenceQuoteAt } from "./quote-around.ts";
4
4
 
5
5
  // 数と序数の字が合わない所(3th、22th、11st)。どの数の終わりにどの字が付くかは語彙表 ordinal-suffix が言う。
6
6
 
@@ -34,7 +34,7 @@ export const ordinalSuffix: Detector = (doc): Finding[] => {
34
34
  severity: "warning",
35
35
  line: 0,
36
36
  column: 0,
37
- quote: quoteAround(text, slip.offset, slip.offset + slip.written.length),
37
+ quote: sentenceQuoteAt(doc.sentences, slip.offset) ?? quoteAround(text, slip.offset, slip.offset + slip.written.length),
38
38
  values: { written: slip.written, expected: `${slip.number}${slip.expected[0] ?? ""}`, offset: slip.offset },
39
39
  }));
40
40
  };