user6335896 user6335896 - 4 months ago 42
Ruby Question

Can't find syntax error, unexpected end-of-input, expecting keyword_end

Could someone please help me find the syntax error, its supposed to by occurring on line 78. At this point I am convinced there isn

#!/usr/bin/env ruby

$LOAD_PATH.unshift "lib"
require 'wordnet'
require 'pp'


print_synsets = false



lex = WordNet::Lexicon.new

puts "Hello! I'm Complainbot. To stop talking to enter \'cya\'. What would you like to complain about today?\n\n"
user_response = gets.chomp

while not user_response.include? "cya" do
puts

if is_command?(user_response)
handle_commands(user_response)
else
establish_context(user_response)
end

puts

user_response = gets.chomp
end



def establish_context(sentence)
nouns = get_nouns(sentence)
puts nouns
end


def get_nouns(sentence)
words = sentence.strip.split(' ')
nouns_in_sentence = []

words.each do |word|
word_synsets = lex.lookup_synsets(word)

if print_synsets do PP.pp(word_synsets) end

word_synsets.each do |synset|
nouns = synset.nouns
if not nouns.empty?
nouns_in_sentence.append(nouns.first)
break
end
end
end
return nouns_in_sentence
end


def is_command?(sentence)
words = sentence.strip.split(' ')

if words.first[0].to_s == '\\' then
return true
else
return false
end
end


def handle_commands(commands)
if commands.include? 'PRINT_SYNSETS'
print_synsets = true
elsif commands.include? '~PRINT_SYNSETS'
print_synsets = false
end
end

Answer

if statements in Ruby don't require then

if words.first[0].to_s == '\\'
    return true 
else 
    return false
end