@chaffjs/lang-ja 0.34.0 → 0.35.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 (62) hide show
  1. package/dist/english-list-line.d.ts +6 -0
  2. package/dist/english-list-line.d.ts.map +1 -0
  3. package/dist/english-list-line.js +91 -0
  4. package/dist/english-list-line.js.map +1 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +10 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/list-line.d.ts +12 -0
  9. package/dist/list-line.d.ts.map +1 -0
  10. package/dist/list-line.js +82 -0
  11. package/dist/list-line.js.map +1 -0
  12. package/lexicons/addressee-suffix.yaml +8 -0
  13. package/lexicons/any-year-marker.yaml +6 -0
  14. package/lexicons/breakdown-partial-word.yaml +7 -0
  15. package/lexicons/common-acronym.yaml +9 -0
  16. package/lexicons/company-form-latin.yaml +20 -0
  17. package/lexicons/comparative-baseline.yaml +21 -1
  18. package/lexicons/compound-slip-ignored.yaml +13 -0
  19. package/lexicons/count-title.yaml +13 -0
  20. package/lexicons/date-stamp-label.yaml +1 -0
  21. package/lexicons/definition-alternative.yaml +6 -0
  22. package/lexicons/duration-per-period.yaml +17 -0
  23. package/lexicons/figure-scale-joiner.yaml +8 -0
  24. package/lexicons/figure-scale-word.yaml +11 -0
  25. package/lexicons/headline-ending.yaml +9 -0
  26. package/lexicons/known-misspelling.yaml +23 -0
  27. package/lexicons/latin-bound-suffix.yaml +10 -0
  28. package/lexicons/latin-joiner.yaml +10 -0
  29. package/lexicons/list-note-lead.yaml +8 -0
  30. package/lexicons/literal-quote-cue.yaml +22 -0
  31. package/lexicons/memo-header-label.yaml +8 -0
  32. package/lexicons/mention-cue.yaml +11 -0
  33. package/lexicons/misconversion.yaml +13 -0
  34. package/lexicons/nado-closed-list.yaml +4 -0
  35. package/lexicons/nakaguro-word.yaml +13 -0
  36. package/lexicons/named-deadline.yaml +34 -0
  37. package/lexicons/negation-word.yaml +1 -1
  38. package/lexicons/notice-phrase.yaml +15 -0
  39. package/lexicons/organisation-form.yaml +13 -11
  40. package/lexicons/orthographic-variant-conjunction.yaml +13 -0
  41. package/lexicons/orthographic-variant-distinct.yaml +3 -0
  42. package/lexicons/orthographic-variant-idiom.yaml +14 -0
  43. package/lexicons/orthographic-variant-whole-word.yaml +17 -0
  44. package/lexicons/particle-run-break.yaml +23 -0
  45. package/lexicons/person-other-sense.yaml +6 -0
  46. package/lexicons/request-condition.yaml +4 -1
  47. package/lexicons/request-owner.yaml +3 -0
  48. package/lexicons/requirement-open-condition.yaml +9 -0
  49. package/lexicons/requirement-open-end.yaml +21 -0
  50. package/lexicons/requirement-open-question.yaml +18 -0
  51. package/lexicons/rounded-amount-unit.yaml +13 -0
  52. package/lexicons/self-prefix.yaml +1 -0
  53. package/lexicons/stated-deadline.yaml +4 -0
  54. package/lexicons/teki-fixed-term.yaml +12 -0
  55. package/lexicons/title-ending.yaml +6 -1
  56. package/lexicons/translationese.yaml +5 -0
  57. package/lexicons/unnumbered-heading.yaml +6 -0
  58. package/lexicons/vague-deadline.yaml +1 -0
  59. package/package.json +1 -1
  60. package/src/english-list-line.ts +106 -0
  61. package/src/index.ts +11 -1
  62. package/src/list-line.ts +99 -0
@@ -0,0 +1,99 @@
1
+ import type { Span } from "chaffjs/plugin";
2
+
3
+ /**
4
+ * 空行を挟まず 1 行に 1 項目を並べた箇条書き(「①誓約書」「・〜に関する業務」「(1)学歴:…」、`<br>` で改めた行)。
5
+ * 項目は句点で終わらないので、分割器は項目の並び全体を 1 文に読む。行頭の印が、そこで文が改まる印。
6
+ *
7
+ * 切るのは、印で始まる行の前と後ろの改行。ただし前の行が読点で終わるか、括弧を開いたまま終わるなら、文は次の行へ続いている。
8
+ * 印の無い行の折り返しは切らない。
9
+ */
10
+
11
+ const SPACE = "[ \\t\\u3000]";
12
+ /** 記号の印。後ろに何が続いても項目の頭。「○」「◎」は議事録の発言者の印でもあるので含めない。 */
13
+ const BULLET = "[・•●■□◆◇▪▫★☆▶►➢✓]";
14
+ /** 番号の印。囲み数字(①〜㊿・⑴〜⒇)、括弧の番号・英字・仮名((1)(イ))、数字と点・閉じ括弧(1. 1.2))。 */
15
+ const NUMBERED = [
16
+ "[\\u2460-\\u2473\\u3251-\\u325F\\u32B1-\\u32BF\\u2474-\\u2487]",
17
+ "[((][0-90-9]{1,3}[))]",
18
+ "[((](?:[a-zA-Za-zA-Z]|[ivx]{2,4}|[IVX]{2,4})[))]",
19
+ "[((][\\p{Script=Katakana}\\p{Script=Hiragana}][))]",
20
+ "[0-90-9]{1,3}[..))](?![0-90-9])",
21
+ ].join("|");
22
+ /**
23
+ * 英字や片仮名 1 字の印は、空白で本文と区切るときだけ(「a. 教育機関」、片仮名 1 字と全角空白)。「イベント」は語。
24
+ * 法令の号の漢数字は、全角空白で本文と区切るときだけ。半角空白なら「一 人で」のような本文。
25
+ */
26
+ const SPACED = "(?:(?:[a-z][.)]|[ア-ンア-ン])(?=[ \\t\\u3000])|[一二三四五六七八九十]{1,3}(?=\\u3000))";
27
+ /** 番号の後ろが助詞なら、番号は文の中の語(「①に掲げる」「(1)の規定」)。 */
28
+ const PARTICLE_AFTER = "(?![ \\t\\u3000]*(?:の|に|を|が|は|と|で|へ|も|から|まで|より|及び|又は|並びに|若しくは))";
29
+
30
+ const MARKER = new RegExp(`^${SPACE}*(?:${BULLET}|(?:${NUMBERED}|${SPACED})${PARTICLE_AFTER})`, "u");
31
+
32
+ /** 行が箇条書きの印で始まるか。 */
33
+ export const startsWithListMarker = (line: string): boolean => MARKER.test(line);
34
+
35
+ /** 行の終わりで、文が次の行へ続いている: 読点で終わるか、開いた括弧を閉じずに終わる。 */
36
+ const COMMA_END = /[、,,][ \t\u3000]*$/u;
37
+ const OPENERS = /[((「『【[[{{〔〈《]/gu;
38
+ const CLOSERS = /[))」』】]\]}}〕〉》]/gu;
39
+ const leavesBracketOpen = (line: string): boolean => (line.match(OPENERS)?.length ?? 0) > (line.match(CLOSERS)?.length ?? 0);
40
+ const continuesToNextLine = (line: string): boolean => COMMA_END.test(line) || leavesBracketOpen(line);
41
+
42
+ type Line = { readonly start: number; readonly end: number; readonly text: string };
43
+
44
+ const NEWLINE = /\r?\n/gu;
45
+
46
+ const linesOf = (text: string): Line[] => {
47
+ const breaks = [...text.matchAll(NEWLINE)];
48
+ const starts = [0, ...breaks.map((match) => match.index + match[0].length)];
49
+ return starts.map((start, index) => {
50
+ const end = breaks[index]?.index ?? text.length;
51
+ return { start, end, text: text.slice(start, end) };
52
+ });
53
+ };
54
+
55
+ /** 改行の前の行と後ろの行のどちらかが項目で、前の行が次へ続いていなければ、そこで文が改まる。 */
56
+ const isCut = (previous: Line, next: Line): boolean =>
57
+ next.text.trim().length > 0 && !continuesToNextLine(previous.text) && (startsWithListMarker(next.text) || startsWithListMarker(previous.text));
58
+
59
+ /** 文を改める改行の位置: 前の行の終わり(end)と、次の行の最初の文字(start)。 */
60
+ export const listLineBreaks = (text: string): Span[] => {
61
+ const lines = linesOf(text);
62
+ return lines.slice(1).flatMap((next, index) => {
63
+ const previous = lines[index];
64
+ if (previous === undefined || !isCut(previous, next)) return [];
65
+ return [{ start: previous.end, end: next.start + (next.text.length - next.text.trimStart().length) }];
66
+ });
67
+ };
68
+
69
+ /**
70
+ * 注記の印(「※」)。前の行に添える注記で、前の行の文を終えるとは限らない(「ファックス番号:…\n※送ったらご連絡ください。」)。
71
+ * 文を改めはしないが、そこで文が始まっていれば項目と同じく段落を改める。
72
+ */
73
+ const NOTE = /^[ \t\u3000]*※/u;
74
+
75
+ /** 箇条書きの項目か注記の行の頭: 行の始まりから印の最初の文字まで。項目を始める文は、ここで始まる。 */
76
+ export const listItemHeads = (text: string): Span[] =>
77
+ linesOf(text).flatMap((line) =>
78
+ startsWithListMarker(line.text) || NOTE.test(line.text)
79
+ ? [{ start: line.start, end: line.start + line.text.length - line.text.trimStart().length + 1 }]
80
+ : [],
81
+ );
82
+
83
+ /** offset が、項目の頭(heads、並び順で重ならない)のどれかの中にあるか。 */
84
+ export const startsListItem = (lines: readonly Span[], offset: number): boolean => {
85
+ const search = (low: number, high: number): Span | undefined => {
86
+ if (low >= high) return lines[low - 1];
87
+ const middle = (low + high) >> 1;
88
+ return (lines[middle]?.start ?? Number.POSITIVE_INFINITY) > offset ? search(low, middle) : search(middle + 1, high);
89
+ };
90
+ const line = search(0, lines.length);
91
+ return line !== undefined && offset < line.end;
92
+ };
93
+
94
+ /** span を、中にある改行(breaks)で割る。割った前の片は改行の手前で終わり、後ろの片は次の行の最初の文字から始まる。 */
95
+ export const cutAtBreaks = (span: Span, breaks: readonly Span[]): Span[] => {
96
+ const inside = breaks.filter((part) => part.start > span.start && part.end < span.end);
97
+ const starts = [span.start, ...inside.map((part) => part.end)];
98
+ return starts.map((start, index) => ({ start, end: inside[index]?.start ?? span.end }));
99
+ };