{"id":55,"date":"2015-11-23T20:40:21","date_gmt":"2015-11-23T15:10:21","guid":{"rendered":"http:\/\/madhurendra.com\/?p=55"},"modified":"2015-11-23T21:12:38","modified_gmt":"2015-11-23T15:42:38","slug":"converting-opensource-dictionary-to-json","status":"publish","type":"post","link":"https:\/\/madhurendra.com\/converting-opensource-dictionary-to-json\/","title":{"rendered":"Converting Opensource Dictionary to JSON"},"content":{"rendered":"
Folddoc provide free online computer dictionary but they don’t have any standard tool or format to import dictionary in database or so.<\/p>\n
Dictionary can be downloaded form http:\/\/foldoc.org\/Dictionary.txt<\/p>\n
Run the following nodejs code it will dump dictionary to OUTPUT.json and don’t forget to remove initial lines of disclaimer or they will add to your dictionary.<\/p>\n
var fs = require(\"fs\");\r\nvar words=[];\r\nvar word,meaning=\"\";\r\nfs.readFileSync('.\/Dictionary.txt').toString().split('\\n').forEach(function (line) { \r\n\tif(line.length==0){\r\n\t\tmeaning+=\"\\n\";\r\n\t\treturn;\r\n\t}\r\n if(line.indexOf(\"\\t\")==0)\r\n\t\tmeaning+=line.trim()+\"\\n\";\r\n\telse{\r\n\t\tif(meaning.length>0)\r\n\t\t\twords.push({title:word,definition:meaning.trim()});\r\n\t\tword = line.trim();\r\n\t\tmeaning = \"\";\r\n\t}\r\n \r\n});\r\n\r\nfs.appendFileSync(\".\/output.json\", JSON.stringify(words));\r\n<\/pre>\nif you want to import to mongo use `mongoimport –db mad –collection foldoc –file foldoc.json –jsonArray`<\/p>\n
At time of writing this article it had 15093 terms but importing resulted in 15110 documents, this might be because of some false positive.<\/p>\n","protected":false},"excerpt":{"rendered":"
Folddoc provide free online computer dictionary but they don’t have any standard tool or format to import dictionary in database or so. Dictionary can be downloaded form http:\/\/foldoc.org\/Dictionary.txt Run the following nodejs code it will dump dictionary to OUTPUT.json and don’t forget to remove initial lines of disclaimer or they will add to your dictionary. … <\/p>\n