Skip to content

Instantly share code, notes, and snippets.

@brapse
Created April 7, 2009 04:13
Show Gist options
  • Save brapse/91096 to your computer and use it in GitHub Desktop.
Save brapse/91096 to your computer and use it in GitHub Desktop.
lex = WordNet::Lexicon.new
collection = []
current = ""
while true
trap("INT") do
Process.exit
end
begin
system("stty raw -echo")
str = STDIN.getc
ensure
system("stty -raw echo")
end
if str.chr == " "
#new word
origins = lex.lookup_synsets( current, WordNet::Noun )
if origins
# its a nouse
output = origins.map{|x| x.traverse(:hypernyms).first.gloss.join(', ')}
puts output
end
puts current
collection << current
current = ""
else
# add to the word
print str.chr
current << str.chr
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment