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,7 +1,8 @@
1
- import type { Detector, LexiconEntry, ProseDocument, Sentence } from "../plugin.ts";
1
+ import type { Detector, LexiconEntry, ProseDocument, Sentence, Span } from "../plugin.ts";
2
2
  import { entryRanges } from "./lexicon-match.ts";
3
3
  import { phraseMatchWhere } from "./phrase-match.ts";
4
4
  import { followsToldQuote, type TellingCues } from "./reported-speech.ts";
5
+ import { citationMarks, citationWordsOf, referenceListsOf } from "./citation-marks.ts";
5
6
 
6
7
  const cuesOf = (doc: ProseDocument): TellingCues => {
7
8
  const entries = doc.lexicons["telling-cue"] ?? [];
@@ -9,16 +10,41 @@ const cuesOf = (doc: ProseDocument): TellingCues => {
9
10
  return { occasion: inGroup("occasion"), sayer: inGroup("sayer") };
10
11
  };
11
12
 
13
+ /** Where the document names its sources: its reference lists, and the in-text citations ([11, 49], Smith (2020)). */
14
+ type Sources = { readonly referenceLists: readonly Span[]; readonly citations: readonly Span[] };
15
+
16
+ const sourcesOf = (doc: ProseDocument): Sources => {
17
+ const words = citationWordsOf(doc);
18
+ const referenceLists = referenceListsOf(doc, words);
19
+ return { referenceLists, citations: citationMarks(doc.prose ?? doc.source, referenceLists, words) };
20
+ };
21
+
22
+ const isInside = (spans: readonly Span[], at: number): boolean => spans.some((span) => span.start <= at && at < span.end);
23
+
24
+ /**
25
+ * A phrase that names its source: an entry of a reference list (a cited headline, "…, experts say") is the cited work's
26
+ * words, and a citation later in the sentence ("previous studies showing … [11, 49]") says which studies.
27
+ */
28
+ const namesSource = (sources: Sources, sentence: Sentence, phraseStart: number): boolean =>
29
+ isInside(sources.referenceLists, sentence.span.start) ||
30
+ sources.citations.some((citation) => phraseStart <= citation.start && citation.start < sentence.span.end);
31
+
12
32
  /**
13
33
  * A weasel phrase counts unless every use of it in the sentence reports a quotation told on a named occasion or by a named
14
- * sayer (申し込んだら、「…」と言われています). Without tokens the uses cannot be placed, so each one counts.
34
+ * sayer (申し込んだら、「…」と言われています), or names its source. Without tokens the uses cannot be placed, so each one counts.
15
35
  */
16
- const isWeaselUse = (doc: ProseDocument, sentence: Sentence, entry: LexiconEntry): boolean => {
36
+ const isWeaselUse = (doc: ProseDocument, sources: Sources, sentence: Sentence, entry: LexiconEntry): boolean => {
17
37
  const tokens = sentence.tokens ?? [];
18
38
  const ranges = entryRanges(sentence, entry);
19
39
  if (ranges.length === 0) return true;
20
40
  const cues = cuesOf(doc);
21
- return !ranges.every((range) => followsToldQuote(doc.source.slice(sentence.span.start, tokens[range.start]?.span.start ?? sentence.span.start), cues));
41
+ return !ranges.every((range) => {
42
+ const start = tokens[range.start]?.span.start ?? sentence.span.start;
43
+ return followsToldQuote(doc.source.slice(sentence.span.start, start), cues) || namesSource(sources, sentence, start);
44
+ });
22
45
  };
23
46
 
24
- export const weaselWord: Detector = (doc, options) => phraseMatchWhere(doc, options, (sentence, entry) => isWeaselUse(doc, sentence, entry));
47
+ export const weaselWord: Detector = (doc, options) => {
48
+ const sources = sourcesOf(doc);
49
+ return phraseMatchWhere(doc, options, (sentence, entry) => isWeaselUse(doc, sources, sentence, entry));
50
+ };
@@ -0,0 +1,7 @@
1
+ /** 元号のすぐ後ろ(空白一つまで)の数。暦の年(平成29年、令和 3 年)で、年数という長さではない。元号は語彙表 calendar-era から。 */
2
+ const ERA_GAP = /[ \t\u3000]?$/u;
3
+
4
+ export const followsEra = (source: string, start: number, eras: readonly string[]): boolean => {
5
+ const head = source.slice(0, start).replace(ERA_GAP, "");
6
+ return eras.some((era) => era !== "" && head.endsWith(era));
7
+ };
@@ -11,7 +11,7 @@ import { withoutEdgeMarks } from "./trim-marks.ts";
11
11
  */
12
12
  export type FactPart = "opening" | "summary" | "body";
13
13
 
14
- /** record: 同じ範囲で、行の頭に何度も書かれた名前。催しや論文ごとの記録の欄で、値が違っても食い違いではない。 */
14
+ /** record: 同じ範囲で、行の頭(か行の中の文の切れ目の後ろ)に何度も書かれた名前。催しや論文ごとの記録の欄で、値が違っても食い違いではない。 */
15
15
  export type ScopedFact = Fact & { readonly scope: string; readonly part: FactPart; readonly record: boolean };
16
16
 
17
17
  const CONTAINERS: ReadonlySet<string> = new Set(["section", "chapter", "article"]);
@@ -99,15 +99,29 @@ const partOf = (around: readonly StructureNode[], tree: StructureNode, offset: n
99
99
  return isOpening(around.at(-1), tree, offset) ? "opening" : "body";
100
100
  };
101
101
 
102
- /** 名前ごとに、頭にその名前を書いた行の番号。 */
102
+ /** 行の中の文の切れ目のすぐ後ろ。参考文献の項目は、書誌の文のあとに「External Links: …」と欄を続ける。 */
103
+ const INLINE_LABEL = /[.!?。.!?][ \t]+([^.!?。.!?::|]{1,24})[::]/gu;
104
+
105
+ /** 文の切れ目の後ろから始まる「名前:」の名前。行の頭の名前と同じ書き方に揃える。表の行は読まない。 */
106
+ const inlineLabelsOf = (line: Line): string[] =>
107
+ line.text.trimStart().startsWith("|")
108
+ ? []
109
+ : [...line.text.matchAll(INLINE_LABEL)].flatMap((match) => {
110
+ const label = withoutEdgeMarks(match[1] ?? "");
111
+ return /\p{L}/u.test(label) ? [label.normalize("NFKC").toLowerCase()] : [];
112
+ });
113
+
114
+ /** 名前ごとに、その名前の欄を書いた行の番号。欄は行の頭か、行の中の文の切れ目の後ろ。 */
103
115
  const headLines = (lines: readonly Line[]): ReadonlyMap<string, readonly number[]> => {
104
116
  const found = new Map<string, number[]>();
105
117
  lines.forEach((line, index) => {
106
118
  const head = headLabelOf(line);
107
- if (head === undefined) return;
108
- const indexes = found.get(head);
109
- if (indexes === undefined) found.set(head, [index]);
110
- else indexes.push(index);
119
+ const labels = new Set([...(head === undefined ? [] : [head]), ...inlineLabelsOf(line)]);
120
+ labels.forEach((label) => {
121
+ const indexes = found.get(label);
122
+ if (indexes === undefined) found.set(label, [index]);
123
+ else indexes.push(index);
124
+ });
111
125
  });
112
126
  return found;
113
127
  };
@@ -112,17 +112,44 @@ const groupsOf = <T>(items: readonly T[], width: number | undefined): T[][] =>
112
112
  /** columnGroups: 見出しを繰り返す表を、並びごとに読む(並びの升には columnGroup が付く)。 */
113
113
  export type TableReading = { readonly columnGroups?: boolean };
114
114
 
115
- type RowReading = { readonly values: readonly FactValue[]; readonly source: string; readonly totals?: TotalColumns; readonly counts?: CountLabelWords };
115
+ /** repeated: 並びの中で二つ以上の行に書いた行の見出し(groupLabelKey)。 */
116
+ type RowReading = {
117
+ readonly values: readonly FactValue[];
118
+ readonly source: string;
119
+ readonly repeated: ReadonlySet<string>;
120
+ readonly totals?: TotalColumns;
121
+ readonly counts?: CountLabelWords;
122
+ };
116
123
 
117
124
  /** 一つの行の升の値。見出しを繰り返す表(width がある)は、並びごとに読んで columnGroup を付ける。 */
118
125
  const groupedRowFacts = (row: Line, headings: readonly string[], width: number | undefined, at: RowReading): TableFact[] => {
119
126
  const headingGroups = groupsOf(headings, width);
120
127
  return groupsOf(cellsOf(row), width).flatMap((cells, group) => {
121
- const facts = rowFacts(cells, headingGroups[group] ?? [], at.values, at.source, at.totals, at.counts);
128
+ const read = rowFacts(cells, headingGroups[group] ?? [], at.values, at.source, at.totals, at.counts);
129
+ const facts = at.repeated.has(groupLabelKey(cells, group)) ? read.map((fact) => withRowCells(fact, cells)) : read;
122
130
  return width === undefined ? facts : facts.map((fact) => ({ ...fact, columnGroup: group }));
123
131
  });
124
132
  };
125
133
 
134
+ const groupLabelKey = (cells: readonly Cell[], group: number): string => `${String(group)}\u0000${keyOf(plain(cells[0]?.text ?? ""))}`;
135
+
136
+ /** 一つの表の並びごとに、二つ以上の行に書いた行の見出し。 */
137
+ const repeatedRowLabels = (rows: readonly Line[], width: number | undefined): ReadonlySet<string> => {
138
+ const keys = rows.flatMap((row) =>
139
+ groupsOf(cellsOf(row), width).flatMap((cells, group) => (plain(cells[0]?.text ?? "") === "" ? [] : [groupLabelKey(cells, group)])),
140
+ );
141
+ return new Set(keys.filter((key, index) => keys.indexOf(key) !== index));
142
+ };
143
+
144
+ /**
145
+ * 同じ見出しの行が二つある表の升は、ほかの升(行の見出しと自分の升を除く)も名前に入れる。状態や条件の列が違う二つの行
146
+ * (Enabled with at least 1 と at least 2)は別の行で、値の違いは食い違いではない。ほかの升がすべて同じ行どうしだけを比べる。
147
+ */
148
+ const withRowCells = (fact: TableFact, cells: readonly Cell[]): TableFact => {
149
+ const others = cells.slice(1).filter((cell) => !inside(cell, fact.value));
150
+ return { ...fact, key: [fact.key, ...others.map((cell) => keyOf(plain(cell.text)))].join("\u0000") };
151
+ };
152
+
126
153
  /** 文書の表すべての升の値。 */
127
154
  export const tableFacts = (
128
155
  source: string,
@@ -134,7 +161,8 @@ export const tableFacts = (
134
161
  tablesOf(linesOf(source)).flatMap((table) => {
135
162
  const headings = cellsOf(table.header).map((cell) => plain(cell.text));
136
163
  const width = reading.columnGroups === true ? columnGroupWidth(headings) : undefined;
137
- const at: RowReading = { values, source, ...(totals === undefined ? {} : { totals }), ...(counts === undefined ? {} : { counts }) };
164
+ const repeated = repeatedRowLabels(table.rows, width);
165
+ const at: RowReading = { values, source, repeated, ...(totals === undefined ? {} : { totals }), ...(counts === undefined ? {} : { counts }) };
138
166
  return table.rows.flatMap((row) => groupedRowFacts(row, headings, width, at));
139
167
  });
140
168
 
@@ -0,0 +1,28 @@
1
+ import type { MarkupHeading, Span } from "./plugin.ts";
2
+ import { escapeRegExp } from "./orthography.ts";
3
+
4
+ // Where a document quotes one of its own headings within a line of other words: an article citing itself
5
+ // (常川真央. Machine-actionable DMPs(maDMPs)の動向. カレントアウェアネス.).
6
+
7
+ /** A heading shorter than this is a word or two (概要, (1)), which the text repeats as a word, not as a quoted title. */
8
+ const MIN_TITLE_LENGTH = 8;
9
+
10
+ /** A line's list marker: a line that holds only one and the heading is a table of contents' entry. */
11
+ const LIST_MARKER = /^(?:[-*+]|\d+\.) /u;
12
+
13
+ const lineAround = (source: string, start: number, end: number): string =>
14
+ source.slice(source.lastIndexOf("\n", start - 1) + 1, source.indexOf("\n", end) === -1 ? source.length : source.indexOf("\n", end));
15
+
16
+ /**
17
+ * The places in `source`, outside the heading itself and outside a line that is only the heading (a table of contents),
18
+ * where the text repeats a heading of MIN_TITLE_LENGTH or more that holds one of `marks`.
19
+ */
20
+ export const ownTitleQuoteSpans = (source: string, headings: readonly MarkupHeading[], marks: ReadonlySet<string>): Span[] =>
21
+ headings
22
+ .filter((heading) => heading.text.length >= MIN_TITLE_LENGTH && heading.text.split("").some((char) => marks.has(char)))
23
+ .flatMap((heading) =>
24
+ [...source.matchAll(new RegExp(escapeRegExp(heading.text), "gu"))]
25
+ .map((match) => ({ start: match.index, end: match.index + heading.text.length }))
26
+ .filter((span) => span.start < heading.start || span.start >= heading.end)
27
+ .filter((span) => lineAround(source, span.start, span.end).trim().replace(LIST_MARKER, "").trim() !== heading.text),
28
+ );
@@ -19,6 +19,16 @@ const FUSED_HEADING = /^[ \t\u3000]*[0-90-9①-⑳]{1,3}【[^】\n]+】[ \t\
19
19
  /** 段落の本文が、番号付きの見出しから改行なしで始まる。段落の切れ目が失われた文書で、長さを測っても書き手の段落ではない。 */
20
20
  export const opensWithFusedHeading = (text: string): boolean => FUSED_HEADING.test(text);
21
21
 
22
+ /** A sentence end glued to the next sentence with no space ("speculate about it.Judge the claim"): a line break lost in copying. The next word ends in a space or a mark other than a period: "Cong.Rec." is an abbreviation. */
23
+ const GLUED_SENTENCES = /(?<=\p{Ll}\p{Ll})[.!?](?=\p{Lu}\p{Ll}+[\s,;:])/gu;
24
+
25
+ /** One glued pair is a typo; two or more mean the block's line breaks were lost, so its sentences were not one paragraph. */
26
+ const MIN_GLUED = 2;
27
+
28
+ /** 文の終わりと次の文の頭が空白なしでつながる所が二つ以上ある。改行が落ちた塊で、長さを測っても書き手の段落ではない。 */
29
+ export const lostLineBreaks = (sentences: readonly { readonly text: string }[]): boolean =>
30
+ sentences.reduce((count, sentence) => count + [...sentence.text.matchAll(GLUED_SENTENCES)].length, 0) >= MIN_GLUED;
31
+
22
32
  /** 【】のラベルだけの文(【0001】【技術分野】)。見出しで、文に数えない。 */
23
33
  const LABELS_ONLY = /^\s*(?:【[^】\n]+】\s*)+$/u;
24
34
 
package/src/plugin.ts CHANGED
@@ -77,6 +77,8 @@ export type LexiconEntry = {
77
77
  readonly genres?: readonly string[] | undefined;
78
78
  /** The entry counts only in a heading: a title phrase that body text uses plainly. A detector that reads headings honours it. */
79
79
  readonly heading_only?: boolean | undefined;
80
+ /** The entry counts only where it opens the sentence (近年、… but not その後、近年の…). phrase-match honours it. */
81
+ readonly opens?: boolean | undefined;
80
82
  /** pattern を adapter が語に分けたもの。品詞が読めるときだけ core が入れる。語彙表を書く側は書かない。 */
81
83
  readonly tokens?: readonly Token[] | undefined;
82
84
  };
@@ -6,6 +6,7 @@ import type { BulletList } from "./plugin.ts";
6
6
  * 箇条書きが少ないと、1 つで割合が大きく動く(4 つなら 25 ポイント)。そのときは全部が 3 項目のときだけ報告する。
7
7
  * 2 つでも測る。生成文の報告書は「要因 3 つ」「提言 3 つ」の 2 つの箇条書きで終わることが多く、人の文書で 2 つとも 3 項目は少ない。
8
8
  * 本文の最初の文より前の箇条書き(題・日付・見出しのすぐ下の要点や概要)は数えない。項目の数はサイトの型が決めている。
9
+ * どの項目も「札:数」の内訳も、ちょうど 3 項目とは数えない。
9
10
  */
10
11
  export type ThreeShare = { readonly count: number; readonly total: number; readonly share: number; readonly first: BulletList };
11
12
 
@@ -48,8 +49,33 @@ const isProseLine = (line: string): boolean => !NOT_PROSE_LINE.test(line) && SEN
48
49
  /** 本文の最初の文がある行の頭。それより前は題・日付・見出しだけ。文が無ければ文書の終わり。 */
49
50
  export const firstProseOffset = (source: string): number => [...source.matchAll(/^.*$/gmu)].find(([line]) => isProseLine(line))?.index ?? source.length;
50
51
 
52
+ const ITEM_MARKER = /^\s*(?:[-*+]|\d+[.)])\s+/u;
53
+ const LABEL_COLON = /[::]/u;
54
+ const DIGIT = /[0-90-9]/u;
55
+ const EMPHASIS = /[*_]/u;
56
+ /** 札と値の長さの上限。「執務エリアの通路沿い」「大きめを2鉢」は入り、文になった値は入らない。 */
57
+ const MAX_LABEL = 20;
58
+ const MAX_VALUE = 12;
59
+
60
+ /** 太字でない短い札とコロン、その後ろに数字を含む短い値だけがある項目(「受付:大きめを2鉢」「Rent: $1,200」)。 */
61
+ const isLabelledFigure = (item: string): boolean => {
62
+ const line = item.replace(ITEM_MARKER, "").split("\n")[0] ?? "";
63
+ const colon = line.search(LABEL_COLON);
64
+ const label = line.slice(0, colon);
65
+ const value = line.slice(colon + 1).trim();
66
+ return colon > 0 && label.length <= MAX_LABEL && !EMPHASIS.test(label) && value.length <= MAX_VALUE && DIGIT.test(value);
67
+ };
68
+
69
+ /**
70
+ * どの項目も「札:数」の箇条書き(置き場所ごとの鉢の数、費目ごとの金額)。数の内訳で、項目の数は中身が決めている。
71
+ * 札の側だけに数がある日程(「2026年12月:承認」)は内訳ではない。太字の札や、値が文になった項目(「**件数**:月平均 420 件届く」)は、
72
+ * 生成文が理由を 3 つに揃える形なので内訳と読まない。
73
+ */
74
+ export const isFigureBreakdown = (source: string, list: BulletList): boolean =>
75
+ list.itemSpans.length > 0 && list.itemSpans.every((item) => isLabelledFigure(source.slice(item.start, item.end)));
76
+
51
77
  const isExactlyThree = (source: string, list: BulletList, openWords: readonly string[]): boolean =>
52
- list.items.length === THREE && !continuesBeyond(source, list, openWords);
78
+ list.items.length === THREE && !continuesBeyond(source, list, openWords) && !isFigureBreakdown(source, list);
53
79
 
54
80
  /** 報告するときの数。報告しないときは undefined。 */
55
81
  export const threeShare = (source: string, allLists: readonly BulletList[], openWords: readonly string[], limit: number): ThreeShare | undefined => {
@@ -3,6 +3,7 @@ import { atxHeadingText, headingText } from "../heading-text.ts";
3
3
  import { addressSpans } from "../address-chain.ts";
4
4
  import { relativeMentions, substitutedDocuments } from "./relative-find.ts";
5
5
  import { resolveRelative } from "./relative-resolve.ts";
6
+ import { resolveOwnNames } from "./own-name.ts";
6
7
  import { maskSpans } from "../mask.ts";
7
8
  import type { DocumentProfile, Mention, NumberedLine, NumberingContext, Span, StructureKind, StructureNode, StructurePatterns } from "../plugin.ts";
8
9
  import { lineNumberAt, linesOf, type Line } from "./lines.ts";
@@ -398,7 +399,7 @@ export const buildTree = (input: StructureInput, patterns: StructurePatterns): S
398
399
  // コードの行は覆って読まないが、開いている節の中身ではある。節の最後にコードブロックがあっても、範囲をそこまで伸ばす。
399
400
  else if (input.source.slice(line.start, line.start + line.text.length).trim() !== "") extend(state, line.start + line.text.length);
400
401
  });
401
- const tree = freeze(doc);
402
+ const tree = resolveOwnNames(freeze(doc), input.source);
402
403
  const relative = input.profile?.relative;
403
404
  return relative === undefined ? tree : resolveRelative(tree, relative.implicitFirst);
404
405
  };
@@ -61,13 +61,16 @@ const SINGLE_KANJI = /^\p{Script=Han}$/u;
61
61
  /** loose は最初の一字の大小を問わない(文頭の "Personal data")。exact は書いたとおりだけ("Access" は "early access" に当たらない)。 */
62
62
  type CaseMatch = "loose" | "exact";
63
63
 
64
+ /** 語の間の空白は、続いた空白や改行でもよい(Normal Business\nHours、桁を揃えた写しの Normal Business Hours)。 */
65
+ const spacedLoosely = (escaped: string): string => escaped.replace(/ +/gu, String.raw`\s+`);
66
+
64
67
  /**
65
68
  * 語の現れを探す形。英字で始まる・終わる語は語の途中に当たらない("Term" は "Terms" には当たり、"Termination" には当たらない)。
66
69
  * 複数形と所有の形(Services、Policies、Seller's)は同じ語の使用。
67
70
  */
68
71
  const termPattern = (term: string, caseMatch: CaseMatch): RegExp => {
69
72
  const first = term.charAt(0);
70
- const rest = /\p{Ll}y$/u.test(term) ? `${escapeRegExp(term.slice(1, -1))}(?:y|ie)` : escapeRegExp(term.slice(1));
73
+ const rest = spacedLoosely(/\p{Ll}y$/u.test(term) ? `${escapeRegExp(term.slice(1, -1))}(?:y|ie)` : escapeRegExp(term.slice(1)));
71
74
  const caseless = caseMatch === "exact" || first.toUpperCase() === first.toLowerCase();
72
75
  const head = caseless ? escapeRegExp(first) : `[${escapeRegExp(first.toUpperCase())}${escapeRegExp(first.toLowerCase())}]`;
73
76
  if (SINGLE_KANJI.test(term)) return new RegExp(String.raw`(?<!\p{Script=Han})${head}`, "gu");
@@ -13,7 +13,7 @@ export const NEGATED = "¬";
13
13
  export const negationWords = (lexicon: Lexicon | undefined): ReadonlySet<string> =>
14
14
  new Set((lexicon ?? []).filter((entry) => entry.group === undefined).map((entry) => entry.pattern.toLowerCase()));
15
15
 
16
- const isNegation = (token: Token, words: ReadonlySet<string>): boolean =>
16
+ export const isNegation = (token: Token, words: ReadonlySet<string>): boolean =>
17
17
  words.has(token.surface.toLowerCase()) || (token.lemma !== undefined && words.has(token.lemma.toLowerCase()));
18
18
 
19
19
  export const isMarkedNegation = (token: Token): boolean => token.features?.[NEGATION_FEATURE] !== undefined;
@@ -0,0 +1,28 @@
1
+ import type { StructureNode } from "../plugin.ts";
2
+ import { foldPostOrder } from "../tree-walk.ts";
3
+
4
+ // A reference named with a longer form of the document's own name (本共同研究開発契約第6条 where 本契約 is the document's
5
+ // short own name) points into another document only when the document calls itself by the short form; otherwise the
6
+ // longer form is the document's own name (本利用規約 with no 本規約) and the reference stays in it. The language package
7
+ // marks such a reference with document and ownName; this pass decides, over the whole text. Pure.
8
+
9
+ const resolvedAttrs = (attrs: StructureNode["attrs"], ownName: string, source: string): StructureNode["attrs"] => {
10
+ const elsewhere = source.includes(ownName);
11
+ return Object.fromEntries(Object.entries(attrs).filter(([key]) => key !== "ownName" && (elsewhere || key !== "document")));
12
+ };
13
+
14
+ /** One node rebuilt over its resolved children; a node whose children did not change and that holds no marker is kept as it was. */
15
+ const resolved = (node: StructureNode, children: readonly StructureNode[], source: string): StructureNode => {
16
+ const ownName = node.attrs["ownName"];
17
+ const same = children.every((child, index) => child === node.children[index]);
18
+ if (typeof ownName !== "string") return same ? node : { ...node, children };
19
+ return { ...node, attrs: resolvedAttrs(node.attrs, ownName, source), children };
20
+ };
21
+
22
+ /** The tree with each ownName-marked reference kept in another document or brought back into this one. Read without recursion: a tree may be thousands of levels deep. */
23
+ export const resolveOwnNames = (tree: StructureNode, source: string): StructureNode =>
24
+ foldPostOrder<StructureNode, StructureNode>(
25
+ tree,
26
+ (node) => node.children,
27
+ (node, children) => resolved(node, children, source),
28
+ );
@@ -77,11 +77,22 @@ const namesRest = (source: string, sentence: Span, shares: readonly Amount[], wo
77
77
  });
78
78
  };
79
79
 
80
+ /** Whether only a joiner stands between two percentages ("from 51% to 53%", 「50%〜60%」): one share at two values. */
81
+ const joinedTo = (source: string, earlier: Amount, later: Amount, joiners: readonly string[]): boolean => {
82
+ const written = source.slice(earlier.end, later.offset);
83
+ const between = (written.startsWith(earlier.unit) ? written.slice(earlier.unit.length) : written).trim().toLowerCase();
84
+ return joiners.some((joiner) => joiner.toLowerCase() === between);
85
+ };
86
+
87
+ /** Two shares joined into a range or a change: which of the two values is the part cannot be told, so the sentence is not added. */
88
+ const holdsJoinedPair = (source: string, shares: readonly Amount[], joiners: readonly string[]): boolean =>
89
+ shares.some((share, index) => index > 0 && joinedTo(source, shares[index - 1] ?? share, share, joiners));
90
+
80
91
  const issueIn = (source: string, sentence: Span, percents: readonly Amount[], words: ShareWords): StructureIssue[] => {
81
92
  const text = source.slice(sentence.start, sentence.end);
82
93
  if (includesAny(text, words.exceptions)) return [];
83
94
  const shares = percents.filter((amount) => amount.offset >= sentence.start && amount.end <= sentence.end);
84
- if (shares.length < MIN_PARTS || shares.some((share) => isSigned(source, share))) return [];
95
+ if (shares.length < MIN_PARTS || shares.some((share) => isSigned(source, share)) || holdsJoinedPair(source, shares, words.joiners ?? [])) return [];
85
96
  if (!includesAny(text, words.labels) && !namesRest(source, sentence, shares, words)) return [];
86
97
  const sum = shares.reduce((total, share) => total + share.value, 0);
87
98
  const decimals = Math.max(0, ...shares.map((share) => decimalsOf(source, share)));
@@ -24,6 +24,8 @@ export type ShareWords = {
24
24
  readonly rests?: readonly string[];
25
25
  /** 値の動いた向きの語(伸び、grew)。その文の百分率は変化で、「その他」があっても内訳ではない。 */
26
26
  readonly changes?: readonly string[];
27
+ /** 二つの値を一つの範囲や変化につなぐ語と印(to, 〜)。つないだ二つの百分率は一つの割合の二つの値で、どちらが内訳の部分かは言えない。 */
28
+ readonly joiners?: readonly string[];
27
29
  readonly units: readonly string[];
28
30
  readonly totalLabels: readonly string[];
29
31
  };
@@ -116,9 +116,13 @@ const EN_TOPIC = /^(?:the |a |an )?([a-z][a-z-]{2,}(?: [a-z][a-z-]{2,}){0,2})/iu
116
116
  const STEM = 5;
117
117
  const LATIN_TOPIC = /^[a-z -]+$/iu;
118
118
 
119
+ /** The link starts the text as a whole word: "for" in "for pricing", not in "formulate". */
120
+ const startsWithLink = (text: string, link: string): boolean =>
121
+ text.toLowerCase().startsWith(link.toLowerCase()) && !(LATIN_TOPIC.test(link) && LETTER.test(text.charAt(link.length)));
122
+
119
123
  const topicAfter = (source: string, end: number, links: readonly string[]): string | undefined => {
120
124
  const after = source.slice(end, end + 60);
121
- const link = links.find((candidate) => after.replace(SPACE_BEFORE, "").toLowerCase().startsWith(candidate.toLowerCase()));
125
+ const link = links.find((candidate) => startsWithLink(after.replace(SPACE_BEFORE, ""), candidate));
122
126
  if (link === undefined) return undefined;
123
127
  const rest = after.replace(SPACE_BEFORE, "").slice(link.length).replace(SPACE_BEFORE, "");
124
128
  return JA_TOPIC.exec(rest)?.[0] ?? EN_TOPIC.exec(rest)?.[1];
@@ -1,7 +1,7 @@
1
1
  import { lengthOf } from "../measure.ts";
2
2
  import type { Lexicon, ProseDocument, Section, Sentence } from "../plugin.ts";
3
3
  import { coefficientOfVariation } from "../detectors/structure.ts";
4
- import { boldLabelItems } from "../detectors/bold-label.ts";
4
+ import { boldLabelItems, isQuotedAt, standingBoldLabelOf } from "../detectors/bold-label.ts";
5
5
  import { MIN_DOCUMENT_LENGTH } from "../detectors/signals.ts";
6
6
  import { bookendOf, headingFormOf, headingWords, proConPairs } from "./heading-words.ts";
7
7
  import { restatementPercent } from "./restatement.ts";
@@ -165,9 +165,25 @@ const threeItemLists = (doc: ProseDocument): FeatureValue => {
165
165
  const emojiHeadings = (doc: ProseDocument): FeatureValue =>
166
166
  measured("emoji-headings", doc.sections.filter((section) => section.depth > 0 && EMOJI.test(section.heading)).length);
167
167
 
168
+ /** The paragraphs and list items, as written, that are not quoted: where a bold label can stand in place of a heading. */
169
+ const blocksOf = (doc: ProseDocument): string[] =>
170
+ [...doc.paragraphs.map((paragraph) => paragraph.span), ...doc.lists.flatMap((list) => list.itemSpans)]
171
+ .filter((span) => !isQuotedAt(doc.source, span.start))
172
+ .map((span) => doc.source.slice(span.start, span.end));
173
+
174
+ /** Bold labels that are a side of a pair and nothing more (`**Pros:**`, `**デメリット:**`): a heading set in bold. */
175
+ const proConLabels = (doc: ProseDocument, lexicon: Lexicon): string[] => {
176
+ const sides = new Set(lexicon.flatMap((entry) => [entry.pattern, entry.instead_of ?? ""]).map((side) => side.toLowerCase()));
177
+ return blocksOf(doc).flatMap((block) => {
178
+ const label = standingBoldLabelOf(block);
179
+ return label !== undefined && sides.has(headingWords(label)) ? [headingWords(label)] : [];
180
+ });
181
+ };
182
+
168
183
  const proCon = (doc: ProseDocument, words: readonly string[]): FeatureValue => {
169
184
  if (words.length < MIN_BOOKEND_HEADINGS) return notMeasured("pro-con", "too-few-headings");
170
- const pairs = proConPairs(words, lexiconOf(doc, "pro-con-heading"));
185
+ const lexicon = lexiconOf(doc, "pro-con-heading");
186
+ const pairs = proConPairs([...words, ...proConLabels(doc, lexicon)], lexicon);
171
187
  return measured("pro-con", pairs.length, pairs.join(", "));
172
188
  };
173
189
 
@@ -0,0 +1,52 @@
1
+ import type { Token } from "./plugin.ts";
2
+ import { isHelperByTeFormOnly, teFormVerbOf, type InContext } from "./word-use.ts";
3
+
4
+ // orthographic-variant: a kanji verb after a て-form is the helper (書いて見る) or the next act (並んで見た), and the form alone
5
+ // cannot tell. These decide which, from the document's own spellings.
6
+
7
+ /** Where a word stands after a て-form. */
8
+ export type TeForm = {
9
+ /** A full verb read as a helper only for the て-form before it, whose verb takes no object (並んで見た). */
10
+ readonly teFormOnly?: boolean;
11
+ /** The verb whose て-form stands before it (まとめる in まとめてみる). */
12
+ readonly teVerb?: string;
13
+ };
14
+
15
+ type KeyedTeWord = TeForm & { readonly key: string; readonly spelling: string };
16
+
17
+ const OBJECT_PARTICLE = "を";
18
+
19
+ /** The て-form verb takes an object (芽を残して置く): the verb after it has none of its own, and is the helper. */
20
+ const teVerbHasObject = (word: InContext, tokens: readonly Token[], at: number): boolean => {
21
+ const teVerbAt = word.previous?.pos === "SCONJ" ? at - 2 : at - 1;
22
+ const particle = tokens[teVerbAt - 1];
23
+ return particle?.pos === "ADP" && particle.surface === OBJECT_PARTICLE;
24
+ };
25
+
26
+ export const teFormOf = (word: InContext, tokens: readonly Token[], at: number): TeForm => {
27
+ const teVerb = teFormVerbOf(word);
28
+ const doubtful = isHelperByTeFormOnly(word) && !teVerbHasObject(word, tokens, at);
29
+ return { ...(doubtful ? { teFormOnly: true } : {}), ...(teVerb === undefined ? {} : { teVerb }) };
30
+ };
31
+
32
+ const BOUND_USE = "|bound|";
33
+ const FREE_USE = "|free|";
34
+
35
+ /**
36
+ * A verb after a て-form that may be the helper or the next act (並んで見た) is read as the full verb where the document writes
37
+ * the full verb that way and its sure helpers (投資してみる) the other way: the writer keeps the helper in kana on purpose. It stays
38
+ * a helper where the same verb takes the sure helper elsewhere (まとめてみました beside まとめて見ました).
39
+ */
40
+ export const withTeFormFullVerbs = <Word extends KeyedTeWord>(words: readonly Word[]): Word[] => {
41
+ const sureOf = (key: string): Word[] => words.filter((word) => word.key === key && word.teFormOnly !== true);
42
+ const freeSpellingsOf = (key: string): Set<string> => new Set(words.filter((word) => word.key === key).map((word) => word.spelling));
43
+ return words.map((word) => {
44
+ if (word.teFormOnly !== true || !word.key.includes(BOUND_USE)) return word;
45
+ const freeKey = word.key.replace(BOUND_USE, FREE_USE);
46
+ const sure = sureOf(word.key);
47
+ const sureSpellings = new Set(sure.map((helper) => helper.spelling));
48
+ const helpsSameVerb = sure.some((helper) => helper.teVerb !== undefined && helper.teVerb === word.teVerb);
49
+ const isFullVerbSpelling = freeSpellingsOf(freeKey).has(word.spelling) && sure.length > 0 && !sureSpellings.has(word.spelling) && !helpsSameVerb;
50
+ return isFullVerbSpelling ? { ...word, key: freeKey } : word;
51
+ });
52
+ };
package/src/word-use.ts CHANGED
@@ -35,6 +35,19 @@ const negatesAfterTopic = ({ token, previous, before }: InContext): boolean =>
35
35
 
36
36
  const isHelper = (word: InContext): boolean => word.token.features?.["Bound"] === "Yes" || followsTeForm(word.previous) || negatesAfterTopic(word);
37
37
 
38
+ /**
39
+ * A verb the tokenizer reads as a full verb, taken for a helper only because a て-form stands before it: 見た in 並んで見た is
40
+ * the next act, 見る in 書いて見る a helper, and the form cannot tell them apart.
41
+ */
42
+ export const isHelperByTeFormOnly = (word: InContext): boolean =>
43
+ word.token.pos === "VERB" && word.token.features?.["Bound"] !== "Yes" && followsTeForm(word.previous);
44
+
45
+ /** The verb whose て-form stands before the word (まとめる in まとめてみる), or undefined after no て-form. */
46
+ export const teFormVerbOf = ({ previous, before }: InContext): string | undefined => {
47
+ if (!followsTeForm(previous)) return undefined;
48
+ return (previous?.pos === "SCONJ" ? before : previous)?.lemma;
49
+ };
50
+
38
51
  export const isTouching = (left: Token | undefined, right: Token): boolean => left !== undefined && left.span.end === right.span.start;
39
52
 
40
53
  export const HIRAGANA_ONLY = /^[ぁ-ゖー]+$/u;
@@ -140,9 +153,18 @@ const isCompoundVerbHead = ({ token, following }: InContext): boolean => {
140
153
  /** A verb written straight onto the verb before it (貼り付ける, 書き込む): the tail of a compound verb, not the verb alone (番号をつける). */
141
154
  const isCompoundVerbTail = ({ token, previous }: InContext): boolean => token.pos === "VERB" && previous?.pos === "VERB" && isTouching(previous, token);
142
155
 
156
+ /**
157
+ * A noun joined by や or と to a noun after it (物やサービス): it names a thing alongside the other, as the full noun does, even
158
+ * where the tokenizer reads it as the dependent noun (延長するもの).
159
+ */
160
+ const isCoordinatedThing = ({ token, following }: InContext): boolean => {
161
+ const [joiner, partner] = following ?? [];
162
+ return token.pos === "NOUN" && joiner?.pos === "CCONJ" && partner?.pos === "NOUN" && partner.features?.["NounType"] !== "Dependent";
163
+ };
164
+
143
165
  /** A word used freely, or as a helper: a bound noun after a word is a suffix, and anything else bound a helper. */
144
166
  const helperUseOf = (word: InContext, lightVerbs: ReadonlySet<string>): string => {
145
- if (!isHelper(word) && !isLightVerbAfterQuotative(word, lightVerbs)) return "free";
167
+ if ((!isHelper(word) && !isLightVerbAfterQuotative(word, lightVerbs)) || isCoordinatedThing(word)) return "free";
146
168
  return word.token.pos === "NOUN" && word.token.features?.["NounType"] !== "Dependent" ? "suffix" : "bound";
147
169
  };
148
170
 
@@ -1,22 +0,0 @@
1
- import type { Token } from "./plugin.ts";
2
-
3
- const touches = (left: Token | undefined, right: Token | undefined): boolean => left !== undefined && right !== undefined && left.span.end === right.span.start;
4
-
5
- /**
6
- * 人の集まりを敬って呼ぶ語(皆様、方々)の直前の助詞で、呼び方がさらに同じ助詞で次の語に係るもの。「国民の皆様の期待」の
7
- * 「国民の皆様」は一つの呼び方として次の語に係り、その中の「の」は入れ子を深くしない。呼び方で連なりが終わるとき
8
- * (それ以外の全てのVim使いの皆様が)は、呼び方が連なりの頭の語なので数える。particles は数える助詞(の)、groups は呼び方の語(皆様)。
9
- */
10
- export const honorificGroupParticles = (tokens: readonly Token[], particles: readonly string[], groups: readonly string[]): ReadonlySet<Token> =>
11
- new Set(
12
- tokens.filter((token, at) => {
13
- const [group, after] = [tokens[at + 1], tokens[at + 2]];
14
- return (
15
- particles.includes(token.surface) &&
16
- groups.includes(group?.surface ?? "") &&
17
- touches(token, group) &&
18
- touches(group, after) &&
19
- particles.includes(after?.surface ?? "")
20
- );
21
- }),
22
- );