nlu_adapter 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0d420268d61b9e8d7de1c7abf829f2983d1ed6cd9feee7642d04c81ea10d7360
4
+ data.tar.gz: 184f17f29ef2711f7d5d85b19b40151a4560d95f3e87b11f10fb634c1a74fd01
5
+ SHA512:
6
+ metadata.gz: 80e1d18f9089ea3cbdbb78db5b5f8fec92cfa71ddec6634ce474bc1055b6477a789dac24c0d517c1dfcd5981897821ccb5577f0ba417e46d4814a358ee1b2405
7
+ data.tar.gz: 317b8cdb1b06af61b2b34131beeb1dfc94c9b0cba7bf345e5f00bc878cabed71c7a2f3b59bcb74091da612d91d2233c4fa0580bb438ecc856dfaf582779ae5e8
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at getgirish@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Dockerfile ADDED
@@ -0,0 +1,13 @@
1
+ FROM ruby:2.4.4-jessie
2
+
3
+ RUN bundle config --global frozen 1
4
+
5
+ WORKDIR /usr/src/app
6
+
7
+ COPY Gemfile Gemfile.lock ./
8
+
9
+ RUN bundle install
10
+
11
+ COPY . .
12
+
13
+ ENTRYPOINT ["./entrypoint.sh"]
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/technopreneurG/nlu_adapter_ruby" }
4
+
5
+ # Specify your gem's dependencies in nlu_adapter.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,94 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nlu_adapter (0.1.0)
5
+ aws-sdk-lex (= 1.9)
6
+ aws-sdk-lexmodelbuildingservice (= 1.12)
7
+ google-cloud-dialogflow (= 0.2.3)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.5.2)
13
+ public_suffix (>= 2.0.2, < 4.0)
14
+ aws-eventstream (1.0.1)
15
+ aws-partitions (1.127.0)
16
+ aws-sdk-core (3.44.1)
17
+ aws-eventstream (~> 1.0)
18
+ aws-partitions (~> 1.0)
19
+ aws-sigv4 (~> 1.0)
20
+ jmespath (~> 1.0)
21
+ aws-sdk-lex (1.9.0)
22
+ aws-sdk-core (~> 3, >= 3.39.0)
23
+ aws-sigv4 (~> 1.0)
24
+ aws-sdk-lexmodelbuildingservice (1.12.0)
25
+ aws-sdk-core (~> 3, >= 3.39.0)
26
+ aws-sigv4 (~> 1.0)
27
+ aws-sigv4 (1.0.3)
28
+ diff-lcs (1.3)
29
+ faraday (0.15.3)
30
+ multipart-post (>= 1.2, < 3)
31
+ google-cloud-dialogflow (0.2.3)
32
+ google-gax (~> 1.3)
33
+ google-gax (1.4.0)
34
+ google-protobuf (~> 3.2)
35
+ googleapis-common-protos (>= 1.3.5, < 2.0)
36
+ googleauth (~> 0.6.2)
37
+ grpc (>= 1.7.2, < 2.0)
38
+ rly (~> 0.2.3)
39
+ google-protobuf (3.6.1-x86_64-linux)
40
+ googleapis-common-protos (1.3.7)
41
+ google-protobuf (~> 3.0)
42
+ googleapis-common-protos-types (~> 1.0)
43
+ grpc (~> 1.0)
44
+ googleapis-common-protos-types (1.0.2)
45
+ google-protobuf (~> 3.0)
46
+ googleauth (0.6.7)
47
+ faraday (~> 0.12)
48
+ jwt (>= 1.4, < 3.0)
49
+ memoist (~> 0.16)
50
+ multi_json (~> 1.11)
51
+ os (>= 0.9, < 2.0)
52
+ signet (~> 0.7)
53
+ grpc (1.16.0-x86_64-linux)
54
+ google-protobuf (~> 3.1)
55
+ googleapis-common-protos-types (~> 1.0.0)
56
+ jmespath (1.4.0)
57
+ jwt (2.1.0)
58
+ memoist (0.16.0)
59
+ multi_json (1.13.1)
60
+ multipart-post (2.0.0)
61
+ os (1.0.0)
62
+ public_suffix (3.0.3)
63
+ rake (12.3.2)
64
+ rly (0.2.3)
65
+ rspec (3.8.0)
66
+ rspec-core (~> 3.8.0)
67
+ rspec-expectations (~> 3.8.0)
68
+ rspec-mocks (~> 3.8.0)
69
+ rspec-core (3.8.0)
70
+ rspec-support (~> 3.8.0)
71
+ rspec-expectations (3.8.2)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.8.0)
74
+ rspec-mocks (3.8.0)
75
+ diff-lcs (>= 1.2.0, < 2.0)
76
+ rspec-support (~> 3.8.0)
77
+ rspec-support (3.8.0)
78
+ signet (0.11.0)
79
+ addressable (~> 2.3)
80
+ faraday (~> 0.9)
81
+ jwt (>= 1.5, < 3.0)
82
+ multi_json (~> 1.10)
83
+
84
+ PLATFORMS
85
+ ruby
86
+
87
+ DEPENDENCIES
88
+ bundler (~> 1.16)
89
+ nlu_adapter!
90
+ rake (~> 12.0)
91
+ rspec (~> 3.8)
92
+
93
+ BUNDLED WITH
94
+ 1.16.6
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # NluAdapter
2
+ An adapter to various NLU web services
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'nlu_adapter'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install nlu_adapter
19
+
20
+ ## Usage
21
+
22
+ Check [documentation](docs) for usage.
23
+
24
+ ## Supported NLU services
25
+ 1. [Aws Lex](https://aws.amazon.com/lex/)
26
+ 2. [Google Dialogflow](https://dialogflow.com/)
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/technopreneurG/nlu_adapter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the NluAdapter project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/technopreneurG/nlu_adapter/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nlu_adapter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ # NluAdapter::Dialogflow
2
+
3
+ Adapter for Google Dialogflow
4
+
5
+ ## Setup
6
+
7
+
8
+ ## Examples
9
+
10
+ 1. Parse a text and identify intent from an existing Lex bot
11
+ ```ruby
12
+ require 'nlu_adapter'
13
+
14
+
15
+ d = NluAdapter.new(:Dialogflow, {project_id: "test-1-NNNN", session_id: 'SESSION1'})
16
+
17
+ puts d.parse('I want to book a hotel')
18
+
19
+ ```
20
+ ```
21
+ {:intent_name=>"BookHotel"}
22
+ ```
23
+ 2. Create an intent
24
+ ```ruby
25
+ require 'nlu_adapter'
26
+
27
+ d = NluAdapter.new(:Dialogflow, {project_id: "test-1-NNNN", session_id: 'SESSION1'})
28
+ i = d.new_intent('BookHotel', ['please book a hotel', 'I want to book a hotel'])
29
+
30
+ d.create_intent(i)
31
+
32
+ ```
33
+
34
+ 3. Create an intent collection
35
+
36
+ Create an Agent from Dialogflow console.
data/docs/lex.md ADDED
@@ -0,0 +1,47 @@
1
+ # NluAdapter::Lex
2
+
3
+ Adapter for Aws Lex
4
+
5
+ ## Setup
6
+
7
+
8
+ ## Examples
9
+
10
+ 1. Parse a text and identify intent from an existing Lex bot
11
+ ```ruby
12
+ require 'nlu_adapter'
13
+
14
+
15
+ l = NluAdapter.new(:Lex, {bot_name: "BotName", bot_alias: "BotAlias", user_id: "user-1"})
16
+
17
+ puts l.parse('I want to book a hotel')
18
+
19
+ ```
20
+ ```
21
+ {:intent_name=>"BookHotel"}
22
+ ```
23
+ 2. Create an intent
24
+ ```ruby
25
+ require 'nlu_adapter'
26
+
27
+ l = NluAdapter.new(:Lex, {bot_name: "BotName", bot_alias: "BotAlias", user_id: "user-1"})
28
+ i = l.new_intent('BookHotel', ['please book a hotel', 'I want to book a hotel'])
29
+
30
+ l.create_intent(i)
31
+
32
+ ```
33
+
34
+ 3. Create an intent collection
35
+ ```ruby
36
+
37
+ require 'nlu_adapter'
38
+
39
+ l = NluAdapter.new(:Lex, {bot_name: "BotName", bot_alias: "BotAlias", user_id: "user-1"})
40
+ intents = []
41
+ i = l.new_intent('BookHotel', ['please book a hotel', 'I want to book a hotel'])
42
+ intents << i
43
+
44
+ ic = l.new_intent_collection('BotName', intents)
45
+ l.create_intent_collection(ic)
46
+
47
+ ```
data/entrypoint.sh ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ tail -f /dev/null
@@ -0,0 +1,111 @@
1
+ require "google/cloud/dialogflow"
2
+
3
+ module NluAdapter
4
+ module Adapters
5
+ class Dialogflow
6
+ def initialize(options = {})
7
+ @project_id = options[:project_id]
8
+ @session_id = options[:session_id]
9
+ end
10
+
11
+ def parse(text, language_code = 'en')
12
+ sessions_client = Google::Cloud::Dialogflow::Sessions.new(version: :v2)
13
+ formatted_session = Google::Cloud::Dialogflow::V2::SessionsClient.session_path(@project_id, @session_id)
14
+ query_input = Google::Cloud::Dialogflow::V2::QueryInput.new({text: {language_code: language_code, text: text}})
15
+ response = sessions_client.detect_intent(formatted_session, query_input)
16
+
17
+ return { intent_name: response.query_result.intent.display_name }
18
+ end
19
+
20
+ def get_intent(name)
21
+ intents_client = Google::Cloud::Dialogflow::Intents.new(version: :v2)
22
+ formatted_parent = Google::Cloud::Dialogflow::V2::IntentsClient.project_agent_path(@project_id)
23
+
24
+ #Iterate over all results.
25
+ #todo: should be cached for better performance
26
+ intents_client.list_intents(formatted_parent).each do |intent|
27
+ if intent.display_name == name
28
+ return Intent.new({id: intent.name, display_name: intent.display_name})
29
+ end
30
+ end
31
+ return nil
32
+ end
33
+
34
+ def new_intent(name, utterences = [])
35
+ i = get_intent(name)
36
+
37
+ i = Intent.new if !i
38
+ i.name = name
39
+ i.utterences = utterences
40
+ return i
41
+ end
42
+
43
+ def create_intent(intent)
44
+ intents_client = Google::Cloud::Dialogflow::Intents.new(version: :v2)
45
+ formatted_parent = Google::Cloud::Dialogflow::V2::IntentsClient.project_agent_path(@project_id)
46
+
47
+ #check: to create / update
48
+ if !intent.id
49
+ i = intent.to_h
50
+ response = intents_client.create_intent(formatted_parent, i)
51
+ else
52
+ i = intent.to_h
53
+ language_code = 'en'
54
+ response = intents_client.update_intent(i, language_code)
55
+ end
56
+ end
57
+
58
+ def get_intent_collection(name)
59
+ end
60
+
61
+ def new_intent_collection(name, intents)
62
+ end
63
+
64
+ def create_intent_collection(collection)
65
+ end
66
+
67
+ class Intent
68
+ include NluAdapterIntent
69
+ attr_accessor :id
70
+
71
+ def initialize(options = {})
72
+ @name = options[:name] #DF.intent.display_name
73
+ @id = options[:id] #DF.intent.name
74
+ @utterences = options[:utterences]
75
+ end
76
+
77
+ def to_h
78
+ training_phrases = []
79
+ @utterences.each do |u|
80
+ training_phrases << {"type" => "EXAMPLE", "parts" =>[{"text" => u }]}
81
+ end
82
+
83
+ {
84
+ name: @id,
85
+ display_name: @name,
86
+ training_phrases: training_phrases
87
+ }
88
+ end
89
+
90
+ def to_json
91
+ to_h.to_json
92
+ end
93
+
94
+ end
95
+
96
+ class IntentCollection
97
+ include NluAdapterIntentCollection
98
+
99
+ def initialize(options = {})
100
+ end
101
+
102
+ def to_h
103
+ end
104
+
105
+ def to_json
106
+ end
107
+ end
108
+
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+
3
+ #Class represents Intent in an IntentCollection
4
+ module NluAdapterIntent
5
+ attr_accessor :name, :utterences
6
+
7
+ def to_h
8
+ {
9
+ :name => @name,
10
+ :utterences => @utterences
11
+ }
12
+ end
13
+
14
+ def to_json
15
+ to_h.to_json
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ require 'json'
2
+
3
+ #Class represents a collection of Intents
4
+ module NluAdapterIntentCollection
5
+ attr_accessor :name, :intents
6
+
7
+ def initialize(name, intents)
8
+ @name = name
9
+ @intents = intents
10
+ end
11
+
12
+ def to_h
13
+ {
14
+ :name => @name,
15
+ :intents => @intents.map { |i| i.to_h }
16
+ }
17
+ end
18
+
19
+ def to_json
20
+ to_h.to_json
21
+ end
22
+ end
@@ -0,0 +1,193 @@
1
+
2
+ require 'aws-sdk-lex'
3
+ require 'aws-sdk-lexmodelbuildingservice'
4
+
5
+ module NluAdapter
6
+ module Adapters
7
+ class Lex
8
+
9
+ def initialize(options = {})
10
+ #creds & region from config/env
11
+ @bot_name = options[:bot_name]
12
+ @bot_alias = options[:bot_alias]
13
+ @user_id = options[:user_id]
14
+ @lex_client = Aws::Lex::Client.new()
15
+ @lexm_client = Aws::LexModelBuildingService::Client.new()
16
+ end
17
+
18
+ #understand a given text
19
+ def parse(text)
20
+ intent_name = nil
21
+ begin
22
+ resp = @lex_client.post_text({
23
+ bot_name: @bot_name, # required
24
+ bot_alias: @bot_alias, # required
25
+ user_id: @user_id, # required
26
+ session_attributes: {
27
+ "String" => "String",
28
+ },
29
+ request_attributes: {
30
+ "String" => "String",
31
+ },
32
+ input_text: text, # required
33
+ })
34
+
35
+ intent_name = resp.intent_name #=> String
36
+ rescue Aws::Lex::Errors::ServiceError => e
37
+ puts "Error: #{e.inspect}"
38
+ end
39
+ return { intent_name: intent_name }
40
+ end
41
+
42
+ #get an instance of Intent, if it exists
43
+ def get_intent(name, version = nil)
44
+ version = '$LATEST'
45
+
46
+ begin
47
+ resp = @lexm_client.get_intent({name: name, version: version})
48
+ return Intent.new(resp.to_h)
49
+
50
+ rescue Aws::LexModelBuildingService::Errors::NotFoundException => e
51
+ puts "Error: #{e.inspect}"
52
+ end
53
+ return nil
54
+ end
55
+
56
+ #get a new instance of Intent
57
+ def new_intent(name, utterences= [])
58
+ #check for existing intent, and get checksum
59
+
60
+ i = get_intent(name)
61
+ i = Intent.new if !i
62
+ i.name = name
63
+ i.utterences = utterences
64
+
65
+ return i
66
+ end
67
+
68
+ #given an Intent object, create it in Lex
69
+ def create_intent(intent)
70
+ resp = @lexm_client.put_intent(intent.to_h)
71
+ end
72
+
73
+ #get an instance of IntentCollection, if it exists
74
+ def get_intent_collection(name, version = nil)
75
+ version = '$LATEST'
76
+ begin
77
+ resp = @lexm_client.get_bot({name: name, version_or_alias: version})
78
+
79
+ return IntentCollection.new(resp.to_h)
80
+ rescue Aws::LexModelBuildingService::Errors::NotFoundException => e
81
+ puts "Error: #{e.inspect}"
82
+ end
83
+ return nil
84
+ end
85
+
86
+ #get a new instance of Intent
87
+ def new_intent_collection(name, intents)
88
+ ic = get_intent_collection(name)
89
+
90
+ ic = IntentCollection.new if !ic
91
+ ic.name = name
92
+ ic.intents = intents
93
+ return ic
94
+ end
95
+
96
+ #given an IntentCollection object, create it in Lex
97
+ def create_intent_collection(collection)
98
+ #create/update intents
99
+ collection.intents.each do |i|
100
+ create_intent(i)
101
+ end
102
+
103
+ resp = @lexm_client.put_bot(collection.to_h)
104
+ end
105
+
106
+ #Classes
107
+ class Intent
108
+ include NluAdapterIntent
109
+ def initialize(options = {})
110
+ @name = options[:name]
111
+ @version = options[:version]
112
+ @checksum = options[:checksum]
113
+ end
114
+
115
+ def to_h
116
+ {
117
+ name: @name,
118
+ sample_utterances: @utterences,
119
+ fulfillment_activity: {
120
+ type: "ReturnIntent"
121
+ },
122
+ checksum: @checksum
123
+ }
124
+ end
125
+
126
+ def to_json
127
+ to_h.to_json
128
+ end
129
+ end
130
+
131
+ #Classes
132
+ class IntentCollection
133
+ include NluAdapterIntentCollection
134
+ attr_accessor :extra
135
+
136
+ def initialize(options = {})
137
+ @name = options[:name]
138
+ @checksum = options[:checksum]
139
+ @intents = options[:intents]
140
+ end
141
+
142
+ def to_h
143
+ intents = []
144
+ @intents.each do |i|
145
+ intents << {
146
+ intent_name: i.name,
147
+ intent_version: '$LATEST'
148
+ }
149
+ end
150
+
151
+ {
152
+ name: @name,
153
+ intents: intents,
154
+ locale: "en-US",
155
+ child_directed: false,
156
+ voice_id: "0",
157
+ clarification_prompt: {
158
+ max_attempts: 1,
159
+ messages: [
160
+ {
161
+ content: "I'm sorry, Can you please repeat that?",
162
+ content_type: "PlainText"
163
+ },
164
+ {
165
+ content: "Can you say that again?",
166
+ content_type: "PlainText"
167
+ }
168
+ ]
169
+ },
170
+ abort_statement: {
171
+ messages: [
172
+ {
173
+ content: "I don't understand. Can you try again?",
174
+ content_type: "PlainText"
175
+ },
176
+ {
177
+ content: "I'm sorry, I don't understand.",
178
+ content_type: "PlainText"
179
+ }
180
+ ]
181
+ },
182
+ checksum: @checksum
183
+ }
184
+ end
185
+
186
+ def to_json
187
+ to_h.to_json
188
+ end
189
+
190
+ end
191
+ end
192
+ end
193
+ end
@@ -0,0 +1,3 @@
1
+ module NluAdapter
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,14 @@
1
+ require "nlu_adapter/version"
2
+
3
+ module NluAdapter
4
+ autoload :NluAdapterIntent, './lib/nlu_adapter/intent'
5
+ autoload :NluAdapterIntentCollection, './lib/nlu_adapter/intent_collection'
6
+ module Adapters
7
+ autoload :Lex, './lib/nlu_adapter/lex'
8
+ autoload :Dialogflow, './lib/nlu_adapter/dialogflow'
9
+ end
10
+
11
+ def self.new(name, options = {})
12
+ aforadapter = Adapters.const_get(name).new(options)
13
+ end
14
+ end
@@ -0,0 +1,50 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "nlu_adapter/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nlu_adapter"
8
+ spec.version = NluAdapter::VERSION
9
+ spec.authors = ["Girish"]
10
+ spec.email = ["getgirish@gmail.com"]
11
+
12
+ spec.summary = %q{NLU Adapter - An adapter for various NLU web services}
13
+ spec.description = %q{An adapter for various NLU web services like Aws Lex, Google Dialogflow etc.}
14
+ spec.homepage = "https://rubygems.org/gems/nlu_adapter"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/technopreneurG/nlu_adapter_ruby"
24
+ spec.metadata["changelog_uri"] = "https://github.com/technopreneurG/nlu_adapter_ruby/CHANGELOG.md"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.16"
40
+ spec.add_development_dependency "rake", "~> 12.0"
41
+ spec.add_development_dependency "rspec", "~> 3.8"
42
+
43
+ #Official AWS Ruby gem for Amazon Lex Runtime Service. This gem is part of the AWS SDK for Ruby.
44
+ spec.add_dependency('aws-sdk-lex', '1.9')
45
+ spec.add_dependency('aws-sdk-lexmodelbuildingservice', '1.12')
46
+
47
+ #google-cloud-dialogflow is the official library for Dialogflow API.
48
+ spec.add_dependency('google-cloud-dialogflow', '0.2.3')
49
+
50
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nlu_adapter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Girish
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aws-sdk-lex
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: '1.9'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: '1.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aws-sdk-lexmodelbuildingservice
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: '1.12'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: '1.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: google-cloud-dialogflow
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.2.3
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.2.3
97
+ description: An adapter for various NLU web services like Aws Lex, Google Dialogflow
98
+ etc.
99
+ email:
100
+ - getgirish@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".rspec"
106
+ - CODE_OF_CONDUCT.md
107
+ - Dockerfile
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - docs/dialogflow.md
115
+ - docs/lex.md
116
+ - entrypoint.sh
117
+ - lib/nlu_adapter.rb
118
+ - lib/nlu_adapter/dialogflow.rb
119
+ - lib/nlu_adapter/intent.rb
120
+ - lib/nlu_adapter/intent_collection.rb
121
+ - lib/nlu_adapter/lex.rb
122
+ - lib/nlu_adapter/version.rb
123
+ - nlu_adapter.gemspec
124
+ homepage: https://rubygems.org/gems/nlu_adapter
125
+ licenses:
126
+ - MIT
127
+ metadata:
128
+ allowed_push_host: https://rubygems.org
129
+ homepage_uri: https://rubygems.org/gems/nlu_adapter
130
+ source_code_uri: https://github.com/technopreneurG/nlu_adapter_ruby
131
+ changelog_uri: https://github.com/technopreneurG/nlu_adapter_ruby/CHANGELOG.md
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.7.7
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: NLU Adapter - An adapter for various NLU web services
152
+ test_files: []