Sha256: e3e7c91ad39f037efcd8233fdfe36a69db2ff328d4ffa4172b5d3a3f078cb0c7
Contents?: true
Size: 803 Bytes
Versions: 9
Compression:
Stored size: 803 Bytes
Contents
#!/usr/bin/ruby -w # # Find all the hypernyms of all senses of a given noun and display them in a # heirarchy # $LOAD_PATH.unshift "lib" require 'wordnet' raise RuntimeError, "No word specified." if ARGV.empty? # Create the lexicon lex = WordNet::Lexicon.new # Look up the synsets for the specified word origins = lex.lookup_synsets( ARGV[0], WordNet::Noun ) # Use the analyzer to traverse hypernyms of the synset, adding a string for each # one with indentation for the level origins.each_index {|i| treeComponents = [] origins[i].traverse( :hypernyms ) {|syn,depth| treeComponents << " #{' ' * depth}#{syn.words[0]} -- #{syn.gloss.split(/;/)[0]}" } puts "\nHypernym tree for sense #{i} of #{ARGV[0]}:\n" + treeComponents.join( "\n" ) puts "Tree has #{treeComponents.length} synsets." }
Version data entries
9 entries across 9 versions & 1 rubygems