class NextwordController < ApplicationController # start_choices must return an array of strings def start_choices @text=get_text.strip lw=last_word(@text) if lw.empty? # suggestions for first word nw=get_starting_words(get_sentences_dir) else rx=Regexp.new(lw,Regexp::IGNORECASE) ac=get_matching_sentences(get_sentences_dir,rx) logger.info "ac #{ac.inspect}" nw=ac.grep(%r{\b#{lw} (\w+)}) do $1 end end logger.info "suggested #{nw}" nw.uniq end #file_choices? true if choices are static def filechoices? false end #selected processes the string str that the user #has selected def selected(str) logger.info "selected string #{str.inspect}" session[:text]=get_text.strip+" #{str} "; nil end def get_title translate("suggested next word") end #extras allows instance variables to be displayed #to be initialized def extras @display=get_text end end