Class: YahooApiDAService
- Inherits:
-
Object
- Object
- YahooApiDAService
- Defined in:
- lib/yahoo_api.rb
Constant Summary collapse
- REQUEST_HOST =
'jlp.yahooapis.jp'
- API_PATH =
'/DAService/V1/parse'
Instance Method Summary collapse
-
#initialize(app_id, sentence) ⇒ YahooApiDAService
constructor
A new instance of YahooApiDAService.
- #parsed_array ⇒ Object
- #request ⇒ Object
- #xml_document ⇒ Object
Constructor Details
#initialize(app_id, sentence) ⇒ YahooApiDAService
Returns a new instance of YahooApiDAService.
10 11 12 13 14 15 |
# File 'lib/yahoo_api.rb', line 10 def initialize app_id, sentence @app_id = app_id @sentence = sentence request self end |
Instance Method Details
#parsed_array ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/yahoo_api.rb', line 29 def parsed_array result = Array.new xml_document.elements.each('ResultSet/Result/ChunkList/Chunk') do |chunk| chunk.elements.each('MorphemList/Morphem') do |morphem| result << { 'POS' => morphem.elements['POS'].text, 'Surface' => morphem.elements['Surface'].text, } end end result end |
#request ⇒ Object
17 18 19 20 21 22 |
# File 'lib/yahoo_api.rb', line 17 def request http = Net::HTTP.new(REQUEST_HOST,80) query = "?appid=#{@app_id}&sentence=#{CGI.escape(@sentence)}" req = Net::HTTP::Get.new(API_PATH + query) @response = http.request(req) end |
#xml_document ⇒ Object
24 25 26 27 |
# File 'lib/yahoo_api.rb', line 24 def xml_document @xml_doc ||= REXML::Document.new @response.body @xml_doc end |