rosette_api 1.14.4 → 1.37.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/LICENSE +1 -1
- data/README.md +23 -16
- data/examples/README.md +2 -2
- data/examples/address_similarity.rb +7 -6
- data/examples/categories.rb +9 -8
- data/examples/entities.rb +8 -8
- data/examples/events.rb +23 -0
- data/examples/info.rb +7 -6
- data/examples/language.rb +7 -6
- data/examples/language_multilingual.rb +7 -6
- data/examples/morphology_complete.rb +7 -6
- data/examples/morphology_compound-components.rb +7 -6
- data/examples/morphology_han-readings.rb +7 -6
- data/examples/morphology_lemmas.rb +7 -6
- data/examples/morphology_parts-of-speech.rb +7 -6
- data/examples/multipart_language_file.rb +29 -0
- data/examples/name_deduplication.rb +7 -6
- data/examples/name_similarity.rb +9 -7
- data/examples/name_translation.rb +7 -6
- data/examples/ping.rb +7 -6
- data/examples/record_similarity.rb +114 -0
- data/examples/relationships.rb +7 -6
- data/examples/semantic_vectors.rb +7 -6
- data/examples/sentences.rb +7 -6
- data/examples/sentiment.rb +8 -7
- data/examples/similar_terms.rb +7 -6
- data/examples/syntax_dependencies.rb +7 -6
- data/examples/tokens.rb +7 -6
- data/examples/topics.rb +7 -6
- data/examples/transliteration.rb +7 -6
- data/lib/address_parameter.rb +3 -4
- data/lib/address_similarity_parameters.rb +13 -6
- data/lib/bad_request_error.rb +3 -3
- data/lib/bad_request_format_error.rb +3 -3
- data/lib/document_parameters.rb +10 -12
- data/lib/name_deduplication_parameters.rb +5 -8
- data/lib/name_parameter.rb +22 -5
- data/lib/name_similarity_parameters.rb +51 -21
- data/lib/name_translation_parameters.rb +17 -10
- data/lib/record_similarity_parameters.rb +68 -0
- data/lib/request_builder.rb +94 -54
- data/lib/rosette_api.rb +90 -50
- data/lib/rosette_api_error.rb +5 -4
- metadata +28 -33
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'rosette_api'
|
|
5
|
+
|
|
6
|
+
api_key, url = ARGV
|
|
7
|
+
|
|
8
|
+
analytics_api = if url
|
|
9
|
+
RosetteAPI.new(api_key, url)
|
|
10
|
+
else
|
|
11
|
+
RosetteAPI.new(api_key)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
begin
|
|
15
|
+
# Field names
|
|
16
|
+
primary_name_field = 'primaryName'
|
|
17
|
+
dob_field = 'dob'
|
|
18
|
+
dob2_field = 'dob2'
|
|
19
|
+
addr_field = 'addr'
|
|
20
|
+
str_field = 'jobTitle'
|
|
21
|
+
number_field = 'age'
|
|
22
|
+
bool_field = 'isRetired'
|
|
23
|
+
|
|
24
|
+
dob_hyphen = '1993-04-16'
|
|
25
|
+
|
|
26
|
+
# Request fields definition
|
|
27
|
+
fields = {
|
|
28
|
+
primary_name_field => { type: 'rni_name', weight: 0.5 },
|
|
29
|
+
dob_field => { type: 'rni_date', weight: 0.2 },
|
|
30
|
+
dob2_field => { type: 'rni_date', weight: 0.1 },
|
|
31
|
+
addr_field => { type: 'rni_address', weight: 0.5 },
|
|
32
|
+
str_field => { type: 'rni_string', weight: 0.2 },
|
|
33
|
+
number_field => { type: 'rni_number', weight: 0.4 },
|
|
34
|
+
bool_field => { type: 'rni_boolean', weight: 0.05 }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# Request properties
|
|
38
|
+
properties = {
|
|
39
|
+
threshold: 0.7,
|
|
40
|
+
includeExplainInfo: true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
# Records payload. This shape mirrors the Java example's left/right lists.
|
|
44
|
+
#
|
|
45
|
+
# NOTE: The exact record field object schemas are API-specific. This example
|
|
46
|
+
# uses descriptive hashes that are intended to serialize cleanly to JSON.
|
|
47
|
+
records = {
|
|
48
|
+
left: [
|
|
49
|
+
{
|
|
50
|
+
primary_name_field => {
|
|
51
|
+
text: 'Ethan R',
|
|
52
|
+
entityType: 'PERSON',
|
|
53
|
+
language: 'eng',
|
|
54
|
+
languageOfOrigin: 'eng',
|
|
55
|
+
script: 'Latn'
|
|
56
|
+
},
|
|
57
|
+
dob_field => dob_hyphen,
|
|
58
|
+
dob2_field => {
|
|
59
|
+
date: '04161993',
|
|
60
|
+
format: 'MMddyyyy'
|
|
61
|
+
},
|
|
62
|
+
addr_field => '123 Roadlane Ave',
|
|
63
|
+
str_field => 'software engineer'
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
primary_name_field => {
|
|
67
|
+
text: 'Evan R'
|
|
68
|
+
},
|
|
69
|
+
dob_field => {
|
|
70
|
+
date: dob_hyphen
|
|
71
|
+
},
|
|
72
|
+
number_field => 47,
|
|
73
|
+
bool_field => false
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
right: [
|
|
77
|
+
{
|
|
78
|
+
primary_name_field => {
|
|
79
|
+
text: 'Seth R',
|
|
80
|
+
language: 'eng'
|
|
81
|
+
},
|
|
82
|
+
dob_field => {
|
|
83
|
+
date: dob_hyphen
|
|
84
|
+
},
|
|
85
|
+
str_field => 'manager',
|
|
86
|
+
bool_field => true
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
primary_name_field => 'Ivan R',
|
|
90
|
+
dob_field => {
|
|
91
|
+
date: dob_hyphen
|
|
92
|
+
},
|
|
93
|
+
dob2_field => {
|
|
94
|
+
date: '1993/04/16'
|
|
95
|
+
},
|
|
96
|
+
addr_field => {
|
|
97
|
+
houseNumber: '123',
|
|
98
|
+
road: 'Roadlane Ave',
|
|
99
|
+
cityDistrict: 'Alpha'
|
|
100
|
+
},
|
|
101
|
+
number_field => 72,
|
|
102
|
+
bool_field => true
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
params = RecordSimilarityParameters.new(fields, records, properties)
|
|
108
|
+
response = analytics_api.get_record_similarity(params)
|
|
109
|
+
puts JSON.pretty_generate(response)
|
|
110
|
+
rescue RosetteAPIError => e
|
|
111
|
+
printf('Rosette API Error (%<status_code>s): %<message>s',
|
|
112
|
+
status_code: e.status_code,
|
|
113
|
+
message: e.message)
|
|
114
|
+
end
|
data/examples/relationships.rb
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'json'
|
|
3
4
|
require 'rosette_api'
|
|
4
5
|
|
|
5
6
|
api_key, url = ARGV
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
analytics_api = if url
|
|
9
|
+
RosetteAPI.new(api_key, url)
|
|
10
|
+
else
|
|
11
|
+
RosetteAPI.new(api_key)
|
|
12
|
+
end
|
|
12
13
|
|
|
13
14
|
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.'
|
|
14
15
|
|
|
15
16
|
begin
|
|
16
17
|
params = DocumentParameters.new(content: relationships_text_data)
|
|
17
|
-
response =
|
|
18
|
+
response = analytics_api.get_relationships(params)
|
|
18
19
|
puts JSON.pretty_generate(response)
|
|
19
20
|
rescue RosetteAPIError => e
|
|
20
21
|
printf('Rosette API Error (%<status_code>s): %<message>s',
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'json'
|
|
3
4
|
require 'rosette_api'
|
|
4
5
|
|
|
5
6
|
api_key, url = ARGV
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
analytics_api = if url
|
|
9
|
+
RosetteAPI.new(api_key, url)
|
|
10
|
+
else
|
|
11
|
+
RosetteAPI.new(api_key)
|
|
12
|
+
end
|
|
12
13
|
|
|
13
14
|
semantic_vectors_data = 'Cambridge, Massachusetts'
|
|
14
15
|
begin
|
|
15
16
|
params = DocumentParameters.new(content: semantic_vectors_data)
|
|
16
|
-
response =
|
|
17
|
+
response = analytics_api.get_semantic_vectors(params)
|
|
17
18
|
puts JSON.pretty_generate(response)
|
|
18
19
|
rescue RosetteAPIError => e
|
|
19
20
|
printf('Rosette API Error (%<status_code>s): %<message>s',
|
data/examples/sentences.rb
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'json'
|
|
3
4
|
require 'rosette_api'
|
|
4
5
|
|
|
5
6
|
api_key, url = ARGV
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
analytics_api = if url
|
|
9
|
+
RosetteAPI.new(api_key, url)
|
|
10
|
+
else
|
|
11
|
+
RosetteAPI.new(api_key)
|
|
12
|
+
end
|
|
12
13
|
|
|
13
14
|
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.'
|
|
14
15
|
|
|
15
16
|
begin
|
|
16
17
|
params = DocumentParameters.new
|
|
17
18
|
params.content = sentences_data
|
|
18
|
-
response =
|
|
19
|
+
response = analytics_api.get_sentences(params)
|
|
19
20
|
puts JSON.pretty_generate(response)
|
|
20
21
|
rescue RosetteAPIError => e
|
|
21
22
|
printf('Rosette API Error (%<status_code>s): %<message>s',
|
data/examples/sentiment.rb
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require '
|
|
3
|
+
require 'json'
|
|
4
4
|
require 'rosette_api'
|
|
5
|
+
require 'tempfile'
|
|
5
6
|
|
|
6
7
|
api_key, url = ARGV
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
analytics_api = if url
|
|
10
|
+
RosetteAPI.new(api_key, url)
|
|
11
|
+
else
|
|
12
|
+
RosetteAPI.new(api_key)
|
|
13
|
+
end
|
|
13
14
|
|
|
14
15
|
file = Tempfile.new(%w[foo .html])
|
|
15
16
|
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>'
|
|
@@ -17,7 +18,7 @@ file.write(sentiment_file_data)
|
|
|
17
18
|
file.close
|
|
18
19
|
begin
|
|
19
20
|
params = DocumentParameters.new(file_path: file.path, language: 'eng')
|
|
20
|
-
response =
|
|
21
|
+
response = analytics_api.get_sentiment(params)
|
|
21
22
|
puts JSON.pretty_generate(response)
|
|
22
23
|
rescue RosetteAPIError => e
|
|
23
24
|
printf('Rosette API Error (%<status_code>s): %<message>s',
|
data/examples/similar_terms.rb
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'json'
|
|
3
4
|
require 'rosette_api'
|
|
4
5
|
|
|
5
6
|
api_key, url = ARGV
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
analytics_api = if url
|
|
9
|
+
RosetteAPI.new(api_key, url)
|
|
10
|
+
else
|
|
11
|
+
RosetteAPI.new(api_key)
|
|
12
|
+
end
|
|
12
13
|
|
|
13
14
|
similar_terms_data = 'spy'
|
|
14
15
|
begin
|
|
15
16
|
params = DocumentParameters.new(content: similar_terms_data)
|
|
16
17
|
params.rosette_options = { 'resultLanguages' => %w[spa deu jpn] }
|
|
17
|
-
response =
|
|
18
|
+
response = analytics_api.get_similar_terms(params)
|
|
18
19
|
puts JSON.pretty_generate(response)
|
|
19
20
|
rescue RosetteAPIError => e
|
|
20
21
|
printf('Rosette API Error (%<status_code>s): %<message>s',
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'json'
|
|
3
4
|
require 'rosette_api'
|
|
4
5
|
|
|
5
6
|
api_key, url = ARGV
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
analytics_api = if url
|
|
9
|
+
RosetteAPI.new(api_key, url)
|
|
10
|
+
else
|
|
11
|
+
RosetteAPI.new(api_key)
|
|
12
|
+
end
|
|
12
13
|
|
|
13
14
|
syntax_dependencies_data = 'Yoshinori Ohsumi, a Japanese cell biologist, was awarded the Nobel Prize in Physiology or Medicine on Monday.'
|
|
14
15
|
|
|
15
16
|
begin
|
|
16
17
|
params = DocumentParameters.new(content: syntax_dependencies_data)
|
|
17
|
-
response =
|
|
18
|
+
response = analytics_api.get_syntax_dependencies(params)
|
|
18
19
|
puts JSON.pretty_generate(response)
|
|
19
20
|
rescue RosetteAPIError => e
|
|
20
21
|
printf('Rosette API Error (%<status_code>s): %<message>s',
|
data/examples/tokens.rb
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'json'
|
|
3
4
|
require 'rosette_api'
|
|
4
5
|
|
|
5
6
|
api_key, url = ARGV
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
analytics_api = if url
|
|
9
|
+
RosetteAPI.new(api_key, url)
|
|
10
|
+
else
|
|
11
|
+
RosetteAPI.new(api_key)
|
|
12
|
+
end
|
|
12
13
|
|
|
13
14
|
tokens_data = '北京大学生物系主任办公室内部会议'
|
|
14
15
|
begin
|
|
15
16
|
params = DocumentParameters.new(content: tokens_data)
|
|
16
|
-
response =
|
|
17
|
+
response = analytics_api.get_tokens(params)
|
|
17
18
|
puts JSON.pretty_generate(response)
|
|
18
19
|
rescue RosetteAPIError => e
|
|
19
20
|
printf('Rosette API Error (%<status_code>s): %<message>s',
|
data/examples/topics.rb
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'json'
|
|
3
4
|
require 'rosette_api'
|
|
4
5
|
|
|
5
6
|
api_key, url = ARGV
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
analytics_api = if url
|
|
9
|
+
RosetteAPI.new(api_key, url)
|
|
10
|
+
else
|
|
11
|
+
RosetteAPI.new(api_key)
|
|
12
|
+
end
|
|
12
13
|
|
|
13
14
|
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
15
|
|
|
15
16
|
begin
|
|
16
17
|
params = DocumentParameters.new(content: topics_data)
|
|
17
|
-
response =
|
|
18
|
+
response = analytics_api.get_topics(params)
|
|
18
19
|
puts JSON.pretty_generate(response)
|
|
19
20
|
rescue RosetteAPIError => e
|
|
20
21
|
printf('Rosette API Error (%<status_code>s): %<message>s',
|
data/examples/transliteration.rb
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'json'
|
|
3
4
|
require 'rosette_api'
|
|
4
5
|
|
|
5
6
|
api_key, url = ARGV
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
analytics_api = if url
|
|
9
|
+
RosetteAPI.new(api_key, url)
|
|
10
|
+
else
|
|
11
|
+
RosetteAPI.new(api_key)
|
|
12
|
+
end
|
|
12
13
|
|
|
13
14
|
transliteration_content_data = 'ana r2ye7 el gam3a el sa3a 3 el 3asr'
|
|
14
15
|
|
|
15
16
|
begin
|
|
16
17
|
params = DocumentParameters.new
|
|
17
18
|
params.content = transliteration_content_data
|
|
18
|
-
response =
|
|
19
|
+
response = analytics_api.get_transliteration(params)
|
|
19
20
|
puts JSON.pretty_generate(response)
|
|
20
21
|
rescue RosetteAPIError => e
|
|
21
22
|
printf('Rosette API Error (%<status_code>s): %<message>s',
|
data/lib/address_parameter.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# This class represents an address in
|
|
3
|
+
# This class represents an address in Analytics API.
|
|
4
4
|
class AddressParameter
|
|
5
5
|
# house (optional)
|
|
6
6
|
attr_accessor :house
|
|
@@ -39,7 +39,7 @@ class AddressParameter
|
|
|
39
39
|
# po_box (optional)
|
|
40
40
|
attr_accessor :po_box
|
|
41
41
|
|
|
42
|
-
def initialize(options = {})
|
|
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
|
-
.
|
|
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.
|
|
@@ -4,16 +4,20 @@ require_relative 'bad_request_error'
|
|
|
4
4
|
require_relative 'address_parameter'
|
|
5
5
|
|
|
6
6
|
# This class encapsulates parameters that are needed for address-similarity in
|
|
7
|
-
#
|
|
7
|
+
# Analytics API.
|
|
8
8
|
class AddressSimilarityParameters
|
|
9
9
|
# Address to be compared to address2
|
|
10
10
|
attr_accessor :address1
|
|
11
11
|
# Address to be compared to address1
|
|
12
12
|
attr_accessor :address2
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
# Parameters map sent to the API (optional, should be a hash)
|
|
15
|
+
attr_accessor :parameters
|
|
16
|
+
|
|
17
|
+
def initialize(address1, address2, address_parameters = nil) # :notnew:
|
|
15
18
|
@address1 = address1
|
|
16
19
|
@address2 = address2
|
|
20
|
+
@parameters = address_parameters
|
|
17
21
|
end
|
|
18
22
|
|
|
19
23
|
# Validates the parameters by checking if address1 and address2 are instances
|
|
@@ -24,6 +28,9 @@ class AddressSimilarityParameters
|
|
|
24
28
|
|
|
25
29
|
a2_msg = 'address2 option can only be an instance of an AddressParameter or a String'
|
|
26
30
|
raise BadRequestError.new(a2_msg) if [String, AddressParameter].none? { |clazz| @address2.is_a? clazz }
|
|
31
|
+
|
|
32
|
+
opt_msg = 'parameters can only be an instance of a Hash'
|
|
33
|
+
raise BadRequestError.new(opt_msg) if @parameters && !(@parameters.is_a? Hash)
|
|
27
34
|
end
|
|
28
35
|
|
|
29
36
|
# Converts this class to Hash with its keys in lower CamelCase.
|
|
@@ -32,9 +39,8 @@ class AddressSimilarityParameters
|
|
|
32
39
|
def load_params
|
|
33
40
|
validate_params
|
|
34
41
|
to_hash
|
|
35
|
-
.
|
|
36
|
-
.
|
|
37
|
-
.to_h
|
|
42
|
+
.compact
|
|
43
|
+
.transform_keys { |key| key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase) }
|
|
38
44
|
end
|
|
39
45
|
|
|
40
46
|
# Converts this class to Hash.
|
|
@@ -43,7 +49,8 @@ class AddressSimilarityParameters
|
|
|
43
49
|
def to_hash
|
|
44
50
|
{
|
|
45
51
|
address1: @address1.is_a?(AddressParameter) ? @address1.load_param : @address1,
|
|
46
|
-
address2: @address2.is_a?(AddressParameter) ? @address2.load_param : @address2
|
|
52
|
+
address2: @address2.is_a?(AddressParameter) ? @address2.load_param : @address2,
|
|
53
|
+
parameters: @parameters
|
|
47
54
|
}
|
|
48
55
|
end
|
|
49
56
|
end
|
data/lib/bad_request_error.rb
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative 'rosette_api_error'
|
|
4
4
|
|
|
5
|
-
# This class represents
|
|
5
|
+
# This class represents Analytics API errors with badRequest status_code.
|
|
6
6
|
class BadRequestError < RosetteAPIError
|
|
7
|
-
def initialize(message)
|
|
8
|
-
super
|
|
7
|
+
def initialize(message) # :notnew:
|
|
8
|
+
super('badRequest', message)
|
|
9
9
|
end
|
|
10
10
|
end
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative 'rosette_api_error'
|
|
4
4
|
|
|
5
|
-
# This class represents
|
|
5
|
+
# This class represents Analytics API errors with badRequestFormat status_code.
|
|
6
6
|
class BadRequestFormatError < RosetteAPIError
|
|
7
|
-
def initialize(message)
|
|
8
|
-
super
|
|
7
|
+
def initialize(message) # :notnew:
|
|
8
|
+
super('badRequestFormat', message)
|
|
9
9
|
end
|
|
10
10
|
end
|
data/lib/document_parameters.rb
CHANGED
|
@@ -17,12 +17,12 @@ class DocumentParameters
|
|
|
17
17
|
attr_accessor :genre
|
|
18
18
|
# ISO 639-3 language code of the provided content (optional)
|
|
19
19
|
attr_accessor :language
|
|
20
|
-
#
|
|
20
|
+
# API options (optional, should be a hash)
|
|
21
21
|
attr_accessor :rosette_options
|
|
22
|
-
# custom
|
|
22
|
+
# custom API headers
|
|
23
23
|
attr_accessor :custom_headers
|
|
24
24
|
|
|
25
|
-
def initialize(options = {})
|
|
25
|
+
def initialize(options = {}) # :notnew:
|
|
26
26
|
options = {
|
|
27
27
|
content: nil,
|
|
28
28
|
content_uri: nil,
|
|
@@ -45,18 +45,18 @@ 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
|
-
|
|
49
|
-
|
|
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
|
-
|
|
52
|
-
|
|
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)
|
|
56
56
|
elsif [@content, @content_uri, @file_path].all?(&:nil?)
|
|
57
57
|
raise BadRequestFormatError.new(no_content_msg)
|
|
58
|
-
elsif @rosette_options
|
|
59
|
-
raise BadRequestError.new(opt_msg)
|
|
58
|
+
elsif @rosette_options && !@rosette_options.is_a?(Hash)
|
|
59
|
+
raise BadRequestError.new(opt_msg)
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
|
|
@@ -67,8 +67,7 @@ class DocumentParameters
|
|
|
67
67
|
validate_params
|
|
68
68
|
to_hash
|
|
69
69
|
.select { |_key, value| value }
|
|
70
|
-
.
|
|
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.
|
|
@@ -79,7 +78,6 @@ class DocumentParameters
|
|
|
79
78
|
content: @content,
|
|
80
79
|
content_uri: @content_uri,
|
|
81
80
|
file_path: @file_path,
|
|
82
|
-
genre: @genre,
|
|
83
81
|
language: @language,
|
|
84
82
|
options: @rosette_options,
|
|
85
83
|
custom_headers: @custom_headers
|
|
@@ -4,16 +4,16 @@ require_relative 'bad_request_error'
|
|
|
4
4
|
require_relative 'name_parameter'
|
|
5
5
|
|
|
6
6
|
# This class encapsulates parameters that are needed for name-deduplication in
|
|
7
|
-
#
|
|
7
|
+
# Analytics API.
|
|
8
8
|
class NameDeduplicationParameters
|
|
9
|
-
#
|
|
9
|
+
# API options (optional, should be a hash)
|
|
10
10
|
attr_accessor :rosette_options
|
|
11
11
|
# List of Name objects to be de-duplicated
|
|
12
12
|
attr_accessor :names
|
|
13
13
|
# Threshold for determining cluster size
|
|
14
14
|
attr_accessor :threshold
|
|
15
15
|
|
|
16
|
-
def initialize(names, threshold, options = {})
|
|
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
|
-
.
|
|
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.
|
data/lib/name_parameter.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# This class represents an entity name in
|
|
3
|
+
# This class represents an entity name in Analytics API.
|
|
4
4
|
class NameParameter
|
|
5
5
|
# Name's entity type (PERSON, LOCATION, ORGANIZATION) (optional)
|
|
6
6
|
attr_accessor :entity_type
|
|
@@ -8,19 +8,36 @@ class NameParameter
|
|
|
8
8
|
attr_accessor :language
|
|
9
9
|
# ISO 15924 code of the name's script (optional)
|
|
10
10
|
attr_accessor :script
|
|
11
|
+
# Name's gender (male, female, nonbinary) (optional)
|
|
12
|
+
attr_accessor :gender
|
|
11
13
|
# Name to be analyzed
|
|
12
14
|
attr_accessor :text
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
VALID_GENDERS = %w[male female nonbinary].freeze
|
|
17
|
+
|
|
18
|
+
def initialize(text, options = {}) # :notnew:
|
|
15
19
|
options = {
|
|
16
20
|
entity_type: nil,
|
|
17
21
|
language: nil,
|
|
18
|
-
script: nil
|
|
22
|
+
script: nil,
|
|
23
|
+
gender: nil
|
|
19
24
|
}.update options
|
|
20
25
|
@text = text
|
|
21
26
|
@entity_type = options[:entity_type]
|
|
22
27
|
@language = options[:language]
|
|
23
28
|
@script = options[:script]
|
|
29
|
+
@gender = options[:gender]
|
|
30
|
+
|
|
31
|
+
validate_gender
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def validate_gender
|
|
35
|
+
return if @gender.nil?
|
|
36
|
+
|
|
37
|
+
normalized = @gender.to_s.downcase
|
|
38
|
+
return if VALID_GENDERS.include?(normalized)
|
|
39
|
+
|
|
40
|
+
raise ArgumentError.new("gender must be one of: #{VALID_GENDERS.join(', ')}")
|
|
24
41
|
end
|
|
25
42
|
|
|
26
43
|
# Converts this class to Hash with its keys in lower CamelCase.
|
|
@@ -29,8 +46,7 @@ class NameParameter
|
|
|
29
46
|
def load_param
|
|
30
47
|
to_hash
|
|
31
48
|
.select { |_key, value| value }
|
|
32
|
-
.
|
|
33
|
-
.to_h
|
|
49
|
+
.transform_keys { |key| key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase) }
|
|
34
50
|
end
|
|
35
51
|
|
|
36
52
|
# Converts this class to Hash.
|
|
@@ -41,6 +57,7 @@ class NameParameter
|
|
|
41
57
|
entity_type: @entity_type,
|
|
42
58
|
language: @language,
|
|
43
59
|
script: @script,
|
|
60
|
+
gender: @gender,
|
|
44
61
|
text: @text
|
|
45
62
|
}
|
|
46
63
|
end
|