@chaffjs/lang-ja 0.27.0 → 0.29.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 (115) hide show
  1. package/dist/quantities.d.ts.map +1 -1
  2. package/dist/quantities.js +47 -6
  3. package/dist/quantities.js.map +1 -1
  4. package/lexicons/action-due-label.yaml +9 -0
  5. package/lexicons/action-section-heading.yaml +9 -0
  6. package/lexicons/amount-bound-label.yaml +11 -0
  7. package/lexicons/amount-change-word.yaml +28 -0
  8. package/lexicons/clock-range-joiner.yaml +12 -0
  9. package/lexicons/code-global.yaml +27 -0
  10. package/lexicons/common-acronym.yaml +19 -0
  11. package/lexicons/company-form.yaml +21 -13
  12. package/lexicons/connective-clause-end.yaml +9 -0
  13. package/lexicons/count-counter.yaml +2 -0
  14. package/lexicons/count-hedge.yaml +4 -0
  15. package/lexicons/count-member.yaml +34 -0
  16. package/lexicons/day-shift-mark.yaml +15 -0
  17. package/lexicons/deadline-passed-word.yaml +11 -0
  18. package/lexicons/default-header.yaml +9 -0
  19. package/lexicons/default-phrase.yaml +10 -0
  20. package/lexicons/defined-term-pointer.yaml +12 -0
  21. package/lexicons/deprecation-negated.yaml +9 -0
  22. package/lexicons/deprecation-word.yaml +8 -0
  23. package/lexicons/due-date-label.yaml +12 -0
  24. package/lexicons/duty-ending.yaml +28 -0
  25. package/lexicons/duty-terms-elsewhere.yaml +9 -0
  26. package/lexicons/earlier-section-word.yaml +7 -0
  27. package/lexicons/fact-change-from.yaml +5 -0
  28. package/lexicons/fact-change-subject-mark.yaml +6 -0
  29. package/lexicons/fact-change-to.yaml +7 -0
  30. package/lexicons/fact-condition-from.yaml +18 -0
  31. package/lexicons/fact-condition-to.yaml +14 -0
  32. package/lexicons/fact-event.yaml +12 -0
  33. package/lexicons/fact-label-lead.yaml +9 -0
  34. package/lexicons/fact-name-joiner.yaml +6 -0
  35. package/lexicons/fact-value-end.yaml +20 -0
  36. package/lexicons/floor-level.yaml +7 -0
  37. package/lexicons/floor-unit.yaml +7 -0
  38. package/lexicons/install-command.yaml +20 -0
  39. package/lexicons/issue-date-label.yaml +7 -0
  40. package/lexicons/item-done-word.yaml +8 -0
  41. package/lexicons/kana-function-word.yaml +41 -0
  42. package/lexicons/label-particle.yaml +7 -0
  43. package/lexicons/leg-column.yaml +13 -0
  44. package/lexicons/leg-mark.yaml +11 -0
  45. package/lexicons/length-half.yaml +5 -0
  46. package/lexicons/line-amount-column.yaml +8 -0
  47. package/lexicons/local-time-mark.yaml +8 -0
  48. package/lexicons/meeting-date-label.yaml +9 -0
  49. package/lexicons/minutes-title-word.yaml +9 -0
  50. package/lexicons/nado-closed-list.yaml +39 -0
  51. package/lexicons/name-label.yaml +8 -0
  52. package/lexicons/name-particle.yaml +19 -0
  53. package/lexicons/name-quote.yaml +7 -0
  54. package/lexicons/number-word.yaml +54 -0
  55. package/lexicons/ordinal-frame.yaml +18 -0
  56. package/lexicons/parameter-header.yaml +11 -0
  57. package/lexicons/partial-listing-marker.yaml +16 -0
  58. package/lexicons/party-order-joiner.yaml +20 -0
  59. package/lexicons/party-order-label.yaml +9 -0
  60. package/lexicons/per-unit-mark.yaml +24 -0
  61. package/lexicons/period-aside.yaml +32 -0
  62. package/lexicons/period-deadline.yaml +11 -0
  63. package/lexicons/period-label.yaml +16 -0
  64. package/lexicons/period-overview-heading.yaml +8 -0
  65. package/lexicons/period-term-label.yaml +9 -0
  66. package/lexicons/person-lead.yaml +11 -0
  67. package/lexicons/phone-label.yaml +18 -0
  68. package/lexicons/place-word.yaml +20 -0
  69. package/lexicons/prerequisite-opener.yaml +10 -0
  70. package/lexicons/quantity-column.yaml +8 -0
  71. package/lexicons/quote-advice.yaml +30 -0
  72. package/lexicons/quote-attribution.yaml +3 -0
  73. package/lexicons/rate-unit.yaml +19 -0
  74. package/lexicons/requirement-heading.yaml +19 -0
  75. package/lexicons/requirement-item-ending.yaml +14 -0
  76. package/lexicons/requirement-length-unit.yaml +12 -0
  77. package/lexicons/requirement-length-word.yaml +8 -0
  78. package/lexicons/return-clause.yaml +11 -0
  79. package/lexicons/return-item.yaml +8 -0
  80. package/lexicons/return-label.yaml +8 -0
  81. package/lexicons/return-subject.yaml +8 -0
  82. package/lexicons/return-type-word.yaml +14 -0
  83. package/lexicons/return-verb.yaml +9 -0
  84. package/lexicons/self-reference-noun.yaml +30 -0
  85. package/lexicons/sentence-opener.yaml +15 -0
  86. package/lexicons/session-count-unit.yaml +7 -0
  87. package/lexicons/session-total.yaml +11 -0
  88. package/lexicons/share-column-rate.yaml +16 -0
  89. package/lexicons/share-column.yaml +10 -0
  90. package/lexicons/share-rest.yaml +7 -0
  91. package/lexicons/stated-deadline-not.yaml +6 -0
  92. package/lexicons/stated-deadline.yaml +13 -0
  93. package/lexicons/stay-check-in-column.yaml +8 -0
  94. package/lexicons/stay-check-out-column.yaml +7 -0
  95. package/lexicons/stay-night.yaml +5 -0
  96. package/lexicons/stay-nights-column.yaml +7 -0
  97. package/lexicons/stay-pair-joiner.yaml +7 -0
  98. package/lexicons/summed-counter.yaml +14 -0
  99. package/lexicons/tax-included-word.yaml +8 -0
  100. package/lexicons/tax-label.yaml +8 -0
  101. package/lexicons/timed-duty.yaml +18 -0
  102. package/lexicons/travel-time-word.yaml +32 -0
  103. package/lexicons/uncomparable-graded.yaml +36 -0
  104. package/lexicons/unit-price-column.yaml +7 -0
  105. package/lexicons/unnamed-speaker.yaml +38 -0
  106. package/lexicons/very-copula.yaml +13 -0
  107. package/lexicons/very-exception.yaml +5 -0
  108. package/lexicons/very-intensifier.yaml +10 -0
  109. package/lexicons/warning-action.yaml +16 -0
  110. package/lexicons/warning-label.yaml +11 -0
  111. package/lexicons/wordy-phrase.yaml +19 -0
  112. package/lexicons/working-hours-break.yaml +9 -0
  113. package/lexicons/working-hours-total.yaml +10 -0
  114. package/package.json +1 -1
  115. package/src/quantities.ts +58 -11
@@ -0,0 +1,10 @@
1
+ # 休憩を除いた勤務時間に付ける語(duration-mismatch の勤務時間)。before は長さの前(実働8時間)、after は後ろ(8時間労働)。
2
+ id: working-hours-total
3
+ language: ja
4
+ entries:
5
+ - { pattern: "実働", position: before }
6
+ - { pattern: "実働時間", position: before }
7
+ - { pattern: "実労働", position: before }
8
+ - { pattern: "実労働時間", position: before }
9
+ - { pattern: "所定労働時間", position: before }
10
+ - { pattern: "労働", position: after }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaffjs/lang-ja",
3
- "version": "0.27.0",
3
+ "version": "0.29.0",
4
4
  "description": "Japanese language adapter for chaff",
5
5
  "license": "MIT",
6
6
  "author": "isamu",
package/src/quantities.ts CHANGED
@@ -168,20 +168,33 @@ export const countedByTable = (text: string): Counted[] =>
168
168
  /** quantities と dates は同じ行を続けて読む。直前の 1 行だけ覚えて、同じ行を二度解析しない。 */
169
169
  const last: { text: string | undefined; ready: boolean; found: readonly Counted[] } = { text: undefined, ready: false, found: [] };
170
170
 
171
+ /** これより小さい「年」は期間(3年)で、暦の年ではない。 */
172
+ const YEAR_FLOOR = 1000;
173
+
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
+ }, []);
185
+
171
186
  const counted = (text: string): readonly Counted[] => {
172
187
  if (last.text === text && last.ready === isReady()) return last.found;
173
188
  // IPADIC は全角の「4月」を一語の名詞と読む。全角数字は 1 文字ずつ半角にしてから読むので、位置は変わらない。
174
189
  const half = toHalfWidth(text);
175
190
  const morphs = morphemes(half);
176
- const found = morphs === undefined ? countedByTable(text) : countedByMorphemes(half, morphs);
191
+ const found = withEraGlosses(half, morphs === undefined ? countedByTable(text) : countedByMorphemes(half, morphs));
177
192
  Object.assign(last, { text, ready: isReady(), found });
178
193
  return found;
179
194
  };
180
195
 
