chaffjs 0.42.0 → 0.44.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 (330) 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/agreement-slip.d.ts +2 -0
  13. package/dist/detectors/agreement-slip.d.ts.map +1 -1
  14. package/dist/detectors/agreement-slip.js +22 -8
  15. package/dist/detectors/agreement-slip.js.map +1 -1
  16. package/dist/detectors/bold-label.d.ts +7 -1
  17. package/dist/detectors/bold-label.d.ts.map +1 -1
  18. package/dist/detectors/bold-label.js +26 -3
  19. package/dist/detectors/bold-label.js.map +1 -1
  20. package/dist/detectors/bold-quoted.d.ts +4 -0
  21. package/dist/detectors/bold-quoted.d.ts.map +1 -0
  22. package/dist/detectors/bold-quoted.js +17 -0
  23. package/dist/detectors/bold-quoted.js.map +1 -0
  24. package/dist/detectors/caps-caption.d.ts +5 -0
  25. package/dist/detectors/caps-caption.d.ts.map +1 -1
  26. package/dist/detectors/caps-caption.js +7 -0
  27. package/dist/detectors/caps-caption.js.map +1 -1
  28. package/dist/detectors/clause-shape.d.ts +8 -2
  29. package/dist/detectors/clause-shape.d.ts.map +1 -1
  30. package/dist/detectors/clause-shape.js +14 -6
  31. package/dist/detectors/clause-shape.js.map +1 -1
  32. package/dist/detectors/count-per-section.d.ts.map +1 -1
  33. package/dist/detectors/count-per-section.js +7 -4
  34. package/dist/detectors/count-per-section.js.map +1 -1
  35. package/dist/detectors/defined-term-form.d.ts.map +1 -1
  36. package/dist/detectors/defined-term-form.js +2 -1
  37. package/dist/detectors/defined-term-form.js.map +1 -1
  38. package/dist/detectors/document-shape.d.ts +6 -1
  39. package/dist/detectors/document-shape.d.ts.map +1 -1
  40. package/dist/detectors/document-shape.js +14 -4
  41. package/dist/detectors/document-shape.js.map +1 -1
  42. package/dist/detectors/doubled-word.d.ts.map +1 -1
  43. package/dist/detectors/doubled-word.js +5 -1
  44. package/dist/detectors/doubled-word.js.map +1 -1
  45. package/dist/detectors/emoticon.d.ts +6 -0
  46. package/dist/detectors/emoticon.d.ts.map +1 -0
  47. package/dist/detectors/emoticon.js +19 -0
  48. package/dist/detectors/emoticon.js.map +1 -0
  49. package/dist/detectors/en-shape.d.ts +6 -1
  50. package/dist/detectors/en-shape.d.ts.map +1 -1
  51. package/dist/detectors/en-shape.js +21 -2
  52. package/dist/detectors/en-shape.js.map +1 -1
  53. package/dist/detectors/ending-refrain.d.ts +9 -0
  54. package/dist/detectors/ending-refrain.d.ts.map +1 -0
  55. package/dist/detectors/ending-refrain.js +52 -0
  56. package/dist/detectors/ending-refrain.js.map +1 -0
  57. package/dist/detectors/fact-consistency.d.ts.map +1 -1
  58. package/dist/detectors/fact-consistency.js +5 -1
  59. package/dist/detectors/fact-consistency.js.map +1 -1
  60. package/dist/detectors/gram-predicate.d.ts.map +1 -1
  61. package/dist/detectors/gram-predicate.js +12 -3
  62. package/dist/detectors/gram-predicate.js.map +1 -1
  63. package/dist/detectors/katakana-density.d.ts +6 -1
  64. package/dist/detectors/katakana-density.d.ts.map +1 -1
  65. package/dist/detectors/katakana-density.js +14 -1
  66. package/dist/detectors/katakana-density.js.map +1 -1
  67. package/dist/detectors/lexicon.d.ts.map +1 -1
  68. package/dist/detectors/lexicon.js +3 -1
  69. package/dist/detectors/lexicon.js.map +1 -1
  70. package/dist/detectors/lookalike-character.d.ts +2 -0
  71. package/dist/detectors/lookalike-character.d.ts.map +1 -1
  72. package/dist/detectors/lookalike-character.js +36 -9
  73. package/dist/detectors/lookalike-character.js.map +1 -1
  74. package/dist/detectors/mark-shape.d.ts +3 -3
  75. package/dist/detectors/mark-shape.d.ts.map +1 -1
  76. package/dist/detectors/mark-shape.js +53 -17
  77. package/dist/detectors/mark-shape.js.map +1 -1
  78. package/dist/detectors/mentioned-phrase.d.ts +3 -1
  79. package/dist/detectors/mentioned-phrase.d.ts.map +1 -1
  80. package/dist/detectors/mentioned-phrase.js +9 -0
  81. package/dist/detectors/mentioned-phrase.js.map +1 -1
  82. package/dist/detectors/number-style.d.ts +7 -1
  83. package/dist/detectors/number-style.d.ts.map +1 -1
  84. package/dist/detectors/number-style.js +34 -2
  85. package/dist/detectors/number-style.js.map +1 -1
  86. package/dist/detectors/number-unit.d.ts +7 -1
  87. package/dist/detectors/number-unit.d.ts.map +1 -1
  88. package/dist/detectors/number-unit.js +20 -6
  89. package/dist/detectors/number-unit.js.map +1 -1
  90. package/dist/detectors/obligation-without-deadline.d.ts +10 -2
  91. package/dist/detectors/obligation-without-deadline.d.ts.map +1 -1
  92. package/dist/detectors/obligation-without-deadline.js +47 -2
  93. package/dist/detectors/obligation-without-deadline.js.map +1 -1
  94. package/dist/detectors/open-end-names.d.ts +2 -0
  95. package/dist/detectors/open-end-names.d.ts.map +1 -1
  96. package/dist/detectors/open-end-names.js +8 -1
  97. package/dist/detectors/open-end-names.js.map +1 -1
  98. package/dist/detectors/orthographic-variant.d.ts.map +1 -1
  99. package/dist/detectors/orthographic-variant.js +5 -3
  100. package/dist/detectors/orthographic-variant.js.map +1 -1
  101. package/dist/detectors/paragraph-pointer.d.ts +4 -0
  102. package/dist/detectors/paragraph-pointer.d.ts.map +1 -0
  103. package/dist/detectors/paragraph-pointer.js +22 -0
  104. package/dist/detectors/paragraph-pointer.js.map +1 -0
  105. package/dist/detectors/particle-run-long-forms.d.ts +7 -0
  106. package/dist/detectors/particle-run-long-forms.d.ts.map +1 -0
  107. package/dist/detectors/particle-run-long-forms.js +23 -0
  108. package/dist/detectors/particle-run-long-forms.js.map +1 -0
  109. package/dist/detectors/particle-run-quoted-names.d.ts +6 -0
  110. package/dist/detectors/particle-run-quoted-names.d.ts.map +1 -0
  111. package/dist/detectors/particle-run-quoted-names.js +18 -0
  112. package/dist/detectors/particle-run-quoted-names.js.map +1 -0
  113. package/dist/detectors/phrase-match.d.ts +4 -1
  114. package/dist/detectors/phrase-match.d.ts.map +1 -1
  115. package/dist/detectors/phrase-match.js +12 -5
  116. package/dist/detectors/phrase-match.js.map +1 -1
  117. package/dist/detectors/redundant-pair.d.ts +5 -0
  118. package/dist/detectors/redundant-pair.d.ts.map +1 -0
  119. package/dist/detectors/redundant-pair.js +18 -0
  120. package/dist/detectors/redundant-pair.js.map +1 -0
  121. package/dist/detectors/register-separate-part.d.ts +9 -1
  122. package/dist/detectors/register-separate-part.d.ts.map +1 -1
  123. package/dist/detectors/register-separate-part.js +23 -0
  124. package/dist/detectors/register-separate-part.js.map +1 -1
  125. package/dist/detectors/register-voice.d.ts +4 -3
  126. package/dist/detectors/register-voice.d.ts.map +1 -1
  127. package/dist/detectors/register-voice.js +11 -4
  128. package/dist/detectors/register-voice.js.map +1 -1
  129. package/dist/detectors/register.d.ts.map +1 -1
  130. package/dist/detectors/register.js +9 -6
  131. package/dist/detectors/register.js.map +1 -1
  132. package/dist/detectors/registry/redundant-pair.d.ts +3 -0
  133. package/dist/detectors/registry/redundant-pair.d.ts.map +1 -0
  134. package/dist/detectors/registry/redundant-pair.js +3 -0
  135. package/dist/detectors/registry/redundant-pair.js.map +1 -0
  136. package/dist/detectors/request-owner.d.ts +1 -0
  137. package/dist/detectors/request-owner.d.ts.map +1 -1
  138. package/dist/detectors/request-owner.js +6 -3
  139. package/dist/detectors/request-owner.js.map +1 -1
  140. package/dist/detectors/sentence-ending.d.ts +1 -0
  141. package/dist/detectors/sentence-ending.d.ts.map +1 -1
  142. package/dist/detectors/sentence-ending.js +7 -3
  143. package/dist/detectors/sentence-ending.js.map +1 -1
  144. package/dist/detectors/signals.d.ts.map +1 -1
  145. package/dist/detectors/signals.js +5 -2
  146. package/dist/detectors/signals.js.map +1 -1
  147. package/dist/detectors/stacked-hedge.d.ts +4 -2
  148. package/dist/detectors/stacked-hedge.d.ts.map +1 -1
  149. package/dist/detectors/stacked-hedge.js +16 -3
  150. package/dist/detectors/stacked-hedge.js.map +1 -1
  151. package/dist/detectors/structure-tree.d.ts.map +1 -1
  152. package/dist/detectors/structure-tree.js +1 -0
  153. package/dist/detectors/structure-tree.js.map +1 -1
  154. package/dist/detectors/structure.js +3 -3
  155. package/dist/detectors/structure.js.map +1 -1
  156. package/dist/detectors/superlative-context.d.ts +7 -0
  157. package/dist/detectors/superlative-context.d.ts.map +1 -1
  158. package/dist/detectors/superlative-context.js +9 -0
  159. package/dist/detectors/superlative-context.js.map +1 -1
  160. package/dist/detectors/token-shape.d.ts.map +1 -1
  161. package/dist/detectors/token-shape.js +20 -6
  162. package/dist/detectors/token-shape.js.map +1 -1
  163. package/dist/detectors/unbalanced-bracket.d.ts.map +1 -1
  164. package/dist/detectors/unbalanced-bracket.js +2 -1
  165. package/dist/detectors/unbalanced-bracket.js.map +1 -1
  166. package/dist/detectors/unknown-word-context.d.ts +5 -0
  167. package/dist/detectors/unknown-word-context.d.ts.map +1 -1
  168. package/dist/detectors/unknown-word-context.js +8 -0
  169. package/dist/detectors/unknown-word-context.js.map +1 -1
  170. package/dist/detectors/unknown-word.d.ts.map +1 -1
  171. package/dist/detectors/unknown-word.js +3 -3
  172. package/dist/detectors/unknown-word.js.map +1 -1
  173. package/dist/detectors/weasel-word.d.ts.map +1 -1
  174. package/dist/detectors/weasel-word.js +23 -4
  175. package/dist/detectors/weasel-word.js.map +1 -1
  176. package/dist/facts/era-year.d.ts +2 -0
  177. package/dist/facts/era-year.d.ts.map +1 -0
  178. package/dist/facts/era-year.js +7 -0
  179. package/dist/facts/era-year.js.map +1 -0
  180. package/dist/facts/fact-scope.d.ts +1 -1
  181. package/dist/facts/fact-scope.d.ts.map +1 -1
  182. package/dist/facts/fact-scope.js +18 -8
  183. package/dist/facts/fact-scope.js.map +1 -1
  184. package/dist/facts/table-facts.d.ts.map +1 -1
  185. package/dist/facts/table-facts.js +18 -2
  186. package/dist/facts/table-facts.js.map +1 -1
  187. package/dist/own-title-quote.d.ts +7 -0
  188. package/dist/own-title-quote.d.ts.map +1 -0
  189. package/dist/own-title-quote.js +19 -0
  190. package/dist/own-title-quote.js.map +1 -0
  191. package/dist/paragraph-length.d.ts +4 -0
  192. package/dist/paragraph-length.d.ts.map +1 -1
  193. package/dist/paragraph-length.js +6 -0
  194. package/dist/paragraph-length.js.map +1 -1
  195. package/dist/plugin.d.ts +2 -0
  196. package/dist/plugin.d.ts.map +1 -1
  197. package/dist/rule-of-three.d.ts +7 -0
  198. package/dist/rule-of-three.d.ts.map +1 -1
  199. package/dist/rule-of-three.js +22 -1
  200. package/dist/rule-of-three.js.map +1 -1
  201. package/dist/structure/build.d.ts.map +1 -1
  202. package/dist/structure/build.js +2 -1
  203. package/dist/structure/build.js.map +1 -1
  204. package/dist/structure/definition-use.d.ts.map +1 -1
  205. package/dist/structure/definition-use.js +3 -1
  206. package/dist/structure/definition-use.js.map +1 -1
  207. package/dist/structure/negated-act.d.ts +1 -0
  208. package/dist/structure/negated-act.d.ts.map +1 -1
  209. package/dist/structure/negated-act.js +1 -1
  210. package/dist/structure/negated-act.js.map +1 -1
  211. package/dist/structure/own-name.d.ts +4 -0
  212. package/dist/structure/own-name.d.ts.map +1 -0
  213. package/dist/structure/own-name.js +20 -0
  214. package/dist/structure/own-name.js.map +1 -0
  215. package/dist/structure/percent-sum-prose.d.ts.map +1 -1
  216. package/dist/structure/percent-sum-prose.js +9 -1
  217. package/dist/structure/percent-sum-prose.js.map +1 -1
  218. package/dist/structure/percent-sum.d.ts +2 -0
  219. package/dist/structure/percent-sum.d.ts.map +1 -1
  220. package/dist/structure/percent-sum.js.map +1 -1
  221. package/dist/structure/reference-text.d.ts.map +1 -1
  222. package/dist/structure/reference-text.js +3 -1
  223. package/dist/structure/reference-text.js.map +1 -1
  224. package/dist/structure-shape/features.d.ts.map +1 -1
  225. package/dist/structure-shape/features.js +15 -2
  226. package/dist/structure-shape/features.js.map +1 -1
  227. package/dist/te-form-helper.d.ts +22 -0
  228. package/dist/te-form-helper.d.ts.map +1 -0
  229. package/dist/te-form-helper.js +35 -0
  230. package/dist/te-form-helper.js.map +1 -0
  231. package/dist/word-use.d.ts +7 -0
  232. package/dist/word-use.d.ts.map +1 -1
  233. package/dist/word-use.js +20 -1
  234. package/dist/word-use.js.map +1 -1
  235. package/package.json +3 -3
  236. package/rules/absolute-exception.yaml +3 -3
  237. package/rules/adverb-overuse.yaml +2 -2
  238. package/rules/all-caps-shouting.yaml +2 -2
  239. package/rules/bold-label-list.yaml +9 -2
  240. package/rules/bracket-nesting.yaml +7 -2
  241. package/rules/bracket-width-consistency.yaml +2 -2
  242. package/rules/doubled-word.yaml +2 -2
  243. package/rules/duration-mismatch.yaml +2 -2
  244. package/rules/excessive-hedging.yaml +2 -1
  245. package/rules/fact-conflict.yaml +2 -2
  246. package/rules/katakana-density.yaml +3 -3
  247. package/rules/lookalike-character.yaml +2 -2
  248. package/rules/ngram-repetition.yaml +2 -2
  249. package/rules/no-doubled-joshi.yaml +2 -2
  250. package/rules/no-mixed-desumasu.yaml +3 -2
  251. package/rules/number-style-consistency.yaml +2 -2
  252. package/rules/number-without-unit.yaml +2 -2
  253. package/rules/obligation-without-deadline.yaml +2 -2
  254. package/rules/orthographic-variant.yaml +2 -2
  255. package/rules/padded-intro.yaml +1 -1
  256. package/rules/redundant-expression.yaml +1 -1
  257. package/rules/repeated-sentence-ending.yaml +2 -2
  258. package/rules/request-without-deadline.yaml +2 -2
  259. package/rules/requirement-smell.yaml +2 -2
  260. package/rules/rule-of-three.yaml +2 -2
  261. package/rules/title-length.yaml +7 -2
  262. package/rules/undefined-acronym.yaml +2 -2
  263. package/rules/unknown-word.yaml +2 -2
  264. package/rules/unused-definition.yaml +4 -2
  265. package/src/bound-word-particles.ts +23 -0
  266. package/src/derived/stays.ts +4 -1
  267. package/src/detectors/absolute-exception.ts +11 -5
  268. package/src/detectors/agreement-slip.ts +35 -10
  269. package/src/detectors/bold-label.ts +31 -4
  270. package/src/detectors/bold-quoted.ts +21 -0
  271. package/src/detectors/caps-caption.ts +10 -0
  272. package/src/detectors/clause-shape.ts +14 -12
  273. package/src/detectors/count-per-section.ts +9 -4
  274. package/src/detectors/defined-term-form.ts +2 -1
  275. package/src/detectors/document-shape.ts +17 -6
  276. package/src/detectors/doubled-word.ts +9 -1
  277. package/src/detectors/emoticon.ts +21 -0
  278. package/src/detectors/en-shape.ts +25 -2
  279. package/src/detectors/ending-refrain.ts +66 -0
  280. package/src/detectors/fact-consistency.ts +4 -1
  281. package/src/detectors/gram-predicate.ts +14 -3
  282. package/src/detectors/katakana-density.ts +17 -2
  283. package/src/detectors/lexicon.ts +3 -1
  284. package/src/detectors/lookalike-character.ts +40 -10
  285. package/src/detectors/mark-shape.ts +59 -19
  286. package/src/detectors/mentioned-phrase.ts +13 -1
  287. package/src/detectors/number-style.ts +43 -3
  288. package/src/detectors/number-unit.ts +29 -8
  289. package/src/detectors/obligation-without-deadline.ts +69 -5
  290. package/src/detectors/open-end-names.ts +21 -2
  291. package/src/detectors/orthographic-variant.ts +20 -15
  292. package/src/detectors/paragraph-pointer.ts +28 -0
  293. package/src/detectors/particle-run-long-forms.ts +34 -0
  294. package/src/detectors/particle-run-quoted-names.ts +27 -0
  295. package/src/detectors/phrase-match.ts +13 -5
  296. package/src/detectors/redundant-pair.ts +25 -0
  297. package/src/detectors/register-separate-part.ts +32 -1
  298. package/src/detectors/register-voice.ts +17 -4
  299. package/src/detectors/register.ts +9 -6
  300. package/src/detectors/registry/redundant-pair.ts +4 -0
  301. package/src/detectors/request-owner.ts +6 -3
  302. package/src/detectors/sentence-ending.ts +10 -4
  303. package/src/detectors/signals.ts +5 -2
  304. package/src/detectors/stacked-hedge.ts +24 -7
  305. package/src/detectors/structure-tree.ts +1 -0
  306. package/src/detectors/structure.ts +3 -3
  307. package/src/detectors/superlative-context.ts +12 -0
  308. package/src/detectors/token-shape.ts +24 -8
  309. package/src/detectors/unbalanced-bracket.ts +2 -1
  310. package/src/detectors/unknown-word-context.ts +9 -0
  311. package/src/detectors/unknown-word.ts +4 -2
  312. package/src/detectors/weasel-word.ts +31 -5
  313. package/src/facts/era-year.ts +7 -0
  314. package/src/facts/fact-scope.ts +20 -6
  315. package/src/facts/table-facts.ts +31 -3
  316. package/src/own-title-quote.ts +28 -0
  317. package/src/paragraph-length.ts +10 -0
  318. package/src/plugin.ts +2 -0
  319. package/src/rule-of-three.ts +27 -1
  320. package/src/structure/build.ts +2 -1
  321. package/src/structure/definition-use.ts +4 -1
  322. package/src/structure/negated-act.ts +1 -1
  323. package/src/structure/own-name.ts +28 -0
  324. package/src/structure/percent-sum-prose.ts +12 -1
  325. package/src/structure/percent-sum.ts +2 -0
  326. package/src/structure/reference-text.ts +5 -1
  327. package/src/structure-shape/features.ts +18 -2
  328. package/src/te-form-helper.ts +52 -0
  329. package/src/word-use.ts +23 -1
  330. package/src/honorific-group.ts +0 -22
