fasdfsa commited on
Commit
cac436a
·
1 Parent(s): ee034c2

add .boxsnew

Browse files
Files changed (36) hide show
  1. data/ch000/評論出像水滸傳卷之一_楔子/out2/000057_1.boxsnew +3 -0
  2. data/ch000/評論出像水滸傳卷之一_楔子/out2/000058_0.boxsnew +3 -0
  3. data/ch000/評論出像水滸傳卷之一_楔子/out2/000058_1.boxsnew +3 -0
  4. data/ch000/評論出像水滸傳卷之一_楔子/out2/000059_0.boxsnew +3 -0
  5. data/ch000/評論出像水滸傳卷之一_楔子/out2/000059_1.boxsnew +3 -0
  6. data/ch000/評論出像水滸傳卷之一_楔子/out2/000060_0.boxsnew +3 -0
  7. data/ch000/評論出像水滸傳卷之一_楔子/out2/000060_1.boxsnew +3 -0
  8. data/ch000/評論出像水滸傳卷之一_楔子/out2/000061_0.boxsnew +3 -0
  9. data/ch000/評論出像水滸傳卷之一_楔子/out2/000061_1.boxsnew +3 -0
  10. data/ch000/評論出像水滸傳卷之一_楔子/out2/000062_0.boxsnew +3 -0
  11. data/ch000/評論出像水滸傳卷之一_楔子/out2/000062_1.boxsnew +3 -0
  12. data/ch000/評論出像水滸傳卷之一_楔子/out2/000063_0.boxsnew +3 -0
  13. data/ch000/評論出像水滸傳卷之一_楔子/out2/000063_1.boxsnew +3 -0
  14. data/ch000/評論出像水滸傳卷之一_楔子/out2/000064_0.boxsnew +3 -0
  15. data/ch000/評論出像水滸傳卷之一_楔子/out2/000064_1.boxsnew +3 -0
  16. data/ch000/評論出像水滸傳卷之一_楔子/out2/000065_0.boxsnew +3 -0
  17. data/ch000/評論出像水滸傳卷之一_楔子/out2/000065_1.boxsnew +3 -0
  18. data/ch000/評論出像水滸傳卷之一_楔子/out2/000066_0.boxsnew +3 -0
  19. data/ch000/評論出像水滸傳卷之一_楔子/out2/000066_1.boxsnew +3 -0
  20. data/ch000/評論出像水滸傳卷之一_楔子/out2/000067_0.boxsnew +3 -0
  21. data/ch000/評論出像水滸傳卷之一_楔子/out2/000067_1.boxsnew +3 -0
  22. data/ch000/評論出像水滸傳卷之一_楔子/out2/000068_0.boxsnew +3 -0
  23. data/ch000/評論出像水滸傳卷之一_楔子/out2/000068_1.boxsnew +3 -0
  24. data/ch000/評論出像水滸傳卷之一_楔子/out2/000069_0.boxsnew +3 -0
  25. data/ch000/評論出像水滸傳卷之一_楔子/out2/000069_1.boxsnew +3 -0
  26. data/ch000/評論出像水滸傳卷之一_楔子/out2/000070_0.boxsnew +3 -0
  27. data/ch000/評論出像水滸傳卷之一_楔子/out2/000070_1.boxsnew +3 -0
  28. data/ch000/評論出像水滸傳卷之一_楔子/out2/000071_0.boxsnew +3 -0
  29. data/ch000/評論出像水滸傳卷之一_楔子/out2/000071_1.boxsnew +3 -0
  30. data/ch000/評論出像水滸傳卷之一_楔子/out2/000072_0.boxsnew +3 -0
  31. data/ch000/評論出像水滸傳卷之一_楔子/out2/000072_1.boxsnew +3 -0
  32. data/ch000/評論出像水滸傳卷之一_楔子/out2/000073_0.boxsnew +3 -0
  33. data/ch000/評論出像水滸傳卷之一_楔子/out2/000074.boxsnew +3 -0
  34. data/ch000/評論出像水滸傳卷之一_楔子/out2/000075.boxsnew +3 -0
  35. requirements.txt +2 -0
  36. typ_ch.py +167 -0
