Datasets:
Tasks:
Translation
Multilinguality:
translation
Size Categories:
1M<n<10M
Language Creators:
found
Annotations Creators:
found
Source Datasets:
original
Tags:
License:
Commit
•
8182d28
1
Parent(s):
7d7bc1d
Delete loading script
Browse files- opus_finlex.py +0 -92
opus_finlex.py
DELETED
@@ -1,92 +0,0 @@
|
|
1 |
-
# coding=utf-8
|
2 |
-
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
3 |
-
#
|
4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
-
# you may not use this file except in compliance with the License.
|
6 |
-
# You may obtain a copy of the License at
|
7 |
-
#
|
8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
-
#
|
10 |
-
# Unless required by applicable law or agreed to in writing, software
|
11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
-
# See the License for the specific language governing permissions and
|
14 |
-
# limitations under the License.
|
15 |
-
|
16 |
-
|
17 |
-
import os
|
18 |
-
|
19 |
-
import datasets
|
20 |
-
|
21 |
-
|
22 |
-
_CITATION = """\
|
23 |
-
J. Tiedemann, 2012, Parallel Data, Tools and Interfaces in OPUS. In Proceedings of the \
|
24 |
-
8th International Conference on Language Resources and Evaluation (LREC 2012)"""
|
25 |
-
|
26 |
-
|
27 |
-
_DESCRIPTION = """\
|
28 |
-
The Finlex Data Base is a comprehensive collection of legislative and other judicial information of Finland, \
|
29 |
-
which is available in Finnish, Swedish and partially in English. This corpus is taken from the Semantic Finlex serice \
|
30 |
-
that provides the Finnish and Swedish data as linked open data and also raw XML files."""
|
31 |
-
|
32 |
-
|
33 |
-
_HOMEPAGE = "http://opus.nlpl.eu/Finlex.php"
|
34 |
-
|
35 |
-
|
36 |
-
_LICENSE = ""
|
37 |
-
|
38 |
-
|
39 |
-
_URLs = {"train": "https://object.pouta.csc.fi/OPUS-Finlex/v2018/moses/fi-sv.txt.zip"}
|
40 |
-
|
41 |
-
|
42 |
-
class OpusFinlex(datasets.GeneratorBasedBuilder):
|
43 |
-
"""TODO: Short description of my dataset."""
|
44 |
-
|
45 |
-
VERSION = datasets.Version("1.0.0")
|
46 |
-
|
47 |
-
BUILDER_CONFIGS = [datasets.BuilderConfig(name="fi-sv", version=VERSION)]
|
48 |
-
|
49 |
-
def _info(self):
|
50 |
-
return datasets.DatasetInfo(
|
51 |
-
description=_DESCRIPTION,
|
52 |
-
features=datasets.Features(
|
53 |
-
{"translation": datasets.features.Translation(languages=tuple(self.config.name.split("-")))}
|
54 |
-
),
|
55 |
-
supervised_keys=None,
|
56 |
-
homepage="http://opus.nlpl.eu/Finlex.php",
|
57 |
-
citation=_CITATION,
|
58 |
-
)
|
59 |
-
|
60 |
-
def _split_generators(self, dl_manager):
|
61 |
-
"""Returns SplitGenerators."""
|
62 |
-
data_dir = dl_manager.download_and_extract(_URLs)
|
63 |
-
return [
|
64 |
-
datasets.SplitGenerator(
|
65 |
-
name=datasets.Split.TRAIN,
|
66 |
-
# These kwargs will be passed to _generate_examples
|
67 |
-
gen_kwargs={
|
68 |
-
"source_file": os.path.join(data_dir["train"], "Finlex.fi-sv.fi"),
|
69 |
-
"target_file": os.path.join(data_dir["train"], "Finlex.fi-sv.sv"),
|
70 |
-
"split": "train",
|
71 |
-
},
|
72 |
-
),
|
73 |
-
]
|
74 |
-
|
75 |
-
def _generate_examples(self, source_file, target_file, split):
|
76 |
-
"""This function returns the examples in the raw (text) form."""
|
77 |
-
with open(source_file, encoding="utf-8") as f:
|
78 |
-
source_sentences = f.read().split("\n")
|
79 |
-
with open(target_file, encoding="utf-8") as f:
|
80 |
-
target_sentences = f.read().split("\n")
|
81 |
-
|
82 |
-
assert len(target_sentences) == len(source_sentences), "Sizes do not match: %d vs %d for %s vs %s." % (
|
83 |
-
len(source_sentences),
|
84 |
-
len(target_sentences),
|
85 |
-
source_file,
|
86 |
-
target_file,
|
87 |
-
)
|
88 |
-
|
89 |
-
source, target = tuple(self.config.name.split("-"))
|
90 |
-
for idx, (l1, l2) in enumerate(zip(source_sentences, target_sentences)):
|
91 |
-
result = {"translation": {source: l1, target: l2}}
|
92 |
-
yield idx, result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|