Upload lefff_morpho.py
Browse files- lefff_morpho.py +126 -0
lefff_morpho.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
# TODO: Address all TODOs and remove all explanatory comments
|
| 15 |
+
"""TODO: Add a description here."""
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
import csv
|
| 19 |
+
import json
|
| 20 |
+
import os
|
| 21 |
+
|
| 22 |
+
import datasets
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# TODO: Add BibTeX citation
|
| 26 |
+
# Find for instance the citation on arxiv or on the dataset repo/website
|
| 27 |
+
_CITATION = """\
|
| 28 |
+
@inproceedings{sagot:inria-00521242,
|
| 29 |
+
TITLE = {{The Lefff, a freely available and large-coverage morphological and syntactic lexicon for French}},
|
| 30 |
+
AUTHOR = {Sagot, Beno{\^i}t},
|
| 31 |
+
URL = {https://hal.inria.fr/inria-00521242},
|
| 32 |
+
BOOKTITLE = {{7th international conference on Language Resources and Evaluation (LREC 2010)}},
|
| 33 |
+
ADDRESS = {Valletta, Malta},
|
| 34 |
+
YEAR = {2010},
|
| 35 |
+
MONTH = May,
|
| 36 |
+
PDF = {https://hal.inria.fr/inria-00521242/file/lrec10lefff.pdf},
|
| 37 |
+
HAL_ID = {inria-00521242},
|
| 38 |
+
HAL_VERSION = {v1},
|
| 39 |
+
}"""
|
| 40 |
+
|
| 41 |
+
# TODO: Add description of the dataset here
|
| 42 |
+
# You can copy an official description
|
| 43 |
+
_DESCRIPTION = """\
|
| 44 |
+
The lefff-morpho dataset gives access to the morphological information, in both its original format and the UniMorph format.
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
# TODO: Add a link to an official homepage for the dataset here
|
| 48 |
+
_HOMEPAGE = "http://almanach.inria.fr/software_and_resources/custom/Alexina-en.html"
|
| 49 |
+
|
| 50 |
+
# TODO: Add the licence for the dataset here if you can find it
|
| 51 |
+
_LICENSE = "LGPL-LR"
|
| 52 |
+
|
| 53 |
+
# TODO: Add link to the official dataset URLs here
|
| 54 |
+
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
| 55 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
| 56 |
+
_URLS = {
|
| 57 |
+
"all": "lefff_morpho.json",
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
| 62 |
+
class LefffMorpho(datasets.GeneratorBasedBuilder):
|
| 63 |
+
"""The lefff-morpho dataset gives access to the morphological information, in both its original format and the UniMorph format."""
|
| 64 |
+
|
| 65 |
+
VERSION = datasets.Version("3.5.0")
|
| 66 |
+
|
| 67 |
+
# This is an example of a dataset with multiple configurations.
|
| 68 |
+
# If you don't want/need to define several sub-sets in your dataset,
|
| 69 |
+
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
| 70 |
+
|
| 71 |
+
# If you need to make complex sub-parts in the datasets with configurable options
|
| 72 |
+
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
| 73 |
+
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
| 74 |
+
|
| 75 |
+
# You will be able to load one or the other configurations in the following list with
|
| 76 |
+
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
| 77 |
+
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
| 78 |
+
|
| 79 |
+
DEFAULT_CONFIG_NAME = "all" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
| 80 |
+
|
| 81 |
+
def _info(self):
|
| 82 |
+
# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
| 83 |
+
features = datasets.Features({
|
| 84 |
+
"form": datasets.Value("string"),
|
| 85 |
+
"lemma": datasets.Value("string"),
|
| 86 |
+
"category": datasets.Value("string")
|
| 87 |
+
"type": datasets.Value("string")
|
| 88 |
+
"msfeatures": datasets.Value("string")
|
| 89 |
+
"unimorph": datasets.Value("string")
|
| 90 |
+
"expansion": datasets.Value("string")
|
| 91 |
+
})
|
| 92 |
+
return datasets.DatasetInfo(
|
| 93 |
+
# This is the description that will appear on the datasets page.
|
| 94 |
+
description=_DESCRIPTION,
|
| 95 |
+
# This defines the different columns of the dataset and their types
|
| 96 |
+
features=features, # Here we define them above because they are different between the two configurations
|
| 97 |
+
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
| 98 |
+
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
| 99 |
+
# supervised_keys=("sentence", "label"),
|
| 100 |
+
# Homepage of the dataset for documentation
|
| 101 |
+
homepage=_HOMEPAGE,
|
| 102 |
+
# License for the dataset if available
|
| 103 |
+
license=_LICENSE,
|
| 104 |
+
# Citation for the dataset
|
| 105 |
+
citation=_CITATION,
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
def _split_generators(self, dl_manager):
|
| 109 |
+
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
| 110 |
+
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
| 111 |
+
|
| 112 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
| 113 |
+
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
|
| 114 |
+
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
| 115 |
+
urls = _URLS[self.config.name]
|
| 116 |
+
data_dir = dl_manager.download_and_extract(urls)
|
| 117 |
+
return [datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={'filepath': downloaded_files['test']})]
|
| 118 |
+
|
| 119 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
| 120 |
+
def _generate_examples(self, filepath, split):
|
| 121 |
+
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
| 122 |
+
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
| 123 |
+
with open(filepath, encoding="utf-8") as f:
|
| 124 |
+
lefff_morpho = json.load(f)
|
| 125 |
+
for key, row in enumerate(lefff_morpho):
|
| 126 |
+
yield key, row
|