を期待し、入力終了予期しないが、その私がそこにISN確信しています。この時点で、ライン78上に発生によってはずは、構文エラーを見つけることができません、誰かが私に構文エラーを見つけるのに役立つてもらえkeyword_end
#!/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
Rubyで
こんにちは、正しくフォーマットされるように、すべてのコードを4つのスペースにインデントする必要があります。 –
ブロックのキーワードは 'do' _only_のままにすることをお勧めします。 – Aetherus
1行ブロックの場合は、 'do ... end'の代わりに中かっこを使用します。 – Aetherus