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
@@ -1,4 +1,4 @@
1
- import type { Detector, Finding, ProseDocument, Span } from "../plugin.ts";
1
+ import type { Detector, DetectorOptions, Finding, ProseDocument, Span } 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;
@@ -26,6 +26,12 @@ export const boldLabelOf = (item: string): string | undefined => {
26
26
  return label === undefined || isCodeOnly(label) ? undefined : label;
27
27
  };
28
28
 
29
+ /** `**Label:**` opening a paragraph, with text after it or standing alone over the list it introduces. */
30
+ const STANDING_LABEL = new RegExp(String.raw`^(\*\*|__)(?!\s)((?:(?!\1)[^\n]){1,${MAX_LABEL_CHARS}}?)(?:\1[ \t]*[::]|[::]\1)`, "u");
31
+
32
+ /** The bold label a paragraph or item opens with, whether text follows it on the line or not. */
33
+ export const standingBoldLabelOf = (text: string): string | undefined => STANDING_LABEL.exec(text.replace(ITEM_MARKER, "").replace(TASK_BOX, ""))?.[2]?.trim();
34
+
29
35
  /** Whether an item opens with a bold label of any kind, code-only ones included: bold that labels rather than emphasises. */
30
36
  export const opensWithBoldLabel = (item: string): boolean => BOLD_LABEL.test(item.replace(ITEM_MARKER, "").replace(TASK_BOX, ""));
31
37
 
@@ -55,11 +61,32 @@ const unquotedItems = (doc: ProseDocument, opens: (item: string) => string | und
55
61
  /** The list items, in document order, that open with a bold label and are not quoted. */
56
62
  export const boldLabelItems = (doc: ProseDocument): Span[] => unquotedItems(doc, boldLabelOf);
57
63
 
58
- /** 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
+ const minLeads = (options: DetectorOptions): number => {
68
+ const value = options.settings?.["min_leads"];
69
+ return typeof value === "number" ? value : DEFAULT_MIN_LEADS;
70
+ };
71
+
72
+ /** The count reported and the limit it reached: all the labelled items, or else the bold lead sentences alone, or undefined. */
73
+ const reached = (items: readonly Span[], leads: number, options: DetectorOptions): { count: number; limit: number } | undefined => {
74
+ if (items.length >= options.limit) return { count: items.length, limit: options.limit };
75
+ const least = minLeads(options);
76
+ return leads >= least ? { count: leads, limit: least } : undefined;
77
+ };
78
+
79
+ /**
80
+ * 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.
81
+ * Bold lead sentences (- **Check one result by hand.** …) report at fewer items than colon labels: human documents write a few
82
+ * colon labels for steps or fields (- **Gather input**: …), but rarely make a list of bold lead sentences.
83
+ */
59
84
  export const boldLabelList: Detector = (doc, options): Finding[] => {
60
85
  const items = unquotedItems(doc, labelOrLeadOf);
61
86
  const first = items[0];
62
- if (first === undefined || items.length < options.limit) return [];
87
+ const leads = items.filter((span) => boldLabelOf(doc.source.slice(span.start, span.end)) === undefined).length;
88
+ const found = reached(items, leads, options);
89
+ if (first === undefined || found === undefined) return [];
63
90
  const written = doc.source.slice(first.start, first.end);
64
91
  return [
65
92
  {
@@ -68,7 +95,7 @@ export const boldLabelList: Detector = (doc, options): Finding[] => {
68
95
  line: 0,
69
96
  column: 0,
70
97
  quote: (written.split("\n")[0] ?? "").trim(),
71
- values: { label: labelOrLeadOf(written) ?? "", count: items.length, limit: options.limit, offset: first.start },
98
+ values: { label: labelOrLeadOf(written) ?? "", count: found.count, limit: found.limit, offset: first.start },
72
99
  },
73
100
  ];
74
101
  };
@@ -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));
@@ -1,6 +1,8 @@
1
1
  import type { Detector, DetectorOptions, Finding, Lexicon, ProseDocument, Sentence, Token } from "../plugin.ts";
2
2
  import { isWithinAny, quotedIn } from "../quoted-span.ts";
3
3
  import { definitionWordsOf, isParallelDefinition } from "./parallel-definition.ts";
4
+ import { continuesThrough } from "./register.ts";
5
+ import { beatsOf } from "./ending-refrain.ts";
4
6
 
5
7
  // The shape of a clause read from its words: how it ends, a paired word left alone, an adverb that needs a
6
8
  // negation, a particle used where another one belongs. Every word comes from a lexicon; this file knows parts of speech.
@@ -52,10 +54,13 @@ export const endingOf = (sentence: Sentence): string | undefined => {
52
54
 
53
55
  type Ended = { readonly sentence: Sentence; readonly ending: string | undefined };
54
56
 
55
- /** Runs of consecutive sentences with the same ending. A sentence with no ending to compare closes a run. */
57
+ /**
58
+ * Runs of consecutive sentences with the same ending. A sentence with no ending to compare closes a run, and so does a
59
+ * question run together with the next one inside a single sentence (これはリストか?順序付きか?などです。): it is not the writer's ending.
60
+ */
56
61
  export const endingRuns = (sentences: readonly Sentence[]): Ended[][] =>
57
62
  sentences
58
- .map((sentence) => ({ sentence, ending: endingOf(sentence) }))
63
+ .map((sentence, index) => ({ sentence, ending: continuesThrough(sentences, index) ? undefined : endingOf(sentence) }))
59
64
  .reduce<Ended[][]>((runs, ended) => {
60
65
  const last = runs.at(-1) ?? [];
61
66
  const continues = ended.ending !== undefined && last[0]?.ending === ended.ending;
@@ -75,20 +80,17 @@ const runFinding = (run: readonly Ended[], limit: number): Finding => {
75
80
  };
76
81
  };
77
82
 
78
- /** More than limit sentences in a row within one paragraph that end with the same words, unless they define different terms in one frame. */
83
+ /**
84
+ * More than limit sentences in a row within one paragraph that end with the same words, unless they define different terms in one
85
+ * frame. A refrain (いい船でした。…いい船でした。) counts once.
86
+ */
79
87
  export const endingRun: Detector = (doc, options): Finding[] => {
80
88
  const words = definitionWordsOf(options.lexicon);
81
89
  return doc.paragraphs.flatMap((paragraph) =>
82
90
  endingRuns(paragraph.sentences)
83
- .filter(
84
- (run) =>
85
- run.length > options.limit &&
86
- !isParallelDefinition(
87
- run.map(({ sentence }) => sentence),
88
- words,
89
- ),
90
- )
91
- .map((run) => runFinding(run, options.limit)),
91
+ .map((run) => ({ run, sentences: run.map(({ sentence }) => sentence) }))
92
+ .filter(({ sentences }) => beatsOf(sentences, patternsOf(options.lexicon, "being")) > options.limit && !isParallelDefinition(sentences, words))
93
+ .map(({ run }) => runFinding(run, options.limit)),
92
94
  );
93
95
  };
94
96
 
@@ -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);
@@ -4,7 +4,7 @@ import { newContentMorphemes } from "./content-morphemes.ts";
4
4
  import { formValueTokens, isFormBlock } from "./form-line.ts";
5
5
  import { trigrams } from "./heading-overlap.ts";
6
6
  import { findingAt, writtenHeadings } from "./markup-finding.ts";
7
- import type { Detector, Finding, LengthUnit, MarkupHeading, Paragraph, ProseDocument, Section } from "../plugin.ts";
7
+ import type { Detector, Finding, LengthUnit, MarkupHeading, Paragraph, ProseDocument, Section, Token } from "../plugin.ts";
8
8
 
9
9
  /** A title shorter than this many character trigrams matches any lead by chance. */
10
10
  const MIN_TITLE_GRAMS = 4;
@@ -99,6 +99,17 @@ const QUESTION_END = /[??]["'”’))」』]*$/u;
99
99
 
100
100
  export const isQuestionHeading = (heading: string): boolean => QUESTION_END.test(heading.trim());
101
101
 
102
+ const TRAILING_MARKS: ReadonlySet<string> = new Set(["PUNCT", "SYM"]);
103
+
104
+ /**
105
+ * A heading that ends on a particle closing a question (…補正することはできますか。): it asks as one ending in ? does. The
106
+ * particles come from the language's question-particle word list; a language without one has none.
107
+ */
108
+ export const endsWithQuestionParticle = (tokens: readonly Token[], particles: ReadonlySet<string>): boolean => {
109
+ const last = tokens.findLast((token) => !TRAILING_MARKS.has(token.pos));
110
+ return last?.pos === "PART" && particles.has(last.surface);
111
+ };
112
+
102
113
  /** A series label in brackets at a heading's end, a number and a colon opening it ("(490: Employee travel)"): the manual's reference. */
103
114
  const SERIES_LABEL_END = /[((]\p{N}+[::][^()()]*[))]$/u;
104
115
  const QUOTED = /「[^「」]*」/gu;
@@ -140,18 +151,18 @@ const variantOf = (heading: MarkupHeading, title: MarkupHeading | undefined): st
140
151
  return heading === title ? "title" : undefined;
141
152
  };
142
153
 
143
- /** The heading's words without a number label at its head (Chapter 2, 1.), from the section the heading opens. */
144
- const unlabeledOf = (doc: ProseDocument, heading: MarkupHeading): string =>
145
- doc.sections.find((section) => section.span.start === heading.end)?.unlabeledHeading ?? heading.text;
154
+ const sectionOf = (doc: ProseDocument, heading: MarkupHeading): Section | undefined => doc.sections.find((section) => section.span.start === heading.end);
146
155
 
147
156
  /** Each title or heading longer than the limit. The first top-level heading is the title; every other is a heading. */
148
157
  export const titleLength: Detector = (doc, options): Finding[] => {
149
158
  const headings = writtenHeadings(doc);
150
159
  const title = headings.find((heading) => heading.depth === 1);
151
160
  const citedTitleActions = (doc.lexicons["cited-title-action"] ?? []).map((entry) => entry.pattern);
161
+ const questionParticles = new Set((doc.lexicons["question-particle"] ?? []).map((entry) => entry.pattern));
152
162
  return headings
153
- .map((heading) => ({ heading, words: unlabeledOf(doc, heading) }))
154
- .filter(({ words }) => !isParagraphHeading(words) && !isQuestionHeading(words))
163
+ .map((heading) => ({ heading, section: sectionOf(doc, heading) }))
164
+ .map(({ heading, section }) => ({ heading, words: section?.unlabeledHeading ?? heading.text, tokens: section?.headingTokens ?? [] }))
165
+ .filter(({ words, tokens }) => !isParagraphHeading(words) && !isQuestionHeading(words) && !endsWithQuestionParticle(tokens, questionParticles))
155
166
  .map(({ heading, words }) => ({ heading, count: headingLength(ownWordsOf(words, citedTitleActions), doc.lengthUnit) }))
156
167
  .filter(({ count }) => count > options.limit)
157
168
  .map(({ heading, count }) => ({
@@ -2,6 +2,7 @@ import type { Detector, Finding, Lexicon, Sentence, Span, Token } from "../plugi
2
2
  import { citedNamesOf, endsCitedName } from "./cited-name.ts";
3
3
  import { doubledAcrossAside } from "./doubled-across-aside.ts";
4
4
  import { furiganaSpans } from "../furigana.ts";
5
+ import { isFlattenedTable } from "./sentence-parts.ts";
5
6
 
6
7
  /**
7
8
  * 語を書き損じて二度書いた(the the / 資料をを)。消し忘れと、書き換えの途中で残った語(our the platform)の二つ。
@@ -170,6 +171,9 @@ const FIXED_PHRASE = "fixed-phrase";
170
171
  const inReading = (sentence: Sentence, readings: readonly Span[], doubled: Doubled): boolean =>
171
172
  readings.some((span) => sentence.span.start + span.start <= doubled.first.span.start && doubled.second.span.end <= sentence.span.start + span.end);
172
173
 
174
+ /** 変換で潰れた表の文では、名詞の重なりは隣り合った二つのセル(株主資本|資本金)。付属語の重なり(をを)は書き損じのまま。 */
175
+ const isCellBoundary = (tableLike: boolean, doubled: Doubled): boolean => tableLike && doubled.first.pos === "NOUN" && doubled.second.pos === "NOUN";
176
+
173
177
  export const doubledWord: Detector = (doc, options): Finding[] => {
174
178
  const spaced = doc.lengthUnit === "word";
175
179
  const allowed = options.lexicon ?? [];
@@ -179,8 +183,12 @@ export const doubledWord: Detector = (doc, options): Finding[] => {
179
183
  return doc.sentences.flatMap((sentence) => {
180
184
  // The readings are found once per sentence: once per doubled pair costs the pairs times the sentence's length.
181
185
  const readings = furiganaSpans(sentence.text);
186
+ const tableLike = isFlattenedTable(sentence.text);
182
187
  return [...doubledIn(doc.source, sentence.tokens ?? [], spaced, allowed, phrases), ...(spaced ? [] : doubledAcrossAside(doc.source, sentence.tokens ?? []))]
183
- .filter((doubled) => !endsCitedName(doubled.first, doubled.second, cited, kinds) && !inReading(sentence, readings, doubled))
188
+ .filter(
189
+ (doubled) =>
190
+ !endsCitedName(doubled.first, doubled.second, cited, kinds) && !inReading(sentence, readings, doubled) && !isCellBoundary(tableLike, doubled),
191
+ )
184
192
  .map((doubled) => findingOf(sentence, doubled, spaced));
185
193
  });
186
194
  };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A round bracket written as the mouth of an emoticon (":-)", ";)", ":(" ). It opens and closes nothing.
3
+ * text is the section, offset the bracket's position.
4
+ */
5
+
6
+ /**
7
+ * The eyes and an optional nose right before the mouth, at the start of a word or after an opening quote: ":", ";" or "=",
8
+ * then "-" or "'". Not after an opening bracket: "(:)" names the colon.
9
+ */
10
+ const FACE_BEFORE = /(?:^|[\s"'“‘])[:;=][-']?$/u;
11
+
12
+ /** After the mouth: the end, a space, a closing quote or punctuation. A letter or digit would make it part of a word. */
13
+ const FACE_AFTER = /^(?:$|[\s"'”’),.;:!?])/u;
14
+
15
+ const LOOK_AROUND = 4;
16
+
17
+ export const isEmoticonMouth = (text: string, offset: number): boolean => {
18
+ const mark = text[offset];
19
+ if (mark !== "(" && mark !== ")") return false;
20
+ return FACE_BEFORE.test(text.slice(Math.max(0, offset - LOOK_AROUND), offset)) && FACE_AFTER.test(text.slice(offset + 1, offset + 2));
21
+ };
@@ -15,13 +15,27 @@ const wordsIn = (doc: ProseDocument): number => doc.sentences.reduce((sum, sente
15
15
 
16
16
  const isLyAdverb = (token: Token): boolean => token.pos === "ADV" && token.surface.toLowerCase().endsWith("ly");
17
17
 
18
+ /** 頭だけ大文字の語。全部大文字(ONLY)は強調で、副詞のまま。 */
19
+ const CAPITALISED = /^\p{Lu}\p{Ll}/u;
20
+
21
+ const LETTER = /\p{L}/u;
22
+
23
+ /**
24
+ * 文の途中の頭だけ大文字の -ly の語は、解析器が語尾で副詞と当てた名前(July、Kelly)か、題の語(Frequently Asked Questions)。
25
+ * どちらも動詞に畳める副詞ではない。
26
+ */
27
+ const lyAdverbsOf = (tokens: readonly Token[]): Token[] => {
28
+ const first = tokens.findIndex((token) => LETTER.test(token.surface));
29
+ return tokens.filter((token, at) => isLyAdverb(token) && !(at > first && CAPITALISED.test(token.surface)));
30
+ };
31
+
18
32
  /**
19
33
  * -ly 副詞は、動詞が弱いことの目印になる。「walked quickly」より「hurried」。
20
34
  * 1 つずつは正しいので、件数ではなく密度で見る(bold-density と同じ)。
21
35
  */
22
36
  export const adverbDensity: Detector = (doc, options): Finding[] => {
23
37
  const words = wordsIn(doc);
24
- const hits = doc.sentences.flatMap((sentence) => (sentence.tokens ?? []).filter(isLyAdverb).map((token) => ({ sentence, token })));
38
+ const hits = doc.sentences.flatMap((sentence) => lyAdverbsOf(sentence.tokens ?? []).map((token) => ({ sentence, token })));
25
39
  const density = words === 0 ? 0 : Math.round((hits.length / words) * PER);
26
40
  const first = hits[0];
27
41
  if (words < MIN_WORDS || first === undefined || density <= options.limit) return [];
@@ -39,6 +53,15 @@ export const adverbDensity: Detector = (doc, options): Finding[] => {
39
53
 
40
54
  const BE = new Set(["be", "is", "are", "was", "were"]);
41
55
 
56
+ /**
57
+ * The words before ", but": "It's not fashionable these days, but my view is that …" is a concessive aside, and its
58
+ * that-clause belongs to the clause after but.
59
+ */
60
+ export const beforeConcession = (tokens: readonly Token[]): readonly Token[] => {
61
+ const at = tokens.findIndex((token, index) => token.surface === "," && tokens[index + 1]?.surface.toLowerCase() === "but");
62
+ return at === -1 ? tokens : tokens.slice(0, at);
63
+ };
64
+
42
65
  /**
43
66
  * There is / It is ... that は、主語を後ろへ押しやって誰が何をするのかを消す。
44
67
  * 「There is a need to review」は、誰が必要としているのかを言っていない。
@@ -51,7 +74,7 @@ const expletiveAt = (tokens: readonly Token[]): Token | undefined => {
51
74
  const next = tokens.find((token) => token.span.start >= head.span.end && token.pos !== "PUNCT");
52
75
  if (next === undefined || !BE.has(next.lemma ?? next.surface.toLowerCase())) return undefined;
53
76
  // "it is" は "it is raining" のような正当な用法があるので、that 節を伴うときだけ数える。
54
- if (lead === "it" && !tokens.some((token) => token.surface.toLowerCase() === "that")) return undefined;
77
+ if (lead === "it" && !beforeConcession(tokens).some((token) => token.surface.toLowerCase() === "that")) return undefined;
55
78
  return head;
56
79
  };
57
80
 
@@ -0,0 +1,66 @@
1
+ import type { Sentence, Token } from "../plugin.ts";
2
+
3
+ // A refrain: sentences in a row that end with the very same words, the word before the predicate included
4
+ // (いい船でした。…いい船でした。, …隊員がいます。…隊員がいます。). A speaker repeats a whole closing phrase on purpose;
5
+ // it is one figure, not the same ending said again and again (必要です。重要です。, Aが必要です。Bも必要です。). The predicate is a
6
+ // noun or an adjective with its copula, or a verb of being (verbs: いる, ある from the rule's word list); a definition said three
7
+ // times (…風を指します。…風を指します。) stays a run. Pure.
8
+
9
+ const TRAILING_POS: ReadonlySet<string> = new Set(["PUNCT", "SYM"]);
10
+ const TAIL_POS: ReadonlySet<string> = new Set(["AUX", "PART"]);
11
+ const CONTENT_POS: ReadonlySet<string> = new Set(["NOUN", "PROPN", "ADJ"]);
12
+ const VERB = "VERB";
13
+
14
+ const isSpace = (token: Token): boolean => token.surface.trim() === "";
15
+
16
+ /**
17
+ * A word that names a thing on its own: not a bound or dependent word (法 in 定額法, こと, の) and not a noun of an act (補助, 支援,
18
+ * 被害). A report repeats an act on purpose of record (…経費の補助を行った。…経費の補助を行った。), and that is the monotone run.
19
+ */
20
+ const isFree = (token: Token | undefined): token is Token =>
21
+ token !== undefined && token.features?.["Bound"] !== "Yes" && token.features?.["NounType"] !== "Dependent" && token.features?.["VerbForm"] !== "Vnoun";
22
+
23
+ /** A noun or adjective said with its copula (船でした), or a verb of being (隊員がいます). */
24
+ const isPredicate = (token: Token | undefined, verbs: ReadonlySet<string>): boolean =>
25
+ isFree(token) && (CONTENT_POS.has(token.pos) || (token.pos === VERB && verbs.has(token.lemma ?? token.surface)));
26
+
27
+ /** Where the content word before the predicate stands: right before it, or before one particle (隊員|が|います). */
28
+ const argumentAt = (tokens: readonly Token[], head: number): number => {
29
+ const at = tokens[head - 1]?.pos === "ADP" ? head - 2 : head - 1;
30
+ const token = tokens[at];
31
+ return isFree(token) && CONTENT_POS.has(token.pos) ? at : -1;
32
+ };
33
+
34
+ /**
35
+ * The closing words of a sentence from the content word before its predicate: いい船でした for …いい船でした。, 隊員がいます for
36
+ * …隊員がいます。. A predicate after a て-form or a bound word (採用しております, こともできます, ないのです) has no such word.
37
+ */
38
+ export const closingPhraseOf = (sentence: Sentence, verbs: ReadonlySet<string>): string | undefined => {
39
+ const tokens = (sentence.tokens ?? []).filter((token) => !isSpace(token));
40
+ const last = tokens.findLastIndex((token) => !TRAILING_POS.has(token.pos));
41
+ const head = tokens.slice(0, last + 1).findLastIndex((token) => !TAIL_POS.has(token.pos));
42
+ if (head <= 0 || head === last || !isPredicate(tokens[head], verbs)) return undefined;
43
+ const from = argumentAt(tokens, head);
44
+ if (from < 0) return undefined;
45
+ return tokens
46
+ .slice(from, last + 1)
47
+ .map((token) => token.surface)
48
+ .join("");
49
+ };
50
+
51
+ /** The fewest sentences that make a refrain. Two alike (…の被害もあります。…の被害もあります。) is the same ending said twice. */
52
+ const REFRAIN_MIN = 3;
53
+
54
+ type Block = { readonly phrase: string | undefined; readonly size: number };
55
+
56
+ const blocksOf = (phrases: readonly (string | undefined)[]): Block[] =>
57
+ phrases.reduce<Block[]>((blocks, phrase) => {
58
+ const last = blocks.at(-1);
59
+ return last !== undefined && phrase !== undefined && last.phrase === phrase
60
+ ? [...blocks.slice(0, -1), { phrase, size: last.size + 1 }]
61
+ : [...blocks, { phrase, size: 1 }];
62
+ }, []);
63
+
64
+ /** How many beats a run of sentences holds: a refrain (REFRAIN_MIN sentences or more in a row with the same closing phrase) is one. */
65
+ export const beatsOf = (sentences: readonly Sentence[], verbs: ReadonlySet<string>): number =>
66
+ blocksOf(sentences.map((sentence) => closingPhraseOf(sentence, verbs))).reduce((beats, block) => beats + (block.size >= REFRAIN_MIN ? 1 : block.size), 0);
@@ -11,6 +11,7 @@ import { partsAt, scopedFacts, type ScopedFact } from "../facts/fact-scope.ts";
11
11
  import { conditionPairConflicts, type ChangeSentence, type ChangeWords, type ConditionWord, type PairConflict, type WordAt } from "../facts/condition-pairs.ts";
12
12
  import { scopeConflicts, summaryConflicts, type FactConflict } from "../facts/fact-conflicts.ts";
13
13
  import { eventDateConflicts, type EventDateConflict, type EventWord } from "../facts/event-dates.ts";
14
+ import { followsEra } from "../facts/era-year.ts";
14
15
  import { retentionConflicts, type LengthMark, type RetentionLength, type RetentionVerb, type RetentionWords } from "../facts/retention-periods.ts";
15
16
  import type { DurationUnit } from "../derived/date-arithmetic.ts";
16
17
  import { DURATION_LEXICONS, quantitiesOf, type Quantity } from "./derived-numbers.ts";
@@ -187,10 +188,12 @@ const endWithLongerUnit = (doc: ProseDocument, quantity: Quantity): number => {
187
188
  return unitStart + longer;
188
189
  };
189
190
 
191
+ /** 元号の年(平成29年法律第51号 の 29年)は暦の年で、保存期間ではない。 */
190
192
  const retentionLengthsOf = (doc: ProseDocument, tree: StructureNode): RetentionLength[] =>
191
193
  quantitiesOf(tree, doc.source).flatMap((quantity) => {
192
194
  const unit = retentionUnitOf(doc, quantity.unit);
193
- return unit === undefined ? [] : [{ start: quantity.start, end: endWithLongerUnit(doc, quantity), amount: quantity.amount, unit }];
195
+ if (unit === undefined || followsEra(doc.source, quantity.start, patternsOf(doc, "calendar-era"))) return [];
196
+ return [{ start: quantity.start, end: endWithLongerUnit(doc, quantity), amount: quantity.amount, unit }];
194
197
  });
195
198
 
196
199
  const retentionVerbsOf = (doc: ProseDocument): RetentionVerb[] =>
@@ -108,11 +108,11 @@ const OBJECT_START = new Set(["DET", "PRON", "NUM"]);
108
108
  * 読み違い(the federal funds rate の rate、small business subcontracting)。窓の中に機能語があれば言い回し(your contract says)。
109
109
  */
110
110
  /** 窓の最後の語が index で、その前が名詞と形容詞だけの用語(先頭の冠詞は許す)か。 */
111
- const closesTerm = (tokens: readonly Token[], index: number, window: Span): boolean => {
111
+ const closesTerm = (tokens: readonly Token[], index: number, window: Span, minWords: number = MIN_COMPOUND_WORDS): boolean => {
112
112
  const touched = tokens.flatMap((token, at) => (overlaps(token, window) ? [at] : []));
113
113
  if (touched.at(-1) !== index) return false;
114
114
  const before = touched.slice(0, -1).filter((at, order) => !(order === 0 && tokens[at]?.pos === "DET"));
115
- return before.length >= MIN_COMPOUND_WORDS && before.every((at) => COMPOUND_POS.has(tokens[at]?.pos ?? ""));
115
+ return before.length >= minWords && before.every((at) => COMPOUND_POS.has(tokens[at]?.pos ?? ""));
116
116
  };
117
117
 
118
118
  const endsNounCompound = (tokens: readonly Token[], index: number, window: Span, unit: LengthUnit): boolean => {
@@ -145,11 +145,22 @@ const opensNounSlot = (token: Token | undefined): boolean =>
145
145
  const gerundAsNoun = (tokens: readonly Token[], index: number, unit: LengthUnit): boolean =>
146
146
  unit === "word" && tokens[index]?.features?.["VerbForm"] === "Ger" && opensNounSlot(tokens[index - 1]);
147
147
 
148
+ const MODALS = new Set(["can", "could", "may", "might", "must", "shall", "should", "will", "would"]);
149
+
150
+ /**
151
+ * 英語で、名詞の主語のすぐ後ろの助動詞 should や must で窓が終わる(the Manager should)。窓にあるのは誰がするかだけで、何をするかは
152
+ * 窓の外で出てくるたびに違う。手順書は手順ごとに役割を名指しし、名指しを繰り返すから誰の務めかが正確に読める。代名詞の主語(you should)は外さない。
153
+ */
154
+ const modalAfterSubject = (tokens: readonly Token[], index: number, window: Span, unit: LengthUnit): boolean => {
155
+ const token = tokens[index];
156
+ return unit === "word" && token?.pos === "AUX" && MODALS.has(token.lemma ?? token.surface.toLowerCase()) && closesTerm(tokens, index, window, 1);
157
+ };
158
+
148
159
  const countsAsPredicate = (tokens: readonly Token[], index: number, window: Span, unit: LengthUnit): boolean => {
149
160
  const token = tokens[index];
150
161
  if (token === undefined || !PREDICATE_POS.has(token.pos) || !overlaps(token, window)) return false;
151
162
  if (modifiesNoun(tokens, index, unit) || namePartAt(tokens, index, unit) || endsNounCompound(tokens, index, window, unit)) return false;
152
- if (gerundAsNoun(tokens, index, unit) || copulaAfterTerm(tokens, index, window, unit)) return false;
163
+ if (gerundAsNoun(tokens, index, unit) || copulaAfterTerm(tokens, index, window, unit) || modalAfterSubject(tokens, index, window, unit)) return false;
153
164
  return !isCut(token, window) || !onlyNamesBeside(tokens, index, window, unit);
154
165
  };
155
166
 
@@ -33,8 +33,23 @@ export const mostFrequent = (words: readonly string[], count: number): string[]
33
33
  .map(([word]) => word);
34
34
  };
35
35
 
36
- const wordsOfDocument = (doc: ProseDocument): KatakanaWord[] =>
37
- doc.sentences.flatMap((sentence) => katakanaWordsIn(sentence.text, doc.names ?? []).map((word) => ({ sentence, word })));
36
+ /**
37
+ * The katakana words of the document's title: what the document is about (e-Govアカウントの登録方法). A manual on accounts
38
+ * cannot say アカウント another way, so the subject is not a loanword to trim.
39
+ */
40
+ export const subjectWords = (doc: ProseDocument): ReadonlySet<string> => {
41
+ const title = doc.markup?.headings.find((heading) => heading.depth === 1)?.text ?? "";
42
+ return new Set(katakanaWordsIn(title, doc.names ?? []));
43
+ };
44
+
45
+ const wordsOfDocument = (doc: ProseDocument): KatakanaWord[] => {
46
+ const subject = subjectWords(doc);
47
+ return doc.sentences.flatMap((sentence) =>
48
+ katakanaWordsIn(sentence.text, doc.names ?? [])
49
+ .filter((word) => !subject.has(word))
50
+ .map((word) => ({ sentence, word })),
51
+ );
52
+ };
38
53
 
39
54
  /**
40
55
  * Katakana loanwords per 1000 characters, over the whole document. Reported once, at the first sentence holding one, with the
@@ -11,7 +11,7 @@ import { restricted, type Restrictors } from "./superlative-clause.ts";
11
11
  import { stackedHedges, type StackedHedge } from "./stacked-hedge.ts";
12
12
  import { comparisonMarkersOf, counterpartBefore, onlyQuoted, quotedRange, type ComparisonMarkers } from "./superlative-comparison.ts";
13
13
  import { inPhrase, ownedBefore } from "./superlative-phrase.ts";
14
- import { asked, contextOf, pointsAtReferent, ranksParts, sought, viewpointBefore, type Context } from "./superlative-context.ts";
14
+ import { asked, contextOf, picksFromNamedSet, pointsAtReferent, ranksParts, sought, viewpointBefore, type Context } from "./superlative-context.ts";
15
15
 
16
16
  const PER = 1000;
17
17
 
@@ -110,6 +110,7 @@ export const hedging: Detector = (doc, options): Finding[] => {
110
110
  hedges: options.lexicon ?? [],
111
111
  frames: doc.lexicons["hedge-frame"] ?? [],
112
112
  scope: doc.lexicons["hedge-scope"] ?? [],
113
+ complements: doc.lexicons["hedge-complement"] ?? [],
113
114
  });
114
115
  const reported = new Set(stacked.map((entry) => entry.sentence.span.start));
115
116
  const density = hedgingDensity(doc, options).filter((finding) => !reported.has(Number(finding.values["offset"])));
@@ -155,6 +156,7 @@ const qualifiedAt = (tokens: readonly Token[], range: TokenRange, qualifiers: Qu
155
156
  viewpointBefore(tokens, range, qualifiers.context.viewpoints) ||
156
157
  pointsAtReferent(tokens, range, qualifiers.context.referents) ||
157
158
  ranksParts(tokens, range, qualifiers.context.parts) ||
159
+ picksFromNamedSet(tokens, range, qualifiers.context.proForms) ||
158
160
  restricted(tokens, range, qualifiers.restrictors) ||
159
161
  namesQuantity(tokens, range, qualifiers.quantityNouns) ||
160
162
  makesWord(tokens, range, qualifiers.suffixes) ||
@@ -53,6 +53,32 @@ export const lookalikesIn = (source: string): Lookalike[] =>
53
53
  (left, right) => left.span.start - right.span.start,
54
54
  );
55
55
 
56
+ /** Words naming the characters themselves (濁点, NFD, Kangxi). A look-alike next to one is an example shown on purpose. */
57
+ const MENTION_LEXICON = "lookalike-mention";
58
+
59
+ const lineStartBefore = (source: string, at: number): number => source.lastIndexOf("\n", at - 1) + 1;
60
+
61
+ const lineEndAfter = (source: string, at: number): number => {
62
+ const end = source.indexOf("\n", at);
63
+ return end === -1 ? source.length : end;
64
+ };
65
+
66
+ /** The look-alike's line with the line before and the line after it: an example and its explanation may sit on neighbouring lines (a code comment). */
67
+ const linesAround = (source: string, span: Span): string => {
68
+ const lineStart = lineStartBefore(source, span.start);
69
+ const lineEnd = lineEndAfter(source, span.end);
70
+ const start = lineStart === 0 ? 0 : lineStartBefore(source, lineStart - 1);
71
+ const end = lineEnd === source.length ? lineEnd : lineEndAfter(source, lineEnd + 1);
72
+ return source.slice(start, end).toLowerCase();
73
+ };
74
+
75
+ /** Whether a word that names these characters stands on or next to the look-alike's line (ホ゜ケット のような…濁点のチェック). */
76
+ export const isShownExample = (source: string, span: Span, mentions: readonly string[]): boolean => {
77
+ if (mentions.length === 0) return false;
78
+ const around = linesAround(source, span);
79
+ return mentions.some((mention) => around.includes(mention.toLowerCase()));
80
+ };
81
+
56
82
  const QUOTE_REACH = 20;
57
83
 
58
84
  const quoteOf = (source: string, span: Span): string =>
@@ -63,13 +89,17 @@ const quoteOf = (source: string, span: Span): string =>
63
89
 
64
90
  const codesOf = (text: string): string => Array.from(text).map(codePointName).join(" ");
65
91
 
66
- export const lookalikeCharacter: Detector = (doc): Finding[] =>
67
- lookalikesIn(doc.source).map((lookalike) => ({
68
- rule: "",
69
- severity: "warning",
70
- line: 0,
71
- column: 0,
72
- quote: quoteOf(doc.source, lookalike.span),
73
- values: { written: lookalike.written, usual: lookalike.usual, code: codesOf(lookalike.written), offset: lookalike.span.start },
74
- variant: lookalike.kind,
75
- }));
92
+ export const lookalikeCharacter: Detector = (doc): Finding[] => {
93
+ const mentions = (doc.lexicons[MENTION_LEXICON] ?? []).map((entry) => entry.pattern);
94
+ return lookalikesIn(doc.source)
95
+ .filter((lookalike) => !isShownExample(doc.source, lookalike.span, mentions))
96
+ .map((lookalike) => ({
97
+ rule: "",
98
+ severity: "warning",
99
+ line: 0,
100
+ column: 0,
101
+ quote: quoteOf(doc.source, lookalike.span),
102
+ values: { written: lookalike.written, usual: lookalike.usual, code: codesOf(lookalike.written), offset: lookalike.span.start },
103
+ variant: lookalike.kind,
104
+ }));
105
+ };