{"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>\n

if 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

Continue reading<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[8,1],"tags":[12,9,11],"class_list":["post-55","post","type-post","status-publish","format-standard","hentry","category-snippets","category-uncategorized","tag-dictionary","tag-mongodb","tag-nodejs","item-wrap"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pciGs2-T","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/posts\/55","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/comments?post=55"}],"version-history":[{"count":5,"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/posts\/55\/revisions"}],"predecessor-version":[{"id":60,"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/posts\/55\/revisions\/60"}],"wp:attachment":[{"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/media?parent=55"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/categories?post=55"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/madhurendra.com\/wp-json\/wp\/v2\/tags?post=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}