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
@@ -0,0 +1,34 @@
1
+ import type { Span, Token } from "../plugin.ts";
2
+
3
+ // The long form a writer gives a short name to (性犯罪・性暴力の被害者のためのワンストップ支援センター(以下「ワンストップ支援センター」
4
+ // という)): the long form is a name the writer cannot rephrase, so its particles are read as one noun, like a quoted title.
5
+ // Pure: the words that open such an aside (以下) and what keeps a phrase going come in.
6
+
7
+ const OPENING = /[((]\s*/gu;
8
+
9
+ /** Where the asides that give a short name open in text (the bracket's offset), each opened by one of markers. */
10
+ const namingAsides = (text: string, markers: readonly string[]): number[] =>
11
+ [...text.matchAll(OPENING)]
12
+ .filter((open) => markers.some((marker) => marker !== "" && text.startsWith(marker, open.index + open[0].length)))
13
+ .map((open) => open.index);
14
+
15
+ /** The words written straight before at, back to the first one that does not continue the phrase. */
16
+ const phraseBefore = (tokens: readonly Token[], at: number, continues: (token: Token) => boolean): Span | undefined => {
17
+ const last = tokens.findLastIndex((token) => token.span.end <= at);
18
+ if (last === -1 || tokens[last]?.span.end !== at) return undefined;
19
+ const stop = tokens.slice(0, last + 1).findLastIndex((token) => !continues(token));
20
+ const first = tokens[stop + 1];
21
+ return first === undefined || stop === last ? undefined : { start: first.span.start, end: at };
22
+ };
23
+
24
+ /**
25
+ * The long forms named by an aside in a sentence (text starting at offset in the document, tokens in document offsets).
26
+ * markers: the words that open a naming aside (以下). continues: whether a word belongs to the phrase (a noun, the nesting の).
27
+ */
28
+ export const namedLongForms = (
29
+ text: string,
30
+ offset: number,
31
+ tokens: readonly Token[],
32
+ markers: readonly string[],
33
+ continues: (token: Token) => boolean,
34
+ ): Span[] => namingAsides(text, markers).flatMap((at) => phraseBefore(tokens, offset + at, continues) ?? []);
@@ -0,0 +1,27 @@
1
+ import { quotedSpans } from "../quoted-span.ts";
2
+ import type { Span } from "../plugin.ts";
3
+
4
+ // A name the document quotes once (「maDMPsのための共通データモデル」) and then writes without the brackets: still the same
5
+ // name, so its particles are read as one noun wherever it stands. Pure: the particles a name must hold come in.
6
+
7
+ /** Whether name holds one of particles inside it. One that ends in the particle (「実際の」) quotes words, not a name. */
8
+ const holdsParticle = (name: string, particles: readonly string[]): boolean =>
9
+ particles.some((particle) => particle !== "" && name.includes(particle) && !name.endsWith(particle));
10
+
11
+ /** The names quoted in 「」『』 anywhere in source that hold one of particles inside them, each once. */
12
+ export const quotedNames = (source: string, particles: readonly string[]): string[] => [
13
+ ...new Set(
14
+ quotedSpans(source)
15
+ .map((span) => source.slice(span.start, span.end))
16
+ .filter((name) => holdsParticle(name, particles)),
17
+ ),
18
+ ];
19
+
20
+ const placesOf = (text: string, name: string, from = 0): number[] => {
21
+ const at = text.indexOf(name, from);
22
+ return at === -1 ? [] : [at, ...placesOf(text, name, at + name.length)];
23
+ };
24
+
25
+ /** Where names stand in text (starting at offset in the document), with or without brackets. */
26
+ export const quotedNameSpans = (text: string, offset: number, names: readonly string[]): Span[] =>
27
+ names.flatMap((name) => placesOf(text, name).map((at) => ({ start: offset + at, end: offset + at + name.length })));
@@ -1,6 +1,7 @@
1
1
  import type { Detector, DetectorOptions, Finding, Lexicon, LexiconEntry, ProseDocument, Sentence } from "../plugin.ts";
2
- import { entryEnds, entryIn } from "./lexicon-match.ts";
3
- import { mentionCuesOf, onlyMentioned } from "./mentioned-phrase.ts";
2
+ import { entryEnds, entryIn, entryOpens } from "./lexicon-match.ts";
3
+ import { externalLinkTitleSpans } from "../link-title.ts";
4
+ import { mentionCuesOf, onlyInTitles, onlyMentioned } from "./mentioned-phrase.ts";
4
5
  import { closingSentences } from "../closing-paragraph.ts";
5
6
  import { quotedPattern } from "./quoted-pattern.ts";
6
7
 
@@ -22,9 +23,12 @@ type Hit = { readonly sentence: Sentence; readonly matched: string };
22
23
  /** Whether the entry's words in the sentence count as a use. phrase-match counts every one. */
23
24
  type IsUsed = (sentence: Sentence, entry: LexiconEntry) => boolean;
24
25
 
26
+ /** An entry marked opens counts only at the head of the sentence: 「近年、」 opens a stock opening, 「その後、近年の」 is a plain word. */
27
+ const writtenIn = (sentence: Sentence, entry: LexiconEntry): boolean => (entry.opens === true ? entryOpens(sentence, entry) : entryIn(sentence, entry));
28
+
25
29
  const hitsIn = (sentences: readonly Sentence[], lexicon: Lexicon, isUsed: IsUsed = () => true): Hit[] =>
26
30
  sentences.flatMap((sentence) => {
27
- const matched = lexicon.find((entry) => entryIn(sentence, entry) && isUsed(sentence, entry));
31
+ const matched = lexicon.find((entry) => writtenIn(sentence, entry) && isUsed(sentence, entry));
28
32
  return matched === undefined ? [] : [{ sentence, matched: quotedPattern(matched.pattern) }];
29
33
  });
30
34
 
@@ -58,10 +62,14 @@ export const phraseMatchWhere = (doc: ProseDocument, options: DetectorOptions, i
58
62
  return hits.length < options.limit ? [] : findingsOf(hits, options.limit);
59
63
  };
60
64
 
61
- /** phrase-match の、言葉として名指しただけの言い回し(the phrase "…", 「…」という言い方)を数えない版(mentioned-phrase.ts)。 */
65
+ /**
66
+ * phrase-match の、言葉として名指しただけの言い回し(the phrase "…", 「…」という言い方)を数えない版(mentioned-phrase.ts)。
67
+ * 参考文献のリンクに写した外のページの題名([文章の極意は…](https://…))の言い回しも、書き手の言葉ではないので数えない。
68
+ */
62
69
  export const phraseInUse: Detector = (doc, options): Finding[] => {
63
70
  const cues = mentionCuesOf(doc.lexicons["mention-cue"] ?? []);
64
- const hits = phraseHits(doc, options, (sentence, entry) => !onlyMentioned(sentence, entry, cues));
71
+ const titles = externalLinkTitleSpans(doc.source, doc.links);
72
+ const hits = phraseHits(doc, options, (sentence, entry) => !onlyMentioned(sentence, entry, cues) && !onlyInTitles(sentence, entry, titles));
65
73
  return hits.length < options.limit ? [] : findingsOf(hits, options.limit);
66
74
  };
67
75
 
@@ -0,0 +1,25 @@
1
+ // redundant-expression: phrase-match over the language's pairs, except a pair whose last word starts a hyphenated compound
2
+ // ("true fact-check" is a fact-check whose verdict is true, not a true fact).
3
+ import type { Detector, LexiconEntry, Sentence, Token } from "../plugin.ts";
4
+ import { entryRanges } from "./lexicon-match.ts";
5
+ import { phraseMatchWhere } from "./phrase-match.ts";
6
+
7
+ const HYPHENS: ReadonlySet<string> = new Set(["-", "‐"]);
8
+
9
+ const joined = (left: Token | undefined, right: Token | undefined): boolean => left !== undefined && right !== undefined && left.span.end === right.span.start;
10
+
11
+ /** The token at end is a hyphen that ties the word before it to the next word, with no space on either side. */
12
+ export const hyphenatedOnward = (tokens: readonly Token[], end: number): boolean => {
13
+ const hyphen = tokens[end];
14
+ const next = tokens[end + 1];
15
+ return hyphen !== undefined && HYPHENS.has(hyphen.surface) && joined(tokens[end - 1], hyphen) && joined(hyphen, next) && /^\p{L}/u.test(next?.surface ?? "");
16
+ };
17
+
18
+ /** Some place of the pair in the sentence ends a phrase rather than running on into a compound. Without tokens every place counts. */
19
+ const standsAsPair = (sentence: Sentence, entry: LexiconEntry): boolean => {
20
+ const tokens = sentence.tokens ?? [];
21
+ const ranges = entryRanges(sentence, entry);
22
+ return ranges.length === 0 || ranges.some((range) => !hyphenatedOnward(tokens, range.end));
23
+ };
24
+
25
+ export const redundantPair: Detector = (doc, options) => phraseMatchWhere(doc, options, standsAsPair);
@@ -1,4 +1,4 @@
1
- import type { Section, Sentence } from "../plugin.ts";
1
+ import type { Paragraph, Section, Sentence } from "../plugin.ts";
2
2
 
3
3
  // A document that holds two texts under two top-level headings (a directive, then the agency's page about it) may write each in
4
4
  // its own register. A part whose sentences all share the register the rest of the document does not use is a text of its own,
@@ -40,3 +40,34 @@ export const separatePartSentences = <R>(
40
40
  return own ? sentences : [];
41
41
  }),
42
42
  );
