Sha256: a93002611550505a827616d6e8badf2da353e104434e117a601bf4ca628f8067

Contents?: true

Size: 768 Bytes

Versions: 3

Compression:

Stored size: 768 Bytes

Contents

#!/usr/bin/env ruby
#encoding: utf-8

#
#	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 )


# Iterate over the synsets for the different senses of the word
origins.each.with_index do |syn, i|
	hypernyms = []

	# Traverse the hypernyms
	syn.traverse( :hypernyms ).with_depth.each do |hyper_syn, depth|
		indent = '  ' * depth
		hypernyms << "%s%s" % [ indent, hyper_syn ]
	end

	puts "\nHypernym tree for #{syn} (sense #{i + 1}):", *hypernyms
	puts "Tree has #{hypernyms.length} synsets."
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wordnet-1.1.1 examples/hypernym_tree.rb
wordnet-1.1.0 examples/hypernym_tree.rb
wordnet-1.0.1 examples/hypernym_tree.rb