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
@@ -3,13 +3,14 @@ import { conjugatedStartsOutside } from "./conjugated-entry.ts";
3
3
  import { calendarRuns, calendarUnitsOf, type CalendarUnits } from "../calendar-number.ts";
4
4
  import { escapeRegExp, latinBoundaries, occurrencesOutside, type Boundary, type SpacingKind } from "../orthography.ts";
5
5
  import { minorityReport, withoutSideOnTie } from "../spacing-minority.ts";
6
- import { isWithinAny, quotedSpans } from "../quoted-span.ts";
6
+ import { isWithinAny, QUOTATION_MARKS, quotedSpans } from "../quoted-span.ts";
7
7
  import { digitRunAround, endsWithDivisionLabel, isNumberName, sequenceLabelStarts, type NameContext } from "../number-name.ts";
8
8
  import { isSpacedLocationPart, type FloorWords } from "../location-part.ts";
9
9
  import { isFieldSeparator, isNameSeparator, type OrganizationWords } from "../name-separator.ts";
10
10
  import { addressSpans, clockTimeSpans, identifierSpans, isInsideSpan } from "../spacing-code.ts";
11
11
  import { followsHandle, isBoundSuffix, isJoinerSpace } from "../latin-word-boundary.ts";
12
12
  import { licenceNoticeSentences } from "./licence-notice.ts";
13
+ import { followsCaptionLabel, isCitedEntryLine, isNumberTableBoundary, lineAt } from "../latin-spacing-source.ts";
13
14
 
14
15
  /** 書いた形の出現に、動詞の活用した形(行う → 行います)を足したもの。同じ位置は一度だけ。 */
