|
import json |
|
from string import Template |
|
|
|
import datasets |
|
|
|
_CITATION = "" |
|
_DESCRIPTION = \ |
|
""" |
|
A collection of passages culled from news websites for Cross-Lingual Information Retrieval for African Languages. |
|
""" |
|
_HOMEPAGE = "https://github.com/ciral/ciral-corpus" |
|
_LICENSE = "Apache License 2.0" |
|
_VERSION = "1.0.0" |
|
_LANGUAGES = [ |
|
"hausa", |
|
"somali", |
|
"swahili", |
|
"yoruba", |
|
"combined" |
|
] |
|
_DATASET_URL = Template("./passages-v1.0/${language}_passages.jsonl") |
|
|
|
|
|
class CiralPassages(datasets.GeneratorBasedBuilder): |
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
version=datasets.Version(_VERSION), |
|
name=language, |
|
description=f"CIRAL passages for language: {language}" |
|
) for language in _LANGUAGES |
|
] |
|
DEFAULT_CONFIG_NAME = "combined" |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
citation=_CITATION, |
|
features=datasets.Features({ |
|
"docid": datasets.Value("string"), |
|
"title": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
"url": datasets.Value("string") |
|
}), |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE |
|
) |
|
|
|
def _split_generators(self, dl_manager: datasets.DownloadManager): |
|
language = self.config.name |
|
if language == "combined": |
|
language_file = dl_manager.download_and_extract({ |
|
_language: _DATASET_URL.substitute(language=_language) |
|
for _language in _LANGUAGES[:-1] |
|
}) |
|
|
|
splits = [ |
|
datasets.SplitGenerator( |
|
name=_language, gen_kwargs={"filepath": language_file[_language]} |
|
) for _language in _LANGUAGES[:-1] |
|
] |
|
return splits |
|
else: |
|
language_file = dl_manager.download_and_extract( |
|
_DATASET_URL.substitute(language=language)) |
|
|
|
splits = [ |
|
datasets.SplitGenerator( |
|
name="train", |
|
gen_kwargs={"filepath": language_file} |
|
) |
|
] |
|
return splits |
|
|
|
def _generate_examples(self, filepath: str): |
|
with open(filepath, encoding="utf-8") as f: |
|
for line in f: |
|
data = json.loads(line) |
|
yield data["docid"], data |
|
|