Skip to content

Instantly share code, notes, and snippets.

@koduki
Created October 30, 2010 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koduki/5e7545c6f22ce49110ae to your computer and use it in GitHub Desktop.
Save koduki/5e7545c6f22ce49110ae to your computer and use it in GitHub Desktop.
# -*- 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