rosette_api 1.14.3 → 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: 88f16158b8883961fecc410ce85c874914d8610a3e179955f5d2429fb2c4b7ab
4
- data.tar.gz: 818932647be367d98c903e4487ba52bd8164f686f0c16be791a8cc54a3b30cc5
3
+ metadata.gz: 3d5037aff054e99e751a771f2f320382aeb888c42e50791c1a4c4ddcb17eebe0
4
+ data.tar.gz: f61eaa6cd0cf434208dba133666d9b3886ad9395858d871dcd4058cf5a293b74
5
5
  SHA512:
6
- metadata.gz: c1cc5483c3e5e4ed59104c82a14c548b303f85d7be9bb74551b8dbec467de16b15b23fbc9bf7b4374aade07f41bd1d2ac2b16ec509293ceeccb4ca5f35922650
7
- data.tar.gz: 0fa5063ae2d6765314df3b33c1a0620b974b24a8c0c3b627c5617b75ca9e13d1ac1d62a2d4522464004e654c24f4217c52e164d606690ff8697ccd83389fa2f2
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
@@ -18,13 +18,7 @@ begin
18
18
  state: 'DC',
19
19
  post_code: '20500'
20
20
  )
21
- address2 = AddressParameter.new(
22
- house_number: '160',
23
- road: 'Pennsilvana Avenue',
24
- city: 'Washington',
25
- state: 'D.C.',
26
- post_code: '20500'
27
- )
21
+ address2 = '160 Pennsilvana Avenue, Washington, D.C., 20500'
28
22
  params = AddressSimilarityParameters.new(address1, address2)
29
23
  response = rosette_api.get_address_similarity(params)
30
24
  puts JSON.pretty_generate(response)
@@ -10,11 +10,9 @@ rosette_api = if url
10
10
  RosetteAPI.new(api_key)
11
11
  end
12
12
 
13
- categories_url_data =
14
- 'https://onlocationvacations.com/2015/03/05/the-new-ghostbusters-movie-' \
15
- 'begins-filming-in-boston-in-june/'
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.'
16
14
  begin
17
- params = DocumentParameters.new(content_uri: categories_url_data)
15
+ params = DocumentParameters.new(content: categories_text_data)
18
16
  response = rosette_api.get_categories(params)
19
17
  puts JSON.pretty_generate(response)
20
18
  rescue RosetteAPIError => e
data/examples/entities.rb CHANGED
@@ -10,18 +10,9 @@ rosette_api = if url
10
10
  RosetteAPI.new(api_key)
11
11
  end
12
12
 
13
- entities_text_data = 'The Securities and Exchange Commission today ' \
14
- 'announced the leadership of the agency\'s trial unit. Bridget Fitzpatrick ' \
15
- 'has been named Chief Litigation Counsel of the SEC and David Gottesman ' \
16
- 'will continue to serve as the agency\'s Deputy Chief Litigation Counsel. ' \
17
- 'Since December 2016, Ms. Fitzpatrick and Mr. Gottesman have served as ' \
18
- 'Co-Acting Chief Litigation Counsel. In that role, they were jointly ' \
19
- 'responsible for supervising the trial unit at the agency\'s Washington ' \
20
- 'D.C. headquarters as well as coordinating with litigators in the SEC\'s ' \
21
- '11 regional offices around the country.'
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.'
22
14
  begin
23
- params = DocumentParameters.new(content: entities_text_data,
24
- genre: 'social-media')
15
+ params = DocumentParameters.new(content: entities_text_data)
25
16
  response = rosette_api.get_entities(params)
26
17
  puts JSON.pretty_generate(response)
27
18
  rescue RosetteAPIError => e
@@ -10,15 +10,7 @@ rosette_api = if url
10
10
  RosetteAPI.new(api_key)
11
11
  end
12
12
 
