Skip to content

Instantly share code, notes, and snippets.

@koduki koduki/ma.rb
Created Oct 30, 2010

Embed
What would you like to do?
# -*- 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
You can’t perform that action at this time.