Datasets:

Modalities:
Text
Formats:
csv
Languages:
Arabic
Libraries:
Datasets
pandas
License:
File size: 1,233 Bytes
28ce7f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import tqdm
import csv
import pandas as pd


def get_darija_values(file):
    """This function reads the darija column from a csv file and returns 
    a generator of the values in the column.
    """
    with open(file, 'r', encoding='utf-8') as infile:
        reader = csv.reader(infile)
        headers = next(reader)
        for i, col in enumerate(headers):
            if col=='darija':
                break
        for row in reader:
            if row[i] != "":
                yield row[i]


def ingest(input_data_path="ongoing/", output_data_path="data.csv"):
    """This function reads all the csv files in the input_data_path and extracts the 
    darija column from each file. It then saves the darija column in a csv file.
    """
    full_df = pd.DataFrame()
    text_list = []

    for file in tqdm.tqdm(os.listdir(input_data_path)):
        if file.endswith(".csv"):
            darija_txt = list(get_darija_values(input_data_path + file))
            text_list.extend(darija_txt)
            full_df = pd.concat([full_df, pd.DataFrame(darija_txt, columns=["darija"])])

    full_df.to_csv(output_data_path, index=False)
    print("Ingestion complete")


if __name__ == "__main__":
    ingest("ongoing/")