13
- language_multilingual_data = 'On Thursday, as protesters gathered in ' \
14
- 'Washington D.C., the United States Federal Communications Commission ' \
15
- 'under Chairman Ajit Pai voted 3-2 to overturn a 2015 decision, commonly ' \
16
- 'called Net Neutrality, that forbade Internet service providers (ISPs) ' \
17
- 'such as Verizon, Comcast, and AT&T from blocking individual websites or ' \
18
- 'charging websites or customers more for faster load times. Quatre ' \
19
- 'femmes ont été nommées au Conseil de rédaction de la loi du Qatar. Jeudi, ' \
20
- 'le décret royal du Qatar a annoncé que 28 nouveaux membres ont été nommés ' \
21
- 'pour le Conseil de la Choura du pays. ذكرت مصادر أمنية يونانية، أن 9 موقوفين من منظمة \"د هـ ك ب ج\" الذين كانت قد أوقفتهم الشرطة اليونانية في وقت سابق كانوا يخططون لاغتيال الرئيس التركي رجب طيب أردوغان.'
13
+ language_multilingual_data = 'On Thursday, as protesters gathered in Washington D.C., the United States Federal Communications Commission under Chairman Ajit Pai voted 3-2 to overturn a 2015 decision, commonly called Net Neutrality, that forbade Internet service providers (ISPs) such as Verizon, Comcast, and AT&T from blocking individual websites or charging websites or customers more for faster load times. Quatre femmes ont été nommées au Conseil de rédaction de la loi du Qatar. Jeudi, le décret royal du Qatar a annoncé que 28 nouveaux membres ont été nommés pour le Conseil de la Choura du pays. ذكرت مصادر أمنية يونانية، أن 9 موقوفين من منظمة \"د هـ ك ب ج\" الذين كانت قد أوقفتهم الشرطة اليونانية في وقت سابق كانوا يخططون لاغتيال الرئيس التركي رجب طيب أردوغان.'
22
14
 
23
15
  begin
24
16
  params = DocumentParameters.new(content: language_multilingual_data)
@@ -10,8 +10,7 @@ rosette_api = if url
10
10
  RosetteAPI.new(api_key)
11
11
  end
12
12
 
13
- morphology_complete_data = 'The quick brown fox jumped over the lazy ' \
14
- 'dog. 👍🏾 Yes he did. B)'
13
+ morphology_complete_data = 'The quick brown fox jumped over the lazy dog. 👍🏾 Yes he did. B)'
15
14
  begin
16
15
  params = DocumentParameters.new(content: morphology_complete_data)
17
16
  response = rosette_api.get_morphology_complete(params)
@@ -10,9 +10,7 @@ rosette_api = if url
10
10
  RosetteAPI.new(api_key)
11
11
  end
12
12
 
13
- morphology_lemmas_data =
14
- 'The fact is that the geese just went back to get a rest and I\'m not ' \
15
- 'banking on their return soon'
13
+ morphology_lemmas_data = 'The fact is that the geese just went back to get a rest and I\'m not banking on their return soon'
16
14
  begin
17
15
  params = DocumentParameters.new(content: morphology_lemmas_data)
18
16
  response = rosette_api.get_lemmas(params)
@@ -10,9 +10,7 @@ rosette_api = if url
10
10
  RosetteAPI.new(api_key)
11
11
  end
12
12
 
13
- morphology_parts_of_speech_data =
14
- 'The fact is that the geese just went back to get a rest and I\'m not ' \
15
- 'banking on their return soon'
13
+ morphology_parts_of_speech_data = 'The fact is that the geese just went back to get a rest and I\'m not banking on their return soon'
16
14
  begin
17
15
  params = DocumentParameters.new(content: morphology_parts_of_speech_data)
18
16
  response = rosette_api.get_parts_of_speech(params)
@@ -10,9 +10,7 @@ rosette_api = if url
10
10
  RosetteAPI.new(api_key)
11
11
  end
12
12
 
13
- name_dedupe_data = 'Alice Terry,Alice Thierry,Betty Grable,Betty Gable,' \
14
- 'Norma Shearer,Norm Shearer,Brigitte Helm,Bridget Helem,Judy Holliday,' \
15
- 'Julie Halliday'
13
+ name_dedupe_data = 'Alice Terry,Alice Thierry,Betty Grable,Betty Gable,Norma Shearer,Norm Shearer,Brigitte Helm,Bridget Helem,Judy Holliday,Julie Halliday'
16
14
 
