|
import gzip |
|
import json |
|
import datasets |
|
|
|
_URLS = { |
|
"csl": "https://huggingface.co./datasets/neuclir/csl/resolve/main/data/csl.jsonl.gz", |
|
"en_translation": "https://huggingface.co./datasets/neuclir/csl/resolve/main/data/csl.gt.063023.jsonl.gz", |
|
} |
|
|
|
class Csl(datasets.GeneratorBasedBuilder): |
|
VERSION = datasets.Version("1.1.1") |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
features=datasets.Features({ |
|
"doc_id": datasets.Value("string"), |
|
"title": datasets.Value("string"), |
|
"abstract": datasets.Value("string"), |
|
"keywords": datasets.Sequence(feature=datasets.Value("string"), length=-1), |
|
"category": datasets.Value("string"), |
|
"category_eng": datasets.Value("string"), |
|
"discipline": datasets.Value("string"), |
|
"discipline_eng": datasets.Value("string"), |
|
}), |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
paths = dl_manager.download(_URLS) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=split, |
|
gen_kwargs={ |
|
"filepath": paths[split], |
|
}) |
|
for split in _URLS |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
with gzip.open(filepath) as f: |
|
for key, row in enumerate(f): |
|
data = json.loads(row) |
|
if "category_eng" not in data: |
|
data["category_eng"] = "" |
|
data["discipline_eng"] = "" |
|
yield key, data |
|
|