|
import json |
|
import os |
|
from pathlib import Path |
|
|
|
import datasets |
|
|
|
_DESCRIPTION = """\ |
|
General Corpora for the Maltese language. |
|
""" |
|
|
|
_CITATION = """\ |
|
@inproceedings{BERTu, |
|
title = "Pre-training Data Quality and Quantity for a Low-Resource Language: New Corpus and {BERT} Models for {M}altese", |
|
author = "Micallef, Kurt and |
|
Gatt, Albert and |
|
Tanti, Marc and |
|
van der Plas, Lonneke and |
|
Borg, Claudia", |
|
booktitle = "Proceedings of the Third Workshop on Deep Learning for Low-Resource Natural Language Processing", |
|
month = jul, |
|
year = "2022", |
|
address = "Hybrid", |
|
publisher = "Association for Computational Linguistics", |
|
url = "https://aclanthology.org/2022.deeplo-1.10", |
|
doi = "10.18653/v1/2022.deeplo-1.10", |
|
pages = "90--101", |
|
} |
|
""" |
|
|
|
_HOMEPAGE = "https://mlrs.research.um.edu.mt/" |
|
|
|
_LICENSE = "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (CC BY-NC-SA 4.0)" |
|
|
|
_URL = "data/" |
|
_SHUFFLED_URL = { |
|
"train": os.path.join(_URL, "shuffled/train.txt"), |
|
"validation": os.path.join(_URL, "shuffled/validation.txt"), |
|
"test": os.path.join(_URL, "shuffled/test.txt"), |
|
} |
|
_SUBSET_URL_PATTERN = "{}/**/*.jsonl" |
|
|
|
|
|
class KorpusMalti(datasets.GeneratorBasedBuilder): |
|
"""Korpus Malti: General Corpora for the Maltese Language""" |
|
|
|
VERSION = datasets.Version("4.0.0") |
|
|
|
DEFAULT_CONFIG_NAME = "shuffled" |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name=DEFAULT_CONFIG_NAME, |
|
version=VERSION, |
|
description="The shuffled data from all subsets.", |
|
), |
|
datasets.BuilderConfig(name="belles_lettres", |
|
version=VERSION, |
|
description="Literary texts, usually published and included in the corpus by permission of the copyright holder. Unfortunately these cannot be disseminated in their integral form.", |
|
), |
|
datasets.BuilderConfig(name="blogs", |
|
version=VERSION, |
|
description="Online blog articles from specific blogs, identified in advance and known to contain text written (or human-translated into) Maltese.", |
|
), |
|
datasets.BuilderConfig(name="comics", |
|
version=VERSION, |
|
description="A small set of online information about comic books in Maltese.", |
|
), |
|
datasets.BuilderConfig(name="court", |
|
version=VERSION, |
|
description="Publicly available proceedings form the courts of Malta.", |
|
), |
|
datasets.BuilderConfig(name="eu_docs", |
|
version=VERSION, |
|
description="Miscellaneous policy documents from the European Union institutions.", |
|
), |
|
datasets.BuilderConfig(name="gov_docs", |
|
version=VERSION, |
|
description="Miscellaneous policy documents from the Government of Malta.", |
|
), |
|
datasets.BuilderConfig(name="government_gazzette", |
|
version=VERSION, |
|
description="The official, publicly available gazette of the Government of Malta. The gazzette is bilingual; only the Maltese text is included.", |
|
), |
|
datasets.BuilderConfig(name="law_eu", |
|
version=VERSION, |
|
description="Miscellaneous EU laws in their official Maltese translation, obtained via the Eur-Lex repository and including the segments of the Acquis Communautaire available in the DGT translation memory.", |
|
), |
|
datasets.BuilderConfig(name="law_mt", |
|
version=VERSION, |
|
description="Maltese laws.", |
|
), |
|
datasets.BuilderConfig(name="legal", |
|
version=VERSION, |
|
description="Miscellaneous legal text.", |
|
), |
|
datasets.BuilderConfig(name="nonfiction", |
|
version=VERSION, |
|
description="Miscellaneous nonfiction, published or unpublished. Published texts are included with the permission of the copyright holder, where relevant.", |
|
), |
|
datasets.BuilderConfig(name="parliament", |
|
version=VERSION, |
|
description="The officially released transcripts of parliamentary debates of the Maltese parliament.", |
|
), |
|
datasets.BuilderConfig(name="press_eu", |
|
version=VERSION, |
|
description="Press releases in Maltese by the European Council of Ministers, European Parliament and European Commission.", |
|
), |
|
datasets.BuilderConfig(name="press_mt", |
|
version=VERSION, |
|
description="Articles in the Maltese press, sourced primarily from the online portals of Maltese newspapers.", |
|
), |
|
datasets.BuilderConfig(name="speeches", |
|
version=VERSION, |
|
description="Miscellaneous speeches in Maltese (pre-written).", |
|
), |
|
datasets.BuilderConfig(name="theses", |
|
version=VERSION, |
|
description="Academic dissertations written in Maltese.", |
|
), |
|
datasets.BuilderConfig(name="umlib_oar", |
|
version=VERSION, |
|
description="Very broad variety of nonfiction texts which are publicly available in the University of Malta Open Access Repository. Included with help and permission from the University of Malta library.", |
|
), |
|
datasets.BuilderConfig(name="web_general", |
|
version=VERSION, |
|
description="Miscellaneous text scraped from pre-identified web pages in Maltese.", |
|
), |
|
datasets.BuilderConfig(name="wiki", |
|
version=VERSION, |
|
description="The Maltese Wikipedia dump (downloaded 26th May, 2020).", |
|
), |
|
] |
|
|
|
def _info(self): |
|
if self.config.name == self.DEFAULT_CONFIG_NAME: |
|
features = { |
|
"text": datasets.Value("string"), |
|
} |
|
else: |
|
features = { |
|
"text": datasets.Sequence(datasets.Value("string")), |
|
} |
|
|
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features(features), |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
license=_LICENSE, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
if self.config.name == self.DEFAULT_CONFIG_NAME: |
|
data_files = dl_manager.download_and_extract(_SHUFFLED_URL) |
|
data_split = [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"filepath": data_files["train"], |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={ |
|
"filepath": data_files["validation"], |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"filepath": data_files["test"], |
|
}, |
|
), |
|
] |
|
else: |
|
file_pattern = _SUBSET_URL_PATTERN.format(self.config.name) |
|
base_path = self.base_path or "" |
|
file_paths = [path.relative_to(base_path) |
|
for path in Path(os.path.join(base_path, _URL)).glob(file_pattern)] |
|
|
|
data_files = dl_manager.download_and_extract(file_paths) |
|
data_split = [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"filepath": data_files, |
|
}, |
|
), |
|
] |
|
|
|
return data_split |
|
|
|
def _generate_examples(self, filepath): |
|
if self.config.name == self.DEFAULT_CONFIG_NAME: |
|
with open(filepath, encoding="utf-8") as file: |
|
for key, line in enumerate(file): |
|
if len(line) > 0: |
|
yield key, { |
|
"text": line, |
|
} |
|
else: |
|
key = 0 |
|
for path in filepath: |
|
with open(path, encoding="utf-8") as file: |
|
for line in file: |
|
data = json.loads(line) |
|
yield key, { |
|
"text": data["text"], |
|
} |
|
key += 1 |
|
|