generated from OpenPecha/python-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from OpenPecha/feat-prepare_data
Feat prepare data
- Loading branch information
Showing
17 changed files
with
264 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
output/ | ||
data/ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,12 @@ requires = ["setuptools>=61.0"] | |
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "project_name" | ||
name = "bo_rag_prep_tool" | ||
version = "0.0.1" | ||
authors = [ | ||
{ name="OpenPecha", email="[email protected]" }, | ||
] | ||
description = "A small example package" | ||
description = "Tool to prepare data for rag prep tool" | ||
readme = "README.md" | ||
requires-python = ">=3.8" | ||
classifiers = [ | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from pathlib import Path | ||
|
||
import yaml | ||
|
||
from bo_rag_prep_tool.utils import write_json | ||
|
||
|
||
def prepare(opf_path: Path, output_path: Path): | ||
book_metadata = [] | ||
ann_files = list(Path(opf_path / "layers").rglob("*.yml")) | ||
ann_files = sorted(ann_files, key=lambda x: x.name) | ||
|
||
pecha_id = opf_path.name.split(".")[0] | ||
for ann_file in ann_files: | ||
with open(ann_file) as f: | ||
layer = yaml.load(f, Loader=yaml.FullLoader) | ||
# Get base | ||
base_path = opf_path / "base" / f"{ann_file.parent.name}.txt" | ||
base_content = base_path.read_text(encoding="utf-8") | ||
# Get annotations | ||
anns = layer["annotations"] | ||
for ann in anns.values(): | ||
start = ann["span"]["start"] | ||
end = ann["span"]["end"] | ||
base_span = base_content[start:end] | ||
curr_book_metadata = { | ||
"pecha_id": pecha_id, | ||
"base": ann_file.parent.name, | ||
"start": start, | ||
"end": end, | ||
"content": base_span, | ||
} | ||
for k, v in ann.items(): | ||
if k != "span": | ||
curr_book_metadata[k] = v | ||
book_metadata.append(curr_book_metadata) | ||
|
||
output_path.mkdir(exist_ok=True, parents=True) | ||
json_output_path = output_path / f"{pecha_id}.json" | ||
write_json(json_output_path, book_metadata) | ||
return json_output_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import json | ||
|
||
|
||
def read_json(file_path): | ||
with open(file_path) as f: | ||
data = json.load(f) | ||
return data | ||
|
||
|
||
def write_json(file_path, data): | ||
with open(file_path, "w") as f: | ||
json.dump(data, f, ensure_ascii=False, indent=2) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
༄༅། །ཨོ་རྒྱན་རྩ་གསུམ་གླིང་པའི་རིང་ལུགས་ཟབ་གཏེར་པོད་ཉེར་བདུན་པ་གྲོལ་བྱེད་ཁྲིད་ཀྱི་ | ||
རིམ་པ་ཕྱོགས་གཅིག་ཏུ་བསྡུས་པ་ཐེག་མཆོག་རྩེ་མོར་འཇུག་པའི་ཐེམ་སྐས་ཞེས་བྱ་བ་བཞུགས་སོ།། | ||
|
||
༄༅། །ཨོ་རྒྱན་རྩ་གསུམ་གླིང་པའི་རིང་ལུགས་གྲོལ་བྱེད་ཁྲིད་ཀྱི་རིམ་པ་ཕྱོགས་གཅིག་ཏུ་བསྡུས་པ་ཐེག་མཆོག་རྩེ་མོར་འཇུག་པའི་ཐེམ་སྐས་ཞེས་བྱ་བ་བཞུགས་སོ།། ཨོཾ་སྭ་སྟི། གཏེར་ཆེན་རྩ་ | ||
གསུམ་གླིང་པའི་ཟབ་མོའི་གཏེར། །བདུན་ཅུའི་ཡང་སྙིང་གྲོལ་བྱེད་ཁྲིད་རིམ་ཕལ། །དུས་རླུང་དྲག་པོས་ཁྱེར་བའི་འཐོར་ལུས་རིགས། །འབད་བརྒྱས་ཕྱོགས་བསྡུས་གང་ནུས་སྲི་ | ||
ཞུ་བཅས། །ཐེག་རྩེར་འཇུག་པའི་ཐེམ་སྐས་འདིར་སློང་བྱ། །དེ་ལ་ཨོ་རྒྱན་རྩ་གསུམ་གླིང་པའི་ཟབ་གཏེར་རྗེས་འབྲངས་དང་བཅས་པའི་ཕྱོགས་གཏོགས་གྲོལ་བྱེད་ཁྲིད་ཀྱི་རིམ་པ་ | ||
ཟབ་པ་གཏེར་བྱོན་སྐོར། བཀའ་བརྒྱད་གསང་བ་ཟིལ་གནོན་ལས། ཕྱི་རྒྱུད་ཐེག་པ་རིམ་དགུ་དང་། རྫོགས་ཆེན་ཡང་གསང་བླ་མེད། དེའི་དོན་ཁྲིད་དཀོན་སེང་པཎྜི་ཏས་མཛད་པ་ | ||
དང་༑ རྒ་རྒྱལ་གཏེར་བྱོན་རྫོགས་ཆེན་འཁོར་འདས་རང་གྲོལ་ལས་ཚོགས་ཆ་ལག་དང་བཅས་པ། གསང་བ་ཡེ་ཤེས་རྩ་རླུང་སྙན་བརྒྱུད་གསང་མཛོད་སོགས་ཆོས་སྡེ་ཕལ་ཆེ་བར་ | ||
|
||
རྒྱབ་ཆོས་ཁྲིད་གཞུང་དང་། སྤྲ་ཁྲིད་མན་ངག་ཟབ་ཁྱད་མང་དུ་བཞུགས་པ་ཕལ་ཆེར་གངས་ལྗོངས་སྤྱི་མཐུན་བཞིན་དུས་འགྱུར་ཆུ་ལོག་དྲག་པོས་ཁྱེར་ནས་མི་མངོན་གདོད་མའི་ | ||
དབྱིངས་སུ་གཤེགས་ཟིན་པར་མངོན་ལ། ཡང་དར་ཆོས་རིགས་སླར་གསོའི་སྐབས། དཔེ་རྒྱན་གང་རྙེད་ཕྱོགས་བསྡུས་བྱས་པའི་ནང༌། པདྨ་ཁྲག་འཐུང་གི་ཁྲིད་སྐོར་སོགས་ | ||
འཐོར་བུ་འགའ་རྙེད་པ་དང་། དེ་དག་ལ་ཁོ་བོས་སྲི་ཞུར་དམིགས་པའི་དགོངས་འགྲེལ་དང་ཟིན་བྲིས་ཅི་རིགས་པ་བཅས་ཁྲིད་ཡིག་ཕྱོགས་བསྡུས་ཀྱི་ཐེམ་བྱང་འགོད་པ་ལ། ཐོག་མ | ||
མར་ཀ༽ ལོ་གསུམ་བསྙེན་སྒྲུབ་མཚམས་ཀྱི་ཁོག་དབུབ་མཁྱེན་བརྩེའི་དགོངས་རྒྱན་སྒེག་མོའི་མེ་ལོང་། 1-32 ཁ༽ ཞི་གནས་དང་ལྷག་མཐོང་སྒབ་པའི་ཚུལ་འཇམ་མགོན་ | ||
བླ་མའི་ཞལ་གྱི་བདུད་རྩིའི་ཉིང་ཁུ། 33-70 ག༽ ཐུན་མོང་ཕྱི་ཡི་སྔོན་འགྲོའི་ལག་ཁྲིད་གདབ་པ་མན་ངག་གནད་ཀྱི་གཟེར་བུ། 71-126 ང༽ རྫོགས་པ་ཆེན་པོ་འཁོར་ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
༄༅། །ཨོ་རྒྱན་རྩ་གསུམ་གླིང་པའི་རིང་ལུགས་ཟབ་གཏེར་པོད་ཉེར་བརྒྱད་པ་རྗེ་གོང་མའི་གཏེར་མཐའ་སྐྱོང་བ་པད་རྒྱལ་ | ||
གླིང་པའི་ཟབ་གཏེར་ལས། ཆ་ཤས་ཁ་སྐོང་གི་ཚུལ་དུ་བཀོད་པ་དང་གནམ་ལྕགས་ཐོར་བུ་ཐེམ་སྐས་བཅས་བཞུགས་སོ།། | ||
|
||
༄༅། །ཨོ་རྒྱན་རྩ་གསུམ་གླིང་པའི་གཏེར་གྱི་མཐའ་སྐྱོང་བ་སྤྲུལ་པའི་གཏེར་ཆེན་པདྨ་རྒྱལ་པོ་གར་དབང་འགྲོ་འདུལ་གླིང་པ་རྩལ་གྱི་ཟབ་གཏེར་ལས། ཆ་ཤས་ཁ་སྐོང་གི་ཚུལ་དུ་བཞུགས་པའི་ཐེམ་བྱང་བཞུགས་སོ། | ||
། ཨོཾ་སྭཱ་སྟི། སྡེ་གསུམ་ཡོངས་ཀྱི་སྲོལ་འབྱེད་གནུབས་ཆེན་ཉིད། །དེ་ཡང་གཙུག་ལག་དཔལ་དགེ་ཞང་ཁྲོམ་དང་། །དྲི་མེད་ཀུན་དགའ་རྩ་གསུམ་གླིང་པ་སོགས། །སྲོལ་ | ||
འབྱེད་གཏེར་ཆེན་དུ་མའི་རོལ་གར་བསྒྱུར། །ཕྱི་མོ་གར་དབང་གནམ་ལྕགས་རྡོ་རྗེ་རྩལ། །དེང་དུས་གཏེར་ཆེན་པད་རྒྱལ་གླིང་པར་ཤར། །དེ་ལྟར་གོང་འོག་ཟབ་གཏེར་འཕྲོ་མཐུད་ | ||
ཕྱིར། །གོང་གི་བཀའ་བཞིན་ཆ་ཤས་འདིར་བཞུགས་གསོལ། །དེ་ལ་སྤྲུལ་པའི་གཏེར་ཆེན་རྩ་གསུམ་གླིང་པའི་ཟབ་གཏེར་མཐའ་སྐྱོང་བ་གཏེར་ཆེན་པདྨ་རྒྱལ་པོ་གར་དབང་འགྲོ་ | ||
འདུལ་རྩལ་འདི་ཉིད་ཡིན་ལ། དེས་ན་གཏེར་ཁ་གོང་མ་གནམ་ལྕགས་དང༌། ཕྱི་མ་སྐུ་གསུམ་དགོངས་འདུས་འདི་ཉིད་ཡིན་ཕྱིར་གོང་འོག་འཕྲོ་མི་ཆད་པའི་ཆེད་དུ་གནམ་ལྕགས་ |
22 changes: 22 additions & 0 deletions
22
tests/prepare/data/I46409446.opf/layers/I1PD108815/Pagination.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
id: 6cc17bb2bb8a41a586d506ead87d7ce7 | ||
annotation_type: Pagination | ||
revision: '00001' | ||
annotations: | ||
5cc9b1e74a7441e89d33100c956422a2: | ||
span: | ||
start: 0 | ||
end: 163 | ||
imgnum: 3 | ||
reference: I1PD1088150003.tif | ||
e6a42a5e463540d4876be4263ca656de: | ||
span: | ||
start: 165 | ||
end: 905 | ||
imgnum: 4 | ||
reference: I1PD1088150004.tif | ||
62e8c55cc3d74085a13f8dd165590093: | ||
span: | ||
start: 907 | ||
end: 1602 | ||
imgnum: 5 | ||
reference: I1PD1088150005.tif |
16 changes: 16 additions & 0 deletions
16
tests/prepare/data/I46409446.opf/layers/I1PD108816/Pagination.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
id: 9d07b7acefe543029e062e3098395bce | ||
annotation_type: Pagination | ||
revision: '00001' | ||
annotations: | ||
a870d803d8264254b8af5b8dc4c7bf53: | ||
span: | ||
start: 0 | ||
end: 192 | ||
imgnum: 3 | ||
reference: I1PD1088160003.tif | ||
d21a7d7373294f1ea75b09996df80d8e: | ||
span: | ||
start: 194 | ||
end: 937 | ||
imgnum: 4 | ||
reference: I1PD1088160004.tif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
id: I46409446 | ||
ocr_import_info: | ||
bdrc_scan_id: W4CZ1042 | ||
source: bdrc | ||
ocr_info: | ||
timestamp: '2023-02-01T00:00:00Z' | ||
batch_id: batch-0001 | ||
software_id: norbuketaka | ||
expected_default_language: bo | ||
op_import_options: null | ||
default_language: bo | ||
source: https://library.bdrc.io | ||
initial_creation_type: ocr | ||
imported: 2024-09-12 14:18:06.326672 | ||
last_modified: 2023-02-01 00:00:00+00:00 | ||
parser: https://github.com/OpenPecha/Norbu-Keta-eText-import/blob/main/norbu_ketaka_parser.py | ||
source_metadata: | ||
id: http://purl.bdrc.io/resource/W4CZ1042 | ||
status: http://purl.bdrc.io/admindata/StatusReleased | ||
access: http://purl.bdrc.io/admindata/AccessOpen | ||
geo_restriction: | ||
- CN | ||
outline: http://purl.bdrc.io/resource/O8LS1837 | ||
reproduction_of: http://purl.bdrc.io/resource/MW4CZ1042 | ||
copyright_status: http://purl.bdrc.io/resource/CopyrightPublicDomain | ||
title: གཏེར་ཆོས། རྩ་གསུམ་གླིང་པ། | ||
languages: | ||
- bo | ||
author: གནམ་ལྕགས་རྩ་གསུམ་གཏེར་བདག་གླིང་པ། | ||
bases: | ||
I1PD108815: | ||
source_metadata: | ||
id: http://purl.bdrc.io/resource/I1PD108815 | ||
total_pages: 687 | ||
volume_number: 27 | ||
volume_pages_bdrc_intro: 2 | ||
base_file: I1PD108815.txt | ||
order: 1 | ||
I1PD108816: | ||
source_metadata: | ||
id: http://purl.bdrc.io/resource/I1PD108816 | ||
total_pages: 665 | ||
volume_number: 28 | ||
volume_pages_bdrc_intro: 2 | ||
base_file: I1PD108816.txt | ||
order: 2 | ||
I1PD108817: | ||
source_metadata: | ||
id: http://purl.bdrc.io/resource/I1PD108817 | ||
total_pages: 324 | ||
volume_number: 29 | ||
volume_pages_bdrc_intro: 2 | ||
base_file: I1PD108817.txt | ||
order: 3 | ||
I1PD108818: | ||
source_metadata: | ||
id: http://purl.bdrc.io/resource/I1PD108818 | ||
total_pages: 764 | ||
volume_number: 30 | ||
volume_pages_bdrc_intro: 2 | ||
base_file: I1PD108818.txt | ||
order: 4 | ||
copyright: | ||
status: Public domain | ||
notice: The proofread texts are donated by the Norbu Ketaka project led by Queenie | ||
Luo (Harvard University), Zhiying Li (Sichuan University) and Leonard van der | ||
Kuijp (Harvard University). Correspondence should be directed to [email protected] | ||
license: CC0 |
Oops, something went wrong.