15
16
  const avoidedStarts = (sentence: Sentence, entry: LexiconEntry, use: string): number[] => {
@@ -59,6 +60,8 @@ type NumberContext = NameContext & {
59
60
  readonly organizations: OrganizationWords;
60
61
  /** 日本語の句をつなぐ英語の語(or、vs.)と、英字の語に付ける接尾の語(版、化)。 */
61
62
  readonly latinWords: { readonly joiners: ReadonlySet<string>; readonly boundSuffixes: ReadonlySet<string> };
63
+ /** 図表の札(表、図)。行の頭にこれだけを書いた後ろの空白は、札と題の区切り。 */
64
+ readonly captionLabels: ReadonlySet<string>;
62
65
  };
63
66
 
64
67
  /** 文頭の項目の番号の後ろと見る境目の位置の上限。番号は短く文の頭にあるので、これより後ろの境目は番号の後ろではない。長い文で文頭からの切り出しを繰り返さない。 */
@@ -107,7 +110,10 @@ type SentenceCodes = {
107
110
  */
108
111
  /** 項目の番号・識別子・チャンネルや宛先の名前(#pj_oss-team)の端の境目。どれも名前や番号を閉じる空白で、空け方の好みではない。 */
109
112
  const closesName = (sentence: Sentence, boundary: Boundary, context: NumberContext, codes: SentenceCodes): boolean =>
110
- followsItemNumber(sentence.text, boundary, context.itemNumbers) || besideSpan(codes.identifiers, boundary) || followsHandle(sentence.text, boundary);
113
+ followsItemNumber(sentence.text, boundary, context.itemNumbers) ||
114
+ followsCaptionLabel(sentence.text, boundary, context.captionLabels) ||
115
+ besideSpan(codes.identifiers, boundary) ||
116
+ followsHandle(sentence.text, boundary);
111
117
 
112
118
  const isCounted = (sentence: Sentence, boundary: Boundary, context: NumberContext, codes: SentenceCodes): boolean => {
113
119
  if (closesName(sentence, boundary, context, codes)) return false;
@@ -194,22 +200,29 @@ export const latinSpacing: Detector = (doc, options): Finding[] => {
194
200
  floors: { units: patternsOf(doc, "floor-unit"), levels: patternsOf(doc, "floor-level") },
195
201
  organizations: { units: patternsOf(doc, "organization-unit"), forms: patternList(doc, "company-form") },
196
202
  latinWords: { joiners: patternsOf(doc, "latin-joiner"), boundSuffixes: patternsOf(doc, "latin-bound-suffix") },
203
+ captionLabels: patternsOf(doc, "figure-label"),
197
204
  };
198
205
  // 文書の最後の利用条件の断り書き(クリエイティブ・コモンズ 表示 4.0 国際)は、掲載先の書き方で書き手の空け方ではない。
199
206
  const licence = licenceNoticeSentences(doc, doc.lexicons["licence-word"] ?? []);
200
207
  const located: Located[] = doc.sentences.flatMap((sentence) => {
201
208
  if (licence.has(sentence)) return [];
202
- const quoted = quotedSpans(sentence.text);
209
+ // 「」『』のほか、“”で引いた題名(“パブリック・ドメイン・マーク 1.0 全世界コモンズ証”)も元の書き方。
210
+ const quoted = quotedSpans(sentence.text, QUOTATION_MARKS);
203
211
  const codes = {
204
212
  calendar: calendarStarts(sentence, context.calendar),
205
213
  clockTimes: clockTimeSpans(sentence.text),
206
214
  addresses: addressSpans(sentence.text),
207
215
  identifiers: identifierSpans(sentence.text),
208
216
  };
209
- return latinBoundaries(sentence.text, doc.source.slice(sentence.span.start, sentence.span.end))
210
- .filter((boundary) => !isQuoted(quoted, boundary) && !isInsideLink(doc.links, sentence.span.start + boundary.offset))
211
- .filter((boundary) => isCounted(sentence, boundary, context, codes))
212
- .map((boundary) => ({ sentence, ...boundary }));
217
+ return (
218
+ latinBoundaries(sentence.text, doc.source.slice(sentence.span.start, sentence.span.end))
219
+ .filter((boundary) => !isQuoted(quoted, boundary) && !isInsideLink(doc.links, sentence.span.start + boundary.offset))
220
+ .filter((boundary) => !isCitedEntryLine(lineAt(doc.source, sentence.span.start + boundary.offset)))
221
+ // 変換で一続きになった数の表の、升の区切りの空白。
222
+ .filter((boundary) => !isNumberTableBoundary(sentence.text, boundary))
223
+ .filter((boundary) => isCounted(sentence, boundary, context, codes))
224
+ .map((boundary) => ({ sentence, ...boundary }))
225
+ );
213
226
  });
214
227
  return KINDS.flatMap((kind) =>
215
228
  findingsOf(
@@ -1,4 +1,5 @@
1
1
  import type { Lexicon } from "../plugin.ts";
2
+ import { joinedBlanks } from "./blank-runs.ts";
2
3
 
3
4
  type Span = { readonly start: number; readonly end: number };
4
5
 
@@ -110,6 +111,18 @@ const endsWithAny = (text: string, words: Lexicon): boolean => words.some((word)
110
111
 
111
112
  type BlankWords = { readonly suffixes: Lexicon; readonly prefixes: Lexicon; readonly units: Lexicon };
112
113
 
114
+ /** 行の残りが空白と伏せ字だけか(「代表取締役 〇〇 〇〇」の姓の後ろ)。 */
115
+ const ONLY_BLANKS = /^[\s○〇◯△]*$/u;
116
+ /** 項目名のコロンか空白の後ろ(「氏名:〇〇」「総務部長 〇〇」)。行の終わりまで伏せ字なら、その値が空欄。 */
117
+ const VALUE_SEPARATOR = /[\s::]$/u;
118
+ /** 番号の組を繋ぐハイフン(〒〇〇〇-〇〇〇〇、03-〇〇〇〇-〇〇〇〇)。伏せ字がその一組なら、番号の空欄。 */
119
+ const NUMBER_JOIN_BEFORE = /[-‐-][\d○〇◯]*$/u;
120
+ const NUMBER_JOIN_AFTER = /^[-‐-]/u;
121
+
122
+ /** 名前の長さの伏せ字が、行の終わりまで続く値か、番号の一組か。 */
123
+ const isValueOrNumberBlank = (lineBefore: string, lineAfter: string): boolean =>
124
+ (VALUE_SEPARATOR.test(lineBefore) && ONLY_BLANKS.test(lineAfter)) || NUMBER_JOIN_BEFORE.test(lineBefore) || NUMBER_JOIN_AFTER.test(lineAfter);
125
+
113
126
  /** 記号の並びが空欄の位置にあるか。あれば、空欄として言う範囲(後ろに付いた語まで)。 */
114
127
  const blankSpanAt = (text: string, match: RegExpExecArray, words: BlankWords): Span | undefined => {
115
128
  const start = match.index;
@@ -122,6 +135,7 @@ const blankSpanAt = (text: string, match: RegExpExecArray, words: BlankWords): S
122
135
  if (suffix !== undefined) return { start, end: end + suffix.pattern.length };
123
136
  if (endsWithAny(before.trimEnd(), words.prefixes)) return { start, end };
124
137
  if (atLineHead(before) && lineAfter.trim() === "") return { start, end };
138
+ if (isValueOrNumberBlank(before.split("\n").at(-1) ?? "", lineAfter)) return { start, end };
125
139
  }
126
140
  const unit = startsWithAny(after, words.units);
127
141
  if (unit === undefined || NUMERAL_BEFORE.test(before)) return undefined;
@@ -135,10 +149,13 @@ const blankSpanAt = (text: string, match: RegExpExecArray, words: BlankWords): S
135
149
  const blankMarkSpans = (text: string, words: BlankWords): Span[] =>
136
150
  words.suffixes.length + words.prefixes.length + words.units.length === 0
137
151
  ? []
138
- : [...text.matchAll(BLANK_MARKS)].flatMap((match) => {
139
- const span = blankSpanAt(text, match, words);
140
- return span === undefined ? [] : [span];
141
- });
152
+ : joinedBlanks(
153
+ text,
154
+ [...text.matchAll(BLANK_MARKS)].flatMap((match) => {
155
+ const span = blankSpanAt(text, match, words);
156
+ return span === undefined ? [] : [span];
157
+ }),
158
+ );
142
159
 
143
160
  /** 文の中の、埋め忘れた雛形の空欄([Your Name]、【会社名】、(ここに会社名を書く)、TBD: …、〇〇様)の範囲。words は placeholder-word の語彙表。 */
144
161
  export const placeholderSpans = (text: string, words: Lexicon): Span[] => {
@@ -6,7 +6,7 @@
6
6
  import { QUOTATION_MARKS, quotedSpans } from "../quoted-span.ts";
7
7
  import { readMarkdown } from "../markdown-read.ts";
8
8
  import { blockQuotations, type BlockQuotation } from "./block-quotation.ts";
9
- import type { Detector, Finding, LexiconEntry, ProseDocument } from "../plugin.ts";
9
+ import type { Detector, Finding, LexiconEntry, Paragraph, ProseDocument } from "../plugin.ts";
10
10
 
11
11
  export type QuoteText = { readonly start: number; readonly text: string };
12
12
 
@@ -56,8 +56,11 @@ const cueStarts = (text: string, cue: string): number[] => {
56
56
 
57
57
  type Quoted = { readonly start: number; readonly end: number };
58
58
 
59
- /** The word lists the rule reads: quote-attribution, and quote-advice (「…」と述べる方が: a wording suggested, not quoted). */
60
- export type QuoteWords = { readonly cues: readonly LexiconEntry[]; readonly advice?: readonly LexiconEntry[] };
59
+ /**
60
+ * The word lists the rule reads: quote-attribution, quote-advice (「…」と述べる方が: a wording suggested, not quoted), and
61
+ * quote-not-attribution (an example made up by the writer, words received, words written on a thing).
62
+ */
63
+ export type QuoteWords = { readonly cues: readonly LexiconEntry[]; readonly advice?: readonly LexiconEntry[]; readonly not?: readonly LexiconEntry[] };
61
64
 
62
65
  const patternsIn = (entries: readonly LexiconEntry[], group: string): string[] =>
63
66
  entries.filter((entry) => entry.group === group && entry.pattern !== "").map((entry) => entry.pattern);
@@ -72,12 +75,27 @@ const isAdvice = (text: string, quoted: Quoted, advice: readonly LexiconEntry[])
72
75
  return patternsIn(advice, "say").some((say) => text.startsWith(say, after) && tails.some((tail) => text.startsWith(tail, after + say.length)));
73
76
  };
74
77
 
78
+ /** A word of the group stands in the text (an English one as a whole word, ignoring case). */
79
+ const standsIn = (text: string, entries: readonly LexiconEntry[], group: string): boolean =>
80
+ patternsIn(entries, group).some((word) => cueStarts(text, word).length > 0);
81
+
82
+ /** Words received rather than quoted, right after the closing mark: 「…」と言われて、送れない. */
83
+ const isReceived = (text: string, quoted: Quoted, not: readonly LexiconEntry[]): boolean =>
84
+ patternsIn(not, "received").some((tail) => text.startsWith(tail, quoted.end + 1));
85
+
86
+ /** The cue's subject is a thing, by the word right before it: a sign that said "…". */
87
+ const THING_GAP = /^\s+$/u;
88
+ const saidByThing = (text: string, at: number, not: readonly LexiconEntry[]): boolean =>
89
+ patternsIn(not, "thing").some((word) => cueStarts(text.slice(0, at), word).some((start) => THING_GAP.test(text.slice(start + word.length, at))));
90
+
75
91
  /** A cue just before the quotation's opening mark, or just after its closing mark. position says which side it may stand on. */
76
92
  /** Advice after the quotation silences only the cue after it: 山田氏によれば「…」と言う方が適切だ still gives the words to someone. */
77
- const isAttributed = (text: string, quoted: Quoted, { cues, advice = [] }: QuoteWords): boolean => {
78
- const advised = isAdvice(text, quoted, advice);
93
+ const isAttributed = (text: string, quoted: Quoted, { cues, advice = [], not = [] }: QuoteWords): boolean => {
94
+ if (standsIn(text.slice(0, quoted.start), not, "example")) return false;
95
+ const advised = isAdvice(text, quoted, advice) || isReceived(text, quoted, not);
79
96
  return cues.some((cue) =>
80
97
  cueStarts(text, cue.pattern).some((at) => {
98
+ if (saidByThing(text, at, not)) return false;
81
99
  const before = cue.position !== "after" && at + cue.pattern.length <= quoted.start - 1 && at + cue.pattern.length >= quoted.start - 1 - CUE_REACH_BEFORE;
82
100
  const after = !advised && cue.position !== "before" && at >= quoted.end + 1 && at <= quoted.end + 1 + CUE_REACH_AFTER;
83
101
  return before || after;
@@ -85,17 +103,27 @@ const isAttributed = (text: string, quoted: Quoted, { cues, advice = [] }: Quote
85
103
  );
86
104
  };
87
105
 
106
+ /** A Latin-script quotation with no space in it is one word, a term or a value ("core_claim_false"), not someone's words. */
107
+ const isOneWord = (quote: string): boolean => LATIN.test(quote) && !/\s/u.test(quote);
108
+
109
+ const isWords = (quote: string): boolean => [...quote].length >= MIN_QUOTE_CHARS && !isOneWord(quote);
110
+
88
111
  const quotesIn = (sentence: QuoteText, words: QuoteWords): UnsourcedQuote[] => {
89
112
  return quotedSpans(sentence.text, QUOTATION_MARKS)
90
- .filter((span) => [...sentence.text.slice(span.start, span.end).trim()].length >= MIN_QUOTE_CHARS && isAttributed(sentence.text, span, words))
113
+ .filter((span) => isWords(sentence.text.slice(span.start, span.end).trim()) && isAttributed(sentence.text, span, words))
91
114
  .map((span) => ({ offset: sentence.start + span.start, quote: sentence.text.slice(span.start, span.end).trim() }));
92
115
  };
93
116
 
94
117
  /** Each quotation given to someone, in a paragraph that names no source. cues: the word list quote-attribution. */
95
- export const unsourcedQuotes = (paragraphs: readonly QuoteParagraph[], cues: readonly LexiconEntry[], advice: readonly LexiconEntry[] = []): UnsourcedQuote[] =>
118
+ export const unsourcedQuotes = (
119
+ paragraphs: readonly QuoteParagraph[],
120
+ cues: readonly LexiconEntry[],
121
+ advice: readonly LexiconEntry[] = [],
122
+ not: readonly LexiconEntry[] = [],
123
+ ): UnsourcedQuote[] =>
96
124
  paragraphs
97
125
  .filter((paragraph) => !namesSource(paragraph.source))
98
- .flatMap((paragraph) => paragraph.sentences.flatMap((sentence) => quotesIn(sentence, { cues, advice })));
126
+ .flatMap((paragraph) => paragraph.sentences.flatMap((sentence) => quotesIn(sentence, { cues, advice, not })));
99
127
 
100
128
  /** Each block quotation given to someone by a dash line (— Name) with no source in it or on that line. */
101
129
  export const unsourcedBlockQuotes = (quotations: readonly BlockQuotation[]): UnsourcedQuote[] =>
@@ -112,14 +140,28 @@ const blockQuotesOf = (doc: ProseDocument): UnsourcedQuote[] => {
112
140
  return unsourcedBlockQuotes(blockQuotations(readMarkdown(doc.source).root, doc.source));
113
141
  };
114
142
 
143
+ /**
144
+ * The lines written together with a paragraph, with no blank line between: a note's quotation and the reference on the line
145
+ * above it are one block, and a source named there is named for the quotation.
146
+ */
147
+ const blockAround = (doc: ProseDocument, index: number): string => {
148
+ const joined = (left: Paragraph | undefined, right: Paragraph | undefined): boolean =>
149
+ left !== undefined && right !== undefined && !doc.source.slice(left.span.end, right.span.start).includes("\n\n");
150
+ const first = doc.paragraphs.slice(0, index + 1).findLastIndex((paragraph, at) => !joined(doc.paragraphs[at - 1], paragraph));
151
+ const after = doc.paragraphs.slice(index).findIndex((paragraph, offset) => !joined(paragraph, doc.paragraphs[index + offset + 1]));
152
+ const last = doc.paragraphs[index + after] ?? doc.paragraphs[index];
153
+ return doc.source.slice(doc.paragraphs[first]?.span.start ?? 0, last?.span.end ?? 0);
154
+ };
155
+
115
156
  const paragraphQuotesOf = (doc: ProseDocument): UnsourcedQuote[] =>
116
157
  unsourcedQuotes(
117
- doc.paragraphs.map((paragraph) => ({
118
- source: doc.source.slice(paragraph.span.start, paragraph.span.end),
158
+ doc.paragraphs.map((paragraph, index) => ({
159
+ source: blockAround(doc, index),
119
160
  sentences: paragraph.sentences.map((sentence) => ({ start: sentence.span.start, text: sentence.text })),
120
161
  })),
121
162
  doc.lexicons["quote-attribution"] ?? [],
122
163
  doc.lexicons["quote-advice"] ?? [],
164
+ doc.lexicons["quote-not-attribution"] ?? [],
123
165
  );
124
166
 
125
167
  /** Every quotation in the document given to someone with no source, in document order: what the rule and `cite --scaffold` list. */
@@ -0,0 +1,42 @@
1
+ import type { Section, Sentence } from "../plugin.ts";
2
+
3
+ // A document that holds two texts under two top-level headings (a directive, then the agency's page about it) may write each in
4
+ // its own register. A part whose sentences all share the register the rest of the document does not use is a text of its own,
5
+ // not a slip in the other. Pure.
6
+
7
+ /** The depth of a top-level heading: a part of the document starts at each one. */
8
+ const PART_DEPTH = 1;
9
+
10
+ /** One sentence alone in the other register may still be a slip; a part is read as its own text from two on. */
11
+ const MIN_SENTENCES = 2;
12
+
13
+ /** The sentences of each part opened by a top-level heading, in order, when the document has two such parts or more. */
14
+ const partsOf = (sections: readonly Section[]): Sentence[][] => {
15
+ const parts = sections.reduce<Sentence[][]>((found, section) => {
16
+ if (section.depth === PART_DEPTH) return [...found, [...section.sentences]];
17
+ const last = found.at(-1);
18
+ if (section.depth > PART_DEPTH && last !== undefined) last.push(...section.sentences);
19
+ return found;
20
+ }, []);
21
+ return parts.length >= 2 ? parts : [];
22
+ };
23
+
24
+ /**
25
+ * The sentences of every top-level part whose counted sentences (registerOf gives a register) are MIN_SENTENCES or more and all
26
+ * in one register other than majority, the register of the document as a whole.
27
+ */
28
+ export const separatePartSentences = <R>(
29
+ sections: readonly Section[],
30
+ registerOf: (sentence: Sentence) => R | undefined,
31
+ majority: R | undefined,
32
+ ): Set<Sentence> =>
33
+ new Set(
34
+ partsOf(sections).flatMap((sentences) => {
35
+ const registers = sentences.flatMap((sentence) => {
36
+ const register = registerOf(sentence);
37
+ return register === undefined ? [] : [register];
38
+ });
39
+ const own = registers.length >= MIN_SENTENCES && registers.every((register) => register === registers[0] && register !== majority);
40
+ return own ? sentences : [];
41
+ }),
42
+ );
@@ -1,4 +1,4 @@
1
1
  import type { Detector } from "../../plugin.ts";
2
- import { contractionMix } from "../lexicon.ts";
2
+ import { contractionMix } from "../contraction-mix.ts";
3
3
 
4
4
  export const detector: Detector = contractionMix;
@@ -1,4 +1,4 @@
1
1
  import type { Detector } from "../../plugin.ts";
2
- import { duplicateDefinition } from "../structure-tree.ts";
2
+ import { duplicateDefinition } from "../duplicate-definition.ts";
3
3
 
4
4
  export const detector: Detector = duplicateDefinition;
@@ -0,0 +1,33 @@
1
+ import type { Paragraph, Span, StructureNode } from "../plugin.ts";
2
+ import { articlesInCitedDocuments } from "../structure/cited-document-section.ts";
3
+
4
+ // Text the writer reproduces from another document, word for word: the articles of a statute copied under a heading that
5
+ // names it (### …に関する法律 / 第7条 …), and a paragraph after a lead-in that says it is reproduced (The entire receipt
6
+ // reads as follows:). Its sentences are the source's, not the writer's to shorten. Pure.
7
+
8
+ /** A lead-in closes its paragraph with a colon. */
9
+ const ENDS_WITH_COLON = /[::]\s*$/u;
10
+
11
+ const isVerbatimLead = (text: string, leads: readonly string[]): boolean =>
12
+ ENDS_WITH_COLON.test(text) && leads.some((lead) => text.toLowerCase().includes(lead.toLowerCase()));
13
+
14
+ /** The paragraphs right after a lead-in that says the next text is reproduced (reads as follows:, 次のように規定している:). */
15
+ const afterVerbatimLeads = (paragraphs: readonly Paragraph[], source: string, leads: readonly string[]): Span[] =>
16
+ paragraphs.flatMap((paragraph, at) => {
17
+ const next = paragraphs[at + 1];
18
+ return next !== undefined && isVerbatimLead(source.slice(paragraph.span.start, paragraph.span.end), leads) ? [next.span] : [];
19
+ });
20
+
21
+ /** The spans of reproduced text: copied articles of a cited statute, and the paragraph after a verbatim lead-in. */
22
+ export const reproducedSpans = (
23
+ structure: StructureNode | undefined,
24
+ paragraphs: readonly Paragraph[],
25
+ source: string,
26
+ leads: readonly string[],
27
+ ): readonly Span[] => [
28
+ ...(structure === undefined ? [] : articlesInCitedDocuments(structure).map((article) => article.span)),
29
+ ...afterVerbatimLeads(paragraphs, source, leads),
30
+ ];
31
+
32
+ export const isReproduced = (span: Span, reproduced: readonly Span[]): boolean =>
33
+ reproduced.some((outer) => outer.start <= span.start && span.end <= outer.end);
@@ -20,6 +20,7 @@ export const REQUEST_LEXICONS = {
20
20
  contact: "request-contact",
21
21
  prohibition: "request-prohibition",
22
22
  deadlineSection: "request-deadline-section",
23
+ noDeadlineTitle: "request-no-deadline-title",
23
24
  } as const;
24
25
 
25
26
  type Words = Readonly<Record<keyof typeof REQUEST_LEXICONS, readonly string[]>>;
@@ -42,6 +43,7 @@ const wordsOf = (doc: ProseDocument): Words => ({
42
43
  contact: patternsOf(doc.lexicons[REQUEST_LEXICONS.contact]),
43
44
  prohibition: patternsOf(doc.lexicons[REQUEST_LEXICONS.prohibition]),
44
45
  deadlineSection: patternsOf(doc.lexicons[REQUEST_LEXICONS.deadlineSection]),
46
+ noDeadlineTitle: patternsOf(doc.lexicons[REQUEST_LEXICONS.noDeadlineTitle]),
45
47
  });
46
48
 
47
49
  /** How far apart, in characters, the action word and the request ending may be: the action must be what is requested. */
@@ -228,26 +230,47 @@ const statesDeadline = (source: string, sentence: Sentence, words: Words, dates:
228
230
  };
229
231
 
230
232
  /**
231
- * Where a section headed only by a deadline-section word (a notice's "DATES:", "2. Deadline") states a date with a
232
- * deadline word: the document gives its deadline once there, for the requests that follow it. Undefined without one.
233
+ * The section headed only by a deadline-section word (a notice's "DATES:", "2. Deadline") that states a date with a
234
+ * deadline word: the document gives its deadline once there. -1 without one.
233
235
  */
234
- const documentDeadlineAt = (source: string, sections: readonly Section[], words: Words, dates: readonly Span[]): number | undefined =>
235
- sections.find(
236
+ const documentDeadlineSection = (source: string, sections: readonly Section[], words: Words, dates: readonly Span[]): number =>
237
+ sections.findIndex(
236
238
  (section) =>
237
239
  words.deadlineSection.includes(withoutHeadingEnd(comparableWords(section.unlabeledHeading ?? section.heading)).trim()) &&
238
240
  section.sentences.some((sentence) => statesDeadline(source, sentence, words, dates)),
239
- )?.span.start;
241
+ );
242
+
243
+ /**
244
+ * Whether the deadline section at index covers the offset: everything after it, and a section before it at its own level
245
+ * under the same heading (a proposal's 結論 asks, its 判断の期限 says by when). Text before the sections, or under another
246
+ * heading, is not covered.
247
+ */
248
+ const coveredByDeadline = (sections: readonly Section[], deadline: number, offset: number): boolean => {
249
+ const section = sections[deadline];
250
+ if (section === undefined) return false;
251
+ if (offset > section.span.start) return true;
252
+ const own = sections.findLastIndex((candidate) => candidate.span.start <= offset);
253
+ const between = sections.slice(own + 1, deadline);
254
+ return own >= 0 && sections[own]?.depth === section.depth && section.depth > 0 && between.every((other) => other.depth >= section.depth);
255
+ };
256
+
257
+ /** A document whose title names a kind that asks without a deadline by its nature (a 諮問 asks a council to deliberate). */
258
+ const asksWithoutDeadline = (sections: readonly Section[], words: Words): boolean => {
259
+ const title = sections.find((section) => section.depth > 0)?.heading;
260
+ return title !== undefined && containsAny(title, words.noDeadlineTitle);
261
+ };
240
262
 
241
263
  /**
242
264
  * The request sentences with neither a deadline nor a person in them, in the sentence after (same paragraph or item), in a
243
- * heading above, or in a deadline section before them.
265
+ * heading above, or in a deadline section that covers them; none in a document that asks without a deadline by its kind.
244
266
  */
245
267
  export const ownerlessRequests = (doc: ProseDocument): Sentence[] => {
246
268
  const words = wordsOf(doc);
247
269
  const dates = dateSpans(doc.structure);
248
- const deadlineAt = documentDeadlineAt(doc.source, doc.sections, words, dates) ?? Number.POSITIVE_INFINITY;
270
+ if (asksWithoutDeadline(doc.sections, words)) return [];
271
+ const deadline = documentDeadlineSection(doc.source, doc.sections, words, dates);
249
272
  return doc.sentences.filter((sentence, index) => {
250
- if (sentence.span.start > deadlineAt) return false;
273
+ if (coveredByDeadline(doc.sections, deadline, sentence.span.start)) return false;
251
274
  if (!isRequest(proseText(sentence), words) || saysWhenOrWho(sentence, words, dates, true)) return false;
252
275
  if (notesContactLine(doc.source, doc.sentences[index - 1], sentence, words)) return false;
253
276
  const next = doc.sentences[index + 1];
@@ -5,6 +5,8 @@ import { classWordsOf, isClassCue, namesClassAfter } from "./open-end-class.ts";
5
5
  import { glossesCondition } from "./open-end-condition.ts";
6
6
  import { openEndAt, openEndNames, type OpenEndNames } from "./open-end-names.ts";
7
7
  import { asksAfter, questionWordsOf } from "./open-end-question.ts";
8
+ import { anaphorWordsOf, isAnaphorCue, refersBack } from "./open-end-anaphor.ts";
9
+ import { itemsOpenOnPurpose } from "./open-end-lead.ts";
8
10
  import { isScopeCue, openOnPurpose, scopeWordsOf } from "./open-end-scope.ts";
9
11
  import { statesConcrete } from "./vague-deadline.ts";
10
12
 
@@ -70,12 +72,12 @@ const boundedInTime = (doc: ProseDocument, sentence: Sentence, entry: LexiconEnt
70
72
  * lexicon also holds the cues of a class named after the list and of what holds it, which are no smell.
71
73
  */
72
74
  const smellWords = (doc: ProseDocument, lexicon: string, genre: string | undefined): LexiconEntry[] =>
73
- entriesForGenre(doc.lexicons[lexicon] ?? [], genre).filter((entry) => !isClassCue(entry) && !isScopeCue(entry));
75
+ entriesForGenre(doc.lexicons[lexicon] ?? [], genre).filter((entry) => !isClassCue(entry) && !isScopeCue(entry) && !isAnaphorCue(entry));
74
76
 
75
77
  /**
76
78
  * Where the word stands as a smell. An open-end word inside a name the document gives (業務執行取締役等), giving examples
77
- * of a class named right after it (印刷等、二次的に利用), or ending a list a condition, a permission or a prohibition holds
78
- * (転載等をしてはならない), is none; without tokens none of these can be told apart.
79
+ * of a class named right after it (印刷等、二次的に利用), ending a list a condition, a permission or a prohibition holds
80
+ * (転載等をしてはならない), or ending a list a pointing word opens (当該改良、改善等), is none; without tokens none of these can be told apart.
79
81
  */
80
82
  const smellAt = (doc: ProseDocument, sentence: Sentence, entry: LexiconEntry, lexicon: string, names: () => OpenEndNames): number | undefined => {
81
83
  if (!entryIn(sentence, entry) || boundedInTime(doc, sentence, entry, lexicon)) return undefined;
@@ -83,7 +85,14 @@ const smellAt = (doc: ProseDocument, sentence: Sentence, entry: LexiconEntry, le
83
85
  if (lexicon !== OPEN_END || !tokenized) return offsetOf(sentence, entry);
84
86
  const classWords = classWordsOf(doc.lexicons[OPEN_END] ?? []);
85
87
  const scopeWords = scopeWordsOf(doc.lexicons[OPEN_END] ?? []);
86
- return openEndAt(doc, sentence, entry, names(), (tokens, range) => namesClassAfter(tokens, range, classWords) || openOnPurpose(tokens, range, scopeWords));
88
+ const anaphors = anaphorWordsOf(doc.lexicons[OPEN_END] ?? []);
89
+ return openEndAt(
90
+ doc,
91
+ sentence,
92
+ entry,
93
+ names(),
94
+ (tokens, range) => namesClassAfter(tokens, range, classWords) || openOnPurpose(tokens, range, scopeWords) || refersBack(tokens, range, anaphors),
95
+ );
87
96
  };
88
97
 
89
98
  /** An open list right before a question the reader answers (…措置など、どのような措置を求めるのか): its items are example answers. */
@@ -118,5 +127,12 @@ export const requirementSmell: Detector = (doc, options): Finding[] => {
118
127
  // Read once, and only when a requirement has an open-end word to tell apart from a name.
119
128
  const cache: { names?: OpenEndNames } = {};
120
129
  const names = (): OpenEndNames => (cache.names ??= openEndNames(doc, smellWords(doc, OPEN_END, options.genre), statements));
121
- return doc.sentences.filter((sentence) => isRequirement(sentence, markers, notMarkers)).flatMap((sentence) => smellsIn(doc, sentence, options.genre, names));
130
+ const onPurpose = scopeWordsOf(doc.lexicons[OPEN_END] ?? []).onPurpose;
131
+ const openItems = itemsOpenOnPurpose(doc.source, doc.sentences, doc.lists, onPurpose);
132
+ return doc.sentences.flatMap((sentence, index) => {
133
+ if (!isRequirement(sentence, markers, notMarkers)) return [];
134
+ const findings = smellsIn(doc, sentence, options.genre, names);
135
+ // An item under a lead that forbids or permits it: its list is open on purpose, like the lead's own.
136
+ return openItems.has(index) ? findings.filter((finding) => finding.variant !== "open-end") : findings;
137
+ });
122
138
  };
@@ -2,7 +2,7 @@ import type { Detector, DetectorOptions, Finding, Lexicon, ProseDocument, Senten
2
2
  import { escapeRegExp } from "../orthography.ts";
3
3
  import { isWithinAny, quotedIn } from "../quoted-span.ts";
4
4
  import { entryOpens } from "./lexicon-match.ts";
5
- import { laterAlternatives } from "../alternative-words.ts";
5
+ import { laterAlternatives, laterJoined } from "../alternative-words.ts";
6
6
  import { isContrastiveGa } from "./adversative-ga.ts";
7
7
 
8
8
  type TokenTest = (token: Token, at: number, tokens: readonly Token[]) => boolean;
@@ -45,25 +45,45 @@ const sentencesOver = (doc: ProseDocument, limit: number, test: TokenTest, fixed
45
45
  return counted.length > limit ? [findingOf(sentence, counted, limit)] : [];
46
46
  });
47
47
 
48
+ /** The counted words that only repeat the point of the one before: a later option of a choice, a later half of a joined pair. */
49
+ const laterOfOnePoint = (tokens: readonly Token[], counted: readonly number[]): ReadonlySet<number> =>
50
+ new Set([...laterAlternatives(tokens, counted), ...laterJoined(tokens, counted)]);
51
+
52
+ /** A mark that opens an item with a circled number (③): an item of a list written inside the sentence. */
53
+ const CIRCLED_ITEM = /^[①-⒇❶-❿]/u;
54
+
55
+ /** The counted tokens of the sentence's largest part, the sentence cut before each circled item mark (①Credit:…、②…). */
56
+ const largestItem = (sentence: Sentence, counted: readonly Token[]): readonly Token[] => {
57
+ const marks = (sentence.tokens ?? []).filter((token) => CIRCLED_ITEM.test(token.surface)).map((token) => token.span.start);
58
+ const itemOf = (token: Token): number => marks.filter((start) => start <= token.span.start).length;
59
+ const items = counted.reduce((byItem, token) => byItem.set(itemOf(token), [...(byItem.get(itemOf(token)) ?? []), token]), new Map<number, Token[]>());
60
+ return [...items.values()].reduce<readonly Token[]>((largest, item) => (item.length > largest.length ? item : largest), []);
61
+ };
62
+
48
63
  /**
49
64
  * A sentence holding more than limit tokens written as one of the lexicon's words (the suffix 的). The options of one choice
50
- * (連続的か断続的か、一時的) count once: they name one point, the kinds a thing may be.
65
+ * (連続的か断続的か、一時的) and a joined pair (信仰的主観的) count once: each names one point. A list written inside the sentence
66
+ * (①…、②…) is counted item by item, as each item is a point of its own.
51
67
  */
52
68
  export const sentenceWordCount: Detector = (doc, options): Finding[] => {
53
69
  const words = wordsOf(options.lexicon);
54
- const alternatives = new WeakMap<readonly Token[], ReadonlySet<number>>();
70
+ const onePoint = new WeakMap<readonly Token[], ReadonlySet<number>>();
55
71
  const laterOf = (tokens: readonly Token[]): ReadonlySet<number> => {
56
- const known = alternatives.get(tokens);
72
+ const known = onePoint.get(tokens);
57
73
  if (known !== undefined) return known;
58
- const found = laterAlternatives(
74
+ const found = laterOfOnePoint(
59
75
  tokens,
60
76
  tokens.flatMap((token, at) => (words.has(token.surface) ? [at] : [])),
61
77
  );
62
- alternatives.set(tokens, found);
78
+ onePoint.set(tokens, found);
63
79
  return found;
64
80
  };
65
81
  const isCounted: TokenTest = (token, at, tokens) => words.has(token.surface) && !laterOf(tokens).has(at);
66
- return sentencesOver(doc, options.limit, isCounted, doc.lexicons[FIXED_TERM_LEXICON] ?? []);
82
+ const fixedTerms = doc.lexicons[FIXED_TERM_LEXICON] ?? [];
83
+ return doc.sentences.flatMap((sentence) => {
84
+ const counted = largestItem(sentence, countedTokens(sentence, isCounted, fixedTerms));
85
+ return counted.length > options.limit ? [findingOf(sentence, counted, options.limit)] : [];
86
+ });
67
87
  };
68
88
 
69
89
  const NOMINAL: ReadonlySet<string> = new Set(["NOUN", "PROPN", "NUM"]);
@@ -3,6 +3,7 @@ import { enumeratedRuns, enumeratorStarts, numberedStarts } from "./enumerated-r
3
3
  import { continuesThrough, groupOf, majorityOf, registerOf, slipsOf, type Register } from "./register.ts";
4
4
  import { isRunInLabel } from "./run-in-label.ts";
5
5
  import { noticeSentences } from "./notice-paragraph.ts";
6
+ import { separatePartSentences } from "./register-separate-part.ts";
6
7
  import { askerSentences } from "./asker-voice.ts";
7
8
  import { licenceNoticeSentences } from "./licence-notice.ts";
8
9
  import { chronologyRows } from "../chronology-rows.ts";
@@ -24,6 +25,7 @@ import type { Detector, Finding, LexiconEntry, ProseDocument, Sentence, Span, To
24
25
  * 文書の最後に掲載先が付けた利用条件の断り書き(…ライセンスの下に提供されています。)も数えない(licence-notice.ts)。
25
26
  * 札を付けて引いた言葉(例:…。Q: …?)、印を付けた札の行の下の記入欄の値(■ 調査目的\n…とする。)、
26
27
  * 〒や電話の行のある問い合わせ先の段落も数えない(register-set-apart.ts)。
28
+ * 一番上の見出しで分けた部分のうち、2 文以上がみな文書の多いほうと違う同じ調子のものは、別の文書として数えない(register-separate-part.ts)。
27
29
  */
28
30
  /**
29
31
  * quiet: 常体と読めるが、願い・問い・言いさしの形(register-neutral-shape.ts)の文。どちらの調子の文書にも現れるので指さない。
@@ -120,8 +122,10 @@ export const judgedSentences = (doc: ProseDocument, polite: readonly LexiconEntr
120
122
  });
121
123
  const registers = new Map(all.map((entry) => [entry.sentence, entry.register]));
122
124
  const majority = majorityOf(all.map((entry) => ({ register: entry.register, group: undefined })));
123
- const notices = noticeSentences(doc.paragraphs, doc.lexicons["notice-phrase"] ?? [], (sentence) => registers.get(sentence), majority);
124
- const found = all.filter((entry) => !notices.has(entry.sentence));
125
+ const registerAt = (sentence: Sentence): Register | undefined => registers.get(sentence);
126
+ const notices = noticeSentences(doc.paragraphs, doc.lexicons["notice-phrase"] ?? [], registerAt, majority);
127
+ const parts = separatePartSentences(doc.sections, registerAt, majority);
128
+ const found = all.filter((entry) => !notices.has(entry.sentence) && !parts.has(entry.sentence));
125
129
  const runs = runsOf(
126
130
  doc,
127
131
  found.map((entry) => entry.register),
@@ -1,10 +1,11 @@
1
1
  import { lengthOf, proseText } from "../measure.ts";
2
2
  import type { Detector, DetectorOptions, Finding, LengthUnit, Sentence } from "../plugin.ts";
3
3
  import { citationLead } from "./citation-sentence.ts";
4
- import { isCitationString } from "./citation-string.ts";
4
+ import { isCitationString, wordsAroundCitation } from "./citation-string.ts";
5
5
  import { isNameList } from "./name-list-sentence.ts";
6
6
  import { pageMarkerPattern, pageMarkerSize } from "./page-marker.ts";
7
7
  import { quotedSentenceParts } from "./quoted-sentences.ts";
8
+ import { isReproduced, reproducedSpans } from "./reproduced-text.ts";
8
9
  import { colonQuotationParts, flattenedTableParts, isGrammarBlock, labelLineParts } from "./sentence-parts.ts";
9
10
  import { isInListItem, isReferenceLine, isTitleLine, quotedTitleWords, remarkAfterTitle, termSeriesSaving } from "./sentence-title.ts";
10
11
 
@@ -61,6 +62,8 @@ const partsOf = (sentence: Sentence, text: string): readonly string[] | undefine
61
62
  const ownSize = (sentence: Sentence, unit: LengthUnit, words: SentenceWords): number => {
62
63
  const text = proseText(sentence);
63
64
  if (isUnwritten(sentence, text, unit, words)) return 0;
65
+ const aroundCitation = unit === "word" ? wordsAroundCitation(text, words.citationSignals) : undefined;
66
+ if (aroundCitation !== undefined) return sizeOf(aroundCitation, unit);
64
67
  const parts = partsOf(sentence, text);
65
68
  if (parts !== undefined) return Math.max(0, ...parts.map((part) => sizeOf(part, unit) - pageMarkerSize(part, words.markers, unit)));
66
69
  const remark = unit === "word" ? remarkAfterTitle(text) : undefined;
@@ -76,9 +79,21 @@ export const sentenceLength: Detector = (doc, options): Finding[] => {
76
79
  citationSignals: (doc.lexicons["citation-signal"] ?? []).map((entry) => entry.pattern),
77
80
  listItems: doc.lists.flatMap((list) => list.itemSpans),
78
81
  };
79
- return doc.sentences
82
+ const long = doc.sentences
80
83
  .map((sentence) => ({ sentence, measure: measureOf(sentence, doc.lengthUnit, options, words) }))
81
- .filter(({ sentence, measure }) => measure.size > measure.limit && !isNameList(proseText(sentence)))
84
+ .filter(({ sentence, measure }) => measure.size > measure.limit && !isNameList(proseText(sentence)));
85
+ // 他の文書から引き写した文(法律の条、「reads as follows:」の後の段落)は書き手の文ではない。探すのに文書の木を組むので、長い文があるときだけ。
86
+ const reproduced =
87
+ long.length === 0
88
+ ? []
89
+ : reproducedSpans(
90
+ doc.structure,
91
+ doc.paragraphs,
92
+ doc.source,
93
+ (doc.lexicons["verbatim-lead"] ?? []).map((entry) => entry.pattern),
94
+ );
95
+ return long
96
+ .filter(({ sentence }) => !isReproduced(sentence.span, reproduced))
82
97
  .map(({ sentence, measure }) => ({
83
98
  rule: "max-sentence-length",
84
99
  severity: "warning",
@@ -52,9 +52,12 @@ const MIN_GLUED_DATES = 3;
52
52
 
53
53
  const nonEmpty = (parts: readonly string[]): string[] => parts.map((part) => part.trim()).filter((part) => part !== "");
54
54
 
55
+ /** Whether the text holds cells of numbers a converter ran together (39,0439,677). */
56
+ export const hasGluedNumbers = (text: string): boolean => GLUED_NUMBER.test(text);
57
+
55
58
  /** The cells of a table a converter flattened into one sentence, cut at the glued numbers or at each row's date. */
56
59
  export const flattenedTableParts = (text: string): readonly string[] | undefined => {
57
- if (GLUED_NUMBER.test(text)) return nonEmpty(text.replace(NUMBER_RUN, (run) => (GLUED_NUMBER.test(run) ? CUT : run)).split(CUT));
60
+ if (hasGluedNumbers(text)) return nonEmpty(text.replace(NUMBER_RUN, (run) => (GLUED_NUMBER.test(run) ? CUT : run)).split(CUT));
58
61
  const rows = text.split(GLUED_DATE);
59
62
  return rows.length > MIN_GLUED_DATES ? nonEmpty(rows) : undefined;
60
63
  };