zeusfsx commited on
Commit
915dba1
1 Parent(s): 6cb5e66

Create ukrainian-stackexchange.py

Browse files
Files changed (1) hide show
  1. ukrainian-stackexchange.py +58 -0
ukrainian-stackexchange.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import DatasetBuilder, SplitGenerator, DownloadConfig
2
+ from pathlib import Path
3
+ import json
4
+
5
+
6
+ URL = "ukrainian-stackexchange.json"
7
+
8
+
9
+ class UkrainianStackExchange(DatasetBuilder):
10
+
11
+ VERSION = "1.0.0"
12
+ BUILDER_CONFIGS = [
13
+ {
14
+ "name": "ukrainian-stackexchange",
15
+ "version": VERSION,
16
+ "description": "Ukrainian StackExchange Dataset collected from https://ukrainian.stackexchange.com/"
17
+ }
18
+ ]
19
+
20
+ def _info(self):
21
+ return datasets.DatasetInfo(
22
+ description=_DESCRIPTION,
23
+ features=datasets.Features({
24
+ "question": {
25
+ "id": datasets.Value("string"),
26
+ "title": datasets.Value("string"),
27
+ "text": datasets.Value("string"),
28
+ "upvoteCount": datasets.Value("int32"),
29
+ "tags": datasets.Sequence(datasets.Value("string")),
30
+ },
31
+ "answers": datasets.Sequence({
32
+ "id": datasets.Value("string"),
33
+ "text": datasets.Value("string"),
34
+ "upvoteCount": datasets.Value("int32"),
35
+ "isAccepted": datasets.Value("bool"),
36
+ }),
37
+ "url": datasets.Value("string"),
38
+ }),
39
+ supervised_keys=None,
40
+ )
41
+
42
+ def _split_generators(self, dl_manager):
43
+ path_to_file = Path(URL)
44
+ return [
45
+ SplitGenerator(
46
+ name=datasets.Split.TRAIN,
47
+ gen_kwargs={
48
+ "filepath": path_to_file,
49
+ },
50
+ ),
51
+ ]
52
+
53
+ def _generate_examples(self, filepath):
54
+ with open(filepath, "r", encoding="utf-8") as f:
55
+ json_data = json.load(f)
56
+
57
+ for idx, data in enumerate(json_data):
58
+ yield idx, data