martingrzzler
commited on
Commit
•
877fc86
1
Parent(s):
9b9a970
Update radicals.py
Browse files- radicals.py +5 -3
radicals.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import datasets
|
2 |
import json
|
|
|
3 |
|
4 |
_DESCRIPTION = """\
|
5 |
Contains radical images with radicals ids from WaniKani or https://api.robanohashi.org/docs/index.html
|
@@ -46,15 +47,16 @@ class Radicals(datasets.GeneratorBasedBuilder):
|
|
46 |
|
47 |
def _generate_examples(self, metadata_path, images_iter):
|
48 |
radicals = {}
|
|
|
49 |
with open(metadata_path, encoding="utf-8") as f:
|
50 |
for line in f:
|
51 |
metadata = json.loads(line)
|
52 |
radicals[metadata["id"]] = metadata
|
53 |
|
54 |
for idx, (image_path, image) in enumerate(images_iter):
|
55 |
-
|
56 |
-
id = int(image_path.split("/")[0])
|
57 |
yield image_path, {
|
58 |
"meta": radicals[id],
|
59 |
"radical_image": image.read(),
|
60 |
-
}
|
|
|
|
1 |
import datasets
|
2 |
import json
|
3 |
+
import re
|
4 |
|
5 |
_DESCRIPTION = """\
|
6 |
Contains radical images with radicals ids from WaniKani or https://api.robanohashi.org/docs/index.html
|
|
|
47 |
|
48 |
def _generate_examples(self, metadata_path, images_iter):
|
49 |
radicals = {}
|
50 |
+
pattern = r"/(\d+)"
|
51 |
with open(metadata_path, encoding="utf-8") as f:
|
52 |
for line in f:
|
53 |
metadata = json.loads(line)
|
54 |
radicals[metadata["id"]] = metadata
|
55 |
|
56 |
for idx, (image_path, image) in enumerate(images_iter):
|
57 |
+
id = int(re.search(pattern, image_path).group(1))
|
|
|
58 |
yield image_path, {
|
59 |
"meta": radicals[id],
|
60 |
"radical_image": image.read(),
|
61 |
+
}
|
62 |
+
|