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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9add1c46b3d018c6604b8842a746999b56e64dc4
4
- data.tar.gz: 9e1d10de405f9f90c6ec6c16927a7a04ea2917b5
3
+ metadata.gz: 2f1164982eb594a4d0a61c032390470cbd666e47
4
+ data.tar.gz: 0c0fab4adc203dc840778f3ebf42b8cca97a6408
5
5
  SHA512:
6
- metadata.gz: ed3d4907aa3cea062c547a85d1f1b25cb3e66ce492fe28f0062ca82ea3de577619ac5eef094d8327b30076d823e3aaec4334fe57d1c1de97177b354524401baa
7
- data.tar.gz: 3b2ba52ff23d67c3505676d397d9d852409812f4e53df175e585157feffc46b025f7278ec579ed0eab5eaec0516464c48c8262cd9fdefc66f78561134edadb44
6
+ metadata.gz: c27cc2db01ff6c14f0ef1a420f7a2cd22ac6f8091ab4aaa8ff51dc2d2c63a107d8e4ddb72f1c14fb8faf85d4bc4f42a7da5dc4d83ed800e187af3121fd300d31
7
+ data.tar.gz: d930b5ab986291ef15bf2cdd07b9049c8682d36d36040e0c5094822a049412c8c9a4060c17dc5b6baf698eab2175e6378e675c9a0fa5b98042863e823c25f03b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- WatsonNLPWrapper (1.0.0)
4
+ WatsonNLPWrapper (1.1.0)
5
5
  httparty (~> 0.13.7)
6
6
  json (~> 1.8)
7
7
 
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 TODO: Write your name
3
+ Copyright (c) 2018 Rohan Anand
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # WatsonNLPWrapper
2
2
 
3
3
  [![Build Status](https://travis-ci.org/thededlier/WatsonNLPWrapper.svg?branch=master)](https://travis-ci.org/thededlier/WatsonNLPWrapper)
4
+ [![Gem Version](https://badge.fury.io/rb/WatsonNLPWrapper.svg)](https://badge.fury.io/rb/WatsonNLPWrapper)
5
+ [rubygems.org/gems/WatsonNLPWrapper](https://rubygems.org/gems/WatsonNLPWrapper)
4
6
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/WatsonNLPWrapper`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
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`. 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).
65
+ To install this gem onto your local machine, run `bundle exec rake install`.
34
66
 
35
67
  ## Contributing
36
68
 
@@ -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
- # Returns credentials used for basic auth
37
- def auth
38
- {
39
- username: @username,
40
- password: @password
41
- }
42
- end
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
- # Default features if no features specified
45
- def default_features
46
- {
47
- entities: {
48
- emotion: true,
49
- sentiment: true,
50
- limit: 2
51
- },
52
- keywords: {
53
- emotion: true,
54
- sentiment: true,
55
- limit: 2
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
@@ -2,5 +2,7 @@ module WatsonNLPWrapper
2
2
  module Constants
3
3
  DEFAULT_VERSION = '2018-03-16'
4
4
  CONTENT_TYPE = 'application/json'
5
+
6
+ NIL_ARGUMENT_ERROR = "Arguments cannot be nil"
5
7
  end
6
8
  end
@@ -1,3 +1,3 @@
1
1
  module WatsonNLPWrapper
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  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.0.0
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-05 00:00:00.000000000 Z
11
+ date: 2018-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler