Class: Mocodo::Entity

Inherits:
GooLanguageAnalysis show all
Defined in:
lib/mocodo/goo_language_analysis.rb

Instance Attribute Summary

Attributes inherited from GooLanguageAnalysis

#config_e, #config_h, #config_m, #config_s

Instance Method Summary collapse

Methods inherited from GooLanguageAnalysis

#initialize

Constructor Details

This class inherits a constructor from Mocodo::GooLanguageAnalysis

Instance Method Details

#build_body(sentence) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/mocodo/goo_language_analysis.rb', line 67

def build_body(sentence)
  body = {}
  self.config_e.each { |sym|
    body[sym[0].id2name] = sym[1]
  }
  body['sentence'] = sentence
  return body.to_json
end

#configure(options = {}) ⇒ Object



53
54
55
56
57
# File 'lib/mocodo/goo_language_analysis.rb', line 53

def configure(options = {})
  options.each do |key, value|
    self.config_e[key] = value
  end
end

#entity(sentence) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/mocodo/goo_language_analysis.rb', line 76

def entity sentence
  uri = URI.parse("https://api.apigw.smt.docomo.ne.jp/gooLanguageAnalysis/v1/entity?APIKEY=#{@client.get_api_key}")
  http = Net::HTTP.new('api.apigw.smt.docomo.ne.jp', 443)
  http.use_ssl = true
  request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' =>'application/json'})
  request.body = build_body(sentence)
  response = nil
  http.start do |h|
    response = JSON.parse(h.request(request).body, symbolize_names: true)
  end
  return response[:ne_list]
end

#get_current_data(option = nil) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/mocodo/goo_language_analysis.rb', line 59

def get_current_data(option=nil)
  if option.nil?
    return self.config_e
  else
    return self.config_e[option]
  end
end