data/ch000/評論出像水滸傳卷之一_楔子/out2/000057_1.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:65f41883f4154559abc544ed77e95318287ad64c00d331a5fe933f204b572873
3
+ size 90572
data/ch000/評論出像水滸傳卷之一_楔子/out2/000058_0.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c909ab26f3bd920c8d5082dea7400d893e88945f88658bbed9e9399237ac70ec
3
+ size 109176
data/ch000/評論出像水滸傳卷之一_楔子/out2/000058_1.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3ac745bfa539e14fcbc5b8dfcbb3c0044c53fdaa0a56df91b15585561aa7f011
3
+ size 101055
data/ch000/評論出像水滸傳卷之一_楔子/out2/000059_0.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1ceb7a598638138cc560b1bee66a843a529afd95908ad942f9b6f833b12b2b7e
3
+ size 101841
data/ch000/評論出像水滸傳卷之一_楔子/out2/000059_1.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a7cd30026a2015d0a1975b19f359d0d81be01441471b8237e3bdd8804ca70f48
3
+ size 140683
data/ch000/評論出像水滸傳卷之一_楔子/out2/000060_0.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f8b1decbb90c02068c9d14463460d1415f02946683e4aafe0c7ddb44ca17248b
3
+ size 131604
data/ch000/評論出像水滸傳卷之一_楔子/out2/000060_1.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:30c3c880144e67bc05150e1ccf7460994612eb39861320edcbac0e7e637d1044
3
+ size 144320
data/ch000/評論出像水滸傳卷之一_楔子/out2/000061_0.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1d1019e7582d70ef386e34df06be873b8c0d3e4aaa8ba1d06876f6d8853d65f7
3
+ size 134400
data/ch000/評論出像水滸傳卷之一_楔子/out2/000061_1.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b543ca0fb5486dd8b175814e66b919ae9b15196b57402850f3f6214dc1278518
3
+ size 125418
data/ch000/評論出像水滸傳卷之一_楔子/out2/000062_0.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:42bece0f29eafd12ed0408cdab2c99ce915f5188b2a9f26063b84f47ff84da49
3
+ size 129891
data/ch000/評論出像水滸傳卷之一_楔子/out2/000062_1.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:328a556c2530a502e658fce2eb3ea287d3d5a903721643a1ab7ad8320155321b
3
+ size 122704
data/ch000/評論出像水滸傳卷之一_楔子/out2/000063_0.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:15741c4de71b9efb0627452f0144f3e5378cb71f44f73bab3ec6a109bf182fc1
3
+ size 137465
data/ch000/評論出像水滸傳卷之一_楔子/out2/000063_1.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7e366344edc8064cbe23a47737134911c69da9255fb0d6f9b7675ad8eb214ca7
3
+ size 137084
data/ch000/評論出像水滸傳卷之一_楔子/out2/000064_0.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:922c90a5d59a673a3640204d94706054d6163a4f7b67ca264b363a670e75469c
3
+ size 143881
data/ch000/評論出像水滸傳卷之一_楔子/out2/000064_1.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:24f06f0ed1114712c92c8db8ac3f931ab825c3e67dfea1ab61ec4061a835799b
3
+ size 133991
data/ch000/評論出像水滸傳卷之一_楔子/out2/000065_0.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ff82cd569c3fbcba86650fd2c07f73ed6bd942491ba4eb30bbdb764a84aaa12f
3
+ size 128527
data/ch000/評論出像水滸傳卷之一_楔子/out2/000065_1.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5e321c1f30bece0c992c1fd0f2bbdaa1f25ef8a4161d3f12d78a9fa77a7e9cb9
3
+ size 124960
data/ch000/評論出像水滸傳卷之一_楔子/out2/000066_0.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:94fb04fc491c627fbfa00de3e48cd1ae1480820690714f65e1eb06720e894ee9
3
+ size 137006
data/ch000/評論出像水滸傳卷之一_楔子/out2/000066_1.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a53fc7f17969141a3114f615d3a44df77e320b1c453c249ad44072e4b5ada0c4
3
+ size 128966
data/ch000/評論出像水滸傳卷之一_楔子/out2/000067_0.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2ff51b6241be22fed1df5e019530befec18e6c3e108e5dba821d03b361c8f554
3
+ size 123557
data/ch000/評論出像水滸傳卷之一_楔子/out2/000067_1.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:92b11d4519702b1d4839aa1e4a241a936a58768bb256a475a4477088316a925e
3
+ size 130804
data/ch000/評論出像水滸傳卷之一_楔子/out2/000068_0.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:daf1ece983784d6073127cb8c9c0b239267b041e3fff49147541ee1fa5a77603
3
+ size 135328
data/ch000/評論出像水滸傳卷之一_楔子/out2/000068_1.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dfc150d22a390f1220f2a71c924bdff4ffeb95321940eb6167c22b70f09492a3
3
+ size 134412
data/ch000/評論出像水滸傳卷之一_楔子/out2/000069_0.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dbb64c214603e057bf05e849d02729f84a8d764d066ae05fa986e582e0f09784
3
+ size 130283
data/ch000/評論出像水滸傳卷之一_楔子/out2/000069_1.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2e6f5c7b982035c852355c98c038ad880d8d567decb18fa56e66516cd900b2cf
3
+ size 132065
data/ch000/評論出像水滸傳卷之一_楔子/out2/000070_0.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:71c22ef358ed51146f7d108ed3dfd771577e23400897a1c8fa9d80536c1b17fd
3
+ size 75545
data/ch000/評論出像水滸傳卷之一_楔子/out2/000070_1.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5183761bab3b496d92ed1715656581b640aa8730246fa04c318832c4f98dfcc9
3
+ size 73710
data/ch000/評論出像水滸傳卷之一_楔子/out2/000071_0.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6c27a77e5e1ce095a92b63e7571695f51c9b396cd146c21e236f6977a3a6b285
3
+ size 72794
data/ch000/評論出像水滸傳卷之一_楔子/out2/000071_1.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3fbf9e3a3f86a1c6db6726689597422e8a7d5433eeed271848d4242f82be9177
3
+ size 77337
data/ch000/評論出像水滸傳卷之一_楔子/out2/000072_0.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:df6d4cd8e8a1529831d94f756cd881418fa9c2a86dbea2efb0f2e4c1df605450
3
+ size 74639
data/ch000/評論出像水滸傳卷之一_楔子/out2/000072_1.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7899f41070ac23769a3786cd33aa36a0ca551a9ebaf962a2386d5b2cfbccbd37
3
+ size 72805
data/ch000/評論出像水滸傳卷之一_楔子/out2/000073_0.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:41e06b145bd9ce2e2b436bb899f0150ac488495d0d8d4b256412e66df3702b92
3
+ size 95521
data/ch000/評論出像水滸傳卷之一_楔子/out2/000074.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
3
+ size 2
data/ch000/評論出像水滸傳卷之一_楔子/out2/000075.boxsnew ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
3
+ size 2
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ numpy<2.0
2
+ opencc
typ_ch.py ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # 原先是 typst_hlm 给 huggingface_echodict\typst-app-clone\public\chapters\ch01.typ 它排版,校对
3
+
4
+ # 自动生成 typst 章节,放 auto_chapters 目录下
5
+
6
+ # see exinfo.py 先生成 .boxsnew ,再手动改 space is_menu is_menutitle 属性
7
+
8
+ if __name__ == '__main__':
9
+
10
+ import glob
11
+ import os
12
+ import json
13
+ import numpy as np
14
+ from pathlib import Path
15
+ import opencc
16
+ import copy
17
+ from collections import defaultdict, OrderedDict
18
+ s2t = opencc.OpenCC('s2t.json') # 简繁转换
19
+ t2s = opencc.OpenCC('t2s.json')
20
+
21
+ chs = glob.glob('data/ch*', recursive=False)
22
+
23
+ menus = []
24
+ pages_all = []
25
+ for i, pth in enumerate(chs):
26
+ pth = pth.replace('\\', '/')
27
+ parts = pth.split('/')
28
+ chapter = parts[1]
29
+
30
+ chapter_path = glob.glob(f'data/{chapter}/*', recursive=False)[0]
31
+
32
+ out2 = f'{chapter_path}/out2'
33
+
34
+ if not os.path.exists(out2):
35
+ continue
36
+
37
+ with open(f"{out2}/page_texts.json", "r", encoding='UTF-8') as fp:
38
+ page_texts = json.load(fp)
39
+
40
+ with open(f"{out2}/pageIds_pageNames.json", "r", encoding='UTF-8') as fp:
41
+ pageIds_pageNames = json.load(fp)
42
+
43
+ pageNames_pageIds = {}
44
+ for k, v in pageIds_pageNames.items():
45
+ pageNames_pageIds[v] = k
46
+
47
+
48
+ boxs = glob.glob(f"{out2}/*.boxsnew", recursive=False)
49
+
50
+
51
+ menu = ''
52
+ menu_title = ''
53
+
54
+ pages = []
55
+
56
+ for j, pt in enumerate(boxs):
57
+
58
+ pageName = Path(pt).stem
59
+ pageId = pageNames_pageIds[pageName]
60
+
61
+ with open(pt, "r", encoding='UTF-8') as fp:
62
+ box = json.load(fp)
63
+
64
+ page_text = ''
65
+
66
+ for k, bx in enumerate(box):
67
+ charPoly = bx["charPoly"]
68
+ charText = bx["charText"]
69
+ sign = bx["sign"]
70
+ space = bx["space"]
71
+ is_menu = bx["is_menu"]
72
+ is_menutitle = bx["is_menutitle"]
73
+
74
+ if is_menu:
75
+ menu = menu + charText + sign
76
+ if is_menutitle:
77
+ menu_title = menu_title + charText + sign
78
+
79
+ if menu_title != '' and not is_menutitle:
80
+
81
+ if len(pages) > 0:
82
+ menus[-1]["pages"] = copy.deepcopy(pages)
83
+ pages = []
84
+
85
+ menus.append({ "menu": menu, "menu_title": menu_title })
86
+ menu = ''
87
+ menu_title = ''
88
+
89
+ # if not is_menu and not is_menutitle:
90
+ # page_text = page_text + charText + sign
91
+ page_text = page_text + charText + sign
92
+ pass
93
+
94
+ pages.append({"pageName":pageName, "pageId":pageId, "chapter":chapter, "page_text": page_text, "box": box })
95
+ pages_all.append({"pageName":pageName, "pageId":pageId, "chapter":chapter, "page_text": page_text, "box": box })
96
+
97
+ pass
98
+
99
+ # 不存在就写
100
+ pth_pages_all = 'data/pages_all.json'
101
+ if not os.path.exists(pth_pages_all):
102
+ with open(pth_pages_all, 'w', encoding='utf-8') as fp:
103
+ json.dump(pages_all, fp, indent=4, ensure_ascii=False)
104
+
105
+ # 存在就读 pages_all.json ,生成 typst 章节
106
+ if os.path.exists(pth_pages_all):
107
+ with open(pth_pages_all, "r", encoding='UTF-8') as fp:
108
+ pages_all = json.load(fp)
109
+
110
+
111
+ dir_autochapters = 'auto_chapters'
112
+ if not os.path.exists(dir_autochapters):
113
+ os.makedirs(dir_autochapters)
114
+
115
+ # py3.7+ 字典默认就是有序的
116
+ grouped = defaultdict(list)
117
+ for item in pages_all:
118
+ grouped[item.get("chapter")].append(item)
119
+
120
+ for ch, pages in grouped.items():
121
+ pt_ch = f'{dir_autochapters}/{ch}.typ'
122
+ menu = ''
123
+ menu_title = ''
124
+ page_text = ''
125
+ ch_text = """#import "../lib.typ": *\n#heading(level: 1, outlined: true)"""
126
+ menu_linkChar = ''
127
+ menu_title_linkChar = ''
128
+ for i, page in enumerate(pages):
129
+ box = page["box"]
130
+ pageName = page['pageName']
131
+ for k, bx in enumerate(box):
132
+ charPoly = bx["charPoly"]
133
+ charText = bx["charText"]
134
+ sign = bx["sign"]
135
+ space = ' ' if bx["space"] else ''
136
+ space_n = ' ' if bx["space"] else ''
137
+ is_menu = bx["is_menu"]
138
+ is_menutitle = bx["is_menutitle"]
139
+ x0, y0, x1, y1, x2, y2, x3, y3 = charPoly['x0'], charPoly['y0'], charPoly['x1'], charPoly['y1'], charPoly['x2'], charPoly['y2'], charPoly['x3'], charPoly['y3']
140
+ linkChar = f"""#c("{charText}", "{pageName},{x0},{y0},{x1},{y1},{x2},{y2},{x3},{y3}")"""
141
+ if is_menu:
142
+ menu = menu + charText + space_n
143
+ menu_linkChar = menu_linkChar + linkChar + space
144
+ if is_menutitle:
145
+ menu_title = menu_title + charText + space_n
146
+ menu_title_linkChar = menu_title_linkChar + linkChar + space
147
+
148
+ if menu_title != '' and not is_menutitle:
149
+ ch_text = ch_text + f"""[{menu} {menu_title}]\n #v(0.1em){menu_linkChar}#v(18em)\n {menu_title_linkChar}#v(18em)\n"""
150
+ menu = ''
151
+ menu_title = ''
152
+ menu_linkChar = ''
153
+ menu_title_linkChar = ''
154
+
155
+ if not is_menu and not is_menutitle:
156
+ page_text = page_text + linkChar + space + sign
157
+
158
+ page_text += '\n'
159
+
160
+
161
+ ch_text += page_text
162
+
163
+ with open(pt_ch, 'w', encoding='utf-8') as f:
164
+ f.write(ch_text)
165
+
166
+ pass
167
+