Skip to content

Instantly share code, notes, and snippets.

@koduki koduki/keyphrase.rb Secret
Created Oct 30, 2010

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