Skip to content

Commit

Permalink
more debugging csv rtl
Browse files Browse the repository at this point in the history
  • Loading branch information
sterlingwes committed Feb 12, 2024
1 parent de44380 commit 113092a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 0 additions & 1 deletion scripts/data/common/killed-in-gaza/data/dict_ar_ar.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
original,cleaned
عبد الله,عبدالله
ابو ,ابو
بهاء الدين,بهاءالدين
Expand Down
19 changes: 12 additions & 7 deletions scripts/data/common/killed-in-gaza/generate_killed_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ const pwd = "scripts/data/common/killed-in-gaza";
const arRawNameColumnLabel = "name_ar_raw";
const arEnNameColumnLabel = "name_en";

const readCsv = (repoPath: string) => {
const readCsv = (repoPath: string, rtl: boolean) => {
const csvString = fs.readFileSync(repoPath).toString();
return csvString.split(/\r?\n/g).map((row) => row.split(","));
return csvString.split(/\r?\n/g).map((row) => {
if (rtl) {
console.log(">>", row);
}
const ltrRow = row.replace(/\u200f/u, "");
return ltrRow.split(",");
});
};

/**
* read a CSV file and return an object lookup ("dict") with keys
* as the first CSV column value, and values as the second CSV column
*/
const readCsvToDict = (repoPath: string) => {
return readCsv(repoPath).reduce(
const readCsvToDict = (repoPath: string, rtl = false) => {
return readCsv(repoPath, rtl).reduce(
(dict, row) => ({
...dict,
[row[0]]: row[1],
Expand All @@ -24,9 +30,8 @@ const readCsvToDict = (repoPath: string) => {
);
};

const rawList = readCsv(`${pwd}/data/raw.csv`);
const arToAr = readCsvToDict(`${pwd}/data/dict_ar_ar.csv`);
console.log(arToAr);
const rawList = readCsv(`${pwd}/data/raw.csv`, false);
const arToAr = readCsvToDict(`${pwd}/data/dict_ar_ar.csv`, true);
const arToEn = readCsvToDict(`${pwd}/data/dict_ar_en.csv`);

const [rawHeaderRow, ...rawListRows] = rawList;
Expand Down

0 comments on commit 113092a

Please sign in to comment.