Skip to content

Instantly share code, notes, and snippets.

@nbqx
Created January 4, 2012 07:15
Show Gist options
  • Save nbqx/1558918 to your computer and use it in GitHub Desktop.
Save nbqx/1558918 to your computer and use it in GitHub Desktop.
# -*- 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