-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script to convert dictionary file from TSV to JSON
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |