@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.
- package/dist/quantities.d.ts.map +1 -1
- package/dist/quantities.js +47 -6
- package/dist/quantities.js.map +1 -1
- package/lexicons/action-due-label.yaml +9 -0
- package/lexicons/action-section-heading.yaml +9 -0
- package/lexicons/amount-bound-label.yaml +11 -0
- package/lexicons/amount-change-word.yaml +28 -0
- package/lexicons/clock-range-joiner.yaml +12 -0
- package/lexicons/code-global.yaml +27 -0
- package/lexicons/common-acronym.yaml +19 -0
- package/lexicons/company-form.yaml +21 -13
- package/lexicons/connective-clause-end.yaml +9 -0
- package/lexicons/count-counter.yaml +2 -0
- package/lexicons/count-hedge.yaml +4 -0
- package/lexicons/count-member.yaml +34 -0
- package/lexicons/day-shift-mark.yaml +15 -0
- package/lexicons/deadline-passed-word.yaml +11 -0
- package/lexicons/default-header.yaml +9 -0
- package/lexicons/default-phrase.yaml +10 -0
- package/lexicons/defined-term-pointer.yaml +12 -0
- package/lexicons/deprecation-negated.yaml +9 -0
- package/lexicons/deprecation-word.yaml +8 -0
- package/lexicons/due-date-label.yaml +12 -0
- package/lexicons/duty-ending.yaml +28 -0
- package/lexicons/duty-terms-elsewhere.yaml +9 -0
- package/lexicons/earlier-section-word.yaml +7 -0
- package/lexicons/fact-change-from.yaml +5 -0
- package/lexicons/fact-change-subject-mark.yaml +6 -0
- package/lexicons/fact-change-to.yaml +7 -0
- package/lexicons/fact-condition-from.yaml +18 -0
- package/lexicons/fact-condition-to.yaml +14 -0
- package/lexicons/fact-event.yaml +12 -0
- package/lexicons/fact-label-lead.yaml +9 -0
- package/lexicons/fact-name-joiner.yaml +6 -0
- package/lexicons/fact-value-end.yaml +20 -0
- package/lexicons/floor-level.yaml +7 -0
- package/lexicons/floor-unit.yaml +7 -0
- package/lexicons/install-command.yaml +20 -0
- package/lexicons/issue-date-label.yaml +7 -0
- package/lexicons/item-done-word.yaml +8 -0
- package/lexicons/kana-function-word.yaml +41 -0
- package/lexicons/label-particle.yaml +7 -0
- package/lexicons/leg-column.yaml +13 -0
- package/lexicons/leg-mark.yaml +11 -0
- package/lexicons/length-half.yaml +5 -0
- package/lexicons/line-amount-column.yaml +8 -0
- package/lexicons/local-time-mark.yaml +8 -0
- package/lexicons/meeting-date-label.yaml +9 -0
- package/lexicons/minutes-title-word.yaml +9 -0
- package/lexicons/nado-closed-list.yaml +39 -0
- package/lexicons/name-label.yaml +8 -0
- package/lexicons/name-particle.yaml +19 -0
- package/lexicons/name-quote.yaml +7 -0
- package/lexicons/number-word.yaml +54 -0
- package/lexicons/ordinal-frame.yaml +18 -0
- package/lexicons/parameter-header.yaml +11 -0
- package/lexicons/partial-listing-marker.yaml +16 -0
- package/lexicons/party-order-joiner.yaml +20 -0
- package/lexicons/party-order-label.yaml +9 -0
- package/lexicons/per-unit-mark.yaml +24 -0
- package/lexicons/period-aside.yaml +32 -0
- package/lexicons/period-deadline.yaml +11 -0
- package/lexicons/period-label.yaml +16 -0
- package/lexicons/period-overview-heading.yaml +8 -0
- package/lexicons/period-term-label.yaml +9 -0
- package/lexicons/person-lead.yaml +11 -0
- package/lexicons/phone-label.yaml +18 -0
- package/lexicons/place-word.yaml +20 -0
- package/lexicons/prerequisite-opener.yaml +10 -0
- package/lexicons/quantity-column.yaml +8 -0
- package/lexicons/quote-advice.yaml +30 -0
- package/lexicons/quote-attribution.yaml +3 -0
- package/lexicons/rate-unit.yaml +19 -0
- package/lexicons/requirement-heading.yaml +19 -0
- package/lexicons/requirement-item-ending.yaml +14 -0
- package/lexicons/requirement-length-unit.yaml +12 -0
- package/lexicons/requirement-length-word.yaml +8 -0
- package/lexicons/return-clause.yaml +11 -0
- package/lexicons/return-item.yaml +8 -0
- package/lexicons/return-label.yaml +8 -0
- package/lexicons/return-subject.yaml +8 -0
- package/lexicons/return-type-word.yaml +14 -0
- package/lexicons/return-verb.yaml +9 -0
- package/lexicons/self-reference-noun.yaml +30 -0
- package/lexicons/sentence-opener.yaml +15 -0
- package/lexicons/session-count-unit.yaml +7 -0
- package/lexicons/session-total.yaml +11 -0
- package/lexicons/share-column-rate.yaml +16 -0
- package/lexicons/share-column.yaml +10 -0
- package/lexicons/share-rest.yaml +7 -0
- package/lexicons/stated-deadline-not.yaml +6 -0
- package/lexicons/stated-deadline.yaml +13 -0
- package/lexicons/stay-check-in-column.yaml +8 -0
- package/lexicons/stay-check-out-column.yaml +7 -0
- package/lexicons/stay-night.yaml +5 -0
- package/lexicons/stay-nights-column.yaml +7 -0
- package/lexicons/stay-pair-joiner.yaml +7 -0
- package/lexicons/summed-counter.yaml +14 -0
- package/lexicons/tax-included-word.yaml +8 -0
- package/lexicons/tax-label.yaml +8 -0
- package/lexicons/timed-duty.yaml +18 -0
- package/lexicons/travel-time-word.yaml +32 -0
- package/lexicons/uncomparable-graded.yaml +36 -0
- package/lexicons/unit-price-column.yaml +7 -0
- package/lexicons/unnamed-speaker.yaml +38 -0
- package/lexicons/very-copula.yaml +13 -0
- package/lexicons/very-exception.yaml +5 -0
- package/lexicons/very-intensifier.yaml +10 -0
- package/lexicons/warning-action.yaml +16 -0
- package/lexicons/warning-label.yaml +11 -0
- package/lexicons/wordy-phrase.yaml +19 -0
- package/lexicons/working-hours-break.yaml +9 -0
- package/lexicons/working-hours-total.yaml +10 -0
- package/package.json +1 -1
- 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
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
|
-
|
|
227
|
-
|
|
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
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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 !== "名詞";
|