Created
October 5, 2016 08:59
-
-
Save pocke/47d75ad86745e746cd4c2a0c12691d32 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'levenshtein' | |
| content = ARGF.read.split(/[^\w]/).grep(/^\w+$/) | |
| h = {} | |
| content.each do |c| | |
| h[c] ||= 0 | |
| h[c] += 1 | |
| end | |
| words = h.keys | |
| alone = h.select{|k, v| v == 1}.keys | |
| alone.each do |word| | |
| next if word.size < 4 | |
| like = h.keys.find{|k| word != k && Levenshtein.normalized_distance(word, k) < 0.2} | |
| next unless like | |
| puts "Detect Typo!: #{word}" | |
| puts "Did you mean #{like} ?" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment