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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
from typing import List
|
| 4 |
+
from huggingface_hub import hf_hub_url
|
| 5 |
+
|
| 6 |
+
import datasets
|
| 7 |
+
|
| 8 |
+
num_plenary_shard = 28
|
| 9 |
+
num_of_committee_shards = 90
|
| 10 |
+
_KnessetCorpus_CITATION = "@misc{goldin2024knesset, title={The Knesset Corpus: An Annotated Corpus of Hebrew Parliamentary Proceedings}, author={Gili Goldin and Nick Howell and Noam Ordan and Ella Rabinovich and Shuly Wintner}, year={2024}, eprint={2405.18115}, archivePrefix={arXiv}, primaryClass={cs.CL} }"
|
| 11 |
+
|
| 12 |
+
_KnessetCorpus_DESCRIPTION = """
|
| 13 |
+
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.
|
| 14 |
+
Sentences are annotated with various levels of linguistic information, including part-of-speech tags, morphological features, dependency structures, and named entities.
|
| 15 |
+
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.
|
| 16 |
+
"""
|
| 17 |
+
_AllFeaturesSentences_DESCRIPTION = """\
|
| 18 |
+
AllFeaturesSentences consists of samples of all the sentences in the corpus (plenary and committee) together with all the features available in the dataset:\
|
| 19 |
+
The features are consistent with the Sentence model features, the Protocol model features of the protocol the sentence belongs to,
|
| 20 |
+
the Person model features of the speaker and the Faction model features \
|
| 21 |
+
of the faction of the speaker at that time.
|
| 22 |
+
This is roughly equivalent to a join between all models in dataset (Protocol, Faction, Person, Sentence)
|
| 23 |
+
"""
|
| 24 |
+
_NoMorphAllFeaturesSentences_DESCRIPTION = """\
|
| 25 |
+
AllFeaturesSentences consists of samples of all the sentences in the corpus (plenary and committee) together with all the non-morphological features available in the dataset :\
|
| 26 |
+
The features are consistent with the Sentence model features, the Protocol model features of the protocol the sentence belongs to,
|
| 27 |
+
the Person model features of the speaker and the Faction model features \
|
| 28 |
+
of the faction of the speaker at that time.
|
| 29 |
+
This is roughly equivalent to a join between all models in dataset (Protocol, Faction, Person, Sentence)
|
| 30 |
+
Ideal if morpho-syntactic annotations aren't relevant to your work, providing a less disk space heavy option.
|
| 31 |
+
|
| 32 |
+
"""
|
| 33 |
+
_CommitteeAllFeaturesSentences_DESCRIPTION = """\
|
| 34 |
+
CommitteeAllFeaturesSentences consists of samples of all the sentences in the committee sessions in the corpus together with all the features available in the dataset:\
|
| 35 |
+
The features are consistent with the Sentence model features, the Protocol model features of the protocol the sentence belongs to,
|
| 36 |
+
the Person model features of the speaker and the Faction model features \
|
| 37 |
+
of the faction of the speaker at that time.
|
| 38 |
+
This is roughly equivalent to a join between all models in dataset (Protocol, Faction, Person, Sentence)
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
_NoMorphCommitteeAllFeaturesSentences_DESCRIPTION = """\
|
| 42 |
+
AllFeaturesSentences consists of samples of all the sentences in the committee sessions in the corpus together with all the non-morphological features available in the dataset :\
|
| 43 |
+
The features are consistent with the Sentence model features, the Protocol model features of the protocol the sentence belongs to,
|
| 44 |
+
the Person model features of the speaker and the Faction model features \
|
| 45 |
+
of the faction of the speaker at that time.
|
| 46 |
+
This is roughly equivalent to a join between all models in dataset (Protocol, Faction, Person, Sentence)
|
| 47 |
+
Ideal if morpho-syntactic annotations aren't relevant to your work, providing a less disk space heavy option.
|
| 48 |
+
|
| 49 |
+
"""
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
_PlenaryAllFeaturesSentences_DESCRIPTION = """\
|
| 54 |
+
PlenaryAllFeaturesSentences consists of samples of all the sentences in the plenary sessions in the corpus together with all the features available in the dataset:\
|
| 55 |
+
The features are consistent with the Sentence model features, the Protocol model features of the protocol the sentence belongs to,
|
| 56 |
+
the Person model features of the speaker and the Faction model features \
|
| 57 |
+
of the faction of the speaker at that time.
|
| 58 |
+
This is roughly equivalent to a join between all models in dataset (Protocol, Faction, Person, Sentence)
|
| 59 |
+
"""
|
| 60 |
+
|
| 61 |
+
_NoMorphPlenaryAllFeaturesSentences_DESCRIPTION = """\
|
| 62 |
+
AllFeaturesSentences consists of samples of all the sentences in the plenary sessions in the corpus together with all the non-morphological features available in the dataset :\
|
| 63 |
+
The features are consistent with the Sentence model features, the Protocol model features of the protocol the sentence belongs to,
|
| 64 |
+
the Person model features of the speaker and the Faction model features \
|
| 65 |
+
of the faction of the speaker at that time.
|
| 66 |
+
This is roughly equivalent to a join between all models in dataset (Protocol, Faction, Person, Sentence)
|
| 67 |
+
Ideal if morpho-syntactic annotations aren't relevant to your work, providing a less disk space heavy option.
|
| 68 |
+
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
_KnessetMembers_DESCRIPTION = """\
|
| 72 |
+
KnessetMembers consists of samples of the knesset members in the dataset and their meta-data information such as name, gender and factions affiliations.
|
| 73 |
+
The features are consistent with the Person model features
|
| 74 |
+
"""
|
| 75 |
+
|
| 76 |
+
_Factions_DESCRIPTION = """\
|
| 77 |
+
Factions consists of samples of the factions in the dataset and their meta-data information such as name, political orientation and active periods.
|
| 78 |
+
The features are consistent with the Faction model features
|
| 79 |
+
"""
|
| 80 |
+
|
| 81 |
+
_Protocols_DESCRIPTION = """\
|
| 82 |
+
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.
|
| 83 |
+
The features are consistent with the Protocol model features and the features for each sentence are consistent with the Sentence model
|
| 84 |
+
"""
|
| 85 |
+
|
| 86 |
+
class KnessetCorpusConfig(datasets.BuilderConfig):
|
| 87 |
+
"""BuilderConfig for KnessetCorpus."""
|
| 88 |
+
|
| 89 |
+
def __init__(self, features, data_urls, citation, **kwargs):
|
| 90 |
+
"""BuilderConfig for KnessetCorpus.
|
| 91 |
+
|
| 92 |
+
Args:
|
| 93 |
+
features: *list[string]*, list of the features that will appear in the
|
| 94 |
+
feature dict. Should not include "label".
|
| 95 |
+
data_urls: *list[string]*, urls to download the files from.
|
| 96 |
+
citation: *string*, citation for the data set.
|
| 97 |
+
**kwargs: keyword arguments forwarded to super.
|
| 98 |
+
"""
|
| 99 |
+
|
| 100 |
+
super().__init__(version=datasets.Version("1.0.1"), **kwargs)
|
| 101 |
+
self.features = features
|
| 102 |
+
self.data_urls = data_urls
|
| 103 |
+
self.citation = citation
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
class KnessetCorpus(datasets.GeneratorBasedBuilder):
|
| 110 |
+
|
| 111 |
+
BUILDER_CONFIG_CLASS = KnessetCorpusConfig
|
| 112 |
+
BUILDER_CONFIGS = [
|
| 113 |
+
KnessetCorpusConfig(
|
| 114 |
+
name="knessetMembers",
|
| 115 |
+
description=_KnessetMembers_DESCRIPTION,
|
| 116 |
+
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" ],
|
| 117 |
+
data_urls=["https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/raw/main/all_knesset_members_jsons.jsonl"],
|
| 118 |
+
citation=_KnessetCorpus_CITATION,
|
| 119 |
+
),
|
| 120 |
+
KnessetCorpusConfig(
|
| 121 |
+
name="factions",
|
| 122 |
+
description=_Factions_DESCRIPTION,
|
| 123 |
+
features=["faction_name", "faction_popular_initials", "faction_id", "active_periods", "knesset_numbers", "coalition_or_opposition_memberships", "political_orientation", "other_names", "notes", "wiki_link", ],
|
| 124 |
+
data_urls=["https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/raw/main/factions_jsons.jsonl"],
|
| 125 |
+
citation=_KnessetCorpus_CITATION,
|
| 126 |
+
),
|
| 127 |
+
KnessetCorpusConfig(
|
| 128 |
+
name="protocols",
|
| 129 |
+
description=_Protocols_DESCRIPTION,
|
| 130 |
+
features=["protocol_name", "session_name", "parent_session_name", "knesset_number", "protocol_number", "protocol_date", "is_ocr_output", "protocol_type", "protocol_sentences"],
|
| 131 |
+
data_urls=[f"https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/resolve/main/protocols_sentences/committee_protocols_jsons.zip", f"https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/resolve/main/protocols_sentences/plenary_protocols_jsons.zip"],
|
| 132 |
+
citation=_KnessetCorpus_CITATION,
|
| 133 |
+
),
|
| 134 |
+
KnessetCorpusConfig(
|
| 135 |
+
name="all_features_sentences",
|
| 136 |
+
description=_AllFeaturesSentences_DESCRIPTION,
|
| 137 |
+
features=[ "_id", "knesset_number", "protocol_name", "protocol_number", "protocol_type", "session_name", "parent_session_name", "@timestamp", "protocol_date", "is_ocr_output", "sentence_id", "speaker_id", "speaker_name", "is_valid_speaker", "is_chairman", "turn_num_in_protocol", "sent_num_in_turn", "sentence_text", "morphological_fields", "factuality_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", "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"],
|
| 138 |
+
data_urls=[f"https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/resolve/main/protocols_sentences/plenary_full_sentences_shards_bzip2_files/plenary_full_sentences_shard_{str(i).zfill(2)}.jsonl.bz2" for i in range(num_plenary_shard)] + [f"https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/resolve/main/protocols_sentences/committee_full_sentences_shards_bzip2_files/committee_full_sentences_shard_{str(i).zfill(2)}.jsonl.bz2" for i in range(num_of_committee_shards)],
|
| 139 |
+
citation=_KnessetCorpus_CITATION,
|
| 140 |
+
),
|
| 141 |
+
KnessetCorpusConfig(
|
| 142 |
+
name="no_morph_all_features_sentences",
|
| 143 |
+
description=_NoMorphAllFeaturesSentences_DESCRIPTION,
|
| 144 |
+
features=["_id", "knesset_number", "protocol_name", "protocol_number", "protocol_type", "session_name",
|
| 145 |
+
"parent_session_name", "@timestamp", "protocol_date", "is_ocr_output", "sentence_id",
|
| 146 |
+
"speaker_id", "speaker_name", "is_valid_speaker", "is_chairman", "turn_num_in_protocol",
|
| 147 |
+
"sent_num_in_turn", "sentence_text", "factuality_fields",
|
| 148 |
+
"speaker_first_name", "speaker_last_name", "speaker_is_knesset_member", "speaker_gender",
|
| 149 |
+
"speaker_email", "speaker_last_updated_date", "speaker_date_of_birth", "speaker_place_of_birth",
|
| 150 |
+
"speaker_year_of_aliya", "speaker_date_of_death", "speaker_mother_tongue", "speaker_religion",
|
| 151 |
+
"speaker_nationality", "speaker_religious_orientation", "speaker_residence",
|
| 152 |
+
"speaker_factions_memberships", "speaker_languages", "speaker_sources", "speaker_notes",
|
| 153 |
+
"faction_id", "faction_general_name", "knesset_faction_id", "current_faction_name",
|
| 154 |
+
"faction_popular_initials", "faction_active_periods", "faction_knesset_numbers",
|
| 155 |
+
"faction_coalition_or_opposition_memberships", "faction_political_orientation",
|
| 156 |
+
"faction_other_names", "faction_notes", "faction_wiki_link"],
|
| 157 |
+
data_urls=[
|
| 158 |
+
f"https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/resolve/main/protocols_sentences/plenary_no_morph_sentences_shards_bzip2_files/no_morph_plenary_full_sentences_shard_{str(i).zfill(2)}.jsonl.bz2" for i in range(num_plenary_shard)] + [f"https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/resolve/main/protocols_sentences/committee_no_morph_sentences_shards_bzip2_files/no_morph_committee_full_sentences_shard_{str(i).zfill(2)}.jsonl.bz2" for i in range(num_plenary_shard)],#TODO update num of shards
|
| 159 |
+
citation=_KnessetCorpus_CITATION,
|
| 160 |
+
),
|
| 161 |
+
KnessetCorpusConfig(
|
| 162 |
+
name="committees_all_features_sentences",
|
| 163 |
+
description=_AllFeaturesSentences_DESCRIPTION,
|
| 164 |
+
features=[ "_id", "knesset_number", "protocol_name", "protocol_number", "protocol_type", "session_name", "parent_session_name", "@timestamp", "protocol_date", "is_ocr_output", "sentence_id", "speaker_id", "speaker_name", "is_valid_speaker", "is_chairman", "turn_num_in_protocol", "sent_num_in_turn", "sentence_text", "morphological_fields", "factuality_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", "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"],
|
| 165 |
+
data_urls=[f"https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/resolve/main/protocols_sentences/committee_full_sentences_shards_bzip2_files/committee_full_sentences_shard_{str(i).zfill(2)}.jsonl.bz2" for i in range(num_of_committee_shards)],
|
| 166 |
+
citation=_KnessetCorpus_CITATION,
|
| 167 |
+
),
|
| 168 |
+
KnessetCorpusConfig(
|
| 169 |
+
name="no_morph_committee_all_features_sentences",
|
| 170 |
+
description=_NoMorphCommitteeAllFeaturesSentences_DESCRIPTION,
|
| 171 |
+
features=["_id", "knesset_number", "protocol_name", "protocol_number", "protocol_type", "session_name",
|
| 172 |
+
"parent_session_name", "@timestamp", "protocol_date", "is_ocr_output", "sentence_id",
|
| 173 |
+
"speaker_id", "speaker_name", "is_valid_speaker", "is_chairman", "turn_num_in_protocol",
|
| 174 |
+
"sent_num_in_turn", "sentence_text", "factuality_fields",
|
| 175 |
+
"speaker_first_name", "speaker_last_name", "speaker_is_knesset_member", "speaker_gender",
|
| 176 |
+
"speaker_email", "speaker_last_updated_date", "speaker_date_of_birth", "speaker_place_of_birth",
|
| 177 |
+
"speaker_year_of_aliya", "speaker_date_of_death", "speaker_mother_tongue", "speaker_religion",
|
| 178 |
+
"speaker_nationality", "speaker_religious_orientation", "speaker_residence",
|
| 179 |
+
"speaker_factions_memberships", "speaker_languages", "speaker_sources", "speaker_notes",
|
| 180 |
+
"faction_id", "faction_general_name", "knesset_faction_id", "current_faction_name",
|
| 181 |
+
"faction_popular_initials", "faction_active_periods", "faction_knesset_numbers",
|
| 182 |
+
"faction_coalition_or_opposition_memberships", "faction_political_orientation",
|
| 183 |
+
"faction_other_names", "faction_notes", "faction_wiki_link"],
|
| 184 |
+
data_urls=[ f"https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/resolve/main/protocols_sentences/committee_no_morph_sentences_shards_bzip2_files/no_morph_committee_full_sentences_shard_{str(i).zfill(2)}.jsonl.bz2" for i in range(num_of_committee_shards)],
|
| 185 |
+
citation=_KnessetCorpus_CITATION,
|
| 186 |
+
),
|
| 187 |
+
KnessetCorpusConfig(
|
| 188 |
+
name="no_morph_plenary_all_features_sentences",
|
| 189 |
+
description=_NoMorphPlenaryAllFeaturesSentences_DESCRIPTION,
|
| 190 |
+
features=["_id", "knesset_number", "protocol_name", "protocol_number", "protocol_type", "session_name",
|
| 191 |
+
"parent_session_name", "@timestamp", "protocol_date", "is_ocr_output", "sentence_id",
|
| 192 |
+
"speaker_id", "speaker_name", "is_valid_speaker", "is_chairman", "turn_num_in_protocol",
|
| 193 |
+
"sent_num_in_turn", "sentence_text", "factuality_fields",
|
| 194 |
+
"speaker_first_name", "speaker_last_name", "speaker_is_knesset_member", "speaker_gender",
|
| 195 |
+
"speaker_email", "speaker_last_updated_date", "speaker_date_of_birth", "speaker_place_of_birth",
|
| 196 |
+
"speaker_year_of_aliya", "speaker_date_of_death", "speaker_mother_tongue", "speaker_religion",
|
| 197 |
+
"speaker_nationality", "speaker_religious_orientation", "speaker_residence",
|
| 198 |
+
"speaker_factions_memberships", "speaker_languages", "speaker_sources", "speaker_notes",
|
| 199 |
+
"faction_id", "faction_general_name", "knesset_faction_id", "current_faction_name",
|
| 200 |
+
"faction_popular_initials", "faction_active_periods", "faction_knesset_numbers",
|
| 201 |
+
"faction_coalition_or_opposition_memberships", "faction_political_orientation",
|
| 202 |
+
"faction_other_names", "faction_notes", "faction_wiki_link"],
|
| 203 |
+
data_urls=[
|
| 204 |
+
f"https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/resolve/main/protocols_sentences/plenary_no_morph_sentences_shards_bzip2_files/no_morph_plenary_full_sentences_shard_{str(i).zfill(2)}.jsonl.bz2" for i in range(num_plenary_shard)],
|
| 205 |
+
citation=_KnessetCorpus_CITATION,
|
| 206 |
+
),
|
| 207 |
+
KnessetCorpusConfig(
|
| 208 |
+
name="plenary_all_features_sentences",
|
| 209 |
+
description=_AllFeaturesSentences_DESCRIPTION,
|
| 210 |
+
features=[ "_id", "knesset_number", "protocol_name", "protocol_number", "protocol_type", "session_name", "parent_session_name", "@timestamp", "protocol_date", "is_ocr_output", "sentence_id", "speaker_id", "speaker_name", "is_valid_speaker", "is_chairman", "turn_num_in_protocol", "sent_num_in_turn", "sentence_text", "morphological_fields", "factuality_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", "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"],
|
| 211 |
+
data_urls=[f"https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/resolve/main/protocols_sentences/plenary_full_sentences_shards_bzip2_files/plenary_full_sentences_shard_{str(i).zfill(2)}.jsonl.bz2" for i in range(num_plenary_shard)],
|
| 212 |
+
citation=_KnessetCorpus_CITATION,
|
| 213 |
+
)]
|
| 214 |
+
|
| 215 |
+
DEFAULT_CONFIG_NAME = "all_features_sentences"
|
| 216 |
+
|
| 217 |
+
def _info(self):
|
| 218 |
+
features = {feature: datasets.Value("string") for feature in self.config.features}
|
| 219 |
+
|
| 220 |
+
if "all_features_sentences" in self.config.name:
|
| 221 |
+
if not "no_morph" in self.config.name:
|
| 222 |
+
features.update({"morphological_fields": datasets.Sequence({
|
| 223 |
+
"id": datasets.Value("string"),
|
| 224 |
+
"form": datasets.Value("string"),
|
| 225 |
+
"lemma": datasets.Value("string"),
|
| 226 |
+
"upos": datasets.Value("string"),
|
| 227 |
+
"xpos": datasets.Value("string"),
|
| 228 |
+
"feats": datasets.Value("string"),
|
| 229 |
+
"head": datasets.Value("int32"),
|
| 230 |
+
"deprel": datasets.Value("string"),
|
| 231 |
+
"deps": datasets.Value("string"),
|
| 232 |
+
"misc": datasets.Value("string")})})
|
| 233 |
+
features.update({
|
| 234 |
+
"faction_active_periods": datasets.Sequence({
|
| 235 |
+
"end_date": datasets.Value("string"), # Date converted to string
|
| 236 |
+
"start_date": datasets.Value("string"), # Date converted to string
|
| 237 |
+
}),
|
| 238 |
+
"faction_coalition_or_opposition_memberships": datasets.Sequence({
|
| 239 |
+
"end_date": datasets.Value("string"), # Date converted to string
|
| 240 |
+
"knesset_faction_name": datasets.Value("string"),
|
| 241 |
+
"knesset_num": datasets.Value("string"),
|
| 242 |
+
"member_of_coalition": datasets.Value("bool"),
|
| 243 |
+
"notes": datasets.Value("string"),
|
| 244 |
+
"start_date": datasets.Value("string") # Date converted to string
|
| 245 |
+
}),
|
| 246 |
+
"faction_other_names": datasets.Sequence({
|
| 247 |
+
"name": datasets.Value("string"),
|
| 248 |
+
"name_end_date": datasets.Value("string"), # Date converted to string
|
| 249 |
+
"name_start_date": datasets.Value("string") # Date converted to string
|
| 250 |
+
}),
|
| 251 |
+
"is_chairman": datasets.Value("bool"),
|
| 252 |
+
"is_ocr_output": datasets.Value("bool"),
|
| 253 |
+
"is_valid_speaker": datasets.Value("bool"),
|
| 254 |
+
"sent_num_in_turn": datasets.Value("int64"),
|
| 255 |
+
"turn_num_in_protocol": datasets.Value("int64"),
|
| 256 |
+
"speaker_factions_memberships": datasets.Sequence({
|
| 257 |
+
"end_date": datasets.Value("string"),
|
| 258 |
+
"faction_id": datasets.Value("string"),
|
| 259 |
+
"faction_name": datasets.Value("string"),
|
| 260 |
+
"knesset_faction_id": datasets.Value("string"),
|
| 261 |
+
"knesset_number": datasets.Value("string"),
|
| 262 |
+
"start_date": datasets.Value("string")}),
|
| 263 |
+
"speaker_is_knesset_member": datasets.Value("bool"),
|
| 264 |
+
"speaker_notes": datasets.Sequence(datasets.Value("string")),
|
| 265 |
+
"speaker_languages": datasets.Sequence(datasets.Value("string"))
|
| 266 |
+
})
|
| 267 |
+
|
| 268 |
+
if self.config.name == "protocols":
|
| 269 |
+
features.update({
|
| 270 |
+
"is_ocr_output": datasets.Value("bool"),
|
| 271 |
+
"protocol_sentences": datasets.Sequence({
|
| 272 |
+
"sentence_id": datasets.Value("string"),
|
| 273 |
+
"protocol_name": datasets.Value("string"),
|
| 274 |
+
"speaker_id": datasets.Value("string"),
|
| 275 |
+
"speaker_name": datasets.Value("string"),
|
| 276 |
+
"is_valid_speaker": datasets.Value("bool"),
|
| 277 |
+
"turn_num_in_protocol": datasets.Value("int64"),
|
| 278 |
+
"sent_num_in_turn": datasets.Value("int64"),
|
| 279 |
+
"sentence_text": datasets.Value("string"),
|
| 280 |
+
"is_chairman": datasets.Value("bool"),
|
| 281 |
+
"morphological_fields": datasets.Sequence({
|
| 282 |
+
"id": datasets.Value("string"),
|
| 283 |
+
"form": datasets.Value("string"),
|
| 284 |
+
"lemma": datasets.Value("string"),
|
| 285 |
+
"upos": datasets.Value("string"),
|
| 286 |
+
"xpos": datasets.Value("string"),
|
| 287 |
+
"feats": datasets.Value("string"),
|
| 288 |
+
"head": datasets.Value("int32"),
|
| 289 |
+
"deprel": datasets.Value("string"),
|
| 290 |
+
"deps": datasets.Value("string"),
|
| 291 |
+
"misc": datasets.Value("string"),
|
| 292 |
+
}),
|
| 293 |
+
"factuality_fields": datasets.Value("string")
|
| 294 |
+
})
|
| 295 |
+
})
|
| 296 |
+
if self.config.name == "factions":
|
| 297 |
+
features.update({
|
| 298 |
+
"active_periods": datasets.Sequence({
|
| 299 |
+
"end_date": datasets.Value("string"), # Date converted to string
|
| 300 |
+
"start_date": datasets.Value("string"), # Date converted to string
|
| 301 |
+
}),
|
| 302 |
+
"coalition_or_opposition_memberships": datasets.Sequence({
|
| 303 |
+
"end_date": datasets.Value("string"), # Date converted to string
|
| 304 |
+
"knesset_faction_name": datasets.Value("string"),
|
| 305 |
+
"knesset_num": datasets.Value("string"),
|
| 306 |
+
"member_of_coalition": datasets.Value("bool"),
|
| 307 |
+
"notes": datasets.Value("string"),
|
| 308 |
+
"start_date": datasets.Value("string"), # Date converted to string
|
| 309 |
+
}),
|
| 310 |
+
"other_names": datasets.Sequence({
|
| 311 |
+
"name": datasets.Value("string"),
|
| 312 |
+
"name_end_date": datasets.Value("string"), # Date converted to string
|
| 313 |
+
"name_start_date": datasets.Value("string"), # Date converted to string
|
| 314 |
+
})
|
| 315 |
+
})
|
| 316 |
+
if self.config.name == "KnessetMembers":
|
| 317 |
+
features.update({
|
| 318 |
+
"is_knesset_member": datasets.Value("bool"),
|
| 319 |
+
"factions_memberships": datasets.Sequence({
|
| 320 |
+
"end_date": datasets.Value("string"),
|
| 321 |
+
"faction_id": datasets.Value("string"),
|
| 322 |
+
"faction_name": datasets.Value("string"),
|
| 323 |
+
"knesset_faction_id": datasets.Value("string"),
|
| 324 |
+
"knesset_number": datasets.Value("string"),
|
| 325 |
+
"start_date": datasets.Value("string")}),
|
| 326 |
+
"notes": datasets.Sequence(datasets.Value("string")),
|
| 327 |
+
"languages": datasets.Sequence(datasets.Value("string"))
|
| 328 |
+
})
|
| 329 |
+
|
| 330 |
+
return datasets.DatasetInfo(
|
| 331 |
+
description=_KnessetCorpus_DESCRIPTION + self.config.description,
|
| 332 |
+
features=datasets.Features(features),
|
| 333 |
+
citation=self.config.citation
|
| 334 |
+
)
|
| 335 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 336 |
+
urls = self.config.data_urls
|
| 337 |
+
downloaded_files = dl_manager.download_and_extract(urls)
|
| 338 |
+
|
| 339 |
+
# Handle single file case
|
| 340 |
+
if not isinstance(downloaded_files, list):
|
| 341 |
+
downloaded_files = [downloaded_files]
|
| 342 |
+
|
| 343 |
+
# Only process if we detect zip files
|
| 344 |
+
if any('zip://' in str(file) for file in downloaded_files):
|
| 345 |
+
extracted_files = []
|
| 346 |
+
for file_path in downloaded_files:
|
| 347 |
+
# Remove the zip:// prefix and download the actual zip content
|
| 348 |
+
actual_url = str(file_path).replace('zip://::', '')
|
| 349 |
+
extracted = dl_manager.download_and_extract(actual_url)
|
| 350 |
+
|
| 351 |
+
# If it's a directory, get all files inside
|
| 352 |
+
if os.path.isdir(extracted):
|
| 353 |
+
for root, _, files in os.walk(extracted):
|
| 354 |
+
for filename in files:
|
| 355 |
+
full_path = os.path.join(root, filename)
|
| 356 |
+
extracted_files.append(full_path)
|
| 357 |
+
else:
|
| 358 |
+
extracted_files.append(extracted)
|
| 359 |
+
|
| 360 |
+
data_files = extracted_files
|
| 361 |
+
else:
|
| 362 |
+
data_files = downloaded_files
|
| 363 |
+
|
| 364 |
+
return [
|
| 365 |
+
datasets.SplitGenerator(
|
| 366 |
+
name=datasets.Split.TRAIN,
|
| 367 |
+
gen_kwargs={
|
| 368 |
+
"data_files": data_files,
|
| 369 |
+
},
|
| 370 |
+
),
|
| 371 |
+
]
|
| 372 |
+
|
| 373 |
+
def _generate_examples(self, data_files):
|
| 374 |
+
if "all_features_sentences" in self.config.name:
|
| 375 |
+
id_field_name = "sentence_id"
|
| 376 |
+
elif self.config.name == "protocols":
|
| 377 |
+
id_field_name = "protocol_name"
|
| 378 |
+
elif self.config.name == "factions":
|
| 379 |
+
id_field_name = "faction_id"
|
| 380 |
+
elif self.config.name == "knessetMembers":
|
| 381 |
+
id_field_name = "person_id"
|
| 382 |
+
|
| 383 |
+
for i, filepath in enumerate(data_files):
|
| 384 |
+
try:
|
| 385 |
+
with open(filepath, encoding="utf-8") as f:
|
| 386 |
+
for line in f:
|
| 387 |
+
sample = {}
|
| 388 |
+
try:
|
| 389 |
+
row = json.loads(line)
|
| 390 |
+
except Exception as e:
|
| 391 |
+
print(f'couldnt load sample. error was: {e}. Continuing to next sample')
|
| 392 |
+
continue
|
| 393 |
+
id_ = row.get(id_field_name, None)
|
| 394 |
+
if id_ is None:
|
| 395 |
+
print(f"Key '{id_field_name}' not found in row. Skipping this row. row is: {row}")
|
| 396 |
+
continue
|
| 397 |
+
for feature in self._info().features:
|
| 398 |
+
if feature == "protocol_sentences":
|
| 399 |
+
protocol_sentences = row.get("protocol_sentences", [])
|
| 400 |
+
# Ensure protocol_sentences is a list of dictionaries
|
| 401 |
+
if isinstance(protocol_sentences, dict):
|
| 402 |
+
protocol_sentences = list(protocol_sentences.values())
|
| 403 |
+
elif not isinstance(protocol_sentences, list):
|
| 404 |
+
print(f"'protocol_sentences' is not a list or dict. Skipping this row. Row: {row}")
|
| 405 |
+
continue
|
| 406 |
+
sample[feature] = protocol_sentences
|
| 407 |
+
else:
|
| 408 |
+
sample[feature] = row.get(feature, None)
|
| 409 |
+
|
| 410 |
+
try:
|
| 411 |
+
yield id_, sample
|
| 412 |
+
except Exception as e:
|
| 413 |
+
print(f'couldnt yield sample. error: {e}. sample is: {sample}.', flush=True)
|
| 414 |
+
except Exception as e:
|
| 415 |
+
print(f"Error opening file '{filepath}': {e}. Skipping.")
|
| 416 |
+
|
| 417 |
+
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
|