File size: 1,839 Bytes
915dba1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from datasets import DatasetBuilder, SplitGenerator, DownloadConfig
from pathlib import Path
import json


URL = "ukrainian-stackexchange.json"


class UkrainianStackExchange(DatasetBuilder):

    VERSION = "1.0.0"
    BUILDER_CONFIGS = [
        {
            "name": "ukrainian-stackexchange",
            "version": VERSION,
            "description": "Ukrainian StackExchange Dataset collected from https://ukrainian.stackexchange.com/"
        }
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features({
                "question": {
                    "id": datasets.Value("string"),
                    "title": datasets.Value("string"),
                    "text": datasets.Value("string"),
                    "upvoteCount": datasets.Value("int32"),
                    "tags": datasets.Sequence(datasets.Value("string")),
                },
                "answers": datasets.Sequence({
                    "id": datasets.Value("string"),
                    "text": datasets.Value("string"),
                    "upvoteCount": datasets.Value("int32"),
                    "isAccepted": datasets.Value("bool"),
                }),
                "url": datasets.Value("string"),
            }),
            supervised_keys=None,
        )

    def _split_generators(self, dl_manager):
        path_to_file = Path(URL)
        return [
            SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "filepath": path_to_file,
                },
            ),
        ]

    def _generate_examples(self, filepath):
        with open(filepath, "r", encoding="utf-8") as f:
            json_data = json.load(f)

        for idx, data in enumerate(json_data):
            yield idx, data