43
+
44
+ /** A paragraph that holds no sentence with a register: a line of links or labels (第1, 第2), as a page lays out under the text it carries. */
45
+ const isRegisterless = <R>(paragraph: Paragraph, registerOf: (sentence: Sentence) => R | undefined): boolean =>
46
+ paragraph.sentences.length > 0 && paragraph.sentences.every((sentence) => registerOf(sentence) === undefined);
47
+
48
+ /**
49
+ * The page's own note after the text it carries, without a heading of its own (a directive in である, then ※…ご覧ください。, a line of
50
+ * links, and なお、…ありません。): every counted sentence after the last one in the majority register, when they are MIN_SENTENCES or
51
+ * more, all in one other register that no sentence before them uses, and a paragraph between the first and the last of them holds no counted sentence. Without
52
+ * that line the end of the document is the text's own closing; sentences are the document's in order, lists included; with the other register used earlier too, the end is not a part of its
53
+ * own, and setting it apart would leave the earlier sentences a smaller minority to be pointed at.
54
+ */
55
+ export const trailingPartSentences = <R>(
56
+ sentences: readonly Sentence[],
57
+ paragraphs: readonly Paragraph[],
58
+ registerOf: (sentence: Sentence) => R | undefined,
59
+ majority: R | undefined,
60
+ ): Set<Sentence> => {
61
+ const counted = sentences.filter((sentence) => registerOf(sentence) !== undefined);
62
+ const lastMajority = counted.findLastIndex((sentence) => registerOf(sentence) === majority);
63
+ if (majority === undefined || lastMajority < 0) return new Set();
64
+ const tail = counted.slice(lastMajority + 1);
65
+ const registers = tail.map(registerOf);
66
+ const before = counted.slice(0, lastMajority + 1);
67
+ const ownRegister =
68
+ tail.length >= MIN_SENTENCES && registers.every((register) => register === registers[0]) && before.every((sentence) => registerOf(sentence) === majority);
69
+ const from = tail[0]?.span.end ?? 0;
70
+ const to = tail.at(-1)?.span.start ?? 0;
71
+ const setOff = paragraphs.some((paragraph) => paragraph.span.start >= from && paragraph.span.end <= to && isRegisterless(paragraph, registerOf));
72
+ return ownRegister && setOff ? new Set(tail) : new Set();
73
+ };
@@ -21,18 +21,31 @@ const PAST = new Set(["た", "だ"]);
21
21
  const hasParticle = (tokens: readonly Token[], particles: readonly LexiconEntry[]): boolean =>
