File size: 2,497 Bytes
fcc0e32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ab872f8
fcc0e32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

import os
import textwrap
from textwrap import TextWrapper
import datasets
import pyarrow.parquet as pq

_URLS = {
    "original_text": "./original_text",
    "unlabeled_sentences": "./unlabeled_sentences"
}

_metadata = {
    "citation": """\
    @InProceedings{
        huggingface:dataset,
        title = {Paraguay Legislation Dataset},
        author={Peres, Fernando; Costa, Victor},
        year={2023}
    }
    """,

    "description": "Dataset for researching.",

    "homepage": "https://www.leyes.com.py/",

    "license": "apache-2.0",
}


class TestBuilder(datasets.GeneratorBasedBuilder):
    VERSION = datasets.Version("1.0.0")

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name="raw_text",
            version=VERSION,
            description="desc raw text",
        ),

        datasets.BuilderConfig(
            name="unlabeled_sentences",
            version=VERSION,
            description="desc unlabeled",
        ),
    ]

    def _info(self):

        features = None
        if self.config.name == "raw_text":

            features = datasets.Features(
                {
                    "id": datasets.Value(dtype="int64"),
                    "text": datasets.Value(dtype="string"),
                }
            )

        if self.config.name == "unlabeled_sentences":
            features = features = datasets.Features(
                {
                    "id": datasets.Value(dtype="int64"),
                    "text_2": datasets.Value(dtype="string"),
                    "note": datasets.Value(dtype="string"),
                }
            )

        return datasets.DatasetInfo(
            builder_name=self.config.name,
            description="description xxxxxxxxxxxxxxx",
            features=features,
            homepage=_metadata["homepage"],
            license=_metadata["license"],
            citation=_metadata["citation"],
        )

    def _split_generators(self, dl_manager):
        urls_to_download = _URLS[self.config.name]

        filepaths = dl_manager.download_and_extract(urls_to_download)

        return datasets.SplitGenerator(
            name=datasets.Split.TRAIN,
            gen_kwargs={"filepath": filepaths},
        )

    def _generate_examples(self, filepath):
        pq_table = pq.read_table(filepath)
        for i in range(len(pq_table)):
            yield i, {
                col_name: pq_table[col_name][i].as_py()
                for col_name in pq_table.column_names
            }