Skip to content

Instantly share code, notes, and snippets.

@yohfee
Created March 19, 2011 01:56
Show Gist options
  • Select an option

  • Save yohfee/877141 to your computer and use it in GitHub Desktop.

Select an option

Save yohfee/877141 to your computer and use it in GitHub Desktop.
/lib/earthquake/commands.rbの"init"ブロック内に追記
command :zenra do |m|
require 'open-uri'
require 'rexml/document'
sentence = m[1]
appid = 'YOUR_YAHOO_APPID'
position = '動詞'
text = '全裸で'
base_url = 'http://jlp.yahooapis.jp/MAService/V1/parse'
raise 'appid is not configured.' if appid.nil? || appid.empty?
req = "#{base_url}?results=ma&appid=#{appid}&sentence=#{URI.encode(sentence)}"
res = open(req).read
xml = REXML::Document.new(res)
return sentence if xml.elements['ResultSet/ma_result/total_count'].text == '0'
result = ''
xml.elements.each('ResultSet/ma_result/word_list/word') do |e|
result << text if e.elements['pos'].text == position
result << e.elements['surface'].text
end
twitter.update(result) if confirm("update '#{result}'")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment