Skip to content

Commit

Permalink
Implement most of external data seeding
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsilvestre committed Nov 2, 2023
1 parent 737ef7a commit ae3b1d4
Show file tree
Hide file tree
Showing 28 changed files with 410,426 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ node_modules
/postgres-data

/app/styles/tailwind.css

/app/lib/vendor
/app/lib/dic
3,874 changes: 3,874 additions & 0 deletions app/lib/dic/sbgy.json

Large diffs are not rendered by default.

4,601 changes: 4,601 additions & 0 deletions app/lib/dic/sbgyNotes.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions app/lib/files.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@ import path from "path";
export const files = {
kanjidicInput1: vendor("kanjidic/kanji_bank_1.json"),
kanjidicInput2: vendor("kanjidic/kanji_bank_2.json"),
unihanReadings15: vendor("unihan/Unihan_Readings.txt"),
unihanVariants12: vendor("unihan/Unihan_Variants_12.txt"),
unihanVariants14: vendor("unihan/Unihan_Variants_14.txt"),
kanjiDbOldStyle: vendor("kanjiDb/jp-old-style.txt"),
kanjiDbHyogaiVariants: vendor("kanjiDb/hyogai-variants.txt"),
kanjiDbJinmeiVariants: vendor("kanjiDb/jinmei-variants.txt"),
kanjiDbBorrowedInput: vendor("kanjiDb/jp-borrowed.txt"),
kanjiDbTwEduVariants: vendor("kanjiDb/twedu-variants.txt"),
kanjiDbHanyuDaCidianVariants: vendor("kanjiDb/hydzd-variants.txt"),
kanjiDbIdsCdpTxt: vendor("kanjiDb/ids-cdp.txt"),
kanjiDbAnalysisTxt: vendor("kanjiDb/ids-analysis.txt"),
sbgyJson: dic("sbgy.json"),
sbgyNotesJson: dic("sbgyNotes.json"),
};

function vendor<S extends string>(string: S) {
return path.resolve(__dirname, "vendor", string) as `${string}/vendor/${S}`;
}
function dic<S extends string>(string: S) {
return path.resolve(__dirname, "dic", string) as `${string}/vendor/${S}`;
}

function readTextFileSync<T>(filepath: string) {
return fs.readFileSync(filepath, "utf-8") as T;
Expand Down
25 changes: 25 additions & 0 deletions app/lib/forEachLine.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import fs from "fs";
import readline from "readline";

export type LineReader = readline.Interface;

export async function getLineReader(filename: string): Promise<LineReader> {
const fileStream = fs.createReadStream(filename);

const rl = readline.createInterface({
input: fileStream,
// recognize all instances of CR LF
// ('\r\n') in input as a single line break.
crlfDelay: Infinity,
});
return rl;
}
export async function forEachLine(
filename: string,
callback: (line: string) => void
) {
const rl = await getLineReader(filename);
for await (const line of rl) {
callback(line);
}
}
Loading

0 comments on commit ae3b1d4

Please sign in to comment.