Sha256: 4eaa4be926f7db1f621882e70e05cf067785810fa71792a6e88d3153f3e3f76f

Contents?: true

Size: 799 Bytes

Versions: 9

Compression:

Stored size: 799 Bytes

Contents

#!/usr/bin/ruby -w
#
#	Find all the hyponyms 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 hyponyms of the synset, adding a string for each
# one with indentation for the level
origins.each_index {|i|
	treeComponents = []
	origins[i].traverse( :hyponyms ) {|syn,depth|
		treeComponents << "  #{'  ' * depth}#{syn.words[0]} -- #{syn.gloss.split(/;/)[0]}"
	}

	puts "\nHyponym 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

Version Path
wordnet-1.0.0 examples/hyponymTree.rb
wordnet-1.0.0.pre.141 examples/hyponymTree.rb
wordnet-1.0.0.pre.140 examples/hyponymTree.rb
wordnet-1.0.0.pre.139 examples/hyponymTree.rb
wordnet-1.0.0.pre.136 examples/hyponymTree.rb
wordnet-1.0.0.pre.134 examples/hyponymTree.rb
wordnet-1.0.0.pre.127 examples/hyponymTree.rb
wordnet-1.0.0.pre.126 examples/hyponymTree.rb
wordnet-0.0.5 examples/hyponymTree.rb