@@ -4,8 +4,9 @@ import { isConventionalPhrase } from "./caps-phrase.ts";
4
4
  import { minorityReport } from "../spacing-minority.ts";
5
5
  import { externalLinkTitleSpans } from "../link-title.ts";
6
6
  import { formulaBracketSpans } from "../formula-brackets.ts";
7
+ import { ownTitleQuoteSpans } from "../own-title-quote.ts";
7
8
  import { isWithinAny, quotedSpans } from "../quoted-span.ts";
8
- import { bracketPlaceholderSpans, capitalLineSpans, captionsOf, isCaptionAt, isWithinSorted } from "./caps-caption.ts";
9
+ import { bracketPlaceholderSpans, capitalLineSpans, captionsOf, isCaptionAt, isWholeQuotation, isWithinSorted } from "./caps-caption.ts";
9
10
  import { lineStarts } from "../position.ts";
10
11
  import { isTypewritten } from "./typewritten.ts";
11
12
  import { divisionLabelPattern, isDivisionSeparator } from "./division-label-separator.ts";
@@ -93,32 +94,49 @@ const minorityFindings = <T extends Sided>(items: readonly T[], limit: number, v
93
94
  const ownSentences = (doc: ProseDocument): readonly Sentence[] => doc.sentences.filter((sentence) => sentence.embeddedLanguage === undefined);
94
95
 
95
96
  /**
96
- * A bracketed item number opening a line ((1)開催趣旨, (ア), (iv), a list bullet before it), both brackets of one width.
97
- * It numbers the line, a style of its own: the brackets of the prose around it may be written the other width. A
98
- * bracketed word at a line's head ((背景), (注)) is not a number, and an item number the prose refers to (次の(1)及び(2))
99
- * is written in the prose; both stay with the prose's brackets.
97
+ * A bracketed item number opening a line ((1)開催趣旨, (ア), (iv), a list bullet before it), both brackets of one width,
98
+ * or a tag in Latin letters opening a line ([Web]登録完了のお知らせ, a subject line's prefix). It labels the line, a style of
99
+ * its own: the brackets of the prose around it may be written the other width. A bracketed word in Japanese at a line's head
100
+ * ((背景), (注)) is not a label of that kind, and an item number the prose refers to (次の(1)及び(2)) is written in the prose;
101
+ * both stay with the prose's brackets.
100
102
  */
101
103
  const LINE_HEAD = /^\s*(?:[-*+] +)?/u;
102
- const BRACKETED = /^([(([[])([^))\]]]{1,4})([))\]]])/u;
104
+ const BRACKETED = /^([(([[])([^))\]]]{1,12})([))\]]])/u;
103
105
  const NUMBERING = /^(?:[0-90-9]{1,3}|[一二三四五六七八九十]{1,3}|[A-Za-zA-Za-zァ-ヶぁ-んヲ-ン])$/u;
