class WikinextController < ApplicationController require 'hpricot' #starting with the entire typed text, then #progressively deleting the first word, all #pages corresponding to keywords are seached for #the text, and if found, the word following is #added to the choices offered def start_choices chs=[] #pick all text following last punctuation text=get_text.strip.scan(/[\w ]+$/).join while !text.empty? rx=Regexp.new(text+' +(\w+)', Regexp::IGNORECASE) get_keywords.split.each do |w| page=Hpricot(Wikipedia.new.page(w)).inner_text chs+=page.scan(rx) end if !text.gsub!(/\s*\w+\s+/,'') #first word del? break end end chs.flatten.uniq end def first_time redirect_to :action => "index" end def filechoices? false end def get_title 'next word suggestions' end def extras @text=get_text end def selected(str) session[:text]=get_text.strip+" #{str} " end end