Skip to content

Instantly share code, notes, and snippets.

@james-irwin
Created May 6, 2018 10:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save james-irwin/4dd88550a3faa50390b9854e0a5a37e0 to your computer and use it in GitHub Desktop.
Save james-irwin/4dd88550a3faa50390b9854e0a5a37e0 to your computer and use it in GitHub Desktop.
Collapse word pairs into a dictionary -- see http://james-irwin.github.io/#backwell
var fs=require('fs');
if (process.argv[2] == null)
{
console.error('Provide a filename');
return;
}
var fileBuf=fs.readFileSync(process.argv[2]).toString();
var lines=fileBuf.split('\n');
var wordlist={};
var i=0;
for (; i<lines.length-1; i++) {
var o=JSON.parse(lines[i]);
var keyword=Object.keys(o)[0];
if (typeof wordlist[keyword] == "undefined") {
wordlist[keyword]=[];
}
wordlist[keyword].push(o[keyword]);
}
console.log("var dict=" + JSON.stringify(wordlist) + ";");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment