Class: Watson::RetrieveAndRank

Inherits:
Object
  • Object
show all
Defined in:
lib/watson/retrieve_and_rank.rb

Class Method Summary collapse

Class Method Details

.answers(data) ⇒ Object



26
27
28
29
30
31
# File 'lib/watson/retrieve_and_rank.rb', line 26

def self.answers(data)
  data.collect do |d|
    { source: 'retrieveandrank', intent: '',
      message: @message, tittle: d['title'], body: d['body'] }
  end
end

.configure(options = {}) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/watson/retrieve_and_rank.rb', line 3

def self.configure(options = {})
  @username         = options[:username]
  @password         = options[:password]
  @url              = options[:url]
  @cluster          = options[:cluster_id]
  @collection_name  = options[:collection_name]
end

.send_message(message = '') ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/watson/retrieve_and_rank.rb', line 11

def self.send_message(message = '')
  return if message.empty?
  @message = message
  query = URI.encode(@message)
  response = Excon.post(url(query),
                        headers: {
                          'Content-Type' => 'application/json',
                          'Accept' => 'application/json'
                        },
                        user:      @username,
                        password:  @password)
  result = JSON.parse(response.body)
  answers(result['response']['docs'])
end

.url(query) ⇒ Object



33
34
35
36
# File 'lib/watson/retrieve_and_rank.rb', line 33

def self.url(query)
  @url + '/v1/solr_clusters/' + @cluster + '/solr/' + @collection_name +
    '/select?q=' + query + '&wt=json'
end