Upload knessetCorpus.py
Browse files- knessetCorpus.py +11 -12
knessetCorpus.py
CHANGED
@@ -120,7 +120,7 @@ class KnessetCorpus(datasets.GeneratorBasedBuilder):
|
|
120 |
name="plenary_all_features_sentences",
|
121 |
description=_AllFeaturesSentences_DESCRIPTION,
|
122 |
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"],
|
123 |
-
data_urls=["https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/resolve/main/protocols_sentences/
|
124 |
citation=_KnessetCorpus_CITATION,
|
125 |
)]
|
126 |
|
@@ -268,25 +268,24 @@ class KnessetCorpus(datasets.GeneratorBasedBuilder):
|
|
268 |
id_field_name = "person_id"
|
269 |
|
270 |
for i, filepath in enumerate(data_files):
|
271 |
-
print(f'i:{i}')
|
272 |
-
print(f'filepath: {filepath}')
|
273 |
-
|
274 |
with open(filepath, encoding="utf-8") as f:
|
275 |
for line in f:
|
276 |
sample = {}
|
277 |
try:
|
278 |
row = json.loads(line)
|
279 |
-
id_ = row.get(id_field_name, None)
|
280 |
-
if id_ is None:
|
281 |
-
print(f"Key '{id_field_name}' not found in row. Skipping this row.")
|
282 |
-
continue
|
283 |
-
for feature in self._info().features:
|
284 |
-
sample[feature] = row[feature]
|
285 |
-
yield id_, sample
|
286 |
-
|
287 |
except Exception as e:
|
288 |
print(f'couldnt load sample. error was: {e}. Continuing to next sample')
|
289 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
|
291 |
|
292 |
|
|
|
120 |
name="plenary_all_features_sentences",
|
121 |
description=_AllFeaturesSentences_DESCRIPTION,
|
122 |
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"],
|
123 |
+
data_urls=["https://huggingface.co/datasets/HaifaCLGroup/KnessetCorpus/resolve/main/protocols_sentences/plenary_female_sentences.jsonl.bz2"],#TODO change to plenary and not female
|
124 |
citation=_KnessetCorpus_CITATION,
|
125 |
)]
|
126 |
|
|
|
268 |
id_field_name = "person_id"
|
269 |
|
270 |
for i, filepath in enumerate(data_files):
|
|
|
|
|
|
|
271 |
with open(filepath, encoding="utf-8") as f:
|
272 |
for line in f:
|
273 |
sample = {}
|
274 |
try:
|
275 |
row = json.loads(line)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
276 |
except Exception as e:
|
277 |
print(f'couldnt load sample. error was: {e}. Continuing to next sample')
|
278 |
continue
|
279 |
+
id_ = row.get(id_field_name, None)
|
280 |
+
if id_ is None:
|
281 |
+
print(f"Key '{id_field_name}' not found in row. Skipping this row. row is: {row}")
|
282 |
+
continue
|
283 |
+
for feature in self._info().features:
|
284 |
+
sample[feature] = row[feature]
|
285 |
+
try:
|
286 |
+
yield id_, sample
|
287 |
+
except Exception as e:
|
288 |
+
print(f'couldnt yield sample. error: {e}. sample is: {sample}.')
|
289 |
|
290 |
|
291 |
|