nlu_tools 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +145 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/data/.keep +0 -0
- data/exe/nlu_toolset +9 -0
- data/lib/nlu_tools/cli/import.rb +85 -0
- data/lib/nlu_tools/cli/test.rb +143 -0
- data/lib/nlu_tools/cli.rb +18 -0
- data/lib/nlu_tools/version.rb +5 -0
- data/lib/nlu_tools.rb +9 -0
- data/nlu_tools.gemspec +46 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 57668b33bec11c4b6f381cb623b58ecb55d160e4c9b581929c1be7dc8a7c75d5
|
4
|
+
data.tar.gz: 40e5cf7c30e7a193b30eb35734f4d3ae57760bf98b8ae96c23352c4581635a74
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 25075378cd1ae7605043e2df602899f053e76c29cd40beb45b7161c3be147ae40abf43992b28fca2d2f31ebe2e8e37373b165fa501abc82cc8d9a4355cf3c925
|
7
|
+
data.tar.gz: 36191f7979f3dd4c9d9ba8aa3515a017cf417857167ddf47169d45245d08c9eaa2148df58c689f6ce964a686fa8144c1c833e1c47507d3d2bbe9e93e46cc21a0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 TODO: Write your email address. 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/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nlu_tools (0.1.0)
|
5
|
+
nlu_adapter (~> 0.1.6)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.7.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
ast (2.4.0)
|
13
|
+
aws-eventstream (1.0.3)
|
14
|
+
aws-partitions (1.220.0)
|
15
|
+
aws-sdk-core (3.68.1)
|
16
|
+
aws-eventstream (~> 1.0, >= 1.0.2)
|
17
|
+
aws-partitions (~> 1.0)
|
18
|
+
aws-sigv4 (~> 1.1)
|
19
|
+
jmespath (~> 1.0)
|
20
|
+
aws-sdk-lex (1.19.0)
|
21
|
+
aws-sdk-core (~> 3, >= 3.61.1)
|
22
|
+
aws-sigv4 (~> 1.1)
|
23
|
+
aws-sdk-lexmodelbuildingservice (1.21.0)
|
24
|
+
aws-sdk-core (~> 3, >= 3.61.1)
|
25
|
+
aws-sigv4 (~> 1.1)
|
26
|
+
aws-sigv4 (1.1.0)
|
27
|
+
aws-eventstream (~> 1.0, >= 1.0.2)
|
28
|
+
concurrent-ruby (1.1.5)
|
29
|
+
diff-lcs (1.3)
|
30
|
+
domain_name (0.5.20190701)
|
31
|
+
unf (>= 0.0.5, < 1.0.0)
|
32
|
+
eventmachine (1.2.7)
|
33
|
+
faraday (0.17.0)
|
34
|
+
multipart-post (>= 1.2, < 3)
|
35
|
+
faye-websocket (0.10.9)
|
36
|
+
eventmachine (>= 0.12.0)
|
37
|
+
websocket-driver (>= 0.5.1)
|
38
|
+
google-cloud-dialogflow (0.2.3)
|
39
|
+
google-gax (~> 1.3)
|
40
|
+
google-gax (1.7.1)
|
41
|
+
google-protobuf (~> 3.2)
|
42
|
+
googleapis-common-protos (>= 1.3.5, < 2.0)
|
43
|
+
googleauth (>= 0.6.2, < 0.10.0)
|
44
|
+
grpc (>= 1.7.2, < 2.0)
|
45
|
+
rly (~> 0.2.3)
|
46
|
+
google-protobuf (3.9.2)
|
47
|
+
googleapis-common-protos (1.3.9)
|
48
|
+
google-protobuf (~> 3.0)
|
49
|
+
googleapis-common-protos-types (~> 1.0)
|
50
|
+
grpc (~> 1.0)
|
51
|
+
googleapis-common-protos-types (1.0.4)
|
52
|
+
google-protobuf (~> 3.0)
|
53
|
+
googleauth (0.9.0)
|
54
|
+
faraday (~> 0.12)
|
55
|
+
jwt (>= 1.4, < 3.0)
|
56
|
+
memoist (~> 0.16)
|
57
|
+
multi_json (~> 1.11)
|
58
|
+
os (>= 0.9, < 2.0)
|
59
|
+
signet (~> 0.7)
|
60
|
+
grpc (1.24.0)
|
61
|
+
google-protobuf (~> 3.8)
|
62
|
+
googleapis-common-protos-types (~> 1.0)
|
63
|
+
http (3.3.0)
|
64
|
+
addressable (~> 2.3)
|
65
|
+
http-cookie (~> 1.0)
|
66
|
+
http-form_data (~> 2.0)
|
67
|
+
http_parser.rb (~> 0.6.0)
|
68
|
+
http-cookie (1.0.3)
|
69
|
+
domain_name (~> 0.5)
|
70
|
+
http-form_data (2.1.1)
|
71
|
+
http_parser.rb (0.6.0)
|
72
|
+
ibm_watson (0.12.0)
|
73
|
+
concurrent-ruby (~> 1.0)
|
74
|
+
eventmachine (~> 1.2)
|
75
|
+
faye-websocket (~> 0.10)
|
76
|
+
http (~> 3.3)
|
77
|
+
jaro_winkler (1.5.3)
|
78
|
+
jmespath (1.4.0)
|
79
|
+
jwt (2.2.1)
|
80
|
+
matrix (0.1.0)
|
81
|
+
memoist (0.16.0)
|
82
|
+
multi_json (1.13.1)
|
83
|
+
multipart-post (2.1.1)
|
84
|
+
nlu_adapter (0.1.6)
|
85
|
+
aws-sdk-lex (~> 1.9)
|
86
|
+
aws-sdk-lexmodelbuildingservice (~> 1.12)
|
87
|
+
google-cloud-dialogflow (~> 0.2.3)
|
88
|
+
ibm_watson (~> 0.12.0)
|
89
|
+
matrix (~> 0.1.0)
|
90
|
+
os (1.0.1)
|
91
|
+
parallel (1.18.0)
|
92
|
+
parser (2.6.5.0)
|
93
|
+
ast (~> 2.4.0)
|
94
|
+
public_suffix (4.0.1)
|
95
|
+
rainbow (3.0.0)
|
96
|
+
rake (13.0.0)
|
97
|
+
rly (0.2.3)
|
98
|
+
rspec (3.9.0)
|
99
|
+
rspec-core (~> 3.9.0)
|
100
|
+
rspec-expectations (~> 3.9.0)
|
101
|
+
rspec-mocks (~> 3.9.0)
|
102
|
+
rspec-core (3.9.0)
|
103
|
+
rspec-support (~> 3.9.0)
|
104
|
+
rspec-expectations (3.9.0)
|
105
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
106
|
+
rspec-support (~> 3.9.0)
|
107
|
+
rspec-mocks (3.9.0)
|
108
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
109
|
+
rspec-support (~> 3.9.0)
|
110
|
+
rspec-support (3.9.0)
|
111
|
+
rubocop (0.75.0)
|
112
|
+
jaro_winkler (~> 1.5.1)
|
113
|
+
parallel (~> 1.10)
|
114
|
+
parser (>= 2.6)
|
115
|
+
rainbow (>= 2.2.2, < 4.0)
|
116
|
+
ruby-progressbar (~> 1.7)
|
117
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
118
|
+
ruby-progressbar (1.10.1)
|
119
|
+
signet (0.11.0)
|
120
|
+
addressable (~> 2.3)
|
121
|
+
faraday (~> 0.9)
|
122
|
+
jwt (>= 1.5, < 3.0)
|
123
|
+
multi_json (~> 1.10)
|
124
|
+
unf (0.1.4)
|
125
|
+
unf_ext
|
126
|
+
unf_ext (0.0.7.6)
|
127
|
+
unicode-display_width (1.6.0)
|
128
|
+
websocket-driver (0.7.1)
|
129
|
+
websocket-extensions (>= 0.1.0)
|
130
|
+
websocket-extensions (0.1.4)
|
131
|
+
yard (0.9.20)
|
132
|
+
|
133
|
+
PLATFORMS
|
134
|
+
ruby
|
135
|
+
|
136
|
+
DEPENDENCIES
|
137
|
+
bundler (~> 1.16)
|
138
|
+
nlu_tools!
|
139
|
+
rake (~> 13.0)
|
140
|
+
rspec (~> 3.9)
|
141
|
+
rubocop (~> 0.75.0)
|
142
|
+
yard (~> 0.9.20)
|
143
|
+
|
144
|
+
BUNDLED WITH
|
145
|
+
1.16.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all 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,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# NluTools
|
2
|
+
|
3
|
+
Useful NLU Tools to import training data into AWS Lex, Google Dialogflow and run tests
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
To install:
|
8
|
+
```bash
|
9
|
+
$ gem install nlu_tools
|
10
|
+
```
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
```bash
|
15
|
+
$ nlu_toolset help
|
16
|
+
$ nlu_toolset import help
|
17
|
+
$ nlu_toolset import help dialogflow
|
18
|
+
$ nlu_toolset import help lex
|
19
|
+
$ nlu_toolset test help
|
20
|
+
$ nlu_toolset test help lex
|
21
|
+
$ nlu_toolset test help dialogflow
|
22
|
+
```
|
23
|
+
|
24
|
+
## Development
|
25
|
+
|
26
|
+
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.
|
27
|
+
|
28
|
+
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).
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nlu_tools. 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.
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
37
|
+
|
38
|
+
## Code of Conduct
|
39
|
+
|
40
|
+
Everyone interacting in the NluTools project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/nlu_tools/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nlu_tools"
|
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
data/data/.keep
ADDED
File without changes
|
data/exe/nlu_toolset
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NluTools
|
4
|
+
# The subcommand import
|
5
|
+
class Import < Thor
|
6
|
+
desc 'dialogflow', 'import the data in <file> into Goole Dialogflow'
|
7
|
+
long_desc 'import the given input file data into given Goole Dialogflow <project>
|
8
|
+
|
9
|
+
options:
|
10
|
+
|
11
|
+
-f --file IMPORTDATA_FILENAME the file containing data for importing
|
12
|
+
|
13
|
+
-p --project_id PROJECT_ID the google project-id
|
14
|
+
|
15
|
+
'
|
16
|
+
option :file,
|
17
|
+
aliases: :f,
|
18
|
+
banner: 'IMPORTDATA_FILENAME',
|
19
|
+
type: :string,
|
20
|
+
required: true
|
21
|
+
option :project_id,
|
22
|
+
aliases: :p,
|
23
|
+
banner: 'PROJECT_ID',
|
24
|
+
type: :string,
|
25
|
+
required: true
|
26
|
+
def dialogflow
|
27
|
+
unless File.exist?(options[:file])
|
28
|
+
puts "File #{options[:file]} does not exist"
|
29
|
+
exit(1)
|
30
|
+
end
|
31
|
+
intents = JSON.parse(File.read(options[:file]))
|
32
|
+
d = NluAdapter.new(:Dialogflow,
|
33
|
+
project_id: options[:project_id],
|
34
|
+
session_id: 'SESSION1')
|
35
|
+
intents.each do |intent|
|
36
|
+
i = d.new_intent(intent['intent'], intent['train'])
|
37
|
+
d.create_intent(i)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'lex', 'import the data in <file> into AWS Lex'
|
42
|
+
long_desc 'import the given input file data into given Lex <botname>
|
43
|
+
|
44
|
+
options:
|
45
|
+
|
46
|
+
-f --file IMPORTDATA_FILENAME the file containing data for importing
|
47
|
+
|
48
|
+
-b --botname BOTNAME the Lex bot name
|
49
|
+
|
50
|
+
'
|
51
|
+
option :file,
|
52
|
+
aliases: :f,
|
53
|
+
banner: 'IMPORTDATA_FILENAME',
|
54
|
+
type: :string,
|
55
|
+
required: true
|
56
|
+
option :botname,
|
57
|
+
aliases: :b,
|
58
|
+
banner: 'BOT_NAME',
|
59
|
+
type: :string,
|
60
|
+
required: true
|
61
|
+
def lex
|
62
|
+
unless File.exist?(options[:file])
|
63
|
+
puts "File #{options[:file]} does not exist"
|
64
|
+
exit(1)
|
65
|
+
end
|
66
|
+
|
67
|
+
intents = JSON.parse(File.read(options[:file]))
|
68
|
+
puts intents.size
|
69
|
+
l = NluAdapter.new(:Lex,
|
70
|
+
bot_name: options[:botname],
|
71
|
+
bot_alias: 'BotAlias',
|
72
|
+
user_id: 'user-1')
|
73
|
+
lex_intents = []
|
74
|
+
intents.each do |intent|
|
75
|
+
intent_name = intent['intent'].gsub('-', '_')
|
76
|
+
puts '---'
|
77
|
+
i = l.new_intent(intent_name, intent['train'])
|
78
|
+
lex_intents << i
|
79
|
+
end
|
80
|
+
|
81
|
+
ic = l.new_intent_collection(options[:botname], lex_intents)
|
82
|
+
l.create_intent_collection(ic)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NluTools
|
4
|
+
# The subcommand for test
|
5
|
+
class Test < Thor
|
6
|
+
desc 'dialogflow', 'test the data in <file> using Goolge Dialogflow'
|
7
|
+
long_desc 'test the given input file data using Google Dialogflow
|
8
|
+
|
9
|
+
options:
|
10
|
+
|
11
|
+
-f --file TESTDATA_FILENAME the file containing data for testing
|
12
|
+
|
13
|
+
-p --project_id PROJECT_ID the google project-id
|
14
|
+
|
15
|
+
-o --output_file OUTPUT_FILENAME.ext filename extension .json/.csv/.yaml
|
16
|
+
is used to determine the output format. if skipped, output to STDOUT
|
17
|
+
|
18
|
+
-t --output_type OUTPUT_TYPE raw/summary. if skipped, output is raw
|
19
|
+
'
|
20
|
+
option :file,
|
21
|
+
aliases: :f,
|
22
|
+
banner: :TESTDATA_FILENAME,
|
23
|
+
type: :string,
|
24
|
+
required: true
|
25
|
+
option :project_id,
|
26
|
+
aliases: :p,
|
27
|
+
banner: :PROJECT_ID,
|
28
|
+
type: :string,
|
29
|
+
required: true
|
30
|
+
option :output_file,
|
31
|
+
aliases: :o,
|
32
|
+
banner: :OUTPUT_FILENAME,
|
33
|
+
type: :string
|
34
|
+
option :output_type,
|
35
|
+
aliases: :t,
|
36
|
+
banner: :OUTPUT_TYPE,
|
37
|
+
type: :string
|
38
|
+
def dialogflow
|
39
|
+
unless File.exist?(options[:file])
|
40
|
+
puts "File #{options[:file]} does not exist"
|
41
|
+
exit(1)
|
42
|
+
end
|
43
|
+
|
44
|
+
intents = JSON.parse(File.read(options[:file]))
|
45
|
+
na = NluAdapter.new(:Dialogflow,
|
46
|
+
project_id: options[:project_id],
|
47
|
+
session_id: 'SESSION1')
|
48
|
+
new_intents = {}
|
49
|
+
intents.each do |intent|
|
50
|
+
new_intents[intent['intent']] = intent['test']
|
51
|
+
end
|
52
|
+
|
53
|
+
run_tests(na, new_intents, options[:output_file], options[:output_type])
|
54
|
+
end
|
55
|
+
|
56
|
+
desc 'lex', 'test the data in <file> using AWS Lex'
|
57
|
+
long_desc 'test the given input file data using AWS Lex
|
58
|
+
|
59
|
+
options:
|
60
|
+
|
61
|
+
-f --file TESTDATA_FILENAME the file containing data for testing
|
62
|
+
|
63
|
+
-b --botname BOTNAME the AWS Lex bot name
|
64
|
+
|
65
|
+
-o --output_file OUTPUT_FILENAME.ext filename extension .json/.csv/.yaml
|
66
|
+
is used to determine the output format. if skipped, output to STDOUT
|
67
|
+
|
68
|
+
-t --output_type OUTPUT_TYPE raw/summary. if skipped, output is raw
|
69
|
+
|
70
|
+
'
|
71
|
+
option :file,
|
72
|
+
aliases: :f,
|
73
|
+
banner: 'TESTDATA_FILENAME',
|
74
|
+
type: :string,
|
75
|
+
required: true
|
76
|
+
option :botname,
|
77
|
+
aliases: :b,
|
78
|
+
banner: 'BOT_NAME',
|
79
|
+
type: :string,
|
80
|
+
required: true
|
81
|
+
option :output_file,
|
82
|
+
aliases: :o,
|
83
|
+
banner: 'OUTPUT_FILENAME.json/csv/yaml',
|
84
|
+
type: :string,
|
85
|
+
default: :STDOUT
|
86
|
+
option :output_type,
|
87
|
+
aliases: :t,
|
88
|
+
banner: :OUTPUT_TYPE,
|
89
|
+
type: :string,
|
90
|
+
default: :raw
|
91
|
+
def lex
|
92
|
+
unless File.exist?(options[:file])
|
93
|
+
puts "File #{options[:file]} does not exist"
|
94
|
+
exit(1)
|
95
|
+
end
|
96
|
+
|
97
|
+
intents = JSON.parse(File.read(options[:file]))
|
98
|
+
na = NluAdapter.new(:Lex,
|
99
|
+
bot_name: options[:botname],
|
100
|
+
bot_alias: 'BotAlias',
|
101
|
+
user_id: 'user-1')
|
102
|
+
new_intents = {}
|
103
|
+
intents.each do |intent|
|
104
|
+
intent_name = intent['intent'].gsub('-', '_')
|
105
|
+
new_intents[intent_name] = intent['test']
|
106
|
+
end
|
107
|
+
|
108
|
+
run_tests(na, new_intents, options[:output_file], options[:output_type])
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def run_tests(nlu_adapter, intents, output_file, output_type)
|
114
|
+
ext = output_file.nil? || output_file.empty? ? :none : output_file.split('.')[-1].intern
|
115
|
+
type = output_type.nil? || output_type.empty? ? :raw : output_type.intern
|
116
|
+
|
117
|
+
case type
|
118
|
+
when :raw
|
119
|
+
case ext
|
120
|
+
when :none
|
121
|
+
puts nlu_adapter.parse_test(intents, :csv)
|
122
|
+
when :csv, :json, :yaml
|
123
|
+
File.open(output_file, 'w') { |file| file.write(nlu_adapter.parse_test(intents, ext)) }
|
124
|
+
else
|
125
|
+
puts 'Only csv/json/yaml output file format supported'
|
126
|
+
end
|
127
|
+
|
128
|
+
when :summary
|
129
|
+
case ext
|
130
|
+
when :none
|
131
|
+
puts nlu_adapter.parse_test_report(intents, :csv)
|
132
|
+
when :csv, :json, :yaml
|
133
|
+
File.open(output_file, 'w') { |file| file.write(nlu_adapter.parse_test_report(intents, ext)) }
|
134
|
+
else
|
135
|
+
puts 'Only csv/json/yaml output file format supported'
|
136
|
+
end
|
137
|
+
|
138
|
+
else
|
139
|
+
puts 'Only raw/summary output type supported'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'json'
|
5
|
+
require 'nlu_adapter'
|
6
|
+
|
7
|
+
module NluTools
|
8
|
+
# The CLI
|
9
|
+
class CLI < Thor
|
10
|
+
desc 'import <provider>', 'import data into <provider>'
|
11
|
+
require_relative 'cli/import'
|
12
|
+
subcommand 'import', Import
|
13
|
+
|
14
|
+
desc 'test <provider>', 'test data using <provider>'
|
15
|
+
require_relative 'cli/test'
|
16
|
+
subcommand 'test', Test
|
17
|
+
end
|
18
|
+
end
|
data/lib/nlu_tools.rb
ADDED
data/nlu_tools.gemspec
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "nlu_tools/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nlu_tools"
|
8
|
+
spec.version = NluTools::VERSION
|
9
|
+
spec.authors = ["Girish Nair"]
|
10
|
+
spec.email = ["getgirish@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{NLU Tools in Ruby}
|
13
|
+
spec.description = %q{A Toolset for NLU evaluation}
|
14
|
+
spec.homepage = "https://rubygems.org/gems/nlu_tools"
|
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_tools_ruby"
|
24
|
+
spec.metadata["changelog_uri"] = "https://github.com/technopreneurG/nlu_tools_ruby/blob/master/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', '~> 13.0'
|
41
|
+
spec.add_development_dependency 'rspec', '~> 3.9'
|
42
|
+
spec.add_development_dependency 'yard', '~> 0.9.20'
|
43
|
+
spec.add_development_dependency 'rubocop', '~> 0.75.0'
|
44
|
+
|
45
|
+
spec.add_dependency('nlu_adapter', '~> 0.1.6')
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nlu_tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Girish Nair
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-08 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: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.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.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.20
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.9.20
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.75.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.75.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: nlu_adapter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.1.6
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.1.6
|
97
|
+
description: A Toolset for NLU evaluation
|
98
|
+
email:
|
99
|
+
- getgirish@gmail.com
|
100
|
+
executables:
|
101
|
+
- nlu_toolset
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- CHANGELOG.md
|
109
|
+
- CODE_OF_CONDUCT.md
|
110
|
+
- Gemfile
|
111
|
+
- Gemfile.lock
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- bin/console
|
116
|
+
- bin/setup
|
117
|
+
- data/.keep
|
118
|
+
- exe/nlu_toolset
|
119
|
+
- lib/nlu_tools.rb
|
120
|
+
- lib/nlu_tools/cli.rb
|
121
|
+
- lib/nlu_tools/cli/import.rb
|
122
|
+
- lib/nlu_tools/cli/test.rb
|
123
|
+
- lib/nlu_tools/version.rb
|
124
|
+
- nlu_tools.gemspec
|
125
|
+
homepage: https://rubygems.org/gems/nlu_tools
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata:
|
129
|
+
allowed_push_host: https://rubygems.org
|
130
|
+
homepage_uri: https://rubygems.org/gems/nlu_tools
|
131
|
+
source_code_uri: https://github.com/technopreneurG/nlu_tools_ruby
|
132
|
+
changelog_uri: https://github.com/technopreneurG/nlu_tools_ruby/blob/master/CHANGELOG.md
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.7.7
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: NLU Tools in Ruby
|
153
|
+
test_files: []
|