@yanqirenshi/hefti 0.0.0-stage → 2.1.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 (111) hide show
  1. package/README.md +299 -2
  2. package/examples/invalid/index/decoration_type.json +112 -0
  3. package/examples/invalid/index/file_chars_negative.json +112 -0
  4. package/examples/invalid/index/file_name.json +112 -0
  5. package/examples/invalid/index/file_no_file.json +111 -0
  6. package/examples/invalid/index/no_files.json +74 -0
  7. package/examples/invalid/index/no_pages.json +86 -0
  8. package/examples/invalid/index/no_sha256.json +111 -0
  9. package/examples/invalid/index/no_source.json +108 -0
  10. package/examples/invalid/index/no_toc.json +73 -0
  11. package/examples/invalid/index/no_version.json +111 -0
  12. package/examples/invalid/index/page_no_id.json +111 -0
  13. package/examples/invalid/index/page_status.json +112 -0
  14. package/examples/invalid/index/sha256_bad.json +112 -0
  15. package/examples/invalid/index/split_chars_0.json +112 -0
  16. package/examples/invalid/index/toc_children_string.json +89 -0
  17. package/examples/invalid/index/toc_id.json +112 -0
  18. package/examples/invalid/index/toc_level_0.json +112 -0
  19. package/examples/invalid/index/toc_no_file.json +111 -0
  20. package/examples/invalid/index/version_1.json +112 -0
  21. package/examples/invalid/part/caption--id.json +72 -0
  22. package/examples/invalid/part/caption--no_source.json +69 -0
  23. package/examples/invalid/part/caption--no_text.json +71 -0
  24. package/examples/invalid/part/figure--id.json +72 -0
  25. package/examples/invalid/part/figure--no_source.json +69 -0
  26. package/examples/invalid/part/figure--text_string.json +70 -0
  27. package/examples/invalid/part/file_ancestor_level_0.json +86 -0
  28. package/examples/invalid/part/file_body_string.json +18 -0
  29. package/examples/invalid/part/file_id.json +86 -0
  30. package/examples/invalid/part/file_no_ancestors.json +74 -0
  31. package/examples/invalid/part/file_no_body.json +17 -0
  32. package/examples/invalid/part/file_no_version.json +85 -0
  33. package/examples/invalid/part/file_version_1.json +86 -0
  34. package/examples/invalid/part/list--id.json +92 -0
  35. package/examples/invalid/part/list--item_id.json +92 -0
  36. package/examples/invalid/part/list--item_no_sentences.json +86 -0
  37. package/examples/invalid/part/list--no_items.json +62 -0
  38. package/examples/invalid/part/list--no_source.json +88 -0
  39. package/examples/invalid/part/paragraph--id.json +25 -0
  40. package/examples/invalid/part/paragraph--no_sentences.json +15 -0
  41. package/examples/invalid/part/paragraph--no_source.json +22 -0
  42. package/examples/invalid/part/paragraph--sentence_id.json +25 -0
  43. package/examples/invalid/part/paragraph--sentence_no_text.json +24 -0
  44. package/examples/invalid/part/paragraph--sentence_text_number.json +25 -0
  45. package/examples/invalid/part/paragraph--sentences_string.json +16 -0
  46. package/examples/invalid/part/paragraph--source_block_not_number.json +25 -0
  47. package/examples/invalid/part/paragraph--source_string.json +23 -0
  48. package/examples/invalid/part/paragraph--type.json +25 -0
  49. package/examples/invalid/part/section--id.json +92 -0
  50. package/examples/invalid/part/section--level_0.json +92 -0
  51. package/examples/invalid/part/section--level_string.json +92 -0
  52. package/examples/invalid/part/section--no_children.json +17 -0
  53. package/examples/invalid/part/section--no_id.json +91 -0
  54. package/examples/invalid/part/section--no_source.json +89 -0
  55. package/examples/invalid/part/section--no_title.json +91 -0
  56. package/examples/invalid/part/section--source_no_hash.json +92 -0
  57. package/examples/invalid/part/section--type.json +92 -0
  58. package/examples/invalid/part/section_ref--file_name.json +92 -0
  59. package/examples/invalid/part/section_ref--level_0.json +92 -0
  60. package/examples/invalid/part/section_ref--no_file.json +91 -0
  61. package/examples/invalid/part/section_ref--no_id.json +91 -0
  62. package/examples/invalid/part/section_ref--no_title.json +91 -0
  63. package/examples/invalid/part/table--cell_col_negative.json +86 -0
  64. package/examples/invalid/part/table--cell_col_span_0.json +86 -0
  65. package/examples/invalid/part/table--cell_no_text.json +85 -0
  66. package/examples/invalid/part/table--cell_row_negative.json +86 -0
  67. package/examples/invalid/part/table--cell_row_span_0.json +86 -0
  68. package/examples/invalid/part/table--id.json +86 -0
  69. package/examples/invalid/part/table--no_cells.json +56 -0
  70. package/examples/invalid/part/table--no_source.json +83 -0
  71. package/examples/valid/big_table_book/001_s1.json +27 -0
  72. package/examples/valid/big_table_book/002_s1.1.json +216 -0
  73. package/examples/valid/big_table_book/003_s1.2.json +27 -0
  74. package/examples/valid/big_table_book/004_s2.json +25 -0
  75. package/examples/valid/big_table_book/index.json +28 -0
  76. package/examples/valid/deep_book/001_s1.json +27 -0
  77. package/examples/valid/deep_book/002_s1.1.json +29 -0
  78. package/examples/valid/deep_book/003_s1.1.1.json +30 -0
  79. package/examples/valid/deep_book/004_s1.1.1.1.json +31 -0
  80. package/examples/valid/deep_book/005_s1.1.1.1.1.json +32 -0
  81. package/examples/valid/deep_book/006_s1.1.1.1.1.1.json +33 -0
  82. package/examples/valid/deep_book/007_s1.1.1.1.1.1.1.json +33 -0
  83. package/examples/valid/deep_book/index.json +69 -0
  84. package/examples/valid/empty_book/index.json +9 -0
  85. package/examples/valid/merged_table_book/001_s1.json +38 -0
  86. package/examples/valid/merged_table_book/index.json +15 -0
  87. package/examples/valid/no_heading_book/001_front.json +39 -0
  88. package/examples/valid/no_heading_book/index.json +14 -0
  89. package/examples/valid/rich_book/001_front.json +17 -0
  90. package/examples/valid/rich_book/002_s1.json +123 -0
  91. package/examples/valid/rich_book/003_s2.json +25 -0
  92. package/examples/valid/rich_book/index.json +45 -0
  93. package/examples/valid/rich_split_book/001_front.json +17 -0
  94. package/examples/valid/rich_split_book/002_s1.json +28 -0
  95. package/examples/valid/rich_split_book/003_s1.1.json +90 -0
  96. package/examples/valid/rich_split_book/004_s1.1.1.json +28 -0
  97. package/examples/valid/rich_split_book/005_s2.json +25 -0
  98. package/examples/valid/rich_split_book/index.json +47 -0
  99. package/examples/valid/sized_book/001_front.json +17 -0
  100. package/examples/valid/sized_book/002_s1.json +51 -0
  101. package/examples/valid/sized_book/003_s1.1.json +43 -0
  102. package/examples/valid/sized_book/004_s1.1.1.json +42 -0
  103. package/examples/valid/sized_book/005_s1.2.json +28 -0
  104. package/examples/valid/sized_book/006_s2.json +64 -0
  105. package/examples/valid/sized_book/index.json +39 -0
  106. package/index.d.ts +44 -0
  107. package/index.js +693 -0
  108. package/package.json +45 -4
  109. package/schema/structure-index.schema.json +196 -0
  110. package/schema/structure-part.schema.json +492 -0
  111. package/types.d.ts +420 -0
