Created
October 8, 2009 02:31
-
-
Save jcsalterego/204651 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/ruby -w | |
| CORPUS = 'magnus.tsv' | |
| RE_SKIPLIST = [ /^\#/, | |
| /^http:/ ] | |
| class Oracle | |
| def initialize(corpus) | |
| @corpus = corpus | |
| end | |
| def foretell | |
| File.open(CORPUS).each do |line| | |
| id, text = line.split("\t") | |
| id = id.to_i | |
| next line if not id | |
| words = text.downcase.split | |
| words_ = [] | |
| for word in words do | |
| if RE_SKIPLIST.any? { |re| word =~ re } | |
| next word | |
| end | |
| # otherwise, add to words | |
| words_ << word | |
| end | |
| puts words_ | |
| end | |
| end | |
| end | |
| def main | |
| o = Oracle.new(CORPUS) | |
| o.foretell | |
| 0 | |
| end | |
| if __FILE__ == $0 | |
| exit main | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment