fernando-peres
commited on
Commit
·
fcc0e32
1
Parent(s):
f11f1f0
Builder created
Browse files- test_builder.py +94 -0
test_builder.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import os
|
| 3 |
+
import textwrap
|
| 4 |
+
from textwrap import TextWrapper
|
| 5 |
+
import datasets
|
| 6 |
+
import pyarrow.parquet as pq
|
| 7 |
+
|
| 8 |
+
_URLS = {
|
| 9 |
+
"original_text": "./original_text",
|
| 10 |
+
"unlabeled_sentences": "./unlabeled_sentences"
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
_metadata = {
|
| 14 |
+
"citation": """\
|
| 15 |
+
@InProceedings{
|
| 16 |
+
huggingface:dataset,
|
| 17 |
+
title = {Paraguay Legislation Dataset},
|
| 18 |
+
author={Peres, Fernando; Costa, Victor},
|
| 19 |
+
year={2023}
|
| 20 |
+
}
|
| 21 |
+
""",
|
| 22 |
+
|
| 23 |
+
"description": "Dataset for researching.",
|
| 24 |
+
|
| 25 |
+
"homepage": "https://www.leyes.com.py/",
|
| 26 |
+
|
| 27 |
+
"license": "apache-2.0",
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class TestBuilder(datasets.GeneratorBasedBuilder):
|
| 32 |
+
VERSION = datasets.Version("1.0.0")
|
| 33 |
+
|
| 34 |
+
BUILDER_CONFIGS = [
|
| 35 |
+
datasets.BuilderConfig(
|
| 36 |
+
name="raw_text",
|
| 37 |
+
version=VERSION,
|
| 38 |
+
description="desc raw text",
|
| 39 |
+
),
|
| 40 |
+
|
| 41 |
+
datasets.BuilderConfig(
|
| 42 |
+
name="unlabeled_sentences",
|
| 43 |
+
version=VERSION,
|
| 44 |
+
description="desc unlabeled",
|
| 45 |
+
),
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
def _info(self):
|
| 49 |
+
|
| 50 |
+
features = None
|
| 51 |
+
if self.config.name == "raw_text":
|
| 52 |
+
|
| 53 |
+
features = datasets.Features(
|
| 54 |
+
{
|
| 55 |
+
"id": datasets.Value(dtype="int64"),
|
| 56 |
+
"text": datasets.Value(dtype="string"),
|
| 57 |
+
}
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
if self.config.name == "unlabeled_sentences":
|
| 61 |
+
features = features = datasets.Features(
|
| 62 |
+
{
|
| 63 |
+
"id": datasets.Value(dtype="int64"),
|
| 64 |
+
"text_2": datasets.Value(dtype="string"),
|
| 65 |
+
"note": datasets.Value(dtype="string"),
|
| 66 |
+
}
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
return datasets.DatasetInfo(
|
| 70 |
+
builder_name=self.config.name,
|
| 71 |
+
description="description xxxxxxxxxxxxxxx",
|
| 72 |
+
features=features,
|
| 73 |
+
homepage=_metadata["homepage"],
|
| 74 |
+
license=_metadata["license"],
|
| 75 |
+
citation=_metadata["citation"],
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
def _split_generators(self, dl_manager):
|
| 79 |
+
urls_to_download = _URLS
|
| 80 |
+
|
| 81 |
+
filepaths = dl_manager.download_and_extract(urls_to_download)
|
| 82 |
+
|
| 83 |
+
return datasets.SplitGenerator(
|
| 84 |
+
name=datasets.Split.TRAIN,
|
| 85 |
+
gen_kwargs={"filepath": filepaths},
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
def _generate_examples(self, filepath):
|
| 89 |
+
pq_table = pq.read_table(filepath)
|
| 90 |
+
for i in range(len(pq_table)):
|
| 91 |
+
yield i, {
|
| 92 |
+
col_name: pq_table[col_name][i].as_py()
|
| 93 |
+
for col_name in pq_table.column_names
|
| 94 |
+
}
|