JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
coffeescript to filter by huge wordlist
authorJason Woofenden <jason@jasonwoof.com>
Thu, 8 Nov 2012 07:35:26 +0000 (02:35 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Thu, 8 Nov 2012 07:35:26 +0000 (02:35 -0500)
spellcheck.coffee [new file with mode: 0644]

diff --git a/spellcheck.coffee b/spellcheck.coffee
new file mode 100644 (file)
index 0000000..0779356
--- /dev/null
@@ -0,0 +1,30 @@
+fs = require 'fs'
+async = require 'async'
+
+dict = {}
+
+async.waterfall [
+       (callback) -> async.parallel [
+               (callback) -> fs.readFile '/etc/dictionaries-common/words', 'utf8', callback
+               (callback) -> fs.readFile 'my_log_words', 'utf8', callback
+       ], callback
+       ([dictionary, log_words], callback) ->
+               for word in dictionary.split(/\n/)
+                       dict[word] = true
+               good = []
+               for line in log_words.split(/\n/)
+                       word = line[line.lastIndexOf(' ')+1..]
+                       if dict[word]
+                               good.push word
+                               if good.length == 8836
+                                       return callback(null, good)
+               callback 'could find enough real words'
+       (words, callback) ->
+               for word in words
+                       console.log word
+               callback()
+       ], (err) ->
+               if err
+                       console.log err
+                       process.exit 1
+               process.exit 0