104
106
  /** Roman numerals i to x, either case. */
105
107
  const ROMAN = /^(?:i{2,3}|iv|vi{1,3}|ix|I{2,3}|IV|VI{1,3}|IX)$/u;
108
+ /** A word in Latin letters with a capital, digits, dots or hyphens after its first letter (Web, e-Gov); not a numeral (iiii). */
109
+ const LATIN_TAG = /^(?=.*[A-Z])[A-Za-z][A-Za-z0-9.-]+$/u;
106
110
  const CLOSER_OF: Readonly<Record<string, string>> = { "(": ")", "(": ")", "[": "]", "[": "]" };
107
111
 
108
- const isItemNumber = (text: string): boolean => NUMBERING.test(text) || ROMAN.test(text);
112
+ const isLineLabel = (text: string): boolean => NUMBERING.test(text) || ROMAN.test(text) || LATIN_TAG.test(text);
109
113
 
110
- /** The offsets in a line of its item number's opening and closing bracket, or none. */
114
+ /** The offsets in a line of its label's opening and closing bracket, or none. */
111
115
  const enumeratorIn = (line: string): readonly number[] => {
112
116
  const head = LINE_HEAD.exec(line)?.[0].length ?? 0;
113
117
  const found = BRACKETED.exec(line.slice(head));
114
- if (found === null || CLOSER_OF[found[1] ?? ""] !== found[3] || !isItemNumber(found[2] ?? "")) return [];
118
+ if (found === null || CLOSER_OF[found[1] ?? ""] !== found[3] || !isLineLabel(found[2] ?? "")) return [];
115
119
  return [head, head + found[0].length - 1];
116
120
  };
