Class | WikinextController |
In: |
app/controllers/wikinext_controller.rb
|
Parent: | ApplicationController |
# File app/controllers/wikinext_controller.rb, line 25 25: def first_time 26: redirect_to :action => "index" 27: end
# File app/controllers/wikinext_controller.rb, line 31 31: def get_title 32: 'next word suggestions' 33: end
# File app/controllers/wikinext_controller.rb, line 37 37: def selected(str) 38: session[:text]=get_text.strip+" #{str} " 39: end
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
# File app/controllers/wikinext_controller.rb, line 8 8: def start_choices 9: chs=[] 10: #pick all text following last punctuation 11: text=get_text.strip.scan(/[\w ]+$/).join 12: while !text.empty? 13: rx=Regexp.new(text+' +(\w+)', 14: Regexp::IGNORECASE) 15: get_keywords.split.each do |w| 16: page=Hpricot(Wikipedia.new.page(w)).inner_text 17: chs+=page.scan(rx) 18: end 19: if !text.gsub!(/\s*\w+\s+/,'') #first word del? 20: break 21: end 22: end 23: chs.flatten.uniq 24: end