181
196
  const pad = (value: number): string => String(value).padStart(2, "0");
182
197
 
183
- const YEAR_FLOOR = 1000;
184
-
185
198
  type DateMatch = { readonly date: Mention; readonly used: number };
186
199
 
187
200
  /** right が left の直後に続く、単位 unit の数量か。「2024年 4月」のように間が空けば日付にしない。 */
@@ -223,8 +236,36 @@ const toDates = (items: readonly Counted[]): { readonly dates: Mention[]; readon
223
236
  return { dates, rest };
224
237
  };
225
238
 
226
- export const quantities = (text: string): Mention[] =>
227
- toDates(counted(text)).rest.map((item) => ({ start: item.start, end: item.end, attrs: { value: item.value, unit: item.unit } }));
239
+ /**
240
+ * 「2026-10-02」。前後に数字や記号が続くもの(版 1.2026-10-02、URL やファイルの名前、時刻の付いた日時、番号の一部)は読まない。
241
+ * 4 桁と 2 桁 2 つの組でも、月と日として読めないもの、1000 より小さい年(0120-12-34)は日付でない。
242
+ */
243
+ const ISO_DATE = /(?<![\w/.\-0-9])(?<y>[0-90-9]{4})-(?<m>[0-90-9]{2})-(?<d>[0-90-9]{2})(?![\w/\-0-9]|\.[\w0-9])/gu;
244
+ const MONTHS_IN_YEAR = 12;
245
+ const DAYS_IN_MONTH = 31;
246
+
247
+ const inRange = (value: number, high: number): boolean => value >= 1 && value <= high;
248
+
249
+ const isoDateOf = (match: RegExpExecArray): Mention[] => {
250
+ const [year, month, day] = ["y", "m", "d"].map((name) => Number(toHalfWidth(match.groups?.[name] ?? "")));
251
+ if (year === undefined || month === undefined || day === undefined) return [];
252
+ if (year < YEAR_FLOOR || !inRange(month, MONTHS_IN_YEAR) || !inRange(day, DAYS_IN_MONTH)) return [];
253
+ return [{ start: match.index, end: match.index + match[0].length, attrs: { value: `${String(year)}-${pad(month)}-${pad(day)}` } }];
254
+ };
255
+
256
+ const isoDates = (text: string): Mention[] => [...text.matchAll(ISO_DATE)].flatMap(isoDateOf);
257
+
258
+ type Span = { readonly start: number; readonly end: number };
259
+
260
+ /** ISO の日付の中の数(「02」)を、数量や年月日の日付として二重に読まない。 */
261
+ const overlaps = (item: Span, spans: readonly Span[]): boolean => spans.some((span) => item.start < span.end && span.start < item.end);
262
+
263
+ export const quantities = (text: string): Mention[] => {
264
+ const iso = isoDates(text);
265
+ return toDates(counted(text))
266
+ .rest.filter((item) => !overlaps(item, iso))
267
+ .map((item) => ({ start: item.start, end: item.end, attrs: { value: item.value, unit: item.unit } }));
268
+ };
228
269
 
229
270
  /** 日付のすぐ後ろに書いた曜日(「2026年10月1日(木)」「10月1日 木曜日」)。日曜日が 0。 */
230
271
  const WEEKDAY_CHARS = "日月火水木金土";
@@ -265,12 +306,18 @@ const inWesternYear = (text: string, date: Mention): Mention => {
265
306
  return { ...date, start: date.start - era.length, attrs: { ...date.attrs, value } };
266
307
  };
267
308
 
268
- export const dates = (text: string): Mention[] =>
269
- toDates(counted(text)).dates.map((found) => {
270
- const date = inWesternYear(text, found);
271
- const weekday = weekdayAfter(text, date.end);
272
- return weekday === undefined ? date : { ...date, attrs: { ...date.attrs, weekday } };
273
- });
309
+ const withWeekday = (text: string, date: Mention): Mention => {
310
+ const weekday = weekdayAfter(text, date.end);
311
+ return weekday === undefined ? date : { ...date, attrs: { ...date.attrs, weekday } };
312
+ };
313
+
314
+ export const dates = (text: string): Mention[] => {
315
+ const iso = isoDates(text);
316
+ const written = toDates(counted(text))
317
+ .dates.map((found) => inWesternYear(text, found))
318
+ .filter((date) => !overlaps(date, iso));
319
+ return [...written, ...iso].toSorted((left, right) => left.start - right.start).map((date) => withWeekday(text, date));
320
+ };
274
321
 
275
322
  /** 数がそこで閉じる。助数詞(「万人」)か、名詞でない語(「万を」「万。」)か、行の終わり。 */
276
323
  const closesNumber = (morph: Morph | undefined): boolean => morph === undefined || isCounter(morph) || morph.pos !== "名詞";