WatsonNLPWrapper 1.0.0 → 1.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 +4 -4
- data/Gemfile.lock +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +37 -5
- data/lib/WatsonNLPWrapper.rb +29 -21
- data/lib/WatsonNLPWrapper/constants.rb +2 -0
- data/lib/WatsonNLPWrapper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f1164982eb594a4d0a61c032390470cbd666e47
|
4
|
+
data.tar.gz: 0c0fab4adc203dc840778f3ebf42b8cca97a6408
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c27cc2db01ff6c14f0ef1a420f7a2cd22ac6f8091ab4aaa8ff51dc2d2c63a107d8e4ddb72f1c14fb8faf85d4bc4f42a7da5dc4d83ed800e187af3121fd300d31
|
7
|
+
data.tar.gz: d930b5ab986291ef15bf2cdd07b9049c8682d36d36040e0c5094822a049412c8c9a4060c17dc5b6baf698eab2175e6378e675c9a0fa5b98042863e823c25f03b
|
data/Gemfile.lock
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# WatsonNLPWrapper
|
2
2
|
|
3
3
|
[](https://travis-ci.org/thededlier/WatsonNLPWrapper)
|
4
|
+
[](https://badge.fury.io/rb/WatsonNLPWrapper)
|
5
|
+
[rubygems.org/gems/WatsonNLPWrapper](https://rubygems.org/gems/WatsonNLPWrapper)
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
TODO: Delete this and the text above, and describe your gem
|
7
|
+
This is a simple ruby wrapper implementation of IBM's Watson Natural Language Understanding API which is used to analyze text to extract meta-data from content
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -24,13 +24,45 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
|
27
|
+
```ruby
|
28
|
+
# Require the library
|
29
|
+
require "WatsonNLPWrapper"
|
30
|
+
|
31
|
+
# Initialize
|
32
|
+
# Version parameter is not needed to be sent and by default is 2018-03-16
|
33
|
+
nlp = WatsonNLPWrapper::WatsonNLPApi.new('{url}', '{username}', '{password}', '{version}')
|
34
|
+
|
35
|
+
# Set sample text
|
36
|
+
text = '{sample text}'
|
37
|
+
|
38
|
+
# Call the analyze API with default features
|
39
|
+
# This will give a json response
|
40
|
+
nlp.analyze(text)
|
41
|
+
|
42
|
+
# If you want to enable specific features only and not the default features
|
43
|
+
|
44
|
+
features =
|
45
|
+
{
|
46
|
+
entities: {
|
47
|
+
emotion: true,
|
48
|
+
sentiment: true,
|
49
|
+
limit: 2
|
50
|
+
},
|
51
|
+
keywords: {
|
52
|
+
emotion: true,
|
53
|
+
sentiment: true,
|
54
|
+
limit: 2
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
nlp.analyze(text, features)
|
59
|
+
```
|
28
60
|
|
29
61
|
## Development
|
30
62
|
|
31
63
|
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.
|
32
64
|
|
33
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
65
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
34
66
|
|
35
67
|
## Contributing
|
36
68
|
|
data/lib/WatsonNLPWrapper.rb
CHANGED
@@ -10,6 +10,9 @@ module WatsonNLPWrapper
|
|
10
10
|
include WatsonNLPWrapper::Constants
|
11
11
|
# Initialize instance variables for use later
|
12
12
|
def initialize(url, username, password, version = DEFAULT_VERSION)
|
13
|
+
if url.nil? || username.nil? || password.nil? || version.nil?
|
14
|
+
raise ArgumentError.new(NIL_ARGUMENT_ERROR)
|
15
|
+
end
|
13
16
|
@url = url
|
14
17
|
@username = username
|
15
18
|
@password = password
|
@@ -18,6 +21,10 @@ module WatsonNLPWrapper
|
|
18
21
|
|
19
22
|
# Sends a POST request to analyze text with certain features enabled
|
20
23
|
def analyze(text, features = default_features)
|
24
|
+
if text.nil? || features.nil?
|
25
|
+
raise ArgumentError.new(NIL_ARGUMENT_ERROR)
|
26
|
+
end
|
27
|
+
|
21
28
|
response = self.class.post(
|
22
29
|
"#{@url}/analyze?version=#{@version}",
|
23
30
|
body: {
|
@@ -33,28 +40,29 @@ module WatsonNLPWrapper
|
|
33
40
|
response.parsed_response
|
34
41
|
end
|
35
42
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
private
|
44
|
+
# Returns credentials used for basic auth
|
45
|
+
def auth
|
46
|
+
{
|
47
|
+
username: @username,
|
48
|
+
password: @password
|
49
|
+
}
|
50
|
+
end
|
43
51
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
# Default features if no features specified
|
53
|
+
def default_features
|
54
|
+
{
|
55
|
+
entities: {
|
56
|
+
emotion: true,
|
57
|
+
sentiment: true,
|
58
|
+
limit: 2
|
59
|
+
},
|
60
|
+
keywords: {
|
61
|
+
emotion: true,
|
62
|
+
sentiment: true,
|
63
|
+
limit: 2
|
64
|
+
}
|
56
65
|
}
|
57
|
-
|
58
|
-
end
|
66
|
+
end
|
59
67
|
end
|
60
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: WatsonNLPWrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rohan Anand
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|