imvladikon
commited on
Commit
•
b535f28
1
Parent(s):
13934e6
changes
Browse files- obsolete.paranames.py +83 -0
obsolete.paranames.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
import csv
|
4 |
+
import os
|
5 |
+
from functools import partial
|
6 |
+
from typing import Dict, Iterable
|
7 |
+
|
8 |
+
import datasets
|
9 |
+
from datasets import DatasetDict, DownloadManager, load_dataset
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
VERSION = datasets.Version("0.0.1")
|
14 |
+
|
15 |
+
AVAILABLE_DATASETS = {
|
16 |
+
'paranames': "https://github.com/bltlab/paranames/releases/download/v2021.03.04.1/paranames.tsv.gz"
|
17 |
+
}
|
18 |
+
|
19 |
+
|
20 |
+
class ParanamesDataset(datasets.GeneratorBasedBuilder):
|
21 |
+
"""ParanamesDataset dataset."""
|
22 |
+
|
23 |
+
BUILDER_CONFIGS = [
|
24 |
+
datasets.BuilderConfig(
|
25 |
+
name=data_name, version=VERSION, description=f"{data_name} dataset"
|
26 |
+
)
|
27 |
+
for data_name in AVAILABLE_DATASETS
|
28 |
+
]
|
29 |
+
|
30 |
+
|
31 |
+
def _info(self) -> datasets.DatasetInfo:
|
32 |
+
return datasets.DatasetInfo(
|
33 |
+
description="",
|
34 |
+
features=datasets.Features(
|
35 |
+
{
|
36 |
+
"wikidata_id": datasets.Value("string"),
|
37 |
+
"name": datasets.Value("string"),
|
38 |
+
"name_origin": datasets.Value("string"),
|
39 |
+
"language": datasets.Value("string"),
|
40 |
+
"type": datasets.Value("string"),
|
41 |
+
}
|
42 |
+
),
|
43 |
+
supervised_keys=None,
|
44 |
+
homepage="https://github.com/bltlab/paranames",
|
45 |
+
citation="",
|
46 |
+
)
|
47 |
+
|
48 |
+
def _split_generators(
|
49 |
+
self, dl_manager: DownloadManager
|
50 |
+
) -> Iterable[datasets.SplitGenerator]:
|
51 |
+
downloader = partial(
|
52 |
+
lambda split: dl_manager.download_and_extract(
|
53 |
+
AVAILABLE_DATASETS[self.config.name]
|
54 |
+
)
|
55 |
+
)
|
56 |
+
filepath = downloader(AVAILABLE_DATASETS[self.config.name])
|
57 |
+
|
58 |
+
# There is no predefined train/val/test split for this dataset.
|
59 |
+
return [
|
60 |
+
datasets.SplitGenerator(
|
61 |
+
name=datasets.Split.TRAIN,
|
62 |
+
gen_kwargs={
|
63 |
+
"filepath": filepath,
|
64 |
+
},
|
65 |
+
),
|
66 |
+
]
|
67 |
+
|
68 |
+
def _generate_examples(self, filepath: str) -> Iterable[Dict]:
|
69 |
+
with open(filepath, encoding="utf-8") as f_in:
|
70 |
+
csv_reader = csv.reader(
|
71 |
+
f_in,
|
72 |
+
delimiter="\t",
|
73 |
+
)
|
74 |
+
for idx, row in enumerate(csv_reader):
|
75 |
+
if idx == 0:
|
76 |
+
continue
|
77 |
+
yield idx, {
|
78 |
+
"wikidata_id": row[0],
|
79 |
+
"name": row[1],
|
80 |
+
"name_origin": row[2],
|
81 |
+
"language": row[3],
|
82 |
+
"type": row[4],
|
83 |
+
}
|