Created
May 6, 2018 10:10
-
-
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
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
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