@chaffjs/lang-ja 0.14.0 → 0.16.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/citation.d.ts +3 -1
- package/dist/citation.d.ts.map +1 -1
- package/dist/citation.js +8 -3
- package/dist/citation.js.map +1 -1
- package/dist/counter-tsu.d.ts +4 -0
- package/dist/counter-tsu.d.ts.map +1 -1
- package/dist/counter-tsu.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/dist/lexicons.d.ts.map +1 -1
- package/dist/lexicons.js +5 -6
- package/dist/lexicons.js.map +1 -1
- package/dist/passive-reading.d.ts +6 -1
- package/dist/passive-reading.d.ts.map +1 -1
- package/dist/passive-reading.js +62 -9
- package/dist/passive-reading.js.map +1 -1
- package/dist/pos.d.ts +2 -0
- package/dist/pos.d.ts.map +1 -1
- package/dist/pos.js +41 -6
- package/dist/pos.js.map +1 -1
- package/dist/reduplication.d.ts +31 -1
- package/dist/reduplication.d.ts.map +1 -1
- package/dist/reduplication.js +104 -8
- package/dist/reduplication.js.map +1 -1
- package/dist/sentence-split.js +1 -1
- package/dist/sentence-split.js.map +1 -1
- package/dist/spaced-counter.d.ts.map +1 -1
- package/dist/spaced-counter.js +2 -1
- package/dist/spaced-counter.js.map +1 -1
- package/dist/structure.d.ts.map +1 -1
- package/dist/structure.js +26 -13
- package/dist/structure.js.map +1 -1
- package/lexicons/calendar-unit.yaml +8 -0
- package/lexicons/calendar-year-unit.yaml +7 -0
- package/lexicons/date-time-unit.yaml +1 -0
- package/lexicons/document-kind.yaml +1 -0
- package/lexicons/doubled-word.yaml +1 -0
- package/lexicons/emphasis-word.yaml +2 -1
- package/lexicons/excessive-hedging.yaml +9 -5
- package/lexicons/hedge-frame.yaml +14 -0
- package/lexicons/hedge-scope.yaml +7 -0
- package/lexicons/iteration-kanji.yaml +18 -0
- package/lexicons/name-joiner.yaml +5 -0
- package/lexicons/name-title.yaml +20 -0
- package/lexicons/self-prefix.yaml +2 -1
- package/lexicons/stative-passive-verb.yaml +38 -2
- package/package.json +1 -1
- package/src/citation.ts +11 -3
- package/src/counter-tsu.ts +4 -0
- package/src/index.ts +9 -8
- package/src/lexicons.ts +9 -8
- package/src/passive-reading.ts +80 -10
- package/src/pos.ts +60 -6
- package/src/reduplication.ts +163 -10
- package/src/sentence-split.ts +1 -1
- package/src/spaced-counter.ts +2 -1
- package/src/structure.ts +26 -14
package/src/spaced-counter.ts
CHANGED
|
@@ -26,7 +26,8 @@ const asCounter = (token: Token): Token => ({
|
|
|
26
26
|
surface: token.surface,
|
|
27
27
|
pos: "NOUN",
|
|
28
28
|
...(token.lemma === undefined ? {} : { lemma: token.lemma }),
|
|
29
|
-
|
|
29
|
+
// 解析器が読む助数詞(名詞,接尾,助数詞)と同じ印。数に付いて単独では語にならない。
|
|
30
|
+
features: { NounType: "Class", Bound: "Yes" },
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
export const markSpacedCounters = (tokens: readonly Token[], readsAsCounter: CounterReading): Token[] =>
|
package/src/structure.ts
CHANGED
|
@@ -21,7 +21,7 @@ const ARTICLE_RANGE = new RegExp(
|
|
|
21
21
|
const PARAGRAPH = new RegExp(`^${SPACE}*第(?<n>${NUMBER})項(?<rest>(?:${SPACE}|(|\\().*|)$`, "u");
|
|
22
22
|
const ITEM = new RegExp(`^${SPACE}*第(?<n>${NUMBER})号(?<rest>(?:${SPACE}|(|\\().*|)$`, "u");
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* 法令の項と号は、番号だけを行頭に置き、全角空白で本文と区切る(「2」「一」)。条の中でだけ読み、見出しの行(章の番号)では読まない。
|
|
25
25
|
* 半角数字や漢数字に半角空白が続くだけなら本文として扱う。「3 人で」「一 人で」を項や号にしない。
|
|
26
26
|
*/
|
|
27
27
|
const BARE_PARAGRAPH = new RegExp(`^${SPACE}*(?<n>[0-9]{1,3})\\u3000+(?<rest>\\S.*)$`, "u");
|
|
@@ -44,10 +44,20 @@ const numberOf = (text: string | undefined): string | undefined => {
|
|
|
44
44
|
|
|
45
45
|
const insideArticle = (context: NumberingContext): boolean => context.open.some((open) => open.kind === "article");
|
|
46
46
|
|
|
47
|
-
/**
|
|
47
|
+
/** 条の行に本文があれば、番号の無い第 1 項がその行で始まっている。見出しだけの条(「第1条(目的)」「第1条 総則」)は違う。 */
|
|
48
|
+
const opensFirstParagraph = (open: NumberedLine | undefined): boolean => open?.kind === "article" && open.heading === "" && open.rest !== "";
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 「(2)」は開いている「(1)」の兄弟。無ければ、開いているものより一段深い。
|
|
52
|
+
* ただし本文のある条の直下なら、番号の無い第 1 項の号。規則の「第3条 …次のとおりとする。」「(1) 学士」「2 …」の (1) は、第 2 項の兄弟ではない。
|
|
53
|
+
*/
|
|
48
54
|
const PAREN_LABEL = /^(\d+)$/u;
|
|
49
|
-
const parenDepth = (context: NumberingContext): number =>
|
|
50
|
-
|
|
55
|
+
const parenDepth = (context: NumberingContext): number => {
|
|
56
|
+
const sibling = context.open.findLast((open) => PAREN_LABEL.test(open.label));
|
|
57
|
+
if (sibling !== undefined) return sibling.depth;
|
|
58
|
+
const innermost = context.open.at(-1);
|
|
59
|
+
return opensFirstParagraph(innermost) ? ITEM_DEPTH : (innermost?.depth ?? 0) + 1;
|
|
60
|
+
};
|
|
51
61
|
|
|
52
62
|
/**
|
|
53
63
|
* 条の範囲の行は、最初の条の番地を持ち、並びの位置は範囲の最後まで進める。中の条は番地を持たない。
|
|
@@ -125,11 +135,11 @@ const ITEM_SHAPES: readonly ItemShape[] = [
|
|
|
125
135
|
* 「第十二条第二項」(12.2)がぶつからないようにする。
|
|
126
136
|
*/
|
|
127
137
|
const inFirstParagraph = (context: NumberingContext, depth: number): boolean =>
|
|
128
|
-
depth === ITEM_DEPTH &&
|
|
138
|
+
depth === ITEM_DEPTH && context.open.findLast((open) => open.depth < ITEM_DEPTH)?.kind === "article";
|
|
129
139
|
|
|
130
140
|
const item = (line: string, context: NumberingContext): NumberedLine | undefined =>
|
|
131
141
|
ITEM_SHAPES.reduce<NumberedLine | undefined>((found, shape) => {
|
|
132
|
-
if (found !== undefined || (shape.needsArticle && !insideArticle(context))) return found;
|
|
142
|
+
if (found !== undefined || (shape.needsArticle && (context.isHeading || !insideArticle(context)))) return found;
|
|
133
143
|
const groups = shape.pattern.exec(line)?.groups;
|
|
134
144
|
const number = numberOf(groups?.["n"]);
|
|
135
145
|
if (groups === undefined || number === undefined) return undefined;
|
|
@@ -192,7 +202,9 @@ const DEFINITIONS = [/以下「(?<term>[^「」\n]{1,40})」という/gu, /「(?
|
|
|
192
202
|
*/
|
|
193
203
|
const THIS_PART = /この[条項号款目節章編](?:及び[^、。]{1,20})?において$/u;
|
|
194
204
|
const NEARBY_PART = /[前次同](?:各)?[項条号]に規定する$/u;
|
|
195
|
-
|
|
205
|
+
/** 「規則第7条に規定する『X』とは」「法第31条第1項第1号の『X』とは」は、その番地で使う X の意味。番地の末尾だけを見る。 */
|
|
206
|
+
const ADDRESSED_PART = new RegExp(`第${NUMBER}[条項号](?:の${NUMBER})?(?:に規定する|の)$`, "u");
|
|
207
|
+
const scopedLocally = (before: string): boolean => THIS_PART.test(before) || NEARBY_PART.test(before) || ADDRESSED_PART.test(before);
|
|
196
208
|
|
|
197
209
|
const definitions = (text: string): Mention[] =>
|
|
198
210
|
DEFINITIONS.flatMap((pattern) =>
|
|
@@ -258,12 +270,12 @@ const addressOfReference = (
|
|
|
258
270
|
const main = numberOf(groups["a"]);
|
|
259
271
|
if (main === undefined) return undefined;
|
|
260
272
|
const sub = numberOf(groups["s"]);
|
|
261
|
-
const
|
|
262
|
-
const
|
|
273
|
+
const articleNumber = sub === undefined ? main : `${main}-${sub}`;
|
|
274
|
+
const itemNumber = numberOf(groups["i"]);
|
|
263
275
|
// 「第二条第一号」は第 1 項の号。項を書かずに号を指すのは、項が一つしかない条。
|
|
264
|
-
const paragraph = numberOf(groups["p"]) ?? (
|
|
265
|
-
const target = [
|
|
266
|
-
return { target, fallback: paragraph === "1" &&
|
|
276
|
+
const paragraph = numberOf(groups["p"]) ?? (itemNumber === undefined ? undefined : "1");
|
|
277
|
+
const target = [articleNumber, paragraph, itemNumber].filter((part) => part !== undefined).join(".");
|
|
278
|
+
return { target, fallback: paragraph === "1" && itemNumber === undefined ? articleNumber : undefined };
|
|
267
279
|
};
|
|
268
280
|
|
|
269
281
|
/** 他の文書の名前を読む語と、章・節の番地でない言い方。語彙表から一度だけ作る。 */
|
|
@@ -292,7 +304,7 @@ const references = (text: string): Mention[] => {
|
|
|
292
304
|
// 括弧書きの中の参照(「(同法第五十九条において準用する場合を含む。)」)は、外の並びを切らない。並びは括弧の深さごとに持つ。
|
|
293
305
|
const chains = new Map<number, { readonly end: number; readonly document: string | undefined }>();
|
|
294
306
|
return [...articlesOf(text), ...sectionsOf(text)]
|
|
295
|
-
.
|
|
307
|
+
.toSorted((left, right) => left.start - right.start)
|
|
296
308
|
.map((mention) => {
|
|
297
309
|
const depth = depths[mention.start] ?? 0;
|
|
298
310
|
const previous = chains.get(depth);
|
|
@@ -350,7 +362,7 @@ const obligations = (text: string): Mention[] => {
|
|
|
350
362
|
kept.push({ start, end, attrs: { marker, type } });
|
|
351
363
|
});
|
|
352
364
|
});
|
|
353
|
-
return kept.
|
|
365
|
+
return kept.toSorted((left, right) => left.start - right.start);
|
|
354
366
|
};
|
|
355
367
|
|
|
356
368
|
/** 「二十二」「2」を数にする。相対の参照(前二項・前条第二項)を core が読むときに使う。 */
|