scandi-wiki / scandi_wiki.py
saattrupdan's picture
feat: Add data, script and readme
0c3c2dd
raw
history blame
4.25 kB
# Copyright 2022 The HuggingFace Datasets Authors and Dan Saattrup Nielsen.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""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",
}
# _CITATION = """
# @InProceedings{huggingface:dataset,
# title = {ScandiWiki: A Scandinavian Wikipedia Dump},
# author={Dan Saattrup Nielsen},
# year={2022}
# }
# """
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,
# homepage=_HOMEPAGE,
license=_LICENSE,
# citation=_CITATION,
)
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