@chaffjs/lang-ja 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 (242) hide show
  1. package/dist/currency-amounts.d.ts +21 -0
  2. package/dist/currency-amounts.d.ts.map +1 -0
  3. package/dist/currency-amounts.js +73 -0
  4. package/dist/currency-amounts.js.map +1 -0
  5. package/dist/era-year.d.ts +18 -0
  6. package/dist/era-year.d.ts.map +1 -0
  7. package/dist/era-year.js +47 -0
  8. package/dist/era-year.js.map +1 -0
  9. package/dist/lexicons.d.ts +3 -0
  10. package/dist/lexicons.d.ts.map +1 -1
  11. package/dist/lexicons.js +9 -0
  12. package/dist/lexicons.js.map +1 -1
  13. package/dist/numbers.d.ts +1 -1
  14. package/dist/numbers.d.ts.map +1 -1
  15. package/dist/numbers.js +7 -4
  16. package/dist/numbers.js.map +1 -1
  17. package/dist/quantities.d.ts +2 -0
  18. package/dist/quantities.d.ts.map +1 -1
  19. package/dist/quantities.js +56 -27
  20. package/dist/quantities.js.map +1 -1
  21. package/dist/structure.d.ts.map +1 -1
  22. package/dist/structure.js +5 -1
  23. package/dist/structure.js.map +1 -1
  24. package/dist/unit-case.d.ts +4 -0
  25. package/dist/unit-case.d.ts.map +1 -0
  26. package/dist/unit-case.js +11 -0
  27. package/dist/unit-case.js.map +1 -0
  28. package/lexicons/address-label.yaml +16 -0
  29. package/lexicons/age-reference-label.yaml +12 -0
  30. package/lexicons/age-time-mark.yaml +9 -0
  31. package/lexicons/annual-holidays-label.yaml +10 -0
  32. package/lexicons/annual-holidays-word.yaml +23 -0
  33. package/lexicons/annual-pay-label.yaml +22 -0
  34. package/lexicons/annual-pay-word.yaml +44 -0
  35. package/lexicons/any-year-marker.yaml +18 -0
  36. package/lexicons/balance-column.yaml +43 -0
  37. package/lexicons/battery-label.yaml +42 -0
  38. package/lexicons/battery-unit.yaml +18 -0
  39. package/lexicons/benefit-limit-word.yaml +9 -0
  40. package/lexicons/birth-date-label.yaml +6 -0
  41. package/lexicons/bmi-term.yaml +10 -0
  42. package/lexicons/bmi-unit.yaml +7 -0
  43. package/lexicons/calendar-era.yaml +6 -0
  44. package/lexicons/capacity-exception.yaml +30 -0
  45. package/lexicons/capacity-label.yaml +12 -0
  46. package/lexicons/change-column.yaml +28 -0
  47. package/lexicons/change-target.yaml +4 -1
  48. package/lexicons/closing-balance-label.yaml +48 -0
  49. package/lexicons/company-form-foreign.yaml +45 -0
  50. package/lexicons/company-name-kana.yaml +91 -0
  51. package/lexicons/contact-label.yaml +14 -0
  52. package/lexicons/count-frame.yaml +7 -0
  53. package/lexicons/cumulative-table.yaml +35 -0
  54. package/lexicons/currency-column.yaml +13 -0
  55. package/lexicons/date-deadline-mark.yaml +10 -0
  56. package/lexicons/date-now-word.yaml +8 -0
  57. package/lexicons/dated-column-label.yaml +14 -0
  58. package/lexicons/dated-pair-label.yaml +232 -0
  59. package/lexicons/dated-span-label.yaml +12 -0
  60. package/lexicons/deductible-basis.yaml +20 -0
  61. package/lexicons/deductible-word.yaml +8 -0
  62. package/lexicons/discount-rate-label.yaml +30 -0
  63. package/lexicons/due-date-label.yaml +4 -0
  64. package/lexicons/email-sentence-end.yaml +10 -0
  65. package/lexicons/event-aside.yaml +15 -0
  66. package/lexicons/event-bill-word.yaml +5 -0
  67. package/lexicons/event-date-label.yaml +9 -0
  68. package/lexicons/event-deadline-word.yaml +9 -0
  69. package/lexicons/event-due-word.yaml +6 -0
  70. package/lexicons/event-payment-deadline-word.yaml +18 -0
  71. package/lexicons/event-payment-word.yaml +8 -0
  72. package/lexicons/event-registration-word.yaml +11 -0
  73. package/lexicons/event-start-label.yaml +9 -0
  74. package/lexicons/event-ticket-word.yaml +8 -0
  75. package/lexicons/event-trip-word.yaml +12 -0
  76. package/lexicons/fact-age-joiner.yaml +10 -0
  77. package/lexicons/fact-age-limit.yaml +7 -0
  78. package/lexicons/fact-age-mark.yaml +7 -0
  79. package/lexicons/fact-amount-condition.yaml +15 -0
  80. package/lexicons/fact-count-column.yaml +8 -0
  81. package/lexicons/fact-count-counter.yaml +7 -0
  82. package/lexicons/fact-count-not-whole.yaml +22 -0
  83. package/lexicons/fact-count-restating.yaml +9 -0
  84. package/lexicons/fact-count-separate-rows.yaml +6 -0
  85. package/lexicons/fact-count-whole.yaml +9 -0
  86. package/lexicons/fact-document-term.yaml +32 -0
  87. package/lexicons/fact-label-count-link.yaml +9 -0
  88. package/lexicons/fact-label-counter.yaml +25 -0
  89. package/lexicons/fact-label-drop.yaml +13 -0
  90. package/lexicons/fact-label-qualifier.yaml +8 -0
  91. package/lexicons/fact-rate-base.yaml +12 -0
  92. package/lexicons/fact-rate-kind.yaml +13 -0
  93. package/lexicons/fact-rate-period.yaml +16 -0
  94. package/lexicons/fact-separator.yaml +2 -0
  95. package/lexicons/fact-term-self.yaml +9 -0
  96. package/lexicons/fact-term-start.yaml +7 -0
  97. package/lexicons/gpa-label.yaml +18 -0
  98. package/lexicons/grade-point.yaml +35 -0
  99. package/lexicons/headcount-label.yaml +31 -0
  100. package/lexicons/headcount-unit.yaml +11 -0
  101. package/lexicons/heading-number-label.yaml +1 -2
  102. package/lexicons/installment-label.yaml +41 -0
  103. package/lexicons/installment-word.yaml +21 -0
  104. package/lexicons/interest-label.yaml +28 -0
  105. package/lexicons/item-amount.yaml +30 -0
  106. package/lexicons/item-at-hand.yaml +17 -0
  107. package/lexicons/item-list-heading.yaml +20 -0
  108. package/lexicons/item-name-column.yaml +9 -0
  109. package/lexicons/item-use.yaml +63 -0
  110. package/lexicons/lab-result-column.yaml +23 -0
  111. package/lexicons/label-product-word.yaml +21 -0
  112. package/lexicons/layout-code.yaml +18 -0
  113. package/lexicons/layout-label.yaml +15 -0
  114. package/lexicons/layout-room.yaml +23 -0
  115. package/lexicons/line-amount-column.yaml +3 -0
  116. package/lexicons/measure-per-mark.yaml +8 -0
  117. package/lexicons/measure-value-lead.yaml +8 -0
  118. package/lexicons/meter-event.yaml +24 -0
  119. package/lexicons/meter-reading-label.yaml +29 -0
  120. package/lexicons/meter-unit.yaml +10 -0
  121. package/lexicons/model-code-label.yaml +13 -0
  122. package/lexicons/name-char-reading.yaml +18 -0
  123. package/lexicons/name-lookalike-char.yaml +26 -0
  124. package/lexicons/name-spelling-char.yaml +8 -0
  125. package/lexicons/net-amount-label.yaml +62 -0
  126. package/lexicons/net-amount-period.yaml +14 -0
  127. package/lexicons/net-gross-weight-column.yaml +20 -0
  128. package/lexicons/order-quantity-column.yaml +26 -0
  129. package/lexicons/organization-unit.yaml +25 -0
  130. package/lexicons/orthographic-variant-whole-word.yaml +27 -0
  131. package/lexicons/overnight-work-mark.yaml +13 -0
  132. package/lexicons/pack-count-column.yaml +10 -0
  133. package/lexicons/pack-price-column.yaml +12 -0
  134. package/lexicons/per-unit-mark.yaml +1 -0
  135. package/lexicons/period-after-term.yaml +21 -0
  136. package/lexicons/period-deadline.yaml +5 -2
  137. package/lexicons/period-label.yaml +9 -0
  138. package/lexicons/period-multiple-label.yaml +12 -0
  139. package/lexicons/period-multiple-word.yaml +30 -0
  140. package/lexicons/period-part-after.yaml +8 -0
  141. package/lexicons/period-part-inline-joiner.yaml +5 -0
  142. package/lexicons/period-part-marker.yaml +9 -0
  143. package/lexicons/period-part-range.yaml +10 -0
  144. package/lexicons/period-part-word.yaml +5 -0
  145. package/lexicons/person-label.yaml +19 -0
  146. package/lexicons/person-title.yaml +22 -0
  147. package/lexicons/phone-label.yaml +10 -0
  148. package/lexicons/place-direction.yaml +18 -0
  149. package/lexicons/place-name-char.yaml +56 -0
  150. package/lexicons/place-word.yaml +8 -1
  151. package/lexicons/points-earned-column.yaml +20 -0
  152. package/lexicons/points-rate-joiner.yaml +9 -0
  153. package/lexicons/points-unit.yaml +7 -0
  154. package/lexicons/product-form.yaml +23 -0
  155. package/lexicons/quantity-bound-label.yaml +13 -0
  156. package/lexicons/quantity-change-word.yaml +35 -0
  157. package/lexicons/quantity-column.yaml +22 -0
  158. package/lexicons/range-band-heading.yaml +13 -0
  159. package/lexicons/range-band-unit.yaml +35 -0
  160. package/lexicons/range-band-word.yaml +22 -0
  161. package/lexicons/rate-unit.yaml +8 -0
  162. package/lexicons/ratio-label.yaml +15 -0
  163. package/lexicons/ratio-term.yaml +13 -0
  164. package/lexicons/reference-bound-mark.yaml +14 -0
  165. package/lexicons/reference-column-heading.yaml +7 -0
  166. package/lexicons/reference-column.yaml +16 -0
  167. package/lexicons/reference-flag.yaml +23 -0
  168. package/lexicons/reference-label.yaml +123 -0
  169. package/lexicons/reference-unit-column.yaml +7 -0
  170. package/lexicons/reference-unit.yaml +80 -0
  171. package/lexicons/rent-label.yaml +12 -0
  172. package/lexicons/rent-multiple-label.yaml +13 -0
  173. package/lexicons/rent-multiple-word.yaml +30 -0
  174. package/lexicons/reporting-comparison.yaml +26 -0
  175. package/lexicons/reporting-current-not.yaml +10 -0
  176. package/lexicons/reporting-current.yaml +15 -0
  177. package/lexicons/reporting-forecast.yaml +18 -0
  178. package/lexicons/reporting-period-frame.yaml +19 -0
  179. package/lexicons/reporting-period-line.yaml +12 -0
  180. package/lexicons/reporting-period-not.yaml +23 -0
  181. package/lexicons/reporting-results-word.yaml +10 -0
  182. package/lexicons/reporting-year-frame.yaml +7 -0
  183. package/lexicons/request-offer.yaml +15 -0
  184. package/lexicons/retention-bound.yaml +12 -0
  185. package/lexicons/retention-length-mark.yaml +12 -0
  186. package/lexicons/retention-length-modifier.yaml +5 -0
  187. package/lexicons/retention-object-mark.yaml +9 -0
  188. package/lexicons/retention-unit.yaml +6 -0
  189. package/lexicons/retention-verb.yaml +11 -0
  190. package/lexicons/revision-column.yaml +15 -0
  191. package/lexicons/revision-direction.yaml +21 -0
  192. package/lexicons/scaled-unit-form.yaml +20 -0
  193. package/lexicons/serial-label.yaml +9 -0
  194. package/lexicons/service-charge-label.yaml +6 -0
  195. package/lexicons/servings-column.yaml +17 -0
  196. package/lexicons/share-amount-label.yaml +20 -0
  197. package/lexicons/share-column-rate-header.yaml +41 -0
  198. package/lexicons/shift-column.yaml +25 -0
  199. package/lexicons/stamp-order-label.yaml +24 -0
  200. package/lexicons/step-time-not-own.yaml +31 -0
  201. package/lexicons/step-time-total.yaml +9 -0
  202. package/lexicons/table-scale-unit.yaml +19 -0
  203. package/lexicons/table-unit-caption.yaml +6 -0
  204. package/lexicons/tax-price-column.yaml +14 -0
  205. package/lexicons/tier-label.yaml +25 -0
  206. package/lexicons/tier-unit.yaml +9 -0
  207. package/lexicons/timed-pair-label.yaml +71 -0
  208. package/lexicons/total-label.yaml +12 -1
  209. package/lexicons/total-noun-listed.yaml +8 -0
  210. package/lexicons/total-noun-qualifier.yaml +8 -0
  211. package/lexicons/total-noun-unsummed.yaml +10 -0
  212. package/lexicons/total-period-qualifier.yaml +10 -0
  213. package/lexicons/transcript-column.yaml +17 -0
  214. package/lexicons/unit-area.yaml +29 -0
  215. package/lexicons/unit-concentration.yaml +71 -0
  216. package/lexicons/unit-context.yaml +20 -0
  217. package/lexicons/unit-equivalent-hedge.yaml +7 -0
  218. package/lexicons/unit-item-link.yaml +5 -0
  219. package/lexicons/unit-length.yaml +2 -0
  220. package/lexicons/unit-pressure.yaml +12 -0
  221. package/lexicons/unit-price-column.yaml +21 -0
  222. package/lexicons/unit-temperature.yaml +14 -0
  223. package/lexicons/unit-volume.yaml +18 -0
  224. package/lexicons/unit-zero.yaml +8 -0
  225. package/lexicons/unscaled-amount.yaml +11 -0
  226. package/lexicons/use-amount-word.yaml +9 -0
  227. package/lexicons/use-count-word.yaml +22 -0
  228. package/lexicons/use-interval-word.yaml +18 -0
  229. package/lexicons/variance-column.yaml +17 -0
  230. package/lexicons/vehicle-plate.yaml +7 -0
  231. package/lexicons/walk-rate.yaml +23 -0
  232. package/lexicons/walk-word.yaml +16 -0
  233. package/lexicons/weekly-days-off.yaml +35 -0
  234. package/lexicons/year-span-joiner.yaml +13 -0
  235. package/package.json +1 -1
  236. package/src/currency-amounts.ts +96 -0
  237. package/src/era-year.ts +66 -0
  238. package/src/lexicons.ts +14 -0
  239. package/src/numbers.ts +7 -3
  240. package/src/quantities.ts +61 -29
  241. package/src/structure.ts +5 -1
  242. package/src/unit-case.ts +14 -0
