File size: 6,784 Bytes
ea3a10e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73d6df6
 
2220b47
ea3a10e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73d6df6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea3a10e
 
 
 
 
 
 
 
 
 
a9ee0d0
ea3a10e
 
 
 
67bd7ad
ea3a10e
67bd7ad
ea3a10e
 
 
 
 
73d6df6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea3a10e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# 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.
"""macocu_parallel"""


import os
import csv
import datasets


_CITATION = """\
@inproceedings{banon2022macocu,
  title={MaCoCu: Massive collection and curation of monolingual and bilingual data: focus on under-resourced languages},
  author={Ban{\'o}n, Marta and Espla-Gomis, Miquel and Forcada, Mikel L and Garc{\'\i}a-Romero, Cristian and Kuzman, Taja and Ljube{\v{s}}i{\'c}, Nikola and van Noord, Rik and Sempere, Leopoldo Pla and Ram{\'\i}rez-S{\'a}nchez, Gema and Rupnik, Peter and others},
  booktitle={23rd Annual Conference of the European Association for Machine Translation, EAMT 2022},
  pages={303--304},
  year={2022},
  organization={European Association for Machine Translation}
}
"""

_DESCRIPTION = """\
The MaCoCu parallel dataset is an English-centric collection of 11
parallel corpora including the following languages: Albanian,
Bulgarian, Bosnian, Croatian, Icelandic, Macedonian, Maltese,
Montenegrin, Serbian, Slovenian, and Turkish. These corpora have
been automatically crawled from national and generic top-level
domains (for example, ".hr" for croatian, or ".is" for icelandic);
then, a parallel curation pipeline has been applied to produce
the final data (see https://github.com/bitextor/bitextor).
"""

_LanguagePairs = [ "en-is" ]
#_LanguagePairs = [ "en-bg", "en-is", "en-sq", "en-mt", "en-mk", "en-sl", "en-tr" ]
#_LanguagePairs = [ "en-bs", "en-bg", "en-is", "en-hr", "en-sq", "en-mt", "en-mk", "en-cnr", "en-sr", "en-sl", "en-tr" ]

_LICENSE = "cc0"
_HOMEPAGE = "https://macocu.eu"

class macocuConfig(datasets.BuilderConfig):
    """BuilderConfig for macocu_parallel"""

    def __init__(self, language_pair, **kwargs):
        super().__init__(**kwargs)
        """

        Args:
            language_pair: language pair to be loaded
            **kwargs: keyword arguments forwarded to super.
        """
        self.language_pair = language_pair


class MaCoCu_parallel(datasets.GeneratorBasedBuilder):
    VERSION = datasets.Version("1.0.0")

    BUILDER_CONFIG_CLASS = macocuConfig
    BUILDER_CONFIGS = [
        macocuConfig(name=pair, description=_DESCRIPTION, language_pair=pair )
        for pair in _LanguagePairs
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features({
                "src_url": datasets.Value("string"),
                "trg_url": datasets.Value("string"),
                "src_text": datasets.Value("string"),
                "trg_text": datasets.Value("string"),
                "bleualign_score": datasets.Value("string"),
                "src_deferred_hash": datasets.Value("string"),
                "trg_deferred_hash": datasets.Value("string"),
                "src_paragraph_id": datasets.Value("string"),
                "trg_paragraph_id": datasets.Value("string"),
                "src_doc_title": datasets.Value("string"),
                "trg_doc_title": datasets.Value("string"),
                "src_crawl_date": datasets.Value("string"),
                "trg_crawl_date": datasets.Value("string"),
                "src_file_type": datasets.Value("string"),
                "trg_file_type": datasets.Value("string"),
                "src_boilerplate": datasets.Value("string"),
                "trg_boilerplate": datasets.Value("string"),
                "src_heading_html_tag": datasets.Value("string"),
                "trg_heading_html_tag": datasets.Value("string"),
                "bifixer_hash": datasets.Value("string"),
                "bifixer_score": datasets.Value("string"),
                "bicleaner_ai_score": datasets.Value("string"),
                "biroamer_entities_detected": datasets.Value("string"),
                "dsi": datasets.Value("string"),
                "translation_direction": datasets.Value("string"),
                "en_document_level_variant": datasets.Value("string"),
                "domain_en": datasets.Value("string"),
                "en_domain_level_variant": datasets.Value("string")
            }),
            homepage=_HOMEPAGE,
            citation=_CITATION,
            license=_LICENSE
        )

    def _split_generators(self, dl_manager):

        lang_pair = self.config.language_pair
        
        path = os.path.join("data", f"{lang_pair}.tsv")
        
        data_file = dl_manager.download_and_extract({"data_file": path})
        return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs=data_file)]

    def _generate_examples(self, data_file):
        """Yields examples."""
        with open(data_file, encoding="utf-8") as f:
            reader = csv.reader(f, delimiter="\t", quotechar='"')
            for id_, row in enumerate(reader):
                if id_ == 0:
                    continue
                yield id_, {
                    "src_url": row[0],
                    "trg_url": row[1],
                    "src_text": row[2],
                    "trg_text": row[3],
                    "bleualign_score": row[4],
                    "src_deferred_hash": row[5],
                    "trg_deferred_hash": row[6],
                    "src_paragraph_id": row[7],
                    "trg_paragraph_id": row[8],
                    "src_doc_title": row[9],
                    "trg_doc_title": row[10],
                    "src_crawl_date": row[11],
                    "trg_crawl_date": row[12],
                    "src_file_type": row[13],
                    "trg_file_type": row[14],
                    "src_boilerplate": row[15],
                    "trg_boilerplate": row[16],
                    "src_heading_html_tag": row[17],
                    "trg_heading_html_tag": row[18],
                    "bifixer_hash": row[19],
                    "bifixer_score": row[20],
                    "bicleaner_ai_score": row[21],
                    "biroamer_entities_detected": row[22],
                    "dsi": row[23],
                    "translation_direction": row[24],
                    "en_document_level_variant": row[25],
                    "domain_en": row[26],
                    "en_domain_level_variant": row[27]
                }