class PhrasepicsController < ModsentenceController InterchangeablesFolder='interchangeables/' def sibling_text st rxfile=Regexp.new( '([\w,/, ]*\.txt)$',Regexp::IGNORECASE) files=get_filtered_filename_part(InterchangeablesFolder,rxfile) files.each do |f| lines=IO.readlines f phrases=[] lines.each do |l| if l.strip=~ /(\w+)$/ verb= $1.strip pronouns=$`.split '/' phrases+= pronouns.collect do |p| "#{p.strip} #{verb}" end end end phrases.each do|p| if st.match /\b#{p}\b/i return phrases end end end [] end def interchangeables_in_sentence st rxfile=Regexp.new( '([\w,/, ]*\.txt)$',Regexp::IGNORECASE) # full path of txt files interchangeables=[] @files=get_filtered_filename_part(InterchangeablesFolder,rxfile) @files.each do |f| lines=IO.readlines f # logger.info "#{f} contains #{lines.join(";\n")}" lines.each do |l| if l.strip=~ /(\w+)$/ verb= $1 pronouns=$`.split '/' pronouns.each do |p| phrase="#{p.strip} #{verb.strip}" if st.match /\b#{phrase}\b/i # logger.info "phrase found #{phrase}" interchangeables << phrase end end end end end # logger.info "interchangeables #{interchangeables}" interchangeables end def replaceable_words st super(st)+interchangeables_in_sentence(st) end def start_choices if (s=super).empty? return sibling_text session[:picked] else s end end end