Last active
December 25, 2015 18:49
-
-
Save kazoo04/7023380 to your computer and use it in GitHub Desktop.
ぎんこさんワロタbotの精度向上
This file contains 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 'rubygems' | |
require 'levenshtein' | |
require 'shellwords' | |
def similar(s1, s2, threshold = 2) | |
d = Levenshtein.distance(toKatakana(s1), toKatakana(s2)) | |
d <= threshold | |
end | |
def toKatakana(str) | |
safe_str = str.gsub(/[!-\/:-@\[-`{-~] /, '').strip.shellescape | |
`echo #{safe_str} | nkf -e | kakasi -JK -HK | nkf -w` | |
end | |
s1 = "銀行" | |
s2 = "インコ" | |
puts "ぎんこさん#{s1}と#{s2}間違えててワロタwww" if similar(s1, s2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
shellescapeを使ってより安全になりました