File size: 2,423 Bytes
0935a99
 
 
dea82da
0935a99
 
 
 
f01a46e
 
0935a99
 
 
 
dea82da
 
0935a99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a63fb94
 
2b23524
0935a99
 
 
d7212a4
0935a99
 
 
d7212a4
fce1bd6
f01a46e
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import csv
csv.field_size_limit(int(1e6))
import os.path

import datasets
from urllib.parse import urlparse
import io


_CITATION = """
"""

_DESCRIPTION = """
"""


class HebrewNewsConfig(datasets.BuilderConfig):
    """BuilderConfig"""

    def __init__(self, **kwargs):
        """BuilderConfig
        Args:
          **kwargs: keyword arguments forwarded to super.
        """
        super(HebrewNewsConfig, self).__init__(**kwargs)


class HebrewNews(datasets.GeneratorBasedBuilder):
    """HebrewNews dataset."""

    BUILDER_CONFIGS = [
        HebrewNewsConfig(
            name="hebrew_news", version=datasets.Version("1.0.0"),
            description=f"hebrew news dataset"
        )
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "id": datasets.Value("string"),
                    "articleBody": datasets.Value("string"),
                    "description": datasets.Value("string"),
                    "headline": datasets.Value("string"),
                    "title": datasets.Value("string"),
                }
            ),
            supervised_keys=None,
            homepage="",
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        urls_to_download = "data/news.tar.gz"
        archive_path = dl_manager.download(urls_to_download)
        archive_iter = dl_manager.iter_archive(archive_path)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={"archive_iter":archive_iter },
            ),
        ]

    def _generate_examples(self, archive_iter):
        for filepath, f in archive_iter:
            csv_file = io.TextIOWrapper(f, encoding="utf-8")
            fieldnames = ["articleBody", "description", "headline", "title"]
            reader = csv.DictReader(csv_file, delimiter=",", fieldnames=fieldnames)
            next(reader)
            for idx, row in enumerate(reader):
                yield idx, {
                    "id": idx,
                    "articleBody": row["articleBody"],
                    "description": row["description"],
                    "headline": row["headline"],
                    "title": row["title"],
                }