Created
January 4, 2012 07:15
-
-
Save nbqx/1558918 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
# -*- coding: utf-8 -*- | |
Earthquake.init do | |
command %r|^:cen\s*(\d+)*\s+(.+)$|, :as => :cen do |m| | |
_str = "▓" | |
th = 0.5 | |
censored = ["名詞","動詞","助動詞","形容詞"] | |
cmd = m[1] ? ":reply #{m[1]}" : ":update" | |
url = "http://yapi.ta2o.net/apis/mecapi.cgi?sentence=#{URI.escape(m[2])}&response=surface+pos&filter=&format=json" | |
open(url) do |res| | |
tw = [] | |
data = JSON.parse res.read | |
data.each do |itm| | |
pos = itm["pos"].split(",") | |
if censored.include? pos.first | |
if rand > th | |
tw << _str*itm["surface"].size | |
else | |
tw << itm["surface"] | |
end | |
else | |
tw << itm["surface"] | |
end | |
end | |
input("%s %s" % [cmd, tw.join('')]) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment