rosette_api 1.14.4 → 1.27.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b38b4872ea8951d43abf562f7feed44bf672e2508ec78e34c6e05327293b8c35
4
- data.tar.gz: 5608e8136b43a67a771fe860f51deee5c14da58aefa90211d6bb0be77a14834a
3
+ metadata.gz: 3d5037aff054e99e751a771f2f320382aeb888c42e50791c1a4c4ddcb17eebe0
4
+ data.tar.gz: f61eaa6cd0cf434208dba133666d9b3886ad9395858d871dcd4058cf5a293b74
5
5
  SHA512:
6
- metadata.gz: 85f6244f0c40958eabe5165b85dc2ee13e849924f9a500404391541bfb490291e46b8461dcc4f3bfd90ca54ff04ba5585d3b9654d4df8b9b3d2d7c72a4f031ae
7
- data.tar.gz: 2dea9f348e81a32fa8f6e692f66385fe0b4143b34902d03765d027087f0b83f670bb428845d77afded27a12bfa013a52b806d042e233266e3cd5924a805bcd64
6
+ metadata.gz: a0106a3b3b555bc4c49284740e348356262bce1b39a44dee87651127b8a07192fe5a26a726d1eb60d95af0d8c8e1087b3074f1440de4958752e5c2a1cd2b204e
7
+ data.tar.gz: 966fbc85cadb4b09b53879ee1b3d6f7d7c91a21c7ffb4bc51e1f43f58524bf5ed6c0e8f3547539341bf2a9132f092a6248953d3ab5f290b78c7d2cf204313d2b
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2016-2019 Basis Technology Corporation.
1
+ Copyright (c) 2016-2024 Basis Technology Corporation.
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- <a href="https://www.rosette.com"><img src="https://s3.amazonaws.com/styleguide.basistech.com/logos/rosette-logo.png" width="181" height="47" /></a>
1
+ <a href="https://www.babelstreet.com/rosette"><img src="https://s3.amazonaws.com/styleguide.basistech.com/logos/rosette-logo.png" width="181" height="47" /></a>
2
2
 
3
3
  ---
4
4
 
5
- [![Build Status](https://travis-ci.org/rosette-api/ruby.svg?branch=develop)](https://travis-ci.org/rosette-api/ruby) [![Gem Version](https://badge.fury.io/rb/rosette_api.svg)](https://badge.fury.io/rb/rosette_api)
5
+ [![Gem Version](https://badge.fury.io/rb/rosette_api.svg)](https://badge.fury.io/rb/rosette_api)
6
6
 
7
7
  ## Rosette API
8
8
  The Rosette Text Analytics Platform uses natural language processing, statistical modeling, and machine learning to
@@ -12,7 +12,6 @@ comparing the similarity of names, categorizing and adding linguistic tags to te
12
12
 
13
13
  ## Rosette API Access
14
14
  - Rosette Cloud [Sign Up](https://developer.rosette.com/signup)
15
- - Rosette Enterprise [Evaluation](https://www.rosette.com/product-eval/)
16
15
 
17
16
  ## Quick Start
18
17
 
data/examples/README.md CHANGED
@@ -13,7 +13,7 @@ A note on prerequisites. Rosette API only suports TLS 1.2 so ensure your toolcha
13
13
  ```
14
14
  git clone git@github.com:rosette-api/ruby.git
15
15
  cd ruby
16
- docker run -it -v $(pwd):/source --entrypoint bash ruby:2.6-slim-stretch
16
+ docker run -it -v $(pwd):/source --entrypoint bash ruby:3.3-slim
17
17
 
18
18
  gem install rosette_api
19
19
 
@@ -25,7 +25,7 @@ ruby ping.rb $API_KEY
25
25
  ```
26
26
  git clone git@github.com:rosette-api/ruby.git
27
27
  cd ruby
28
- docker run -it -v $(pwd):/source --entrypoint bash ruby:2.6-slim-stretch
28
+ docker run -it -v $(pwd):/source --entrypoint bash ruby:3.3-slim
29
29
 
30
30
  cd /source
31
31
  gem build rosette_api.gemspec
@@ -10,9 +10,9 @@ rosette_api = if url
10
10
  RosetteAPI.new(api_key)
11
11
  end
12
12
 
13
- categories_url_data = 'https://onlocationvacations.com/2018/02/06/downton-abbey-exhibition-extended-april-2-nyc/'
13
+ categories_text_data = 'If you are a fan of the British television series Downton Abbey and you are planning to be in New York anytime before April 2nd, there is a perfect stop for you while in town.'
14
14
  begin
15
- params = DocumentParameters.new(content_uri: categories_url_data)
15
+ params = DocumentParameters.new(content: categories_text_data)
16
16
  response = rosette_api.get_categories(params)
17
17
  puts JSON.pretty_generate(response)
18
18
  rescue RosetteAPIError => e
data/examples/entities.rb CHANGED
@@ -12,8 +12,7 @@ rosette_api = if url
12
12
 
13
13
  entities_text_data = 'The Securities and Exchange Commission today announced the leadership of the agency\'s trial unit. Bridget Fitzpatrick has been named Chief Litigation Counsel of the SEC and David Gottesman will continue to serve as the agency\'s Deputy Chief Litigation Counsel. Since December 2016, Ms. Fitzpatrick and Mr. Gottesman have served as Co-Acting Chief Litigation Counsel. In that role, they were jointly responsible for supervising the trial unit at the agency\'s Washington D.C. headquarters as well as coordinating with litigators in the SEC\'s 11 regional offices around the country.'
14
14
  begin
15
- params = DocumentParameters.new(content: entities_text_data,
16
- genre: 'social-media')
15
+ params = DocumentParameters.new(content: entities_text_data)
17
16
  response = rosette_api.get_entities(params)
18
17
  puts JSON.pretty_generate(response)
19
18
  rescue RosetteAPIError => e
@@ -39,7 +39,7 @@ class AddressParameter
39
39
  # po_box (optional)
40
40
  attr_accessor :po_box
41
41
 
42
- def initialize(options = {}) #:notnew:
42
+ def initialize(options = {}) # :notnew:
43
43
  options = {
44
44
  house: nil,
45
45
  house_number: nil,
@@ -85,8 +85,7 @@ class AddressParameter
85
85
  # Returns the new Hash.
86
86
  def load_param
87
87
  to_hash.select { |_key, value| value }
88
- .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
89
- .to_h
88
+ .transform_keys { |key| key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase) }
90
89
  end
91
90
 
92
91
  # Converts this class to Hash.
@@ -11,7 +11,7 @@ class AddressSimilarityParameters
11
11
  # Address to be compared to address1
12
12
  attr_accessor :address2
13
13
 
14
- def initialize(address1, address2) #:notnew:
14
+ def initialize(address1, address2) # :notnew:
15
15
  @address1 = address1
16
16
  @address2 = address2
17
17
  end
@@ -32,9 +32,8 @@ class AddressSimilarityParameters
32
32
  def load_params
33
33
  validate_params
34
34
  to_hash
35
- .reject { |_key, value| value.nil? }
36
- .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
37
- .to_h
35
+ .compact
36
+ .transform_keys { |key| key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase) }
38
37
  end
39
38
 
40
39
  # Converts this class to Hash.
@@ -4,7 +4,7 @@ require_relative 'rosette_api_error'
4
4
 
5
5
  # This class represents Rosette API errors with badRequest status_code.
6
6
  class BadRequestError < RosetteAPIError
7
- def initialize(message) #:notnew:
8
- super 'badRequest', message
7
+ def initialize(message) # :notnew:
8
+ super('badRequest', message)
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ require_relative 'rosette_api_error'
4
4
 
5
5
  # This class represents Rosette API errors with badRequestFormat status_code.
6
6
  class BadRequestFormatError < RosetteAPIError
7
- def initialize(message) #:notnew:
8
- super 'badRequestFormat', message
7
+ def initialize(message) # :notnew:
8
+ super('badRequestFormat', message)
9
9
  end
10
10
  end
@@ -22,7 +22,7 @@ class DocumentParameters
22
22
  # custom Rosette API headers
23
23
  attr_accessor :custom_headers
24
24
 
25
- def initialize(options = {}) #:notnew:
25
+ def initialize(options = {}) # :notnew:
26
26
  options = {
27
27
  content: nil,
28
28
  content_uri: nil,
@@ -45,11 +45,11 @@ class DocumentParameters
45
45
  # set or no content provided at all.
46
46
  def validate_params
47
47
  content_msg = 'The format of the request is invalid: multiple content ' \
48
- 'sources; must be one of an attachment, an inline "content" field, or ' \
49
- 'an external "contentUri"'
48
+ 'sources; must be one of an attachment, an inline "content" field, or ' \
49
+ 'an external "contentUri"'
50
50
  no_content_msg = 'The format of the request is invalid: no content ' \
51
- 'provided; must be one of an attachment, an inline "content" field, or ' \
52
- 'an external "contentUri"'
51
+ 'provided; must be one of an attachment, an inline "content" field, or ' \
52
+ 'an external "contentUri"'
53
53
  opt_msg = 'rosette_options can only be an instance of a Hash'
54
54
  if [@content, @content_uri, @file_path].compact.length > 1
55
55
  raise BadRequestFormatError.new(content_msg)
@@ -67,8 +67,7 @@ class DocumentParameters
67
67
  validate_params
68
68
  to_hash
69
69
  .select { |_key, value| value }
70
- .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
71
- .to_h
70
+ .transform_keys { |key| key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase) }
72
71
  end
73
72
 
74
73
  # Converts this class to Hash.
@@ -13,7 +13,7 @@ class NameDeduplicationParameters
13
13
  # Threshold for determining cluster size
14
14
  attr_accessor :threshold
15
15
 
16
- def initialize(names, threshold, options = {}) #:notnew:
16
+ def initialize(names, threshold, options = {}) # :notnew:
17
17
  options = {
18
18
  rosette_options: nil
19
19
  }.update options
@@ -35,9 +35,7 @@ class NameDeduplicationParameters
35
35
  raise BadRequestError.new(thresh_msg) if @threshold.negative? || @threshold > 1
36
36
  end
37
37
  opt_msg = 'rosette_options can only be an instance of a Hash'
38
- if @rosette_options
39
- raise BadRequestError.new(opt_msg) unless @rosette_options.is_a? Hash
40
- end
38
+ raise BadRequestError.new(opt_msg) if @rosette_options && !(@rosette_options.is_a? Hash)
41
39
  end
42
40
 
43
41
  # Converts this class to Hash with its keys in lower CamelCase.
@@ -47,8 +45,7 @@ class NameDeduplicationParameters
47
45
  validate_params
48
46
  to_hash
49
47
  .select { |_key, value| value }
50
- .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
51
- .to_h
48
+ .transform_keys { |key| key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase) }
52
49
  end
53
50
 
54
51
  # Converts this class to Hash.
@@ -11,7 +11,7 @@ class NameParameter
11
11
  # Name to be analyzed
12
12
  attr_accessor :text
13
13
 
14
- def initialize(text, options = {}) #:notnew:
14
+ def initialize(text, options = {}) # :notnew:
15
15
  options = {
16
16
  entity_type: nil,
17
17
  language: nil,
@@ -29,8 +29,7 @@ class NameParameter
29
29
  def load_param
30
30
  to_hash
31
31
  .select { |_key, value| value }
32
- .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
33
- .to_h
32
+ .transform_keys { |key| key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase) }
34
33
  end
35
34
 
36
35
  # Converts this class to Hash.
@@ -15,7 +15,7 @@ class NameSimilarityParameters
15
15
  # Name to be compared to name1
16
16
  attr_accessor :name2
17
17
 
18
- def initialize(name1, name2, options = {}) #:notnew:
18
+ def initialize(name1, name2, options = {}) # :notnew:
19
19
  options = {
20
20
  genre: nil,
21
21
  rosette_options: nil
@@ -36,9 +36,7 @@ class NameSimilarityParameters
36
36
  raise BadRequestError.new(n2_msg) if [String, NameParameter].none? { |clazz| @name2.is_a? clazz }
37
37
 
38
38
  opt_msg = 'rosette_options can only be an instance of a Hash'
39
- if @rosette_options
40
- raise BadRequestError.new(opt_msg) unless @rosette_options.is_a? Hash
41
- end
39
+ raise BadRequestError.new(opt_msg) if @rosette_options && !(@rosette_options.is_a? Hash)
42
40
  end
43
41
 
44
42
  # Converts this class to Hash with its keys in lower CamelCase.
@@ -47,9 +45,8 @@ class NameSimilarityParameters
47
45
  def load_params
48
46
  validate_params
49
47
  to_hash
50
- .reject { |_key, value| value.nil? }
51
- .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
52
- .to_h
48
+ .compact
49
+ .transform_keys { |key| key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase) }
53
50
  end
54
51
 
55
52
  # Converts this class to Hash.
@@ -27,7 +27,7 @@ class NameTranslationParameters
27
27
  # ISO 15924 code of name's script (optional)
28
28
  attr_accessor :target_script
29
29
 
30
- def initialize(name, target_language, options = {}) #:notnew:
30
+ def initialize(name, target_language, options = {}) # :notnew:
31
31
  options = {
32
32
  entity_type: nil,
33
33
  genre: nil,
@@ -54,9 +54,7 @@ class NameTranslationParameters
54
54
  # of a Hash.
55
55
  def validate_params
56
56
  msg = 'rosette_options can only be an instance of a Hash'
57
- if @rosette_options
58
- raise BadRequestError.new(msg) unless @rosette_options.is_a? Hash
59
- end
57
+ raise BadRequestError.new(msg) if @rosette_options && !(@rosette_options.is_a? Hash)
60
58
  end
61
59
 
62
60
  # Converts this class to Hash with its keys in lower CamelCase.
@@ -66,8 +64,7 @@ class NameTranslationParameters
66
64
  validate_params
67
65
  to_hash
68
66
  .select { |_key, value| value }
69
- .map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
70
- .to_h
67
+ .transform_keys { |key| key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase) }
71
68
  end
72
69
 
73
70
  # Converts this class to Hash.
@@ -28,11 +28,11 @@ class RequestBuilder
28
28
  @http_client = http_client
29
29
  @binding_version = binding_version
30
30
  @params = params
31
- @user_agent = 'Ruby/' + binding_version + '/' + RUBY_VERSION
31
+ @user_agent = "Ruby/#{binding_version}/#{RUBY_VERSION}"
32
32
 
33
33
  return unless url_parameters
34
34
 
35
- @alternate_url = @alternate_url + '?' + URI.encode_www_form(url_parameters)
35
+ @alternate_url = "#{@alternate_url}?#{URI.encode_www_form(url_parameters)}"
36
36
  end
37
37
 
38
38
  # Prepares a plain POST request for Rosette API.
@@ -203,16 +203,16 @@ class RequestBuilder
203
203
  def get_response(http, request)
204
204
  response = http.request request
205
205
 
206
- if response.code != '200'
207
- message = JSON.parse(response.body)['message']
208
- code = JSON.parse(response.body)['code']
209
- raise RosetteAPIError.new code, message
210
- else
206
+ if response.code == '200'
211
207
  response_headers = {}
212
208
  response.header.each_header { |key, value| response_headers[key] = value }
213
209
  response_headers = { responseHeaders: response_headers }
214
210
 
215
211
  JSON.parse(response.body).merge(response_headers)
212
+ else
213
+ message = JSON.parse(response.body)['message']
214
+ code = JSON.parse(response.body)['code']
215
+ raise RosetteAPIError.new code, message
216
216
  end
217
217
  end
218
218
  end
data/lib/rosette_api.rb CHANGED
@@ -9,11 +9,12 @@ require_relative 'address_similarity_parameters'
9
9
  require_relative 'rosette_api_error'
10
10
  require_relative 'bad_request_error'
11
11
  require_relative 'bad_request_format_error'
12
+ require 'logger'
12
13
 
13
14
  # This class allows you to access all Rosette API endpoints.
14
15
  class RosetteAPI
15
16
  # Version of Ruby binding
16
- BINDING_VERSION = '1.14.4'
17
+ BINDING_VERSION = '1.27.1'
17
18
  # Rosette API language endpoint
18
19
  LANGUAGE_ENDPOINT = '/language'
19
20
  # Rosette API morphology endpoint
@@ -65,13 +66,12 @@ class RosetteAPI
65
66
  attr_accessor :url_parameters
66
67
 
67
68
  def initialize(user_key, alternate_url = 'https://api.rosette.com/rest/v1')
69
+ @log = Logger.new($stdout)
68
70
  @user_key = user_key
69
71
  @alternate_url = alternate_url
70
72
  @url_parameters = nil
71
73
 
72
- if @alternate_url.to_s.end_with?('/')
73
- @alternate_url = alternate_url.to_s.slice(0..-2)
74
- end
74
+ @alternate_url = alternate_url.to_s.slice(0..-2) if @alternate_url.to_s.end_with?('/')
75
75
 
76
76
  uri = URI.parse alternate_url
77
77
  @http_client = Net::HTTP.new uri.host, uri.port
@@ -111,7 +111,7 @@ class RosetteAPI
111
111
 
112
112
  params = params.load_params
113
113
 
114
- endpoint = MORPHOLOGY_ENDPOINT + '/complete'
114
+ endpoint = "#{MORPHOLOGY_ENDPOINT}/complete"
115
115
  RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client,
116
116
  BINDING_VERSION, params, @url_parameters)
117
117
  .send_post_request
@@ -131,7 +131,7 @@ class RosetteAPI
131
131
 
132
132
  params = params.load_params
133
133
 
134
- endpoint = MORPHOLOGY_ENDPOINT + '/compound-components'
134
+ endpoint = "#{MORPHOLOGY_ENDPOINT}/compound-components"
135
135
  RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client,
136
136
  BINDING_VERSION, params, @url_parameters)
137
137
  .send_post_request
@@ -151,7 +151,7 @@ class RosetteAPI
151
151
 
152
152
  params = params.load_params
153
153
 
154
- endpoint = MORPHOLOGY_ENDPOINT + '/han-readings'
154
+ endpoint = "#{MORPHOLOGY_ENDPOINT}/han-readings"
155
155
  RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client,
156
156
  BINDING_VERSION, params, @url_parameters)
157
157
  .send_post_request
@@ -170,7 +170,7 @@ class RosetteAPI
170
170
 
171
171
  params = params.load_params
172
172
 
173
- endpoint = MORPHOLOGY_ENDPOINT + '/lemmas'
173
+ endpoint = "#{MORPHOLOGY_ENDPOINT}/lemmas"
174
174
  RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client,
175
175
  BINDING_VERSION, params, @url_parameters)
