martingrzzler
commited on
Commit
•
52ecf39
1
Parent(s):
23e84f9
Update kanjis2radicals.py
Browse files- kanjis2radicals.py +6 -4
kanjis2radicals.py
CHANGED
@@ -6,7 +6,7 @@ Contains Kanji images with corresponding radicals ids from WaniKani or https://a
|
|
6 |
"""
|
7 |
|
8 |
_METADATA_URL = "https://huggingface.co/datasets/martingrzzler/kanjis2radicals/raw/main/kanji_metadata.jsonl"
|
9 |
-
_IMAGES_URL = "https://huggingface.co/datasets/martingrzzler/kanjis2radicals/resolve/main/
|
10 |
|
11 |
|
12 |
class Kanji2Radicals(datasets.GeneratorBasedBuilder):
|
@@ -52,15 +52,17 @@ class Kanji2Radicals(datasets.GeneratorBasedBuilder):
|
|
52 |
]
|
53 |
|
54 |
def _generate_examples(self, metadata_path, images_iter):
|
55 |
-
|
|
|
56 |
with open(metadata_path, encoding="utf-8") as f:
|
57 |
for line in f:
|
58 |
metadata = json.loads(line)
|
59 |
-
|
60 |
|
61 |
for idx, (image_path, image) in enumerate(images_iter):
|
|
|
62 |
yield image_path, {
|
63 |
-
"meta":
|
64 |
"kanji_image": image.read(),
|
65 |
}
|
66 |
|
|
|
6 |
"""
|
7 |
|
8 |
_METADATA_URL = "https://huggingface.co/datasets/martingrzzler/kanjis2radicals/raw/main/kanji_metadata.jsonl"
|
9 |
+
_IMAGES_URL = "https://huggingface.co/datasets/martingrzzler/kanjis2radicals/resolve/main/kanjis.tar.gz"
|
10 |
|
11 |
|
12 |
class Kanji2Radicals(datasets.GeneratorBasedBuilder):
|
|
|
52 |
]
|
53 |
|
54 |
def _generate_examples(self, metadata_path, images_iter):
|
55 |
+
meta_kanjis = {}
|
56 |
+
|
57 |
with open(metadata_path, encoding="utf-8") as f:
|
58 |
for line in f:
|
59 |
metadata = json.loads(line)
|
60 |
+
meta_kanjis[metadata["id"]] = metadata
|
61 |
|
62 |
for idx, (image_path, image) in enumerate(images_iter):
|
63 |
+
characters = image_path.split("/")[-1].split(".")[0]
|
64 |
yield image_path, {
|
65 |
+
"meta": meta_kanjis[characters],
|
66 |
"kanji_image": image.read(),
|
67 |
}
|
68 |
|