22
22
  tokens.some((token) => token.pos === "ADP" && particles.some((particle) => particle.pattern === token.surface));
23
23
 
24
+ /** The sentence ends in a forward-looking form from declaration-ending (…形にしていく。). */
25
+ const endsInResolve = (sentence: Sentence, endings: readonly LexiconEntry[]): boolean => {
26
+ const text = withoutTrailingMarks(sentence.text);
27
+ return endings.some((ending) => text.endsWith(ending.pattern));
28
+ };
29
+
24
30
  /**
25
31
  * A speaker's declaration (負担軽減を、目に見える形で実現する。二度と繰り返さない。): an object particle, no subject particle, and a
26
- * verb in the present at the end. particles is the declaration-particle word list already narrowed to the document's genre; without
27
- * an object particle for the genre the shape does not hold.
32
+ * verb in the present at the end. A sentence ending in a forward-looking form (現場の気づきを、幹部の皆さんが形にしていく。) declares even
33
+ * with its subject said. particles and endings are the declaration-particle and declaration-ending word lists already narrowed to the
34
+ * document's genre; without an object particle for the genre the shape does not hold.
28
35
  */
29
- export const isDeclaration = (sentence: Sentence, ending: readonly Token[], particles: readonly LexiconEntry[]): boolean => {
36
+ export const isDeclaration = (
37
+ sentence: Sentence,
38
+ ending: readonly Token[],
39
+ particles: readonly LexiconEntry[],
40
+ endings: readonly LexiconEntry[] = [],
41
+ ): boolean => {
30
42
  const objects = particles.filter((particle) => particle.group === "object");
31
43
  const subjects = particles.filter((particle) => particle.group === "subject");
32
44
  const tokens = sentence.tokens ?? [];
33
45
  const last = ending.at(-1);
34
46
  if (objects.length === 0 || last === undefined || PAST.has(last.surface)) return false;
35
- return ending.some((token) => token.pos === "VERB") && hasParticle(tokens, objects) && !hasParticle(tokens, subjects);
47
+ const subjectAllowed = !hasParticle(tokens, subjects) || endsInResolve(sentence, endings);
48
+ return ending.some((token) => token.pos === "VERB") && hasParticle(tokens, objects) && subjectAllowed;
36
49
  };
37
50
 
38
51
  /** The most tokens an opener in takeup-opener spans (これ/だけ). */
@@ -94,11 +94,14 @@ export const majorityOf = (judged: readonly Judged[]): Register | undefined => {
94
94
  return difference > 0 ? "polite" : "plain";
95
95
  };
96
96
 
97
- /** 少ないほう。同数なら文書全体で少ないほう、それも同数なら丁寧体。 */
98
- const minorityOf = (group: readonly Judged[], whole: readonly Judged[]): Register => {
99
- const majority = majorityOf(group);
100
- if (majority !== undefined) return majority === "polite" ? "plain" : "polite";
101
- return countIn(whole, "polite") <= countIn(whole, "plain") ? "polite" : "plain";
97
+ /**
98
+ * 少ないほう。同数なら文書全体で少ないほう。文書全体でも同数なら、揃える先の多いほうが無いので undefined(どちらも指さない)。
99
+ * 半々に書いた文書(くだけたメールの「お願いしたい。…です。…助かる。…送ります。」)は、書き損じではなく混ぜた書き方。
100
+ */
101
+ const minorityOf = (group: readonly Judged[], whole: readonly Judged[]): Register | undefined => {
102
+ const majority = majorityOf(group) ?? majorityOf(whole);
103
+ if (majority === undefined) return undefined;
104
+ return majority === "polite" ? "plain" : "polite";
102
105
  };
103
106
 
104
107
  /**
@@ -111,7 +114,7 @@ export const followsDocument = (group: number | undefined, minority: Register, w
111
114
  const slipsInGroup = <T extends Judged>(judged: readonly T[], group: number | undefined, limit: number): Slip<T>[] => {
112
115
  const members = judged.filter((entry) => entry.group === group);
113
116
  const minority = minorityOf(members, judged);
114
- if (followsDocument(group, minority, judged)) return [];
117
+ if (minority === undefined || followsDocument(group, minority, judged)) return [];
115
118
  const slips = members.filter((entry) => entry.register === minority);
116
119
  // 片方しか無ければ揃っている。少数派が閾値を超えて多ければ、混在ではなく別の文体。
117
120
  if (slips.length === 0 || slips.length > limit) return [];
@@ -0,0 +1,4 @@
1
+ import type { Detector } from "../../plugin.ts";
2
+ import { redundantPair } from "../redundant-pair.ts";
3
+
4
+ export const detector: Detector = redundantPair;
@@ -21,6 +21,7 @@ export const REQUEST_LEXICONS = {
21
21
  prohibition: "request-prohibition",
22
22
  deadlineSection: "request-deadline-section",
23
23
  noDeadlineTitle: "request-no-deadline-title",
24
+ decision: "request-decision",
24
25
  } as const;
25
26
 
26
27
  type Words = Readonly<Record<keyof typeof REQUEST_LEXICONS, readonly string[]>>;
@@ -44,6 +45,7 @@ const wordsOf = (doc: ProseDocument): Words => ({
44
45
  prohibition: patternsOf(doc.lexicons[REQUEST_LEXICONS.prohibition]),
45
46
  deadlineSection: patternsOf(doc.lexicons[REQUEST_LEXICONS.deadlineSection]),
46
47
  noDeadlineTitle: patternsOf(doc.lexicons[REQUEST_LEXICONS.noDeadlineTitle]),
48
+ decision: patternsOf(doc.lexicons[REQUEST_LEXICONS.decision]),
47
49
  });
48
50
 
49
51
  /** How far apart, in characters, the action word and the request ending may be: the action must be what is requested. */
@@ -224,14 +226,15 @@ const withoutDates = (source: string, span: Span, inside: readonly Span[]): stri
224
226
  source.slice(span.start, span.end),
225
227
  );
226
228
 
229
+ /** A date with a deadline word, or with the decision step (a schedule's 「12月:経営会議にて承認」 says when the decision is made). */
227
230
  const statesDeadline = (source: string, sentence: Sentence, words: Words, dates: readonly Span[]): boolean => {
228
231
  const inside = datesInside(sentence.span, dates);
229
- return inside.length > 0 && containsAny(withoutDates(source, sentence.span, inside), words.deadline);
232
+ return inside.length > 0 && containsAny(withoutDates(source, sentence.span, inside), [...words.deadline, ...words.decision]);
230
233
  };
231
234
 
232
235
  /**
233
- * The section headed only by a deadline-section word (a notice's "DATES:", "2. Deadline") that states a date with a
234
- * deadline word: the document gives its deadline once there. -1 without one.
236
+ * The section headed only by a deadline-section word (a notice's "DATES:", "2. Deadline", a proposal's schedule) that
237
+ * states a date with a deadline or decision word: the document gives its deadline once there. -1 without one.
235
238
  */
236
239
  const documentDeadlineSection = (source: string, sections: readonly Section[], words: Words, dates: readonly Span[]): number =>
237
240
  sections.findIndex(
@@ -3,7 +3,7 @@ import { enumeratedRuns, enumeratorStarts, numberedStarts } from "./enumerated-r
3
3
  import { continuesThrough, groupOf, majorityOf, registerOf, slipsOf, type Register } from "./register.ts";
4
4
  import { isRunInLabel } from "./run-in-label.ts";
5
5
  import { noticeSentences } from "./notice-paragraph.ts";
6
- import { separatePartSentences } from "./register-separate-part.ts";
6
+ import { separatePartSentences, trailingPartSentences } from "./register-separate-part.ts";
7
7
  import { askerSentences } from "./asker-voice.ts";
8
8
  import { licenceNoticeSentences } from "./licence-notice.ts";
9
9
  import { chronologyRows } from "../chronology-rows.ts";
@@ -26,6 +26,7 @@ import type { Detector, Finding, LexiconEntry, ProseDocument, Sentence, Span, To
26
26
  * 札を付けて引いた言葉(例:…。Q: …?)、印を付けた札の行の下の記入欄の値(■ 調査目的\n…とする。)、
27
27
  * 〒や電話の行のある問い合わせ先の段落も数えない(register-set-apart.ts)。
28
28
  * 一番上の見出しで分けた部分のうち、2 文以上がみな文書の多いほうと違う同じ調子のものは、別の文書として数えない(register-separate-part.ts)。
29
+ * 多いほうの最後の文より後ろの 2 文以上が、みな前に無い違う同じ調子で、間に調子を持たない行(リンクの並び)を挟むものも、ページの注記として数えない。
29
30
  */
30
31
  /**
31
32
  * quiet: 常体と読めるが、願い・問い・言いさしの形(register-neutral-shape.ts)の文。どちらの調子の文書にも現れるので指さない。
@@ -37,7 +38,7 @@ import type { Detector, Finding, LexiconEntry, ProseDocument, Sentence, Span, To
37
38
  type Entry = { readonly sentence: Sentence; readonly register: Register; readonly group: number | undefined; readonly quiet: boolean };
38
39
 
39
40
  /** 文の調子と quiet を決める語彙表。polite は polite-ending、neutral は neutral-ending、requests は neutral-request、wishes は neutral-wish、
40
- * greetings は set-polite-phrase、declaration は declaration-particle を文書の genre で絞ったもの、openers は takeup-opener。 */
41
+ * greetings は set-polite-phrase、declaration と resolves は declaration-particle と declaration-ending を文書の genre で絞ったもの、openers は takeup-opener。 */
41
42
  type EndingWords = {
42
43
  readonly polite: readonly LexiconEntry[];
43
44
  readonly neutral: readonly LexiconEntry[];
@@ -45,6 +46,7 @@ type EndingWords = {
45
46
  readonly wishes: readonly LexiconEntry[];
46
47
  readonly greetings: readonly LexiconEntry[];
47
48
  readonly declaration: readonly LexiconEntry[];
49
+ readonly resolves: readonly LexiconEntry[];
48
50
  readonly openers: readonly LexiconEntry[];
49
51
  };
50
52
 
@@ -57,6 +59,7 @@ const endingWords = (doc: ProseDocument, polite: readonly LexiconEntry[], genre:
57
59
  wishes: doc.lexicons["neutral-wish"] ?? [],
58
60
  greetings: doc.lexicons["set-polite-phrase"] ?? [],
59
61
  declaration: entriesForGenre(doc.lexicons["declaration-particle"] ?? [], genre),
62
+ resolves: entriesForGenre(doc.lexicons["declaration-ending"] ?? [], genre),
60
63
  openers: doc.lexicons["takeup-opener"] ?? [],
61
64
  });
62
65
 
@@ -65,7 +68,7 @@ const isQuiet = (sentence: Sentence, ending: readonly Token[], register: Registe
65
68
  register === "polite"
66
69
  ? endsInSetGreeting(sentence, words.greetings)
67
70
  : isNeutralPlainShape(sentence, ending, words.requests, words.wishes) ||
68
- isDeclaration(sentence, ending, words.declaration) ||
71
+ isDeclaration(sentence, ending, words.declaration, words.resolves) ||
69
72
  isExclamation(sentence) ||
70
73
  isTakenUp(next, between, words.openers);
71
74
 
@@ -124,7 +127,10 @@ export const judgedSentences = (doc: ProseDocument, polite: readonly LexiconEntr
124
127
  const majority = majorityOf(all.map((entry) => ({ register: entry.register, group: undefined })));
125
128
  const registerAt = (sentence: Sentence): Register | undefined => registers.get(sentence);
126
129
  const notices = noticeSentences(doc.paragraphs, doc.lexicons["notice-phrase"] ?? [], registerAt, majority);
127
- const parts = separatePartSentences(doc.sections, registerAt, majority);
130
+ const parts = new Set([
131
+ ...separatePartSentences(doc.sections, registerAt, majority),
132
+ ...trailingPartSentences(doc.sentences, doc.paragraphs, registerAt, majority),
133
+ ]);
128
134
  const found = all.filter((entry) => !notices.has(entry.sentence) && !parts.has(entry.sentence));
129
135
  const runs = runsOf(
130
136
  doc,
@@ -89,15 +89,18 @@ const ACRONYM = new RegExp(String.raw`${EDGE_BEFORE}${ACRONYM_PART}(?:-${ACRONYM
89
89
  * 強調は読点や括弧をまたいで続くので(THE AUTHOR, THE COMPANY (IF ANY))、そういう続きを含む
90
90
  * 「大文字以外の文字を含まない一続き」を丸ごと強調と見なす。小文字の語が挟まれば切れるので、
91
91
  * 「SRE, SLO, MTTR」のような略語の並びは残る。引用符に包まれた大文字の句(“AS IS”)も強調。
92
- * 2 語でも、片方が略語にしては長い語なら強調(BILLING CODE)。略語 2 つの並び(NIST SP)は残る。
92
+ * 2 語でも、片方が略語にしては長い語なら強調(BILLING CODE)。どちらも 5 字以上の 2 語(MIRAI SCHOOL、UNITED STATES)は
93
+ * 大文字で書いた名前や語で、略語がそう並ぶことはない。略語 2 つの並び(NIST SP、FEMA NFIP)は残る。
93
94
  */
94
95
  const CAPS_WORD = String.raw`[A-Z]+(?:&[A-Z]+)*`;
95
96
  const LONG_CAPS_WORD = String.raw`[A-Z]{${ACRONYM_MAX + 1},}`;
97
+ const WORD_PAIR_MIN = 5;
98
+ const WORD_PAIR_PART = String.raw`[A-Z]{${WORD_PAIR_MIN},}`;
96
99
  const CAPS_GAP = String.raw`[\s"“”'‘’]+`;
97
100
  const SHOUTED_RUN = new RegExp(String.raw`${EDGE_BEFORE}${CAPS_WORD}(?:${CAPS_GAP}${CAPS_WORD}){2,}${EDGE_AFTER}`, "u");
98
101
  /** 2 語の強調は、その 2 語だけを外す。続きまで外すと、区切りの後ろの略語(NEW GUIDELINES: SRE)まで消える。 */
99
102
  const SHOUTED_PAIR = new RegExp(
100
- String.raw`${EDGE_BEFORE}(?:${LONG_CAPS_WORD}${CAPS_GAP}${CAPS_WORD}|${CAPS_WORD}${CAPS_GAP}${LONG_CAPS_WORD})${EDGE_AFTER}`,
103
+ String.raw`${EDGE_BEFORE}(?:${LONG_CAPS_WORD}${CAPS_GAP}${CAPS_WORD}|${CAPS_WORD}${CAPS_GAP}${LONG_CAPS_WORD}|${WORD_PAIR_PART}${CAPS_GAP}${WORD_PAIR_PART})${EDGE_AFTER}`,
101
104
  "gu",
102
105
  );
103
106
  const UNCASED_STRETCH = /(?:[A-Z]|\P{L})+/gu;
@@ -6,10 +6,11 @@ import { isWithinAny, quotedIn, QUOTATION_MARKS } from "../quoted-span.ts";
6
6
  const STACKED_AT = 2;
7
7
 
8
8
  /**
9
- * 語彙表 3 つ。hedges は逃げの表現そのもの、frames はそれだけでは逃げていない包む言い方(「という状況です」、may)、
10
- * scope は hedges のうち、どれだけ確かかではなくどこで成り立つかを言うもの(「場合がある」、in some cases)。
9
+ * 語彙表 4 つ。hedges は逃げの表現そのもの、frames はそれだけでは逃げていない包む言い方(「という状況です」、may)、
10
+ * scope は hedges のうち、書き手の確かさを下げないもの(「場合がある」、「と思われている」)、
11
+ * complements は動詞の後ろで中身の節を始める語(knowing that の that)。
11
12
  */
12
- export type HedgeWords = { readonly hedges: Lexicon; readonly frames: Lexicon; readonly scope: Lexicon };
13
+ export type HedgeWords = { readonly hedges: Lexicon; readonly frames: Lexicon; readonly scope: Lexicon; readonly complements: Lexicon };
13
14
 
14
15
  type Device = { readonly range: TokenRange; readonly hedge: boolean };
15
16
 
@@ -41,10 +42,25 @@ const spanOf = (tokens: readonly Token[], range: TokenRange): Span | undefined =
41
42
  /** 句読点と等位接続詞(and、but、及び)は節を切る。別の節の逃げは、同じ主張を二重にぼかしていない。 */
42
43
  const CLAUSE_BREAK = new Set(["PUNCT", "CCONJ"]);
43
44
 
45
+ /**
46
+ * 動詞の後ろで中身の節を始める語の位置(knowing that の that)。その節の may は知っていることの中身で、
47
+ * 前の perhaps と同じ主張をぼかしていない。逃げの表現の動詞(it seems that)の後ろは、その逃げが包む節なので切らない。
48
+ */
49
+ const complementOpens = (sentence: Sentence, complements: Lexicon, devices: readonly Device[]): Set<number> => {
50
+ const tokens = sentence.tokens ?? [];
51
+ const inDevice = (at: number): boolean => devices.some((device) => device.range.start <= at && at < device.range.end);
52
+ const opensAfterVerb = (range: TokenRange): boolean => tokens[range.start - 1]?.pos === "VERB" && !inDevice(range.start - 1);
53
+ return new Set(
54
+ rangesOf(sentence, complements)
55
+ .filter(opensAfterVerb)
56
+ .map((range) => range.start),
57
+ );
58
+ };
59
+
44
60
  /** 語ごとの、文の頭から数えた節の番号。 */
45
- const clauseOf = (tokens: readonly Token[]): number[] =>
46
- tokens.reduce<number[]>((clauses, token) => {
47
- clauses.push((clauses.at(-1) ?? 0) + (CLAUSE_BREAK.has(token.pos) ? 1 : 0));
61
+ const clauseOf = (tokens: readonly Token[], opens: ReadonlySet<number>): number[] =>
62
+ tokens.reduce<number[]>((clauses, token, at) => {
63
+ clauses.push((clauses.at(-1) ?? 0) + (CLAUSE_BREAK.has(token.pos) || opens.has(at) ? 1 : 0));
48
64
  return clauses;
49
65
  }, []);
50
66
 
@@ -84,7 +100,8 @@ const stackedClause = (devices: readonly Device[], clauses: readonly number[]):
84
100
  */
85
101
  const stackedHedgeIn = (sentence: Sentence, words: HedgeWords): Span[] => {
86
102
  const tokens = sentence.tokens ?? [];
87
- return stackedClause(devicesIn(sentence, words), clauseOf(tokens))
103
+ const devices = devicesIn(sentence, words);
104
+ return stackedClause(devices, clauseOf(tokens, complementOpens(sentence, words.complements, devices)))
88
105
  .toSorted((left, right) => left.range.start - right.range.start)
89
106
  .flatMap((device) => spanOf(tokens, { start: device.range.start, end: shownEnd(tokens, device.range) }) ?? []);
90
107
  };
@@ -336,6 +336,7 @@ const shareWordsOf = (doc: ProseDocument): ShareWords => ({
336
336
  exceptions: (doc.lexicons["share-exception"] ?? []).map((entry) => entry.pattern),
337
337
  rests: (doc.lexicons["share-rest"] ?? []).map((entry) => entry.pattern),
338
338
  changes: (doc.lexicons["change-direction"] ?? []).map((entry) => entry.pattern),
339
+ joiners: [...(doc.lexicons["range-connector"] ?? []), ...(doc.lexicons["quantity-range-word"] ?? [])].map((entry) => entry.pattern),
339
340
  units: (doc.lexicons["percent-unit"] ?? []).map((entry) => entry.pattern),
340
341
  totalLabels: (doc.lexicons["total-label"] ?? []).map((entry) => entry.pattern),
341
342
  });
@@ -4,7 +4,7 @@ import type { Detector, DetectorOptions, Finding, LengthUnit, Paragraph, ProseDo
4
4
  import { dateStampIndexes, stampCandidates } from "../date-stamp.ts";
5
5
  import { inDocumentOrder } from "../structure/issues.ts";
6
6
  import { preambleParagraphs } from "../preamble-paragraphs.ts";
7
- import { isTooLongParagraph, labelledBlocks, opensWithFusedHeading } from "../paragraph-length.ts";
7
+ import { isTooLongParagraph, labelledBlocks, lostLineBreaks, opensWithFusedHeading } from "../paragraph-length.ts";
8
8
  import { bodySectionOf } from "../body-section.ts";
9
9
  import { threeShare } from "../rule-of-three.ts";
10
10
  import { isInterview, sectionLevels } from "../section-levels.ts";
@@ -65,12 +65,12 @@ const sentenceSize = (sentence: Sentence, unit: LengthUnit): number =>
65
65
  type Block = { readonly start: number; readonly sentences: readonly Sentence[] };
66
66
 
67
67
  /**
68
- * 段落の中の、長さを測る文の組と、その頭の位置(最初の組は段落の頭)。見出しが本文に溶けた段落(改行の落ちた文書)は測らない。
68
+ * 段落の中の、長さを測る文の組と、その頭の位置(最初の組は段落の頭)。見出しが本文に溶けた段落や、文どうしが空白なしでつながった段落(改行の落ちた文書)は測らない。
69
69
  * 【】の見出しや段落番号だけの行で段落を割る。
70
70
  */
71
71
  const measuredBlocks = (doc: ProseDocument, paragraph: Paragraph): Block[] => {
72
72
  const text = doc.source.slice(paragraph.span.start, paragraph.span.end);
73
- if (opensWithFusedHeading(text)) return [];
73
+ if (opensWithFusedHeading(text) || lostLineBreaks(paragraph.sentences)) return [];
74
74
  return labelledBlocks(text, paragraph.span.start, paragraph.sentences).map((sentences, index) => ({
75
75
  start: index === 0 ? paragraph.span.start : (sentences[0]?.span.start ?? paragraph.span.start),
76
76
  sentences,
@@ -12,6 +12,8 @@ export type Context = {
12
12
  readonly viewpoints: Lexicon;
13
13
  /** 全体の部分を言う名詞(part・role・step)。 */
14
14
  readonly parts: Lexicon;
15
+ /** 前に名指した名詞の代わりに立つ語(one・ones)。 */
16
+ readonly proForms: Lexicon;
15
17
  };
16
18
 
17
19
  /** 語彙表の語が最上級まで届く語の数。これより離れた動詞は、間に別の目的語や節がある。 */
@@ -33,6 +35,7 @@ export const contextOf = (lexicons: Readonly<Record<string, Lexicon>>): Context
33
35
  referents: lexicons["superlative-referent"] ?? [],
34
36
  viewpoints: lexicons["superlative-viewpoint"] ?? [],
35
37
  parts: lexicons["superlative-part"] ?? [],
38
+ proForms: lexicons["superlative-pro-form"] ?? [],
36
39
  });
37
40
 
38
41
  const isPunct = (token: Token | undefined): boolean => token === undefined || token.pos === "PUNCT";
@@ -105,3 +108,12 @@ export const ranksParts = (tokens: readonly Token[], range: TokenRange, parts: L
105
108
  const at = phraseEnd(tokens, range.end);
106
109
  return at > range.end && isWord(tokens[at - 1], parts);
107
110
  };
111
+
112
+ /**
113
+ * 最上級の名詞が、前に名指した名詞の代わりの語か(ten topics … the best-scoring one)。比べている集まりは文章が先に
114
+ * 名指したもので、世の中のものと比べた主張ではない。名詞は最上級の修飾の後ろに来る(英語)。
115
+ */
116
+ export const picksFromNamedSet = (tokens: readonly Token[], range: TokenRange, proForms: Lexicon): boolean => {
117
+ const at = phraseEnd(tokens, range.end);
118
+ return at > range.end && isWord(tokens[at - 1], proForms);
119
+ };
@@ -4,10 +4,12 @@ import { chronologyRows } from "../chronology-rows.ts";
4
4
  import { externalLinkTitleSpans } from "../link-title.ts";
5
5
  import type { Detector, Finding, Span, Token } from "../plugin.ts";
6
6
  import { countedTokens, uncountedWordsOf, type UncountedWords } from "../uncounted-particles.ts";
7
- import { honorificGroupParticles } from "../honorific-group.ts";
7
+ import { boundWordParticles } from "../bound-word-particles.ts";
8
8
  import { setPhraseParticles } from "../set-phrase-particles.ts";
9
9
  import { noteSentences } from "../note-paragraphs.ts";
10
10
  import { documentNameSpans } from "./particle-run-names.ts";
11
+ import { namedLongForms } from "./particle-run-long-forms.ts";
12
+ import { quotedNameSpans, quotedNames } from "./particle-run-quoted-names.ts";
11
13
  import { isFlattenedTable } from "./sentence-parts.ts";
12
14
 
13
15
  /**
@@ -89,21 +91,27 @@ const runsOf = (tokens: readonly Token[], nesting: readonly string[], breaks: re
89
91
  return acc;
90
92
  }, []);
91
93
 
94
+ /** 括弧の中で、前の語句に短い呼び名を付ける語(以下「…」という)。前の語句は名前なので、題名と同じく中の助詞を数えない。 */
95
+ const NAMING_LEXICON = "definition-marker";
96
+
92
97
  /** 句と句の間の記号(制限=タグの制限、A→B)。半角の = や : は名詞として読まれ、句読点のようには切れない。 */
93
98
  const RUN_BREAK_LEXICON = "particle-run-break";
94
99
 
95
100
  /** 人の集まりを敬って呼ぶ語(国民の皆様の「皆様」)。直前の助詞は呼び方の一部で、入れ子の輪に数えない。 */
96
101
  const HONORIFIC_GROUP_LEXICON = "honorific-group";
97
102
 
103
+ /** 置き場所を言う語(ラックの下の「下」)。直前の助詞は「ラックの下」という一つの場所の名前の中にあり、入れ子の輪に数えない。 */
104
+ const POSITION_LEXICON = "particle-run-position";
105
+
98
106
  /** 助詞を挟んで一語のように読む決まった言い回し(おそれのある)。中の助詞は入れ子の輪に数えない。 */
99
107
  const SET_PHRASE_LEXICON = "particle-run-set-phrase";
100
108
 
101
- /** 敬って呼ぶ語(皆様)と決まった言い回し(おそれのある)。 */
102
- type Phrases = { readonly groups: readonly string[]; readonly setPhrases: readonly string[] };
109
+ /** 前の語と組んで一つの名前になる語(皆様、下)と決まった言い回し(おそれのある)。 */
110
+ type Phrases = { readonly boundWords: readonly string[]; readonly setPhrases: readonly string[] };
103
111
 
104
- /** 数えない助詞(番号をつなぐ「の」、敬って呼ぶ語の前の「の」、決まった言い回しの中の「の」)を除いた語。 */
105
- const chainTokens = (tokens: readonly Token[], numbering: UncountedWords, { groups, setPhrases }: Phrases): readonly Token[] => {
106
- const uncounted = new Set([...honorificGroupParticles(tokens, numbering.particles, groups), ...setPhraseParticles(tokens, numbering.particles, setPhrases)]);
112
+ /** 数えない助詞(番号をつなぐ「の」、敬って呼ぶ語や置き場所を言う語の前の「の」、決まった言い回しの中の「の」)を除いた語。 */
113
+ const chainTokens = (tokens: readonly Token[], numbering: UncountedWords, { boundWords, setPhrases }: Phrases): readonly Token[] => {
114
+ const uncounted = new Set([...boundWordParticles(tokens, numbering.particles, boundWords), ...setPhraseParticles(tokens, numbering.particles, setPhrases)]);
107
115
  const counted = countedTokens(tokens, numbering);
108
116
  return uncounted.size === 0 ? counted : counted.filter((token) => !uncounted.has(token));
109
117
  };
@@ -114,16 +122,24 @@ export const doubledParticle: Detector = (doc, options): Finding[] => {
114
122
  const breaks = (doc.lexicons[RUN_BREAK_LEXICON] ?? []).map((entry) => entry.pattern);
115
123
  const numbering = uncountedWordsOf(doc.lexicons, nesting);
116
124
  const phrases: Phrases = {
117
- groups: (doc.lexicons[HONORIFIC_GROUP_LEXICON] ?? []).map((entry) => entry.pattern),
125
+ boundWords: [HONORIFIC_GROUP_LEXICON, POSITION_LEXICON].flatMap((id) => (doc.lexicons[id] ?? []).map((entry) => entry.pattern)),
118
126
  setPhrases: (doc.lexicons[SET_PHRASE_LEXICON] ?? []).map((entry) => entry.pattern),
119
127
  };
120
128
  const prose = doc.prose ?? doc.source;
129
+ const namingMarkers = (doc.lexicons[NAMING_LEXICON] ?? []).map((entry) => entry.pattern);
130
+ const names = quotedNames(doc.source, nesting);
131
+ const continuesName = (token: Token): boolean => nesting.includes(token.surface) || !breaksRun(token, breaks);
121
132
  // 平らにした表の文は、見出しのセル(役員の兼任等・営業上の取引・設備の賃貸借)の切れ目が見えず、別のセルの「の」が一つの連なりに見える。
122
133
  return doc.sentences
123
134
  .filter((sentence) => !isFlattenedTable(sentence.text))
124
135
  .flatMap((sentence) => {
125
136
  const tokens = chainTokens(sentence.tokens ?? [], numbering, phrases);
126
- const quoted = [...quotedIn(sentence), ...titles];
137
+ const quoted = [
138
+ ...quotedIn(sentence),
139
+ ...titles,
140
+ ...namedLongForms(sentence.text, sentence.span.start, sentence.tokens ?? [], namingMarkers, continuesName),
141
+ ...quotedNameSpans(sentence.text, sentence.span.start, names),
142
+ ];
127
143
  const longRuns = (skipped: readonly Span[]): Run[] => runsOf(tokens, nesting, breaks, skipped).filter((run) => run.tokens.length > options.limit);
128
144
  const found = longRuns(quoted);
129
145
  // 文書の名前を読むのは長い連なりのある文だけ。名前は位置ごとに読むので、全部の文で読むと遅い。
@@ -6,6 +6,7 @@ import { mergeSpans } from "../span-merge.ts";
6
6
  import { firstEndingAfter } from "../soft-break.ts";
7
7
  import { isLabelClose, isLabelInAside } from "./bracket-label.ts";
8
8
  import { isInchMark } from "./inch-mark.ts";
9
+ import { isEmoticonMouth } from "./emoticon.ts";
9
10
 
10
11
  /**
11
12
  * 括弧の組。どの言語でも同じ字の決まりなので、語彙表ではなくここに置く。family は形(丸・角)で、全角と半角は同じ形の別の幅。
@@ -95,7 +96,7 @@ export const bracketProblems = (text: string): BracketProblem[] => {
95
96
  const heads = paragraphHeads(text);
96
97
  [...text.matchAll(MARKS)].forEach((match) => {
97
98
  const quoteOpen = scan.open.some((entry) => entry.bracket.family === "quote");
98
- if (isInchMark(text, match.index, quoteOpen)) return;
99
+ if (isInchMark(text, match.index, quoteOpen) || isEmoticonMouth(text, match.index)) return;
99
100
  const opening = BY_OPEN.get(match[0]);
100
101
  const closing = BY_CLOSE.get(match[0]);
101
102
  if (opening !== undefined) openWith(scan, opening, match.index, heads.has(match.index));
@@ -18,6 +18,15 @@ export const isClosedCompound = (word: string, speller: Speller): boolean => {
18
18
  .some((split) => isKnownWord(word.slice(0, split), listed) && isKnownWord(word.slice(split), inflected));
19
19
  };
20
20
 
21
+ /**
22
+ * A word spelled -nce where the dictionary spells it -nse (recompence, expence, suspence): the older or British spelling of
23
+ * that word, as licence and defence are, not a slip.
24
+ */
25
+ export const isNceSpelling = (word: string, speller: Speller): boolean => {
26
+ const at = word.lastIndexOf("nce");
27
+ return at > 0 && isKnownWord(`${word.slice(0, at)}nse${word.slice(at + "nce".length)}`, speller);
28
+ };
29
+
21
30
  /** Letters a name keeps before its drug stem: fewer, and the word is too short to be read as a drug by its ending alone. */
22
31
  const MIN_DRUG_HEAD = 3;
23
32
 
@@ -13,6 +13,7 @@ import {
13
13
  inSearchTermList,
14
14
  isClosedCompound,
15
15
  isMention,
16
+ isNceSpelling,
16
17
  usedOnce,
17
18
  } from "./unknown-word-context.ts";
18
19
 
@@ -51,8 +52,9 @@ export const codeWordsOf = (source: string): Set<string> => {
51
52
  return words;
52
53
  };
53
54
 
54
- /** 辞書の語か、派生した語に活用の語尾を付けた語(operationalises、rightsized)か、四字以上の辞書の語二つを続けた語(crowdwork)。 */
55
- const isFormedWord = (word: string, speller: Speller): boolean => isKnownWord(word, speller) || hasTwoEndings(word, speller) || isClosedCompound(word, speller);
55
+ /** 辞書の語か、派生した語に活用の語尾を付けた語(operationalises、rightsized)か、四字以上の辞書の語二つを続けた語(crowdwork)か、-nse の語の -nce の綴り(recompence)。 */
56
+ const isFormedWord = (word: string, speller: Speller): boolean =>
57
+ isKnownWord(word, speller) || hasTwoEndings(word, speller) || isClosedCompound(word, speller) || isNceSpelling(word, speller);
56
58
 
57
59
  /**
58
60
  * 置かれた場所から、名前や用語と分かる語。名指した語("mailto"、(jchaplin))、検索語の並び(vaccin*)、外国語の句(bête noire)、