117
121
 
118
- /** The offsets in `source` of each line's item number's opening and closing bracket. */
122
+ /**
123
+ * An item's address in the prose: a section's number and its item's bracketed number (上記4(2)で), as the lines number them.
124
+ * Not after a digit, a comma or a point, so a figure and its bracketed figure in a table (1,054(47)) is not one.
125
+ */
126
+ const ITEM_ADDRESS = /(?<![0-90-9,,..])[0-90-9]{1,2}(?:\([0-90-9]{1,2}\)|([0-90-9]{1,2}))(?=[\p{Script=Han}\p{Script=Hiragana}])/gu;
127
+
128
+ const addressBrackets = (match: RegExpMatchArray & { index: number }): number[] => {
129
+ const end = match.index + match[0].length - 1;
130
+ return [match.index + match[0].search(/[((]/u), end];
131
+ };
132
+
133
+ /** The offsets in `source` of each line's label's opening and closing bracket, and of the brackets of an item's address. */
119
134
  export const enumeratorBracketOffsets = (source: string): ReadonlySet<number> => {
120
135
  const starts = lineStarts(source);
121
- return new Set(source.split("\n").flatMap((line, index) => enumeratorIn(line).map((at) => (starts[index] ?? 0) + at)));
136
+ return new Set([
137
+ ...source.split("\n").flatMap((line, index) => enumeratorIn(line).map((at) => (starts[index] ?? 0) + at)),
138
+ ...[...source.matchAll(ITEM_ADDRESS)].flatMap(addressBrackets),
139
+ ]);
122
140
  };
123
141
 
124
142
  /** Appended to a mark's kind for an item number's bracket. A lexicon's group, a word from YAML, never holds a NUL. */
@@ -174,9 +192,10 @@ const withNoteKind = (mark: Mark, notes: ReadonlySet<number>): Mark =>
174
192
  export const markConsistency: Detector = (doc, options): Finding[] => {
175
193
  const script = SCRIPT[doc.language];
176
194
  if (script === undefined) return [];
177
- // A link that quotes an outside page's title keeps that page's marks ((コンテキスト内) in a WCAG title).
178
- const titles = externalLinkTitleSpans(doc.source, doc.links);
179
195
  const forms = formsOf(options.lexicon ?? []);
196
+ // A link that quotes an outside page's title keeps that page's marks ((コンテキスト内) in a WCAG title), and a quotation
197
+ // of the document's own heading keeps the heading's.
198
+ const titles = [...externalLinkTitleSpans(doc.source, doc.links), ...ownTitleQuoteSpans(doc.source, doc.markup?.headings ?? [], new Set(forms.keys()))];
180
199
  const enumerators = enumeratorBracketOffsets(doc.source);
181
200
  const doubled = doubledParenOffsets(doc.source);
182
201
  const notes = noteMarkerOffsets(doc.source);
@@ -241,6 +260,20 @@ const reportFrom = (hits: readonly Hit[], limit: number): Finding[] => (hits.len
241
260
  /** A spaced hyphen or a double hyphen between words, standing for a dash ("late - very late", "late--very late"). */
242
261
  const HYPHEN_DASH = /(?<=[\p{L},;)]) -{1,2} (?=[\p{L}(])|(?<=\p{L})--(?=\p{L})/gu;
243
262
 
263
+ /** A spaced hyphen whose side is masked out of the sentence's text: a code span may stand there ("`float` - everything"). */
264
+ const MASKED_SIDE_HYPHEN = /(?<=\s) -{1,2} (?=[\p{L}(])|(?<=[\p{L},;)]) -{1,2} (?=\s)/gu;
265
+ const CODE_MARK = "`";
266
+
267
+ /**
268
+ * A spaced hyphen between a code span and a word, either way round ("`float` - everything", "two properties - `x`"). Code
269
+ * is masked out of the text, so the code side reads as spaces; the source shows the code mark right beside the hyphen.
270
+ * Code on both sides ("`query` - `form`") is a mapping, not a dash.
271
+ */
272
+ const besideCode = (source: string, hit: Hit): boolean => {
273
+ const end = hit.offset + hit.matched.length + 2;
274
+ return (source[hit.offset - 1] === CODE_MARK) !== (source[end] === CODE_MARK);
275
+ };
276
+
244
277
  /** A dash set as a character (an em dash, an en dash). */
245
278
  const TRUE_DASH = /[—–]/u;
246
279
  const DOUBLE_HYPHEN = "--";
@@ -257,10 +290,11 @@ export const hyphenDash: Detector = (doc, options): Finding[] => {
257
290
  const sentences = ownSentences(doc);
258
291
  const setsDashes = sentences.some((sentence) => TRUE_DASH.test(sentence.text));
259
292
  const divisionLabel = divisionLabelPattern((doc.lexicons["numbered-division"] ?? []).map((entry) => entry.pattern));
293
+ const codeHits = hitsOf(sentences, MASKED_SIDE_HYPHEN).filter((hit) => besideCode(doc.source, hit));
260
294
  return reportFrom(
261
- hitsOf(sentences, HYPHEN_DASH).filter(
262
- (hit) => !isTypedDash(hit, setsDashes) && !isDivisionSeparator(doc.source, hit.offset, divisionLabel) && !isInCopiedText(doc.source, hit.offset),
263
- ),
295
+ [...hitsOf(sentences, HYPHEN_DASH), ...codeHits]
296
+ .toSorted((left, right) => left.offset - right.offset)
297
+ .filter((hit) => !isTypedDash(hit, setsDashes) && !isDivisionSeparator(doc.source, hit.offset, divisionLabel) && !isInCopiedText(doc.source, hit.offset)),
264
298
  options.limit,
265
299
  );
266
300
  };
@@ -313,8 +347,8 @@ export const isShouting = (run: string, known: ReadonlySet<string>, conventional
313
347
 
314
348
  /**
315
349
  * Runs of three or more all-capital words that are ordinary words, not acronyms ("DO NOT DELETE THIS"), and not a
316
- * caption, a mention of one, a paragraph of capital lines that ends no sentence (a letterhead, a heading), a roster name, or a
317
- * placeholder in square brackets.
350
+ * caption, a mention of one, a paragraph of capital lines that ends no sentence (a letterhead, a heading), a roster name, a
351
+ * placeholder in square brackets, or a whole quotation.
318
352
  */
319
353
  export const capsShouting: Detector = (doc, options): Finding[] => {
320
354
  const known = lowerCaseWords(doc.prose ?? doc.source);
@@ -324,7 +358,13 @@ export const capsShouting: Detector = (doc, options): Finding[] => {
324
358
  const placeholders = bracketPlaceholderSpans(doc.source);
325
359
  const isCaptionOrLetterhead = (hit: Hit): boolean => {
326
360
  const span = { start: hit.offset, end: hit.offset + hit.matched.length };
327
- return captions.has(hit.matched) || isCaptionAt(doc.source, span.start, span.end) || isWithinSorted(capitalLines, span) || isWithinAny(placeholders, span);
361
+ return (
362
+ captions.has(hit.matched) ||
363
+ isCaptionAt(doc.source, span.start, span.end) ||
364
+ isWithinSorted(capitalLines, span) ||
365
+ isWithinAny(placeholders, span) ||
366
+ isWholeQuotation(doc.source, span.start, span.end)
367
+ );
328
368
  };
329
369
  const hits = hitsOf(ownSentences(doc), CAPS_RUN).filter((hit) => isShouting(hit.matched, known, conventional) && !isCaptionOrLetterhead(hit));
330
370
  return reportFrom(hits, options.limit);
@@ -1,7 +1,7 @@
1
1
  // A phrase that is mentioned rather than used: named as a term (when saying "raise the bar", the phrase "low-hanging
2
2
  // fruit", 「徹底解説」という言い方). The writer is talking about the words, not leaning on them. The cue words come from the
3
3
  // language's mention-cue word list: group before stands right before the phrase, group after right after it. Pure.
4
- import type { LexiconEntry, Sentence, Token } from "../plugin.ts";
4
+ import type { LexiconEntry, Sentence, Span, Token } from "../plugin.ts";
5
5
  import { entryEndsAt, entryRanges, type TokenRange } from "./lexicon-match.ts";
6
6
 
7
7
  const BEFORE = "before";
@@ -36,3 +36,15 @@ export const onlyMentioned = (sentence: Sentence, entry: LexiconEntry, cues: Men
36
36
  const ranges = entryRanges(sentence, entry);
37
37
  return tokens !== undefined && ranges.length > 0 && ranges.every((range) => isMention(tokens, range, cues));
38
38
  };
39
+
40
+ /** Whether every use of the entry in the sentence lies in a linked page's title: the other page's words, which the writer cites. */
41
+ export const onlyInTitles = (sentence: Sentence, entry: LexiconEntry, titles: readonly Span[]): boolean => {
42
+ const tokens = sentence.tokens ?? [];
43
+ const ranges = entryRanges(sentence, entry);
44
+ const inTitle = (start: number, end: number): boolean => titles.some((title) => start >= title.start && end <= title.end);
45
+ return (
46
+ titles.length > 0 &&
47
+ ranges.length > 0 &&
48
+ ranges.every((range) => inTitle(tokens[range.start]?.span.start ?? -1, tokens[range.end - 1]?.span.end ?? Number.POSITIVE_INFINITY))
49
+ );
50
+ };
@@ -4,7 +4,8 @@
4
4
  import { escapeRegExp } from "../orthography.ts";
5
5
  import { QUOTATION_MARKS, isWithinAny, quotedSpans } from "../quoted-span.ts";
6
6
  import { isCitation } from "./kutoten-consistency.ts";
7
- import type { Detector, Finding, ProseDocument, Sentence, Span, Token } from "../plugin.ts";
7
+ import { inDocumentOrder } from "../structure/issues.ts";
8
+ import type { Detector, Finding, ProseDocument, Sentence, Span, StructureNode, Token } from "../plugin.ts";
8
9
 
9
10
  export type NumberKind = "count" | "grouping" | "percent" | "count-small" | "count-large";
10
11
 
@@ -62,12 +63,25 @@ const isBeforeLongerWord = (numeral: string, written: string, offset: number, to
62
63
  return word !== undefined && word.surface.length > counter.length;
63
64
  };
64
65
 
66
+ /** The ordinal suffix (三枚目): a word the tokenizer joins to a count that is still a number of things. */
67
+ const ORDINAL_SUFFIX = "目";
68
+
69
+ /**
70
+ * A kanji numeral and counter that open a longer word (二枚貝, 二枚舌, 三人称): the tokenizer reads the whole as one noun, a name
71
+ * for a thing rather than a count of it, and digits could not be written there.
72
+ */
73
+ const isInsideWord = (written: string, offset: number, tokens: readonly Token[]): boolean => {
74
+ const word = tokens.find((token) => token.span.start === offset);
75
+ if (word === undefined || word.surface.length <= written.length || !word.surface.startsWith(written)) return false;
76
+ return word.surface.slice(written.length) !== ORDINAL_SUFFIX;
77
+ };
78
+
65
79
  const countMarks = (text: string, base: number, words: NumberWords, tokens: readonly Token[]): NumberMark[] => {
66
80
  const pattern = countPattern(words);
67
81
  if (pattern === undefined) return [];
68
82
  return [...text.matchAll(pattern)].flatMap((match): NumberMark[] => {
69
83
  const [written, digits, kanji] = match;
70
- if (kanji !== undefined && isIdiomNumeral(kanji)) return [];
84
+ if (kanji !== undefined && (isIdiomNumeral(kanji) || isInsideWord(written, base + match.index, tokens))) return [];
71
85
  if (isBeforeLongerWord(digits ?? kanji ?? "", written, base + match.index, tokens)) return [];
72
86
  return [{ kind: "count", style: digits === undefined ? "kanji" : "digits", written, offset: base + match.index }];
73
87
  });
@@ -253,12 +267,38 @@ const findingOf = (mark: NumberMark, usual: NumberMark, count: number, of: numbe
253
267
  variant: mark.kind,
254
268
  });
255
269
 
270
+ const isInArticle = (mark: NumberMark, articles: readonly Span[]): boolean =>
271
+ isWithinAny(articles, { start: mark.offset, end: mark.offset + mark.written.length });
272
+
273
+ /**
274
+ * The marks of the document's own text. A document that is not a statute and sets out articles where most of its numbers are
275
+ * outside them (a manual quoting the order its fees rest on) quotes the law there, and the law keeps its own numerals
276
+ * (二千四百円). A document whose numbers are mostly inside its articles (work rules) is written in articles itself.
277
+ */
278
+ export const ownMarks = (marks: readonly NumberMark[], articles: readonly Span[]): readonly NumberMark[] => {
279
+ const outside = marks.filter((mark) => !isInArticle(mark, articles));
280
+ return outside.length > marks.length - outside.length ? outside : marks;
281
+ };
282
+
283
+ /** A numbered heading of the document's own outline (2.1 Corpus) is read as an article too; a law's article names its unit (第5条, Article 5). */
284
+ const OUTLINE_NUMBER = /^[\d.]+$/u;
285
+
286
+ const isLawArticle = (node: StructureNode): boolean => node.kind === "article" && !OUTLINE_NUMBER.test(String(node.attrs["label"] ?? ""));
287
+
288
+ const lawArticleSpans = (doc: ProseDocument): Span[] =>
289
+ doc.structure === undefined ? [] : inDocumentOrder(doc.structure).flatMap((node) => (isLawArticle(node) ? [node.span] : []));
290
+
291
+ const isMixed = (marks: readonly NumberMark[]): boolean => new Set(marks.map((mark) => mark.style)).size > 1;
292
+
256
293
  /** For each kind of number, the marks written in the document's less common style. */
257
294
  export const numberStyleConsistency: Detector = (doc, options): Finding[] => {
258
295
  const words = wordsOf(doc);
259
- const marks = doc.sentences
296
+ const written = doc.sentences
260
297
  .filter((sentence) => sentence.embeddedLanguage === undefined && !isCitation(sentence, doc.source))
261
298
  .flatMap((sentence) => numberMarksIn(sentence, words, doc.language, doc.source));
299
+ // doc.structure builds the tree when first read: a document with one style in every kind has nothing to report either way.
300
+ if (!KINDS.some((kind) => isMixed(written.filter((mark) => mark.kind === kind)))) return [];
301
+ const marks = ownMarks(written, lawArticleSpans(doc));
262
302
  return KINDS.flatMap((kind) => {
263
303
  const ofKind = marks.filter((mark) => mark.kind === kind);
264
304
  const { odd, usual } = minorityStyles(ofKind, options.limit);
@@ -9,8 +9,15 @@ import { quoteAt } from "./structure-tree.ts";
9
9
  import { formsOf } from "./currency-notation.ts";
10
10
  import { scaledFiguresIn, scaleGaps, type ScaleWords } from "./scaled-figure-unit.ts";
11
11
 
12
- /** One value of a kind: where its number starts, as written, and its unit ("" when bare). */
13
- export type Measured = { readonly kind: string; readonly name: string; readonly offset: number; readonly written: string; readonly unit: string };
12
+ /** One value of a kind: where its number starts, as written, and its unit ("" when bare). row: the table row of a cell. */
13
+ export type Measured = {
14
+ readonly kind: string;
15
+ readonly name: string;
16
+ readonly offset: number;
17
+ readonly written: string;
18
+ readonly unit: string;
19
+ readonly row?: string;
20
+ };
14
21
 
15
22
  export type UnitGap = { readonly value: Measured; readonly unit: string };
16
23
 
@@ -50,10 +57,11 @@ export const unitOf = (text: string, units: ReadonlySet<string>): string | undef
50
57
  return currency === "" && UNIT_SHAPE.test(suffix) && isUnit(suffix, units) ? suffix : undefined;
51
58
  };
52
59
 
53
- const measured = (kind: string, name: string, text: string, offset: number, units: ReadonlySet<string>): Measured[] => {
60
+ const measured = (kind: string, name: string, text: string, offset: number, units: ReadonlySet<string>, row?: string): Measured[] => {
54
61
  const written = text.trim();
55
62
  const unit = unitOf(written, units);
56
- return unit === undefined ? [] : [{ kind, name, offset: offset + Math.max(0, text.indexOf(written)), written, unit }];
63
+ const placed = row === undefined ? {} : { row };
64
+ return unit === undefined ? [] : [{ kind, name, offset: offset + Math.max(0, text.indexOf(written)), written, unit, ...placed }];
57
65
  };
58
66
 
59
67
  type LabelLine = { readonly label: string; readonly value: string; readonly at: number };
@@ -83,9 +91,10 @@ const tableValues = (source: string, table: MarkdownNode, index: number, units:
83
91
  const [header, ...body] = table.children ?? [];
84
92
  return (header?.children ?? []).flatMap((headCell, column) => {
85
93
  const name = cellText(source, headCell)?.text.trim() ?? "";
86
- return body.flatMap((row) => {
94
+ return body.flatMap((row, rowIndex) => {
87
95
  const cell = cellText(source, row.children?.[column]);
88
- return cell === undefined || name === "" ? [] : measured(`table ${String(index)}: ${name}`, name, cell.text, cell.start, units);
96
+ const place = `table ${String(index)} row ${String(rowIndex)}`;
97
+ return cell === undefined || name === "" ? [] : measured(`table ${String(index)}: ${name}`, name, cell.text, cell.start, units, place);
89
98
  });
90
99
  });
91
100
  };
@@ -134,6 +143,17 @@ export const unitGaps = (values: readonly Measured[]): UnitGap[] => {
134
143
  return [...kinds.values()].flatMap(gapsOfKind).toSorted((left, right) => left.value.offset - right.value.offset);
135
144
  };
136
145
 
146
+ /**
147
+ * A bare cell whose row gives another column, one that carries a unit elsewhere, a bare number too: the row counts a
148
+ * thing of its own (| Website visits | 412,000 | 486,000 | +18% |), in a table whose rows are different measures.
149
+ */
150
+ export const isBareRow = (gap: UnitGap, values: readonly Measured[]): boolean => {
151
+ const { row, kind } = gap.value;
152
+ if (row === undefined) return false;
153
+ const measuredKinds = new Set(values.filter((value) => value.unit !== "").map((value) => value.kind));
154
+ return values.some((value) => value.row === row && value.kind !== kind && value.unit === "" && measuredKinds.has(value.kind));
155
+ };
156
+
137
157
  const unitsOf = (doc: ProseDocument): Set<string> =>
138
158
  new Set(UNIT_LEXICONS.flatMap((name) => (doc.lexicons[name] ?? []).flatMap((entry) => [entry.pattern, entry.pattern.toLowerCase()])));
139
159
 
@@ -184,8 +204,9 @@ const scaleFindings = (doc: ProseDocument): Finding[] => {
184
204
 
185
205
  const columnFindings = (doc: ProseDocument): Finding[] => {
186
206
  const count = pieceCountOf(doc);
187
- return unitGaps(measuredValues(doc.source, doc.prose ?? doc.source, unitsOf(doc)))
188
- .filter((gap) => !isPieceCount(gap, count))
207
+ const values = measuredValues(doc.source, doc.prose ?? doc.source, unitsOf(doc));
208
+ return unitGaps(values)
209
+ .filter((gap) => !isPieceCount(gap, count) && !isBareRow(gap, values))
189
210
  .map((gap) => ({
190
211
  rule: "number-without-unit",
191
212
  severity: "warning",
@@ -4,21 +4,31 @@
4
4
  // a vague limit (promptly) is vague-deadline's; one stating an amount (pays a fee of $9,000) sets a price, and its
5
5
  // timing is another clause's. The words come from the language package's word lists: timed-duty (the act),
6
6
  // duty-marker (shall, will), duty-ending (う, するものとする: what may follow a Japanese act at the sentence end),
7
- // stated-deadline (by the, までに) with concrete-deadline and vague-deadline, deadline-permission and currency-notation. Pure.
7
+ // stated-deadline (by the, までに) with concrete-deadline and vague-deadline, deadline-permission, currency-notation and paragraph-pointer (前項). Pure.
8
8
  import { quoteAt } from "./structure-tree.ts";
9
9
  import { actsTimedAt, type NamedDeadline, type Units } from "./deadline-unit.ts";
10
+ import { pointedParagraphs } from "./paragraph-pointer.ts";
10
11
  import { inDocumentOrder } from "../structure/issues.ts";
11
12
  import { escapeRegExp } from "../orthography.ts";
12
13
  import { grantsRight, statesConcrete, vagueIn } from "./vague-deadline.ts";
13
- import type { Detector, Finding, LexiconEntry, ProseDocument } from "../plugin.ts";
14
+ import type { Detector, Finding, LexiconEntry, ProseDocument, Span, StructureNode } from "../plugin.ts";
14
15
 
15
16
  export type UntimedDuty = { readonly offset: number; readonly act: string };
16
17
 
17
18
  /**
18
19
  * sameLine: the sentence goes on the line of the one before it (no line break between them). timedActs: the acts whose
19
- * dated deadline (支払期日 for 支払) its article, else its list or paragraph, names; a duty to do one of them is timed.
20
+ * dated deadline (支払期日 for 支払) its article, else its list or paragraph, names; a duty to do one of them is timed. place: its
21
+ * article (where it starts) and its paragraph's number in it.
20
22
  */
21
- type Text = { readonly start: number; readonly text: string; readonly sameLine?: boolean; readonly timedActs?: readonly string[] };
23
+ type Text = {
24
+ readonly start: number;
25
+ readonly text: string;
26
+ readonly sameLine?: boolean;
27
+ readonly timedActs?: readonly string[];
28
+ readonly place?: Place | undefined;
29
+ };
30
+
31
+ type Place = { readonly article: number; readonly paragraph: number };
22
32
 
23
33
  /** What the word lists give the decision. */
24
34
  export type DutyWords = {
@@ -36,6 +46,8 @@ export type DutyWords = {
36
46
  readonly deferrals: readonly string[];
37
47
  readonly permissions: readonly LexiconEntry[];
38
48
  readonly currencies: readonly LexiconEntry[];
49
+ /** Words that point at another paragraph of the article (前項, 本条1項). */
50
+ readonly paragraphPointers?: readonly LexiconEntry[];
39
51
  };
40
52
 
41
53
  const LATIN = /\p{Script=Latin}/u;
@@ -147,13 +159,41 @@ const lineEnds = (texts: readonly Text[]): number[] => {
147
159
  return ends;
148
160
  };
149
161
 
162
+ type Bound = { readonly place: Place; readonly act: string; readonly text: string };
163
+
164
+ /** The limited sentences of articles, with the act each binds. */
165
+ const limitedBounds = (texts: readonly Text[], words: DutyWords): Bound[] =>
166
+ texts.flatMap((text) => {
167
+ const act = text.place === undefined || !limited(text, words) ? undefined : actIn(text.text, words);
168
+ return act === undefined || text.place === undefined ? [] : [{ place: text.place, act: act.act.toLowerCase(), text: text.text }];
169
+ });
170
+
171
+ /**
172
+ * Whether another paragraph of the duty's article times the same act and one of the two points at the other: an article
173
+ * that says what is paid in its first paragraph and, in its third, pays 「本条1項に定める対価」 within ten days, or pays
174
+ * 「前項の対価」 by bank transfer after the paragraph that gives the time.
175
+ */
176
+ const timedInArticle = (text: Text, act: string, bounds: readonly Bound[], pointers: readonly LexiconEntry[]): boolean => {
177
+ const place = text.place;
178
+ if (place === undefined || pointers.length === 0) return false;
179
+ const pointed = pointedParagraphs(text.text, place.paragraph, pointers);
180
+ return bounds.some(
181
+ (bound) =>
182
+ bound.place.article === place.article &&
183
+ bound.place.paragraph !== place.paragraph &&
184
+ bound.act === act.toLowerCase() &&
185
+ (pointed.includes(bound.place.paragraph) || pointedParagraphs(bound.text, bound.place.paragraph, pointers).includes(place.paragraph)),
186
+ );
187
+ };
188
+
150
189
  /**
151
190
  * Each duty to act at a point in time whose sentence, and the rest of whose line, states no limit, holds no vague one, grants no right and states
152
- * no amount, when more sentences of the document state a limit than hold such a duty: these duties are then the
191
+ * no amount, and whose article times its act in a paragraph one of the two points at, when more sentences of the document state a limit than hold such a duty: these duties are then the
153
192
  * document's minority.
154
193
  */
155
194
  export const untimedDuties = (texts: readonly Text[], words: DutyWords): UntimedDuty[] => {
156
195
  const ends = lineEnds(texts);
196
+ const bounds = limitedBounds(texts, words);
157
197
  const found = texts.flatMap((text, index) => {
158
198
  const line = texts.slice(index, ends[index]);
159
199
  if (line.some((later) => limited(later, words) || words.deferrals.some((deferral) => phraseIn(later.text, deferral)))) return [];
@@ -161,6 +201,7 @@ export const untimedDuties = (texts: readonly Text[], words: DutyWords): Untimed
161
201
  const act = actIn(text.text, words);
162
202
  if (act === undefined || (LATIN.test(act.act) && !isWordStart(text.text, act.at))) return [];
163
203
  if (text.timedActs?.some((timed) => timed.toLowerCase() === act.act.toLowerCase()) === true) return [];
204
+ if (timedInArticle(text, act.act, bounds, words.paragraphPointers ?? [])) return [];
164
205
  return [{ offset: text.start + act.at, act: text.text.slice(act.at, act.at + act.act.length) }];
165
206
  });
166
207
  const limitedSentences = texts.filter((text) => statesLimit(text, words)).length;
@@ -185,14 +226,36 @@ const timedActsReader = (doc: ProseDocument): ((offset: number) => string[]) =>
185
226
  return (offset) => actsTimedAt(doc.source, units, offset, deadlines, phraseIn);
186
227
  };
187
228
 
229
+ const within = (span: Span, offset: number): boolean => offset >= span.start && offset < span.end;
230
+
231
+ /** The paragraph's number: its item's label among the article's own items (2, 2), or 1 for the article's first, unnumbered text. */
232
+ const paragraphOf = (article: StructureNode, offset: number): number | undefined => {
233
+ const item = article.children.find((child) => child.kind === "item" && within(child.span, offset));
234
+ if (item === undefined) return 1;
235
+ const label = Number(String(item.attrs["label"] ?? "").normalize("NFKC"));
236
+ return Number.isInteger(label) && label > 0 ? label : undefined;
237
+ };
238
+
239
+ /** Where a sentence stands: its innermost article and the paragraph in it. */
240
+ const placeReader = (doc: ProseDocument): ((offset: number) => Place | undefined) => {
241
+ const articles = doc.structure === undefined ? [] : inDocumentOrder(doc.structure).filter((node) => node.kind === "article");
242
+ return (offset) => {
243
+ const article = articles.filter((node) => within(node.span, offset)).at(-1);
244
+ const paragraph = article === undefined ? undefined : paragraphOf(article, offset);
245
+ return article === undefined || paragraph === undefined ? undefined : { article: article.span.start, paragraph };
246
+ };
247
+ };
248
+
188
249
  export const obligationWithoutDeadline: Detector = (doc): Finding[] => {
189
250
  const timedActs = timedActsReader(doc);
251
+ const placeAt = placeReader(doc);
190
252
  return untimedDuties(
191
253
  doc.sentences.map((sentence, index) => ({
192
254
  start: sentence.span.start,
193
255
  text: sentence.text,
194
256
  sameLine: index > 0 && !doc.source.slice(doc.sentences[index - 1]?.span.end ?? 0, sentence.span.start).includes("\n"),
195
257
  timedActs: timedActs(sentence.span.start),
258
+ place: placeAt(sentence.span.start),
196
259
  })),
197
260
  {
198
261
  acts: patternsOf(doc, "timed-duty"),
@@ -205,6 +268,7 @@ export const obligationWithoutDeadline: Detector = (doc): Finding[] => {
205
268
  deferrals: patternsOf(doc, "duty-terms-elsewhere"),
206
269
  permissions: doc.lexicons["deadline-permission"] ?? [],
207
270
  currencies: doc.lexicons["currency-notation"] ?? [],
271
+ paragraphPointers: doc.lexicons["paragraph-pointer"] ?? [],
208
272
  },
209
273
  ).map((duty) => ({
210
274
  rule: "obligation-without-deadline",
@@ -1,6 +1,7 @@
1
1
  import type { LexiconEntry, ProseDocument, Sentence, Token } from "../plugin.ts";
2
2
  import { escapeRegExp } from "../orthography.ts";
3
3
  import { entryRanges, type TokenRange } from "./lexicon-match.ts";
4
+ import { inDocumentOrder } from "../structure/issues.ts";
4
5
 
5
6
  // A word that leaves a list open (等, etc.) is also part of names a document gives itself: 「業務執行取締役等」,
6
7
  // 銀行等(…をいう。), the head of a definition item (四の二 親会社等 …をいう。), and longer nouns built on them
@@ -43,7 +44,13 @@ type QuotedName = { readonly name: string; readonly at: readonly number[] };
43
44
  * The names a document gives that contain an open-end word: the ones it quotes, the ones it defines in an aside right
44
45
  * after them (whole, as written there), and the heads of its definition items (which may run on into the definition).
45
46
  */
46
- export type OpenEndNames = { readonly quoted: readonly QuotedName[]; readonly defined: ReadonlySet<string>; readonly heads: readonly string[] };
47
+ export type OpenEndNames = {
48
+ readonly quoted: readonly QuotedName[];
49
+ readonly defined: ReadonlySet<string>;
50
+ readonly heads: readonly string[];
51
+ /** Every term the document defines (「秘密情報」): the word right after one (秘密情報等) widens a named thing, not an open list. */
52
+ readonly terms: ReadonlySet<string>;
53
+ };
47
54
 
48
55
  const attached = (left: Token | undefined, right: Token | undefined): boolean =>
49
56
  left !== undefined && right !== undefined && left.span.end === right.span.start;
@@ -129,12 +136,19 @@ const quotedNames = (source: string, words: readonly LexiconEntry[]): QuotedName
129
136
  return at.length === 0 ? [] : [{ name, at }];
130
137
  });
131
138
 
139
+ const definedTerms = (doc: ProseDocument): Set<string> =>
140
+ new Set(
141
+ doc.structure === undefined
142
+ ? []
143
+ : inDocumentOrder(doc.structure).flatMap((node) => (node.kind === "definition" && typeof node.attrs["term"] === "string" ? [node.attrs["term"]] : [])),
144
+ );
145
+
132
146
  /** The names a document gives that contain an open-end word. statements: the language's words of a definition (をいう, means). */
133
147
  export const openEndNames = (doc: ProseDocument, words: readonly LexiconEntry[], statements: readonly string[]): OpenEndNames => {
134
148
  const occurrences = doc.sentences.flatMap((sentence) => words.flatMap((word) => occurrencesIn(sentence, word)));
135
149
  const defined = occurrences.filter((occurrence) => definedInAside(doc.source, occurrence, statements)).map((occurrence) => nounOf(doc.source, occurrence));
136
150
  const heads = occurrences.filter((occurrence) => headsItem(doc.source, occurrence, statements)).map((occurrence) => nounOf(doc.source, occurrence));
137
- return { quoted: quotedNames(doc.source, words), defined: new Set(defined), heads: [...new Set(heads)] };
151
+ return { quoted: quotedNames(doc.source, words), defined: new Set(defined), heads: [...new Set(heads)], terms: definedTerms(doc) };
138
152
  };
139
153
 
140
154
  /** Whether a quoted name holds this occurrence: the text around it reads the whole name (当該責任追及等 holds 「責任追及等」). */
@@ -152,8 +166,13 @@ const partsHoldingWord = (source: string, occurrence: Occurrence): string[] => {
152
166
  return starts.flatMap((start) => ends.map((end) => source.slice(start, end)));
153
167
  };
154
168
 
169
+ /** Whether the word follows a defined term written whole (秘密情報等 where 「秘密情報」 is defined). */
170
+ const followsTerm = (source: string, occurrence: Occurrence, terms: ReadonlySet<string>): boolean =>
171
+ occurrence.tokens.slice(occurrence.first, occurrence.range.start).some((token) => terms.has(source.slice(token.span.start, occurrence.start)));
172
+
155
173
  const isNamed = (source: string, occurrence: Occurrence, names: OpenEndNames): boolean =>
156
174
  inQuotedName(source, occurrence, names.quoted) ||
175
+ followsTerm(source, occurrence, names.terms) ||
157
176
  partsHoldingWord(source, occurrence).some((part) => names.defined.has(part) || names.heads.some((head) => head.startsWith(part)));
158
177
 
159
178
  /** Whether the words around an occurrence bound its list; range: the tokens the word covers. */
@@ -27,24 +27,26 @@ import {
27
27
  } from "../word-use.ts";
28
28
  import { titleCaseNameRuns } from "../title-case-name.ts";
29
29
  import { withoutQuotedSpellings, type Quoted } from "../quoted-spelling.ts";
30
+ import { teFormOf, withTeFormFullVerbs, type TeForm } from "../te-form-helper.ts";
30
31
  import { citedSpans, isOpenIn, namesOf, patternsOf, type IsOpen, type Names } from "./orthographic-variant-open.ts";
31
32
 
32
33
  /**
33
34
  * A word found in the document: where it is, which sentence it is in, its key and spelling, how it is written when that differs, and
34
35
  * whether it is written onto the noun after it (取扱事業者).
35
36
  */
36
- type Placed = KeyedWord & {
37
- readonly sentence: Sentence;
38
- readonly offset: number;
39
- readonly shown?: string;
40
- readonly compoundHead?: boolean;
41
- /** Where a run of words ends (タイヤレバー). */
42
- readonly end?: number;
43
- /** Whether a Latin word stands in a name of capitalised words (the Interagency Group) or in a cited work. */
44
- readonly quoted?: Quoted | undefined;
45
- /** The name a word stands in, as written. */
46
- readonly name?: string | undefined;
47
- };
37
+ type Placed = KeyedWord &
38
+ TeForm & {
39
+ readonly sentence: Sentence;
40
+ readonly offset: number;
41
+ readonly shown?: string;
42
+ readonly compoundHead?: boolean;
43
+ /** Where a run of words ends (タイヤレバー). */
44
+ readonly end?: number;
45
+ /** Whether a Latin word stands in a name of capitalised words (the Interagency Group) or in a cited work. */
46
+ readonly quoted?: Quoted | undefined;
47
+ /** The name a word stands in, as written. */
48
+ readonly name?: string | undefined;
49
+ };
48
50
 
49
51
  /** Parts of speech that carry a word of their own. Particles and endings are written one way by the grammar. */
50
52
  const CONTENT = new Set(["NOUN", "VERB", "ADJ", "ADV", "PRON", "CCONJ", "DET"]);
@@ -155,11 +157,12 @@ const readingWords = (sentence: Sentence, isOpen: IsOpen, skips: Skips): Placed[
155
157
  if (inRun.has(at)) return [];
156
158
  const next = tokens[at + 1];
157
159
  const token = asNounWhereNominal(written, next, skips.phraseSuffixes, skips.nouns);
158
- const key = readingKeyOf({ token, previous: tokens[at - 1], before: tokens[at - 2], following: tokens.slice(at + 1, at + 3) }, skips);
160
+ const word = { token, previous: tokens[at - 1], before: tokens[at - 2], following: tokens.slice(at + 1, at + 3) };
161
+ const key = readingKeyOf(word, skips);
159
162
  const local = token.span.start - sentence.span.start;
160
163
  if (key === undefined || token.lemma === undefined || !isOpen(local, local + token.surface.length)) return [];
161
164
  const compoundHead = isCompoundHead(token, tokens, at, skips.phraseSuffixes);
162
- return [{ key, spelling: token.lemma, sentence, offset: token.span.start, compoundHead }];
165
+ return [{ key, spelling: token.lemma, sentence, offset: token.span.start, compoundHead, ...teFormOf(word, tokens, at) }];
163
166
  }),
164
167
  ];
165
168
  };
@@ -319,7 +322,9 @@ const cellPlace = (cell: TableCell, names: Names): Place => {
319
322
 
320
323
  /** The odd spellings among places that speak in one voice. */
321
324
  const findingsIn = (placed: readonly Place[], skips: Skips, { isWord, nameJoiners }: Reading, limit: number): Finding[] => {
322
- const reading = byKanji(placed.flatMap(({ sentence, isOpen }) => readingWords(withCutNounsJoined(sentence, skips.nouns), isOpen, skips)));
325
+ const reading = byKanji(
326
+ withTeFormFullVerbs(placed.flatMap(({ sentence, isOpen }) => readingWords(withCutNounsJoined(sentence, skips.nouns), isOpen, skips))),
327
+ );
323
328
  const katakana = placed.flatMap(({ sentence, isOpen }) => katakanaWords(sentence, isOpen));
324
329
  const runs = placed.flatMap(({ sentence, isOpen }) => katakanaRunWords(sentence, isOpen));
325
330
  const latin = withoutQuotedSpellings(
@@ -0,0 +1,28 @@
1
+ import { escapeRegExp } from "../orthography.ts";
2
+ import type { LexiconEntry } from "../plugin.ts";
3
+
4
+ // A sentence that points at another paragraph of its own article: the one before it (前項), or one by its number
5
+ // (本条1項). The words come from the language's paragraph-pointer word list: an entry in the group "previous" points at
6
+ // the paragraph before, and one with … in it is a frame whose … is the paragraph's number. Pure.
7
+
8
+ const FRAME = "…";
9
+ const PREVIOUS = "previous";
10
+ const NUMBER = "([0-90-9]+)";
11
+ const FULL_WIDTH_OFFSET = 0xfee0;
12
+
13
+ const halfWidth = (digits: string): string =>
14
+ [...digits].map((char) => (/[0-9]/u.test(char) ? String.fromCharCode(char.charCodeAt(0) - FULL_WIDTH_OFFSET) : char)).join("");
15
+
16
+ const numberedIn = (text: string, frame: string): number[] => {
17
+ const pattern = new RegExp(frame.split(FRAME).map(escapeRegExp).join(NUMBER), "gu");
18
+ return [...text.matchAll(pattern)].map((match) => Number(halfWidth(match[1] ?? "")));
19
+ };
20
+
21
+ /** The paragraphs of its article a sentence in paragraph own points at. */
22
+ export const pointedParagraphs = (text: string, own: number, pointers: readonly LexiconEntry[]): number[] =>
23
+ pointers
24
+ .filter((entry) => entry.pattern !== "")
25
+ .flatMap((entry) => {
26
+ if (entry.pattern.includes(FRAME)) return numberedIn(text, entry.pattern);
27
+ return entry.group === PREVIOUS && text.includes(entry.pattern) ? [own - 1] : [];
28
+ });