class WordNet #TODO end #If the result is an array, then the array's contents will be printed in a sorted and space-delimited string. #Otherwise, the result is printed as-is def print_res(res) if (res.instance_of? Array) then str = "" res.sort.each {|elem| str += elem.to_s + " "} puts str.chomp else puts res end end #Checks that the user has provided an appropriate amount of arguments if (ARGV.length < 3 || ARGV.length > 5) then fail "usage: wordnet.rb " end synsets_file = ARGV[0] hypernyms_file = ARGV[1] command = ARGV[2] input_file = ARGV[3] wordnet = WordNet.new(synsets_file, hypernyms_file) #Refers to number of lines in input file commands_with_0_input = %w(edges nouns) commands_with_1_input = %w(isnoun outcast) commands_with_2_input = %w(length ancestor) #Executes the program according to the provided mode case command when *commands_with_0_input puts wordnet.send(command) when *commands_with_1_input file = File.open(input_file) nouns = file.gets.split(/\s/) file.close print_res(wordnet.send(command, nouns)) when *commands_with_2_input file = File.open(input_file) v = file.gets.split(/\s/).map(&:to_i) w = file.gets.split(/\s/).map(&:to_i) file.close print_res(wordnet.send(command, v, w)) when "root" file = File.open(input_file) v = file.gets.strip w = file.gets.strip file.close print_res(wordnet.send(command, v, w)) else fail "Invalid command" end