@chaffjs/lang-ja 0.36.0 → 0.37.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/english-run.d.ts.map +1 -1
- package/dist/english-run.js +2 -1
- package/dist/english-run.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/initial-stop.d.ts +23 -0
- package/dist/initial-stop.d.ts.map +1 -0
- package/dist/initial-stop.js +33 -0
- package/dist/initial-stop.js.map +1 -0
- package/dist/list-line.d.ts.map +1 -1
- package/dist/list-line.js +55 -7
- package/dist/list-line.js.map +1 -1
- package/dist/pos.d.ts.map +1 -1
- package/dist/pos.js +7 -1
- package/dist/pos.js.map +1 -1
- package/dist/quoted-line-stop.d.ts +4 -0
- package/dist/quoted-line-stop.d.ts.map +1 -0
- package/dist/quoted-line-stop.js +18 -0
- package/dist/quoted-line-stop.js.map +1 -0
- package/lexicons/adversative-ga-causal.yaml +11 -0
- package/lexicons/alternative-clause-label.yaml +7 -0
- package/lexicons/asker-heading.yaml +14 -0
- package/lexicons/bracket-annotation.yaml +8 -0
- package/lexicons/bracket-width.yaml +6 -0
- package/lexicons/case-party-joiner.yaml +7 -0
- package/lexicons/common-acronym.yaml +3 -1
- package/lexicons/comparative-baseline.yaml +8 -1
- package/lexicons/count-hedge.yaml +5 -0
- package/lexicons/defined-term-group-suffix.yaml +6 -0
- package/lexicons/demonstrative-not-opener.yaml +14 -0
- package/lexicons/empty-intensifier.yaml +2 -0
- package/lexicons/final-period.yaml +27 -0
- package/lexicons/fixed-name-ending.yaml +22 -0
- package/lexicons/headnote-heading.yaml +9 -0
- package/lexicons/honorific-group.yaml +9 -0
- package/lexicons/humble-own-act.yaml +15 -0
- package/lexicons/kanji-known-word.yaml +14 -0
- package/lexicons/licence-word.yaml +7 -0
- package/lexicons/link-label-ending.yaml +11 -0
- package/lexicons/list-conjunction.yaml +13 -0
- package/lexicons/list-note-lead.yaml +2 -0
- package/lexicons/list-suffix.yaml +6 -0
- package/lexicons/necessity-purpose.yaml +13 -0
- package/lexicons/neutral-request.yaml +9 -0
- package/lexicons/newsletter-issue.yaml +10 -0
- package/lexicons/ngram-fixed-ending.yaml +9 -0
- package/lexicons/organisation-unit.yaml +2 -0
- package/lexicons/orthographic-variant-conjunction.yaml +4 -0
- package/lexicons/orthographic-variant-distinct.yaml +5 -0
- package/lexicons/orthographic-variant-idiom.yaml +3 -0
- package/lexicons/orthographic-variant-judging.yaml +4 -1
- package/lexicons/orthographic-variant-katakana-sense.yaml +8 -0
- package/lexicons/orthographic-variant-two-readings.yaml +14 -0
- package/lexicons/orthographic-variant-voice.yaml +8 -0
- package/lexicons/orthographic-variant-whole-word.yaml +6 -0
- package/lexicons/placeholder-division.yaml +8 -0
- package/lexicons/placeholder-word.yaml +63 -1
- package/lexicons/prepositive-abbreviation.yaml +9 -0
- package/lexicons/quoted-wording-cue.yaml +14 -0
- package/lexicons/reference-prefix.yaml +12 -0
- package/lexicons/rejected-wording.yaml +18 -0
- package/lexicons/relative-start.yaml +8 -0
- package/lexicons/request-deadline-section.yaml +12 -0
- package/lexicons/request-prohibition.yaml +9 -0
- package/lexicons/requirement-open-end.yaml +8 -0
- package/lexicons/sentence-start-word.yaml +59 -0
- package/lexicons/spelling-mention.yaml +9 -0
- package/lexicons/superlative-owner.yaml +6 -0
- package/lexicons/superlative-phrase.yaml +13 -0
- package/lexicons/telling-cue.yaml +12 -0
- package/lexicons/term-source-marker.yaml +11 -0
- package/lexicons/title-ending.yaml +13 -1
- package/package.json +1 -1
- package/src/english-run.ts +2 -1
- package/src/index.ts +8 -2
- package/src/initial-stop.ts +58 -0
- package/src/list-line.ts +66 -8
- package/src/pos.ts +14 -1
- package/src/quoted-line-stop.ts +20 -0
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
# 題の置き方(括弧の中身を閉じる、すぐ後ろに補いの括弧が付く、文がその連なりだけ、見出しにある)をしていれば、
|
|
3
3
|
# 書き手が選んだ複合語ではなく、変えられない名前(大阪市鶴見区役所公募型比較見積実施要綱、国家公務員中途採用者選考試験)。
|
|
4
4
|
# 閉じる語は語の切れ目で始まり、前に 2 字以上の語が要る(解決方法の「法」、本事業は当たらない)。
|
|
5
|
-
#
|
|
5
|
+
# 文の中で使っただけの連なり(情報処理推進機構認定試験の受験者)は、文書のどこかで題として置かれているか、
|
|
6
|
+
# 文書の中で同じ連なりを繰り返していなければ数える。法令・制度・給付の名前は、置き方を問わない fixed-name-ending にもある。
|
|
7
|
+
# 会合・会同・演習・窓口は催しや受け付けの名前(G7仙台科学技術大臣会合、自衛隊高級幹部会同、区役所就学事務担当窓口)、
|
|
8
|
+
# 戦略・基金・審議会・協議会・機構は計画や機関の名前(保険契約者保護機構)。
|
|
6
9
|
id: title-ending
|
|
7
10
|
language: ja
|
|
8
11
|
entries:
|
|
@@ -32,3 +35,12 @@ entries:
|
|
|
32
35
|
- pattern: 届出書
|
|
33
36
|
- pattern: 報告書
|
|
34
37
|
- pattern: 証明書
|
|
38
|
+
- pattern: 会合
|
|
39
|
+
- pattern: 会同
|
|
40
|
+
- pattern: 演習
|
|
41
|
+
- pattern: 窓口
|
|
42
|
+
- pattern: 戦略
|
|
43
|
+
- pattern: 基金
|
|
44
|
+
- pattern: 審議会
|
|
45
|
+
- pattern: 協議会
|
|
46
|
+
- pattern: 機構
|
package/package.json
CHANGED
package/src/english-run.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* 漢字だけなら含んでよい(英文の中の「東京」)。仮名があれば和文の一部と読む。
|
|
5
5
|
*/
|
|
6
6
|
const KANA = /[\p{Script=Hiragana}\p{Script=Katakana}]/u;
|
|
7
|
-
|
|
7
|
+
/** 全角の英字(TEL)は和文の組み方で、英文は使わない。英字に数えない。 */
|
|
8
|
+
const LATIN = /(?![A-Za-z])\p{Script=Latin}/gu;
|
|
8
9
|
const LETTER = /\p{L}/gu;
|
|
9
10
|
// 英文の文末。閉じ括弧・引用符が続いてよい。断片の末尾だけを見る。
|
|
10
11
|
const ENGLISH_STOP_AT_END = /[.?!][)\]"'”’]{0,3}$/u;
|
package/src/index.ts
CHANGED
|
@@ -5,8 +5,10 @@ import { isEnglishBoundary, isEnglishRun } from "./english-run.ts";
|
|
|
5
5
|
import { unmarkNumberStops } from "./number-stop.ts";
|
|
6
6
|
import { pairMixedWidthBrackets } from "./mixed-width-bracket.ts";
|
|
7
7
|
import { labelStops, unmarkLabelStops } from "./label-stop.ts";
|
|
8
|
+
import { initialStops, unmarkInitialStops } from "./initial-stop.ts";
|
|
8
9
|
import { splitAtQuotedStops } from "./quoted-stop.ts";
|
|
9
10
|
import { reattachClosingQuotes } from "./closing-quote.ts";
|
|
11
|
+
import { splitAtQuotedLineEnds } from "./quoted-line-stop.ts";
|
|
10
12
|
import { insideBrackets, startsWithCloser } from "./inside-brackets.ts";
|
|
11
13
|
import { structure } from "./structure.ts";
|
|
12
14
|
import { cutAtBreaks, lineVocabulary, listItemHeads, listLineBreaks, startsListItem } from "./list-line.ts";
|
|
@@ -105,15 +107,19 @@ const patternsOf = (id: string): string[] => (LEXICONS[id] ?? []).map((entry) =>
|
|
|
105
107
|
const LINE_VOCABULARY = lineVocabulary(patternsOf("numbering-counter"), patternsOf("line-head-tag"));
|
|
106
108
|
|
|
107
109
|
const LABEL_STOPS = labelStops((LEXICONS["abbreviated-label"] ?? []).map((entry) => entry.pattern));
|
|
110
|
+
const INITIAL_STOPS = initialStops(
|
|
111
|
+
(LEXICONS["sentence-start-word"] ?? []).map((entry) => entry.pattern),
|
|
112
|
+
(LEXICONS["prepositive-abbreviation"] ?? []).map((entry) => entry.pattern),
|
|
113
|
+
);
|
|
108
114
|
|
|
109
115
|
/**
|
|
110
116
|
* 英語のアダプタと同じ手当てを英文にも当てる。番号の前の略した名前(FIG. 1)の点で切らず、
|
|
111
117
|
* 英文の閉じ引用符の内側の句点で切り、文頭に取り残された閉じ引用符を前の文へ戻す。
|
|
112
118
|
*/
|
|
113
119
|
const spansOf = (text: string): Span[] => {
|
|
114
|
-
const spans = sentenceSpans(pairMixedWidthBrackets(unmarkNumberStops(unmarkLabelStops(text, LABEL_STOPS))));
|
|
120
|
+
const spans = sentenceSpans(pairMixedWidthBrackets(unmarkInitialStops(unmarkNumberStops(unmarkLabelStops(text, LABEL_STOPS)), INITIAL_STOPS)));
|
|
115
121
|
const quotedStops = spans.flatMap((span) => (isEnglishRun(text.slice(span.start, span.end)) ? splitAtQuotedStops(text, span) : [span]));
|
|
116
|
-
return reattachClosingQuotes(text, quotedStops);
|
|
122
|
+
return reattachClosingQuotes(text, quotedStops).flatMap((span) => splitAtQuotedLineEnds(text, span));
|
|
117
123
|
};
|
|
118
124
|
|
|
119
125
|
export const adapter: LanguageAdapter = {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// lang-en/src/initial-stop.ts の写し。アダプタは互いに依存しないので、和文の中の英文に同じ手当てをするために置く。元とのずれは test_mixed_language_stops.ts で比べる。
|
|
2
|
+
import { escapeRegExp } from "./regexp.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* sentence-splitter reads a capital and a full stop as an initial and never ends a sentence there: "Regulation C. The
|
|
6
|
+
* Guide applies" and "Appendix B. In 2020 …" were one sentence. It also ends a sentence after an abbreviation such as
|
|
7
|
+
* "U.S." before any capital, so "the U.S. Census Bureau" was two. Both are decided by the word after the full stop:
|
|
8
|
+
* - capitals with full stops (C., D.C.) before a sentence-start-word (The, In) end the sentence. Their capitals are
|
|
9
|
+
* replaced with a plain letter, which the splitter does not read as an initial;
|
|
10
|
+
* - a prepositive abbreviation (U.S.) before any other capitalised word does not end it, unless a comma follows that
|
|
11
|
+
* word ("in the U.S. Yesterday, …"). Its last full stop is replaced with a letter;
|
|
12
|
+
* - capitals with full stops (J., U.K.) before a word in lower case ("J. meacham", "Hart, K. and J. Reed") do not end
|
|
13
|
+
* it, since no sentence opens in lower case. A word that is lower case only at its head (iPhone) may be a name that
|
|
14
|
+
* opens one, so it is left out. Their last full stop is replaced with a letter.
|
|
15
|
+
* The length does not change, so the spans fit the original text. Initials first on their line are a list's labels
|
|
16
|
+
* (A. The first item) and are left as they are.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export type InitialStops = { readonly ends: RegExp | undefined; readonly joins: RegExp | undefined };
|
|
20
|
+
|
|
21
|
+
const EDGE_BEFORE = String.raw`(?<![\p{L}\p{N}_.'’])`;
|
|
22
|
+
const WORD_END = String.raw`(?![\p{L}\p{N}_.'’-])`;
|
|
23
|
+
const PLAIN_LETTER = "n";
|
|
24
|
+
const CAPITAL = /\p{Lu}/gu;
|
|
25
|
+
const BEFORE_LOWER_CASE = new RegExp(String.raw`${EDGE_BEFORE}(?:\p{Lu}\.){1,3}(?=[ \t\r\n]+\p{Ll}(?!\p{Lu}))`, "gu");
|
|
26
|
+
|
|
27
|
+
const oneOf = (words: readonly string[]): string => `(?:${words.map(escapeRegExp).join("|")})`;
|
|
28
|
+
|
|
29
|
+
/** Built once from the lexicons. */
|
|
30
|
+
export const initialStops = (startWords: readonly string[], prepositive: readonly string[]): InitialStops => {
|
|
31
|
+
if (startWords.length === 0) return { ends: undefined, joins: undefined };
|
|
32
|
+
const start = String.raw`\s+${oneOf(startWords)}${WORD_END}`;
|
|
33
|
+
const ends = new RegExp(String.raw`${EDGE_BEFORE}(?:\p{Lu}\.){1,3}(?=${start})`, "gu");
|
|
34
|
+
if (prepositive.length === 0) return { ends, joins: undefined };
|
|
35
|
+
return { ends, joins: new RegExp(String.raw`${EDGE_BEFORE}${oneOf(prepositive)}(?=\s+\p{Lu})(?!${start})(?!\s+\p{Lu}\p{L}*,)`, "gu") };
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** Only a list's marker, or nothing, before the initials on their line (A. The first item; - B. The second item). */
|
|
39
|
+
const LABEL_HEAD = /^[ \t]*(?:[-*+•][ \t]+)?$/u;
|
|
40
|
+
|
|
41
|
+
const lineStartOf = (text: string, index: number): number => Math.max(text.lastIndexOf("\n", index - 1), text.lastIndexOf("\r", index - 1)) + 1;
|
|
42
|
+
|
|
43
|
+
const isFirstOnLine = (text: string, index: number): boolean => LABEL_HEAD.test(text.slice(lineStartOf(text, index), index));
|
|
44
|
+
|
|
45
|
+
const withoutLastStop = (abbreviation: string): string => `${abbreviation.slice(0, -1)}${PLAIN_LETTER}`;
|
|
46
|
+
|
|
47
|
+
/** Initials before a word in lower case, not first on their line (a list's label stays as it is), rewritten. */
|
|
48
|
+
const joinedBeforeLowerCase = (text: string): string =>
|
|
49
|
+
text.replace(BEFORE_LOWER_CASE, (initials: string, index: number) => (isFirstOnLine(text, index) ? initials : withoutLastStop(initials)));
|
|
50
|
+
|
|
51
|
+
/** The text with every initial that ends a sentence, and every prepositive abbreviation or initial that does not, rewritten. */
|
|
52
|
+
export const unmarkInitialStops = (text: string, stops: InitialStops): string => {
|
|
53
|
+
const ended =
|
|
54
|
+
stops.ends === undefined
|
|
55
|
+
? text
|
|
56
|
+
: text.replace(stops.ends, (initials: string, index: number) => (isFirstOnLine(text, index) ? initials : initials.replace(CAPITAL, PLAIN_LETTER)));
|
|
57
|
+
return joinedBeforeLowerCase(stops.joins === undefined ? ended : ended.replace(stops.joins, withoutLastStop));
|
|
58
|
+
};
|
package/src/list-line.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { escapeRegExp } from "./regexp.ts";
|
|
|
9
9
|
* 印の無い行の折り返しは切らない。
|
|
10
10
|
*
|
|
11
11
|
* 番号だけの札の行(「第1」「第3条」)と、行頭の括弧で囲んだ札(「(別添)…」)も、印で始まる行と同じに切る。札の語は辞書から取る。
|
|
12
|
+
* URL だけの行、欄の行(電話:…、〒…)、括弧の語だけの行も、文の途中に立っていなければ前後で切る(メールマガジンや連絡先の欄)。
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
15
|
const SPACE = "[ \\t\\u3000]";
|
|
@@ -87,18 +88,75 @@ export const lineVocabulary = (counters: readonly string[], tags: readonly strin
|
|
|
87
88
|
const isListLine = (line: string, vocabulary: LineVocabulary): boolean =>
|
|
88
89
|
startsWithListMarker(line) || vocabulary.label.test(line) || (vocabulary.tag?.test(line) ?? false);
|
|
89
90
|
|
|
90
|
-
/**
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
/** URL だけの行(▼こちら の次の行のアドレス)。 */
|
|
92
|
+
const URL_LINE = new RegExp(`^${SPACE}*https?://\\S+${SPACE}*$`, "u");
|
|
93
|
+
/**
|
|
94
|
+
* 欄の行: 短い札と全角か半角のコロンで始まる行(電話:03-…、E-mail:…)と、郵便番号の印〒で始まる行。連絡先の欄は 1 行 1 項目。
|
|
95
|
+
* 札が数字で終われば時刻(10:00、午前10:00)か比(1:2)で、札ではない。
|
|
96
|
+
*/
|
|
97
|
+
const FIELD_LINE = new RegExp(`^${SPACE}*(?:〒|[^\\s、。,::「」『』()()【】]{0,11}[^\\s、。,::「」『』()()【】0-90-9][::])`, "u");
|
|
98
|
+
/** 括弧でくくった語だけの行((お問い合わせ先)、【新着】(文部科学省)、「報告書は実践の宝庫」)。札か題で、文の途中ではない。 */
|
|
99
|
+
const BRACKET_GROUP = "[((【〔[「『][^((【〔[「『))】〕]」』\\n]*[))】〕]」』]";
|
|
100
|
+
const BRACKET_LINE = new RegExp(`^(?:${SPACE}*${BRACKET_GROUP})+${SPACE}*$`, "u");
|
|
101
|
+
/** 空白の後の括弧の注記で終わる行(題 (○○小学校))。題の行の終わりで、文は折り返しても括弧の前に空白を置かない。 */
|
|
102
|
+
const NOTE_IN_BRACKETS_END = new RegExp(`\\S${SPACE}+[((][^(())\\n]*[))]${SPACE}*$`, "u");
|
|
103
|
+
|
|
104
|
+
/** 行が助詞で始まる: 前の行の語を受けて文が続いている(「…」\nと述べた)。 */
|
|
105
|
+
const PARTICLE_START = new RegExp(`^${SPACE}*(?:の|に|を|が|は|と|で|へ|も|から|まで|より|及び|又は|並びに|若しくは)`, "u");
|
|
106
|
+
/** 行が助詞で終わる: 文が次の行へ続いている(担当者は\n「…」)。 */
|
|
107
|
+
const PARTICLE_END = new RegExp(`(?:の|に|を|が|は|と|で|へ|も|から|まで|より)${SPACE}*$`, "u");
|
|
108
|
+
|
|
109
|
+
/** 1 行で一つの単位になりうる行: URL、欄、括弧の語だけ。 */
|
|
110
|
+
const standsAlone = (line: string): boolean => URL_LINE.test(line) || FIELD_LINE.test(line) || BRACKET_LINE.test(line);
|
|
111
|
+
|
|
112
|
+
/** 空白だけの行。段落の中では、伏せた URL やコードが 1 行を占めていた所。 */
|
|
113
|
+
const isMaskedLine = (line: string): boolean => line.trim() === "";
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 行が文の途中に立っていない: 前の行が読点・開いた括弧・助詞で終わらず、次の行が助詞で始まらない。
|
|
117
|
+
* 折り返した文の途中に括弧の語だけの行が来ることがある(〜始まり、\n(休憩を挟んで)\n夕方まで続く。)。
|
|
118
|
+
*/
|
|
119
|
+
const standsBetween = (before: Line | undefined, after: Line | undefined): boolean =>
|
|
120
|
+
(before === undefined || (!continuesToNextLine(before.text) && !PARTICLE_END.test(before.text))) && (after === undefined || !PARTICLE_START.test(after.text));
|
|
121
|
+
|
|
122
|
+
/** 1 行で一つの単位の行。その前でも後ろでも文が改まる。 */
|
|
123
|
+
const isUnitLine = (lines: readonly Line[], index: number): boolean =>
|
|
124
|
+
standsAlone(lines[index]?.text ?? "") && standsBetween(lines[index - 1], lines[index + 1]);
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* index の行の後ろで文が改まる: 1 行で一つの単位の行、題の注記で終わる行、伏せた行の後ろ。
|
|
128
|
+
* 次の行が注記(※)なら、その行に添える注記なので続ける。
|
|
129
|
+
*/
|
|
130
|
+
const endsUnitAt = (lines: readonly Line[], index: number): boolean => {
|
|
131
|
+
const line = lines[index]?.text ?? "";
|
|
132
|
+
const ends = isUnitLine(lines, index) || ((NOTE_IN_BRACKETS_END.test(line) || isMaskedLine(line)) && standsBetween(lines[index - 1], lines[index + 1]));
|
|
133
|
+
return ends && !NOTE.test(lines[index + 1]?.text ?? "");
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* index - 1 の行と index の行の間で文が改まるか: どちらかが項目の行か、1 行で一つの単位の行か、注記の行が続く。
|
|
138
|
+
* 前の行が次へ続いている(読点、開いた括弧)なら改まらない。
|
|
139
|
+
*/
|
|
140
|
+
const isCut = (lines: readonly Line[], index: number, vocabulary: LineVocabulary): boolean => {
|
|
141
|
+
const previous = lines[index - 1]?.text ?? "";
|
|
142
|
+
const next = lines[index]?.text ?? "";
|
|
143
|
+
return (
|
|
144
|
+
next.trim().length > 0 &&
|
|
145
|
+
!continuesToNextLine(previous) &&
|
|
146
|
+
(isListLine(next, vocabulary) ||
|
|
147
|
+
isListLine(previous, vocabulary) ||
|
|
148
|
+
isUnitLine(lines, index) ||
|
|
149
|
+
endsUnitAt(lines, index - 1) ||
|
|
150
|
+
(NOTE.test(previous) && NOTE.test(next)))
|
|
151
|
+
);
|
|
152
|
+
};
|
|
95
153
|
|
|
96
154
|
/** 文を改める改行の位置: 前の行の終わり(end)と、次の行の最初の文字(start)。 */
|
|
97
155
|
export const listLineBreaks = (text: string, vocabulary: LineVocabulary): Span[] => {
|
|
98
156
|
const lines = linesOf(text);
|
|
99
|
-
return lines.slice(1).flatMap((next,
|
|
100
|
-
const previous = lines[
|
|
101
|
-
if (previous === undefined || !isCut(
|
|
157
|
+
return lines.slice(1).flatMap((next, offset) => {
|
|
158
|
+
const previous = lines[offset];
|
|
159
|
+
if (previous === undefined || !isCut(lines, offset + 1, vocabulary)) return [];
|
|
102
160
|
return [{ start: previous.end, end: next.start + (next.text.length - next.text.trimStart().length) }];
|
|
103
161
|
});
|
|
104
162
|
};
|
package/src/pos.ts
CHANGED
|
@@ -161,7 +161,10 @@ const toToken = (morpheme: Morpheme, start: number, { passive, echo, light, raDr
|
|
|
161
161
|
pos: isPassiveForm(morpheme) ? "AUX" : upos(morpheme.pos, morpheme.pos_detail_1),
|
|
162
162
|
...(morpheme.basic_form === "*" ? {} : { lemma: morpheme.basic_form }),
|
|
163
163
|
...(typeof morpheme.reading !== "string" || morpheme.reading === "*" ? {} : { reading: morpheme.reading }),
|
|
164
|
-
...
|
|
164
|
+
...withAdverbial(
|
|
165
|
+
withRaDropped(withEcho(withWordStatus(featuresOf(morpheme, passive), isBound(morpheme), light), echo), raDropped),
|
|
166
|
+
isAdverbialNoun(morpheme),
|
|
167
|
+
),
|
|
165
168
|
});
|
|
166
169
|
|
|
167
170
|
/**
|
|
@@ -195,6 +198,16 @@ const withEcho = (found: { features?: Readonly<Record<string, string>> }, echo:
|
|
|
195
198
|
const withRaDropped = (found: { features?: Readonly<Record<string, string>> }, raDropped: boolean): { features?: Readonly<Record<string, string>> } =>
|
|
196
199
|
raDropped ? { features: { ...found.features, PotentialRa: "Dropped" } } : found;
|
|
197
200
|
|
|
201
|
+
/**
|
|
202
|
+
* 副詞としても使える名詞(IPADIC の「副詞可能」: 今夜・当日・午前、その日の「日」、午前中の「中」)。今夜は来る、のように助詞なしで
|
|
203
|
+
* 時や量を言える。日本語に固有の印で、UD の FEATS の言語別拡張。非自立名詞や接尾の印はそのまま残す。
|
|
204
|
+
*/
|
|
205
|
+
const isAdverbialNoun = (morpheme: Morpheme): boolean =>
|
|
206
|
+
morpheme.pos === "名詞" && (morpheme.pos_detail_1 === "副詞可能" || morpheme.pos_detail_2 === "副詞可能");
|
|
207
|
+
|
|
208
|
+
const withAdverbial = (found: { features?: Readonly<Record<string, string>> }, adverbial: boolean): { features?: Readonly<Record<string, string>> } =>
|
|
209
|
+
adverbial ? { features: { ...found.features, Adverbial: "Yes" } } : found;
|
|
210
|
+
|
|
198
211
|
/**
|
|
199
212
|
* 数(名詞,数)。UPOS では名詞に寄せるので、数であることは UD の NumType=Card で渡す。
|
|
200
213
|
* 決まった言い回し(二人三脚、三日坊主、一人ひとり、十分)は辞書が一語として持つので、数にはならない。
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Span } from "chaffjs/plugin";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 句点で閉じた引用が行の終わりにあるとき(「…こたえる。」の後で改行)、分割器は括弧の組の後ろで文を切らず、次の行の文まで
|
|
5
|
+
* 一つの文にする。演説や宣誓の引用を一行ずつ置いた文書では、次の行は別の文である。
|
|
6
|
+
* 文末の記号 + 閉じ括弧 + 改行で切る。次の行が「と」や読点で始まるもの(「…。」\nと述べた)は引用が文の途中にあるので切らない。
|
|
7
|
+
*/
|
|
8
|
+
const QUOTE_AT_LINE_END = /[。.!?!?][」』))】〉》]\]]+[ \t\u3000]*(?=\r?\n)/gu;
|
|
9
|
+
const CONTINUES = /^\s*[と、,。」』))]/u;
|
|
10
|
+
|
|
11
|
+
/** span の文を、行の終わりで閉じた引用ごとに分けた span。切れ目が無ければ span そのもの一つ。 */
|
|
12
|
+
export const splitAtQuotedLineEnds = (text: string, span: Span): Span[] => {
|
|
13
|
+
const sentence = text.slice(span.start, span.end);
|
|
14
|
+
const cuts = [...sentence.matchAll(QUOTE_AT_LINE_END)]
|
|
15
|
+
.map((match) => match.index + match[0].length)
|
|
16
|
+
.filter((end) => !CONTINUES.test(sentence.slice(end)) && sentence.slice(end).trim() !== "");
|
|
17
|
+
const starts = [0, ...cuts.map((end) => end + (/^\s+/u.exec(sentence.slice(end))?.[0].length ?? 0))];
|
|
18
|
+
const ends = [...cuts, sentence.length];
|
|
19
|
+
return starts.map((start, index) => ({ start: span.start + start, end: span.start + (ends[index] ?? start) }));
|
|
20
|
+
};
|