@@ -0,0 +1,22 @@
1
+ # 期間あたりの使う回数(1日3回)と、数を上限にする語(product-exceeds-maximum、interval-count-mismatch)。
2
+ # period は期間の語で、weight はその長さ(時間)。数より前に書く(1日3回)。counter は回数の単位。limit は上限の語で、
3
+ # before は数より前の同じ文の中(1日の最大量は4錠)、after は数のすぐ後ろ(1日3回まで)。
4
+ id: use-count-word
5
+ language: ja
6
+ entries:
7
+ - { pattern: "1日", group: period, weight: 24, position: before }
8
+ - { pattern: "一日", group: period, weight: 24, position: before }
9
+ - { pattern: "24時間", group: period, weight: 24, position: before }
10
+ - { pattern: "1週間", group: period, weight: 168, position: before }
11
+ - { pattern: "回", group: counter }
12
+ - { pattern: "最大", group: limit, position: before }
13
+ - { pattern: "最高", group: limit, position: before }
14
+ - { pattern: "上限", group: limit, position: before }
15
+ - { pattern: "限度", group: limit, position: before }
16
+ - { pattern: "まで", group: limit, position: after }
17
+ - { pattern: "以内", group: limit, position: after }
18
+ - { pattern: "以下", group: limit, position: after }
19
+ - { pattern: "を超え", group: limit, position: after }
20
+ - { pattern: "を越え", group: limit, position: after }
21
+ - { pattern: "を限度", group: limit, position: after }
22
+ - { pattern: "を上限", group: limit, position: after }
@@ -0,0 +1,18 @@
1
+ # 使う間隔の下限と、表の回数の列(interval-count-mismatch)。minimum は長さを下限にする語で、長さのすぐ後ろに書く
2
+ # (4時間以上)。cue は下限の長さを使う間隔にする語で、同じ文の中に書く(間隔、あけ)。column は期間あたりの回数の列の見出しで、
3
+ # weight はその期間の長さ(時間)。
4
+ id: use-interval-word
5
+ language: ja
6
+ entries:
7
+ - { pattern: "以上", group: minimum, position: after }
8
+ - { pattern: "間隔", group: cue }
9
+ - { pattern: "あけ", group: cue }
10
+ - { pattern: "空け", group: cue }
11
+ - { pattern: "開け", group: cue }
12
+ - { pattern: "おい", group: cue }
13
+ - { pattern: "置い", group: cue }
14
+ - { pattern: "1日の服用回数", group: column, weight: 24 }
15
+ - { pattern: "1日の使用回数", group: column, weight: 24 }
16
+ - { pattern: "1日の回数", group: column, weight: 24 }
17
+ - { pattern: "1日回数", group: column, weight: 24 }
18
+ - { pattern: "服用回数", group: column, weight: 24 }
@@ -0,0 +1,17 @@
1
+ # 予算と決算を並べた表で、列の見出しが言う役割(variance-mismatch)。group: budget は予算の列、actual は決算・実績の列、
2
+ # variance は二つの差の列、rate は率の列(差の列としては読まない)。rate、variance、budget、actual の順に見るので、
3
+ # 「増減率」は率の列、「予算比」は差の列になる。字面どおりに照らす。
4
+ id: variance-column
5
+ language: ja
6
+ entries:
7
+ - { pattern: 率, group: rate }
8
+ - { pattern: "%", group: rate }
9
+ - { pattern: 増減, group: variance }
10
+ - { pattern: 差異, group: variance }
11
+ - { pattern: 差額, group: variance }
12
+ - { pattern: 予算比, group: variance }
13
+ - { pattern: 過不足, group: variance }
14
+ - { pattern: 予算, group: budget }
15
+ - { pattern: 決算, group: actual }
16
+ - { pattern: 実績, group: actual }
17
+ - { pattern: 執行額, group: actual }
@@ -0,0 +1,7 @@
1
+ # 自動車のナンバー(地名・分類番号・かな・一連番号。ひばり野 330 ね 48-15)の形。reference-number-variant は、reference-label の語のすぐ後ろでこの形に合う並びを、ここの group の番号として読む。
2
+ # pattern は正規表現で、名前の付いた部分がナンバーの部分。serial(一連番号)だけが打ち間違いで変わる部分で、ほかの部分がそろっていないナンバーどうしは一文字違いとして比べない。
3
+ id: vehicle-plate
4
+ language: ja
5
+ entries:
6
+ - pattern: '(?<region>[\p{Script=Han}々ぁ-ゖァ-ヺー]{1,5})[  ]?(?<class>[0-90-9]{1,3}[A-Za-zA-Z]?)[  ]?(?<kana>[ぁ-ゖ])[  ]?(?<serial>[0-90-9]{1,2}[-‐−-][0-90-9]{2}|[・・]{1,3}[0-90-9]{1,3}|[0-90-9]{1,4})'
7
+ group: vehicle
@@ -0,0 +1,23 @@
1
+ # 文書に書いた徒歩の速さを読む語(walk-time-distance-mismatch)。速さを書いていない文書の速さは、文書の種類(profiles/listing.yaml)が決める。
2
+ # group per は長さを速さにする語(80mを1分、分速80m)。position は長さのどちら側か、weight はその時間の秒。
3
+ # group round-up は、速さを書いた行にあれば端数を切り上げると言う語。group not-round-up は、切り上げではないと言う語で、
4
+ # 切り上げの語より先に効く(切り上げません)。どちらも無ければ、端数はどちらに丸めてもよい。
5
+ id: walk-rate
6
+ language: ja
7
+ entries:
8
+ - { pattern: "を1分", position: after, group: per, weight: 60 }
9
+ - { pattern: "につき1分", position: after, group: per, weight: 60 }
10
+ - { pattern: "で1分", position: after, group: per, weight: 60 }
11
+ - { pattern: "/分", position: after, group: per, weight: 60 }
12
+ - { pattern: "毎分", position: after, group: per, weight: 60 }
13
+ - { pattern: "/h", position: after, group: per, weight: 3600 }
14
+ - { pattern: "/時", position: after, group: per, weight: 3600 }
15
+ - { pattern: "分速", position: before, group: per, weight: 60 }
16
+ - { pattern: "時速", position: before, group: per, weight: 3600 }
17
+ - { pattern: "切り上げ", group: round-up }
18
+ - { pattern: "切上げ", group: round-up }
19
+ - { pattern: "切り上げません", group: not-round-up }
20
+ - { pattern: "切り上げない", group: not-round-up }
21
+ - { pattern: "切り上げず", group: not-round-up }
22
+ - { pattern: "切り捨て", group: not-round-up }
23
+ - { pattern: "四捨五入", group: not-round-up }
@@ -0,0 +1,16 @@
1
+ # 徒歩の分数を読む語(walk-time-distance-mismatch)。group walk は分数を徒歩の時間にする語、position は分数のどちら側に書くか。
2
+ # group gap は徒歩の語と分数の間に挟んでよい語(徒歩で5分)。group bound は分数を上限や目安にする語(徒歩10分以内)で、その分数は比べない。
3
+ # group range は二つの数を範囲にする語(5分から10分)で、範囲の数は比べない。
4
+ id: walk-word
5
+ language: ja
6
+ entries:
7
+ - { pattern: "徒歩", position: before, group: walk }
8
+ - { pattern: "歩いて", position: before, group: walk }
9
+ - { pattern: "で", group: gap }
10
+ - { pattern: "から", group: range }
11
+ - { pattern: "ないし", group: range }
12
+ - { pattern: "以内", position: after, group: bound }
13
+ - { pattern: "以下", position: after, group: bound }
14
+ - { pattern: "未満", position: after, group: bound }
15
+ - { pattern: "圏内", position: after, group: bound }
16
+ - { pattern: "程度", position: after, group: bound }
@@ -0,0 +1,35 @@
1
+ # 毎週の休みを言う語と、それが一年に必ず生む休日の数(annual-holidays-mismatch)。weight は52週ぶんの最低の日数で、
2
+ # 年間休日がこれより少なければ食い違い。group every-week は毎週その日数を休む語(完全週休2日制は毎週2日で 52 × 2 = 104日、
3
+ # 4週8休は4週ごとに8日で 52 ÷ 4 × 8 = 104日)。group not-every-week は毎週ではない語で、weight を持たない。「完全」の
4
+ # 付かない週休2日制は「月に1回以上、2日休む週がある」という意味で、毎週2日休むとは限らない。これがある文書は比べない。
5
+ id: weekly-days-off
6
+ language: ja
7
+ entries:
8
+ - { pattern: 完全週休2日制, group: every-week, weight: 104 }
9
+ - { pattern: 完全週休2日, group: every-week, weight: 104 }
10
+ - { pattern: 完全週休2日制, group: every-week, weight: 104 }
11
+ - { pattern: 完全週休2日, group: every-week, weight: 104 }
12
+ - { pattern: 完全週休二日制, group: every-week, weight: 104 }
13
+ - { pattern: 完全週休二日, group: every-week, weight: 104 }
14
+ - { pattern: 完全週休3日制, group: every-week, weight: 156 }
15
+ - { pattern: 完全週休3日, group: every-week, weight: 156 }
16
+ - { pattern: 完全週休3日制, group: every-week, weight: 156 }
17
+ - { pattern: 完全週休3日, group: every-week, weight: 156 }
18
+ - { pattern: 完全週休三日制, group: every-week, weight: 156 }
19
+ - { pattern: 完全週休三日, group: every-week, weight: 156 }
20
+ - { pattern: 4週8休, group: every-week, weight: 104 }
21
+ - { pattern: 4週8休, group: every-week, weight: 104 }
22
+ - { pattern: 4週6休, group: every-week, weight: 78 }
23
+ - { pattern: 4週6休, group: every-week, weight: 78 }
24
+ - { pattern: 週休2日制, group: not-every-week }
25
+ - { pattern: 週休2日, group: not-every-week }
26
+ - { pattern: 週休2日制, group: not-every-week }
27
+ - { pattern: 週休2日, group: not-every-week }
28
+ - { pattern: 週休二日制, group: not-every-week }
29
+ - { pattern: 週休二日, group: not-every-week }
30
+ - { pattern: 週休3日制, group: not-every-week }
31
+ - { pattern: 週休3日, group: not-every-week }
32
+ - { pattern: 週休3日制, group: not-every-week }
33
+ - { pattern: 週休3日, group: not-every-week }
34
+ - { pattern: 週休三日制, group: not-every-week }
35
+ - { pattern: 週休三日, group: not-every-week }
@@ -0,0 +1,13 @@
1
+ # 期間の始めと終わりの日付をつなぐ言葉。date-without-year は、終わりの日付の年を語で言う期間(4月1日から翌年3月31日まで)の
2
+ # 始めの日付を指さない。毎年度の区切りのように、どの年にも当てはまる期間だから。
3
+ id: year-span-joiner
4
+ language: ja
5
+ entries:
6
+ - pattern: から
7
+ - pattern: 〜
8
+ - pattern: ~
9
+ - pattern: "-"
10
+ - pattern: -
11
+ - pattern: ‐
12
+ - pattern: –
13
+ - pattern: —
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaffjs/lang-ja",
3
- "version": "0.29.0",
3
+ "version": "0.31.0",
4
4
  "description": "Japanese language adapter for chaff",
5
5
  "license": "MIT",
6
6
  "author": "isamu",
@@ -0,0 +1,96 @@
1
+ import { parseJapaneseNumber, toHalfWidth } from "./numbers.ts";
2
+ import { startsWithUnit } from "./unit-case.ts";
3
+
4
+ // 通貨の書き方(語彙 currency-notation)と百分率の単位(percent-unit)で読む金額と率。助数詞として読めない書き方
5
+ // (¥1,320、US$1,320、1,320米ドル、1,320ユーロ、1,320兆円、1,320 JPY、8.0 %)を、語彙だけを頼りに読む。
6
+
7
+ export type Multiplier = { readonly pattern: string; readonly weight: number };
8
+
9
+ export type AmountVocabulary = {
10
+ /** 数の前に書く通貨(¥、US$、JPY)。 */
11
+ readonly before: readonly string[];
12
+ /** 数の後ろに書く通貨(円、米ドル、JPY)と百分率の単位。 */
13
+ readonly after: readonly string[];
14
+ /** 数と後ろの通貨のあいだの桁の語(兆、million)と、それが掛ける数。 */
15
+ readonly multipliers: readonly Multiplier[];
16
+ };
17
+
18
+ export type CurrencyAmount = { readonly start: number; readonly end: number; readonly value: number; readonly unit: string };
19
+
20
+ const DIGITS = /[0-90-9][0-90-9,,..]{0,15}/gu;
21
+ const GAP = /^[ \t\u3000]?/u;
22
+ const LATIN = /[A-Za-z]/u;
23
+ const WORD_CHAR = /[A-Za-z0-90-9]/u;
24
+ /** 数の前のこの字は、数を別のものの続きにする。英字や数字(v1.2)と、時刻や比の後ろ半分(10:30 の 30)。 */
25
+ const CONTINUES_BEFORE = /[A-Za-z0-90-9::]/u;
26
+ /** 桁の語の前に書く位(「1,320百万ユーロ」の百)。 */
27
+ const PLACE = /^[十百千]/u;
28
+ /** 数だけを書いた西暦の年(2026)。後ろに空白と通貨が来ても、年のこと(「2020 USD ベース」)がある。 */
29
+ const YEAR = /^(?:1[89]|2[01])\d{2}$/u;
30
+
31
+ const TRAILING_MARKS = new Set([",", ",", ".", "."]);
32
+
33
+ /** 「1,320.」の終わりの点やカンマは数の一部にしない。 */
34
+ const withoutTrailingMarks = (run: string): string => {
35
+ let end = run.length;
36
+ while (end > 0 && TRAILING_MARKS.has(run.charAt(end - 1))) end -= 1;
37
+ return run.slice(0, end);
38
+ };
39
+
40
+ /** 数の前の通貨。数に触れている短いほう(US$1,320 の $)を取る。英字の通貨は、英字や数字の続きでないものだけ。 */
41
+ const markBefore = (text: string, start: number, marks: readonly string[]): string | undefined => {
42
+ const end = start - (GAP.exec(text.slice(start - 1, start))?.[0].length ?? 0);
43
+ return marks
44
+ .filter((mark) => text.startsWith(mark, end - mark.length) && !(LATIN.test(mark) && WORD_CHAR.test(text.charAt(end - mark.length - 1))))
45
+ .toSorted((left, right) => left.length - right.length)[0];
46
+ };
47
+
48
+ const leadingGap = (rest: string): number => GAP.exec(rest)?.[0].length ?? 0;
49
+
50
+ type Scale = { readonly length: number; readonly weight: number };
51
+
52
+ const multiplierAt = (text: string, multipliers: readonly Multiplier[]): Multiplier | undefined =>
53
+ multipliers
54
+ .filter((entry) => startsWithUnit(text, 0, entry.pattern) && !(LATIN.test(entry.pattern) && WORD_CHAR.test(text.charAt(entry.pattern.length))))
55
+ .toSorted((left, right) => right.pattern.length - left.pattern.length)[0];
56
+
57
+ /** 数の直後の桁(「千」「百万」「兆」「 million」)。無ければ 1 倍。 */
58
+ const scaleAt = (rest: string, multipliers: readonly Multiplier[]): Scale => {
59
+ const gap = leadingGap(rest);
60
+ const place = PLACE.exec(rest.slice(gap))?.[0] ?? "";
61
+ const placed = place === "" ? undefined : multiplierAt(rest.slice(gap + place.length), multipliers);
62
+ if (placed !== undefined) return { length: gap + place.length + placed.pattern.length, weight: (parseJapaneseNumber(place) ?? 1) * placed.weight };
63
+ const multiplier = multiplierAt(rest.slice(gap), multipliers);
64
+ return multiplier === undefined ? { length: 0, weight: 1 } : { length: gap + multiplier.pattern.length, weight: multiplier.weight };
65
+ };
66
+
67
+ /** 数の後ろの通貨か単位。長いほう(米ドル)を取る。英字のものは、後ろに英字が続かないものだけ(USDT は USD でない)。 */
68
+ const markAfter = (rest: string, marks: readonly string[]): { readonly mark: string; readonly gap: number } | undefined => {
69
+ const gap = leadingGap(rest);
70
+ const mark = marks
71
+ .filter((entry) => startsWithUnit(rest, gap, entry) && !(LATIN.test(entry) && WORD_CHAR.test(rest.charAt(gap + entry.length))))
72
+ .toSorted((left, right) => right.length - left.length)[0];
73
+ return mark === undefined ? undefined : { mark, gap };
74
+ };
75
+
76
+ const amountAt = (text: string, match: RegExpExecArray, vocabulary: AmountVocabulary): CurrencyAmount | undefined => {
77
+ const number = withoutTrailingMarks(match[0]);
78
+ const value = parseJapaneseNumber(number);
79
+ const end = match.index + number.length;
80
+ const before = markBefore(text, match.index, vocabulary.before);
81
+ if (value === undefined || (before === undefined && CONTINUES_BEFORE.test(text.charAt(match.index - 1)))) return undefined;
82
+ const scale = scaleAt(text.slice(end), vocabulary.multipliers);
83
+ if (before !== undefined) return { start: match.index, end: end + scale.length, value: value * scale.weight, unit: before };
84
+ const after = markAfter(text.slice(end + scale.length), vocabulary.after);
85
+ if (after === undefined) return undefined;
86
+ // 空白を挟んだ年は通貨の額と読まない。空白の無い「2000ユーロ」は額のまま。
87
+ if (scale.length === 0 && after.gap > 0 && YEAR.test(toHalfWidth(number))) return undefined;
88
+ return { start: match.index, end: end + scale.length + after.gap + after.mark.length, value: value * scale.weight, unit: after.mark };
89
+ };
90
+
91
+ /** 文の中の、通貨の書き方で書いた金額と率。値は桁の語を掛けた数(1,320兆円 は 1,320 × 10^12 円)。 */
92
+ export const currencyAmounts = (text: string, vocabulary: AmountVocabulary): CurrencyAmount[] =>
93
+ [...text.matchAll(DIGITS)].flatMap((match) => {
94
+ const amount = amountAt(text, match, vocabulary);
95
+ return amount === undefined ? [] : [amount];
96
+ });
@@ -0,0 +1,66 @@
1
+ import { parseJapaneseNumber, toHalfWidth } from "./numbers.ts";
2
+ import { escapeRegExp } from "./regexp.ts";
3
+
4
+ // 元号の年と西暦の年を並べて書いた年(令和6年(2024年)、2024年(令和6年)、令和6(2024)年)。純粋。元号とその元年は語彙表 calendar-era が言う。
5
+
6
+ /** 元号と、その元年の西暦の年(令和は 2019)。 */
7
+ export type Era = { readonly name: string; readonly firstYear: number };
8
+
9
+ /**
10
+ * 括弧で言い換えた年の一つ。year は括弧の外に書いた年を西暦にしたもの、glossYear は括弧の中の年を西暦にしたもの。
11
+ * 二つが違えば、どちらかの書き違い。
12
+ */
13
+ export type GlossedYear = { readonly start: number; readonly end: number; readonly year: number; readonly glossYear: number };
14
+
15
+ const ERA_NUMBER = "(?:[0-90-9]{1,2}|[一二三四五六七八九十]{1,3}|元)";
16
+ const WESTERN = "(?:[0-90-9]{4}|[〇一二三四五六七八九]{4})";
17
+ const OPEN = "[((]";
18
+ const CLOSE = "[))]";
19
+ /** 元号と年の数、年の数と単位のあいだの空白 1 つ(令和 6 年)。 */
20
+ const GAP = "[ \\u3000]?";
21
+
22
+ /** 西暦の年の前に数字が続けば、もっと長い数の一部(12024年)。 */
23
+ const NOT_AFTER_DIGIT = "(?<![0-90-9〇一二三四五六七八九十])";
24
+
25
+ /** 括弧の後ろの単位が「年度」なら、暦の年でなく会計の年(令和6(2024)年度)。 */
26
+ const CALENDAR_YEAR_AFTER = "年(?!度)";
27
+
28
+ const shapes = (eras: string): readonly string[] => {
29
+ const era = `(?<era>${eras})${GAP}(?<n>${ERA_NUMBER})${GAP}`;
30
+ const western = `${NOT_AFTER_DIGIT}(?<w>${WESTERN})`;
31
+ return [
32
+ `${era}年${OPEN}${western}年${CLOSE}`,
33
+ `${era}${OPEN}${western}${CLOSE}${CALENDAR_YEAR_AFTER}`,
34
+ `${western}年${OPEN}${era}年${CLOSE}`,
35
+ `${western}${OPEN}${era}${CLOSE}${CALENDAR_YEAR_AFTER}`,
36
+ ];
37
+ };
38
+
39
+ /** 元号の年の数。元年は 1。 */
40
+ const eraNumber = (written: string): number | undefined => (written === "元" ? 1 : parseJapaneseNumber(toHalfWidth(written)));
41
+
42
+ const KANJI_DIGITS = "〇一二三四五六七八九";
43
+
44
+ /** 西暦の年。漢数字(二〇二四)は位取りでなく一字ずつ読む。 */
45
+ const readWestern = (written: string): number =>
46
+ Number([...toHalfWidth(written)].map((char) => (KANJI_DIGITS.includes(char) ? String(KANJI_DIGITS.indexOf(char)) : char)).join(""));
47
+
48
+ const glossedOf = (match: RegExpExecArray, eras: readonly Era[]): GlossedYear[] => {
49
+ const groups = match.groups ?? {};
50
+ const era = eras.find((candidate) => candidate.name === groups["era"]);
51
+ const number = eraNumber(groups["n"] ?? "");
52
+ const western = readWestern(groups["w"] ?? "");
53
+ if (era === undefined || number === undefined || number < 1) return [];
54
+ const fromEra = era.firstYear + number - 1;
55
+ const eraFirst = match[0].startsWith(era.name);
56
+ const [year, glossYear] = eraFirst ? [fromEra, western] : [western, fromEra];
57
+ return [{ start: match.index, end: match.index + match[0].length, year, glossYear }];
58
+ };
59
+
60
+ /** 文の中の、括弧で言い換えた年を読む関数。書き方ごとに探し、出てきた順に並べる。元号が無ければ何も読まない。 */
61
+ export const glossedYearReader = (eras: readonly Era[]): ((text: string) => GlossedYear[]) => {
62
+ if (eras.length === 0) return () => [];
63
+ const patterns = shapes(eras.map((era) => escapeRegExp(era.name)).join("|")).map((shape) => new RegExp(shape, "gu"));
64
+ return (text) =>
65
+ patterns.flatMap((pattern) => [...text.matchAll(pattern)].flatMap((match) => glossedOf(match, eras))).toSorted((left, right) => left.start - right.start);
66
+ };
package/src/lexicons.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { parse } from "yaml";
2
2
  import type { Lexicon, LexiconEntry } from "chaffjs/plugin";
3
3
  import { PACKAGE_DIR, joinPath, readDir, readText } from "./package-files.ts";
4
+ import type { Era } from "./era-year.ts";
4
5
 
5
6
  const DIR = joinPath(PACKAGE_DIR, "lexicons");
6
7
 
@@ -14,6 +15,7 @@ const toEntry = (raw: unknown): LexiconEntry | undefined => {
14
15
  const instead = raw["instead_of"];
15
16
  const rewrite = raw["rewrite"];
16
17
  const group = raw["group"];
18
+ const firstYear = raw["first_year"];
17
19
  return {
18
20
  pattern: raw["pattern"],
19
21
  weight: typeof weight === "number" ? weight : undefined,
@@ -21,6 +23,7 @@ const toEntry = (raw: unknown): LexiconEntry | undefined => {
21
23
  position: POSITIONS.find((position) => position === raw["position"]),
22
24
  rewrite: typeof rewrite === "string" ? rewrite : undefined,
23
25
  ...(typeof group === "string" ? { group } : {}),
26
+ ...(typeof firstYear === "number" ? { first_year: firstYear } : {}),
24
27
  };
25
28
  };
26
29
 
@@ -38,3 +41,14 @@ export const loadLexicons = (dir: string = DIR): Record<string, Lexicon> =>
38
41
  return [[raw["id"], raw["entries"].map(toEntry).filter((entry) => entry !== undefined)]];
39
42
  }),