176
176
  .send_post_request
@@ -190,7 +190,7 @@ class RosetteAPI
190
190
 
191
191
  params = params.load_params
192
192
 
193
- endpoint = MORPHOLOGY_ENDPOINT + '/parts-of-speech'
193
+ endpoint = "#{MORPHOLOGY_ENDPOINT}/parts-of-speech"
194
194
  RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client,
195
195
  BINDING_VERSION, params, @url_parameters)
196
196
  .send_post_request
@@ -530,5 +530,9 @@ class RosetteAPI
530
530
  message = 'Expects a DocumentParameters type as an argument',
531
531
  type = DocumentParameters)
532
532
  raise BadRequestError.new message unless params.is_a? type
533
+
534
+ return unless defined?(params.genre) && !params.genre.nil?
535
+
536
+ @log.warn('The genre parameter is deprecated and will be removed in a future release.')
533
537
  end
534
538
  end
@@ -8,8 +8,9 @@ class RosetteAPIError < StandardError
8
8
  # Rosette API error's message
9
9
  attr_accessor :message
10
10
 
11
- def initialize(status_code, message) #:notnew:
11
+ def initialize(status_code, message) # :notnew:
12
12
  @status_code = status_code
13
13
  @message = message
14
+ super(message)
14
15
  end
15
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rosette_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.4
4
+ version: 1.27.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Basis Technology Corp
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-16 00:00:00.000000000 Z
11
+ date: 2024-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubysl-securerandom
@@ -77,8 +77,9 @@ files:
77
77
  homepage: https://developer.rosette.com/
78
78
  licenses:
79
79
  - Apache-2.0
80
- metadata: {}
81
- post_install_message:
80
+ metadata:
81
+ rubygems_mfa_required: 'true'
82
+ post_install_message:
82
83
  rdoc_options: []
83
84
  require_paths:
84
85
  - lib
@@ -86,15 +87,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
87
  requirements:
87
88
  - - ">="
88
89
  - !ruby/object:Gem::Version
89
- version: 2.3.0
90
+ version: 3.0.0
90
91
  required_rubygems_version: !ruby/object:Gem::Requirement
91
92
  requirements:
92
93
  - - ">="
93
94
  - !ruby/object:Gem::Version
94
95
  version: '0'
95
96
  requirements: []
96
- rubygems_version: 3.1.2
97
- signing_key:
97
+ rubygems_version: 3.5.3
98
+ signing_key:
98
99
  specification_version: 4
99
100
  summary: A Ruby interface for Rosette Text Analytics Platform.
100
101
  test_files: []