17
15
  threshold = 0.75
18
16
  names = name_dedupe_data.split(',').map { |n| NameParameter.new(n) }
@@ -10,15 +10,7 @@ rosette_api = if url
10
10
  RosetteAPI.new(api_key)
11
11
  end
12
12
 
13
- relationships_text_data = 'FLIR Systems is headquartered in Oregon and ' \
14
- 'produces thermal imaging, night vision, and infrared cameras and sensor ' \
15
- 'systems. According to the SEC\'s order instituting a settled ' \
16
- 'administrative proceeding, FLIR entered into a multi-million dollar ' \
17
- 'contract to provide thermal binoculars to the Saudi government in ' \
18
- 'November 2008. Timms and Ramahi were the primary sales employees ' \
19
- 'responsible for the contract, and also were involved in negotiations to ' \
20
- 'sell FLIR\'s security cameras to the same government officials. At the ' \
21
- 'time, Timms was the head of FLIR\'s Middle East office in Dubai.'
13
+ relationships_text_data = 'FLIR Systems is headquartered in Oregon and produces thermal imaging, night vision, and infrared cameras and sensor systems. According to the SEC\'s order instituting a settled administrative proceeding, FLIR entered into a multi-million dollar contract to provide thermal binoculars to the Saudi government in November 2008. Timms and Ramahi were the primary sales employees responsible for the contract, and also were involved in negotiations to sell FLIR\'s security cameras to the same government officials. At the time, Timms was the head of FLIR\'s Middle East office in Dubai.'
22
14
 
23
15
  begin
24
16
  params = DocumentParameters.new(content: relationships_text_data)
@@ -10,11 +10,7 @@ rosette_api = if url
10
10
  RosetteAPI.new(api_key)
11
11
  end
12
12
 
13
- sentences_data = 'This land is your land. This land is my land, from ' \
14
- 'California to the New York island; from the red wood forest to the Gulf ' \
15
- 'Stream waters. This land was made for you and Me. As I was walking that ' \
16
- 'ribbon of highway, I saw above me that endless skyway: I saw below me ' \
17
- 'that golden valley: This land was made for you and me.'
13
+ sentences_data = 'This land is your land. This land is my land, from California to the New York island; from the red wood forest to the Gulf Stream waters. This land was made for you and Me. As I was walking that ribbon of highway, I saw above me that endless skyway: I saw below me that golden valley: This land was made for you and me.'
18
14
 
19
15
  begin
20
16
  params = DocumentParameters.new
@@ -12,13 +12,7 @@ rosette_api = if url
12
12
  end
13
13
 
14
14
  file = Tempfile.new(%w[foo .html])
15
- sentiment_file_data =
16
- '<html><head><title>New Ghostbusters Film</title></head><body><p>Original ' \
17
- 'Ghostbuster Dan Aykroyd, who also co-wrote the 1984 Ghostbusters film, ' \
18
- 'couldn\'t be more pleased with the new all-female Ghostbusters cast, ' \
19
- 'telling The Hollywood Reporter, "The Aykroyd family is delighted by this ' \
20
- 'inheritance of the Ghostbusters torch by these most magnificent women in ' \
21
- 'comedy."</p></body></html>'
15
+ sentiment_file_data = '<html><head><title>New Ghostbusters Film</title></head><body><p>Original Ghostbuster Dan Aykroyd, who also co-wrote the 1984 Ghostbusters film, couldn\'t be more pleased with the new all-female Ghostbusters cast, telling The Hollywood Reporter, "The Aykroyd family is delighted by this inheritance of the Ghostbusters torch by these most magnificent women in comedy."</p></body></html>'
22
16
  file.write(sentiment_file_data)
23
17
  file.close
24
18
  begin
@@ -10,9 +10,7 @@ rosette_api = if url
10
10
  RosetteAPI.new(api_key)
11
11
  end
12
12
 
13
- syntax_dependencies_data =
14
- 'Yoshinori Ohsumi, a Japanese cell biologist, was awarded the Nobel Prize ' \
15
- 'in Physiology or Medicine on Monday.'
13
+ syntax_dependencies_data = 'Yoshinori Ohsumi, a Japanese cell biologist, was awarded the Nobel Prize in Physiology or Medicine on Monday.'
16
14
 