40
43
  );
44
+
45
+ const CALENDAR_ERA = "calendar-era.yaml";
46
+
47
+ const toEra = (raw: unknown): Era[] =>
48
+ isRecord(raw) && typeof raw["pattern"] === "string" && typeof raw["first_year"] === "number" ? [{ name: raw["pattern"], firstYear: raw["first_year"] }] : [];
49
+
50
+ /** 語彙表 calendar-era の元号と、その元年の西暦の年。first_year の無い元号は西暦にできないので入れない。 */
51
+ export const loadCalendarEras = (dir: string = DIR): Era[] => {
52
+ const raw: unknown = parse(readText(joinPath(dir, CALENDAR_ERA)));
53
+ return isRecord(raw) && Array.isArray(raw["entries"]) ? raw["entries"].flatMap(toEra) : [];
54
+ };
package/src/numbers.ts CHANGED
@@ -19,16 +19,20 @@ const step = (acc: Reading, char: string): Reading => {
19
19
  return { done: acc.done, total: acc.total, current: acc.current * 10 + (DIGIT[char] ?? 0) };
20
20
  };
21
21
 
22
+ /** 算用数字の後ろの桁の語: 万・億、その前の十・百・千(百万 = 10^6、十億)、千だけ(千円単位の表)。 */
23
+ const ARABIC_SCALED = /^(?<n>\d+(?:\.\d+)?)(?<scale>[十百千]?[万億]|千)$/u;
24
+
22
25
  /**
23
26
  * 番号や数を数にする。全角数字は半角に、漢数字は位取りで読む(十二 = 12、二十一 = 21、百五 = 105、一〇 = 10)。
24
- * 算用数字と万・億の組(「10万」)も読む。小数(「1.5」)も読む。読めないものは undefined。
27
+ * 算用数字と桁の語の組(「10万」、決算の表の「2,400百万」「1,320千」)も読む。小数(「1.5」)も読む。読めないものは undefined。
25
28
  * 番号を読み違えると番地が変わり、参照先が無いという誤りを作ってしまう。
26
29
  */
