chaffjs 0.29.0 → 0.31.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 (681) hide show
  1. package/dist/announced-count.d.ts +2 -0
  2. package/dist/announced-count.d.ts.map +1 -1
  3. package/dist/announced-count.js +4 -3
  4. package/dist/announced-count.js.map +1 -1
  5. package/dist/contacts/addresses.d.ts +21 -0
  6. package/dist/contacts/addresses.d.ts.map +1 -0
  7. package/dist/contacts/addresses.js +144 -0
  8. package/dist/contacts/addresses.js.map +1 -0
  9. package/dist/contacts/emails.d.ts +11 -0
  10. package/dist/contacts/emails.d.ts.map +1 -0
  11. package/dist/contacts/emails.js +51 -0
  12. package/dist/contacts/emails.js.map +1 -0
  13. package/dist/contacts/variants.d.ts +14 -0
  14. package/dist/contacts/variants.d.ts.map +1 -0
  15. package/dist/contacts/variants.js +25 -0
  16. package/dist/contacts/variants.js.map +1 -0
  17. package/dist/derived/battery-runtime.d.ts +85 -0
  18. package/dist/derived/battery-runtime.d.ts.map +1 -0
  19. package/dist/derived/battery-runtime.js +217 -0
  20. package/dist/derived/battery-runtime.js.map +1 -0
  21. package/dist/derived/period-counts.d.ts +48 -0
  22. package/dist/derived/period-counts.d.ts.map +1 -0
  23. package/dist/derived/period-counts.js +128 -0
  24. package/dist/derived/period-counts.js.map +1 -0
  25. package/dist/derived/session-hours.d.ts +26 -0
  26. package/dist/derived/session-hours.d.ts.map +1 -0
  27. package/dist/derived/session-hours.js +29 -0
  28. package/dist/derived/session-hours.js.map +1 -0
  29. package/dist/derived/time-lengths.d.ts +37 -0
  30. package/dist/derived/time-lengths.d.ts.map +1 -0
  31. package/dist/derived/time-lengths.js +171 -0
  32. package/dist/derived/time-lengths.js.map +1 -0
  33. package/dist/derived/unit-counts.d.ts +7 -0
  34. package/dist/derived/unit-counts.d.ts.map +1 -0
  35. package/dist/derived/unit-counts.js +13 -0
  36. package/dist/derived/unit-counts.js.map +1 -0
  37. package/dist/derived/use-interval.d.ts +33 -0
  38. package/dist/derived/use-interval.d.ts.map +1 -0
  39. package/dist/derived/use-interval.js +93 -0
  40. package/dist/derived/use-interval.js.map +1 -0
  41. package/dist/derived/working-hours.d.ts +36 -0
  42. package/dist/derived/working-hours.d.ts.map +1 -0
  43. package/dist/derived/working-hours.js +55 -0
  44. package/dist/derived/working-hours.js.map +1 -0
  45. package/dist/detectors/acronym-expansion.d.ts +1 -1
  46. package/dist/detectors/acronym-expansion.d.ts.map +1 -1
  47. package/dist/detectors/acronym-expansion.js +46 -2
  48. package/dist/detectors/acronym-expansion.js.map +1 -1
  49. package/dist/detectors/announced-count.d.ts.map +1 -1
  50. package/dist/detectors/announced-count.js +1 -0
  51. package/dist/detectors/announced-count.js.map +1 -1
  52. package/dist/detectors/capacity-runtime.d.ts +7 -0
  53. package/dist/detectors/capacity-runtime.d.ts.map +1 -0
  54. package/dist/detectors/capacity-runtime.js +98 -0
  55. package/dist/detectors/capacity-runtime.js.map +1 -0
  56. package/dist/detectors/capitalised-term.d.ts +44 -0
  57. package/dist/detectors/capitalised-term.d.ts.map +1 -0
  58. package/dist/detectors/capitalised-term.js +101 -0
  59. package/dist/detectors/capitalised-term.js.map +1 -0
  60. package/dist/detectors/contact-variant.d.ts +3 -0
  61. package/dist/detectors/contact-variant.d.ts.map +1 -0
  62. package/dist/detectors/contact-variant.js +21 -0
  63. package/dist/detectors/contact-variant.js.map +1 -0
  64. package/dist/detectors/count-over-capacity.d.ts +4 -0
  65. package/dist/detectors/count-over-capacity.d.ts.map +1 -0
  66. package/dist/detectors/count-over-capacity.js +26 -0
  67. package/dist/detectors/count-over-capacity.js.map +1 -0
  68. package/dist/detectors/date-outside-period.d.ts.map +1 -1
  69. package/dist/detectors/date-outside-period.js +5 -1
  70. package/dist/detectors/date-outside-period.js.map +1 -1
  71. package/dist/detectors/date-stamp-order.d.ts +3 -0
  72. package/dist/detectors/date-stamp-order.d.ts.map +1 -0
  73. package/dist/detectors/date-stamp-order.js +24 -0
  74. package/dist/detectors/date-stamp-order.js.map +1 -0
  75. package/dist/detectors/defined-term-form.d.ts.map +1 -1
  76. package/dist/detectors/defined-term-form.js +57 -7
  77. package/dist/detectors/defined-term-form.js.map +1 -1
  78. package/dist/detectors/definition-use.d.ts +1 -1
  79. package/dist/detectors/definition-use.d.ts.map +1 -1
  80. package/dist/detectors/definition-use.js +4 -2
  81. package/dist/detectors/definition-use.js.map +1 -1
  82. package/dist/detectors/derived-numbers.d.ts +11 -1
  83. package/dist/detectors/derived-numbers.d.ts.map +1 -1
  84. package/dist/detectors/derived-numbers.js +74 -20
  85. package/dist/detectors/derived-numbers.js.map +1 -1
  86. package/dist/detectors/due-date.d.ts.map +1 -1
  87. package/dist/detectors/due-date.js +6 -0
  88. package/dist/detectors/due-date.js.map +1 -1
  89. package/dist/detectors/en-shape.d.ts.map +1 -1
  90. package/dist/detectors/en-shape.js +7 -4
  91. package/dist/detectors/en-shape.js.map +1 -1
  92. package/dist/detectors/event-deadline.d.ts +3 -0
  93. package/dist/detectors/event-deadline.d.ts.map +1 -0
  94. package/dist/detectors/event-deadline.js +24 -0
  95. package/dist/detectors/event-deadline.js.map +1 -0
  96. package/dist/detectors/fact-consistency.d.ts +1 -1
  97. package/dist/detectors/fact-consistency.d.ts.map +1 -1
  98. package/dist/detectors/fact-consistency.js +52 -3
  99. package/dist/detectors/fact-consistency.js.map +1 -1
  100. package/dist/detectors/heading-case.d.ts +5 -2
  101. package/dist/detectors/heading-case.d.ts.map +1 -1
  102. package/dist/detectors/heading-case.js +12 -4
  103. package/dist/detectors/heading-case.js.map +1 -1
  104. package/dist/detectors/heading-echo.d.ts +5 -0
  105. package/dist/detectors/heading-echo.d.ts.map +1 -1
  106. package/dist/detectors/heading-echo.js +14 -1
  107. package/dist/detectors/heading-echo.js.map +1 -1
  108. package/dist/detectors/layout-code.d.ts +5 -0
  109. package/dist/detectors/layout-code.d.ts.map +1 -0
  110. package/dist/detectors/layout-code.js +124 -0
  111. package/dist/detectors/layout-code.js.map +1 -0
  112. package/dist/detectors/measured-facts.d.ts +8 -0
  113. package/dist/detectors/measured-facts.d.ts.map +1 -0
  114. package/dist/detectors/measured-facts.js +18 -0
  115. package/dist/detectors/measured-facts.js.map +1 -0
  116. package/dist/detectors/name-variant-model-codes.d.ts +11 -0
  117. package/dist/detectors/name-variant-model-codes.d.ts.map +1 -0
  118. package/dist/detectors/name-variant-model-codes.js +21 -0
  119. package/dist/detectors/name-variant-model-codes.js.map +1 -0
  120. package/dist/detectors/name-variant.d.ts.map +1 -1
  121. package/dist/detectors/name-variant.js +78 -10
  122. package/dist/detectors/name-variant.js.map +1 -1
  123. package/dist/detectors/orthographic-variant.d.ts.map +1 -1
  124. package/dist/detectors/orthographic-variant.js +62 -7
  125. package/dist/detectors/orthographic-variant.js.map +1 -1
  126. package/dist/detectors/orthography.d.ts.map +1 -1
  127. package/dist/detectors/orthography.js +12 -6
  128. package/dist/detectors/orthography.js.map +1 -1
  129. package/dist/detectors/party-order.d.ts +3 -0
  130. package/dist/detectors/party-order.d.ts.map +1 -0
  131. package/dist/detectors/party-order.js +46 -0
  132. package/dist/detectors/party-order.js.map +1 -0
  133. package/dist/detectors/quantity-range.d.ts +3 -0
  134. package/dist/detectors/quantity-range.d.ts.map +1 -0
  135. package/dist/detectors/quantity-range.js +35 -0
  136. package/dist/detectors/quantity-range.js.map +1 -0
  137. package/dist/detectors/range-band.d.ts +5 -0
  138. package/dist/detectors/range-band.d.ts.map +1 -0
  139. package/dist/detectors/range-band.js +80 -0
  140. package/dist/detectors/range-band.js.map +1 -0
  141. package/dist/detectors/registry/capacity-runtime-mismatch.d.ts +3 -0
  142. package/dist/detectors/registry/capacity-runtime-mismatch.d.ts.map +1 -0
  143. package/dist/detectors/registry/capacity-runtime-mismatch.js +3 -0
  144. package/dist/detectors/registry/capacity-runtime-mismatch.js.map +1 -0
  145. package/dist/detectors/registry/connection-time-short.d.ts +3 -0
  146. package/dist/detectors/registry/connection-time-short.d.ts.map +1 -0
  147. package/dist/detectors/registry/connection-time-short.js +3 -0
  148. package/dist/detectors/registry/connection-time-short.js.map +1 -0
  149. package/dist/detectors/registry/contact-variant.d.ts +3 -0
  150. package/dist/detectors/registry/contact-variant.d.ts.map +1 -0
  151. package/dist/detectors/registry/contact-variant.js +3 -0
  152. package/dist/detectors/registry/contact-variant.js.map +1 -0
  153. package/dist/detectors/registry/count-over-capacity.d.ts +3 -0
  154. package/dist/detectors/registry/count-over-capacity.d.ts.map +1 -0
  155. package/dist/detectors/registry/count-over-capacity.js +3 -0
  156. package/dist/detectors/registry/count-over-capacity.js.map +1 -0
  157. package/dist/detectors/registry/date-stamp-order.d.ts +3 -0
  158. package/dist/detectors/registry/date-stamp-order.d.ts.map +1 -0
  159. package/dist/detectors/registry/date-stamp-order.js +3 -0
  160. package/dist/detectors/registry/date-stamp-order.js.map +1 -0
  161. package/dist/detectors/registry/duration-product-mismatch.d.ts +3 -0
  162. package/dist/detectors/registry/duration-product-mismatch.d.ts.map +1 -0
  163. package/dist/detectors/registry/duration-product-mismatch.js +3 -0
  164. package/dist/detectors/registry/duration-product-mismatch.js.map +1 -0
  165. package/dist/detectors/registry/event-deadline.d.ts +3 -0
  166. package/dist/detectors/registry/event-deadline.d.ts.map +1 -0
  167. package/dist/detectors/registry/event-deadline.js +3 -0
  168. package/dist/detectors/registry/event-deadline.js.map +1 -0
  169. package/dist/detectors/registry/interval-count-mismatch.d.ts +3 -0
  170. package/dist/detectors/registry/interval-count-mismatch.d.ts.map +1 -0
  171. package/dist/detectors/registry/interval-count-mismatch.js +3 -0
  172. package/dist/detectors/registry/interval-count-mismatch.js.map +1 -0
  173. package/dist/detectors/registry/layout-code-mismatch.d.ts +3 -0
  174. package/dist/detectors/registry/layout-code-mismatch.d.ts.map +1 -0
  175. package/dist/detectors/registry/layout-code-mismatch.js +3 -0
  176. package/dist/detectors/registry/layout-code-mismatch.js.map +1 -0
  177. package/dist/detectors/registry/party-order.d.ts +3 -0
  178. package/dist/detectors/registry/party-order.d.ts.map +1 -0
  179. package/dist/detectors/registry/party-order.js +3 -0
  180. package/dist/detectors/registry/party-order.js.map +1 -0
  181. package/dist/detectors/registry/quantity-range.d.ts +3 -0
  182. package/dist/detectors/registry/quantity-range.d.ts.map +1 -0
  183. package/dist/detectors/registry/quantity-range.js +3 -0
  184. package/dist/detectors/registry/quantity-range.js.map +1 -0
  185. package/dist/detectors/registry/range-band-mismatch.d.ts +3 -0
  186. package/dist/detectors/registry/range-band-mismatch.d.ts.map +1 -0
  187. package/dist/detectors/registry/range-band-mismatch.js +3 -0
  188. package/dist/detectors/registry/range-band-mismatch.js.map +1 -0
  189. package/dist/detectors/registry/rent-multiple-mismatch.d.ts +3 -0
  190. package/dist/detectors/registry/rent-multiple-mismatch.d.ts.map +1 -0
  191. package/dist/detectors/registry/rent-multiple-mismatch.js +3 -0
  192. package/dist/detectors/registry/rent-multiple-mismatch.js.map +1 -0
  193. package/dist/detectors/registry/requirement-lists.d.ts +3 -0
  194. package/dist/detectors/registry/requirement-lists.d.ts.map +1 -0
  195. package/dist/detectors/registry/requirement-lists.js +3 -0
  196. package/dist/detectors/registry/requirement-lists.js.map +1 -0
  197. package/dist/detectors/registry/return-type.d.ts +3 -0
  198. package/dist/detectors/registry/return-type.d.ts.map +1 -0
  199. package/dist/detectors/registry/return-type.js +3 -0
  200. package/dist/detectors/registry/return-type.js.map +1 -0
  201. package/dist/detectors/registry/scaled-quantity-mismatch.d.ts +3 -0
  202. package/dist/detectors/registry/scaled-quantity-mismatch.d.ts.map +1 -0
  203. package/dist/detectors/registry/scaled-quantity-mismatch.js +3 -0
  204. package/dist/detectors/registry/scaled-quantity-mismatch.js.map +1 -0
  205. package/dist/detectors/registry/step-time-sum-mismatch.d.ts +3 -0
  206. package/dist/detectors/registry/step-time-sum-mismatch.d.ts.map +1 -0
  207. package/dist/detectors/registry/step-time-sum-mismatch.js +3 -0
  208. package/dist/detectors/registry/step-time-sum-mismatch.js.map +1 -0
  209. package/dist/detectors/registry/time-range-reversed.d.ts +3 -0
  210. package/dist/detectors/registry/time-range-reversed.d.ts.map +1 -0
  211. package/dist/detectors/registry/time-range-reversed.js +3 -0
  212. package/dist/detectors/registry/time-range-reversed.js.map +1 -0
  213. package/dist/detectors/registry/unlisted-item-used.d.ts +3 -0
  214. package/dist/detectors/registry/unlisted-item-used.d.ts.map +1 -0
  215. package/dist/detectors/registry/unlisted-item-used.js +3 -0
  216. package/dist/detectors/registry/unlisted-item-used.js.map +1 -0
  217. package/dist/detectors/registry/walk-time-distance-mismatch.d.ts +3 -0
  218. package/dist/detectors/registry/walk-time-distance-mismatch.d.ts.map +1 -0
  219. package/dist/detectors/registry/walk-time-distance-mismatch.js +3 -0
  220. package/dist/detectors/registry/walk-time-distance-mismatch.js.map +1 -0
  221. package/dist/detectors/rent-multiple-mismatch.d.ts +3 -0
  222. package/dist/detectors/rent-multiple-mismatch.d.ts.map +1 -0
  223. package/dist/detectors/rent-multiple-mismatch.js +39 -0
  224. package/dist/detectors/rent-multiple-mismatch.js.map +1 -0
  225. package/dist/detectors/requirement-lists.d.ts +3 -0
  226. package/dist/detectors/requirement-lists.d.ts.map +1 -0
  227. package/dist/detectors/requirement-lists.js +46 -0
  228. package/dist/detectors/requirement-lists.js.map +1 -0
  229. package/dist/detectors/return-type.d.ts +3 -0
  230. package/dist/detectors/return-type.d.ts.map +1 -0
  231. package/dist/detectors/return-type.js +24 -0
  232. package/dist/detectors/return-type.js.map +1 -0
  233. package/dist/detectors/scaled-quantity.d.ts +3 -0
  234. package/dist/detectors/scaled-quantity.d.ts.map +1 -0
  235. package/dist/detectors/scaled-quantity.js +37 -0
  236. package/dist/detectors/scaled-quantity.js.map +1 -0
  237. package/dist/detectors/signals.d.ts.map +1 -1
  238. package/dist/detectors/signals.js +3 -1
  239. package/dist/detectors/signals.js.map +1 -1
  240. package/dist/detectors/step-time-sum.d.ts +3 -0
  241. package/dist/detectors/step-time-sum.d.ts.map +1 -0
  242. package/dist/detectors/step-time-sum.js +46 -0
  243. package/dist/detectors/step-time-sum.js.map +1 -0
  244. package/dist/detectors/structure-tree.d.ts +2 -0
  245. package/dist/detectors/structure-tree.d.ts.map +1 -1
  246. package/dist/detectors/structure-tree.js +31 -6
  247. package/dist/detectors/structure-tree.js.map +1 -1
  248. package/dist/detectors/structure.js +1 -1
  249. package/dist/detectors/structure.js.map +1 -1
  250. package/dist/detectors/technical-docs.d.ts +5 -0
  251. package/dist/detectors/technical-docs.d.ts.map +1 -1
  252. package/dist/detectors/technical-docs.js +12 -0
  253. package/dist/detectors/technical-docs.js.map +1 -1
  254. package/dist/detectors/time-order.d.ts +2 -0
  255. package/dist/detectors/time-order.d.ts.map +1 -1
  256. package/dist/detectors/time-order.js +33 -5
  257. package/dist/detectors/time-order.js.map +1 -1
  258. package/dist/detectors/undefined-term.d.ts.map +1 -1
  259. package/dist/detectors/undefined-term.js +19 -3
  260. package/dist/detectors/undefined-term.js.map +1 -1
  261. package/dist/detectors/unit-consistency.d.ts +1 -1
  262. package/dist/detectors/unit-consistency.d.ts.map +1 -1
  263. package/dist/detectors/unit-consistency.js +46 -38
  264. package/dist/detectors/unit-consistency.js.map +1 -1
  265. package/dist/detectors/unlisted-items.d.ts +3 -0
  266. package/dist/detectors/unlisted-items.d.ts.map +1 -0
  267. package/dist/detectors/unlisted-items.js +57 -0
  268. package/dist/detectors/unlisted-items.js.map +1 -0
  269. package/dist/detectors/use-count-words.d.ts +8 -0
  270. package/dist/detectors/use-count-words.d.ts.map +1 -0
  271. package/dist/detectors/use-count-words.js +20 -0
  272. package/dist/detectors/use-count-words.js.map +1 -0
  273. package/dist/detectors/use-interval.d.ts +3 -0
  274. package/dist/detectors/use-interval.d.ts.map +1 -0
  275. package/dist/detectors/use-interval.js +39 -0
  276. package/dist/detectors/use-interval.js.map +1 -0
  277. package/dist/detectors/walk-time-distance-mismatch.d.ts +4 -0
  278. package/dist/detectors/walk-time-distance-mismatch.d.ts.map +1 -0
  279. package/dist/detectors/walk-time-distance-mismatch.js +38 -0
  280. package/dist/detectors/walk-time-distance-mismatch.js.map +1 -0
  281. package/dist/document.d.ts.map +1 -1
  282. package/dist/document.js +4 -1
  283. package/dist/document.js.map +1 -1
  284. package/dist/facts/approximate-tolerance.d.ts +7 -0
  285. package/dist/facts/approximate-tolerance.d.ts.map +1 -0
  286. package/dist/facts/approximate-tolerance.js +16 -0
  287. package/dist/facts/approximate-tolerance.js.map +1 -0
  288. package/dist/facts/item-amounts.d.ts +18 -0
  289. package/dist/facts/item-amounts.d.ts.map +1 -0
  290. package/dist/facts/item-amounts.js +67 -0
  291. package/dist/facts/item-amounts.js.map +1 -0
  292. package/dist/facts/labelled-facts.d.ts +4 -0
  293. package/dist/facts/labelled-facts.d.ts.map +1 -1
  294. package/dist/facts/labelled-facts.js +21 -6
  295. package/dist/facts/labelled-facts.js.map +1 -1
  296. package/dist/facts/measure-units.d.ts +5 -0
  297. package/dist/facts/measure-units.d.ts.map +1 -0
  298. package/dist/facts/measure-units.js +28 -0
  299. package/dist/facts/measure-units.js.map +1 -0
  300. package/dist/facts/measures.d.ts +23 -4
  301. package/dist/facts/measures.d.ts.map +1 -1
  302. package/dist/facts/measures.js +68 -19
  303. package/dist/facts/measures.js.map +1 -1
  304. package/dist/facts/retention-periods.d.ts +51 -0
  305. package/dist/facts/retention-periods.d.ts.map +1 -0
  306. package/dist/facts/retention-periods.js +148 -0
  307. package/dist/facts/retention-periods.js.map +1 -0
  308. package/dist/facts/table-facts.d.ts +2 -0
  309. package/dist/facts/table-facts.d.ts.map +1 -1
  310. package/dist/facts/table-facts.js +2 -0
  311. package/dist/facts/table-facts.js.map +1 -1
  312. package/dist/facts/unit-conflicts.d.ts +3 -2
  313. package/dist/facts/unit-conflicts.d.ts.map +1 -1
  314. package/dist/facts/unit-conflicts.js +15 -7
  315. package/dist/facts/unit-conflicts.js.map +1 -1
  316. package/dist/facts/unit-equivalents.d.ts +13 -0
  317. package/dist/facts/unit-equivalents.d.ts.map +1 -0
  318. package/dist/facts/unit-equivalents.js +56 -0
  319. package/dist/facts/unit-equivalents.js.map +1 -0
  320. package/dist/facts/unit-tolerance.d.ts +4 -0
  321. package/dist/facts/unit-tolerance.d.ts.map +1 -0
  322. package/dist/facts/unit-tolerance.js +13 -0
  323. package/dist/facts/unit-tolerance.js.map +1 -0
  324. package/dist/facts/unit-word.d.ts +8 -0
  325. package/dist/facts/unit-word.d.ts.map +1 -0
  326. package/dist/facts/unit-word.js +34 -0
  327. package/dist/facts/unit-word.js.map +1 -0
  328. package/dist/facts/written-precision.d.ts +10 -0
  329. package/dist/facts/written-precision.d.ts.map +1 -0
  330. package/dist/facts/written-precision.js +20 -0
  331. package/dist/facts/written-precision.js.map +1 -0
  332. package/dist/kana-spelling.d.ts +12 -0
  333. package/dist/kana-spelling.d.ts.map +1 -1
  334. package/dist/kana-spelling.js +23 -0
  335. package/dist/kana-spelling.js.map +1 -1
  336. package/dist/model-codes.d.ts +23 -0
  337. package/dist/model-codes.d.ts.map +1 -0
  338. package/dist/model-codes.js +81 -0
  339. package/dist/model-codes.js.map +1 -0
  340. package/dist/name-spelling-chars.d.ts +16 -0
  341. package/dist/name-spelling-chars.d.ts.map +1 -0
  342. package/dist/name-spelling-chars.js +14 -0
  343. package/dist/name-spelling-chars.js.map +1 -0
  344. package/dist/name-variants.d.ts +8 -2
  345. package/dist/name-variants.d.ts.map +1 -1
  346. package/dist/name-variants.js +72 -7
  347. package/dist/name-variants.js.map +1 -1
  348. package/dist/name-word-order.d.ts +49 -0
  349. package/dist/name-word-order.d.ts.map +1 -0
  350. package/dist/name-word-order.js +114 -0
  351. package/dist/name-word-order.js.map +1 -0
  352. package/dist/phone-numbers.d.ts.map +1 -1
  353. package/dist/phone-numbers.js +22 -5
  354. package/dist/phone-numbers.js.map +1 -1
  355. package/dist/place-names.d.ts +12 -5
  356. package/dist/place-names.d.ts.map +1 -1
  357. package/dist/place-names.js +34 -14
  358. package/dist/place-names.js.map +1 -1
  359. package/dist/plugin.d.ts +12 -0
  360. package/dist/plugin.d.ts.map +1 -1
  361. package/dist/preamble-paragraphs.d.ts +2 -1
  362. package/dist/preamble-paragraphs.d.ts.map +1 -1
  363. package/dist/preamble-paragraphs.js +16 -1
  364. package/dist/preamble-paragraphs.js.map +1 -1
  365. package/dist/profile/parse.d.ts.map +1 -1
  366. package/dist/profile/parse.js +11 -0
  367. package/dist/profile/parse.js.map +1 -1
  368. package/dist/return-type.d.ts +33 -0
  369. package/dist/return-type.d.ts.map +1 -0
  370. package/dist/return-type.js +302 -0
  371. package/dist/return-type.js.map +1 -0
  372. package/dist/spacing-code.d.ts +6 -0
  373. package/dist/spacing-code.d.ts.map +1 -0
  374. package/dist/spacing-code.js +16 -0
  375. package/dist/spacing-code.js.map +1 -0
  376. package/dist/structure/amount-range.d.ts +2 -2
  377. package/dist/structure/amount-range.d.ts.map +1 -1
  378. package/dist/structure/amount-range.js +12 -5
  379. package/dist/structure/amount-range.js.map +1 -1
  380. package/dist/structure/capacity-count.d.ts +59 -0
  381. package/dist/structure/capacity-count.d.ts.map +1 -0
  382. package/dist/structure/capacity-count.js +118 -0
  383. package/dist/structure/capacity-count.js.map +1 -0
  384. package/dist/structure/connection-times.d.ts +56 -0
  385. package/dist/structure/connection-times.d.ts.map +1 -0
  386. package/dist/structure/connection-times.js +165 -0
  387. package/dist/structure/connection-times.js.map +1 -0
  388. package/dist/structure/counted-amounts.d.ts +6 -0
  389. package/dist/structure/counted-amounts.d.ts.map +1 -1
  390. package/dist/structure/counted-amounts.js +4 -4
  391. package/dist/structure/counted-amounts.js.map +1 -1
  392. package/dist/structure/date-order-tie.d.ts +13 -0
  393. package/dist/structure/date-order-tie.d.ts.map +1 -0
  394. package/dist/structure/date-order-tie.js +61 -0
  395. package/dist/structure/date-order-tie.js.map +1 -0
  396. package/dist/structure/date-order.d.ts +2 -2
  397. package/dist/structure/date-order.d.ts.map +1 -1
  398. package/dist/structure/date-order.js +26 -9
  399. package/dist/structure/date-order.js.map +1 -1
  400. package/dist/structure/date-outside-period.d.ts +8 -0
  401. package/dist/structure/date-outside-period.d.ts.map +1 -1
  402. package/dist/structure/date-outside-period.js +52 -3
  403. package/dist/structure/date-outside-period.js.map +1 -1
  404. package/dist/structure/date-range.d.ts +6 -2
  405. package/dist/structure/date-range.d.ts.map +1 -1
  406. package/dist/structure/date-range.js +37 -9
  407. package/dist/structure/date-range.js.map +1 -1
  408. package/dist/structure/deadline-after-event.d.ts +23 -0
  409. package/dist/structure/deadline-after-event.d.ts.map +1 -0
  410. package/dist/structure/deadline-after-event.js +42 -0
  411. package/dist/structure/deadline-after-event.js.map +1 -0
  412. package/dist/structure/definition-use.d.ts +1 -1
  413. package/dist/structure/definition-use.d.ts.map +1 -1
  414. package/dist/structure/definition-use.js +55 -2
  415. package/dist/structure/definition-use.js.map +1 -1
  416. package/dist/structure/due-date.d.ts.map +1 -1
  417. package/dist/structure/due-date.js +5 -27
  418. package/dist/structure/due-date.js.map +1 -1
  419. package/dist/structure/labelled-date-order.d.ts +38 -0
  420. package/dist/structure/labelled-date-order.d.ts.map +1 -0
  421. package/dist/structure/labelled-date-order.js +41 -0
  422. package/dist/structure/labelled-date-order.js.map +1 -0
  423. package/dist/structure/layout-codes.d.ts +68 -0
  424. package/dist/structure/layout-codes.d.ts.map +1 -0
  425. package/dist/structure/layout-codes.js +161 -0
  426. package/dist/structure/layout-codes.js.map +1 -0
  427. package/dist/structure/leg-times.d.ts +2 -0
  428. package/dist/structure/leg-times.d.ts.map +1 -1
  429. package/dist/structure/leg-times.js +13 -0
  430. package/dist/structure/leg-times.js.map +1 -1
  431. package/dist/structure/measured-amounts.d.ts +17 -0
  432. package/dist/structure/measured-amounts.d.ts.map +1 -0
  433. package/dist/structure/measured-amounts.js +110 -0
  434. package/dist/structure/measured-amounts.js.map +1 -0
  435. package/dist/structure/party-order.d.ts +33 -0
  436. package/dist/structure/party-order.d.ts.map +1 -0
  437. package/dist/structure/party-order.js +79 -0
  438. package/dist/structure/party-order.js.map +1 -0
  439. package/dist/structure/quantity-range.d.ts +8 -0
  440. package/dist/structure/quantity-range.d.ts.map +1 -0
  441. package/dist/structure/quantity-range.js +36 -0
  442. package/dist/structure/quantity-range.js.map +1 -0
  443. package/dist/structure/range-bands.d.ts +75 -0
  444. package/dist/structure/range-bands.d.ts.map +1 -0
  445. package/dist/structure/range-bands.js +244 -0
  446. package/dist/structure/range-bands.js.map +1 -0
  447. package/dist/structure/rent-multiple.d.ts +76 -0
  448. package/dist/structure/rent-multiple.d.ts.map +1 -0
  449. package/dist/structure/rent-multiple.js +186 -0
  450. package/dist/structure/rent-multiple.js.map +1 -0
  451. package/dist/structure/requirement-lists.d.ts +37 -0
  452. package/dist/structure/requirement-lists.d.ts.map +1 -0
  453. package/dist/structure/requirement-lists.js +89 -0
  454. package/dist/structure/requirement-lists.js.map +1 -0
  455. package/dist/structure/scaled-quantities.d.ts +50 -0
  456. package/dist/structure/scaled-quantities.d.ts.map +1 -0
  457. package/dist/structure/scaled-quantities.js +153 -0
  458. package/dist/structure/scaled-quantities.js.map +1 -0
  459. package/dist/structure/stamp-order.d.ts +16 -0
  460. package/dist/structure/stamp-order.d.ts.map +1 -0
  461. package/dist/structure/stamp-order.js +78 -0
  462. package/dist/structure/stamp-order.js.map +1 -0
  463. package/dist/structure/step-times.d.ts +49 -0
  464. package/dist/structure/step-times.d.ts.map +1 -0
  465. package/dist/structure/step-times.js +128 -0
  466. package/dist/structure/step-times.js.map +1 -0
  467. package/dist/structure/term-deadline.d.ts +19 -0
  468. package/dist/structure/term-deadline.d.ts.map +1 -0
  469. package/dist/structure/term-deadline.js +28 -0
  470. package/dist/structure/term-deadline.js.map +1 -0
  471. package/dist/structure/time-order.d.ts +21 -0
  472. package/dist/structure/time-order.d.ts.map +1 -1
  473. package/dist/structure/time-order.js +5 -6
  474. package/dist/structure/time-order.js.map +1 -1
  475. package/dist/structure/time-range.d.ts +16 -0
  476. package/dist/structure/time-range.d.ts.map +1 -0
  477. package/dist/structure/time-range.js +57 -0
  478. package/dist/structure/time-range.js.map +1 -0
  479. package/dist/structure/total-line.d.ts +16 -0
  480. package/dist/structure/total-line.d.ts.map +1 -0
  481. package/dist/structure/total-line.js +44 -0
  482. package/dist/structure/total-line.js.map +1 -0
  483. package/dist/structure/total.d.ts +7 -1
  484. package/dist/structure/total.d.ts.map +1 -1
  485. package/dist/structure/total.js +28 -5
  486. package/dist/structure/total.js.map +1 -1
  487. package/dist/structure/unlisted-items.d.ts +70 -0
  488. package/dist/structure/unlisted-items.d.ts.map +1 -0
  489. package/dist/structure/unlisted-items.js +152 -0
  490. package/dist/structure/unlisted-items.js.map +1 -0
  491. package/dist/structure/version-order.d.ts +2 -0
  492. package/dist/structure/version-order.d.ts.map +1 -1
  493. package/dist/structure/version-order.js +10 -0
  494. package/dist/structure/version-order.js.map +1 -1
  495. package/dist/structure/walk-time.d.ts +87 -0
  496. package/dist/structure/walk-time.d.ts.map +1 -0
  497. package/dist/structure/walk-time.js +195 -0
  498. package/dist/structure/walk-time.js.map +1 -0
  499. package/dist/surname-near.d.ts +6 -0
  500. package/dist/surname-near.d.ts.map +1 -0
  501. package/dist/surname-near.js +31 -0
  502. package/dist/surname-near.js.map +1 -0
  503. package/dist/table-cells.d.ts +13 -0
  504. package/dist/table-cells.d.ts.map +1 -0
  505. package/dist/table-cells.js +36 -0
  506. package/dist/table-cells.js.map +1 -0
  507. package/dist/table-names.d.ts +42 -0
  508. package/dist/table-names.d.ts.map +1 -0
  509. package/dist/table-names.js +94 -0
  510. package/dist/table-names.js.map +1 -0
  511. package/package.json +3 -3
  512. package/profiles/listing.yaml +20 -0
  513. package/rules/announced-count-mismatch.yaml +2 -2
  514. package/rules/capacity-runtime-mismatch.yaml +66 -0
  515. package/rules/connection-time-short.yaml +52 -0
  516. package/rules/contact-variant.yaml +76 -0
  517. package/rules/count-over-capacity.yaml +55 -0
  518. package/rules/date-outside-period.yaml +4 -4
  519. package/rules/date-stamp-order.yaml +82 -0
  520. package/rules/deadline-after-event.yaml +67 -0
  521. package/rules/defined-name-repeated.yaml +2 -2
  522. package/rules/due-before-issue.yaml +11 -7
  523. package/rules/duration-mismatch.yaml +7 -4
  524. package/rules/duration-product-mismatch.yaml +73 -0
  525. package/rules/fact-conflict.yaml +9 -4
  526. package/rules/heading-echo.yaml +2 -2
  527. package/rules/interval-count-mismatch.yaml +54 -0
  528. package/rules/latin-spacing.yaml +2 -2
  529. package/rules/layout-code-mismatch.yaml +68 -0
  530. package/rules/name-variant.yaml +14 -2
  531. package/rules/no-em-dash.yaml +2 -2
  532. package/rules/party-order.yaml +84 -0
  533. package/rules/preamble-length.yaml +2 -2
  534. package/rules/quantity-range-reversed.yaml +53 -0
  535. package/rules/range-band-mismatch.yaml +70 -0
  536. package/rules/rent-multiple-mismatch.yaml +61 -0
  537. package/rules/required-listed-as-preferred.yaml +102 -0
  538. package/rules/return-type-mismatch.yaml +79 -0
  539. package/rules/scaled-quantity-mismatch.yaml +69 -0
  540. package/rules/step-time-sum-mismatch.yaml +65 -0
  541. package/rules/time-range-reversed.yaml +48 -0
  542. package/rules/title-case-consistency.yaml +2 -2
  543. package/rules/total-mismatch.yaml +2 -2
  544. package/rules/undefined-term.yaml +21 -7
  545. package/rules/unit-mismatch.yaml +12 -4
  546. package/rules/unlisted-item-used.yaml +90 -0
  547. package/rules/unused-definition.yaml +2 -2
  548. package/rules/use-before-definition.yaml +2 -2
  549. package/rules/walk-time-distance-mismatch.yaml +55 -0
  550. package/src/announced-count.ts +6 -3
  551. package/src/contacts/addresses.ts +179 -0
  552. package/src/contacts/emails.ts +63 -0
  553. package/src/contacts/variants.ts +33 -0
  554. package/src/derived/battery-runtime.ts +284 -0
  555. package/src/derived/period-counts.ts +178 -0
  556. package/src/derived/session-hours.ts +62 -0
  557. package/src/derived/time-lengths.ts +229 -0
  558. package/src/derived/unit-counts.ts +18 -0
  559. package/src/derived/use-interval.ts +151 -0
  560. package/src/derived/working-hours.ts +97 -0
  561. package/src/detectors/acronym-expansion.ts +57 -2
  562. package/src/detectors/announced-count.ts +1 -0
  563. package/src/detectors/capacity-runtime.ts +128 -0
  564. package/src/detectors/capitalised-term.ts +147 -0
  565. package/src/detectors/contact-variant.ts +24 -0
  566. package/src/detectors/count-over-capacity.ts +37 -0
  567. package/src/detectors/date-outside-period.ts +5 -1
  568. package/src/detectors/date-stamp-order.ts +28 -0
  569. package/src/detectors/defined-term-form.ts +63 -7
  570. package/src/detectors/definition-use.ts +6 -2
  571. package/src/detectors/derived-numbers.ts +97 -24
  572. package/src/detectors/due-date.ts +10 -2
  573. package/src/detectors/en-shape.ts +11 -4
  574. package/src/detectors/event-deadline.ts +29 -0
  575. package/src/detectors/fact-consistency.ts +64 -3
  576. package/src/detectors/heading-case.ts +13 -4
  577. package/src/detectors/heading-echo.ts +17 -1
  578. package/src/detectors/layout-code.ts +174 -0
  579. package/src/detectors/measured-facts.ts +20 -0
  580. package/src/detectors/name-variant-model-codes.ts +27 -0
  581. package/src/detectors/name-variant.ts +99 -15
  582. package/src/detectors/orthographic-variant.ts +78 -9
  583. package/src/detectors/orthography.ts +16 -6
  584. package/src/detectors/party-order.ts +50 -0
  585. package/src/detectors/quantity-range.ts +47 -0
  586. package/src/detectors/range-band.ts +125 -0
  587. package/src/detectors/registry/capacity-runtime-mismatch.ts +4 -0
  588. package/src/detectors/registry/connection-time-short.ts +4 -0
  589. package/src/detectors/registry/contact-variant.ts +4 -0
  590. package/src/detectors/registry/count-over-capacity.ts +4 -0
  591. package/src/detectors/registry/date-stamp-order.ts +4 -0
  592. package/src/detectors/registry/duration-product-mismatch.ts +4 -0
  593. package/src/detectors/registry/event-deadline.ts +4 -0
  594. package/src/detectors/registry/interval-count-mismatch.ts +4 -0
  595. package/src/detectors/registry/layout-code-mismatch.ts +4 -0
  596. package/src/detectors/registry/party-order.ts +4 -0
  597. package/src/detectors/registry/quantity-range.ts +4 -0
  598. package/src/detectors/registry/range-band-mismatch.ts +4 -0
  599. package/src/detectors/registry/rent-multiple-mismatch.ts +4 -0
  600. package/src/detectors/registry/requirement-lists.ts +4 -0
  601. package/src/detectors/registry/return-type.ts +4 -0
  602. package/src/detectors/registry/scaled-quantity-mismatch.ts +4 -0
  603. package/src/detectors/registry/step-time-sum-mismatch.ts +4 -0
  604. package/src/detectors/registry/time-range-reversed.ts +4 -0
  605. package/src/detectors/registry/unlisted-item-used.ts +4 -0
  606. package/src/detectors/registry/walk-time-distance-mismatch.ts +4 -0
  607. package/src/detectors/rent-multiple-mismatch.ts +56 -0
  608. package/src/detectors/requirement-lists.ts +65 -0
  609. package/src/detectors/return-type.ts +30 -0
  610. package/src/detectors/scaled-quantity.ts +49 -0
  611. package/src/detectors/signals.ts +3 -1
  612. package/src/detectors/step-time-sum.ts +55 -0
  613. package/src/detectors/structure-tree.ts +42 -6
  614. package/src/detectors/structure.ts +1 -1
  615. package/src/detectors/technical-docs.ts +12 -0
  616. package/src/detectors/time-order.ts +45 -6
  617. package/src/detectors/undefined-term.ts +20 -3
  618. package/src/detectors/unit-consistency.ts +50 -38
  619. package/src/detectors/unlisted-items.ts +72 -0
  620. package/src/detectors/use-count-words.ts +32 -0
  621. package/src/detectors/use-interval.ts +51 -0
  622. package/src/detectors/walk-time-distance-mismatch.ts +45 -0
  623. package/src/document.ts +4 -1
  624. package/src/facts/approximate-tolerance.ts +19 -0
  625. package/src/facts/item-amounts.ts +94 -0
  626. package/src/facts/labelled-facts.ts +29 -7
  627. package/src/facts/measure-units.ts +31 -0
  628. package/src/facts/measures.ts +113 -25
  629. package/src/facts/retention-periods.ts +216 -0
  630. package/src/facts/table-facts.ts +3 -0
  631. package/src/facts/unit-conflicts.ts +22 -9
  632. package/src/facts/unit-equivalents.ts +70 -0
  633. package/src/facts/unit-tolerance.ts +17 -0
  634. package/src/facts/unit-word.ts +35 -0
  635. package/src/facts/written-precision.ts +23 -0
  636. package/src/kana-spelling.ts +25 -0
  637. package/src/model-codes.ts +104 -0
  638. package/src/name-spelling-chars.ts +34 -0
  639. package/src/name-variants.ts +83 -7
  640. package/src/name-word-order.ts +149 -0
  641. package/src/phone-numbers.ts +26 -6
  642. package/src/place-names.ts +53 -14
  643. package/src/plugin.ts +7 -0
  644. package/src/preamble-paragraphs.ts +21 -2
  645. package/src/profile/parse.ts +10 -0
  646. package/src/return-type.ts +361 -0
  647. package/src/spacing-code.ts +26 -0
  648. package/src/structure/amount-range.ts +16 -7
  649. package/src/structure/capacity-count.ts +196 -0
  650. package/src/structure/connection-times.ts +226 -0
  651. package/src/structure/counted-amounts.ts +5 -4
  652. package/src/structure/date-order-tie.ts +86 -0
  653. package/src/structure/date-order.ts +41 -14
  654. package/src/structure/date-outside-period.ts +77 -7
  655. package/src/structure/date-range.ts +45 -9
  656. package/src/structure/deadline-after-event.ts +67 -0
  657. package/src/structure/definition-use.ts +59 -2
  658. package/src/structure/due-date.ts +8 -32
  659. package/src/structure/labelled-date-order.ts +84 -0
  660. package/src/structure/layout-codes.ts +210 -0
  661. package/src/structure/leg-times.ts +15 -0
  662. package/src/structure/measured-amounts.ts +138 -0
  663. package/src/structure/party-order.ts +115 -0
  664. package/src/structure/quantity-range.ts +54 -0
  665. package/src/structure/range-bands.ts +316 -0
  666. package/src/structure/rent-multiple.ts +277 -0
  667. package/src/structure/requirement-lists.ts +145 -0
  668. package/src/structure/scaled-quantities.ts +225 -0
  669. package/src/structure/stamp-order.ts +100 -0
  670. package/src/structure/step-times.ts +169 -0
  671. package/src/structure/term-deadline.ts +35 -0
  672. package/src/structure/time-order.ts +8 -7
  673. package/src/structure/time-range.ts +64 -0
  674. package/src/structure/total-line.ts +63 -0
  675. package/src/structure/total.ts +41 -6
  676. package/src/structure/unlisted-items.ts +207 -0
  677. package/src/structure/version-order.ts +10 -0
  678. package/src/structure/walk-time.ts +285 -0
  679. package/src/surname-near.ts +31 -0
  680. package/src/table-cells.ts +41 -0
  681. package/src/table-names.ts +113 -0
