Skip to content

Commit

Permalink
Script to convert dictionary file from TSV to JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
kbseah committed Dec 26, 2024
1 parent 4587678 commit fe2c5a5
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tsv2json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env node
// Convert TSV formatted dictionary table to JSON format

const fs = require("fs");
const readline = require("readline");

// main ----------------------------------------------------------------------

// read in dictionary data
let chardict = {};
const dicttsv = fs.readFileSync("dieziu_gdpi.dict.tsv", "utf-8");
dicttsv.split(/\r?\n/).forEach(line => {
try {
let [han, pengim] = line.split(/\t/);
if ( han in chardict ) {
chardict[han].push(pengim);
} else {
chardict[han] = [pengim];
}
} catch(err) {
console.error(err);
}
});

fs.writeFile('dieziu_gdpi.dict.json', JSON.stringify(chardict), (err) => {
console.log(err);
});

0 comments on commit fe2c5a5

Please sign in to comment.