Sha256: bec5718117f3074dbcb1a6218b3eeb2298d32076893dcc5814d68b6ae028f774

Contents?: true

Size: 809 Bytes

Versions: 9

Compression:

Stored size: 809 Bytes

Contents

#!/usr/bin/ruby -w
#
#	Find all meronyms (components) of each sense of a given noun and display
#	them heirarchically
#

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

	puts "\nMeronym 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/meronymTree.rb
wordnet-1.0.0.pre.141 examples/meronymTree.rb
wordnet-1.0.0.pre.140 examples/meronymTree.rb
wordnet-1.0.0.pre.139 examples/meronymTree.rb
wordnet-1.0.0.pre.136 examples/meronymTree.rb
wordnet-1.0.0.pre.134 examples/meronymTree.rb
wordnet-1.0.0.pre.127 examples/meronymTree.rb
wordnet-1.0.0.pre.126 examples/meronymTree.rb
wordnet-0.0.5 examples/meronymTree.rb