lazy.ai 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/README.md +17 -0
  4. data/lib/lazy.ai.rb +91 -0
  5. metadata +87 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a5d3a05c52b2d31ff018566ae102790f7f4b80ec
4
+ data.tar.gz: 33c4337174f32a8b37bb5410368e985fddbfc9e5
5
+ SHA512:
6
+ metadata.gz: c66dfade998fe7a6683946271d5ffc57416ee76fe13b226c1f33fa9294badb3b8362fe4dfb62b28245214ebb8c854fe7606cf9da220c0803db5eb890989c0bd6
7
+ data.tar.gz: 0d5213fb526b365aa6b22f818c5702d0d8a660d87ed7e9ed8f539b34c5db3909da53a0948e117b1b288abc2a20adace278c52a3231de63051b16ec3341d3ad40
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Yiğitcan UÇUM
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # lazy.ai
2
+ Lazy.ai is the ruby client for training the [lazy](https://github.com/cagataycali/lazy) chatbot.
3
+
4
+ ## Usage
5
+ ```ruby
6
+ lazy = Lazy.new(host: "")
7
+
8
+ puts lazy.learn(phrase: "hello", category: "greetings")
9
+
10
+ puts lazy.query(phrase: "hello dude!")
11
+
12
+ puts lazy.add_response(response: "Hello there", category: "greetings")
13
+
14
+ puts lazy.get_response(categry: "greetings")
15
+
16
+ puts lazy.get_categories()
17
+ ```
data/lib/lazy.ai.rb ADDED
@@ -0,0 +1,91 @@
1
+ require 'uri'
2
+ require 'rest-client'
3
+ require 'json'
4
+
5
+ class Lazy
6
+ # Creates and returns a client instance. Configured to work on a specific server.
7
+ # Params:
8
+ # +host+:: The host this Lazy client will use. Example: https://lazy.herokuapp.com
9
+ def initialize(host:)
10
+ raise ArgumentError.new("Host must be a string!") unless host.is_a? String and !host.strip.empty?
11
+ raise ArgumentError.new("Host must be a valid uri.") unless host =~ URI::regexp
12
+ @host = host
13
+ end
14
+
15
+ # Adds a given phrase to the category and trains the server.
16
+ # Path: /learn
17
+ # Params:
18
+ # +phrase+:: string of characters representing a meaningful phrase.
19
+ # +category+:: a string representing the category to put the phrase in.
20
+ def learn(phrase:, category:)
21
+ raise ArgumentError.new("Phrase and category must be strings!") unless [phrase, category].all?{ |p| p.is_a? String and !p.strip.empty? }
22
+ response = RestClient.post @host + "/learn", { :phrase => phrase, :category => category }, { :accept => :json }
23
+ return JSON.parse(response.body)
24
+ end
25
+
26
+ # Forgets a given phrase which is present in the given category.
27
+ # Path: /forget
28
+ # Params:
29
+ # +phrase+:: string of characters representing a phrase which is present in the server.
30
+ # +category+:: a string representing the category to remove the phrase from.
31
+ def forget(phrase:, category:)
32
+ raise ArgumentError.new("Phrase and category must be strings!") unless [phrase, category].all?{ |p| p.is_a? String and !p.strip.empty? }
33
+ response = RestClient.post @host + "/forget", { :phrase => phrase, :category => category }, { :accept => :json }
34
+ return JSON.parse(response.body)
35
+ end
36
+
37
+ # Adds a response to the given category
38
+ # Path: /response
39
+ # Params:
40
+ # +category+:: a string representing the category to add a response to.
41
+ # +response+:: string of characters to put as response to a category.
42
+ def add_response(category:, response:)
43
+ raise ArgumentError.new("Response and category must be valid strings!") unless [response, category].all?{ |p| p.is_a? String and !p.strip.empty? }
44
+ response = RestClient.post @host + "/response", { :response => response, :category => category }, { :accept => :json }
45
+ return JSON.parse(response.body)
46
+ end
47
+
48
+ # Analyzes and returns a random response for the given phrase.
49
+ # Path: /query
50
+ # Method: POST
51
+ # Params:
52
+ # +phrase+:: string of characters representing a meaningful phrase.
53
+ def query(phrase:)
54
+ raise ArgumentError.new("Phrase must be a string!") unless phrase.is_a? String and !phrase.strip.empty?
55
+ response = RestClient.post @host + "/query", { :phrase => phrase }, { :accept => :json }
56
+ return JSON.parse(response.body)
57
+ end
58
+
59
+ # Gets responses for a specific category.
60
+ # Path: /responses/:category
61
+ # Method: GET
62
+ def get_responses(category:)
63
+ raise ArgumentError.new("Category must be a string!") unless category.is_a? String and !category.strip.empty?
64
+ response = RestClient.get @host + "/responses/" + category, { :accept => :json }
65
+ return JSON.parse(response.body)
66
+ end
67
+
68
+ # Returns all the trained categories from the server.
69
+ # Path: /categories
70
+ # Method: GET
71
+ def get_categories()
72
+ response = RestClient.get @host + "/categories", { :accept => :json }
73
+ return JSON.parse(response.body)
74
+ end
75
+
76
+ # Instructs the server to save the trained data.
77
+ # Path: /save
78
+ # Method: GET
79
+ def save()
80
+ response = RestClient.get @host + "/save", { :accept => :json }
81
+ return JSON.parse(response.body)
82
+ end
83
+
84
+ # Instructs the server to load the trained data.
85
+ # Path: /load
86
+ # Method: GET
87
+ def load()
88
+ response = RestClient.get @host + "/load", { :accept => :json }
89
+ return JSON.parse(response.body)
90
+ end
91
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lazy.ai
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yiğitcan UÇUM
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: webmock
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.3'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 2.3.2
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '2.3'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.3.2
53
+ description: Ruby client for the lazy chatbot. Creates a client to train lazy chatbot
54
+ server through HTTP requests.
55
+ email: yigitcan@hotmail.com.tr
56
+ executables: []
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - LICENSE
61
+ - README.md
62
+ - lib/lazy.ai.rb
63
+ homepage: http://rubygems.org/gems/lazy.ai
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.5.1
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Client for training lazy chatbot servers.
87
+ test_files: []