Datasets:

Languages:
Hebrew
ArXiv:
Libraries:
Datasets
pandas
License:
File size: 17,841 Bytes
d329c13
 
 
e1ac33f
d329c13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d5ddef
d329c13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d5ddef
d329c13
 
 
 
 
 
 
3b17622
d329c13
 
 
 
 
 
3ee22d3
d329c13
 
 
 
 
 
c96216b
d329c13
 
 
 
 
 
c0ad566
d329c13
 
 
 
 
 
c0ad566
d329c13
 
 
 
 
 
3b17622
d329c13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d5ddef
d329c13
 
 
 
 
 
 
c72e219
d329c13
 
 
 
 
5887c53
d329c13
 
e1ac33f
 
 
 
d329c13
 
 
 
 
 
 
5887c53
 
 
 
d329c13
 
5887c53
d329c13
 
 
 
 
 
 
 
 
 
 
 
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import json
import os
from typing import List
from huggingface_hub import hf_hub_url

import datasets


_KnessetCorpus_CITATION = """\
@article{
}
"""

_KnessetCorpus_DESCRIPTION = """
An annotated corpus of Hebrew parliamentary proceedings containing over 32 million sentences from all the (plenary and committee) protocols held in the Israeli parliament from 1998 to 2022.
Sentences are annotated with various levels of linguistic information, including part-of-speech tags, morphological features, dependency structures, and named entities.
They are also associated with detailed meta-information reflecting demographic and political properties of the speakers, based on a large database of parliament members and factions that we compiled.
"""
_AllFeaturesSentences_DESCRIPTION = """\
AllFeaturesSentences consists of samples of all the sentences in the corpus (plenary and committee) together with all the features available in the dataset:\
The features are consistent with the Sentence model features, the Protocol model features of the protocol the sentence belongs to,
the Person model features of the speaker and the Faction model features \
of the faction of the speaker at that time.
This is roughly equivalent to a join between all models in dataset (Protocol, Faction, Person, Sentence) 
"""

_CommitteeAllFeaturesSentences_DESCRIPTION = """\
CommitteeAllFeaturesSentences consists of samples of all the sentences in the committee sessions in the corpus together with all the features available in the dataset:\
The features are consistent with the Sentence model features, the Protocol model features of the protocol the sentence belongs to,
the Person model features of the speaker and the Faction model features \
of the faction of the speaker at that time.
This is roughly equivalent to a join between all models in dataset (Protocol, Faction, Person, Sentence) 
"""

_PlenaryAllFeaturesSentences_DESCRIPTION = """\
PlenaryAllFeaturesSentences consists of samples of all the sentences in the plenary sessions in the corpus together with all the features available in the dataset:\
The features are consistent with the Sentence model features, the Protocol model features of the protocol the sentence belongs to,
the Person model features of the speaker and the Faction model features \
of the faction of the speaker at that time.
This is roughly equivalent to a join between all models in dataset (Protocol, Faction, Person, Sentence) 
"""

_KnessetMembers_DESCRIPTION = """\
KnessetMembers consists of samples of the knesset members in the dataset and their meta-data information such as name, gender and factions affiliations.
The features are consistent with the Person model features
"""

_Factions_DESCRIPTION = """\
Factions consists of samples of the factions in the dataset and their meta-data information such as name, political orientation and active periods.
The features are consistent with the Faction model features
"""

_Protocols_DESCRIPTION = """\
Protocols consists of samples of the protocols in the dataset and their meta-data information such as date, knesset number, session name and a list of its sentences.
The features are consistent with the Protocol model features and the features for each sentence are consistent with the Sentence model
"""
class KnessetCorpusConfig(datasets.BuilderConfig):
    """BuilderConfig for KnessetCorpus."""

    def __init__(self, features, data_urls, citation, **kwargs):
        """BuilderConfig for KnessetCorpus.

        Args:
        features: *list[string]*, list of the features that will appear in the
            feature dict. Should not include "label".
        data_urls:  *list[string]*, urls to download the files from.
        citation: *string*, citation for the data set.
        **kwargs: keyword arguments forwarded to super.
        """

        super().__init__(version=datasets.Version("1.0.1"), **kwargs)
        self.features = features
        self.data_urls = data_urls
        self.citation = citation





