|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""Python build script for the ScandiWiki dataset.""" |
|
|
|
|
|
import json |
|
from pathlib import Path |
|
from typing import List |
|
|
|
import datasets |
|
from datasets import Version |
|
from datasets.builder import BuilderConfig, GeneratorBasedBuilder |
|
from datasets.download import DownloadManager |
|
from datasets.features import Features, Value |
|
from datasets.info import DatasetInfo |
|
from datasets.splits import SplitGenerator |
|
|
|
_DESCRIPTION = """ |
|
ScandiWiki is a parsed and deduplicated version of the Danish, Norwegian Bokmål, |
|
Norwegian Nynorsk, Swedish, Icelandic and Faroese Wikipedia corpora, as of January |
|
2023. |
|
""" |
|
|
|
_LICENSE = "CC BY-SA 4.0" |
|
_URLS = { |
|
"da": "https://huggingface.co/datasets/alexandrainst/scandi-wiki/resolve/main/data/da.jsonl", |
|
"sv": "https://huggingface.co/datasets/alexandrainst/scandi-wiki/resolve/main/data/sv.jsonl", |
|
"nb": "https://huggingface.co/datasets/alexandrainst/scandi-wiki/resolve/main/data/nb.jsonl", |
|
"nn": "https://huggingface.co/datasets/alexandrainst/scandi-wiki/resolve/main/data/nn.jsonl", |
|
"is": "https://huggingface.co/datasets/alexandrainst/scandi-wiki/resolve/main/data/is.jsonl", |
|
"fo": "https://huggingface.co/datasets/alexandrainst/scandi-wiki/resolve/main/data/fo.jsonl", |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ScandiWiki(GeneratorBasedBuilder): |
|
"""Scandinavian part of Wikipedia.""" |
|
|
|
VERSION = Version("1.0.0") |
|
|
|
BUILDER_CONFIGS = [ |
|
BuilderConfig( |
|
name="da", |
|
version=VERSION, |
|
description="The deduplicated Danish part of Wikipedia.", |
|
), |
|
BuilderConfig( |
|
name="sv", |
|
version=VERSION, |
|
description="The deduplicated Swedish part of Wikipedia.", |
|
), |
|
BuilderConfig( |
|
name="nb", |
|
version=VERSION, |
|
description="The deduplicated Norwegian Bokmål part of Wikipedia.", |
|
), |
|
BuilderConfig( |
|
name="nn", |
|
version=VERSION, |
|
description="The deduplicated Norwegian Nynorsk part of Wikipedia.", |
|
), |
|
BuilderConfig( |
|
name="is", |
|
version=VERSION, |
|
description="The deduplicated Icelandic part of Wikipedia.", |
|
), |
|
BuilderConfig( |
|
name="fo", |
|
version=VERSION, |
|
description="The deduplicated Faroese part of Wikipedia.", |
|
), |
|
] |
|
|
|
def _info(self) -> DatasetInfo: |
|
features = Features( |
|
{ |
|
"id": Value("string"), |
|
"url": Value("string"), |
|
"title": Value("string"), |
|
"text": Value("string"), |
|
} |
|
) |
|
return DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
|
|
license=_LICENSE, |
|
|
|
) |
|
|
|
def _split_generators(self, dl_manager: DownloadManager) -> List[SplitGenerator]: |
|
url = _URLS[self.config.name] |
|
downloaded_file = dl_manager.download(url) |
|
return [ |
|
SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs=dict( |
|
filepath=downloaded_file, |
|
split="train", |
|
), |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath: str, split): |
|
with Path(filepath).open(encoding="utf-8") as f: |
|
for key, row in enumerate(f): |
|
data = json.loads(row) |
|
yield key, data |
|
|