@@ -0,0 +1,217 @@
1
+ // capacity-runtime-mismatch: a battery capacity divided by the stated consumption is the longest the device can run; a stated
2
+ // runtime above it by more than its written precision cannot be right (5000 mAh at 500 mA is 10 h, not 15 h). The item names
3
+ // come from battery-label, the units from battery-unit and unit-time, the rough marks from approximate-marker. Pure.
4
+ const SECONDS_PER_HOUR = 3600;
5
+ const APPROXIMATE_FACTOR = 2;
6
+ const EPSILON = 1e-9;
7
+ const NUMBER = /^(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?/u;
8
+ const LETTER = /\p{L}/u;
9
+ const SPACES = /^\s*/u;
10
+ const normal = (text) => text.normalize("NFKC").trim();
11
+ const folded = (text) => normal(text).toLowerCase();
12
+ const conditionKey = (text) => folded(text).replace(/\s+/gu, "");
13
+ /** The text without a note in brackets at its end, and the note (連続再生時間(音量50%)). */
14
+ export const splitCondition = (text) => {
15
+ const plain = normal(text);
16
+ const open = plain.lastIndexOf("(");
17
+ if (!plain.endsWith(")") || open <= 0)
18
+ return { bare: plain, condition: "" };
19
+ return { bare: plain.slice(0, open).trim(), condition: conditionKey(plain.slice(open + 1, -1)) };
20
+ };
21
+ const wordsOf = (words, group) => words.labels.filter((entry) => entry.group === group).map((entry) => folded(entry.pattern));
22
+ const holds = (text, patterns) => patterns.some((pattern) => text.includes(pattern));
23
+ const WORD_CHAR = /[\p{L}\p{N}]/u;
24
+ /** The text without the marks at its ends (Max. → max). */
25
+ const withoutEdgeMarks = (text) => {
26
+ const chars = [...text];
27
+ const first = chars.findIndex((char) => WORD_CHAR.test(char));
28
+ const last = chars.findLastIndex((char) => WORD_CHAR.test(char));
29
+ return first === -1 ? "" : chars.slice(first, last + 1).join("");
30
+ };
31
+ /** Whether a condition or a heading is only one of the words, with a word of the state after it (待機時, Max., idle mode). */
32
+ const isOnly = (text, patterns, words) => {
33
+ const bare = withoutEdgeMarks(folded(text));
34
+ const suffixes = ["", ...wordsOf(words, "state")];
35
+ return patterns.some((pattern) => suffixes.some((suffix) => [pattern + suffix, `${pattern} ${suffix}`].includes(bare)));
36
+ };
37
+ const ROLES = ["capacity", "consumption", "runtime"];
38
+ /** What an item name says: which value, under which condition, whether idle or at the maximum. */
39
+ export const labelOf = (label, words) => {
40
+ const { bare, condition } = splitCondition(label);
41
+ const head = folded(bare);
42
+ const roles = ROLES.filter((role) => holds(head, wordsOf(words, role)));
43
+ const [role] = roles;
44
+ if (role === undefined || roles.length > 1)
45
+ return undefined;
46
+ const standby = wordsOf(words, "standby");
47
+ return {
48
+ role,
49
+ standby: holds(head, standby) || (role === "consumption" && isOnly(condition, standby, words)),
50
+ peak: holds(head, wordsOf(words, "peak")) || isOnly(condition, wordsOf(words, "peak"), words),
51
+ condition,
52
+ };
53
+ };
54
+ /** Whether a column heading is only a word of the maximum (最大, Max.). */
55
+ export const isPeakHeading = (heading, words) => isOnly(heading, wordsOf(words, "peak"), words);
56
+ const markAt = (text, marker) => {
57
+ const lower = text.toLowerCase();
58
+ const pattern = folded(marker.pattern);
59
+ return marker.position === "before" ? lower.startsWith(pattern) : lower.endsWith(pattern);
60
+ };
61
+ const stripOnce = (text, markers) => {
62
+ const marker = markers.find((candidate) => markAt(text, candidate));
63
+ if (marker === undefined)
64
+ return undefined;
65
+ const length = folded(marker.pattern).length;
66
+ const core = marker.position === "before" ? text.slice(length) : text.slice(0, text.length - length);
67
+ return { core: core.trim(), marks: [folded(marker.pattern)] };
68
+ };
69
+ const MAX_MARKS = 3;
70
+ /** The value without the marks around it (約, 最大, 以上, about, up to), and the marks taken off. */
71
+ export const stripMarks = (text, markers) => Array.from({ length: MAX_MARKS }).reduce((stripped) => {
72
+ const next = stripOnce(stripped.core, markers);
73
+ return next === undefined ? stripped : { core: next.core, marks: [...stripped.marks, ...next.marks] };
74
+ }, { core: normal(text), marks: [] });
75
+ const byLength = (units) => [...units].sort((left, right) => right.pattern.length - left.pattern.length);
76
+ /** The unit written at `at`, not running on into a word. A unit in lower case (hours) is read in any case; mA and W as written. */
77
+ const unitAt = (text, at, units) => byLength(units).find((unit) => {
78
+ const pattern = normal(unit.pattern);
79
+ const written = text.slice(at, at + pattern.length);
80
+ const caseless = pattern === pattern.toLowerCase();
81
+ return (caseless ? written.toLowerCase() === pattern : written === pattern) && !LETTER.test(text[at + pattern.length] ?? "");
82
+ });
83
+ const spacesAt = (text, at) => at + (SPACES.exec(text.slice(at))?.[0].length ?? 0);
84
+ /** A number at `at` and the unit right after it (spaces between allowed). */
85
+ const scanAt = (text, at, units) => {
86
+ const number = NUMBER.exec(text.slice(at))?.[0];
87
+ if (number === undefined)
88
+ return undefined;
89
+ const unitStart = spacesAt(text, at + number.length);
90
+ const unit = unitAt(text, unitStart, units);
91
+ const end = unit === undefined ? at + number.length : unitStart + normal(unit.pattern).length;
92
+ return { value: Number(number.replaceAll(",", "")), decimals: number.split(".")[1]?.length ?? 0, unit, end };
93
+ };
94
+ /** Every number and unit from `at` to the end; a number without a unit only last. Undefined when anything else is written. */
95
+ const scanAll = (text, at, units) => {
96
+ const from = spacesAt(text, at);
97
+ if (from >= text.length)
98
+ return [];
99
+ const scanned = scanAt(text, from, units);
100
+ if (scanned === undefined)
101
+ return undefined;
102
+ if (scanned.unit === undefined)
103
+ return spacesAt(text, scanned.end) >= text.length ? [scanned] : undefined;
104
+ const rest = scanAll(text, scanned.end, units);
105
+ return rest === undefined ? undefined : [scanned, ...rest];
106
+ };
107
+ const DECIMAL_BASE = 10;
108
+ /** One side of a range: a number and unit, or for time a run of them (10時間30分, 1 h 30 min), or a bare number. */
109
+ const sideOf = (text, units, compound) => {
110
+ const parts = scanAll(text, 0, units);
111
+ const last = parts?.at(-1);
112
+ if (parts === undefined || last === undefined || (parts.length > 1 && (!compound || last.unit === undefined)))
113
+ return undefined;
114
+ const step = DECIMAL_BASE ** -last.decimals;
115
+ if (last.unit === undefined)
116
+ return { value: last.value, step, unit: undefined };
117
+ const value = parts.reduce((sum, part) => sum + part.value * (part.unit?.weight ?? 0), 0);
118
+ return { value, step: step * last.unit.weight, unit: last.unit };
119
+ };
120
+ const splitRange = (text, connectors) => {
121
+ const connector = connectors.map(normal).find((candidate) => text.indexOf(candidate) > 0);
122
+ if (connector === undefined)
123
+ return [text];
124
+ const at = text.indexOf(connector);
125
+ return [text.slice(0, at).trim(), text.slice(at + connector.length).trim()];
126
+ };
127
+ /** A side written without a unit (8〜10時間) takes the unit of the other side. */
128
+ const withUnit = (side, other) => {
129
+ if (side.unit !== undefined)
130
+ return side;
131
+ if (other.unit === undefined)
132
+ return undefined;
133
+ return { value: side.value * other.unit.weight, step: side.step * other.unit.weight, unit: other.unit };
134
+ };
135
+ const rangeOf = (core, units, connectors, compound) => {
136
+ const parts = splitRange(core, connectors);
137
+ const sides = parts.map((part) => sideOf(part, units, compound));
138
+ const [first, second] = sides;
139
+ if (sides.some((side) => side === undefined) || first === undefined)
140
+ return undefined;
141
+ if (second === undefined)
142
+ return first.unit === undefined ? undefined : [first, first];
143
+ const low = withUnit(first, second);
144
+ return low === undefined || second.unit === undefined ? undefined : [low, second];
145
+ };
146
+ const familyOf = (unit, units) => units.find((candidate) => candidate === unit)?.family;
147
+ const ROLE_FAMILIES = {
148
+ capacity: ["charge", "energy"],
149
+ consumption: ["current", "power"],
150
+ runtime: ["time"],
151
+ };
152
+ /**
153
+ * A value cell or the value after a label's colon. A runtime is a time (15時間, 8〜10 hours, 1 h 30 min); a capacity or a
154
+ * consumption one number with an electric unit, or a range of them. A note in brackets at the end is not part of it.
155
+ * Undefined when the value is anything else, or is bounded from one side (10時間以上, under 500 mA).
156
+ */
157
+ export const valueOf = (text, role, words) => {
158
+ const { bare } = splitCondition(text);
159
+ const { core, marks } = stripMarks(bare, words.approximate);
160
+ if (words.bounds.some((marker) => markAt(bare, marker) || markAt(core, marker)))
161
+ return undefined;
162
+ const units = role === "runtime" ? words.time : words.electric;
163
+ const range = rangeOf(core, units, words.connectors, role === "runtime");
164
+ if (range === undefined)
165
+ return undefined;
166
+ const [low, high] = range;
167
+ const family = role === "runtime" ? "time" : familyOf(high.unit, words.electric);
168
+ if (family === undefined || !ROLE_FAMILIES[role].includes(family) || (role !== "runtime" && familyOf(low.unit, words.electric) !== family))
169
+ return undefined;
170
+ const reading = { low: low.value, high: high.value, family, step: low.step, approximate: marks.length > 0 };
171
+ return { reading, peak: marks.some((mark) => wordsOf(words, "peak").includes(mark)) };
172
+ };
173
+ const DIVIDES = { current: "charge", power: "energy" };
174
+ /** The consumption a runtime is read against: the one under the same condition, or the only one. */
175
+ const partnerOf = (runtime, consumptions) => {
176
+ const kind = consumptions.filter((entry) => entry.standby === runtime.standby);
177
+ const same = kind.filter((entry) => entry.condition === runtime.condition);
178
+ if (same.length === 1)
179
+ return same[0];
180
+ const [only] = kind;
181
+ return same.length === 0 && kind.length === 1 && only !== undefined && (only.condition === "" || runtime.condition === "") ? only : undefined;
182
+ };
183
+ /** The one capacity a consumption divides: of the matching kind, and only one value of it. */
184
+ const capacityFor = (consumption, capacities) => {
185
+ const kind = capacities.filter((entry) => entry.reading.family === DIVIDES[consumption.reading.family]);
186
+ const values = new Set(kind.map((entry) => entry.reading.high));
187
+ return values.size === 1 ? kind[0] : undefined;
188
+ };
189
+ const pairsOf = (entries) => {
190
+ const consumptions = entries.filter((entry) => entry.role === "consumption" && !entry.peak);
191
+ const pairs = entries
192
+ .filter((entry) => entry.role === "runtime")
193
+ .flatMap((runtime) => {
194
+ const partner = partnerOf(runtime, consumptions);
195
+ return partner === undefined ? [] : [[runtime, partner]];
196
+ });
197
+ return pairs.filter(([, consumption]) => pairs.filter(([, other]) => other === consumption).length === 1);
198
+ };
199
+ /**
200
+ * Runtimes stated above what the capacity divided by the consumption allows. Entries are one device's: one key-value table and
201
+ * the labelled lines of a section, or one column of a wider table. The margin is one step of the runtime's last written digit
202
+ * (15時間 → 1 h), twice that when any of the three is marked rough (約, about). A runtime at or below the ideal is normal.
203
+ */
204
+ export const capacityRuntimeMismatches = (entries) => {
205
+ const capacities = entries.filter((entry) => entry.role === "capacity");
206
+ return pairsOf(entries).flatMap(([runtime, consumption]) => {
207
+ const capacity = capacityFor(consumption, capacities);
208
+ if (capacity === undefined || consumption.reading.low <= 0)
209
+ return [];
210
+ const idealHours = capacity.reading.high / consumption.reading.low;
211
+ const rough = [runtime, consumption, capacity].some((entry) => entry.reading.approximate);
212
+ const margin = (runtime.reading.step / SECONDS_PER_HOUR) * (rough ? APPROXIMATE_FACTOR : 1);
213
+ const statedHours = runtime.reading.low / SECONDS_PER_HOUR;
214
+ return statedHours > idealHours + margin + EPSILON ? [{ capacity, consumption, runtime, idealHours }] : [];
215
+ });
216
+ };
217
+ //# sourceMappingURL=battery-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"battery-runtime.js","sourceRoot":"","sources":["../../src/derived/battery-runtime.ts"],"names":[],"mappings":"AAAA,8HAA8H;AAC9H,6HAA6H;AAC7H,qHAAqH;AAyCrH,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,MAAM,MAAM,GAAG,wCAAwC,CAAC;AACxD,MAAM,MAAM,GAAG,QAAQ,CAAC;AACxB,MAAM,MAAM,GAAG,OAAO,CAAC;AAEvB,MAAM,MAAM,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;AACvE,MAAM,MAAM,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AACpE,MAAM,YAAY,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAEjF,oFAAoF;AACpF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAY,EAAyD,EAAE;IACpG,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3B,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACpC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI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AC,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE,EAAE;QACzD,MAAM,QAAQ,GAAG,WAAW,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QACtD,IAAI,QAAQ,KAAK,SAAS,IAAI,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;YAAE,OAAO,EAAE,CAAC;QACtE,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC;QACnE,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAC1F,MAAM,MAAM,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,GAAG,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5F,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,GAAG,gBAAgB,CAAC;QAC3D,OAAO,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7G,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,48 @@
1
+ import type { Span } from "../plugin.ts";
2
+ import type { Mark } from "../structure/time-marks.ts";
3
+ /**
4
+ * Counts of uses in a period (1日3回, 3 times a day, twice in 24 hours) and the words that make a number a limit (まで,
5
+ * no more than, 最大量). The words come from the language packages; nothing here knows a language. Pure.
6
+ */
7
+ export type PeriodWord = Mark & {
8
+ readonly hours: number;
9
+ };
10
+ /** A number written as a word, with its value (three, twice). alone: it counts uses without a counter (twice a day). */
11
+ export type CountWord = {
12
+ readonly pattern: string;
13
+ readonly value: number;
14
+ readonly alone: boolean;
15
+ };
16
+ export type PeriodCountWords = {
17
+ /** Periods: before the number (1日3回) or after the counter (3 times a day). */
18
+ readonly periods: readonly PeriodWord[];
19
+ /** What a count of uses is written in (回, times, doses). */
20
+ readonly counters: readonly string[];
21
+ readonly numberWords: readonly CountWord[];
22
+ };
23
+ export type PeriodCount = Span & {
24
+ readonly amount: number;
25
+ readonly hours: number;
26
+ };
27
+ /** Full-width digits as ASCII ones, one for one, so offsets stay (1日 reads as 1日). */
28
+ export declare const asciiDigits: (text: string) => string;
29
+ /** Counts of uses in a period, in the order written. */
30
+ export declare const periodCounts: (written: string, words: PeriodCountWords) => PeriodCount[];
31
+ /** The periods written in text, wherever they stand (the maximum daily dose, 1日の最大量). */
32
+ export declare const periodsIn: (written: string, words: PeriodCountWords) => (Span & {
33
+ readonly hours: number;
34
+ })[];
35
+ /** The index of the last of values (ascending) at or before at, or -1. */
36
+ export declare const lastIndexAtOrBefore: (values: readonly number[], at: number) => number;
37
+ /** Where the stretch a number is read in begins: after the sentence end, or the last of takenEnds (ascending), before at. */
38
+ export declare const windowStart: (text: string, at: number, takenEnds: readonly number[]) => number;
39
+ export type LimitWords = {
40
+ /** Limit words; a word in group limit-negated ("more than") is one only with a negation before it ("do not take more than"). */
41
+ readonly limits: readonly Mark[];
42
+ readonly negations: readonly string[];
43
+ };
44
+ /** A limit word in the window before span (no more than, 最大量は), or right after it (まで, を超えて). */
45
+ export declare const isLimited: (text: string, span: Span, from: number, words: LimitWords) => boolean;
46
+ /** Runs of non-blank lines that are not table rows: the paragraphs a statement of use is read in. */
47
+ export declare const paragraphsOf: (text: string) => Span[];
48
+ //# sourceMappingURL=period-counts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"period-counts.d.ts","sourceRoot":"","sources":["../../src/derived/period-counts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEz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,WAAW,GAAI,MAAM,MAAM,EAAE,IAAI,MAAM,EAAE,WAAW,SAAS,MAAM,EAAE,KAAG,MAIpF,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,gIAAgI;IAChI,QAAQ,CAAC,MAAM,EAAE,SAAS,IAAI,EAAE,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC,CAAC;AAQF,iGAAiG;AACjG,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,EAAE,MAAM,IAAI,EAAE,MAAM,MAAM,EAAE,OAAO,UAAU,KAAG,OAUrF,CAAC;AAMF,qGAAqG;AACrG,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,KAAG,IAAI,EAQxC,CAAC"}
@@ -0,0 +1,128 @@
1
+ import { escapeRegExp } from "../orthography.js";
2
+ import { linesOf } from "../structure/lines.js";
3
+ const alternation = (words) => [...new Set(words.filter((word) => word !== ""))]
4
+ .toSorted((left, right) => right.length - left.length)
5
+ .map(escapeRegExp)
6
+ .join("|");
7
+ /** A word that does not run on from a Latin letter or a digit before it, or into a Latin letter after it. */
8
+ const bounded = (pattern) => `(?<![A-Za-z0-9])(?:${pattern})(?![A-Za-z])`;
9
+ const DIGITS = "(?<![\\p{N}.,.])\\p{Nd}+(?:[..]\\p{Nd}+)?";
10
+ const numberAt = (written, words) => words.find((word) => word.pattern.toLowerCase() === written.toLowerCase())?.value ?? Number(written.normalize("NFKC"));
11
+ const periodsOn = (words, side) => words.periods.filter((period) => (period.position ?? "before") === side);
12
+ const hoursOf = (words, written) => words.periods.find((period) => period.pattern.toLowerCase() === written.toLowerCase())?.hours ?? 0;
13
+ /** The hours of the longest period word the match starts with. */
14
+ const periodHoursIn = (written, words) => {
15
+ const found = periodsOn(words, "before")
16
+ .toSorted((left, right) => right.pattern.length - left.pattern.length)
17
+ .find((period) => written.toLowerCase().startsWith(period.pattern.toLowerCase()));
18
+ return found?.hours ?? 0;
19
+ };
20
+ /** At most this many letters (の, に, あたり) between a period written first and its count: 1日に3回. */
21
+ const JOINER = "[^\\p{N}\\s。、,,..!?!?]{0,4}";
22
+ /** 1日3回: the period first, then the number and the counter. */
23
+ const periodFirst = (text, words) => {
24
+ const [periods, counters] = [alternation(periodsOn(words, "before").map((word) => word.pattern)), alternation(words.counters)];
25
+ if (periods === "" || counters === "")
26
+ return [];
27
+ const pattern = new RegExp(`${bounded(periods)}${JOINER}\\s?(?<digits>${DIGITS})\\s?(?:${counters})`, "giu");
28
+ return [...text.matchAll(pattern)].map((match) => ({
29
+ start: match.index,
30
+ end: match.index + match[0].length,
31
+ amount: Number((match.groups?.["digits"] ?? "").normalize("NFKC")),
32
+ hours: periodHoursIn(match[0], words),
33
+ }));
34
+ };
35
+ const namesOf = (words, alone) => alternation(words.filter((word) => word.alone === alone).map((word) => word.pattern));
36
+ /** 3 times a day, twice in 24 hours: the number and the counter first, then the period. */
37
+ const periodLast = (text, words) => {
38
+ const [periods, counters] = [alternation(periodsOn(words, "after").map((word) => word.pattern)), alternation(words.counters)];
39
+ if (periods === "" || counters === "")
40
+ return [];
41
+ const [counted, alone] = [namesOf(words.numberWords, false), namesOf(words.numberWords, true)];
42
+ const number = counted === "" ? `(?<digits>${DIGITS})` : `(?:(?<digits>${DIGITS})|(?<word>${bounded(counted)}))`;
43
+ const once = alone === "" ? "" : `|(?<alone>${bounded(alone)})`;
44
+ const pattern = new RegExp(`(?:${number}\\s?${bounded(counters)}${once})\\s+(?<period>${bounded(periods)})`, "giu");
45
+ return [...text.matchAll(pattern)].map((match) => {
46
+ const groups = match.groups ?? {};
47
+ const written = groups["digits"] ?? groups["word"] ?? groups["alone"] ?? "";
48
+ return {
49
+ start: match.index,
50
+ end: match.index + match[0].length,
51
+ amount: numberAt(written, words.numberWords),
52
+ hours: hoursOf(words, groups["period"] ?? ""),
53
+ };
54
+ });
55
+ };
56
+ const FULL_WIDTH_ZERO = 0xff10;
57
+ const ASCII_ZERO = 0x30;
58
+ /** Full-width digits as ASCII ones, one for one, so offsets stay (1日 reads as 1日). */
59
+ export const asciiDigits = (text) => text.replace(/[0-9]/gu, (digit) => String.fromCharCode(digit.charCodeAt(0) - FULL_WIDTH_ZERO + ASCII_ZERO));
60
+ /** Counts of uses in a period, in the order written. */
61
+ export const periodCounts = (written, words) => {
62
+ const text = asciiDigits(written);
63
+ return [...periodFirst(text, words), ...periodLast(text, words)]
64
+ .filter((count) => Number.isFinite(count.amount) && count.amount > 0 && count.hours > 0)
65
+ .toSorted((left, right) => left.start - right.start);
66
+ };
67
+ /** The periods written in text, wherever they stand (the maximum daily dose, 1日の最大量). */
68
+ export const periodsIn = (written, words) => {
69
+ const text = asciiDigits(written);
70
+ const all = alternation(words.periods.map((word) => word.pattern));
71
+ if (all === "")
72
+ return [];
73
+ return [...text.matchAll(new RegExp(bounded(all), "giu"))].map((match) => ({
74
+ start: match.index,
75
+ end: match.index + match[0].length,
76
+ hours: hoursOf(words, match[0]),
77
+ }));
78
+ };
79
+ const SENTENCE_END = /[。.!?!?\n]|\.(?=\s|$)/gu;
80
+ /** How far back the window of a number reaches at most, in characters. */
81
+ const WINDOW_REACH = 120;
82
+ /** The index of the last of values (ascending) at or before at, or -1. */
83
+ export const lastIndexAtOrBefore = (values, at) => {
84
+ let [low, high, found] = [0, values.length - 1, -1];
85
+ while (low <= high) {
86
+ const middle = (low + high) >> 1;
87
+ if ((values[middle] ?? Infinity) <= at)
88
+ [found, low] = [middle, middle + 1];
89
+ else
90
+ high = middle - 1;
91
+ }
92
+ return found;
93
+ };
94
+ /** Where the stretch a number is read in begins: after the sentence end, or the last of takenEnds (ascending), before at. */
95
+ export const windowStart = (text, at, takenEnds) => {
96
+ const reach = Math.max(0, at - WINDOW_REACH);
97
+ const ends = [...text.slice(reach, at).matchAll(SENTENCE_END)].map((match) => reach + match.index + match[0].length);
98
+ return Math.max(reach, takenEnds[lastIndexAtOrBefore(takenEnds, at)] ?? 0, ...ends);
99
+ };
100
+ const NEGATED = "limit-negated";
101
+ const LIMIT_GAP_AFTER = /^[\s、,]*/u;
102
+ const LIMIT_REACH_AFTER = 24;
103
+ const containsWord = (text, word) => new RegExp(bounded(escapeRegExp(word.toLowerCase())), "u").test(text);
104
+ /** A limit word in the window before span (no more than, 最大量は), or right after it (まで, を超えて). */
105
+ export const isLimited = (text, span, from, words) => {
106
+ const before = text.slice(from, span.start).toLowerCase();
107
+ const after = text.slice(span.end, span.end + LIMIT_REACH_AFTER).toLowerCase();
108
+ const gap = LIMIT_GAP_AFTER.exec(after)?.[0].length ?? 0;
109
+ const negated = words.negations.some((word) => containsWord(before, word));
110
+ return words.limits.some((limit) => (limit.position ?? "before") === "before"
111
+ ? containsWord(before, limit.pattern) && (limit.group !== NEGATED || negated)
112
+ : after.startsWith(limit.pattern.toLowerCase(), gap));
113
+ };
114
+ const TABLE_ROW = /^\s*\|/u;
115
+ const isProse = (line) => line !== undefined && line.text.trim() !== "" && !TABLE_ROW.test(line.text);
116
+ /** Runs of non-blank lines that are not table rows: the paragraphs a statement of use is read in. */
117
+ export const paragraphsOf = (text) => linesOf(text).reduce((runs, line, index, lines) => {
118
+ if (!isProse(line))
119
+ return runs;
120
+ const end = line.start + line.text.length;
121
+ const last = runs.at(-1);
122
+ if (isProse(lines[index - 1]) && last !== undefined)
123
+ runs[runs.length - 1] = { start: last.start, end };
124
+ else
125
+ runs.push({ start: line.start, end });
126
+ return runs;
127
+ }, []);
128
+ //# sourceMappingURL=period-counts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"period-counts.js","sourceRoot":"","sources":["../../src/derived/period-counts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAqBhD,MAAM,WAAW,GAAG,CAAC,KAAwB,EAAU,EAAE,CACvD,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,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ts";
3
+ import { type TimeLength } from "./time-lengths.ts";
4
+ /**
5
+ * A number of sessions times the length of one against the stated total (90分×15回(計24時間), 15 sessions of 90
6
+ * minutes, 24 hours in total). Read in one line, or in a list whose items say it together, holding exactly one count of
7
+ * two or more sessions, one length of a session and one total. A total written as approximate (約24時間, about 24 hours)
8
+ * may differ by less than the smallest unit it is written in. Pure.
9
+ */
10
+ export type Count = Span & {
11
+ readonly amount: number;
12
+ };
13
+ export type SessionHoursWords = {
14
+ readonly totals: readonly Mark[];
15
+ readonly approximate: readonly Mark[];
16
+ };
17
+ export type SessionHoursMismatch = {
18
+ readonly count: Count;
19
+ readonly length: TimeLength;
20
+ readonly total: TimeLength;
21
+ /** The count times the length, in minutes. */
22
+ readonly expected: number;
23
+ };
24
+ /** Sessions whose count times length is not the stated total. counts are the written counts of sessions (15回, 15 sessions). */
25
+ export declare const sessionHoursMismatches: (text: string, source: string, sentences: readonly Span[], counts: readonly Count[], lengths: readonly TimeLength[], words: SessionHoursWords) => SessionHoursMismatch[];
26
+ //# sourceMappingURL=session-hours.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-hours.d.ts","sourceRoot":"","sources":["../../src/derived/session-hours.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAA+B,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEjF;;;;;GAKG;AACH,MAAM,MAAM,KAAK,GAAG,IAAI,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD,MAAM,MAAM,iBAAiB,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,IAAI,EAAE,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,SAAS,IAAI,EAAE,CAAA;CAAE,CAAC;AAE5G,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,8CAA8C;IAC9C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,CAAC;AA2BF,+HAA+H;AAC/H,eAAO,MAAM,sBAAsB,GACjC,MAAM,MAAM,EACZ,QAAQ,MAAM,EACd,WAAW,SAAS,IAAI,EAAE,EAC1B,QAAQ,SAAS,KAAK,EAAE,EACxB,SAAS,SAAS,UAAU,EAAE,EAC9B,OAAO,iBAAiB,KACvB,oBAAoB,EAMnB,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { labelOf, readScopes, within } from "./time-lengths.js";
2
+ const overlaps = (left, right) => left.start < right.end && right.start < left.end;
3
+ /** The length with a rough mark written before it taken in (計約24時間 reads its label past 約). */
4
+ const withRoughMark = (text, length, words) => {
5
+ const mark = labelOf(text, length, words.approximate);
6
+ return mark !== undefined && mark.end <= length.start ? { start: mark.start, end: length.end } : length;
7
+ };
8
+ const statementIn = (text, scope, counts, lengths, words) => {
9
+ const inCounts = counts.filter((count) => count.amount > 1 && within(count, scope));
10
+ const inLengths = lengths.filter((length) => within(length, scope));
11
+ const totals = inLengths.filter((length) => labelOf(text, withRoughMark(text, length, words), words.totals) !== undefined);
12
+ const sessions = inLengths.filter((length) => !totals.includes(length));
13
+ const [count, length, total] = [inCounts[0], sessions[0], totals[0]];
14
+ if (inCounts.length !== 1 || sessions.length !== 1 || totals.length !== 1 || count === undefined || length === undefined || total === undefined)
15
+ return undefined;
16
+ if (overlaps(count, length) || labelOf(text, length, words.approximate) !== undefined)
17
+ return undefined;
18
+ return { count, length, total };
19
+ };
20
+ const allowanceOf = (text, total, words) => labelOf(text, total, words.approximate) === undefined ? 0 : total.unit;
21
+ /** Sessions whose count times length is not the stated total. counts are the written counts of sessions (15回, 15 sessions). */
22
+ export const sessionHoursMismatches = (text, source, sentences, counts, lengths, words) => readScopes(text, source, { sentences, times: [] }, (scope) => statementIn(text, scope, counts, lengths, words)).flatMap(({ count, length, total }) => {
23
+ const expected = count.amount * length.minutes;
24
+ const allowance = allowanceOf(text, total, words);
25
+ if (allowance === 0 ? expected === total.minutes : Math.abs(expected - total.minutes) < allowance)
26
+ return [];
27
+ return [{ count, length, total, expected }];
28
+ });
29
+ //# sourceMappingURL=session-hours.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-hours.js","sourceRoot":"","sources":["../../src/derived/session-hours.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAmB,MAAM,mBAAmB,CAAC;AAoBjF,MAAM,QAAQ,GAAG,CAAC,IAAU,EAAE,KAAW,EAAW,EAAE,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC;AAIxG,+FAA+F;AAC/F,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,MAAkB,EAAE,KAAwB,EAAQ,EAAE;IACzF,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IACtD,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;AAC1G,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,KAAW,EAAE,MAAwB,EAAE,OAA8B,EAAE,KAAwB,EAAE,EAAE;IACpI,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,MAA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EAAE,KAAK,CAAC,WAAW,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;AAEzE,+HAA+H;AAC/H,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,IAAY,EACZ,MAAc,EACd,SAA0B,EAC1B,MAAwB,EACxB,OAA8B,EAC9B,KAAwB,EACA,EAAE,CAC1B,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE;IACnJ,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;IAC/C,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAClD,IAAI,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,KAAK,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,SAAS;QAAE,OAAO,EAAE,CAAC;IAC7G,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC9C,CAAC,CAAC,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { Span } from "../plugin.ts";
2
+ import { type Mark } from "../structure/time-marks.ts";
3
+ /**
4
+ * Lengths of time in hours and minutes (8時間, 7時間30分, 90分, 1-hour, one-hour, 7.5 hours), the words written beside
5
+ * them (実働8時間, 8 hours a day), and the stretches of text a statement of hours is read in. The words come from the
6
+ * language packages; nothing here knows a language. Pure.
7
+ */
8
+ export type TimeLength = Span & {
9
+ readonly minutes: number;
10
+ /** The smallest unit the length is written in, in minutes: 60 for 24時間, 1 for 90分 or 7時間30分, 30 for 7時間半. */
11
+ readonly unit: number;
12
+ };
13
+ export type LengthWords = {
14
+ readonly hourUnits: readonly string[];
15
+ readonly minuteUnits: readonly string[];
16
+ /** What written right after the hour unit adds half an hour (7時間半). */
17
+ readonly halves: readonly string[];
18
+ /** Numbers written as words, in order from one. */
19
+ readonly numberWords: readonly string[];
20
+ };
21
+ /** Lengths of time in hours and minutes, in the order written. A minutes-only reading inside an hours one is dropped. */
22
+ export declare const timeLengths: (text: string, words: LengthWords) => TimeLength[];
23
+ /** The label beside span, before or after it. */
24
+ export declare const labelOf: (text: string, span: Span, marks: readonly Mark[]) => Span | undefined;
25
+ /** Where the words of marks are written inside scope. */
26
+ export declare const mentionsIn: (text: string, scope: Span, marks: readonly Mark[]) => Span[];
27
+ export declare const within: (inner: Span, outer: Span) => boolean;
28
+ /**
29
+ * The stretches a statement is read in: each sentence of a line, and a list whose items say it together (勤務時間 /
30
+ * 休憩 / 実働 on three items). read returns undefined when a stretch does not hold exactly one statement; a list that
31
+ * reads as one is not read again line by line.
32
+ */
33
+ export declare const readScopes: <T>(text: string, source: string, split: {
34
+ readonly sentences: readonly Span[];
35
+ readonly times: readonly Span[];
36
+ }, read: (scope: Span) => T | undefined) => T[];
37
+ //# sourceMappingURL=time-lengths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time-lengths.d.ts","sourceRoot":"","sources":["../../src/derived/time-lengths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAyB,KAAK,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAG9E;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,6GAA6G;IAC7G,QAAQ,CA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