Skip to content

Instantly share code, notes, and snippets.

@jcsalterego
Created October 8, 2009 02:31
Show Gist options
  • Select an option

  • Save jcsalterego/204651 to your computer and use it in GitHub Desktop.

Select an option

Save jcsalterego/204651 to your computer and use it in GitHub Desktop.
#!/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