Update ultimate_arabic_news.py
Browse files- ultimate_arabic_news.py +31 -0
ultimate_arabic_news.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import csv
|
2 |
import datasets
|
3 |
import os
|
|
|
4 |
|
5 |
_DESCRIPTION = "TODO"
|
6 |
|
@@ -70,5 +71,35 @@ class Ultimate_Arabic_News(datasets.GeneratorBasedBuilder):
|
|
70 |
)
|
71 |
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
|
|
1 |
import csv
|
2 |
import datasets
|
3 |
import os
|
4 |
+
import textwrap
|
5 |
|
6 |
_DESCRIPTION = "TODO"
|
7 |
|
|
|
71 |
)
|
72 |
|
73 |
|
74 |
+
def _split_generators(self, dl_manager):
|
75 |
+
"""Returns SplitGenerators."""
|
76 |
+
# TODO(tydiqa): Downloads the data and defines the splits
|
77 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to
|
78 |
+
# download and extract URLs
|
79 |
+
UltAr_downloaded = dl_manager.download_and_extract(_URL['UltimateArabic'])
|
80 |
+
UltArPre_downloaded = dl_manager.download_and_extract(_URL['UltimateArabicPrePros'])
|
81 |
+
if self.config.name == "UltimateArabic":
|
82 |
+
return [
|
83 |
+
datasets.SplitGenerator(
|
84 |
+
name=datasets.Split.TRAIN,
|
85 |
+
# These kwargs will be passed to _generate_examples
|
86 |
+
gen_kwargs={"filepath": UltAr_downloaded["train"]},
|
87 |
+
),
|
88 |
+
]
|
89 |
+
elif self.config.name == "UltimateArabicPrePros":
|
90 |
+
return [
|
91 |
+
datasets.SplitGenerator(
|
92 |
+
name=datasets.Split.TRAIN,
|
93 |
+
# These kwargs will be passed to _generate_examples
|
94 |
+
gen_kwargs={"filepath": UltArPre_downloaded["train"]},
|
95 |
+
),
|
96 |
|
97 |
+
]
|
98 |
+
|
99 |
+
def _generate_examples(self, csv_file):
|
100 |
+
with open(csv_file, encoding="utf-8") as f:
|
101 |
+
data = csv.DictReader(f)
|
102 |
+
for row, item in enumerate(data):
|
103 |
+
yield row, {"text": item['text'],"label": item['label']}
|
104 |
+
|
105 |
|