From 911424bfe31d511dda25494d3db79c37d7f40197 Mon Sep 17 00:00:00 2001 From: Wes Johnson Date: Mon, 12 Feb 2024 12:58:32 -0500 Subject: [PATCH] handle CI reading RTL csv wrong way --- .../killed-in-gaza/generate_killed_list.ts | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/scripts/data/common/killed-in-gaza/generate_killed_list.ts b/scripts/data/common/killed-in-gaza/generate_killed_list.ts index 4d180fa2..a8ba81d4 100644 --- a/scripts/data/common/killed-in-gaza/generate_killed_list.ts +++ b/scripts/data/common/killed-in-gaza/generate_killed_list.ts @@ -5,23 +5,17 @@ const pwd = "scripts/data/common/killed-in-gaza"; const arRawNameColumnLabel = "name_ar_raw"; const arEnNameColumnLabel = "name_en"; -const readCsv = (repoPath: string, rtl: boolean) => { +const readCsv = (repoPath: string) => { const csvString = fs.readFileSync(repoPath).toString(); - return csvString.split(/\r?\n/g).map((row) => { - if (rtl) { - console.log(">>", row); - } - const ltrRow = row.replace(/\u200f/u, ""); - return ltrRow.split(","); - }); + return csvString.split(/\r?\n/g).map((row) => row.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, rtl = false) => { - return readCsv(repoPath, rtl).reduce( +const readCsvToDict = (repoPath: string) => { + return readCsv(repoPath).reduce( (dict, row) => ({ ...dict, [row[0]]: row[1], @@ -30,10 +24,19 @@ const readCsvToDict = (repoPath: string, rtl = false) => { ); }; -const rawList = readCsv(`${pwd}/data/raw.csv`, false); -const arToAr = readCsvToDict(`${pwd}/data/dict_ar_ar.csv`, true); +const rawList = readCsv(`${pwd}/data/raw.csv`); +let arToAr = readCsvToDict(`${pwd}/data/dict_ar_ar.csv`); const arToEn = readCsvToDict(`${pwd}/data/dict_ar_en.csv`); +// if this matches, our ar->ar dict was read backwards and we need to flip it +if (arToAr["ابوالليل"]) { + console.log("⚠️ inverting ar->ar which was read LTR"); + arToAr = Object.entries(arToAr).reduce( + (flipped, [key, value]) => ({ ...flipped, [value]: key }), + {} + ); +} + const [rawHeaderRow, ...rawListRows] = rawList; const arRawColumn = rawHeaderRow.indexOf(arRawNameColumnLabel); if (arRawColumn === -1) {