package/README.md CHANGED
@@ -1,3 +1,300 @@
1
- # Temporary Holding Version
1
+ # Hefti
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 書籍の構造化 JSON(`structure/<版>/`)の形式を定める JSON Schema(draft 2020-12)です。
4
+ npm パッケージ `@yanqirenshi/hefti` として配ります。
5
+
6
+ この形式は、本を OCR して構造化するプログラムと、それを読む・編集する後工程のプログラムが、共通して使います。
7
+ 形式の定義だけを独立させてあるので、どの言語・どの道具からも同じスキーマで確かめられます。
8
+
9
+ ## 形式
10
+
11
+ `structure/<版>/` は、1 冊の本を「セクション(入れ子)→ パラグラフ → センテンス」で持ち、セクション単位のファイルに分けたフォルダです。
12
+ `structure/` の下には版が並びます(OCR の結果から作る原本の `original`、それを編集した版など)。
13
+ どの版も、同じ形式を使います。
14
+ 各要素に ID と元ページへの参照(`source`)があり、文章のチェックや校正を ID で指して行えます。
15
+
16
+ この形式を使うリポジトリは、次のとおりです。
17
+
18
+ | リポジトリ | 役割 |
19
+ |---|---|
20
+ | [Tyggja](https://github.com/yanqirenshi/Tyggja) | 原本(`structure/original/`)を作る |
21
+ | Melta | 原本を元に、校正・編集した版(`structure/<別の名前>/`)を作る |
22
+ | Frasoga | 版を表示・出版する |
23
+ | Bokasafn | 版を読む |
24
+
25
+ ### フォルダの形
26
+
27
+ ```
28
+ structure/<版>/
29
+ index.json 全体の情報と目次
30
+ 001_front.json 最初の見出しより前の本文(あるときだけ)
31
+ 002_s1.json 読み順の連番 + セクション ID
32
+ 014_s10.1.1.json
33
+ ```
34
+
35
+ 校正・編集のエージェントが、1 ファイルずつ読んで別の版を作れる大きさに分けてあります(64 ページの本で 70 ファイルほど)。
36
+ ファイル名は、読み順の 3 桁の連番とセクション ID です。
37
+
38
+ ### index.json
39
+
40
+ ```json
41
+ {
42
+ "version": 2,
43
+ "title": "本のタイトル",
44
+ "source": { "book": "book.json", "sha256": "…" },
45
+ "split_chars": 12000,
46
+ "pages": [ { "id": "p006_1", "status": "ok", "decorations": [ { "type": "header", "text": "柱の文字" } ] } ],
47
+ "files": [ { "file": "001_front.json", "id": null, "chars": 372, "json_chars": 2210 }, { "file": "002_s1.json", "id": "s1", "chars": 1012, "json_chars": 5873 } ],
48
+ "toc": [
49
+ { "id": "s10", "level": 1, "title": "2 …", "file": "014_s10.json",
50
+ "children": [ { "id": "s10.1", "level": 2, "title": "2.1 …", "file": "015_s10.1.json", "children": [] } ] }
51
+ ]
52
+ }
53
+ ```
54
+
55
+ - `source.sha256`:原本の元になったデータ(`source.book` のファイル)のハッシュです。
56
+ - `split_chars`:分けるときに使った上限(1 ファイルの JSON の文字数)です。
57
+ - `pages`:柱・ノンブル(header / footer / index)は本文に入れず、`pages[].decorations` に残します。`status` は `ok` または `ocr_failed` です。
58
+ - `files`:ファイルの一覧で、読み順です。`id` はファイルの先頭のセクションの ID(001_front.json は `null`)、`chars` は本文の文字数(空白を除く)、`json_chars` はそのファイルの JSON の文字数です。
59
+ - `toc`:すべてのセクションの木です。`file` は、そのセクションの見出しが入っているファイルです(分けられずに親のファイルに入っているセクションは、親と同じファイル名)。
60
+
61
+ ### 分けたファイル
62
+
63
+ ```json
64
+ {
65
+ "version": 2,
66
+ "file": "015_s10.1.json",
67
+ "id": "s10.1",
68
+ "ancestors": [ { "id": "s10", "level": 1, "title": "2 …" } ],
69
+ "body": [
70
+ { "type": "section", "id": "s10.1", "level": 2, "title": "2.1 …", "source": ["p021_1#1"],
71
+ "children": [
72
+ { "type": "paragraph", "id": "p120", "source": ["p021_1#2"], "sentences": [ { "id": "p120.1", "text": "…。" } ] },
73
+ { "type": "list", "id": "l1", "source": ["p007_1#3"],
74
+ "items": [ { "id": "l1.1", "source": ["p007_1#3"], "sentences": [ { "id": "l1.1.1", "text": "…" } ] } ] },
75
+ { "type": "figure", "id": "f1", "src": "figures/p007_1_0.png", "text": ["図の中の文字"], "source": ["p007_1#5"] },
76
+ { "type": "caption", "id": "c1", "text": "…", "source": ["p007_1#6"] },
77
+ { "type": "table", "id": "t1", "n_row": 2, "n_col": 2, "cells": [ { "row": 0, "col": 0, "row_span": 1, "col_span": 1, "text": "…" } ], "source": ["p007_1#7"] },
78
+ { "type": "section_ref", "id": "s10.1.1", "level": 3, "title": "2.1.1 …", "file": "016_s10.1.1.json" }
79
+ ] }
80
+ ]
81
+ }
82
+ ```
83
+
84
+ - `id` は、そのファイルの先頭のセクションの ID です。`ancestors` は、そのセクションより上の見出し(外側から順)です。
85
+ - `body` の要素は、`section`・`paragraph`・`list`・`figure`・`caption`・`table` です(`list` の項目は `items`、表のセルは `cells`)。
86
+ - `section_ref`:子セクションが別のファイルに分けてあることを示す印です。`file` の先のファイルの `body` の先頭が、その子セクションです。
87
+ - `001_front.json` は `id` が `null`、`ancestors` が空で、`body` に本文の要素が直接並びます。
88
+ - `figures` の画像:`figure` の `src`(例: `figures/p008_1_0.png`)は、`<出力フォルダ>` からの相対パスです。`structure/original/` から見ると `../../figures/p008_1_0.png` になります。
89
+ - `source`:`<ページID>#<そのページの book.json の blocks の番号>`。元の本のどこから来たかを辿れます。ページをまたぐ段落は複数になります。
90
+ - パラグラフに `text` はありません。センテンスが唯一の正本で、HTML などにするときはセンテンスを連結して段落にします。
91
+ - センテンスの `text` を連結すると、元の段落になります(区切りの後ろの改行や空白は、前のセンテンスの末尾に含めます)。
92
+ - ID は出現順の連番です(`s1` / `s1.1` / `p12` / `p12.3` / `l1.1.1` / `f1` / `t1` / `c1`)。ID は原本を作り直すと変わります。
93
+
94
+ ### JSON の書き方
95
+
96
+ エージェントが読むので、行数を抑えています。
97
+ センテンス 1 つ、表のセル 1 つ、`source` の配列は、それぞれ 1 行に書きます。短い入れ子(目次の項目など)も 1 行です。それ以外は字下げします。
98
+ 手で直すときも、この書き方でなくてかまいません(JSON として読めればよい)。
99
+
100
+ ### スキーマ
101
+
102
+ 形式は、JSON Schema(draft 2020-12)で定めてあります。
103
+
104
+ | ファイル | 検証するもの |
105
+ |---|---|
106
+ | `schema/structure-index.schema.json` | `structure/<版>/index.json`(全体の情報・ページの情報・ファイルの一覧・目次) |
107
+ | `schema/structure-part.schema.json` | 分けたファイル(`001_front.json`、`002_s1.json` など)。要素(section / section_ref / paragraph / list / figure / caption / table / sentence / source)の定義は、このファイルの `$defs` にまとめてある |
108
+
109
+ - どちらも 1 ファイルだけで検証できます(別ファイルへの `$ref` は使っていません)。
110
+ - 各プロパティに日本語の `description` があります。スキーマだけ読んでも意味が分かります。
111
+ - 知らないプロパティは許します。後工程が要素に情報を足して別の JSON にできるようにするためです。
112
+ - ID の形(`s1.2`・`p12`・`p12.3`・`l1.2.3`・`f1`・`t1`・`c1`)と `source`(`ページID#ブロック番号`)は、`pattern` で締めてあります。
113
+
114
+ ### スキーマでは確かめられないこと
115
+
116
+ 次のことは、読み込む側のプログラムが確かめます。
117
+
118
+ - `index.json` の `files` にあるファイルが無い
119
+ - `section_ref` の先が無い、先の中身と合わない、2 か所から参照されている
120
+ - どのファイルからも辿れないファイルがある
121
+ - ID が `structure/<版>/` 全体で重複している
122
+
123
+ ### 版を編集するときの ID の約束
124
+
125
+ original を元に版(`structure/<別の名前>/`)を作る後工程(Melta など)が、守る約束です。ID が動くと、指摘と本文の対応が取れなくなります。
126
+
127
+ 1. ID は原本を作ったときに決まる名前で、位置を表す番号ではない。版を編集して文を足したり消したりしても、他の要素の ID は振り直さない。
128
+ 2. 文を分けたり足したりするときは、そのパラグラフでまだ使っていない番号を付ける(p12 に 3 文あれば、足す文は p12.4)。並び順は配列の順で決まり、ID の大小は関係ない。
129
+ 3. 消した ID は使い回さない。
130
+ 4. 後工程は ID の形や順序に頼らない(ID は名前で、位置を表す番号ではない)。
131
+
132
+ ## 版番号
133
+
134
+ パッケージの版番号のメジャーは、データ形式の版(JSON の `version`)と同じです。
135
+ いまの形式は `version: 2` なので、`2.x.y` が対応します。
136
+ 形式を壊す変更をしたときは、`version` とメジャーを一緒に上げます。
137
+ メジャーはデータ形式の版です。型(`types.d.ts`)だけの変更は、マイナーで扱います。
138
+
139
+ ## 使い方(npm)
140
+
141
+ ```sh
142
+ npm install @yanqirenshi/hefti
143
+ npm install ajv # 検証に使う場合(Hefti 自体は実行時の依存を持ちません)
144
+ ```
145
+
146
+ スキーマを JS のオブジェクトとして読めます。
147
+ Node でも、Next.js などのバンドラーでも、同じように読めます。
148
+
149
+ ```js
150
+ import Ajv2020 from "ajv/dist/2020.js";
151
+ import { structureIndexSchema, structurePartSchema } from "@yanqirenshi/hefti";
152
+
153
+ const ajv = new Ajv2020();
154
+ const validateIndex = ajv.compile(structureIndexSchema);
155
+ const validatePart = ajv.compile(structurePartSchema);
156
+
157
+ if (!validateIndex(index)) console.error(validateIndex.errors);
158
+ ```
159
+
160
+ JSON ファイルのまま読むこともできます。
161
+
162
+ ```js
163
+ import index from "@yanqirenshi/hefti/schema/structure-index.schema.json" with { type: "json" };
164
+ ```
165
+
166
+ > 補足:ajv の `strict: true`(`strictTypes` を含む)では、`structure-part.schema.json` の `then` の中の `maxItems` に「`type` が無い」と警告されます。
167
+ > 検証の結果は変わらないので、`new Ajv2020({ strictTypes: false })` にするか、既定の設定で使ってください。
168
+
169
+ ## TypeScript の型
170
+
171
+ スキーマから生成した型(`types.d.ts`)を、パッケージに入れています。
172
+ 型は `import type` で読めます。
173
+
174
+ ```ts
175
+ import type { StructureIndex, StructurePart, BodyNode } from "@yanqirenshi/hefti";
176
+ ```
177
+
178
+ 主な型は、次のとおりです。
179
+
180
+ | 型 | 内容 |
181
+ |---|---|
182
+ | `StructureIndex` | `index.json`。`pages`(`PageInfo`)・`files`(`FileEntry`)・`toc`(`TocNode`)を持つ |
183
+ | `StructurePart` | 分けたファイル。`FrontPart`(`id` が `null`、`body` は本文の要素)か `SectionPart`(`body` はセクション 1 つ) |
184
+ | `BodyNode` | セクションの `children` に入る要素。`Section`・`SectionRef`・`Paragraph`・`List`・`Figure`・`Caption`・`Table` の共用体 |
185
+ | `FrontNode` | `001_front.json` の `body` に入る要素(`BodyNode` からセクションと `SectionRef` を除いたもの) |
186
+
187
+ 要素は `type` で絞り込めます(判別共用体)。
188
+ `default` で `never` になるので、種類が増えたときに型検査で気づけます。
189
+
190
+ ```ts
191
+ function text(node: BodyNode): string {
192
+ switch (node.type) {
193
+ case "section": return node.title;
194
+ case "section_ref": return node.title;
195
+ case "paragraph": return node.sentences.map((s) => s.text).join("");
196
+ case "list": return node.items.map((i) => i.sentences.map((s) => s.text).join("")).join("
197
+ ");
198
+ case "figure": return node.text.join("");
199
+ case "caption": return node.text;
200
+ case "table": return node.cells.map((c) => c.text).join(" ");
201
+ default: {
202
+ const unreachable: never = node;
203
+ return unreachable;
204
+ }
205
+ }
206
+ }
207
+
208
+ function elements(part: StructurePart) {
209
+ return part.id === null ? part.body : part.body[0].children; // FrontPart か SectionPart かで決まる
210
+ }
211
+ ```
212
+
213
+ - 知らないプロパティは許す形式なので、どの型にも `[k: string]: unknown` が付いています。後工程が項目を足した JSON も、同じ型で扱えます。
214
+ - 件数(`minItems` / `maxItems`)は型に出ません。`source` は `string[]` です。件数はスキーマの検証で確かめてください。
215
+ - 型で表せない約束があります。ID の書式(`pattern`)、`sha256` の書式、`minimum` などです。たとえば `SectionId` は `string` で、`"s1.2"` も `"abc"` も型検査を通ります。
216
+ これらは型検査では見つからず、スキーマの検証でだけ見つかります。
217
+ 外から受け取ったデータ(ファイルや通信で読んだ JSON)は、型を付けるだけでなく、スキーマで検証してください。
218
+ - 日本語の `description` は、JSDoc として残してあります。
219
+
220
+ ## 使い方(npm を使わない言語)
221
+
222
+ Python や Rust など、npm を使わない言語では、レジストリの tarball から `schema/` を取り出して使います。
223
+ `<版>` には、取り込みたいパッケージの版(例: `2.0.0`)を入れます。
224
+
225
+ ```sh
226
+ curl -fsSL https://registry.npmjs.org/@yanqirenshi/hefti/-/hefti-<版>.tgz -o hefti.tgz
227
+ tar -xzf hefti.tgz package/schema package/examples
228
+ ```
229
+
230
+ `package/schema/` に、スキーマ 2 件が入っています。
231
+ 自分のリポジトリにコピーし、取り込んだ版を記録しておくと、あとで同期を確かめられます。
232
+ 取り込んだファイルは、Hefti のコピーです。直接編集しないでください。
233
+
234
+ Python(`jsonschema`)での検証の例:
235
+
236
+ ```python
237
+ import json
238
+ from pathlib import Path
239
+ from jsonschema import Draft202012Validator
240
+
241
+ def validator(name):
242
+ return Draft202012Validator(json.loads(Path(f"schema/{name}.schema.json").read_text(encoding="utf-8")))
243
+
244
+ index, part = validator("structure-index"), validator("structure-part")
245
+ for f in sorted(Path("out/structure/original").glob("*.json")):
246
+ v = index if f.name == "index.json" else part
247
+ for e in v.iter_errors(json.loads(f.read_text(encoding="utf-8"))):
248
+ print(f.name, "/".join(map(str, e.absolute_path)), e.message)
249
+ ```
250
+
251
+ Rust では、`include_str!` でスキーマをバイナリに埋め込み、`jsonschema` クレートなどで検証できます。
252
+
253
+ ## 見本
254
+
255
+ `examples/valid/<本の名前>/` に、正しい見本があります(`index.json` と分けたファイル)。
256
+ 見本全体で、すべての種類の要素(section / section_ref / paragraph / list / figure / caption / table)を含みます。
257
+ パッケージにも入っているので、ほかの言語の実装が、同じ見本でテストできます。
258
+
259
+ | フォルダ | 内容 |
260
+ |---|---|
261
+ | `rich_book` | 柱・ノンブル・索引、白紙のページ、OCR 失敗、図・表・箇条書き・図表の説明を含む(最上位のセクションごとに 3 ファイル) |
262
+ | `rich_split_book` | `rich_book` と同じ本を小さく分けたもの(`section_ref` を含む) |
263
+ | `sized_book` | 上限を 1 文字にして、セクションごとに分けたもの(`section_ref` を含む) |
264
+ | `no_heading_book` | 見出しが無い本(`id` が `null` のファイルだけ) |
265
+ | `empty_book` | 中身が空の本 |
266
+ | `big_table_book` | 大きな表を含む本(`section_ref` を含む) |
267
+ | `deep_book` | 見出しが 7 段まで入れ子になる本 |
268
+ | `merged_table_book` | 結合セル(`row_span` / `col_span`)を含む表 |
269
+
270
+ `examples/invalid/` には、スキーマに通らない見本があります。
271
+ `sized_book` を 1 か所だけ壊したもので、1 ファイルに違反が 1 つです。
272
+ ファイル名が違反の内容を表します。
273
+
274
+ | フォルダ | 検証に使うスキーマ | ファイル名 |
275
+ |---|---|---|
276
+ | `index/` | `structure-index.schema.json` | `<違反>.json`(例: `no_sha256.json`、`toc_level_0.json`) |
277
+ | `part/` | `structure-part.schema.json` | `<要素の種類>--<違反>.json`(例: `paragraph--no_sentences.json`)。ファイル全体の違反は `file_<違反>.json` |
278
+
279
+ ほかの言語の実装では、`examples/valid/` がすべて通り、`examples/invalid/` がすべて拒否されることを確かめてください。
280
+
281
+ ## 開発
282
+
283
+ ```sh
284
+ npm install
285
+ npm test # スキーマ自体・見本・index.js のテスト(test/)
286
+ node scripts/build-index.mjs # schema/ から index.js を作り直す
287
+ node scripts/build-types.mjs # schema/ から types.d.ts を作り直す(npm run build は両方)
288
+ node scripts/build-invalid.mjs # examples/valid/sized_book から examples/invalid/ を作り直す
289
+ ```
290
+
291
+ `index.js` と `types.d.ts` も、生成したものをコミットしています。
292
+ スキーマを直したときは、`npm run build` で作り直してください。
293
+ `types.d.ts` は、`json-schema-to-typescript` と `typescript` の版を固定して作るので、同じスキーマからは同じ内容になります。
294
+
295
+ `examples/invalid/` は生成したものをコミットしています。
296
+ 壊し方を変えるときは `scripts/build-invalid.mjs` を直して作り直してください(作り直し忘れは `npm test` が見つけます)。
297
+
298
+ ## ライセンス
299
+
300
+ MIT
@@ -0,0 +1,112 @@
1
+ {
2
+ "version": 2,
3
+ "title": "テストの本",
4
+ "source": {
5
+ "book": "book.json",
6
+ "sha256": "b9cf0e2d7620250d09d1c9124cf40f88999c0308f743f0560d2965da21a65555"
7
+ },
8
+ "split_chars": 1,
9
+ "pages": [
10
+ {
11
+ "id": "p0001_0",
12
+ "status": "ok",
13
+ "decorations": [
14
+ {
15
+ "type": "body",
16
+ "text": "柱:テストの本"
17
+ },
18
+ {
19
+ "type": "footer",
20
+ "text": "1"
21
+ }
22
+ ]
23
+ },
24
+ {
25
+ "id": "p0002_0",
26
+ "status": "ok",
27
+ "decorations": [
28
+ {
29
+ "type": "footer",
30
+ "text": "2"
31
+ }
32
+ ]
33
+ }
34
+ ],
35
+ "files": [
36
+ {
37
+ "file": "001_front.json",
38
+ "id": null,
39
+ "chars": 21,
40
+ "json_chars": 273
41
+ },
42
+ {
43
+ "file": "002_s1.json",
44
+ "id": "s1",
45
+ "chars": 51,
46
+ "json_chars": 1112
47
+ },
48
+ {
49
+ "file": "003_s1.1.json",
50
+ "id": "s1.1",
51
+ "chars": 32,
52
+ "json_chars": 862
53
+ },
54
+ {
55
+ "file": "004_s1.1.1.json",
56
+ "id": "s1.1.1",
57
+ "chars": 21,
58
+ "json_chars": 959
59
+ },
60
+ {
61
+ "file": "005_s1.2.json",
62
+ "id": "s1.2",
63
+ "chars": 22,
64
+ "json_chars": 473
65
+ },
66
+ {
67
+ "file": "006_s2.json",
68
+ "id": "s2",
69
+ "chars": 291,
70
+ "json_chars": 2008
71
+ }
72
+ ],
73
+ "toc": [
74
+ {
75
+ "id": "s1",
76
+ "level": 1,
77
+ "title": "第1章 はじめの章",
78
+ "file": "002_s1.json",
79
+ "children": [
80
+ {
81
+ "id": "s1.1",
82
+ "level": 2,
83
+ "title": "1.1 最初の節",
84
+ "file": "003_s1.1.json",
85
+ "children": [
86
+ {
87
+ "id": "s1.1.1",
88
+ "level": 3,
89
+ "title": "1.1.1 深い項",
90
+ "file": "004_s1.1.1.json",
91
+ "children": []
92
+ }
93
+ ]
94
+ },
95
+ {
96
+ "id": "s1.2",
97
+ "level": 2,
98
+ "title": "1.2 二つ目の節",
99
+ "file": "005_s1.2.json",
100
+ "children": []
101
+ }
102
+ ]
103
+ },
104
+ {
105
+ "id": "s2",
106
+ "level": 1,
107
+ "title": "第2章 子の無い大きな章",
108
+ "file": "006_s2.json",
109
+ "children": []
110
+ }
111
+ ]
112
+ }
@@ -0,0 +1,112 @@
1
+ {
2
+ "version": 2,
3
+ "title": "テストの本",
4
+ "source": {
5
+ "book": "book.json",
6
+ "sha256": "b9cf0e2d7620250d09d1c9124cf40f88999c0308f743f0560d2965da21a65555"
7
+ },
8
+ "split_chars": 1,
9
+ "pages": [
10
+ {
11
+ "id": "p0001_0",
12
+ "status": "ok",
13
+ "decorations": [
14
+ {
15
+ "type": "header",
16
+ "text": "柱:テストの本"
17
+ },
18
+ {
19
+ "type": "footer",
20
+ "text": "1"
21
+ }
22
+ ]
23
+ },
24
+ {
25
+ "id": "p0002_0",
26
+ "status": "ok",
27
+ "decorations": [
28
+ {
29
+ "type": "footer",
30
+ "text": "2"
31
+ }
32
+ ]
33
+ }
34
+ ],
35
+ "files": [
36
+ {
37
+ "file": "001_front.json",
38
+ "id": null,
39
+ "chars": -1,
40
+ "json_chars": 273
41
+ },
42
+ {
43
+ "file": "002_s1.json",
44
+ "id": "s1",
45
+ "chars": 51,
46
+ "json_chars": 1112
47
+ },
48
+ {
49
+ "file": "003_s1.1.json",
50
+ "id": "s1.1",
51
+ "chars": 32,
52
+ "json_chars": 862
53
+ },
54
+ {
55
+ "file": "004_s1.1.1.json",
56
+ "id": "s1.1.1",
57
+ "chars": 21,
58
+ "json_chars": 959
59
+ },
60
+ {
61
+ "file": "005_s1.2.json",
62
+ "id": "s1.2",
63
+ "chars": 22,
64
+ "json_chars": 473
65
+ },
66
+ {
67
+ "file": "006_s2.json",
68
+ "id": "s2",
69
+ "chars": 291,
70
+ "json_chars": 2008
71
+ }
72
+ ],
73
+ "toc": [
74
+ {
75
+ "id": "s1",
76
+ "level": 1,
77
+ "title": "第1章 はじめの章",
78
+ "file": "002_s1.json",
79
+ "children": [
80
+ {
81
+ "id": "s1.1",
82
+ "level": 2,
83
+ "title": "1.1 最初の節",
84
+ "file": "003_s1.1.json",
85
+ "children": [
86
+ {
87
+ "id": "s1.1.1",
88
+ "level": 3,
89
+ "title": "1.1.1 深い項",
90
+ "file": "004_s1.1.1.json",
91
+ "children": []
92
+ }
93
+ ]
94
+ },
95
+ {
96
+ "id": "s1.2",
97
+ "level": 2,
98
+ "title": "1.2 二つ目の節",
99
+ "file": "005_s1.2.json",
100
+ "children": []
101
+ }
102
+ ]
103
+ },
104
+ {
105
+ "id": "s2",
106
+ "level": 1,
107
+ "title": "第2章 子の無い大きな章",
108
+ "file": "006_s2.json",
109
+ "children": []
110
+ }
111
+ ]
112
+ }
@@ -0,0 +1,112 @@
1
+ {
2
+ "version": 2,
3
+ "title": "テストの本",
4
+ "source": {
5
+ "book": "book.json",
6
+ "sha256": "b9cf0e2d7620250d09d1c9124cf40f88999c0308f743f0560d2965da21a65555"
7
+ },
8
+ "split_chars": 1,
9
+ "pages": [
10
+ {
11
+ "id": "p0001_0",
12
+ "status": "ok",
13
+ "decorations": [
14
+ {
15
+ "type": "header",
16
+ "text": "柱:テストの本"
17
+ },
18
+ {
19
+ "type": "footer",
20
+ "text": "1"
21
+ }
22
+ ]
23
+ },
24
+ {
25
+ "id": "p0002_0",
26
+ "status": "ok",
27
+ "decorations": [
28
+ {
29
+ "type": "footer",
30
+ "text": "2"
31
+ }
32
+ ]
33
+ }
34
+ ],
35
+ "files": [
36
+ {
37
+ "file": "001_front.json",
38
+ "id": null,
39
+ "chars": 21,
40
+ "json_chars": 273
41
+ },
42
+ {
43
+ "file": "s1.json",
44
+ "id": "s1",
45
+ "chars": 51,
46
+ "json_chars": 1112
47
+ },
48
+ {
49
+ "file": "003_s1.1.json",
50
+ "id": "s1.1",
51
+ "chars": 32,
52
+ "json_chars": 862
53
+ },
54
+ {
55
+ "file": "004_s1.1.1.json",
56
+ "id": "s1.1.1",
57
+ "chars": 21,
58
+ "json_chars": 959
59
+ },
60
+ {
61
+ "file": "005_s1.2.json",
62
+ "id": "s1.2",
63
+ "chars": 22,
64
+ "json_chars": 473
65
+ },
66
+ {
67
+ "file": "006_s2.json",
68
+ "id": "s2",
69
+ "chars": 291,
70
+ "json_chars": 2008
71
+ }
72
+ ],
73
+ "toc": [
74
+ {
75
+ "id": "s1",
76
+ "level": 1,
77
+ "title": "第1章 はじめの章",
78
+ "file": "002_s1.json",
79
+ "children": [
80
+ {
81
+ "id": "s1.1",
82
+ "level": 2,
83
+ "title": "1.1 最初の節",
84
+ "file": "003_s1.1.json",
85
+ "children": [
86
+ {
87
+ "id": "s1.1.1",
88
+ "level": 3,
89
+ "title": "1.1.1 深い項",
90
+ "file": "004_s1.1.1.json",
91
+ "children": []
92
+ }
93
+ ]
94
+ },
95
+ {
96
+ "id": "s1.2",
97
+ "level": 2,
98
+ "title": "1.2 二つ目の節",
99
+ "file": "005_s1.2.json",
100
+ "children": []
101
+ }
102
+ ]
103
+ },
104
+ {
105
+ "id": "s2",
106
+ "level": 1,
107
+ "title": "第2章 子の無い大きな章",
108
+ "file": "006_s2.json",
109
+ "children": []
110
+ }
111
+ ]
112
+ }