Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- text = """Rubular is a Ruby-based regular expression editor. It's a handy way to test regular expressions as you write them.
- To start, enter a regular expression and a test string. Or you can try an example.
- """
- tes = "st"
- rtext = text.scan(/[#{tes}]+/).sort_by{|e| e.size}[-1]
- puts tes + ", did you mean? " + text.split(" ").collect{|text| text if text.downcase =~ %r"^#{rtext}"}.compact[-1]
- puts "done"
- text = """Rubular is a Ruby-based regular expression editor. It's a handy way to test regular expressions as you write them.
- To start, enter a regular expression and a test string. Or you can try an example.
- """
- tes = "eprestion"
- tlist = text.split(" ").collect{|text|
- rtext = text.scan(/[#{tes}]+/).sort_by{|e| e.size}[-1]
- if rtext != nil
- [text, rtext]
- end
- }.compact
- puts tes + ", did you mean? " + tlist.sort_by{|te, rt| rt.size}[-1][0]
- puts "done"
- class AI
- def initialize
- @text = {"apa kabar"=>["kabar baik"],
- "siapa kamu"=>["aku bot", "hi aku bot"],
- "selamat pagi"=>["pagi!", "pagi juga", "selamat pagi"]
- }
- end
- def talk(input)
- output = []
- @text.each do |text, response|
- if input == text
- return response
- elsif text.include? input
- return response
- else
- rtext = text.scan(/[#{input}]+/).sort_by{|e| e.size}[-1]
- if rtext != nil
- output << [response, rtext]
- end
- end
- end
- return output.sort_by{|te, rt| rt.size}[-1][0]
- end
- end
- ai = AI.new
- puts ai.talk("apa kabar").sample
- puts "done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement