Skip to content

Instantly share code, notes, and snippets.

@kazoo04
Last active December 25, 2015 18:49
Show Gist options
  • Save kazoo04/7023380 to your computer and use it in GitHub Desktop.
Save kazoo04/7023380 to your computer and use it in GitHub Desktop.
ぎんこさんワロタbotの精度向上
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)
@kazoo04
Copy link
Author

kazoo04 commented Oct 17, 2013

shellescapeを使ってより安全になりました

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment