File size: 2,343 Bytes
922a4e5
4579cd3
 
 
 
 
 
 
 
882569e
4579cd3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b96173d
4579cd3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c98df0b
4579cd3
 
 
 
 
 
 
 
 
 
 
 
 
 
8e7bef5
4579cd3
 
 
 
 
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
"""Thai CulturaX clean dataset."""
import json
import datasets

logger = datasets.logging.get_logger(__name__)
_DESCRIPTION = """
Thai CulturaX Clean dataset."""
_CITATION = """EMPTY"""
_URL = "EMPTY"
_DATA_URL = "data/thai.{index:02d}.json"
_LICENSE="odc-by"


class ThaiCulturaXConfig(datasets.BuilderConfig):
    """BuilderConfig for Dataset."""

    def __init__(self, *args, languages="Thai", **kwargs):
        """BuilderConfig for Dataset.
        Args:
            languages (:obj:`List[str]`): list of languages to load
            **kwargs: keyword arguments forwarded to super.
        """
        super().__init__(
            *args,
            **kwargs,
        )
        self.languages = languages


class ThaiCulturaX(datasets.GeneratorBasedBuilder):
    """ThaiCulturaX clean dataset."""

    BUILDER_CONFIGS = [
        ThaiCulturaXConfig(languages="Thai", version=datasets.Version("1.0.0"))
    ]
    BUILDER_CONFIG_CLASS = ThaiCulturaXConfig

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "text": datasets.Value("string"),
                    "meta": datasets.Value("string"),
                }
            ),
            supervised_keys=None,
            homepage=_URL,
            citation=_CITATION,
            license=_LICENSE,
        )

    def _split_generators(self, dl_manager):
        data_urls = {}
        for split in ["train"]:
            data_urls[split] = [
                _DATA_URL.format(
                    index=index,
                )
                for index in range(0, 40)
            ]
        train_downloaded_files = dl_manager.download(data_urls["train"])

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

    def _generate_examples(self, filepaths):
        id_ = 0
        for filepath in filepaths:
            logger.info("generating examples from = %s", filepath)
            with open(filepath, "r",encoding="utf-8-sig") as f:
                for line in f:
                    if line:
                        example = json.loads(line)
                        yield id_, example
                        id_ += 1