class KnessetCorpus(datasets.GeneratorBasedBuilder):

    BUILDER_CONFIG_CLASS = KnessetCorpusConfig
    BUILDER_CONFIGS = [
        KnessetCorpusConfig(
            name="knessetMembers",
            description=_KnessetMembers_DESCRIPTION,
            features=["person_id", "first_name", "last_name", "full_name", "is_knesset_member", "gender", "email", "is_current", "last_updated_date", "date_of_birth", "place_of_birth", "year_of_aliya", "date_of_death", "mother_tongue", "religion", "nationality", "religious_orientation", "residence", "factions_memberships",  "languages","allSources", "wikiLink","notes"   ],
            data_urls=["https://huggingface.co./datasets/HaifaCLGroup/KnessetCorpus/raw/main/all_knesset_members_jsons.jsonl"],
            citation=_KnessetCorpus_CITATION,
        ),
        KnessetCorpusConfig(
            name="factions",
            description=_Factions_DESCRIPTION,
            features=["faction_name", "faction_popular_initials", "faction_id", "active_periods", "knesset_numbers", "coalition_or_opposition_memberships", "political_orientation", "other_names", "notes", "wiki_link", ],
            data_urls=["https://huggingface.co./datasets/HaifaCLGroup/KnessetCorpus/raw/main/factions_jsons.jsonl"],
            citation=_KnessetCorpus_CITATION,
        ),
        KnessetCorpusConfig(
            name="protocols",
            description=_Protocols_DESCRIPTION,
            features=["protocol_name", "session_name", "parent_session_name", "knesset_number", "protocol_number", "protocol_date", "is_ocr_output", "protocol_type", "protocol_sentences"],
            data_urls=["https://dl.fbaipublicfiles.com/glue/superglue/data/v2/BoolQ.zip?raw=true"],#TODO
            citation=_KnessetCorpus_CITATION,
        ),
        KnessetCorpusConfig(
            name="all_features_sentences",
            description=_AllFeaturesSentences_DESCRIPTION,
            features=["sentence_id", "protocol_name", "speaker_id", "speaker_name", "is_valid_speaker", "turn_num_in_protocol", "sent_num_in_turn", "sentence_text", "is_chairman","morphological_fields", "speaker_first_name", "speaker_last_name", "speaker_is_knesset_member", "speaker_gender", "speaker_email", "speaker_last_updated_date", "speaker_date_of_birth", "speaker_place_of_birth","speaker_year_of_aliya", "speaker_date_of_death", "speaker_mother_tongue", "speaker_religion", "speaker_nationality", "speaker_religious_orientation", "speaker_residence", "speaker_factions_memberships", "speaker_languages", "speaker_sources",  "speaker_notes","faction_id", "faction_general_name", "knesset_faction_id", "current_faction_name", "member_of_coalition_or_opposition", "faction_popular_initials", "faction_active_periods", "faction_knesset_numbers","faction_coalition_or_opposition_memberships",  "faction_political_orientation", "faction_other_names", "faction_notes", "faction_wiki_link"],
            data_urls=[" https://git-lfs.github.com/spec/v1", "https://huggingface.co./datasets/HaifaCLGroup/KnessetCorpus/raw/main/protocols_sentences/plenary_full_sentences.jsonl.bz2"],
            citation=_KnessetCorpus_CITATION,
        ),
        KnessetCorpusConfig(
            name="committees_all_features_sentences",
            description=_AllFeaturesSentences_DESCRIPTION,
            features=["sentence_id", "protocol_name", "speaker_id", "speaker_name", "is_valid_speaker", "turn_num_in_protocol", "sent_num_in_turn", "sentence_text", "is_chairman","morphological_fields", "speaker_first_name", "speaker_last_name", "speaker_is_knesset_member", "speaker_gender", "speaker_email", "speaker_last_updated_date", "speaker_date_of_birth", "speaker_place_of_birth","speaker_year_of_aliya", "speaker_date_of_death", "speaker_mother_tongue", "speaker_religion", "speaker_nationality", "speaker_religious_orientation", "speaker_residence", "speaker_factions_memberships", "speaker_languages", "speaker_sources",  "speaker_notes","faction_id", "faction_general_name", "knesset_faction_id", "current_faction_name", "member_of_coalition_or_opposition", "faction_popular_initials", "faction_active_periods", "faction_knesset_numbers","faction_coalition_or_opposition_memberships",  "faction_political_orientation", "faction_other_names", "faction_notes", "faction_wiki_link"],
            data_urls=[" https://git-lfs.github.com/spec/v1"],
            citation=_KnessetCorpus_CITATION,
        ),
        KnessetCorpusConfig(
            name="plenary_all_features_sentences",
            description=_AllFeaturesSentences_DESCRIPTION,
            features=["sentence_id", "protocol_name", "speaker_id", "speaker_name", "is_valid_speaker", "turn_num_in_protocol", "sent_num_in_turn", "sentence_text", "is_chairman","morphological_fields", "speaker_first_name", "speaker_last_name", "speaker_is_knesset_member", "speaker_gender", "speaker_email", "speaker_last_updated_date", "speaker_date_of_birth", "speaker_place_of_birth","speaker_year_of_aliya", "speaker_date_of_death", "speaker_mother_tongue", "speaker_religion", "speaker_nationality", "speaker_religious_orientation", "speaker_residence", "speaker_factions_memberships", "speaker_languages", "speaker_sources",  "speaker_notes","faction_id", "faction_general_name", "knesset_faction_id", "current_faction_name", "member_of_coalition_or_opposition", "faction_popular_initials", "faction_active_periods", "faction_knesset_numbers","faction_coalition_or_opposition_memberships",  "faction_political_orientation", "faction_other_names", "faction_notes", "faction_wiki_link"],
            data_urls=["https://huggingface.co./datasets/HaifaCLGroup/KnessetCorpus/raw/main/protocols_sentences/plenary_full_sentences.jsonl.bz2"],
            citation=_KnessetCorpus_CITATION,
        )]

    # DEFAULT_CONFIG_NAME = "all_features_sentences"

    def _info(self):
        features = {feature: datasets.Value("string") for feature in self.config.features}

        if "all_features_sentences" in self.config.name:
            features.update({
                "faction_active_periods": datasets.Sequence({
                    "end_date": datasets.Value("string"),  # Date converted to string
                    "start_date": datasets.Value("string"),  # Date converted to string
                }),
                "faction_coalition_or_opposition_memberships": datasets.Sequence({
                    "end_date": datasets.Value("string"),  # Date converted to string
                    "knesset_faction_name": datasets.Value("string"),
                    "knesset_num": datasets.Value("string"),
                    "member_of_coalition": datasets.Value("bool"),
                    "notes": datasets.Value("string"),
                    "start_date": datasets.Value("string")  # Date converted to string
                }),
                "faction_other_names": datasets.Sequence({
                    "name": datasets.Value("string"),
                    "name_end_date": datasets.Value("string"),  # Date converted to string
                    "name_start_date": datasets.Value("string")  # Date converted to string
                }),
                "is_chairman": datasets.Value("bool"),
                "is_ocr_output": datasets.Value("bool"),
                "is_valid_speaker": datasets.Value("bool"),
                "sent_num_in_turn": datasets.Value("int64"),
                "turn_num_in_protocol": datasets.Value("int64"),
                "morphological_fields": datasets.Sequence({
                    "id": datasets.Value("string"),
                    "form": datasets.Value("string"),
                    "lemma": datasets.Value("string"),
                    "upos": datasets.Value("string"),
                    "xpos": datasets.Value("string"),
                    "feats": datasets.Value("string"),
                    "head": datasets.Value("int32"),
                    "deprel": datasets.Value("string"),
                    "deps": datasets.Value("string"),
                    "misc": datasets.Value("string")}),
                "speaker_factions_memberships": datasets.Sequence({
                    "end_date": datasets.Value("string"),
                    "faction_id": datasets.Value("string"),
                    "faction_name": datasets.Value("string"),
                    "knesset_faction_id": datasets.Value("string"),
                    "knesset_number": datasets.Value("string"),
                    "start_date": datasets.Value("string")}),
                "speaker_is_knesset_member": datasets.Value("bool"),
                "speaker_notes": datasets.Sequence(datasets.Value("string")),
            "speaker_languages": datasets.Sequence(datasets.Value("string"))
              })

        if self.config.name == "protocols":
            features.update({
            "is_ocr_output": datasets.Value("bool"),
            "protocol_sentences": datasets.Sequence({
                "sentence_id": datasets.Value("string"),
                "protocol_name": datasets.Value("string"),
                "speaker_id": datasets.Value("string"),
                "speaker_name": datasets.Value("string"),
                "is_valid_speaker": datasets.Value("bool"),
                "turn_num_in_protocol": datasets.Value("int64"),
                "sent_num_in_turn": datasets.Value("int64"),
                "sentence_text": datasets.Value("string"),
                "is_chairman": datasets.Value("bool"),
                "morphological_fields": datasets.Sequence({
                    "id": datasets.Value("string"),
                    "form": datasets.Value("string"),
                    "lemma": datasets.Value("string"),
                    "upos": datasets.Value("string"),
                    "xpos": datasets.Value("string"),
                    "feats": datasets.Value("string"),
                    "head": datasets.Value("int32"),
                    "deprel": datasets.Value("string"),
                    "deps": datasets.Value("string"),
                    "misc": datasets.Value("string"),
                }),
                "factuality_fields": datasets.Value("string")
            })
            })
        if self.config.name == "factions":
            features.update({
                "active_periods": datasets.Sequence({
                    "end_date": datasets.Value("string"),  # Date converted to string
                    "start_date": datasets.Value("string"),  # Date converted to string
                }),
                "coalition_or_opposition_memberships": datasets.Sequence({
                    "end_date": datasets.Value("string"),  # Date converted to string
                    "knesset_faction_name": datasets.Value("string"),
                    "knesset_num": datasets.Value("string"),
                    "member_of_coalition": datasets.Value("bool"),
                    "notes": datasets.Value("string"),
                    "start_date": datasets.Value("string"),  # Date converted to string
                }),
                "other_names": datasets.Sequence({
                    "name": datasets.Value("string"),
                    "name_end_date": datasets.Value("string"),  # Date converted to string
                    "name_start_date": datasets.Value("string"),  # Date converted to string
                })
            })
        if self.config.name == "KnessetMembers":
            features.update({
            "is_knesset_member": datasets.Value("bool"),
            "factions_memberships": datasets.Sequence({
                "end_date": datasets.Value("string"),
                "faction_id": datasets.Value("string"),
                "faction_name": datasets.Value("string"),
                "knesset_faction_id": datasets.Value("string"),
                "knesset_number": datasets.Value("string"),
                "start_date": datasets.Value("string")}),
            "notes": datasets.Sequence(datasets.Value("string")),
            "languages": datasets.Sequence(datasets.Value("string"))
            })

        return datasets.DatasetInfo(
            description=_KnessetCorpus_DESCRIPTION + self.config.description,
            features=datasets.Features(features),
            citation=self.config.citation
        )
    def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
        urls = self.config.data_urls
        downloaded_files = dl_manager.download_and_extract(urls)

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

    def _generate_examples(self, data_files):
        print(f'data_files:{data_files}')
        if "all_features_sentences" in self.config.name:
            id_field_name = "sentence_id"
            url = hf_hub_url(repo_id="HaifaCLGroup/knessetCorpus",
                       filename="KnessetCorpus/protocols_sentences/committee_full_sentences.jsonl.bz2")
            data_files = [url]

        elif self.config.name == "protocols":
            id_field_name = "protocol_name"
        elif self.config.name == "factions":
            id_field_name = "faction_id"
        elif self.config.name == "knessetMembers":
            id_field_name = "person_id"

        for i, filepath in enumerate(data_files):
            print(f'i:{i}')
            print(f'filepath: {filepath}')

            with open(filepath, encoding="utf-8") as f:
                for line in f:
                    print(f'line: {line}')
                    try:
                        row = json.loads(line)
                    except Exception as e:
                        print(f'couldnt load sample. error was: {e}. Continuing to next sample')
                        continue
                    id_ = row[id_field_name]
                    yield id_, row