27
30
  export const parseJapaneseNumber = (text: string): number | undefined => {
28
31
  const half = toHalfWidth(text).replace(/,/gu, "");
29
32
  if (/^\d+(?:\.\d+)?$/u.test(half)) return Number(half);
30
- const arabicMyriad = /^(?<n>\d+(?:\.\d+)?)(?<unit>[万億])$/u.exec(half)?.groups;
31
- if (arabicMyriad?.["n"] !== undefined && arabicMyriad["unit"] !== undefined) return Number(arabicMyriad["n"]) * (MYRIAD[arabicMyriad["unit"]] ?? 1);
33
+ const arabicScaled = ARABIC_SCALED.exec(half)?.groups;
34
+ const scale = arabicScaled?.["scale"] === undefined ? undefined : parseJapaneseNumber(arabicScaled["scale"]);
35
+ if (arabicScaled?.["n"] !== undefined && scale !== undefined) return Number(arabicScaled["n"]) * scale;
32
36
  if (!/^[〇一二三四五六七八九十百千万億]+$/u.test(text)) return undefined;
33
37
  const { done, total, current } = [...text].reduce(step, { done: 0, total: 0, current: 0 });
34
38
  return done + total + current;
package/src/quantities.ts CHANGED
@@ -1,10 +1,18 @@
1
1
  import type { Mention } from "chaffjs/plugin";
2
2
  import { parseJapaneseNumber, toHalfWidth } from "./numbers.ts";
3
3
  import { isReady, morphemes, type Morph } from "./pos.ts";
4
+ import { currencyAmounts, type AmountVocabulary } from "./currency-amounts.ts";
5
+ import { glossedYearReader } from "./era-year.ts";
6
+ import { loadCalendarEras, loadLexicons } from "./lexicons.ts";
7
+ import { escapeRegExp } from "./regexp.ts";
4
8
 
5
9
  // 数量と日付。形態素が使えれば品詞で読み、使えなければ単位の表で読む。
6
10
 
7
- type Counted = { readonly start: number; readonly end: number; readonly value: number; readonly unit: string };
11
+ /** 元号と元年の西暦の年は語彙表 calendar-era が言う。 */
12
+ const ERAS = loadCalendarEras();
13
+
14
+ /** glossYear: 括弧で言い換えた年(令和6年(2024年))の、括弧の中の年を西暦にしたもの。 */
15
+ type Counted = { readonly start: number; readonly end: number; readonly value: number; readonly unit: string; readonly glossYear?: number };
8
16
 
9
17
  const PERCENT = new Set(["%", "%"]);
10
18
  /** 形態素が無いときの単位の表。長いものから当てる。形態素があれば、助数詞はすべて読める。 */
@@ -50,10 +58,12 @@ const isJoiner = (morphs: readonly Morph[], index: number): boolean => {
50
58
 
51
59
  /** 桁の語。「26.7 万行」「1.2 万円」のように、数と空白 1 つを挟んで書かれても同じ数の一部。兆は数として読めないので入れない。 */
52
60
  const MULTIPLIERS = new Set(["万", "億"]);
61
+ /** 算用数字の後ろの桁の語(「2,400 百万円」「1,320 千円」)の頭。空白を挟んでも数の続き。 */
62
+ const SCALE_HEADS = new Set(["十", "百", "千", ...MULTIPLIERS]);
53
63
 
54
64
  /** 数と桁の語のあいだの空白 1 つ。 */
55
65
  const isSpacedMultiplier = (morphs: readonly Morph[], index: number): boolean =>
56
- isSpace(morphs[index]) && isNumeral(morphs[index - 1]) && MULTIPLIERS.has(morphs[index + 1]?.surface ?? "");
66
+ isSpace(morphs[index]) && isNumeral(morphs[index - 1]) && SCALE_HEADS.has(morphs[index + 1]?.surface ?? "");
57
67
 
58
68
  /** index から始まる数の並びの終わり(含まない)。 */
59
69
  const runEnd = (morphs: readonly Morph[], index: number): number => {
@@ -152,8 +162,8 @@ const countedByMorphemes = (text: string, morphs: readonly Morph[]): Counted[] =
152
162
  return found;
153
163
  };
154
164
 
155
- /** 算用数字は、すぐ後ろか空白 1 つを挟んだ桁の語(1.2万、1.2 万)まで一つの数。形態素の経路と同じ読み方。 */
156
- const NUMBER_RUN = /[0-90-9][0-90-9.,]{0,15}(?:[ \t\u3000]?[万億])?|[〇一二三四五六七八九十百千万億]{1,12}/gu;
165
+ /** 算用数字は、すぐ後ろか空白 1 つを挟んだ桁の語(1.2万、1.2 万、2,400百万)まで一つの数。形態素の経路と同じ読み方。 */
166
+ const NUMBER_RUN = /[0-90-9][0-90-9.,]{0,15}(?:[ \t\u3000]?[十百千]?[万億千])?|[〇一二三四五六七八九十百千万億]{1,12}/gu;
157
167
 
158
168
  export const countedByTable = (text: string): Counted[] =>
159
169
  [...text.matchAll(NUMBER_RUN)].flatMap((match) => {
@@ -171,24 +181,26 @@ const last: { text: string | undefined; ready: boolean; found: readonly Counted[
171
181
  /** これより小さい「年」は期間(3年)で、暦の年ではない。 */
172
182
  const YEAR_FLOOR = 1000;
173
183
 
174
- /** 「2026年(令和8年)9月4日」: 西暦の年のすぐ後ろの括弧に書いた元号の年は、同じ年の言い換えで、数量でも別の日付でもない。 */
175
- const ERA_GLOSS = /^[((](?:令和|平成|昭和|大正|明治)(?:[0-9〇一二三四五六七八九十]{1,3}|元)年[))]/u;
176
-
177
- /** 括弧の言い換えを西暦の年に含め、括弧の中の年を落とす。年の後ろに月が続けば、一つの日付として読める。 */
178
- const withEraGlosses = (text: string, found: readonly Counted[]): Counted[] =>
179
- found.reduce<Counted[]>((kept, item) => {
180
- const previous = kept.at(-1);
181
- if (previous !== undefined && item.end <= previous.end) return kept;
182
- const gloss = item.unit === "年" && item.value >= YEAR_FLOOR ? ERA_GLOSS.exec(text.slice(item.end)) : null;
183
- return [...kept, gloss === null ? item : { ...item, end: item.end + gloss[0].length }];
184
- }, []);
184
+ /**
185
+ * 元号の年と西暦の年を括弧で並べた年(令和6年(2024年)、2024年(令和8年)、令和6(2024)年)は、一つの暦の年。
186
+ * 括弧の外に書いた年を読み、中の年は数量でも別の日付でもない。年の後ろに月が続けば、一つの日付として読める。
187
+ */
188
+ const GLOSSED_YEARS = glossedYearReader(ERAS);
189
+
190
+ const withGlossedYears = (text: string, found: readonly Counted[]): Counted[] => {
191
+ const glossed = GLOSSED_YEARS(text);
192
+ if (glossed.length === 0) return [...found];
193
+ const years = glossed.map((item): Counted => ({ start: item.start, end: item.end, value: item.year, unit: "年", glossYear: item.glossYear }));
194
+ const outside = found.filter((item) => !years.some((year) => item.start < year.end && year.start < item.end));
195
+ return [...outside, ...years].toSorted((left, right) => left.start - right.start);
196
+ };
185
197
 
186
198
  const counted = (text: string): readonly Counted[] => {
187
199
  if (last.text === text && last.ready === isReady()) return last.found;
188
200
  // IPADIC は全角の「4月」を一語の名詞と読む。全角数字は 1 文字ずつ半角にしてから読むので、位置は変わらない。
189
201
  const half = toHalfWidth(text);
190
202
  const morphs = morphemes(half);
191
- const found = withEraGlosses(half, morphs === undefined ? countedByTable(text) : countedByMorphemes(half, morphs));
203
+ const found = withGlossedYears(half, morphs === undefined ? countedByTable(text) : countedByMorphemes(half, morphs));
192
204
  Object.assign(last, { text, ready: isReady(), found });
193
205
  return found;
194
206
  };
@@ -201,10 +213,12 @@ type DateMatch = { readonly date: Mention; readonly used: number };
201
213
  const follows = (left: Counted | undefined, right: Counted | undefined, unit: string): right is Counted =>
202
214
  left !== undefined && right?.unit === unit && right.start === left.end;
203
215
 
204
- const dateOf = (parts: readonly Counted[], value: string): DateMatch => ({
205
- date: { start: parts[0]?.start ?? 0, end: parts.at(-1)?.end ?? 0, attrs: { value } },
206
- used: parts.length,
207
- });
216
+ /** 括弧で言い換えた年で始まる日付は、括弧の中の年も持つ(attrs.glossYear)。外の年と違えば、どちらかの書き違い。 */
217
+ const dateOf = (parts: readonly Counted[], value: string): DateMatch => {
218
+ const glossYear = parts[0]?.glossYear;
219
+ const attrs = glossYear === undefined ? { value } : { value, glossYear };
220
+ return { date: { start: parts[0]?.start ?? 0, end: parts.at(-1)?.end ?? 0, attrs }, used: parts.length };
221
+ };
208
222
 
209
223
  /** 「2024年4月1日」「2024年4月」。 */
210
224
  const yearMonth = (year: Counted | undefined, month: Counted | undefined, day: Counted | undefined): DateMatch | undefined => {
@@ -260,10 +274,25 @@ type Span = { readonly start: number; readonly end: number };
260
274
  /** ISO の日付の中の数(「02」)を、数量や年月日の日付として二重に読まない。 */
261
275
  const overlaps = (item: Span, spans: readonly Span[]): boolean => spans.some((span) => item.start < span.end && span.start < item.end);
262
276
 
277
+ const LEXICONS = loadLexicons();
278
+ const notation = (position: "before" | "after"): string[] =>
279
+ (LEXICONS["currency-notation"] ?? []).filter((entry) => entry.position === position).map((entry) => entry.pattern);
280
+
281
+ const AMOUNT_VOCABULARY: AmountVocabulary = {
282
+ before: notation("before"),
283
+ after: [...notation("after"), ...(LEXICONS["percent-unit"] ?? []).map((entry) => entry.pattern)],
284
+ multipliers: (LEXICONS["amount-multiplier"] ?? []).flatMap((entry) => (entry.weight === undefined ? [] : [{ pattern: entry.pattern, weight: entry.weight }])),
285
+ };
286
+
263
287
  export const quantities = (text: string): Mention[] => {
264
288
  const iso = isoDates(text);
265
- return toDates(counted(text))
266
- .rest.filter((item) => !overlaps(item, iso))
289
+ const { dates: written, rest } = toDates(counted(text));
290
+ const read = rest.filter((item) => !overlaps(item, iso));
291
+ // 助数詞として読めない通貨の書き方(¥1,320、1,320米ドル)は、ほかの読みと重ならないものだけ足す。
292
+ const taken = [...iso, ...written, ...read];
293
+ const added = currencyAmounts(text, AMOUNT_VOCABULARY).filter((item) => !overlaps(item, taken));
294
+ return [...read, ...added]
295
+ .toSorted((left, right) => left.start - right.start)
267
296
  .map((item) => ({ start: item.start, end: item.end, attrs: { value: item.value, unit: item.unit } }));
268
297
  };
269
298
 
@@ -278,19 +307,22 @@ const weekdayAfter = (text: string, end: number): number | undefined => {
278
307
  };
279
308
 
280
309
  /** 元号の最初の年の前年(令和1年 = 2019 年)。元号で書いた日付を西暦の日付にする。 */
281
- const ERA_BASE: Readonly<Record<string, number>> = { 令和: 2018, 平成: 1988, 昭和: 1925, 大正: 1911, 明治: 1867 };
282
- const ERA_BEFORE = /(?<era>令和|平成|昭和|大正|明治)$/u;
310
+ const ERA_BASE: ReadonlyMap<string, number> = new Map(ERAS.map((era) => [era.name, era.firstYear - 1]));
311
+ const ERA_NAMES = ERAS.map((era) => escapeRegExp(era.name)).join("|");
312
+ const LONGEST_ERA = Math.max(0, ...ERAS.map((era) => era.name.length));
313
+ const ERA_BEFORE = new RegExp(`(?<era>${ERA_NAMES})$`, "u");
283
314
  /** 月の付いた日付の年を直す。年だけ(「昭和二十二年法律」)は 1000 に届かないので、はじめから日付でなく期間の数量。 */
284
315
  const ERA_DATE = /^(?<year>\d{1,2})-(?<rest>.+)$/u;
285
316
 
286
317
  /** 「令和元年10月1日」: 元年は数として読めないので、年の無い 10-01 になっている。その前の「元号 + 元年」を 1 年として足す。 */
287
- const FIRST_YEAR_BEFORE = /(?<era>令和|平成|昭和|大正|明治)元年$/u;
318
+ const FIRST_YEAR = "元年";
319
+ const FIRST_YEAR_BEFORE = new RegExp(`(?<era>${ERA_NAMES})${FIRST_YEAR}$`, "u");
288
320
  const MONTH_DAY = /^\d{2}-\d{2}$/u;
289
321
 
290
322
  const inFirstEraYear = (text: string, date: Mention): Mention | undefined => {
291
323
  if (!MONTH_DAY.test(String(date.attrs["value"]))) return undefined;
292
- const found = FIRST_YEAR_BEFORE.exec(text.slice(Math.max(0, date.start - 4), date.start));
293
- const base = found?.groups?.["era"] === undefined ? undefined : ERA_BASE[found.groups["era"]];
324
+ const found = FIRST_YEAR_BEFORE.exec(text.slice(Math.max(0, date.start - LONGEST_ERA - FIRST_YEAR.length), date.start));
325
+ const base = found?.groups?.["era"] === undefined ? undefined : ERA_BASE.get(found.groups["era"]);
294
326
  if (found === null || base === undefined) return undefined;
295
327
  return { ...date, start: date.start - found[0].length, attrs: { ...date.attrs, value: `${String(base + 1)}-${String(date.attrs["value"])}` } };
296
328
  };
@@ -299,8 +331,8 @@ const inWesternYear = (text: string, date: Mention): Mention => {
299
331
  const first = inFirstEraYear(text, date);
300
332
  if (first !== undefined) return first;
301
333
  const parts = ERA_DATE.exec(String(date.attrs["value"]))?.groups;
302
- const era = ERA_BEFORE.exec(text.slice(Math.max(0, date.start - 2), date.start))?.groups?.["era"];
303
- const base = era === undefined ? undefined : ERA_BASE[era];
334
+ const era = ERA_BEFORE.exec(text.slice(Math.max(0, date.start - LONGEST_ERA), date.start))?.groups?.["era"];
335
+ const base = era === undefined ? undefined : ERA_BASE.get(era);
304
336
  if (parts === undefined || era === undefined || base === undefined) return date;
305
337
  const value = `${String(base + Number(parts["year"]))}-${parts["rest"] ?? ""}`;
306
338
  return { ...date, start: date.start - era.length, attrs: { ...date.attrs, value } };
package/src/structure.ts CHANGED
@@ -205,7 +205,11 @@ const mentions = (
205
205
  return found === undefined ? [] : [{ start: match.index, end: match.index + match[0].length, attrs: found }];
206
206
  });
207
207
 
208
- const DEFINITIONS = [/以下「(?<term>[^「」\n]{1,40})」という/gu, /「(?<term>[^「」\n]{1,40})」とは/gu];
208
+ /**
209
+ * 括弧の中の定義は、法令の形(以下「X」という。以下「X」といい、)も、規約やポリシーの丁寧な形(以下、「X」といいます。)も読む。
210
+ * 「以下「X」」の枠と、句点・読点・閉じ括弧で切れる述語が要るので、地の文(そう言います、以下、「X」という見出し)は当たらない。
211
+ */
212
+ const DEFINITIONS = [/以下[、,]?「(?<term>[^「」\n]{1,40})」とい(?:う|い(?:ます)?)(?=[。、,))\s]|$)/gu, /「(?<term>[^「」\n]{1,40})」とは/gu];
209
213
 
210
214
  /**
211
215
  * 範囲を限った定義。「この条において『X』とは」「前項に規定する『X』とは」は、その条や項の中だけの定義で、
@@ -0,0 +1,14 @@
1
+ // 語彙の単位が語(大文字小文字を問わずに読む)か、記号(書かれたとおりに読む)か。
2
+
3
+ /**
4
+ * A word is three or more lowercase letters, possibly in several words ("percent", "per cent", "million", "yen"). Anything
5
+ * else is a symbol whose case carries meaning: a capital the lexicon wrote (USD, kDa, mL vs ML), or a lowercase symbol of
6
+ * one or two letters (m vs M, g vs G, mg vs Mg).
7
+ */
8
+ const UNIT_WORD = /^\p{Ll}{3,}(?: \p{Ll}+)*$/u;
9
+
10
+ export const isUnitWord = (unit: string): boolean => UNIT_WORD.test(unit);
11
+
12
+ /** "8.5 Percent", "198 Million Yen": a unit word starts at `at` in any case; a symbol only as the lexicon wrote it. */
13
+ export const startsWithUnit = (text: string, at: number, unit: string): boolean =>
14
+ isUnitWord(unit) ? text.slice(at, at + unit.length).toLowerCase() === unit : text.startsWith(unit, at);