Delete querie.py
Browse files
querie.py
DELETED
@@ -1,119 +0,0 @@
|
|
1 |
-
import csv
|
2 |
-
import json
|
3 |
-
import lzma
|
4 |
-
import os
|
5 |
-
|
6 |
-
import datasets
|
7 |
-
try:
|
8 |
-
import lzma as xz
|
9 |
-
except ImportError:
|
10 |
-
import pylzma as xz
|
11 |
-
|
12 |
-
|
13 |
-
# TODO: Add BibTeX citation
|
14 |
-
# Find for instance the citation on arxiv or on the dataset repo/website
|
15 |
-
_CITATION = """\
|
16 |
-
@InProceedings{huggingface:dataset,
|
17 |
-
title = {A great new dataset},
|
18 |
-
author={huggingface, Inc.
|
19 |
-
},
|
20 |
-
year={2020}
|
21 |
-
}
|
22 |
-
"""
|
23 |
-
|
24 |
-
# You can copy an official description
|
25 |
-
_DESCRIPTION = """TODO"""
|
26 |
-
|
27 |
-
# TODO: Add a link to an official homepage for the dataset here
|
28 |
-
_HOMEPAGE = ""
|
29 |
-
|
30 |
-
# TODO: Add the licence for the dataset here if you can find it
|
31 |
-
_LICENSE = ""
|
32 |
-
|
33 |
-
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
34 |
-
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
35 |
-
_URLS = {
|
36 |
-
"german": "https://huggingface.co/datasets/Stern5497/querie/resolve/main/queries_de.jsonl",
|
37 |
-
"italian": "https://huggingface.co/datasets/Stern5497/querie/resolve/main/queries_it.jsonl",
|
38 |
-
"french": "https://huggingface.co/datasets/Stern5497/querie/resolve/main/queries_fr.jsonl",
|
39 |
-
|
40 |
-
}
|
41 |
-
|
42 |
-
def get_url(config_name):
|
43 |
-
return _URLS[config_name]
|
44 |
-
|
45 |
-
|
46 |
-
class querie(datasets.GeneratorBasedBuilder):
|
47 |
-
"""This dataset contains court decision for law area prediction task."""
|
48 |
-
|
49 |
-
VERSION = datasets.Version("1.1.0")
|
50 |
-
|
51 |
-
BUILDER_CONFIGS = [
|
52 |
-
datasets.BuilderConfig(name="german", version=VERSION, description="This part of my dataset covers the whole dataset"),
|
53 |
-
datasets.BuilderConfig(name="italian", version=VERSION, description="This dataset is for predicting the sub law areas of the public law"),
|
54 |
-
datasets.BuilderConfig(name="french", version=VERSION, description="This dataset is for predicting the sub law areas of the civil law"),
|
55 |
-
]
|
56 |
-
|
57 |
-
DEFAULT_CONFIG_NAME = "german" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
58 |
-
|
59 |
-
def _info(self):
|
60 |
-
features = datasets.Features(
|
61 |
-
{
|
62 |
-
"id": datasets.Value("string")
|
63 |
-
# These are the features of your dataset like images, labels ...
|
64 |
-
}
|
65 |
-
)
|
66 |
-
return datasets.DatasetInfo(
|
67 |
-
# This is the description that will appear on the datasets page.
|
68 |
-
description=_DESCRIPTION,
|
69 |
-
# This defines the different columns of the dataset and their types
|
70 |
-
features=features, # Here we define them above because they are different between the two configurations
|
71 |
-
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
72 |
-
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
73 |
-
# supervised_keys=("sentence", "label"),
|
74 |
-
# Homepage of the dataset for documentation
|
75 |
-
# homepage=_HOMEPAGE,
|
76 |
-
# License for the dataset if available
|
77 |
-
# license=_LICENSE,
|
78 |
-
# Citation for the dataset
|
79 |
-
# citation=_CITATION,
|
80 |
-
)
|
81 |
-
|
82 |
-
def _split_generators(self, dl_manager):
|
83 |
-
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
84 |
-
|
85 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
86 |
-
# 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.
|
87 |
-
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
88 |
-
urls = get_url(self.config.name)
|
89 |
-
filepath = dl_manager.download(urls)
|
90 |
-
|
91 |
-
return [
|
92 |
-
datasets.SplitGenerator(
|
93 |
-
name=datasets.Split.TRAIN,
|
94 |
-
# These kwargs will be passed to _generate_examples
|
95 |
-
gen_kwargs={
|
96 |
-
"filepath": filepath,
|
97 |
-
"split": "train",
|
98 |
-
},
|
99 |
-
)
|
100 |
-
]
|
101 |
-
|
102 |
-
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
103 |
-
def _generate_examples(self, filepath, split):
|
104 |
-
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
105 |
-
line_counter = 0
|
106 |
-
try:
|
107 |
-
with xz.open(open(filepath, "rb"), "rt", encoding="utf-8") as f:
|
108 |
-
for id, line in enumerate(f):
|
109 |
-
line_counter += 1
|
110 |
-
if line:
|
111 |
-
data = json.loads(line)
|
112 |
-
if self.config.name == "german" or self.config.name == "italian" or self.config.name == "french":
|
113 |
-
yield id, {
|
114 |
-
"id": data["id"]
|
115 |
-
}
|
116 |
-
except lzma.LZMAError as e:
|
117 |
-
print(split, e)
|
118 |
-
if line_counter == 0:
|
119 |
-
raise e
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|