chaffjs 0.39.0 → 0.40.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 (321) hide show
  1. package/README.ja.md +3 -2
  2. package/README.md +2 -1
  3. package/dist/ai-score/human-shares.d.ts.map +1 -1
  4. package/dist/ai-score/human-shares.js +1 -0
  5. package/dist/ai-score/human-shares.js.map +1 -1
  6. package/dist/alternative-words.d.ts +6 -0
  7. package/dist/alternative-words.d.ts.map +1 -1
  8. package/dist/alternative-words.js +10 -0
  9. package/dist/alternative-words.js.map +1 -1
  10. package/dist/closing-code.d.ts +8 -0
  11. package/dist/closing-code.d.ts.map +1 -0
  12. package/dist/closing-code.js +18 -0
  13. package/dist/closing-code.js.map +1 -0
  14. package/dist/date-format.d.ts +19 -1
  15. package/dist/date-format.d.ts.map +1 -1
  16. package/dist/date-format.js +41 -5
  17. package/dist/date-format.js.map +1 -1
  18. package/dist/detectors/acronym-context.d.ts +1 -1
  19. package/dist/detectors/acronym-context.d.ts.map +1 -1
  20. package/dist/detectors/acronym-context.js +3 -2
  21. package/dist/detectors/acronym-context.js.map +1 -1
  22. package/dist/detectors/acronym-mention.d.ts +5 -0
  23. package/dist/detectors/acronym-mention.d.ts.map +1 -1
  24. package/dist/detectors/acronym-mention.js +16 -0
  25. package/dist/detectors/acronym-mention.js.map +1 -1
  26. package/dist/detectors/acronym-name.d.ts +5 -0
  27. package/dist/detectors/acronym-name.d.ts.map +1 -1
  28. package/dist/detectors/acronym-name.js +15 -0
  29. package/dist/detectors/acronym-name.js.map +1 -1
  30. package/dist/detectors/blank-runs.d.ts +12 -0
  31. package/dist/detectors/blank-runs.d.ts.map +1 -0
  32. package/dist/detectors/blank-runs.js +27 -0
  33. package/dist/detectors/blank-runs.js.map +1 -0
  34. package/dist/detectors/bold-label.d.ts +3 -1
  35. package/dist/detectors/bold-label.d.ts.map +1 -1
  36. package/dist/detectors/bold-label.js +16 -6
  37. package/dist/detectors/bold-label.js.map +1 -1
  38. package/dist/detectors/capitalised-term.d.ts.map +1 -1
  39. package/dist/detectors/capitalised-term.js +28 -9
  40. package/dist/detectors/capitalised-term.js.map +1 -1
  41. package/dist/detectors/citation-string.d.ts +6 -0
  42. package/dist/detectors/citation-string.d.ts.map +1 -1
  43. package/dist/detectors/citation-string.js +52 -0
  44. package/dist/detectors/citation-string.js.map +1 -1
  45. package/dist/detectors/contraction-emphasis.d.ts +3 -0
  46. package/dist/detectors/contraction-emphasis.d.ts.map +1 -0
  47. package/dist/detectors/contraction-emphasis.js +24 -0
  48. package/dist/detectors/contraction-emphasis.js.map +1 -0
  49. package/dist/detectors/contraction-mention.d.ts +12 -1
  50. package/dist/detectors/contraction-mention.d.ts.map +1 -1
  51. package/dist/detectors/contraction-mention.js +39 -6
  52. package/dist/detectors/contraction-mention.js.map +1 -1
  53. package/dist/detectors/contraction-mix.d.ts +3 -0
  54. package/dist/detectors/contraction-mix.d.ts.map +1 -0
  55. package/dist/detectors/contraction-mix.js +69 -0
  56. package/dist/detectors/contraction-mix.js.map +1 -0
  57. package/dist/detectors/date-format.d.ts.map +1 -1
  58. package/dist/detectors/date-format.js +13 -1
  59. package/dist/detectors/date-format.js.map +1 -1
  60. package/dist/detectors/duplicate-definition.d.ts +3 -0
  61. package/dist/detectors/duplicate-definition.d.ts.map +1 -0
  62. package/dist/detectors/duplicate-definition.js +16 -0
  63. package/dist/detectors/duplicate-definition.js.map +1 -0
  64. package/dist/detectors/final-period-captions.d.ts +15 -0
  65. package/dist/detectors/final-period-captions.d.ts.map +1 -0
  66. package/dist/detectors/final-period-captions.js +61 -0
  67. package/dist/detectors/final-period-captions.js.map +1 -0
  68. package/dist/detectors/heading-sentences.d.ts +10 -0
  69. package/dist/detectors/heading-sentences.d.ts.map +1 -0
  70. package/dist/detectors/heading-sentences.js +32 -0
  71. package/dist/detectors/heading-sentences.js.map +1 -0
  72. package/dist/detectors/lexicon.d.ts +1 -2
  73. package/dist/detectors/lexicon.d.ts.map +1 -1
  74. package/dist/detectors/lexicon.js +5 -55
  75. package/dist/detectors/lexicon.js.map +1 -1
  76. package/dist/detectors/list-lead-in.d.ts +1 -1
  77. package/dist/detectors/list-lead-in.d.ts.map +1 -1
  78. package/dist/detectors/list-lead-in.js +31 -10
  79. package/dist/detectors/list-lead-in.js.map +1 -1
  80. package/dist/detectors/missing-final-period.d.ts.map +1 -1
  81. package/dist/detectors/missing-final-period.js +3 -1
  82. package/dist/detectors/missing-final-period.js.map +1 -1
  83. package/dist/detectors/numbering-readings.d.ts +2 -2
  84. package/dist/detectors/numbering-readings.d.ts.map +1 -1
  85. package/dist/detectors/numbering-readings.js +7 -0
  86. package/dist/detectors/numbering-readings.js.map +1 -1
  87. package/dist/detectors/open-end-anaphor.d.ts +8 -0
  88. package/dist/detectors/open-end-anaphor.d.ts.map +1 -0
  89. package/dist/detectors/open-end-anaphor.js +22 -0
  90. package/dist/detectors/open-end-anaphor.js.map +1 -0
  91. package/dist/detectors/open-end-lead.d.ts +4 -0
  92. package/dist/detectors/open-end-lead.d.ts.map +1 -0
  93. package/dist/detectors/open-end-lead.js +34 -0
  94. package/dist/detectors/open-end-lead.js.map +1 -0
  95. package/dist/detectors/open-end-scope.d.ts.map +1 -1
  96. package/dist/detectors/open-end-scope.js +7 -1
  97. package/dist/detectors/open-end-scope.js.map +1 -1
  98. package/dist/detectors/ordinal-run-gaps.d.ts +1 -0
  99. package/dist/detectors/ordinal-run-gaps.d.ts.map +1 -1
  100. package/dist/detectors/ordinal-run-gaps.js +1 -1
  101. package/dist/detectors/ordinal-run-gaps.js.map +1 -1
  102. package/dist/detectors/orthographic-variant-open.d.ts +4 -2
  103. package/dist/detectors/orthographic-variant-open.d.ts.map +1 -1
  104. package/dist/detectors/orthographic-variant-open.js +5 -3
  105. package/dist/detectors/orthographic-variant-open.js.map +1 -1
  106. package/dist/detectors/orthography.d.ts.map +1 -1
  107. package/dist/detectors/orthography.js +14 -5
  108. package/dist/detectors/orthography.js.map +1 -1
  109. package/dist/detectors/placeholder-text.d.ts.map +1 -1
  110. package/dist/detectors/placeholder-text.js +14 -2
  111. package/dist/detectors/placeholder-text.js.map +1 -1
  112. package/dist/detectors/quote-without-source.d.ts +6 -2
  113. package/dist/detectors/quote-without-source.d.ts.map +1 -1
  114. package/dist/detectors/quote-without-source.js +33 -8
  115. package/dist/detectors/quote-without-source.js.map +1 -1
  116. package/dist/detectors/register-separate-part.d.ts +7 -0
  117. package/dist/detectors/register-separate-part.d.ts.map +1 -0
  118. package/dist/detectors/register-separate-part.js +32 -0
  119. package/dist/detectors/register-separate-part.js.map +1 -0
  120. package/dist/detectors/registry/contraction-mix.js +1 -1
  121. package/dist/detectors/registry/contraction-mix.js.map +1 -1
  122. package/dist/detectors/registry/duplicate-definition.js +1 -1
  123. package/dist/detectors/registry/duplicate-definition.js.map +1 -1
  124. package/dist/detectors/reproduced-text.d.ts +5 -0
  125. package/dist/detectors/reproduced-text.d.ts.map +1 -0
  126. package/dist/detectors/reproduced-text.js +19 -0
  127. package/dist/detectors/reproduced-text.js.map +1 -0
  128. package/dist/detectors/request-owner.d.ts +2 -1
  129. package/dist/detectors/request-owner.d.ts.map +1 -1
  130. package/dist/detectors/request-owner.js +31 -7
  131. package/dist/detectors/request-owner.js.map +1 -1
  132. package/dist/detectors/requirement-smell.d.ts.map +1 -1
  133. package/dist/detectors/requirement-smell.js +16 -5
  134. package/dist/detectors/requirement-smell.js.map +1 -1
  135. package/dist/detectors/sentence-counts.d.ts +2 -1
  136. package/dist/detectors/sentence-counts.d.ts.map +1 -1
  137. package/dist/detectors/sentence-counts.js +23 -7
  138. package/dist/detectors/sentence-counts.js.map +1 -1
  139. package/dist/detectors/sentence-ending.d.ts +1 -0
  140. package/dist/detectors/sentence-ending.d.ts.map +1 -1
  141. package/dist/detectors/sentence-ending.js +5 -2
  142. package/dist/detectors/sentence-ending.js.map +1 -1
  143. package/dist/detectors/sentence-length.d.ts.map +1 -1
  144. package/dist/detectors/sentence-length.js +13 -3
  145. package/dist/detectors/sentence-length.js.map +1 -1
  146. package/dist/detectors/sentence-parts.d.ts +2 -0
  147. package/dist/detectors/sentence-parts.d.ts.map +1 -1
  148. package/dist/detectors/sentence-parts.js +3 -1
  149. package/dist/detectors/sentence-parts.js.map +1 -1
  150. package/dist/detectors/signals.d.ts.map +1 -1
  151. package/dist/detectors/signals.js +6 -4
  152. package/dist/detectors/signals.js.map +1 -1
  153. package/dist/detectors/spelling-variety.d.ts.map +1 -1
  154. package/dist/detectors/spelling-variety.js +20 -2
  155. package/dist/detectors/spelling-variety.js.map +1 -1
  156. package/dist/detectors/structure-tree.d.ts +2 -1
  157. package/dist/detectors/structure-tree.d.ts.map +1 -1
  158. package/dist/detectors/structure-tree.js +2 -7
  159. package/dist/detectors/structure-tree.js.map +1 -1
  160. package/dist/detectors/structure.d.ts.map +1 -1
  161. package/dist/detectors/structure.js +19 -5
  162. package/dist/detectors/structure.js.map +1 -1
  163. package/dist/detectors/token-shape.d.ts.map +1 -1
  164. package/dist/detectors/token-shape.js +12 -6
  165. package/dist/detectors/token-shape.js.map +1 -1
  166. package/dist/detectors/undefined-term.d.ts +5 -0
  167. package/dist/detectors/undefined-term.d.ts.map +1 -1
  168. package/dist/detectors/undefined-term.js +22 -1
  169. package/dist/detectors/undefined-term.js.map +1 -1
  170. package/dist/detectors/unfilled-placeholder.d.ts.map +1 -1
  171. package/dist/detectors/unfilled-placeholder.js +15 -1
  172. package/dist/detectors/unfilled-placeholder.js.map +1 -1
  173. package/dist/detectors/unknown-word-context.d.ts +7 -0
  174. package/dist/detectors/unknown-word-context.d.ts.map +1 -1
  175. package/dist/detectors/unknown-word-context.js +11 -0
  176. package/dist/detectors/unknown-word-context.js.map +1 -1
  177. package/dist/detectors/unknown-word.d.ts.map +1 -1
  178. package/dist/detectors/unknown-word.js +5 -4
  179. package/dist/detectors/unknown-word.js.map +1 -1
  180. package/dist/latin-spacing-source.d.ts +12 -0
  181. package/dist/latin-spacing-source.d.ts.map +1 -0
  182. package/dist/latin-spacing-source.js +25 -0
  183. package/dist/latin-spacing-source.js.map +1 -0
  184. package/dist/name-separator.d.ts.map +1 -1
  185. package/dist/name-separator.js +4 -1
  186. package/dist/name-separator.js.map +1 -1
  187. package/dist/paragraph-length.d.ts +14 -0
  188. package/dist/paragraph-length.d.ts.map +1 -1
  189. package/dist/paragraph-length.js +25 -0
  190. package/dist/paragraph-length.js.map +1 -1
  191. package/dist/paragraph-runs.d.ts +2 -2
  192. package/dist/paragraph-runs.d.ts.map +1 -1
  193. package/dist/paragraph-runs.js +65 -14
  194. package/dist/paragraph-runs.js.map +1 -1
  195. package/dist/quote-echo.d.ts +6 -0
  196. package/dist/quote-echo.d.ts.map +1 -0
  197. package/dist/quote-echo.js +14 -0
  198. package/dist/quote-echo.js.map +1 -0
  199. package/dist/semantic.d.ts.map +1 -1
  200. package/dist/semantic.js +2 -2
  201. package/dist/semantic.js.map +1 -1
  202. package/dist/set-phrase-particles.d.ts +4 -0
  203. package/dist/set-phrase-particles.d.ts.map +1 -0
  204. package/dist/set-phrase-particles.js +26 -0
  205. package/dist/set-phrase-particles.js.map +1 -0
  206. package/dist/structure/alternative-clause.d.ts +7 -0
  207. package/dist/structure/alternative-clause.d.ts.map +1 -1
  208. package/dist/structure/alternative-clause.js +23 -8
  209. package/dist/structure/alternative-clause.js.map +1 -1
  210. package/dist/structure/cited-document-section.d.ts +2 -0
  211. package/dist/structure/cited-document-section.d.ts.map +1 -1
  212. package/dist/structure/cited-document-section.js +8 -0
  213. package/dist/structure/cited-document-section.js.map +1 -1
  214. package/dist/structure/issues.d.ts +3 -1
  215. package/dist/structure/issues.d.ts.map +1 -1
  216. package/dist/structure/issues.js +12 -8
  217. package/dist/structure/issues.js.map +1 -1
  218. package/dist/structure/numbering.d.ts +10 -1
  219. package/dist/structure/numbering.d.ts.map +1 -1
  220. package/dist/structure/numbering.js +41 -4
  221. package/dist/structure/numbering.js.map +1 -1
  222. package/dist/structure/unread-label.d.ts +13 -0
  223. package/dist/structure/unread-label.d.ts.map +1 -0
  224. package/dist/structure/unread-label.js +70 -0
  225. package/dist/structure/unread-label.js.map +1 -0
  226. package/dist/topic-clause.d.ts.map +1 -1
  227. package/dist/topic-clause.js +15 -2
  228. package/dist/topic-clause.js.map +1 -1
  229. package/package.json +3 -3
  230. package/rules/ai-generated-composite.yaml +1 -0
  231. package/rules/ai-tell.yaml +6 -2
  232. package/rules/bold-label-list.yaml +6 -6
  233. package/rules/closing-cliche.yaml +2 -2
  234. package/rules/colon-lead-in.yaml +2 -2
  235. package/rules/contraction-consistency.yaml +2 -2
  236. package/rules/date-format-consistency.yaml +2 -2
  237. package/rules/duplicate-definition.yaml +2 -2
  238. package/rules/honesty-marker.yaml +84 -0
  239. package/rules/latin-spacing.yaml +6 -4
  240. package/rules/max-paragraph-length.yaml +2 -2
  241. package/rules/max-sentence-length.yaml +4 -2
  242. package/rules/missing-final-period.yaml +2 -2
  243. package/rules/no-doubled-joshi.yaml +2 -2
  244. package/rules/no-mixed-desumasu.yaml +2 -2
  245. package/rules/nominalization.yaml +1 -1
  246. package/rules/numbering-gap.yaml +2 -2
  247. package/rules/one-sentence-paragraph-run.yaml +2 -2
  248. package/rules/orthographic-variant.yaml +2 -2
  249. package/rules/quote-without-source.yaml +2 -2
  250. package/rules/request-without-deadline.yaml +2 -2
  251. package/rules/requirement-smell.yaml +2 -2
  252. package/rules/spelling-consistency.yaml +4 -4
  253. package/rules/teki-overuse.yaml +2 -2
  254. package/rules/topic-predicate-distance.yaml +2 -2
  255. package/rules/undefined-acronym.yaml +3 -2
  256. package/rules/undefined-term.yaml +2 -2
  257. package/rules/unfilled-placeholder.yaml +2 -2
  258. package/rules/unknown-word.yaml +2 -2
  259. package/skills/chaff/SKILL.md +2 -1
  260. package/src/ai-score/human-shares.ts +1 -0
  261. package/src/alternative-words.ts +15 -0
  262. package/src/closing-code.ts +21 -0
  263. package/src/date-format.ts +54 -7
  264. package/src/detectors/acronym-context.ts +3 -2
  265. package/src/detectors/acronym-mention.ts +17 -0
  266. package/src/detectors/acronym-name.ts +18 -0
  267. package/src/detectors/blank-runs.ts +30 -0
  268. package/src/detectors/bold-label.ts +22 -6
  269. package/src/detectors/capitalised-term.ts +36 -9
  270. package/src/detectors/citation-string.ts +57 -0
  271. package/src/detectors/contraction-emphasis.ts +46 -0
  272. package/src/detectors/contraction-mention.ts +52 -6
  273. package/src/detectors/contraction-mix.ts +94 -0
  274. package/src/detectors/date-format.ts +18 -2
  275. package/src/detectors/duplicate-definition.ts +21 -0
  276. package/src/detectors/final-period-captions.ts +78 -0
  277. package/src/detectors/heading-sentences.ts +36 -0
  278. package/src/detectors/lexicon.ts +5 -61
  279. package/src/detectors/list-lead-in.ts +44 -10
  280. package/src/detectors/missing-final-period.ts +9 -1
  281. package/src/detectors/numbering-readings.ts +10 -2
  282. package/src/detectors/open-end-anaphor.ts +31 -0
  283. package/src/detectors/open-end-lead.ts +46 -0
  284. package/src/detectors/open-end-scope.ts +8 -1
  285. package/src/detectors/ordinal-run-gaps.ts +1 -1
  286. package/src/detectors/orthographic-variant-open.ts +8 -3
  287. package/src/detectors/orthography.ts +20 -7
  288. package/src/detectors/placeholder-text.ts +21 -4
  289. package/src/detectors/quote-without-source.ts +52 -10
  290. package/src/detectors/register-separate-part.ts +42 -0
  291. package/src/detectors/registry/contraction-mix.ts +1 -1
  292. package/src/detectors/registry/duplicate-definition.ts +1 -1
  293. package/src/detectors/reproduced-text.ts +33 -0
  294. package/src/detectors/request-owner.ts +31 -8
  295. package/src/detectors/requirement-smell.ts +21 -5
  296. package/src/detectors/sentence-counts.ts +27 -7
  297. package/src/detectors/sentence-ending.ts +6 -2
  298. package/src/detectors/sentence-length.ts +18 -3
  299. package/src/detectors/sentence-parts.ts +4 -1
  300. package/src/detectors/signals.ts +7 -4
  301. package/src/detectors/spelling-variety.ts +26 -2
  302. package/src/detectors/structure-tree.ts +2 -8
  303. package/src/detectors/structure.ts +22 -6
  304. package/src/detectors/token-shape.ts +16 -6
  305. package/src/detectors/undefined-term.ts +26 -1
  306. package/src/detectors/unfilled-placeholder.ts +20 -2
  307. package/src/detectors/unknown-word-context.ts +17 -0
  308. package/src/detectors/unknown-word.ts +15 -4
  309. package/src/latin-spacing-source.ts +33 -0
  310. package/src/name-separator.ts +4 -1
  311. package/src/paragraph-length.ts +31 -0
  312. package/src/paragraph-runs.ts +71 -13
  313. package/src/quote-echo.ts +18 -0
  314. package/src/semantic.ts +2 -3
  315. package/src/set-phrase-particles.ts +32 -0
  316. package/src/structure/alternative-clause.ts +32 -7
  317. package/src/structure/cited-document-section.ts +8 -0
  318. package/src/structure/issues.ts +19 -9
  319. package/src/structure/numbering.ts +50 -3
  320. package/src/structure/unread-label.ts +74 -0
  321. package/src/topic-clause.ts +16 -2
