Class: Apollo::Bot::Classifier

Inherits:
Olimpo::Base
  • Object
show all
Defined in:
lib/apollo/bot/classifier.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Classifier

Returns a new instance of Classifier.



8
9
10
11
12
13
14
15
16
# File 'lib/apollo/bot/classifier.rb', line 8

def initialize(attrs = {})
  @id = attrs["classifier_id"]
  @url = attrs["url"]
  @name = attrs["name"]
  @language = attrs["language"]
  @status = attrs["status"]
  @created = Date.parse(attrs["created"])
  @raw = attrs
end

Instance Attribute Details

#createdObject (readonly)

Returns the value of attribute created.



6
7
8
# File 'lib/apollo/bot/classifier.rb', line 6

def created
  @created
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/apollo/bot/classifier.rb', line 6

def id
  @id
end

#languageObject (readonly)

Returns the value of attribute language.



6
7
8
# File 'lib/apollo/bot/classifier.rb', line 6

def language
  @language
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/apollo/bot/classifier.rb', line 6

def name
  @name
end

#rawObject (readonly)

Returns the value of attribute raw.



6
7
8
# File 'lib/apollo/bot/classifier.rb', line 6

def raw
  @raw
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/apollo/bot/classifier.rb', line 6

def status
  @status
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/apollo/bot/classifier.rb', line 6

def url
  @url
end

Class Method Details

.allObject



60
61
62
63
64
65
66
# File 'lib/apollo/bot/classifier.rb', line 60

def self.all
  response = get("/v1/classifiers")
  parsed_response  = JSON.parse(response.body)

  return parsed_response["classifiers"].map { |attrs| new(attrs) } if response.success?
  raise_exception(response.code, response.body)
end

.classify(id, text) ⇒ Object



42
43
44
45
# File 'lib/apollo/bot/classifier.rb', line 42

def self.classify(id, text)
  classifier = find(id)
  classifier.classify(text)
end

.create(attrs = {}) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/apollo/bot/classifier.rb', line 68

def self.create(attrs = {})
  response = post("/v1/classifiers", body: attrs)
  parsed_response  = JSON.parse(response.body)

  return new(parsed_response) if response.success?
  raise_exception(response.code, response.body)
end

.destroy(id) ⇒ Object



55
56
57
58
# File 'lib/apollo/bot/classifier.rb', line 55

def self.destroy(id)
  response = delete("/v1/classifiers/#{id}")
  response.success?
end

.find(id) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/apollo/bot/classifier.rb', line 47

def self.find(id)
  response = get("/v1/classifiers/#{id}")
  parsed_response  = JSON.parse(response.body)

  return new(parsed_response) if response.success?
  raise_exception(response.code, response.body)
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/apollo/bot/classifier.rb', line 18

def available?
  status == "Available"
end

#classify(text) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/apollo/bot/classifier.rb', line 34

def classify(text)
  response = self.class.get("/v1/classifiers/#{id}/classify", query: { text: text })
  parsed_response  = JSON.parse(response.body)

  return Apollo::Bot::Classification.new(parsed_response) if response.success?
  self.class.raise_exception(response.code, response.body)
end

#non_existent?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/apollo/bot/classifier.rb', line 26

def non_existent?
  status == "Non Existent"
end

#training?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/apollo/bot/classifier.rb', line 30

def training?
  status == "Training"
end

#unavailable?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/apollo/bot/classifier.rb', line 22

def unavailable?
  status == "Unavailable"
end