17
15
  begin
18
16
  params = DocumentParameters.new(content: syntax_dependencies_data)
data/examples/topics.rb CHANGED
@@ -10,14 +10,8 @@ rosette_api = if url
10
10
  RosetteAPI.new(api_key)
11
11
  end
12
12
 
13
- topics_data =
14
- 'Lily Collins is in talks to join Nicholas Hoult in Chernin Entertainment ' \
15
- "and Fox Searchlight's J.R.R. Tolkien biopic Tolkien. Anthony Boyle, known " \
16
- 'for playing Scorpius Malfoy in the British play Harry Potter and the ' \
17
- 'Cursed Child, also has signed on for the film centered on the famed ' \
18
- 'author. In Tolkien, Hoult will play the author of the Hobbit and Lord of ' \
19
- 'the Rings book series that were later adapted into two Hollywood ' \
20
- 'trilogies from Peter Jackson. Dome Karukoski is directing the project.'
13
+ topics_data = 'Lily Collins is in talks to join Nicholas Hoult in Chernin Entertainment and Fox Searchlight\'s J.R.R. Tolkien biopic Tolkien. Anthony Boyle, known for playing Scorpius Malfoy in the British play Harry Potter and the Cursed Child, also has signed on for the film centered on the famed author. In Tolkien, Hoult will play the author of the Hobbit and Lord of the Rings book series that were later adapted into two Hollywood trilogies from Peter Jackson. Dome Karukoski is directing the project.'
14
+
21
15
  begin
22
16
  params = DocumentParameters.new(content: topics_data)
23
17
  response = rosette_api.get_topics(params)
@@ -10,8 +10,7 @@ rosette_api = if url
10
10
  RosetteAPI.new(api_key)
11
11
  end
12
12
 
13
- transliteration_content_data =
14
- 'Kareem Abdul Jabbar holds the records for most points in the NBA'
13
+ transliteration_content_data = 'ana r2ye7 el gam3a el sa3a 3 el 3asr'
15
14
 
16
15
  begin
17
16
  params = DocumentParameters.new
@@ -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,19 +11,19 @@ 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
18
18
 
19
19
  # Validates the parameters by checking if address1 and address2 are instances
20
- # of AddressParameter.
20
+ # of AddressParameters or Strings.
21
21
  def validate_params
22
- a1_msg = 'address1 option can only be an instance of an AddressParameter'
23
- raise BadRequestError.new(a1_msg) if [AddressParameter].none? { |clazz| @address1.is_a? clazz }
22
+ a1_msg = 'address1 option can only be an instance of an AddressParameter or a String'
23
+ raise BadRequestError.new(a1_msg) if [String, AddressParameter].none? { |clazz| @address1.is_a? clazz }
24
24
 
25
- a2_msg = 'address2 option can only be an instance of an AddressParameter'
26
- raise BadRequestError.new(a2_msg) if [AddressParameter].none? { |clazz| @address2.is_a? clazz }
25
+ a2_msg = 'address2 option can only be an instance of an AddressParameter or a String'
26
+ raise BadRequestError.new(a2_msg) if [String, AddressParameter].none? { |clazz| @address2.is_a? clazz }
27
27
  end
28
28
 
29
29
  # Converts this class to Hash with its keys in lower CamelCase.
@@ -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.3'
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.3
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: 2019-11-06 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
@@ -45,10 +45,10 @@ files:
45
45
  - examples/language.rb
46
46
  - examples/language_multilingual.rb
47
47
  - examples/morphology_complete.rb
48
- - examples/morphology_compound_components.rb
49
- - examples/morphology_han_readings.rb
48
+ - examples/morphology_compound-components.rb
49
+ - examples/morphology_han-readings.rb
50
50
  - examples/morphology_lemmas.rb
51
- - examples/morphology_parts_of_speech.rb
51
+ - examples/morphology_parts-of-speech.rb
52
52
  - examples/name_deduplication.rb
53
53
  - examples/name_similarity.rb
54
54
  - examples/name_translation.rb
@@ -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.0.3
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: []