@@ -7,7 +7,7 @@ import { isExplained } from "./acronym-compound.ts";
7
7
  import { statedAcronyms } from "./acronym-definition.ts";
8
8
  import { isBracketed, isInHeading, isNamePart } from "./acronym-lone.ts";
9
9
  import { linkedListTerms } from "./acronym-link.ts";
10
- import { caseVariantsIn, spelledOutAcronyms } from "./acronym-mention.ts";
10
+ import { caseVariantsIn, spelledOutAcronyms, writtenAsWordIn } from "./acronym-mention.ts";
11
11
  import { conjugatedForms } from "./conjugated-form.ts";
12
12
  import { knownByDocument } from "./acronym-known.ts";
13
13
  import { explainedInText, headingsSpellingOut } from "./acronym-gloss.ts";
@@ -204,12 +204,12 @@ const isNamePartAt = (acronym: string, hit: Hit): boolean => {
204
204
  */
205
205
  export const undefinedAcronym: Detector = (doc, options): Finding[] => {
206
206
  const body = bodyOf(doc);
207
- // HTTP のメソッド名(GET)は略語ではなく、税の名前(VAT、GST)は読み手が名前として知るので、通じる略語と同じく展開を求めない。
207
+ // HTTP のメソッド名(GET)と SQL のキーワード(VIEW)は略語ではなく、税の名前(VAT、GST)は読み手が名前として知るので、通じる略語と同じく展開を求めない。
208
208
  // 並べた名前(JAXA)も、繋いだ略語(JAXA-ISAS)の片割れとして説明済みに数える。
209
209
  // 文書が自分で知らせた語(select を書いた文書の SELECT、リンクで引いた講演の場 [Jane Roe, FOSDEM 2024](…))も同じ。
210
210
  const common = new Set([
211
211
  ...(options.lexicon ?? []).map((entry) => entry.pattern),
212
- ...knownByDocument(doc.source, doc.links).concat(patternsOf(doc, "http-method"), patternsOf(doc, "tax-code")),
212
+ ...knownByDocument(doc.source, doc.links).concat(patternsOf(doc, "http-method"), patternsOf(doc, "sql-keyword"), patternsOf(doc, "tax-code")),
213
213
  ...(doc.names ?? []),
214
214
  ]);
215
215
  const expandedAt = expansionAt(definitionWordsOf(doc));
@@ -233,9 +233,12 @@ export const undefinedAcronym: Detector = (doc, options): Finding[] => {
233
233
  isExpanded(body, word, expandedAt) ||
234
234
  headings.some((heading) => expandsInHeading(heading, word, expandedAt));
235
235
  // 大文字の違うだけの書き方(TCoP と TCOP)は同じ略語と読む。どちらかで説明してあれば説明済み。
236
+ // 文の中で頭だけ大文字の語に書いた名前(a hotel / Airbnb)を大文字で書いた AIRBNB は、語を大きく書いただけで略語ではない。
237
+ const wholeText = [body, ...headings].join("\n");
236
238
  const explained = new Map<string, boolean>();
237
239
  const explainedAlone = (word: string): boolean => {
238
- const known = explained.get(word) ?? (explainedAsWritten(word) || caseVariantsIn([body, ...headings].join("\n"), word).some(explainedAsWritten));
240
+ const known =
241
+ explained.get(word) ?? (explainedAsWritten(word) || writtenAsWordIn(wholeText, word) || caseVariantsIn(wholeText, word).some(explainedAsWritten));
239
242
  explained.set(word, known);
240
243
  return known;
241
244
  };
@@ -1,6 +1,7 @@
1
1
  import type { Detector, Finding, Lexicon, ProseDocument, Sentence, Span } from "../plugin.ts";
2
2
  import { minorityWithin } from "../orthography.ts";
3
3
  import { QUOTATION_MARKS, isWithinAny, quotedSpans } from "../quoted-span.ts";
4
+ import { referenceListSpans } from "../reference-lists.ts";
4
5
 
5
6
  /**
6
7
  * 綴りの組の語彙表の名前の頭。組(spelling-variant、spelling-ize)ごとに比べる。組を分けるのは、両方の書き方が一つの
@@ -36,6 +37,15 @@ const CAPITAL = /^\p{Lu}/u;
36
37
  /** 大文字で始まる次の語。文の頭でも、大文字の語が続けば名前(Labor Day、Centre Court)。 */
37
38
  const CAPITALISED_NEXT = /^[ \t]+\p{Lu}/u;
38
39
 
40
+ /** 斜線でつないだ組(analyse/analyze)。両方の綴りを並べて名指ししているので、書き手の綴りではない。 */
41
+ const SLASH = "/";
42
+
43
+ const pairedBySlash = (text: string, at: number, word: string, other: string): boolean => {
44
+ const before = text.slice(Math.max(0, at - other.length - SLASH.length), at).toLowerCase();
45
+ const after = text.slice(at + word.length, at + word.length + SLASH.length + other.length).toLowerCase();
46
+ return before === `${other.toLowerCase()}${SLASH}` || after === `${SLASH}${other.toLowerCase()}`;
47
+ };
48
+
39
49
  export type SpelledWord = { readonly written: string; readonly offset: number; readonly spelling: Spelling };
40
50
 
41
51
  /**
@@ -50,7 +60,10 @@ export const spelledWordsIn = (sentence: Sentence, spellings: ReadonlyMap<string
50
60
  const named = CAPITAL.test(match[0]) && (match.index !== first || CAPITALISED_NEXT.test(sentence.text.slice(match.index + match[0].length)));
51
61
  const inQuote =
52
62
  isWithinAny(quoted, { start: match.index, end: match.index + match[0].length }) || OPENING_QUOTE.test(sentence.text.charAt(match.index - 1));
53
- return spelling === undefined || named || inQuote ? [] : [{ written: match[0], offset: sentence.span.start + match.index, spelling }];
63
+ if (spelling === undefined || named || inQuote) return [];
64
+ return pairedBySlash(sentence.text, match.index, match[0], spelling.other)
65
+ ? []
66
+ : [{ written: match[0], offset: sentence.span.start + match.index, spelling }];
54
67
  });
55
68
  };
56
69
 
@@ -65,13 +78,24 @@ const findingOf = ({ sentence, word }: Located, count: number, of: number): Find
65
78
  values: { matched: word.written, other: word.spelling.other, count, of, offset: word.offset },
66
79
  });
67
80
 
81
+ const REFERENCE_LIST_HEADING = "reference-list-heading";
82
+
83
+ /** 文献一覧の外の文。文献一覧の題や出版者の名前は、引いた文献の綴りのまま書く。 */
84
+ const outsideReferenceLists = (doc: ProseDocument): Sentence[] => {
85
+ const lists = referenceListSpans(
86
+ doc.source,
87
+ (doc.lexicons[REFERENCE_LIST_HEADING] ?? []).map((entry) => entry.pattern),
88
+ );
89
+ return doc.sentences.filter((sentence) => !lists.some((list) => list.start <= sentence.span.start && sentence.span.start < list.end));
90
+ };
91
+
68
92
  /**
69
93
  * イギリスとアメリカの綴り(colour と color、centre と center)が一つの文書で混ざっているか。組ごとに、文書の中で少ないほうを
70
94
  * 指摘する。どちらが正しいかは決めない。少ないほうが組の limit パーセントを超えるなら、使い分けと見て言わない。
71
95
  */
72
96
  export const spellingVariety: Detector = (doc, options): Finding[] => {
73
97
  const spellings = spellingsOf(doc.lexicons);
74
- const located: Located[] = doc.sentences.flatMap((sentence) => spelledWordsIn(sentence, spellings).map((word) => ({ sentence, word })));
98
+ const located: Located[] = outsideReferenceLists(doc).flatMap((sentence) => spelledWordsIn(sentence, spellings).map((word) => ({ sentence, word })));
75
99
  const families = [...new Set(located.map(({ word }) => word.spelling.family))];
76
100
  return families.flatMap((family) => {
77
101
  const ofFamily = located.filter(({ word }) => word.spelling.family === family);
@@ -1,7 +1,6 @@
1
1
  import type { Detector, Finding, ProseDocument, StructureNode } from "../plugin.ts";
2
- import { danglingReferences, duplicateDefinitions, inDocumentOrder, type StructureIssue } from "../structure/issues.ts";
2
+ import { danglingReferences, inDocumentOrder, type StructureIssue } from "../structure/issues.ts";
3
3
  import { numberingBreaks } from "../structure/numbering.ts";
4
- import { attachedPartStarts } from "../structure/attached-parts.ts";
5
4
  import { numberingReadings } from "./numbering-readings.ts";
6
5
  import { listsNumberBreaks } from "../structure/list-numbering.ts";
7
6
  import { weekdayMismatches } from "../structure/weekday.ts";
@@ -38,7 +37,7 @@ export const quoteAt = (source: string, offset: number): string => {
38
37
  .trim();
39
38
  };
40
39
 
41
- const findingsOf =
40
+ export const findingsOf =
42
41
  (rule: string, issuesOf: (tree: NonNullable<ProseDocument["structure"]>, source: string) => StructureIssue[]): Detector =>
43
42
  (doc): Finding[] =>
44
43
  doc.structure === undefined
@@ -95,11 +94,6 @@ export const numberingGap: Detector = (doc, options): Finding[] => {
95
94
  (left, right) => Number(left.values["offset"]) - Number(right.values["offset"]),
96
95
  );
97
96
  };
98
- export const duplicateDefinition: Detector = (doc, options) => {
99
- const labels = patternsOf(doc, "attached-instrument-label");
100
- return findingsOf("duplicate-definition", (tree, source) => duplicateDefinitions(tree, attachedPartStarts(source, labels), source))(doc, options);
101
- };
102
-
103
97
  /** 曜日の名前は言語パッケージの語彙表(weekday、日曜日から順)から取る。無ければ番号のまま。 */
104
98
  const dayName = (doc: ProseDocument, day: unknown): string => {
105
99
  const index = Number(day);
@@ -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 } from "../paragraph-length.ts";
7
+ import { isTooLongParagraph, labelledBlocks, 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";
@@ -62,23 +62,39 @@ const uniformity = (doc: ProseDocument, values: readonly number[], span: { start
62
62
  const sentenceSize = (sentence: Sentence, unit: LengthUnit): number =>
63
63
  lengthOf(sentence, unit) + (unit === "word" ? contractionExtraWords(proseText(sentence)) : 0);
64
64
 
65
+ type Block = { readonly start: number; readonly sentences: readonly Sentence[] };
66
+
67
+ /**
68
+ * 段落の中の、長さを測る文の組と、その頭の位置(最初の組は段落の頭)。見出しが本文に溶けた段落(改行の落ちた文書)は測らない。
69
+ * 【】の見出しや段落番号だけの行で段落を割る。
70
+ */
71
+ const measuredBlocks = (doc: ProseDocument, paragraph: Paragraph): Block[] => {
72
+ const text = doc.source.slice(paragraph.span.start, paragraph.span.end);
73
+ if (opensWithFusedHeading(text)) return [];
74
+ return labelledBlocks(text, paragraph.span.start, paragraph.sentences).map((sentences, index) => ({
75
+ start: index === 0 ? paragraph.span.start : (sentences[0]?.span.start ?? paragraph.span.start),
76
+ sentences,
77
+ }));
78
+ };
79
+
65
80
  /** 1 段落に文を詰めすぎると、読み手はどこで息継ぎしていいか分からなくなる。 */
66
81
  export const paragraphLength: Detector = (doc, options): Finding[] =>
67
82
  doc.paragraphs
68
- .filter((paragraph) =>
83
+ .flatMap((paragraph) => measuredBlocks(doc, paragraph))
84
+ .filter((block) =>
69
85
  isTooLongParagraph(
70
- paragraph.sentences.map((sentence) => sentenceSize(sentence, doc.lengthUnit)),
86
+ block.sentences.map((sentence) => sentenceSize(sentence, doc.lengthUnit)),
71
87
  options.limit,
72
88
  options.fullSentence,
73
89
  ),
74
90
  )
75
- .map((paragraph) => ({
91
+ .map((block) => ({
76
92
  rule: "max-paragraph-length",
77
93
  severity: "warning",
78
94
  line: 0,
79
95
  column: 0,
80
- quote: doc.source.slice(paragraph.span.start, paragraph.span.start + 80).trim(),
81
- values: { count: paragraph.sentences.length, limit: options.limit, offset: paragraph.span.start },
96
+ quote: doc.source.slice(block.start, block.start + 80).trim(),
97
+ values: { count: block.sentences.length, limit: options.limit, offset: block.start },
82
98
  }));
83
99
 
84
100
  const charsOf = (paragraph: Paragraph): number => paragraph.sentences.reduce((sum, sentence) => sum + charLength(sentence), 0);
@@ -5,6 +5,7 @@ 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
7
  import { honorificGroupParticles } from "../honorific-group.ts";
8
+ import { setPhraseParticles } from "../set-phrase-particles.ts";
8
9
  import { noteSentences } from "../note-paragraphs.ts";
9
10
  import { documentNameSpans } from "./particle-run-names.ts";
10
11
 
@@ -93,11 +94,17 @@ const RUN_BREAK_LEXICON = "particle-run-break";
93
94
  /** 人の集まりを敬って呼ぶ語(国民の皆様の「皆様」)。直前の助詞は呼び方の一部で、入れ子の輪に数えない。 */
94
95
  const HONORIFIC_GROUP_LEXICON = "honorific-group";
95
96
 
96
- /** 数えない助詞(番号をつなぐ「の」と、敬って呼ぶ語の前の「の」)を除いた語。 */
97
- const chainTokens = (tokens: readonly Token[], numbering: UncountedWords, groups: readonly string[]): readonly Token[] => {
98
- const honorific = honorificGroupParticles(tokens, numbering.particles, groups);
97
+ /** 助詞を挟んで一語のように読む決まった言い回し(おそれのある)。中の助詞は入れ子の輪に数えない。 */
98
+ const SET_PHRASE_LEXICON = "particle-run-set-phrase";
99
+
100
+ /** 敬って呼ぶ語(皆様)と決まった言い回し(おそれのある)。 */
101
+ type Phrases = { readonly groups: readonly string[]; readonly setPhrases: readonly string[] };
102
+
103
+ /** 数えない助詞(番号をつなぐ「の」、敬って呼ぶ語の前の「の」、決まった言い回しの中の「の」)を除いた語。 */
104
+ const chainTokens = (tokens: readonly Token[], numbering: UncountedWords, { groups, setPhrases }: Phrases): readonly Token[] => {
105
+ const uncounted = new Set([...honorificGroupParticles(tokens, numbering.particles, groups), ...setPhraseParticles(tokens, numbering.particles, setPhrases)]);
99
106
  const counted = countedTokens(tokens, numbering);
100
- return honorific.size === 0 ? counted : counted.filter((token) => !honorific.has(token));
107
+ return uncounted.size === 0 ? counted : counted.filter((token) => !uncounted.has(token));
101
108
  };
102
109
 
103
110
  export const doubledParticle: Detector = (doc, options): Finding[] => {
@@ -105,10 +112,13 @@ export const doubledParticle: Detector = (doc, options): Finding[] => {
105
112
  const titles = externalLinkTitleSpans(doc.source, doc.links);
106
113
  const breaks = (doc.lexicons[RUN_BREAK_LEXICON] ?? []).map((entry) => entry.pattern);
107
114
  const numbering = uncountedWordsOf(doc.lexicons, nesting);
108
- const groups = (doc.lexicons[HONORIFIC_GROUP_LEXICON] ?? []).map((entry) => entry.pattern);
115
+ const phrases: Phrases = {
116
+ groups: (doc.lexicons[HONORIFIC_GROUP_LEXICON] ?? []).map((entry) => entry.pattern),
117
+ setPhrases: (doc.lexicons[SET_PHRASE_LEXICON] ?? []).map((entry) => entry.pattern),
118
+ };
109
119
  const prose = doc.prose ?? doc.source;
110
120
  return doc.sentences.flatMap((sentence) => {
111
- const tokens = chainTokens(sentence.tokens ?? [], numbering, groups);
121
+ const tokens = chainTokens(sentence.tokens ?? [], numbering, phrases);
112
122
  const quoted = [...quotedIn(sentence), ...titles];
113
123
  const longRuns = (skipped: readonly Span[]): Run[] => runsOf(tokens, nesting, breaks, skipped).filter((run) => run.tokens.length > options.limit);
114
124
  const found = longRuns(quoted);
@@ -49,6 +49,8 @@ export type TermWords = {
49
49
  readonly named: readonly string[];
50
50
  /** What turns a term into another one (本報告書等 after 本報告書): a group the document has to define on its own. */
51
51
  readonly groupSuffixes: readonly string[];
52
+ /** The document takes the definitions of another one (本共同研究開発契約において定義した用語…同契約内の定義に従う). */
53
+ readonly inheritsDefinitions?: boolean;
52
54
  };
53
55
 
54
56
  const QUOTED = /[「『“"](?<term>[^「」『』“”"\n]{1,40})[」』”"]/gu;
@@ -84,17 +86,37 @@ const knownForms = (defined: readonly string[], groups: TermWords["prefixGroups"
84
86
  ...defined.flatMap((term) => prefixVariants(term, groups)),
85
87
  ];
86
88
 
89
+ /** Every character of the shorter one, in order, in the longer one (本学習モデル in 本学習済みモデル). */
90
+ const isSubsequence = (shorter: string, longer: string): boolean => {
91
+ const chars = Array.from(longer);
92
+ let at = 0;
93
+ return Array.from(shorter).every((char) => {
94
+ const found = chars.indexOf(char, at);
95
+ at = found + 1;
96
+ return found !== -1;
97
+ });
98
+ };
99
+
100
+ /** A slip for another term: the same prefix, its characters a part of the other's, and not the other's start (本学習モデル for 本学習済みモデル). */
101
+ const isSlipOf = (term: string, other: string, prefix: string): boolean =>
102
+ other.startsWith(prefix) && other.length > term.length && !other.startsWith(term) && isSubsequence(term, other);
103
+
87
104
  /**
88
105
  * The first use of each term written with the document's prefix and defined nowhere, when the document defines at
89
106
  * least one term with that prefix (else the prefix is not its way of naming terms). A use that starts with a known
90
107
  * form (本サービス上 where 本サービス is defined) is that term, unless the rest is a group's mark (本サービス等).
108
+ * A name of a document (本共同開発契約) is left like the document's name for itself, unless it is a slip for a defined term
109
+ * (本共同研究開発契約). A document that takes the definitions of another one has terms defined there: only a slip for
110
+ * another of its terms (本学習モデル beside 本学習済みモデル) is reported then.
91
111
  */
92
112
  export const undefinedTerms = (source: string, sentences: readonly (readonly Token[])[], defined: readonly string[], words: TermWords): UndefinedTerm[] => {
93
113
  const prefixes = words.prefixes.filter((prefix) => prefix !== "");
94
114
  if (!defined.some((term) => hasPrefix(term, prefixes))) return [];
115
+ const selfNouns = words.selfNouns.filter((noun) => noun !== "");
95
116
  const isSelf = (term: string, prefix: string): boolean => {
96
117
  const rest = term.slice(prefix.length);
97
- return words.selfNouns.some((noun) => noun !== "" && (rest.startsWith(noun) || rest.endsWith(noun)));
118
+ if (!selfNouns.some((noun) => rest.startsWith(noun) || rest.endsWith(noun))) return false;
119
+ return selfNouns.includes(rest) || !defined.some((other) => isSlipOf(term, other, prefix));
98
120
  };
99
121
  const runs = sentences.flatMap((tokens) =>
100
122
  tokens.flatMap((token, index) => {
@@ -106,8 +128,10 @@ export const undefinedTerms = (source: string, sentences: readonly (readonly Tok
106
128
  // A name that does not start a run of nouns (② 本研究の具体的な遂行方法) is an item of a list, not a term.
107
129
  const named = words.named.filter((term) => runs.some((run) => run.term.startsWith(term)));
108
130
  const known = knownForms([...defined, ...named], words.prefixGroups);
131
+ const terms = [...defined, ...runs.map((run) => run.term)];
109
132
  const uses = runs
110
133
  .filter((run) => !isSelf(run.term, run.prefix) && !words.isQuoted(run.term) && !isKnownUse(run.term, known, words.groupSuffixes))
134
+ .filter((run) => words.inheritsDefinitions !== true || terms.some((other) => isSlipOf(run.term, other, run.prefix)))
111
135
  .map((run) => ({ offset: run.offset, term: run.term }));
112
136
  return uses.filter((use, index) => uses.findIndex((other) => other.term === use.term) === index);
113
137
  };
@@ -167,6 +191,7 @@ export const undefinedTerm: Detector = (doc): Finding[] => {
167
191
  isQuoted: (term) => QUOTE_PAIRS.some(([open, close]) => doc.source.includes(`${open}${term}${close}`)),
168
192
  named: namedTerms(doc.source, prefixes),
169
193
  groupSuffixes: patternsOf(doc, "defined-term-group-suffix"),
194
+ inheritsDefinitions: patternsOf(doc, "definitions-inherited").some((phrase) => phrase !== "" && doc.source.includes(phrase)),
170
195
  });
171
196
  return [...prefixed, ...capitalisedUses(doc, sentences, definitions)].map((use) => findingOf(doc, use));
172
197
  };
@@ -1,7 +1,23 @@
1
- import type { Detector } from "../plugin.ts";
1
+ import type { Detector, Finding, Lexicon, ProseDocument } from "../plugin.ts";
2
2
  import { entriesForGenre } from "../lexicon-genres.ts";
3
3
  import { unfilledPlaceholder } from "./ai-phrasing.ts";
4
+ import { placeholderSpans } from "./placeholder-text.ts";
4
5
  import { TEMPLATE, isInside, templateSections } from "./template-sections.ts";
6
+ import { tableBodyCells } from "../facts/table-facts.ts";
7
+ import { proseAndTablesOf } from "../table-text.ts";
8
+
9
+ /** The prose covers tables, so a blank left in a cell (| Owner | [Name] |) is read from the cells themselves. */
10
+ const cellBlanks = (doc: ProseDocument, lexicon: Lexicon): Finding[] =>
11
+ tableBodyCells(proseAndTablesOf(doc)).flatMap((cell) =>
12
+ placeholderSpans(cell.text, lexicon).map((span) => ({
13
+ rule: "",
14
+ severity: "info" as const,
15
+ line: 0,
16
+ column: 0,
17
+ quote: cell.text.trim(),
18
+ values: { matched: cell.text.slice(span.start, span.end), offset: cell.start + span.start },
19
+ })),
20
+ );
5
21
 
6
22
  /**
7
23
  * A blank under a heading that names a template (Template, 雛形) is what the template is for, so it is not reported.
@@ -11,5 +27,7 @@ export const unfilledPlaceholderOutsideTemplates: Detector = (doc, options) => {
11
27
  const lexicon = entriesForGenre(options.lexicon ?? [], options.genre);
12
28
  const words = lexicon.filter((word) => word.group === TEMPLATE);
13
29
  const templates = templateSections(doc.markup?.headings ?? [], doc.source.length, words);
14
- return unfilledPlaceholder(doc, { ...options, lexicon }).filter((finding) => !isInside(templates, Number(finding.values["offset"])));
30
+ return [...unfilledPlaceholder(doc, { ...options, lexicon }), ...cellBlanks(doc, lexicon)]
31
+ .filter((finding) => !isInside(templates, Number(finding.values["offset"])))
32
+ .toSorted((left, right) => Number(left.values["offset"]) - Number(right.values["offset"]));
15
33
  };
@@ -110,3 +110,20 @@ export const usedOnce = (words: readonly CheckedWord[], speller: Speller): Check
110
110
  const shared = countsOf([...families.values()].flat());
111
111
  return words.filter(({ word }) => uses.get(word) === 1 && (families.get(word) ?? []).every((key) => shared.get(key) === 1));
112
112
  };
113
+
114
+ /** A release number of three parts or more (1.21.5, v2.0.1), after spaces. */
115
+ const VERSION_AFTER = /^[ \t]+v?\d+\.\d+\.\d+/u;
116
+
117
+ /** The word names what a release number follows (golang 1.21.5): a product or a tool, written as its makers write it. */
118
+ export const beforeVersion = (source: string, offset: number, word: string): boolean => VERSION_AFTER.test(source.slice(offset + word.length));
119
+
120
+ /** Two words of one length that differ in one letter only. */
121
+ const oneLetterApart = (left: string, right: string): boolean =>
122
+ left.length === right.length && [...left].filter((letter, index) => letter !== right.charAt(index)).length === 1;
123
+
124
+ /**
125
+ * Another word of the document, itself not in the dictionary, one letter from this one (pthread and bthread): a family of
126
+ * names built on one scheme. A slip is one letter from a word the dictionary knows, and two slips seldom make such a pair.
127
+ */
128
+ export const hasSiblingName = (word: string, unknownWords: ReadonlySet<string>): boolean =>
129
+ [...unknownWords].some((other) => other !== word && oneLetterApart(word, other));
@@ -3,7 +3,17 @@ import { hasTwoEndings, isKnownWord, isSplitWord, suggestionFor, wordsToCheck, t
3
3
  import { parse } from "../markdown-read.ts";
4
4
  import { eachPreOrder } from "../tree-walk.ts";
5
5
  import { quoteAt } from "./structure-tree.ts";
6
- import { addressWordsOf, besideForeignWord, hasDrugStem, inSearchTermList, isClosedCompound, isMention, usedOnce } from "./unknown-word-context.ts";
6
+ import {
7
+ addressWordsOf,
8
+ beforeVersion,
9
+ besideForeignWord,
10
+ hasDrugStem,
11
+ hasSiblingName,
12
+ inSearchTermList,
13
+ isClosedCompound,
14
+ isMention,
15
+ usedOnce,
16
+ } from "./unknown-word-context.ts";
7
17
 
8
18
  /** これより短い語は見ない。短い語は一字違いの語が多すぎて言い直しが決まらず(tost は test か toast か)、略した語(impl)も多い。 */
9
19
  const MIN_LENGTH = 5;
@@ -43,9 +53,9 @@ export const codeWordsOf = (source: string): Set<string> => {
43
53
  /** 辞書の語か、派生した語に活用の語尾を付けた語(operationalises、rightsized)か、四字以上の辞書の語二つを続けた語(crowdwork)。 */
44
54
  const isFormedWord = (word: string, speller: Speller): boolean => isKnownWord(word, speller) || hasTwoEndings(word, speller) || isClosedCompound(word, speller);
45
55
 
46
- /** 置かれた場所から、名前や用語と分かる語。名指した語("mailto"、(jchaplin))、検索語の並び(vaccin*)、外国語の句(bête noire)。 */
56
+ /** 置かれた場所から、名前や用語と分かる語。名指した語("mailto"、(jchaplin))、検索語の並び(vaccin*)、外国語の句(bête noire)、版の番号の前(golang 1.21.5)。 */
47
57
  const isTermByPlace = (source: string, offset: number, word: string): boolean =>
48
- isMention(source, offset, word) || inSearchTermList(source, offset) || besideForeignWord(source, offset, word);
58
+ isMention(source, offset, word) || inSearchTermList(source, offset) || besideForeignWord(source, offset, word) || beforeVersion(source, offset, word);
49
59
 
50
60
  /**
51
61
  * 辞書に無い英語の語で、一字違いの辞書の語があるもの(recieve → receive)。辞書は adapter が持ち、無い言語では動かない。
@@ -59,8 +69,9 @@ export const unknownWord: Detector = (doc): Finding[] => {
59
69
  const drugStems = patternsOf(doc, "drug-stem");
60
70
  const words = wordsToCheck(doc.prose ?? doc.source, MIN_LENGTH, MAX_LENGTH).filter(({ offset }) => !isSplitWord(doc.source, offset));
61
71
  const used = new Set(words.map(({ word }) => word).filter((word) => isKnownWord(word, speller)));
72
+ const unformed = new Set(words.map(({ word }) => word).filter((word) => !known.has(word) && !isFormedWord(word, speller)));
62
73
  return usedOnce(words, speller).flatMap(({ offset, word }) => {
63
- if (known.has(word) || isFormedWord(word, speller) || hasDrugStem(word, drugStems) || isTermByPlace(doc.source, offset, word)) return [];
74
+ if (!unformed.has(word) || hasDrugStem(word, drugStems) || hasSiblingName(word, unformed) || isTermByPlace(doc.source, offset, word)) return [];
64
75
  const suggestion = suggestionFor(word, speller, used);
65
76
  if (suggestion === undefined) return [];
66
77
  return [{ rule: "", severity: "warning", line: 0, column: 0, quote: quoteAt(doc.source, offset), values: { word, suggestion, offset } }];
@@ -0,0 +1,33 @@
1
+ import type { Boundary } from "./orthography.ts";
2
+ import { hasGluedNumbers } from "./detectors/sentence-parts.ts";
3
+
4
+ // 英数字の前後の空け方が、書き手のものでない所。文献の記載の行(題名は出版されたとおりに写す)、変換で区切りが消えて
5
+ // 一続きになった表(升の区切りの空白)、行の頭の図表の札と題のあいだ(表 6種類の…)。Pure.
6
+
7
+ /**
8
+ * 文献の記載(SIST の書き方)の行: 著者の後ろに「. 」、その後ろに「. 年,」(佐藤翔. 題. 誌名. 2019, (26), p. 136-147.)。
9
+ * 著者の欄は句点を含まない短い語の並び(佐藤翔, 鈴木一郎)。
10
+ */
11
+ const ENTRY_AUTHOR = /^[ \t]*[^.。.\n]{1,60}\.\s/u;
12
+ const ENTRY_YEAR = /\.\s(?:1[89]|20)\d{2}[,,]/u;
13
+
14
+ export const isCitedEntryLine = (line: string): boolean => ENTRY_AUTHOR.test(line) && ENTRY_YEAR.test(line);
15
+
16
+ /** at を含む行。 */
17
+ export const lineAt = (text: string, at: number): string => {
18
+ const end = text.indexOf("\n", at);
19
+ return text.slice(text.lastIndexOf("\n", at - 1) + 1, end === -1 ? text.length : end);
20
+ };
21
+
22
+ /**
23
+ * 変換で区切りが消えた数の表(桁の区切りの崩れた数の列 8,776,90087,769)を一つの文にしたものの、数の前後の境目。
24
+ * 数の前後の空白は升の区切り。英字の前後は升の中の書き手の言葉なので数える(年表の「合弁会社 SANKO」)。
25
+ */
26
+ export const isNumberTableBoundary = (text: string, boundary: Boundary): boolean => boundary.kind !== "letter" && hasGluedNumbers(text);
27
+
28
+ /** 行の頭の字下げと箇条書きの印。 */
29
+ const LINE_LEAD = /^[\s\-*+]*/u;
30
+
31
+ /** 境目が、行の頭に図表の札(表、図)だけを書いた後ろの空白か(表 6種類のCCライセンス)。札と題の区切りで、空け方の好みではない。 */
32
+ export const followsCaptionLabel = (text: string, boundary: Boundary, labels: ReadonlySet<string>): boolean =>
33
+ boundary.spaced && labels.has(text.slice(text.lastIndexOf("\n", boundary.offset - 1) + 1, boundary.offset).replace(LINE_LEAD, ""));
@@ -161,6 +161,9 @@ export const isNameSeparator = (text: string, boundary: Boundary, tokens: readon
161
161
  if (tokens === undefined || boundary.kind !== "letter" || !boundary.spaced) return false;
162
162
  const before = { start: wordStart(text, boundary.offset), end: boundary.offset };
163
163
  const after = { start: boundary.offset + 1, end: wordEnd(text, boundary.offset + 1) };
164
+ const line = lineAround(text, boundary.offset);
164
165
  const isName = (span: Span): boolean => isOrganizationName(text.slice(span.start, span.end), tokensIn(tokens, span, base), words);
165
- return isName(before) && isName(after) && isNameLine(tokensIn(tokens, lineAround(text, boundary.offset), base));
166
+ // 後ろの名前が空白を含むこともある(初等中等教育局 GIGA StuDX(ギガ スタディーエックス)推進チーム)。行の残りが一つの名前なら区切り。
167
+ const restOfLine = { start: after.start, end: line.end };
168
+ return isName(before) && (isName(after) || isName(restOfLine)) && isNameLine(tokensIn(tokens, line, base));
166
169
  };
@@ -7,3 +7,34 @@ export const isTooLongParagraph = (sentenceSizes: readonly number[], limit: numb
7
7
  const size = sentenceSizes.reduce((sum, sentence) => sum + sentence, 0);
8
8
  return sentenceSizes.length > limit && (fullSentence === undefined || size > limit * fullSentence);
9
9
  };
10
+
11
+ type Spanned = { readonly span: { readonly start: number; readonly end: number } };
12
+
13
+ /** 【】の見出しや段落番号だけの行(【0001】、【従来の技術】)。特許の明細書や公文書を写すと改行一つでつながり、Markdown では一つの段落になる。 */
14
+ const LABEL_LINE = /^[ \t\u3000]*【[^】\n]+】[ \t\u3000]*$/gmu;
15
+
16
+ /** 段落の頭の、番号付きの【】の見出しに、改行なしで本文が続く(2【沿革】1893年…)。写すときに改行が落ち、どこが段落の切れ目か分からない。 */
17
+ const FUSED_HEADING = /^[ \t\u3000]*[0-90-9①-⑳]{1,3}【[^】\n]+】[ \t\u3000]*[^\s]/u;
18
+
19
+ /** 段落の本文が、番号付きの見出しから改行なしで始まる。段落の切れ目が失われた文書で、長さを測っても書き手の段落ではない。 */
20
+ export const opensWithFusedHeading = (text: string): boolean => FUSED_HEADING.test(text);
21
+
22
+ /** 【】のラベルだけの文(【0001】【技術分野】)。見出しで、文に数えない。 */
23
+ const LABELS_ONLY = /^\s*(?:【[^】\n]+】\s*)+$/u;
24
+
25
+ /**
26
+ * 段落の文を、【】の見出しや段落番号だけの行で割った組。読み手にとってはその行が段落の切れ目で、ラベルだけの文は数えない。
27
+ * text は段落の文字列で、start はその文書の中の位置(文の span と同じ座標)。割る行が無ければ段落の文がそのまま一つの組。
28
+ */
29
+ export const labelledBlocks = <T extends Spanned>(text: string, start: number, sentences: readonly T[]): T[][] => {
30
+ const cuts = [...text.matchAll(LABEL_LINE)].map((match) => start + match.index);
31
+ if (cuts.length === 0) return sentences.length === 0 ? [] : [[...sentences]];
32
+ const blocks = new Map<number, T[]>();
33
+ sentences
34
+ .filter((sentence) => !LABELS_ONLY.test(text.slice(sentence.span.start - start, sentence.span.end - start)))
35
+ .forEach((sentence) => {
36
+ const block = cuts.filter((cut) => cut < sentence.span.end).length;
37
+ blocks.set(block, [...(blocks.get(block) ?? []), sentence]);
38
+ });
39
+ return [...blocks.values()];
40
+ };
@@ -50,25 +50,83 @@ export const isReferenceEntry = (source: string, paragraph: Paragraph, reference
50
50
  REFERENCE_LABEL.test(source.slice(paragraph.span.start, paragraph.span.end)) ||
51
51
  referenceLists.some((list) => list.start <= paragraph.span.start && paragraph.span.start < list.end);
52
52
 
53
+ /**
54
+ * An enumerator a paragraph opens with: (1), (2), (iii), (a), ① . Paragraphs numbered this way are the items of a list
55
+ * written as plain text, as a glossary's terms or an appendix's categories are.
56
+ */
57
+ const BRACKETED_LABEL = /^[ \t\u3000]*[((]([^))\s]{1,6})[))]/u;
58
+ const CIRCLED_NUMBER = /^[ \t\u3000]*[①-⑳]/u;
59
+ const ENUMERATOR_LABEL = /^(?:\d{1,3}|[0-9]{1,3}|[ivxlc]{1,6}|[IVXLC]{1,6}|[a-zA-Z]|[一二三四五六七八九十]{1,3})$/u;
60
+
61
+ const opensWithEnumerator = (source: string, paragraph: Paragraph): boolean => {
62
+ const text = source.slice(paragraph.span.start, paragraph.span.end);
63
+ return CIRCLED_NUMBER.test(text) || ENUMERATOR_LABEL.test(BRACKETED_LABEL.exec(text)?.[1] ?? "");
64
+ };
65
+
66
+ /** A lead-in's last mark: the paragraph announces what follows (Follow these steps:, 次のとおりです:). */
67
+ const LEAD_IN_END = /[::]$/u;
68
+
69
+ /** How many sentences an item under a lead-in may hold before the paragraphs read as prose again. */
70
+ const MAX_ITEM_SENTENCES = 2;
71
+
72
+ /**
73
+ * The paragraphs that follow a lead-in ending with a colon, adjacent to it and to one another, each short enough to be an item.
74
+ * A list converted from HTML often loses its markup and keeps only its lead-in; its items are not prose split into paragraphs.
75
+ */
76
+ const underLeadIn = (source: string, paragraphs: readonly Paragraph[]): ReadonlySet<Paragraph> => {
77
+ const items = new Set<Paragraph>();
78
+ paragraphs.reduce<Paragraph | undefined>((open, paragraph, at) => {
79
+ const previous = paragraphs[at - 1];
80
+ const continues =
81
+ open !== undefined && previous !== undefined && isAdjacent(source, previous, paragraph) && paragraph.sentences.length <= MAX_ITEM_SENTENCES;
82
+ if (continues) items.add(paragraph);
83
+ if (LEAD_IN_END.test(source.slice(paragraph.span.start, paragraph.span.end).trim())) return paragraph;
84
+ return continues ? open : undefined;
85
+ }, undefined);
86
+ return items;
87
+ };
88
+
53
89
  /** Whether a paragraph can be counted in a run: one sentence, ending as a sentence, not an item or a reference entry. */
54
- const counts = (source: string, paragraph: Paragraph, referenceLists: readonly Span[]): boolean =>
90
+ const counts = (source: string, paragraph: Paragraph, referenceLists: readonly Span[], leadInItems: ReadonlySet<Paragraph>): boolean =>
55
91
  paragraph.sentences.length === 1 &&
56
92
  endsAsSentence(source, paragraph) &&
57
93
  !opensAsItem(source, paragraph) &&
94
+ !opensWithEnumerator(source, paragraph) &&
95
+ !leadInItems.has(paragraph) &&
58
96
  !isReferenceEntry(source, paragraph, referenceLists);
59
97
 
98
+ /** How many opening words every paragraph of a run must share for the run to be a list of parallel entries. */
99
+ const PARALLEL_WORDS = 3;
100
+
101
+ const openingOf = (source: string, paragraph: Paragraph): string =>
102
+ source.slice(paragraph.span.start, paragraph.span.end).trim().split(/\s+/u).slice(0, PARALLEL_WORDS).join(" ").toLowerCase();
103
+
104
+ /**
105
+ * Whether every paragraph of a run opens with the same words (The government's 'How to … guide, one per guide): entries set
106
+ * out in one frame, a list in all but markup. Text written without spaces between words never shares a whole opening.
107
+ */
108
+ const isParallel = (source: string, run: readonly Paragraph[]): boolean => {
109
+ const openings = run.map((paragraph) => openingOf(source, paragraph));
110
+ const first = openings[0];
111
+ return run.length > 1 && first !== undefined && first.split(" ").length === PARALLEL_WORDS && openings.every((opening) => opening === first);
112
+ };
113
+
60
114
  /**
61
115
  * Each run of adjacent one-sentence paragraphs, in document order, as the paragraphs it holds. A paragraph of two sentences or
62
- * more, a paragraph that does not end as a sentence, opens with an item mark or is a reference list's entry, or anything
63
- * between two paragraphs, ends the run.
116
+ * more, a paragraph that does not end as a sentence, opens with an item mark or an enumerator, follows a lead-in as its item or
117
+ * is a reference list's entry, or anything between two paragraphs, ends the run. A run of parallel entries is a list, not a run.
64
118
  */
65
- export const oneSentenceRuns = (source: string, paragraphs: readonly Paragraph[], referenceLists: readonly Span[] = []): Paragraph[][] =>
66
- paragraphs.reduce<Paragraph[][]>((runs, paragraph, at) => {
67
- if (!counts(source, paragraph, referenceLists)) return runs;
68
- const previous = paragraphs[at - 1];
69
- const current = runs.at(-1);
70
- const continues = previous !== undefined && current?.at(-1) === previous && isAdjacent(source, previous, paragraph);
71
- if (continues) current.push(paragraph);
72
- else runs.push([paragraph]);
73
- return runs;
74
- }, []);
119
+ export const oneSentenceRuns = (source: string, paragraphs: readonly Paragraph[], referenceLists: readonly Span[] = []): Paragraph[][] => {
120
+ const leadInItems = underLeadIn(source, paragraphs);
121
+ return paragraphs
122
+ .reduce<Paragraph[][]>((runs, paragraph, at) => {
123
+ if (!counts(source, paragraph, referenceLists, leadInItems)) return runs;
124
+ const previous = paragraphs[at - 1];
125
+ const current = runs.at(-1);
126
+ const continues = previous !== undefined && current?.at(-1) === previous && isAdjacent(source, previous, paragraph);
127
+ if (continues) current.push(paragraph);
128
+ else runs.push([paragraph]);
129
+ return runs;
130
+ }, [])
131
+ .filter((run) => !isParallel(source, run));
132
+ };
@@ -0,0 +1,18 @@
1
+ import type { Span } from "./plugin.ts";
2
+
3
+ // A phrase the writer repeats from a quotation in the same document (「勇気と真心をもって真実を語る」 quoted, then 勇気と真心を
4
+ // もって真実を語り in the writer's own sentence): the words of the echo keep the quotation's spelling. Pure.
5
+
6
+ /** How many characters on each side of a word are read with it: enough to tell an echo from a word that merely recurs. */
7
+ const ECHO_REACH = 4;
8
+ /** The shortest stretch, the word and its sides, that counts as an echo. */
9
+ const MIN_ECHO_LENGTH = 8;
10
+
11
+ /** The insides of the quotations in a text, as quotedSpans places them. */
12
+ export const quotationsIn = (text: string, spans: readonly Span[]): string[] => spans.map((span) => text.slice(span.start, span.end));
13
+
14
+ /** Whether the word at start..end of text, with the characters around it, stands word for word in one of the quotations. */
15
+ export const echoesQuotation = (text: string, { start, end }: Span, quotations: readonly string[]): boolean => {
16
+ const phrase = text.slice(Math.max(0, start - ECHO_REACH), Math.min(text.length, end + ECHO_REACH));
17
+ return phrase.length >= MIN_ECHO_LENGTH && quotations.some((quotation) => quotation.includes(phrase));
18
+ };
package/src/semantic.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { calendarUnitsOf } from "./calendar-number.ts";
2
2
  import { closingAndEarlier, newNumbers } from "./closing-numbers.ts";
3
+ import { hasNewCodeOrLink, isLinkList } from "./closing-code.ts";
3
4
  import { openingProse, opensWithNumber } from "./opening-passage.ts";
4
5
  import { proseText } from "./measure.ts";
5
6
  import type { ProseDocument, Section } from "./plugin.ts";
@@ -31,8 +32,6 @@ export const riskDisclosure: Filter = (doc) => {
31
32
  return [{ text: body.slice(0, 4000), offset: doc.sentences[0]?.span.start ?? 0 }];
32
33
  };
33
34
 
34
- const EVIDENCE = /`|https?:\/\//u;
35
-
36
35
  /** 結びに、前に書いていない数があるか。本文の数を繰り返すだけ(「以上のように、9月は…」)なら具体物ではない。 */
37
36
  const hasNewNumber = (doc: ProseDocument, last: Section): boolean => {
38
37
  const { closing, earlier } = closingAndEarlier(doc, last);
@@ -47,7 +46,7 @@ export const emptyConclusion: Filter = (doc) => {
47
46
  const last = doc.sections.at(-1);
48
47
  if (last === undefined || last.sentences.length === 0) return [];
49
48
  const text = sectionText(doc, last);
50
- if (EVIDENCE.test(text) || hasNewNumber(doc, last)) return [];
49
+ if (isLinkList(text) || hasNewCodeOrLink(text, doc.source.slice(0, last.span.start)) || hasNewNumber(doc, last)) return [];
51
50
  return [{ text: text.slice(0, 2000), offset: last.sentences[0]?.span.start ?? last.span.start }];
52
51
  };
53
52