Skip to content

Instantly share code, notes, and snippets.

@koduki
Created October 30, 2010 17:18
Show Gist options
  • Save koduki/655533 to your computer and use it in GitHub Desktop.
Save koduki/655533 to your computer and use it in GitHub Desktop.
# -*- encoding: utf-8 -*-
require 'rexml/document'
require 'net/http'
class MA
def initialize
path = File.join(File.dirname(__FILE__), "..", "config", "yahooapis.yml")
config = YAML::load(File.open(path))
@app_id = config['app_id']
end
def split(text)
host = 'jlp.yahooapis.jp'
request = "/MAService/V1/parse?appid=#{@app_id}"
http = Net::HTTP.new(host)
response = http.post(request, "sentence=#{text}")
result = []
xml = REXML::Document.new response.body
xml.elements.each("/ResultSet/ma_result/word_list/word") do |item|
word = Hash.new()
item.elements.each do |property|
word["#{property.name}"] = property.text
end
result << word
end
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment