chaffjs 0.43.0 → 0.45.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 (348) hide show
  1. package/dist/bound-word-particles.d.ts +9 -0
  2. package/dist/bound-word-particles.d.ts.map +1 -0
  3. package/dist/bound-word-particles.js +16 -0
  4. package/dist/bound-word-particles.js.map +1 -0
  5. package/dist/derived/stays.d.ts +0 -1
  6. package/dist/derived/stays.d.ts.map +1 -1
  7. package/dist/derived/stays.js +3 -1
  8. package/dist/derived/stays.js.map +1 -1
  9. package/dist/detectors/absolute-exception.d.ts.map +1 -1
  10. package/dist/detectors/absolute-exception.js +10 -4
  11. package/dist/detectors/absolute-exception.js.map +1 -1
  12. package/dist/detectors/abstract-length.d.ts +5 -1
  13. package/dist/detectors/abstract-length.d.ts.map +1 -1
  14. package/dist/detectors/abstract-length.js +13 -5
  15. package/dist/detectors/abstract-length.js.map +1 -1
  16. package/dist/detectors/adversative-ga.d.ts +1 -1
  17. package/dist/detectors/adversative-ga.d.ts.map +1 -1
  18. package/dist/detectors/adversative-ga.js +19 -2
  19. package/dist/detectors/adversative-ga.js.map +1 -1
  20. package/dist/detectors/agreement-slip.d.ts +2 -0
  21. package/dist/detectors/agreement-slip.d.ts.map +1 -1
  22. package/dist/detectors/agreement-slip.js +22 -8
  23. package/dist/detectors/agreement-slip.js.map +1 -1
  24. package/dist/detectors/bold-label.d.ts +5 -1
  25. package/dist/detectors/bold-label.d.ts.map +1 -1
  26. package/dist/detectors/bold-label.js +74 -14
  27. package/dist/detectors/bold-label.js.map +1 -1
  28. package/dist/detectors/bold-quoted.d.ts +4 -0
  29. package/dist/detectors/bold-quoted.d.ts.map +1 -0
  30. package/dist/detectors/bold-quoted.js +17 -0
  31. package/dist/detectors/bold-quoted.js.map +1 -0
  32. package/dist/detectors/caps-caption.d.ts +5 -0
  33. package/dist/detectors/caps-caption.d.ts.map +1 -1
  34. package/dist/detectors/caps-caption.js +7 -0
  35. package/dist/detectors/caps-caption.js.map +1 -1
  36. package/dist/detectors/char-shape.d.ts +0 -6
  37. package/dist/detectors/char-shape.d.ts.map +1 -1
  38. package/dist/detectors/char-shape.js +4 -21
  39. package/dist/detectors/char-shape.js.map +1 -1
  40. package/dist/detectors/clause-shape.d.ts +2 -0
  41. package/dist/detectors/clause-shape.d.ts.map +1 -1
  42. package/dist/detectors/clause-shape.js +11 -2
  43. package/dist/detectors/clause-shape.js.map +1 -1
  44. package/dist/detectors/cleft-focus.d.ts +4 -0
  45. package/dist/detectors/cleft-focus.d.ts.map +1 -0
  46. package/dist/detectors/cleft-focus.js +31 -0
  47. package/dist/detectors/cleft-focus.js.map +1 -0
  48. package/dist/detectors/count-per-section.d.ts.map +1 -1
  49. package/dist/detectors/count-per-section.js +7 -4
  50. package/dist/detectors/count-per-section.js.map +1 -1
  51. package/dist/detectors/defined-term-form.d.ts.map +1 -1
  52. package/dist/detectors/defined-term-form.js +2 -1
  53. package/dist/detectors/defined-term-form.js.map +1 -1
  54. package/dist/detectors/definition-use.d.ts.map +1 -1
  55. package/dist/detectors/definition-use.js +13 -3
  56. package/dist/detectors/definition-use.js.map +1 -1
  57. package/dist/detectors/emoticon.d.ts +6 -0
  58. package/dist/detectors/emoticon.d.ts.map +1 -0
  59. package/dist/detectors/emoticon.js +19 -0
  60. package/dist/detectors/emoticon.js.map +1 -0
  61. package/dist/detectors/empty-section.d.ts +1 -1
  62. package/dist/detectors/empty-section.d.ts.map +1 -1
  63. package/dist/detectors/empty-section.js +3 -2
  64. package/dist/detectors/empty-section.js.map +1 -1
  65. package/dist/detectors/en-shape.d.ts +6 -1
  66. package/dist/detectors/en-shape.d.ts.map +1 -1
  67. package/dist/detectors/en-shape.js +9 -1
  68. package/dist/detectors/en-shape.js.map +1 -1
  69. package/dist/detectors/fullwidth-alnum.d.ts +2 -2
  70. package/dist/detectors/fullwidth-alnum.d.ts.map +1 -1
  71. package/dist/detectors/fullwidth-alnum.js +19 -3
  72. package/dist/detectors/fullwidth-alnum.js.map +1 -1
  73. package/dist/detectors/heading-echo.d.ts.map +1 -1
  74. package/dist/detectors/heading-echo.js +20 -7
  75. package/dist/detectors/heading-echo.js.map +1 -1
  76. package/dist/detectors/heading-number.d.ts +7 -0
  77. package/dist/detectors/heading-number.d.ts.map +1 -0
  78. package/dist/detectors/heading-number.js +21 -0
  79. package/dist/detectors/heading-number.js.map +1 -0
  80. package/dist/detectors/katakana-density.d.ts +6 -1
  81. package/dist/detectors/katakana-density.d.ts.map +1 -1
  82. package/dist/detectors/katakana-density.js +14 -1
  83. package/dist/detectors/katakana-density.js.map +1 -1
  84. package/dist/detectors/lexicon.d.ts.map +1 -1
  85. package/dist/detectors/lexicon.js +2 -1
  86. package/dist/detectors/lexicon.js.map +1 -1
  87. package/dist/detectors/lookalike-character.d.ts +2 -1
  88. package/dist/detectors/lookalike-character.d.ts.map +1 -1
  89. package/dist/detectors/lookalike-character.js +14 -1
  90. package/dist/detectors/lookalike-character.js.map +1 -1
  91. package/dist/detectors/mark-shape.d.ts +8 -3
  92. package/dist/detectors/mark-shape.d.ts.map +1 -1
  93. package/dist/detectors/mark-shape.js +55 -16
  94. package/dist/detectors/mark-shape.js.map +1 -1
  95. package/dist/detectors/mentioned-phrase.d.ts +3 -1
  96. package/dist/detectors/mentioned-phrase.d.ts.map +1 -1
  97. package/dist/detectors/mentioned-phrase.js +9 -0
  98. package/dist/detectors/mentioned-phrase.js.map +1 -1
  99. package/dist/detectors/middle-dot.d.ts +7 -0
  100. package/dist/detectors/middle-dot.d.ts.map +1 -1
  101. package/dist/detectors/middle-dot.js +19 -0
  102. package/dist/detectors/middle-dot.js.map +1 -1
  103. package/dist/detectors/named-by-context.d.ts +13 -0
  104. package/dist/detectors/named-by-context.d.ts.map +1 -0
  105. package/dist/detectors/named-by-context.js +10 -0
  106. package/dist/detectors/named-by-context.js.map +1 -0
  107. package/dist/detectors/number-style.d.ts.map +1 -1
  108. package/dist/detectors/number-style.js +13 -1
  109. package/dist/detectors/number-style.js.map +1 -1
  110. package/dist/detectors/obligation-without-deadline.d.ts +10 -2
  111. package/dist/detectors/obligation-without-deadline.d.ts.map +1 -1
  112. package/dist/detectors/obligation-without-deadline.js +47 -2
  113. package/dist/detectors/obligation-without-deadline.js.map +1 -1
  114. package/dist/detectors/open-end-names.d.ts +2 -0
  115. package/dist/detectors/open-end-names.d.ts.map +1 -1
  116. package/dist/detectors/open-end-names.js +8 -1
  117. package/dist/detectors/open-end-names.js.map +1 -1
  118. package/dist/detectors/orthographic-variant.d.ts.map +1 -1
  119. package/dist/detectors/orthographic-variant.js +5 -3
  120. package/dist/detectors/orthographic-variant.js.map +1 -1
  121. package/dist/detectors/paragraph-pointer.d.ts +4 -0
  122. package/dist/detectors/paragraph-pointer.d.ts.map +1 -0
  123. package/dist/detectors/paragraph-pointer.js +22 -0
  124. package/dist/detectors/paragraph-pointer.js.map +1 -0
  125. package/dist/detectors/phrase-match.d.ts +4 -1
  126. package/dist/detectors/phrase-match.d.ts.map +1 -1
  127. package/dist/detectors/phrase-match.js +12 -5
  128. package/dist/detectors/phrase-match.js.map +1 -1
  129. package/dist/detectors/placeholder-context.d.ts +16 -0
  130. package/dist/detectors/placeholder-context.d.ts.map +1 -0
  131. package/dist/detectors/placeholder-context.js +57 -0
  132. package/dist/detectors/placeholder-context.js.map +1 -0
  133. package/dist/detectors/placeholder-text.d.ts +2 -0
  134. package/dist/detectors/placeholder-text.d.ts.map +1 -1
  135. package/dist/detectors/placeholder-text.js +1 -1
  136. package/dist/detectors/placeholder-text.js.map +1 -1
  137. package/dist/detectors/redundant-pair.d.ts +5 -0
  138. package/dist/detectors/redundant-pair.d.ts.map +1 -0
  139. package/dist/detectors/redundant-pair.js +18 -0
  140. package/dist/detectors/redundant-pair.js.map +1 -0
  141. package/dist/detectors/registry/middle-dot.js +1 -1
  142. package/dist/detectors/registry/redundant-pair.d.ts +3 -0
  143. package/dist/detectors/registry/redundant-pair.d.ts.map +1 -0
  144. package/dist/detectors/registry/redundant-pair.js +3 -0
  145. package/dist/detectors/registry/redundant-pair.js.map +1 -0
  146. package/dist/detectors/request-owner.d.ts +1 -0
  147. package/dist/detectors/request-owner.d.ts.map +1 -1
  148. package/dist/detectors/request-owner.js +6 -3
  149. package/dist/detectors/request-owner.js.map +1 -1
  150. package/dist/detectors/sentence-counts.d.ts +2 -0
  151. package/dist/detectors/sentence-counts.d.ts.map +1 -1
  152. package/dist/detectors/sentence-counts.js +13 -4
  153. package/dist/detectors/sentence-counts.js.map +1 -1
  154. package/dist/detectors/signals.d.ts.map +1 -1
  155. package/dist/detectors/signals.js +10 -1
  156. package/dist/detectors/signals.js.map +1 -1
  157. package/dist/detectors/structure-tree.d.ts.map +1 -1
  158. package/dist/detectors/structure-tree.js +1 -0
  159. package/dist/detectors/structure-tree.js.map +1 -1
  160. package/dist/detectors/structure.d.ts.map +1 -1
  161. package/dist/detectors/structure.js +6 -5
  162. package/dist/detectors/structure.js.map +1 -1
  163. package/dist/detectors/superlative-context.d.ts +7 -0
  164. package/dist/detectors/superlative-context.d.ts.map +1 -1
  165. package/dist/detectors/superlative-context.js +9 -0
  166. package/dist/detectors/superlative-context.js.map +1 -1
  167. package/dist/detectors/template-sections.d.ts +1 -0
  168. package/dist/detectors/template-sections.d.ts.map +1 -1
  169. package/dist/detectors/template-sections.js +1 -1
  170. package/dist/detectors/template-sections.js.map +1 -1
  171. package/dist/detectors/token-shape.d.ts.map +1 -1
  172. package/dist/detectors/token-shape.js +7 -5
  173. package/dist/detectors/token-shape.js.map +1 -1
  174. package/dist/detectors/unbalanced-bracket.d.ts.map +1 -1
  175. package/dist/detectors/unbalanced-bracket.js +2 -1
  176. package/dist/detectors/unbalanced-bracket.js.map +1 -1
  177. package/dist/detectors/unfilled-placeholder.d.ts.map +1 -1
  178. package/dist/detectors/unfilled-placeholder.js +18 -1
  179. package/dist/detectors/unfilled-placeholder.js.map +1 -1
  180. package/dist/detectors/verse-block.d.ts +4 -0
  181. package/dist/detectors/verse-block.d.ts.map +1 -0
  182. package/dist/detectors/verse-block.js +40 -0
  183. package/dist/detectors/verse-block.js.map +1 -0
  184. package/dist/document.d.ts.map +1 -1
  185. package/dist/document.js +1 -0
  186. package/dist/document.js.map +1 -1
  187. package/dist/email-parts.d.ts +2 -0
  188. package/dist/email-parts.d.ts.map +1 -1
  189. package/dist/email-parts.js +10 -7
  190. package/dist/email-parts.js.map +1 -1
  191. package/dist/eval.d.ts.map +1 -1
  192. package/dist/eval.js +3 -0
  193. package/dist/eval.js.map +1 -1
  194. package/dist/paragraph-length.d.ts +4 -0
  195. package/dist/paragraph-length.d.ts.map +1 -1
  196. package/dist/paragraph-length.js +6 -0
  197. package/dist/paragraph-length.js.map +1 -1
  198. package/dist/plugin.d.ts +4 -0
  199. package/dist/plugin.d.ts.map +1 -1
  200. package/dist/reasons.d.ts +2 -0
  201. package/dist/reasons.d.ts.map +1 -1
  202. package/dist/reasons.js +2 -0
  203. package/dist/reasons.js.map +1 -1
  204. package/dist/rule-of-three.d.ts +13 -1
  205. package/dist/rule-of-three.d.ts.map +1 -1
  206. package/dist/rule-of-three.js +32 -3
  207. package/dist/rule-of-three.js.map +1 -1
  208. package/dist/run.d.ts.map +1 -1
  209. package/dist/run.js +4 -1
  210. package/dist/run.js.map +1 -1
  211. package/dist/structure/build.d.ts.map +1 -1
  212. package/dist/structure/build.js +2 -1
  213. package/dist/structure/build.js.map +1 -1
  214. package/dist/structure/cited-elsewhere.d.ts +5 -2
  215. package/dist/structure/cited-elsewhere.d.ts.map +1 -1
  216. package/dist/structure/cited-elsewhere.js +16 -6
  217. package/dist/structure/cited-elsewhere.js.map +1 -1
  218. package/dist/structure/definition-use.d.ts +2 -1
  219. package/dist/structure/definition-use.d.ts.map +1 -1
  220. package/dist/structure/definition-use.js +10 -2
  221. package/dist/structure/definition-use.js.map +1 -1
  222. package/dist/structure/issues.js +1 -1
  223. package/dist/structure/issues.js.map +1 -1
  224. package/dist/structure/negated-act.d.ts +1 -0
  225. package/dist/structure/negated-act.d.ts.map +1 -1
  226. package/dist/structure/negated-act.js +1 -1
  227. package/dist/structure/negated-act.js.map +1 -1
  228. package/dist/structure/own-name.d.ts +4 -0
  229. package/dist/structure/own-name.d.ts.map +1 -0
  230. package/dist/structure/own-name.js +20 -0
  231. package/dist/structure/own-name.js.map +1 -0
  232. package/dist/structure/percent-sum-prose.d.ts.map +1 -1
  233. package/dist/structure/percent-sum-prose.js +9 -1
  234. package/dist/structure/percent-sum-prose.js.map +1 -1
  235. package/dist/structure/percent-sum.d.ts +2 -0
  236. package/dist/structure/percent-sum.d.ts.map +1 -1
  237. package/dist/structure/percent-sum.js.map +1 -1
  238. package/dist/structure/reference-text.d.ts.map +1 -1
  239. package/dist/structure/reference-text.js +3 -1
  240. package/dist/structure/reference-text.js.map +1 -1
  241. package/dist/te-form-helper.d.ts +22 -0
  242. package/dist/te-form-helper.d.ts.map +1 -0
  243. package/dist/te-form-helper.js +35 -0
  244. package/dist/te-form-helper.js.map +1 -0
  245. package/dist/word-use.d.ts +7 -0
  246. package/dist/word-use.d.ts.map +1 -1
  247. package/dist/word-use.js +11 -0
  248. package/dist/word-use.js.map +1 -1
  249. package/package.json +3 -3
  250. package/rules/absolute-exception.yaml +3 -3
  251. package/rules/abstract-length.yaml +2 -2
  252. package/rules/adversative-ga-repeat.yaml +2 -2
  253. package/rules/all-caps-shouting.yaml +2 -2
  254. package/rules/attachment-not-attached.yaml +11 -6
  255. package/rules/bold-label-list.yaml +29 -6
  256. package/rules/bracket-width-consistency.yaml +2 -2
  257. package/rules/demonstrative-opener-run.yaml +2 -2
  258. package/rules/duration-mismatch.yaml +2 -2
  259. package/rules/emoji-density.yaml +2 -2
  260. package/rules/empty-section.yaml +2 -2
  261. package/rules/fullwidth-alnum-consistency.yaml +2 -2
  262. package/rules/katakana-density.yaml +3 -3
  263. package/rules/lookalike-character.yaml +8 -5
  264. package/rules/max-kanji-continuous.yaml +4 -0
  265. package/rules/no-doubled-joshi.yaml +2 -2
  266. package/rules/number-style-consistency.yaml +2 -2
  267. package/rules/obligation-without-deadline.yaml +2 -2
  268. package/rules/padded-intro.yaml +1 -1
  269. package/rules/paragraph-length-variance.yaml +27 -3
  270. package/rules/redundant-expression.yaml +1 -1
  271. package/rules/repeated-sentence-ending.yaml +2 -2
  272. package/rules/request-without-deadline.yaml +2 -2
  273. package/rules/requirement-smell.yaml +2 -2
  274. package/rules/rule-of-three.yaml +2 -2
  275. package/rules/sentence-spacing-consistency.yaml +2 -2
  276. package/rules/teki-overuse.yaml +2 -0
  277. package/rules/unfilled-placeholder.yaml +2 -2
  278. package/rules/use-before-definition.yaml +2 -2
  279. package/src/bound-word-particles.ts +23 -0
  280. package/src/derived/stays.ts +4 -1
  281. package/src/detectors/absolute-exception.ts +11 -5
  282. package/src/detectors/abstract-length.ts +16 -6
  283. package/src/detectors/adversative-ga.ts +24 -2
  284. package/src/detectors/agreement-slip.ts +35 -10
  285. package/src/detectors/bold-label.ts +82 -14
  286. package/src/detectors/bold-quoted.ts +21 -0
  287. package/src/detectors/caps-caption.ts +10 -0
  288. package/src/detectors/char-shape.ts +8 -22
  289. package/src/detectors/clause-shape.ts +14 -3
  290. package/src/detectors/cleft-focus.ts +40 -0
  291. package/src/detectors/count-per-section.ts +9 -4
  292. package/src/detectors/defined-term-form.ts +2 -1
  293. package/src/detectors/definition-use.ts +23 -4
  294. package/src/detectors/emoticon.ts +21 -0
  295. package/src/detectors/empty-section.ts +3 -2
  296. package/src/detectors/en-shape.ts +10 -1
  297. package/src/detectors/fullwidth-alnum.ts +24 -3
  298. package/src/detectors/heading-echo.ts +21 -8
  299. package/src/detectors/heading-number.ts +20 -0
  300. package/src/detectors/katakana-density.ts +17 -2
  301. package/src/detectors/lexicon.ts +2 -1
  302. package/src/detectors/lookalike-character.ts +19 -2
  303. package/src/detectors/mark-shape.ts +61 -13
  304. package/src/detectors/mentioned-phrase.ts +13 -1
  305. package/src/detectors/middle-dot.ts +22 -0
  306. package/src/detectors/named-by-context.ts +15 -0
  307. package/src/detectors/number-style.ts +14 -1
  308. package/src/detectors/obligation-without-deadline.ts +69 -5
  309. package/src/detectors/open-end-names.ts +21 -2
  310. package/src/detectors/orthographic-variant.ts +20 -15
  311. package/src/detectors/paragraph-pointer.ts +28 -0
  312. package/src/detectors/phrase-match.ts +13 -5
  313. package/src/detectors/placeholder-context.ts +72 -0
  314. package/src/detectors/placeholder-text.ts +1 -1
  315. package/src/detectors/redundant-pair.ts +25 -0
  316. package/src/detectors/registry/middle-dot.ts +1 -1
  317. package/src/detectors/registry/redundant-pair.ts +4 -0
  318. package/src/detectors/request-owner.ts +6 -3
  319. package/src/detectors/sentence-counts.ts +16 -4
  320. package/src/detectors/signals.ts +11 -1
  321. package/src/detectors/structure-tree.ts +1 -0
  322. package/src/detectors/structure.ts +6 -5
  323. package/src/detectors/superlative-context.ts +12 -0
  324. package/src/detectors/template-sections.ts +1 -1
  325. package/src/detectors/token-shape.ts +10 -7
  326. package/src/detectors/unbalanced-bracket.ts +2 -1
  327. package/src/detectors/unfilled-placeholder.ts +22 -1
  328. package/src/detectors/verse-block.ts +48 -0
  329. package/src/document.ts +1 -0
  330. package/src/email-parts.ts +16 -7
  331. package/src/eval.ts +2 -0
  332. package/src/paragraph-length.ts +10 -0
  333. package/src/plugin.ts +4 -0
  334. package/src/reasons.ts +4 -0
  335. package/src/rule-of-three.ts +47 -4
  336. package/src/run.ts +3 -1
  337. package/src/structure/build.ts +2 -1
  338. package/src/structure/cited-elsewhere.ts +18 -6
  339. package/src/structure/definition-use.ts +10 -1
  340. package/src/structure/issues.ts +1 -1
  341. package/src/structure/negated-act.ts +1 -1
  342. package/src/structure/own-name.ts +28 -0
  343. package/src/structure/percent-sum-prose.ts +12 -1
  344. package/src/structure/percent-sum.ts +2 -0
  345. package/src/structure/reference-text.ts +5 -1
  346. package/src/te-form-helper.ts +52 -0
  347. package/src/word-use.ts +13 -0
  348. package/src/honorific-group.ts +0 -22
@@ -94,8 +94,11 @@ export const nightsDaysPairs = (
94
94
  });
95
95
 
96
96
  /** 日数が泊数より一つ多くない組。 */
97
+ /** 「43 days and 43 nights」: 日数を先に書いて泊数と同じ数なら、昼も夜もずっとの意味で、泊まりの数ではない。 */
98
+ const isDayAndNight = (pair: { nights: Count; days: Count }): boolean => pair.days.start < pair.nights.start && pair.days.amount === pair.nights.amount;
99
+
97
100
  export const nightsDaysMismatches = (pairs: readonly { nights: Count; days: Count }[]): NightsDaysMismatch[] =>
98
- pairs.flatMap((pair) => (pair.days.amount === pair.nights.amount + 1 ? [] : [{ ...pair, expected: pair.nights.amount + 1 }]));
101
+ pairs.flatMap((pair) => (pair.days.amount === pair.nights.amount + 1 || isDayAndNight(pair) ? [] : [{ ...pair, expected: pair.nights.amount + 1 }]));
99
102
 
100
103
  const keyOf = (text: string): string => withoutEdgeMarks(text).normalize("NFKC").toLowerCase().replace(/\s+/gu, " ");
101
104
 
@@ -7,20 +7,25 @@ import { isWithinAny, QUOTATION_MARKS, quotedIn } from "../quoted-span.ts";
7
7
  import { entryRanges } from "./lexicon-match.ts";
8
8
  import { obligationsOf } from "./modal-conflict.ts";
9
9
  import { quoteAt } from "./structure-tree.ts";
10
+ import { isNegation, negationWords } from "../structure/negated-act.ts";
10
11
 
11
12
  const REQUIRING: ReadonlySet<string> = new Set(["must", "must-not"]);
12
13
 
13
14
  type Hit = { readonly word: string; readonly span: Span };
14
15
 
15
- /** Where the lexicon's words stand in the sentence, outside quotations, in reading order. Needs the sentence's tokens. */
16
- const hitsIn = (sentence: Sentence, lexicon: Lexicon, quoted: readonly Span[]): Hit[] => {
16
+ /**
17
+ * Where the lexicon's words stand in the sentence, outside quotations, in reading order. Needs the sentence's tokens. A word
18
+ * right after a negation ("not always") admits exceptions instead of ruling them out, and is left out.
19
+ */
20
+ const hitsIn = (sentence: Sentence, lexicon: Lexicon, quoted: readonly Span[], negations: ReadonlySet<string> = new Set()): Hit[] => {
17
21
  const tokens = sentence.tokens ?? [];
18
22
  return lexicon
19
23
  .flatMap((entry) =>
20
24
  entryRanges(sentence, entry).flatMap((range) => {
21
25
  const first = tokens[range.start];
22
26
  const last = tokens[range.end - 1];
23
- if (first === undefined || last === undefined) return [];
27
+ const previous = tokens[range.start - 1];
28
+ if (first === undefined || last === undefined || (previous !== undefined && isNegation(previous, negations))) return [];
24
29
  const span = { start: first.span.start, end: last.span.end };
25
30
  return isWithinAny(quoted, span) ? [] : [{ word: entry.pattern, span }];
26
31
  }),
@@ -48,12 +53,12 @@ const innermost = (spans: readonly Span[], offset: number): Span | undefined =>
48
53
  const unitAt = (units: Units, offset: number): number =>
49
54
  [units.articles, units.lists, units.paragraphs].map((spans) => innermost(spans, offset)).find((span) => span !== undefined)?.start ?? offset;
50
55
 
51
- type Words = { readonly absolute: Lexicon; readonly exception: Lexicon; readonly lightVerbs: ReadonlySet<string> };
56
+ type Words = { readonly absolute: Lexicon; readonly exception: Lexicon; readonly lightVerbs: ReadonlySet<string>; readonly negations: ReadonlySet<string> };
52
57
 
53
58
  /** The sentence read for the rule, or nothing when it holds neither word. Only such sentences pay for the unit and the markers. */
54
59
  const statementOf = (sentence: Sentence, obligations: readonly Obligation[], words: Words, units: Units): Statement | undefined => {
55
60
  const quoted = quotedIn(sentence, QUOTATION_MARKS);
56
- const absolute = hitsIn(sentence, words.absolute, quoted);
61
+ const absolute = hitsIn(sentence, words.absolute, quoted, words.negations);
57
62
  const exception = hitsIn(sentence, words.exception, quoted);
58
63
  const tokens = sentence.tokens;
59
64
  if ((absolute.length === 0 && exception.length === 0) || tokens === undefined) return undefined;
@@ -79,6 +84,7 @@ export const absoluteException: Detector = (doc, options): Finding[] => {
79
84
  absolute: options.lexicon ?? [],
80
85
  exception: doc.lexicons["exception-marker"] ?? [],
81
86
  lightVerbs: new Set((doc.lexicons["light-verb"] ?? []).map((entry) => entry.pattern.toLowerCase())),
87
+ negations: negationWords(doc.lexicons["negation-word"]),
82
88
  };
83
89
  const obligations = obligationsOf(doc.structure);
84
90
  const units = unitsOf(doc, doc.structure);
@@ -41,11 +41,15 @@ export const headLabel = (text: string): { readonly label: string; readonly leng
41
41
 
42
42
  export type AbstractSpan = { readonly label: number; readonly body: Span };
43
43
 
44
- type Words = { readonly abstracts: ReadonlySet<string>; readonly sections: ReadonlySet<string> };
44
+ type Words = { readonly abstracts: ReadonlySet<string>; readonly sections: ReadonlySet<string>; readonly bookends: ReadonlySet<string> };
45
+
46
+ /** The lexicon group of a section that only opens or closes a text (はじめに, おわりに), which an essay has as well as a paper. */
47
+ const BOOKEND = "bookend";
45
48
 
46
49
  const wordsOf = (doc: ProseDocument): Words => {
47
- const set = (id: string): ReadonlySet<string> => new Set((doc.lexicons[id] ?? []).map((entry) => entry.pattern.toLowerCase()));
48
- return { abstracts: set("abstract-heading"), sections: set("paper-section-heading") };
50
+ const set = (id: string, group?: string): ReadonlySet<string> =>
51
+ new Set((doc.lexicons[id] ?? []).filter((entry) => group === undefined || entry.group === group).map((entry) => entry.pattern.toLowerCase()));
52
+ return { abstracts: set("abstract-heading"), sections: set("paper-section-heading"), bookends: set("paper-section-heading", BOOKEND) };
49
53
  };
50
54
 
51
55
  /** Abstracts under a heading of their own: the text up to the next heading. */
@@ -75,11 +79,17 @@ export const abstractsOf = (doc: ProseDocument): AbstractSpan[] => {
75
79
  return found.filter((abstract, index) => found.findIndex((other) => other.label === abstract.label) === index);
76
80
  };
77
81
 
78
- /** The first heading that names a paper's section, when there are MIN_SECTIONS of them; undefined otherwise. */
82
+ /**
83
+ * The first heading that names a paper's section, when there are MIN_SECTIONS of them and one is more than an opening or a
84
+ * closing; undefined otherwise. An article with only はじめに and おわりに around its own sections is an essay or a review,
85
+ * which carries no abstract.
86
+ */
79
87
  export const firstSectionHeading = (doc: ProseDocument): number | undefined => {
80
88
  const words = wordsOf(doc);
81
- const sections = (doc.markup?.headings ?? []).filter((heading) => words.sections.has(labelOf(heading.text)));
82
- return sections.length >= MIN_SECTIONS ? sections[0]?.start : undefined;
89
+ const labels = (doc.markup?.headings ?? []).map((heading) => ({ start: heading.start, label: labelOf(heading.text) }));
90
+ const sections = labels.filter(({ label }) => words.sections.has(label));
91
+ const hasBody = sections.some(({ label }) => !words.bookends.has(label));
92
+ return sections.length >= MIN_SECTIONS && hasBody ? sections[0]?.start : undefined;
83
93
  };
84
94
 
85
95
  type Measure = { readonly size: number; readonly limit: number | undefined; readonly unit: LengthUnit };
@@ -22,5 +22,27 @@ const followsVolitional = (at: number, tokens: readonly Token[]): boolean => {
22
22
  /** A が with only punctuation after it (思えるんですが……。) softens the sentence's end; it joins no second clause. */
23
23
  const endsSentence = (at: number, tokens: readonly Token[]): boolean => tokens.slice(at + 1).every((token) => isSpace(token) || CLOSING_POS.has(token.pos));
24
24
 
25
- /** The conjunctive が at `at` contrasts two clauses: not a volitional's concession, not a softened end. */
26
- export const isContrastiveGa = (at: number, tokens: readonly Token[]): boolean => !followsVolitional(at, tokens) && !endsSentence(at, tokens);
25
+ const NOMINAL_POS: ReadonlySet<string> = new Set(["NOUN", "PRON", "PROPN"]);
26
+
27
+ const isNominal = (token: Token | undefined): boolean => token !== undefined && NOMINAL_POS.has(token.pos);
28
+ const isComma = (token: Token | undefined): boolean => token?.surface === "、" || token?.surface === ",";
29
+
30
+ /**
31
+ * A Kyushu dialect topic しや (あんたしやが, ムツシユウしやが): the parser reads a verb し with no particle after a bare noun,
32
+ * then が as conjunctive; the が marks the noun.
33
+ */
34
+ const followsDialectTopic = (at: number, tokens: readonly Token[]): boolean => {
35
+ const [noun, verb, auxiliary] = [tokens[at - 3], tokens[at - 2], tokens[at - 1]];
36
+ return isNominal(noun) && verb?.surface === "し" && verb.pos === "VERB" && auxiliary?.surface === "や" && auxiliary.pos === "AUX";
37
+ };
38
+
39
+ /** A copula cut from its noun by a comma (恋、では無いが): the writer takes back the word just said; no clause is contrasted. */
40
+ const takesBackWord = (at: number, tokens: readonly Token[]): boolean => {
41
+ const comma = tokens.findLastIndex((token, index) => index < at && isComma(token));
42
+ const [copula, topic] = [tokens[comma + 1], tokens[comma + 2]];
43
+ return comma > 0 && isNominal(tokens[comma - 1]) && copula?.surface === "で" && copula.pos === "AUX" && topic?.surface === "は";
44
+ };
45
+
46
+ /** The conjunctive が at `at` contrasts two clauses: not a volitional's concession, not a softened end, not a misread particle. */
47
+ export const isContrastiveGa = (at: number, tokens: readonly Token[]): boolean =>
48
+ !followsVolitional(at, tokens) && !endsSentence(at, tokens) && !followsDialectTopic(at, tokens) && !takesBackWord(at, tokens);
@@ -24,6 +24,8 @@ export type AgreementLists = {
24
24
  readonly misnumbered: Lexicon;
25
25
  /** 冠詞の後ろに立たない限定詞(some / the)。 */
26
26
  readonly afterArticle: ReadonlySet<string>;
27
+ /** 名詞句を目的語に取る前置詞(on / of)。この後ろの this / these は主語にならない。 */
28
+ readonly prepositions?: ReadonlySet<string>;
27
29
  };
28
30
 
29
31
  export type Slip = { readonly variant: "number" | "possessive" | "determiner"; readonly first: Token; readonly last: Token; readonly word: string };
@@ -75,9 +77,15 @@ const isNamePart = (tokens: readonly Token[], at: number): boolean => UPPER_STAR
75
77
 
76
78
  const isModifier = (token: Token): boolean => token.pos === "ADJ" || token.pos === "ADV" || (token.pos === "VERB" && isParticiple(token));
77
79
 
78
- /** 限定詞の後ろの修飾語。数の形容詞(a few days)が挟まれば、単数の限定詞でも複数を数えるので undefined。 */
79
- const modifiersAfter = (tokens: readonly Token[], from: number, count: ReadonlySet<string>): readonly Token[] | undefined => {
80
- const end = tokens.findIndex((token, index) => index >= from && !isModifier(token));
80
+ /** 活用した動詞の形(flagged)。限定詞が主語になれない所では、名詞の前の分詞としか読めない。 */
81
+ const isInflectedVerb = (token: Token): boolean => token.pos === "VERB" && token.lemma !== undefined && token.lemma.toLowerCase() !== lower(token);
82
+
83
+ /**
84
+ * 限定詞の後ろの修飾語。数の形容詞(a few days)が挟まれば、単数の限定詞でも複数を数えるので undefined。
85
+ * bound は限定詞が前置詞の目的語の頭にあること。そこでは活用した動詞の形も修飾語(on these flagged post)。
86
+ */
87
+ const modifiersAfter = (tokens: readonly Token[], from: number, count: ReadonlySet<string>, bound: boolean): readonly Token[] | undefined => {
88
+ const end = tokens.findIndex((token, index) => index >= from && !isModifier(token) && !(bound && isInflectedVerb(token)));
81
89
  const modifiers = tokens.slice(from, end === -1 ? tokens.length : end);
82
90
  return modifiers.some((token) => count.has(lower(token))) ? undefined : modifiers;
83
91
  };
@@ -106,8 +114,14 @@ const determinerAt = (tokens: readonly Token[], at: number, lists: AgreementList
106
114
  */
107
115
  const standsAlone = (determiner: Determiner): boolean => determiner.length === 1 && !isArticle(determiner.head);
108
116
 
109
- const readsAsDeterminer = (determiner: Determiner, modifiers: readonly Token[]): boolean =>
110
- !standsAlone(determiner) || modifiers.some((token) => token.pos === "ADJ");
117
+ const readsAsDeterminer = (determiner: Determiner, modifiers: readonly Token[], bound: boolean): boolean =>
118
+ !standsAlone(determiner) || (bound && modifiers.length > 0) || modifiers.some((token) => token.pos === "ADJ");
119
+
120
+ /** 限定詞が前置詞のすぐ後ろにあるか(on these)。前置詞の目的語の頭は主語にならないので、後ろの語は動詞ではない。 */
121
+ const followsPreposition = (tokens: readonly Token[], at: number, prepositions: ReadonlySet<string> | undefined): boolean => {
122
+ const before = tokens[at - 1];
123
+ return before !== undefined && (prepositions?.has(lower(before)) ?? false);
124
+ };
111
125
 
112
126
  const mayBeNoun = (token: Token): boolean => token.features?.["AlsoNoun"] === "Yes" || isGuessed(token);
113
127
 
@@ -116,8 +130,17 @@ const mayBeNoun = (token: Token): boolean => token.features?.["AlsoNoun"] === "Y
116
130
  * an individual works(individual は名詞にもなる)/ Those responsible report to the board(those は代名詞にもなる)。
117
131
  * 後ろが is / has なら、名詞は動詞ではない(these key result is)。
118
132
  */
119
- const mayBeVerb = (determiner: Determiner, modifiers: readonly Token[], noun: Token, next: Token | undefined, finite: ReadonlySet<string>): boolean =>
120
- noun.features?.["AlsoVerb"] === "Yes" && !(next !== undefined && finite.has(lower(next))) && (standsAlone(determiner) || modifiers.some(mayBeNoun));
133
+ const mayBeVerb = (
134
+ determiner: Determiner,
135
+ modifiers: readonly Token[],
136
+ noun: Token,
137
+ next: Token | undefined,
138
+ finite: ReadonlySet<string>,
139
+ bound: boolean,
140
+ ): boolean =>
141
+ noun.features?.["AlsoVerb"] === "Yes" &&
142
+ !(next !== undefined && finite.has(lower(next))) &&
143
+ ((standsAlone(determiner) && !bound) || modifiers.some(mayBeNoun));
121
144
 
122
145
  /** 冠詞は名詞句の頭に立つ。形容詞や数の後ろの a は、記号の名前(the eight 3-hourly a indices)。 */
123
146
  const AFTER_MODIFIER = new Set(["ADJ", "NUM"]);
@@ -128,14 +151,15 @@ const isLetterName = (tokens: readonly Token[], at: number, determiner: Determin
128
151
  const numberSlipAt = (source: string, tokens: readonly Token[], at: number, lists: AgreementLists): Slip | undefined => {
129
152
  const determiner = determinerAt(tokens, at, lists);
130
153
  if (determiner === undefined || isNamePart(tokens, at) || isLetterName(tokens, at, determiner)) return undefined;
131
- const modifiers = modifiersAfter(tokens, at + determiner.length, lists.count);
132
- if (modifiers === undefined || !readsAsDeterminer(determiner, modifiers)) return undefined;
154
+ const bound = standsAlone(determiner) && followsPreposition(tokens, at, lists.prepositions);
155
+ const modifiers = modifiersAfter(tokens, at + determiner.length, lists.count, bound);
156
+ if (modifiers === undefined || !readsAsDeterminer(determiner, modifiers, bound)) return undefined;
133
157
  const nounAt = at + determiner.length + modifiers.length;
134
158
  const noun = tokens[nounAt];
135
159
  if (!isCommonNoun(noun) || !hasOneNumber(noun, lists.invariant) || isPlural(noun) === determiner.plural) return undefined;
136
160
  // A file name or a path (a quotes.json, a docs/ folder) is spelled as it must be, not counted.
137
161
  if (isPartOfAddress(source, noun.span.start, noun.span.end)) return undefined;
138
- if (mayBeVerb(determiner, modifiers, noun, tokens[nounAt + 1], lists.finite)) return undefined;
162
+ if (mayBeVerb(determiner, modifiers, noun, tokens[nounAt + 1], lists.finite, bound)) return undefined;
139
163
  const span = tokens.slice(at, nounAt + 1);
140
164
  if (!endsNounPhrase(tokens[nounAt + 1], lists.finite) || !joinedBySpace(source, span) || isPartOfLongerWord(source, determiner.head, noun)) return undefined;
141
165
  return slipOf("number", source, determiner.head, noun);
@@ -211,6 +235,7 @@ const listsOf = (lexicons: Readonly<Record<string, Lexicon>>): AgreementLists =>
211
235
  finite: setOf(lexicons["finite-auxiliary"]),
212
236
  misnumbered: lexicons["misnumbered-phrase"] ?? [],
213
237
  afterArticle: setOf(lexicons["determiner-after-article"]),
238
+ prepositions: setOf(lexicons["object-preposition"]),
214
239
  });
215
240
 
216
241
  export const agreementSlip: Detector = (doc): Finding[] => {
@@ -1,4 +1,4 @@
1
- import type { Detector, Finding, ProseDocument, Span } from "../plugin.ts";
1
+ import type { Detector, DetectorOptions, Finding, Paragraph, ProseDocument, Span, Token } from "../plugin.ts";
2
2
 
3
3
  /** A bold run longer than this is a bold sentence, not a label. */
4
4
  const MAX_LABEL_CHARS = 40;
@@ -61,20 +61,88 @@ const unquotedItems = (doc: ProseDocument, opens: (item: string) => string | und
61
61
  /** The list items, in document order, that open with a bold label and are not quoted. */
62
62
  export const boldLabelItems = (doc: ProseDocument): Span[] => unquotedItems(doc, boldLabelOf);
63
63
 
64
- /** A count, not a density: a person writes one or two labels even in a long article. A bold lead sentence counts as a label. */
64
+ /** Bold lead sentences that report on their own (the rule's min_leads). */
65
+ const DEFAULT_MIN_LEADS = 3;
66
+
67
+ /** Paragraphs opened by a bold statement that report on their own (the rule's min_clause_paragraphs). */
68
+ const DEFAULT_MIN_CLAUSE_PARAGRAPHS = 3;
69
+
70
+ const countSetting = (options: DetectorOptions, name: string, fallback: number): number => {
71
+ const value = options.settings?.[name];
72
+ return typeof value === "number" ? value : fallback;
73
+ };
74
+
75
+ const minLeads = (options: DetectorOptions): number => countSetting(options, "min_leads", DEFAULT_MIN_LEADS);
76
+
77
+ const VERBAL = new Set(["VERB", "AUX"]);
78
+
79
+ /** Words that state something: a verb after a first word that is not one. An imperative (Talk to …), a term (Work schedule) or a gerund heading is not. */
80
+ const isStatement = (tokens: readonly Token[]): boolean => {
81
+ const words = tokens.filter((token) => token.pos !== "PUNCT" && token.pos !== "SYM");
82
+ const head = words[0];
83
+ return head !== undefined && !VERBAL.has(head.pos) && words.slice(1).some((token) => VERBAL.has(token.pos));
84
+ };
85
+
86
+ /** The bold run a paragraph opens with, as a label or lead sentence, and where in the paragraph its words end. */
87
+ const openingRunOf = (text: string): { words: string; end: number } | undefined => {
88
+ const match = BOLD_LABEL.exec(text) ?? BOLD_LEAD.exec(text);
89
+ const words = match?.[2];
90
+ if (match?.[1] === undefined || words === undefined || isCodeOnly(words.trim())) return undefined;
91
+ return { words: words.trim(), end: match[1].length + words.length };
92
+ };
93
+
94
+ /** The statement a paragraph opens with in bold (**Usage grew each week**: …), or undefined. A question (an FAQ's) is not a statement. */
95
+ const boldStatementOf = (doc: ProseDocument, paragraph: Paragraph): string | undefined => {
96
+ const { start, end } = paragraph.span;
97
+ const run = isQuotedAt(doc.source, start) ? undefined : openingRunOf(doc.source.slice(start, end));
98
+ if (run === undefined || /[??]$/u.test(run.words)) return undefined;
99
+ const runEnd = start + run.end;
100
+ const tokens = paragraph.sentences.flatMap((sentence) => sentence.tokens ?? []).filter((token) => token.span.start >= start && token.span.start < runEnd);
101
+ return isStatement(tokens) ? run.words.replace(/[.!。!]$/u, "") : undefined;
102
+ };
103
+
104
+ /** The count reported and the limit it reached: all the labelled items, or else the bold lead sentences alone, or undefined. */
105
+ const reached = (items: readonly Span[], leads: number, options: DetectorOptions): { count: number; limit: number } | undefined => {
106
+ if (items.length >= options.limit) return { count: items.length, limit: options.limit };
107
+ const least = minLeads(options);
108
+ return leads >= least ? { count: leads, limit: least } : undefined;
109
+ };
110
+
111
+ const finding = (doc: ProseDocument, span: Span, label: string, found: { count: number; limit: number }, variant?: string): Finding => ({
112
+ rule: "bold-label-list",
113
+ severity: "info",
114
+ line: 0,
115
+ column: 0,
116
+ quote: (doc.source.slice(span.start, span.end).split("\n")[0] ?? "").trim(),
117
+ values: { label, count: found.count, limit: found.limit, offset: span.start },
118
+ ...(variant === undefined ? {} : { variant }),
119
+ });
120
+
121
+ /**
122
+ * Paragraphs that each open with a bold statement (**Usage grew each week**: …): findings set as captions. Human run-in heads
123
+ * are terms, imperatives or questions (**Work schedule**:, **Talk to the people:**, **Who is my audience?**), and are not counted.
124
+ */
125
+ const statementParagraphs = (doc: ProseDocument, options: DetectorOptions): Finding[] => {
126
+ const statements = doc.paragraphs.flatMap((paragraph) => {
127
+ const label = boldStatementOf(doc, paragraph);
128
+ return label === undefined ? [] : [{ span: paragraph.span, label }];
129
+ });
130
+ const first = statements[0];
131
+ const limit = countSetting(options, "min_clause_paragraphs", DEFAULT_MIN_CLAUSE_PARAGRAPHS);
132
+ return first === undefined || statements.length < limit ? [] : [finding(doc, first.span, first.label, { count: statements.length, limit }, "paragraphs")];
133
+ };
134
+
135
+ /**
136
+ * A count, not a density: a person writes one or two labels even in a long article. A bold lead sentence counts as a label.
137
+ * Bold lead sentences (- **Check one result by hand.** …) report at fewer items than colon labels: human documents write a few
138
+ * colon labels for steps or fields (- **Gather input**: …), but rarely make a list of bold lead sentences.
139
+ */
65
140
  export const boldLabelList: Detector = (doc, options): Finding[] => {
66
141
  const items = unquotedItems(doc, labelOrLeadOf);
67
142
  const first = items[0];
68
- if (first === undefined || items.length < options.limit) return [];
69
- const written = doc.source.slice(first.start, first.end);
70
- return [
71
- {
72
- rule: "bold-label-list",
73
- severity: "info",
74
- line: 0,
75
- column: 0,
76
- quote: (written.split("\n")[0] ?? "").trim(),
77
- values: { label: labelOrLeadOf(written) ?? "", count: items.length, limit: options.limit, offset: first.start },
78
- },
79
- ];
143
+ const leads = items.filter((span) => boldLabelOf(doc.source.slice(span.start, span.end)) === undefined).length;
144
+ const found = reached(items, leads, options);
145
+ const paragraphs = statementParagraphs(doc, options);
146
+ if (first === undefined || found === undefined) return paragraphs;
147
+ return [finding(doc, first, labelOrLeadOf(doc.source.slice(first.start, first.end)) ?? "", found)];
80
148
  };
@@ -0,0 +1,21 @@
1
+ import type { Span } from "../plugin.ts";
2
+
3
+ /** The bold marks around a run. */
4
+ const BOLD_MARKS = /^(?:\*\*|__)(.*)(?:\*\*|__)$/su;
5
+
6
+ /** Each opening quote mark or backtick, with the mark that closes it. */
7
+ const CLOSING: Readonly<Record<string, string>> = { '"': '"', "“": "”", "'": "'", "‘": "’", "「": "」", "『": "』", "`": "`" };
8
+
9
+ /** A quotation or a code span that is the whole run: the writer names the words, as a README marks the part of an example it means. */
10
+ const isWhollyQuoted = (text: string): boolean => {
11
+ const chars = Array.from(text);
12
+ const close = CLOSING[chars[0] ?? ""];
13
+ const inside = chars.slice(1, -1);
14
+ return close !== undefined && chars.length > 2 && chars.at(-1) === close && !inside.includes(close) && !inside.includes(chars[0] ?? "");
15
+ };
16
+
17
+ /** Whether the bold run is nothing but a quoted phrase (**"であったが"**, **`strict`**): a mention of words, not emphasis. */
18
+ export const isQuotedMention = (source: string, span: Span): boolean => {
19
+ const inner = BOLD_MARKS.exec(source.slice(span.start, span.end))?.[1];
20
+ return inner !== undefined && isWhollyQuoted(inner.trim());
21
+ };
@@ -157,3 +157,13 @@ export const bracketPlaceholderSpans = (source: string): Span[] =>
157
157
  [...source.matchAll(BRACKETS)]
158
158
  .filter((hit) => isCapitalPlaceholder(hit[0], source.slice(hit.index + hit[0].length, hit.index + hit[0].length + 1)))
159
159
  .map((hit) => ({ start: hit.index, end: hit.index + hit[0].length }));
160
+
161
+ const OPENING_QUOTE = /["“‘']$/u;
162
+ const CLOSING_QUOTE = /^[.,;:!?]?["”’']/u;
163
+
164
+ /**
165
+ * A capital run that is a whole quotation (mark it “THIS DOCUMENT CONTAINS CONFIDENTIAL INFORMATION.”): the words a reader is to
166
+ * write or will see as they stand, quoted from a label or a sign, not the writer raising their voice.
167
+ */
168
+ export const isWholeQuotation = (source: string, start: number, end: number): boolean =>
169
+ OPENING_QUOTE.test(source.slice(Math.max(0, start - 1), start)) && CLOSING_QUOTE.test(source.slice(end, end + 2));
@@ -21,13 +21,13 @@ import { isOneName } from "./name-run.ts";
21
21
  import { isOrganisationHead, isOrganisationRun, type OrganisationWords } from "./organisation-run.ts";
22
22
  import { endsInTitle, inStatuteTitle, isTitlePosition, isTitledName, repeatedRuns, titleBody, type TitleWords } from "./titled-run.ts";
23
23
  import { proseText } from "../measure.ts";
24
- import { parallelDotCount } from "./middle-dot.ts";
25
24
  import { maskSpans } from "../mask.ts";
26
25
  import { quotedSpans } from "../quoted-span.ts";
27
26
  import { nameSpans } from "../team-names.ts";
28
27
  import { isIn } from "../lexicon-genres.ts";
29
28
  import { holdsKnown, isInnerSuffix, isTitledPerson, standaloneNames, unknownPieces } from "./kanji-run-pieces.ts";
30
29
  import { isBibliographyEntry } from "./bibliography-entry.ts";
30
+ import { isNamedByContext } from "./named-by-context.ts";
31
31
 
32
32
  /**
33
33
  * 文字の並びを見る検出。漢字の連なりが住所か名前かだけは、形態素解析の固有名詞と数で決める。
@@ -142,6 +142,10 @@ type NameWords = {
142
142
  readonly listSuffixes: readonly string[];
143
143
  /** 連なりを閉じる、読み手が一つの語と知っている長い語(内閣総理大臣、許可事業者)。その前で連なりを割る。 */
144
144
  readonly knownWords: ReadonlySet<string>;
145
+ /** 制度が区分に入れることを言う句(として認定)。連なりのすぐ後ろに続けば、連なりは区分の名前。 */
146
+ readonly designations: readonly string[];
147
+ /** お知らせやメールの題を閉じる語(お知らせ、ご案内)。 */
148
+ readonly noticeEndings: readonly string[];
145
149
  };
146
150
 
147
151
  type Tail = AddresseeSuffix;
@@ -253,7 +257,7 @@ const measuredOf = (tokens: readonly Token[], run: KanjiRun, span: Span, words:
253
257
  * 住所か名前かは、それを外した残りで決める(1日日本銀行の「日本銀行」)。品詞が無ければ判定しない。
254
258
  */
255
259
  const measuredRun = (tokens: readonly Token[] | undefined, run: KanjiRun, context: RunContext): string => {
256
- if (run.quoted || (context.headwords && run.alone)) return "";
260
+ if (run.quoted || (context.headwords && run.alone) || isNamedByContext(run, context.words)) return "";
257
261
  if (tokens === undefined || run.span === undefined) return run.text;
258
262
  const { rest, text, keptHead } = measuredOf(tokens, run, run.span, context.words);
259
263
  if (context.presented.has(text) || inStatuteTitle(tokens, run.brackets, context.words.fixedName)) return "";
@@ -361,6 +365,8 @@ const nameWordsOf = (doc: ProseDocument): NameWords => {
361
365
  references: patterns("reference-prefix"),
362
366
  listSuffixes: patterns("list-suffix"),
363
367
  knownWords: new Set(patterns("kanji-known-word")),
368
+ designations: patterns("designation-phrase"),
369
+ noticeEndings: patterns("notice-title-ending"),
364
370
  };
365
371
  };
366
372
 
@@ -405,23 +411,3 @@ export const kanjiRun: Detector = (doc, options): Finding[] => {
405
411
  values: { word: run, count: run.length, limit: options.limit, offset: sentence.span.start },
406
412
  }));
407
413
  };
408
-
409
- /**
410
- * 中黒で並べると、どこまでが 1 つの項目か分からなくなる。
411
- * 「企画・開発・運用・保守体制」は、保守体制が 1 つなのか保守と体制なのか読めない。
412
- * 語彙表(nakaguro-word)の、中黒を含めて 1 語の語(キャッシュ・フロー)の中黒は並べていないので数えない。
413
- */
414
- export const middleDot: Detector = (doc, options): Finding[] => {
415
- const words = (options.lexicon ?? []).map((entry) => entry.pattern).toSorted((left, right) => right.length - left.length);
416
- return doc.sentences
417
- .map((sentence) => ({ sentence, count: parallelDotCount(sentence.text, words) }))
418
- .filter(({ count }) => count > options.limit)
419
- .map(({ sentence, count }) => ({
420
- rule: "no-nakaguro-parallel",
421
- severity: "info",
422
- line: 0,
423
- column: 0,
424
- quote: sentence.text.trim(),
425
- values: { count, limit: options.limit, offset: sentence.span.start },
426
- }));
427
- };
@@ -52,18 +52,29 @@ export const endingOf = (sentence: Sentence): string | undefined => {
52
52
  return [headToken !== undefined && VERBAL_POS.has(headToken.pos) ? headToken.surface : "", ...tail].join("");
53
53
  };
54
54
 
55
- type Ended = { readonly sentence: Sentence; readonly ending: string | undefined };
55
+ type Ended = { readonly sentence: Sentence; readonly ending: string | undefined; readonly opensItem: boolean };
56
+
57
+ /** A label at the head of a sentence: a bracketed name ([通信関連], 【部品】) or a name with leader dots (化学品事業……). */
58
+ const ITEM_LABEL = /^\s*(?:[[【[][^]】\]\n]{1,30}[]】\]]|[^\s。、]{1,20}[…‥]+)/u;
59
+
60
+ /** The sentence opens an item of a list written as running text: a new entry, not the next sentence of the one before. */
61
+ const opensItem = (sentence: Sentence): boolean => ITEM_LABEL.test(sentence.text);
56
62
 
57
63
  /**
58
64
  * Runs of consecutive sentences with the same ending. A sentence with no ending to compare closes a run, and so does a
59
65
  * question run together with the next one inside a single sentence (これはリストか?順序付きか?などです。): it is not the writer's ending.
66
+ * A sentence opening a labelled item ([通信関連]…) starts a new run: entries of a list end alike by design.
60
67
  */
61
68
  export const endingRuns = (sentences: readonly Sentence[]): Ended[][] =>
62
69
  sentences
63
- .map((sentence, index) => ({ sentence, ending: continuesThrough(sentences, index) ? undefined : endingOf(sentence) }))
70
+ .map((sentence, index) => ({
71
+ sentence,
72
+ ending: continuesThrough(sentences, index) ? undefined : endingOf(sentence),
73
+ opensItem: opensItem(sentence),
74
+ }))
64
75
  .reduce<Ended[][]>((runs, ended) => {
65
76
  const last = runs.at(-1) ?? [];
66
- const continues = ended.ending !== undefined && last[0]?.ending === ended.ending;
77
+ const continues = ended.ending !== undefined && !ended.opensItem && last[0]?.ending === ended.ending;
67
78
  return continues ? [...runs.slice(0, -1), [...last, ended]] : [...runs, [ended]];
68
79
  }, [])
69
80
  .filter((run) => run[0]?.ending !== undefined);
@@ -0,0 +1,40 @@
1
+ // The focus of a cleft sentence: what it states, after the clause that only presents it (いちばん大きく変わったのは、
2
+ // 季節に気づくようになったことだ。 states 季節に気づくようになった). Pure; the topic markers and closing words come
3
+ // from the language package's cleft-frame lexicon, so a language without one has no clefts.
4
+ import type { LexiconEntry, Span } from "../plugin.ts";
5
+
6
+ const SENTENCE_END = new Set("。..!?!? \t\n\u3000");
7
+ const FOCUS_START = new Set("、,, \t\n\u3000");
8
+
9
+ const withoutTrailing = (text: string, marks: ReadonlySet<string>): string => {
10
+ const chars = [...text];
11
+ const kept = chars.findLastIndex((char) => !marks.has(char));
12
+ return chars.slice(0, kept + 1).join("");
13
+ };
14
+
15
+ const leadingCount = (text: string, marks: ReadonlySet<string>): number => {
16
+ const at = [...text].findIndex((char) => !marks.has(char));
17
+ return at === -1 ? text.length : at;
18
+ };
19
+
20
+ const patternsOf = (entries: readonly LexiconEntry[], group: string): string[] =>
21
+ entries.filter((entry) => entry.group === group).map((entry) => entry.pattern);
22
+
23
+ const firstTopicEnd = (body: string, topics: readonly string[]): number | undefined => {
24
+ const ends = topics.flatMap((topic) => {
25
+ const at = body.indexOf(topic);
26
+ return at > 0 ? [at + topic.length] : [];
27
+ });
28
+ return ends.length === 0 ? undefined : Math.min(...ends);
29
+ };
30
+
31
+ /** The focus's offsets in `text`, when the text opens with a topic clause and ends with a closing word; otherwise undefined. */
32
+ export const cleftFocus = (text: string, entries: readonly LexiconEntry[]): Span | undefined => {
33
+ const body = withoutTrailing(text, SENTENCE_END);
34
+ const close = patternsOf(entries, "close").find((pattern) => body.endsWith(pattern));
35
+ const topicEnd = firstTopicEnd(body, patternsOf(entries, "topic"));
36
+ if (close === undefined || topicEnd === undefined) return undefined;
37
+ const start = topicEnd + leadingCount(body.slice(topicEnd), FOCUS_START);
38
+ const end = body.length - close.length;
39
+ return start < end ? { start, end } : undefined;
40
+ };
@@ -1,5 +1,6 @@
1
1
  import { charLength, proseText } from "../measure.ts";
2
2
  import type { Detector, Finding, Section } from "../plugin.ts";
3
+ import { isQuotedMention } from "./bold-quoted.ts";
3
4
 
4
5
  /** これより短い節では密度が暴れる。43 字に 1 箇所で「1000 字あたり 23」になる。 */
5
6
  const MIN_CHARS = 200;
@@ -8,6 +9,10 @@ const PER = 1000;
8
9
 
9
10
  const charsOf = (section: Section): number => section.sentences.reduce((sum, sentence) => sum + charLength(sentence), 0);
10
11
 
12
+ /** The section's bold runs, less those that only quote words: a README bolds the part of an example sentence it talks about. */
13
+ const boldsOf = (section: Section, source: string): number =>
14
+ section.strongs === undefined ? section.strongCount : section.strongs.filter((span) => !isQuotedMention(source, span)).length;
15
+
11
16
  /**
12
17
  * 節あたりの「密度」を見る。件数ではない。
13
18
  *
@@ -18,11 +23,11 @@ const charsOf = (section: Section): number => section.sentences.reduce((sum, sen
18
23
  */
19
24
  export const countPerSection: Detector = (doc, options): Finding[] =>
20
25
  doc.sections
21
- .map((section) => ({ section, chars: charsOf(section) }))
26
+ .map((section) => ({ section, chars: charsOf(section), bolds: boldsOf(section, doc.source) }))
22
27
  .filter(({ chars }) => chars >= MIN_CHARS)
23
- .map(({ section, chars }) => ({ section, chars, density: Math.round((section.strongCount / chars) * PER) }))
28
+ .map(({ section, chars, bolds }) => ({ section, chars, bolds, density: Math.round((bolds / chars) * PER) }))
24
29
  .filter(({ density }) => density > options.limit)
25
- .map(({ section, chars, density }) => ({
30
+ .map(({ section, chars, bolds, density }) => ({
26
31
  rule: "bold-density",
27
32
  severity: "warning",
28
33
  line: 0,
@@ -32,7 +37,7 @@ export const countPerSection: Detector = (doc, options): Finding[] =>
32
37
  values: {
33
38
  count: density,
34
39
  limit: options.limit,
35
- bolds: section.strongCount,
40
+ bolds,
36
41
  chars,
37
42
  offset: section.firstSentence?.span.start ?? section.span.start,
38
43
  },
@@ -186,7 +186,8 @@ const isOrdinaryPhraseAt = (doc: ProseDocument, offset: number, term: string, de
186
186
  /** The term written longer with a word of its definition (文書管理責任者, the Application), after the sentence that defines it. */
187
187
  const extendedFindings = (doc: ProseDocument, texts: readonly BodyText[], term: DefinedTerm, spans: readonly Span[], defined: readonly string[]): Finding[] => {
188
188
  const definition = definingSentence(doc, term.span)?.text ?? "";
189
- const pointers = patternsOf(doc, "defined-term-pointer");
189
+ // A pointer (当該管理責任者) points at the term, and the definition's own marker (以下本契約において同じ) is no word of its meaning.
190
+ const pointers = [...patternsOf(doc, "defined-term-pointer"), ...patternsOf(doc, "definition-marker")];
190
191
  // Every sentence that defines the term (a second definition too) holds the long words it is defined from.
191
192
  const defining = spans.map((span) => definingSentence(doc, span)?.span ?? span);
192
193
  const definingEnd = definingSentenceEnd(doc, term.span);
@@ -1,5 +1,13 @@
1
- import type { Detector, Finding, ProseDocument } from "../plugin.ts";
2
- import { definedTerms, unusedDefinitions, usesBeforeDefinition, type BodyText, type IsTitle, type Mentioned } from "../structure/definition-use.ts";
1
+ import type { Detector, Finding, ProseDocument, StructureNode } from "../plugin.ts";
2
+ import {
3
+ definedTerms,
4
+ unusedDefinitions,
5
+ usesBeforeDefinition,
6
+ type BodyText,
7
+ type DefinedTerm,
8
+ type IsTitle,
9
+ type Mentioned,
10
+ } from "../structure/definition-use.ts";
3
11
  import { titleLineNumbers } from "../structure/title-lines.ts";
4
12
  import { contentsLineNumbers } from "../structure/contents-lines.ts";
5
13
  import { summarisesLaterDefinition, summarySections } from "../structure/summary-lines.ts";
@@ -7,6 +15,7 @@ import { expansionConflicts, expansionsIn } from "../acronym-expansions.ts";
7
15
  import { linesOf, lineNumberAt } from "../structure/lines.ts";
8
16
  import { isQuotedAlone } from "../quoted-span.ts";
9
17
  import { quoteAt } from "./structure-tree.ts";
18
+ import { articlesInCitedDocuments } from "../structure/cited-document-section.ts";
10
19
 
11
20
  const bodyOf = (doc: ProseDocument): BodyText[] => doc.sentences.map((sentence) => ({ start: sentence.span.start, text: sentence.text }));
12
21
 
@@ -50,19 +59,29 @@ const titleIn = (doc: ProseDocument): IsTitle => {
50
59
  const lines = linesOf(doc.source);
51
60
  const headings = doc.markup?.headings ?? [];
52
61
  const numbers = new Set([...titleLineNumbers(doc.structure, lines, headings), ...contentsLineNumbers(lines, headings, patternsOf(doc, "toc-heading"))]);
53
- const summaries = summarySections(lines, headings, [...patternsOf(doc, "summary-heading"), ...patternsOf(doc, "headnote-heading")]);
62
+ const summaries = summarySections(lines, headings, [
63
+ ...patternsOf(doc, "summary-heading"),
64
+ ...patternsOf(doc, "headnote-heading"),
65
+ ...patternsOf(doc, "introduction-heading"),
66
+ ]);
54
67
  return (offset, definedAt) => {
55
68
  const line = lineNumberAt(lines, offset) ?? 0;
56
69
  return numbers.has(line) || summarisesLaterDefinition(summaries, line, lineNumberAt(lines, definedAt) ?? 0);
57
70
  };
58
71
  };
59
72
 
73
+ /** 他の文書を引き写した節の条(「## 参考:根拠条文」の下の第9条)の定義は、その文書の定義で、この文書の語の定義ではない。 */
74
+ const ownDefinitions = (tree: StructureNode): DefinedTerm[] => {
75
+ const cited = articlesInCitedDocuments(tree).map((article) => article.span);
76
+ return definedTerms(tree).filter((term) => !cited.some((span) => span.start <= term.span.start && term.span.start < span.end));
77
+ };
78
+
60
79
  /** 文の途中で括弧に入れて定義した語を、定義より前で使っている所。 */
61
80
  export const useBeforeDefinition: Detector = (doc): Finding[] =>
62
81
  doc.structure === undefined
63
82
  ? []
64
83
  : usesBeforeDefinition(
65
- definedTerms(doc.structure),
84
+ ownDefinitions(doc.structure),
66
85
  bodyOf(doc),
67
86
  mentionedIn(doc),
68
87
  titleIn(doc),