Datasets:

Modalities:
Text
Formats:
csv
Languages:
Arabic
Libraries:
Datasets
pandas
License:
Imane Momayiz commited on
Commit
28ce7f8
0 Parent(s):

feat: darija sentences from doda

Browse files
Files changed (3) hide show
  1. .gitignore +4 -0
  2. data.csv +0 -0
  3. src/ingestion.py +40 -0
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ .env
2
+ venv/
3
+ ongoing/
4
+ *.ipynb
data.csv ADDED
The diff for this file is too large to render. See raw diff
 
src/ingestion.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import tqdm
3
+ import csv
4
+ import pandas as pd
5
+
6
+
7
+ def get_darija_values(file):
8
+ """This function reads the darija column from a csv file and returns
9
+ a generator of the values in the column.
10
+ """
11
+ with open(file, 'r', encoding='utf-8') as infile:
12
+ reader = csv.reader(infile)
13
+ headers = next(reader)
14
+ for i, col in enumerate(headers):
15
+ if col=='darija':
16
+ break
17
+ for row in reader:
18
+ if row[i] != "":
19
+ yield row[i]
20
+
21
+
22
+ def ingest(input_data_path="ongoing/", output_data_path="data.csv"):
23
+ """This function reads all the csv files in the input_data_path and extracts the
24
+ darija column from each file. It then saves the darija column in a csv file.
25
+ """
26
+ full_df = pd.DataFrame()
27
+ text_list = []
28
+
29
+ for file in tqdm.tqdm(os.listdir(input_data_path)):
30
+ if file.endswith(".csv"):
31
+ darija_txt = list(get_darija_values(input_data_path + file))
32
+ text_list.extend(darija_txt)
33
+ full_df = pd.concat([full_df, pd.DataFrame(darija_txt, columns=["darija"])])
34
+
35
+ full_df.to_csv(output_data_path, index=False)
36
+ print("Ingestion complete")
37
+
38
+
39
+ if __name__ == "__main__":
40
+ ingest("ongoing/")