zeusfsx commited on
Commit
3eecf34
2 Parent(s): 52e8ead d0e003e

Merge branch 'main' of https://huggingface.co/datasets/zeusfsx/ukrainian-news

Browse files
Files changed (1) hide show
  1. ukrainian-news.py +61 -0
ukrainian-news.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import datasets
4
+
5
+
6
+ logger = datasets.logging.get_logger(__name__)
7
+
8
+
9
+ _DESCRIPTION = """\
10
+ Ukrainian News Dataset
11
+
12
+ This is a dataset of news articles downloaded from various Ukrainian websites. The dataset contains approximately 10 569 428 JSON objects (news)
13
+ """
14
+
15
+ _URLS = [
16
+ "ukrainian-news-1.json",
17
+ "ukrainian-news-2.json",
18
+ "ukrainian-news-3.json",
19
+ "ukrainian-news-4.json",
20
+ "ukrainian-news-5.json"
21
+ ]
22
+
23
+
24
+ class UkrainianNews(datasets.GeneratorBasedBuilder):
25
+ """Ukrainian News Dataset"""
26
+ VERSION = datasets.Version("0.0.1")
27
+ DEFAULT_CONFIG_NAME = "default"
28
+ BUILDER_CONFIGS = [
29
+ datasets.BuilderConfig(name="default", version=VERSION, description=""),
30
+ ]
31
+
32
+ def _info(self):
33
+ return datasets.DatasetInfo(
34
+ description=_DESCRIPTION,
35
+ features=datasets.Features(
36
+ {
37
+ "url": datasets.Value("string"),
38
+ "title": datasets.Value("string"),
39
+ "text": datasets.Value("string"),
40
+ "owner": datasets.Value("string"),
41
+ "datetime": datasets.Value("string"),
42
+ }
43
+ )
44
+ )
45
+
46
+ def _split_generators(self, dl_manager):
47
+ downloaded_files = dl_manager.download_and_extract(_URLS)
48
+
49
+ return [
50
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files})
51
+ ]
52
+
53
+ def _generate_examples(self, filepath):
54
+ """This function returns the examples in the raw (text) form."""
55
+ logger.info("generating examples from = %s", filepath)
56
+ key = 0
57
+ with open(filepath, encoding="utf-8") as f:
58
+ news = json.load(f)
59
+ for article in news:
60
+ yield key, article
61
+ key += 1