ndlocr-lite 1.4.0.dev0__py3-none-any.whl
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.
- cli.py +15 -0
- config/NDLmoji.yaml +4 -0
- config/__init__.py +0 -0
- config/ndl.yaml +21 -0
- deim.py +169 -0
- model/__init__.py +0 -0
- model_download.py +87 -0
- ndl_parser.py +1083 -0
- ndlocr_lite-1.4.0.dev0.dist-info/METADATA +182 -0
- ndlocr_lite-1.4.0.dev0.dist-info/RECORD +43 -0
- ndlocr_lite-1.4.0.dev0.dist-info/WHEEL +5 -0
- ndlocr_lite-1.4.0.dev0.dist-info/entry_points.txt +2 -0
- ndlocr_lite-1.4.0.dev0.dist-info/licenses/LICENCE +395 -0
- ndlocr_lite-1.4.0.dev0.dist-info/licenses/LICENCE_DEPENDENCEIES +1891 -0
- ndlocr_lite-1.4.0.dev0.dist-info/top_level.txt +16 -0
- ndlocr_lite_gui/__init__.py +12 -0
- ndlocr_lite_gui/assets/icon.png +0 -0
- ndlocr_lite_gui/gui_config.py +21 -0
- ndlocr_lite_gui/main.py +2105 -0
- ocr.py +1425 -0
- optional_features/__init__.py +52 -0
- parseq.py +74 -0
- pdf_output_utils.py +71 -0
- reading_order/__init__.py +0 -0
- reading_order/order/__init__.py +0 -0
- reading_order/order/parse_xml.py +143 -0
- reading_order/order/reorder.py +211 -0
- reading_order/order/smooth_order.py +110 -0
- reading_order/order/warichu_block.py +178 -0
- reading_order/order/wrap_dataset.py +13 -0
- reading_order/utils/__init__.py +0 -0
- reading_order/utils/file.py +21 -0
- reading_order/utils/logger.py +29 -0
- reading_order/utils/time.py +63 -0
- reading_order/utils/xml.py +97 -0
- reading_order/xy_cut/__init__.py +0 -0
- reading_order/xy_cut/block_xy_cut.py +366 -0
- reading_order/xy_cut/eval.py +55 -0
- tcy_wrapper.py +202 -0
- tools/ndlkoten2tei.py +115 -0
- uicomponent/localelabel.py +118 -0
- uicomponent/textdaisy.py +1093 -0
- version.py +3 -0
tools/ndlkoten2tei.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# TEI converter
|
|
2
|
+
# Copyright 2025 Kiyonori Nagasaki
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
import xml.etree.ElementTree as ET
|
|
17
|
+
|
|
18
|
+
xmltemplate="""<?xml version="1.0" encoding="UTF-8"?>
|
|
19
|
+
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
|
|
20
|
+
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml"
|
|
21
|
+
schematypens="http://purl.oclc.org/dsdl/schematron"?>
|
|
22
|
+
<TEI xmlns="http://www.tei-c.org/ns/1.0">
|
|
23
|
+
<teiHeader>
|
|
24
|
+
<fileDesc>
|
|
25
|
+
<titleStmt>
|
|
26
|
+
<title>Title</title>
|
|
27
|
+
<respStmt>
|
|
28
|
+
<resp>Automated Transcription</resp>
|
|
29
|
+
<name ref="https://github.com/ndl-lab/ndlocr-lite">NDLOCR-Liteアプリケーション</name>
|
|
30
|
+
</respStmt>
|
|
31
|
+
<respStmt><resp>Conversion to TEI encoding</resp>
|
|
32
|
+
<name>Kiyonori Nagasaki</name>
|
|
33
|
+
</respStmt>
|
|
34
|
+
</titleStmt>
|
|
35
|
+
<publicationStmt>
|
|
36
|
+
<p>Publication Information</p>
|
|
37
|
+
</publicationStmt>
|
|
38
|
+
<sourceDesc>
|
|
39
|
+
<p>Information about the source</p>
|
|
40
|
+
</sourceDesc>
|
|
41
|
+
</fileDesc>
|
|
42
|
+
</teiHeader>
|
|
43
|
+
<facsimile>
|
|
44
|
+
</facsimile>
|
|
45
|
+
<text>
|
|
46
|
+
<body>
|
|
47
|
+
<p></p>
|
|
48
|
+
</body>
|
|
49
|
+
</text>
|
|
50
|
+
</TEI>
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
def convert_tei(ndl_jsons):
|
|
54
|
+
root = ET.fromstring(xmltemplate)
|
|
55
|
+
ns = {'tei': 'http://www.tei-c.org/ns/1.0',
|
|
56
|
+
'xml': 'http://www.w3.org/XML/1998/namespace'}
|
|
57
|
+
|
|
58
|
+
ET.register_namespace('', ns['tei'])
|
|
59
|
+
ET.register_namespace('xml', ns['xml'])
|
|
60
|
+
|
|
61
|
+
el_body_p = root.find('tei:text', ns).find('tei:body', ns).find('tei:p', ns)
|
|
62
|
+
el_facsimile = root.find('tei:facsimile', ns)
|
|
63
|
+
|
|
64
|
+
all_data = []
|
|
65
|
+
for json_data in ndl_jsons:
|
|
66
|
+
page_data = {}
|
|
67
|
+
page_data["lines"] = []
|
|
68
|
+
for content in json_data['contents'][0]:
|
|
69
|
+
line_data = {}
|
|
70
|
+
l_x = content["boundingBox"][0][0]
|
|
71
|
+
l_y = content["boundingBox"][0][1]
|
|
72
|
+
l_x2 = content["boundingBox"][3][0]
|
|
73
|
+
l_y2 = content["boundingBox"][3][1]
|
|
74
|
+
line_data['rect'] = [l_x,l_y,l_x2,l_y2]
|
|
75
|
+
line_data['text'] = content["text"]
|
|
76
|
+
line_data['n'] = content["id"]
|
|
77
|
+
page_data["lines"].append(line_data)
|
|
78
|
+
page_data["imginfo"] = json_data["imginfo"]
|
|
79
|
+
all_data.append(page_data)
|
|
80
|
+
|
|
81
|
+
for pn,page in enumerate(all_data):
|
|
82
|
+
pnt = str(pn).zfill(4)
|
|
83
|
+
iname = page['imginfo']['img_name']
|
|
84
|
+
lines = page['lines']
|
|
85
|
+
el_surface = ET.SubElement(el_facsimile, 'surface')
|
|
86
|
+
el_graphic = ET.SubElement(el_surface, 'graphic')
|
|
87
|
+
image_path = page['imginfo']['img_path']
|
|
88
|
+
el_graphic.set('url', image_path.replace(" ","%20"))
|
|
89
|
+
el_graphic.set('width', str(page['imginfo']['img_width']) + 'px')
|
|
90
|
+
el_graphic.set('height', str(page['imginfo']['img_height']) + 'px')
|
|
91
|
+
lines_dict = {}
|
|
92
|
+
for line in lines:
|
|
93
|
+
nid = line['n']
|
|
94
|
+
lnt = str(nid).zfill(3)
|
|
95
|
+
plnt = 'L'+pnt+'_'+lnt
|
|
96
|
+
zone_attrs = {
|
|
97
|
+
'xml:id': plnt,
|
|
98
|
+
'ulx': str(line['rect'][0]),
|
|
99
|
+
'uly': str(line['rect'][1]),
|
|
100
|
+
'lrx': str(line['rect'][2]),
|
|
101
|
+
'lry': str(line['rect'][3]),
|
|
102
|
+
}
|
|
103
|
+
el_zone = ET.Element('zone', zone_attrs)
|
|
104
|
+
el_surface.append(el_zone)
|
|
105
|
+
lines_dict[nid] = f"{line['text']}\t{plnt}"
|
|
106
|
+
el_pb = ET.Element('pb', {'n': iname, 'facs': f'#{iname}'})
|
|
107
|
+
el_body_p.append(el_pb)
|
|
108
|
+
for k, v in lines_dict.items():
|
|
109
|
+
text, facs_id = v.split('\t')
|
|
110
|
+
el_lb = ET.Element('lb', {'n': str(k), 'facs': f'#{facs_id}'})
|
|
111
|
+
el_lb.tail = text
|
|
112
|
+
el_body_p.append(el_lb)
|
|
113
|
+
ET.indent(root)
|
|
114
|
+
xml_string = ET.tostring(root, encoding='utf-8', xml_declaration=True)
|
|
115
|
+
return xml_string
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
TRANSLATIONS = {
|
|
2
|
+
"main_explain":{
|
|
3
|
+
"ja":"処理対象と出力先を選択して「OCR」ボタンを押してください",
|
|
4
|
+
"en":"Please select target images and output folder, then press OCR"
|
|
5
|
+
},
|
|
6
|
+
"imageselector_cropocr_btn":{
|
|
7
|
+
"ja":"切り抜きOCR",
|
|
8
|
+
"en":"Crop OCR"
|
|
9
|
+
},
|
|
10
|
+
"imageselector_zoom_btn":{
|
|
11
|
+
"ja":"拡大する",
|
|
12
|
+
"en":"Zoom"
|
|
13
|
+
},
|
|
14
|
+
"imageselector_prev_btn":{
|
|
15
|
+
"ja":"前の画像",
|
|
16
|
+
"en":"Prev Image"
|
|
17
|
+
},
|
|
18
|
+
"imageselector_next_btn":{
|
|
19
|
+
"ja":"次の画像",
|
|
20
|
+
"en":"Next Image"
|
|
21
|
+
},
|
|
22
|
+
"imageselector_result_title":{
|
|
23
|
+
"ja":"切り抜きOCR結果",
|
|
24
|
+
"en":"OCR Result"
|
|
25
|
+
},
|
|
26
|
+
"capturetool_retry_btn":{
|
|
27
|
+
"ja":"再キャプチャ",
|
|
28
|
+
"en":"Retake"
|
|
29
|
+
},
|
|
30
|
+
"capturetool_fixregion":{
|
|
31
|
+
"ja":"範囲固定",
|
|
32
|
+
"en":"Fix Region"
|
|
33
|
+
},
|
|
34
|
+
"capturetool_ocr_button":{
|
|
35
|
+
"ja":"OCR実行",
|
|
36
|
+
"en":"OCR"
|
|
37
|
+
},
|
|
38
|
+
"capturetool_result_title":{
|
|
39
|
+
"ja":"キャプチャ結果",
|
|
40
|
+
"en":"Captured Image"
|
|
41
|
+
},
|
|
42
|
+
"capturetool_resultocr_title":{
|
|
43
|
+
"ja":"OCR結果",
|
|
44
|
+
"en":"OCR Result"
|
|
45
|
+
},
|
|
46
|
+
"main_file_upload_btn":{
|
|
47
|
+
"ja":"画像ファイルを処理する",
|
|
48
|
+
"en":"Process an Image"
|
|
49
|
+
},
|
|
50
|
+
"main_directory_upload_btn":{
|
|
51
|
+
"ja":"フォルダ内の画像を処理する",
|
|
52
|
+
"en":"Process Images in a Folder",
|
|
53
|
+
},
|
|
54
|
+
"main_directory_output_btn":{
|
|
55
|
+
"ja":"出力先を選択する",
|
|
56
|
+
"en":"Select Output Directory",
|
|
57
|
+
},
|
|
58
|
+
"main_stop_ocr_btn":{
|
|
59
|
+
"ja":"OCRを中断",
|
|
60
|
+
"en":"Stop OCR",
|
|
61
|
+
},
|
|
62
|
+
"main_ocr_cancel_requested":{
|
|
63
|
+
"ja":"中断を要求しました。現在の処理が終わり次第停止します……",
|
|
64
|
+
"en":"Stop requested. OCR will stop after the current operation……",
|
|
65
|
+
},
|
|
66
|
+
"main_ocr_cancelled":{
|
|
67
|
+
"ja":"OCRを中断しました({completed}/{total}画像完了 / 所要時間 {elapsed:.2f}秒)",
|
|
68
|
+
"en":"OCR stopped ({completed}/{total} images completed / Total time {elapsed:.2f} sec)",
|
|
69
|
+
},
|
|
70
|
+
"main_prev_btn":{
|
|
71
|
+
"ja":"前の画像",
|
|
72
|
+
"en":"Prev Image"
|
|
73
|
+
},
|
|
74
|
+
"main_next_btn":{
|
|
75
|
+
"ja":"次の画像",
|
|
76
|
+
"en":"Next Image"
|
|
77
|
+
},
|
|
78
|
+
"main_cap_btn":{
|
|
79
|
+
"ja":"キャプチャモード",
|
|
80
|
+
"en":"ScreenCapture Mode"
|
|
81
|
+
},
|
|
82
|
+
"main_customize_btn":{
|
|
83
|
+
"ja":"出力形式の選択",
|
|
84
|
+
"en":"Custom Setting"
|
|
85
|
+
},
|
|
86
|
+
"main_target_label":{
|
|
87
|
+
"ja":"処理対象:",
|
|
88
|
+
"en":"Target Path:"
|
|
89
|
+
},
|
|
90
|
+
"main_output_label":{
|
|
91
|
+
"ja":"出力先:",
|
|
92
|
+
"en":"Output Path:"
|
|
93
|
+
},
|
|
94
|
+
"main_preview_label":{
|
|
95
|
+
"ja":"処理結果プレビュー",
|
|
96
|
+
"en":"Preview of Result"
|
|
97
|
+
},
|
|
98
|
+
"main_visualize_label":{
|
|
99
|
+
"ja":"認識箇所の可視化画像を保存する",
|
|
100
|
+
"en":"Save Visualization Results"
|
|
101
|
+
},
|
|
102
|
+
"customize_dlg_modal_title":{
|
|
103
|
+
"ja":"設定",
|
|
104
|
+
"en":"Setting"
|
|
105
|
+
},
|
|
106
|
+
"customize_dlg_modal_explain":{
|
|
107
|
+
"ja":"出力形式を選択してください",
|
|
108
|
+
"en":"Please select output format"
|
|
109
|
+
},
|
|
110
|
+
"common_cancel":{
|
|
111
|
+
"ja":"キャンセル",
|
|
112
|
+
"en":"Dismiss",
|
|
113
|
+
},
|
|
114
|
+
"common_close":{
|
|
115
|
+
"ja":"閉じる",
|
|
116
|
+
"en":"Close",
|
|
117
|
+
}
|
|
118
|
+
}
|