|
|
|
import csv |
|
import json |
|
import os |
|
from typing import List |
|
import datasets |
|
|
|
|
|
_DESCRIPTION = """\ |
|
Icelandic GEC corpus. |
|
|
|
The Icelandic Error Corpus (IceEC) is a collection of texts in modern Icelandic annotated for mistakes related to spelling, grammar, and other issues. The texts are organized by genre, if which there are three: student essays, online news texts and Icelandic Wikipedia articles. Each mistake is marked according to error type using an error code, of which there are 253. The corpus consists of 4,046 texts with 56,956 categorized error instances. The corpus is divided into a development corpus, which comprises 90% of the corpus, and a test corpus, which comprises the other 10% of the corpus. |
|
""" |
|
|
|
_HOMEPAGE = "https://repository.clarin.is/repository/xmlui/handle/20.500.12537/105" |
|
|
|
_CITATION = """ |
|
@misc{20.500.12537/105, |
|
title = {Icelandic Error Corpus ({IceEC}) Version 1.1}, |
|
author = {Ingason, Anton Karl and Stef{\'a}nsd{\'o}ttir, Lilja Bj{\"o}rk and Arnard{\'o}ttir, {\TH}{\'o}runn and Xu, Xindan}, |
|
url = {http://hdl.handle.net/20.500.12537/105}, |
|
note = {{CLARIN}-{IS}}, |
|
copyright = {Creative Commons - Attribution 4.0 International ({CC} {BY} 4.0)}, |
|
year = {2021} } |
|
""" |
|
|
|
_LICENSE = "CC BY 4.0" |
|
|
|
_URLS = { |
|
"train": "train.tsv", |
|
"dev": "valid.tsv", |
|
"test": "test.tsv", |
|
|
|
} |
|
|
|
class iceErrorCorpus(datasets.GeneratorBasedBuilder): |
|
"""TODO: Short description of my dataset.""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name="iceErrorCorpus", version=VERSION, description="Icelandic GEC corpus" |
|
), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "iceErrorCorpus" |
|
|
|
def _info(self): |
|
if self.config.name == "iceErrorCorpus": |
|
features = datasets.Features( |
|
{ |
|
"src": datasets.Value("string"), |
|
"tgt": datasets.Value("string"), |
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
supervised_keys=None, |
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
data_dir = dl_manager.download_and_extract(_URLS) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": data_dir["train"], |
|
"split": "train", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": data_dir["test"], |
|
"split": "test" |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"filepath": data_dir["dev"], |
|
"split": "dev", |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples( |
|
self, filepath, split |
|
): |
|
""" Yields examples as (key, example) tuples. """ |
|
|
|
|
|
|
|
with open(filepath, encoding="utf-8") as f: |
|
key = 0 |
|
tsv_f = csv.reader(f, delimiter="\t", quoting=csv.QUOTE_NONE) |
|
for row in tsv_f: |
|
if self.config.name == "iceErrorCorpus": |
|
yield key, { |
|
"src": row[0], |
|
"tgt": row[1], |
|
} |
|
key += 1 |
|
|