Skip to content

Instantly share code, notes, and snippets.

@mwhooker
Last active December 24, 2015 23:08
Show Gist options
  • Save mwhooker/6877457 to your computer and use it in GitHub Desktop.
Save mwhooker/6877457 to your computer and use it in GitHub Desktop.
require "wordnet"
@lex = WordNet::Lexicon.new
def inflections(candidate)
ss = @lex.lookup_synsets(candidate, WordNet::Noun)
ss.collect { |syn|
(syn.hypernyms + syn.hyponyms).collect { |hw| hw.words }
}.flatten.collect { |word|
word.lemma.gsub(/[\s-]/, '_')
}
end
puts "*cow*: \n", inflections('cow')
puts "\n\n*kine*: \n", inflections('kine')
[mwhooker@Wolfe:~]$ ruby inflections.rb 17:25:29
*cow*:
eutherian
eutherian_mammal
placental
placental_mammal
bos_taurus
cattle
cows
kine
oxen
springer
springing_cow
heifer
disagreeable_woman
unpleasant_woman
*kine*:
bovine
ox
stirk
bullock
steer
bull
cow
moo_cow
beef
beef_cattle
welsh
welsh_black
red_poll
africander
dairy_cattle
dairy_cow
milch_cow
milcher
milk_cow
milker
devon
grade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment