# -*- encoding: utf-8 -*- | |
require 'rexml/document' | |
require 'net/http' | |
class Keyphrase | |
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 = "/KeyphraseService/V1/extract?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/Result") do |item| | |
key = item.elements['Keyphrase'].text | |
v = item.elements['Score'].text | |
result[key] = v | |
end | |
result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment