rosette_api 1.8.0 → 1.14.4
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 +5 -5
- data/LICENSE +13 -0
- data/README.md +38 -0
- data/examples/README.md +36 -0
- data/examples/address_similarity.rb +29 -0
- data/examples/categories.rb +22 -0
- data/examples/entities.rb +23 -0
- data/examples/info.rb +20 -0
- data/examples/language.rb +23 -0
- data/examples/language_multilingual.rb +25 -0
- data/examples/morphology_complete.rb +22 -0
- data/examples/morphology_compound-components.rb +24 -0
- data/examples/morphology_han-readings.rb +22 -0
- data/examples/morphology_lemmas.rb +22 -0
- data/examples/morphology_parts-of-speech.rb +22 -0
- data/examples/name_deduplication.rb +25 -0
- data/examples/name_similarity.rb +28 -0
- data/examples/name_translation.rb +26 -0
- data/examples/ping.rb +20 -0
- data/examples/relationships.rb +23 -0
- data/examples/semantic_vectors.rb +22 -0
- data/examples/sentences.rb +24 -0
- data/examples/sentiment.rb +26 -0
- data/examples/similar_terms.rb +23 -0
- data/examples/syntax_dependencies.rb +23 -0
- data/examples/tokens.rb +22 -0
- data/examples/topics.rb +23 -0
- data/examples/transliteration.rb +24 -0
- data/lib/address_parameter.rb +117 -0
- data/lib/address_similarity_parameters.rb +49 -0
- data/lib/bad_request_error.rb +2 -0
- data/lib/bad_request_format_error.rb +2 -0
- data/lib/document_parameters.rb +20 -11
- data/lib/name_deduplication_parameters.rb +15 -7
- data/lib/name_parameter.rb +6 -3
- data/lib/name_similarity_parameters.rb +14 -6
- data/lib/name_translation_parameters.rb +12 -6
- data/lib/request_builder.rb +49 -18
- data/lib/rosette_api.rb +193 -66
- data/lib/rosette_api_error.rb +3 -1
- metadata +43 -14
- data/.rubocop.yml +0 -312
- data/tests/tests_spec.rb +0 -583
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'bad_request_error'
|
2
4
|
require_relative 'name_parameter'
|
3
5
|
|
@@ -23,13 +25,18 @@ class NameDeduplicationParameters
|
|
23
25
|
# Validates the parameters by checking if name1 and name2 are instances of
|
24
26
|
# a String or NameParameter.
|
25
27
|
def validate_params
|
26
|
-
|
28
|
+
param_msg = 'names must be an array of name_parameter'
|
29
|
+
raise BadRequestError.new(param_msg) unless @names.instance_of? Array
|
30
|
+
|
31
|
+
float_msg = 'threshold must be a float'
|
32
|
+
thresh_msg = 'threshold must be in the range of 0 to 1'
|
27
33
|
if @threshold
|
28
|
-
raise BadRequestError.new(
|
29
|
-
raise BadRequestError.new(
|
34
|
+
raise BadRequestError.new(float_msg) unless @threshold.is_a?(Float)
|
35
|
+
raise BadRequestError.new(thresh_msg) if @threshold.negative? || @threshold > 1
|
30
36
|
end
|
37
|
+
opt_msg = 'rosette_options can only be an instance of a Hash'
|
31
38
|
if @rosette_options
|
32
|
-
raise BadRequestError.new(
|
39
|
+
raise BadRequestError.new(opt_msg) unless @rosette_options.is_a? Hash
|
33
40
|
end
|
34
41
|
end
|
35
42
|
|
@@ -38,9 +45,10 @@ class NameDeduplicationParameters
|
|
38
45
|
# Returns the new Hash.
|
39
46
|
def load_params
|
40
47
|
validate_params
|
41
|
-
to_hash
|
42
|
-
|
43
|
-
|
48
|
+
to_hash
|
49
|
+
.select { |_key, value| value }
|
50
|
+
.map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
|
51
|
+
.to_h
|
44
52
|
end
|
45
53
|
|
46
54
|
# Converts this class to Hash.
|
data/lib/name_parameter.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This class represents an entity name in Rosette API.
|
2
4
|
class NameParameter
|
3
5
|
# Name's entity type (PERSON, LOCATION, ORGANIZATION) (optional)
|
@@ -25,9 +27,10 @@ class NameParameter
|
|
25
27
|
#
|
26
28
|
# Returns the new Hash.
|
27
29
|
def load_param
|
28
|
-
to_hash
|
29
|
-
|
30
|
-
|
30
|
+
to_hash
|
31
|
+
.select { |_key, value| value }
|
32
|
+
.map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
|
33
|
+
.to_h
|
31
34
|
end
|
32
35
|
|
33
36
|
# Converts this class to Hash.
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'bad_request_error'
|
2
4
|
require_relative 'name_parameter'
|
3
5
|
|
@@ -27,10 +29,15 @@ class NameSimilarityParameters
|
|
27
29
|
# Validates the parameters by checking if name1 and name2 are instances of
|
28
30
|
# a String or NameParameter.
|
29
31
|
def validate_params
|
30
|
-
|
31
|
-
raise BadRequestError.new(
|
32
|
+
n1_msg = 'name1 option can only be an instance of a String or NameParameter'
|
33
|
+
raise BadRequestError.new(n1_msg) if [String, NameParameter].none? { |clazz| @name1.is_a? clazz }
|
34
|
+
|
35
|
+
n2_msg = 'name2 option can only be an instance of a String or NameParameter'
|
36
|
+
raise BadRequestError.new(n2_msg) if [String, NameParameter].none? { |clazz| @name2.is_a? clazz }
|
37
|
+
|
38
|
+
opt_msg = 'rosette_options can only be an instance of a Hash'
|
32
39
|
if @rosette_options
|
33
|
-
raise BadRequestError.new(
|
40
|
+
raise BadRequestError.new(opt_msg) unless @rosette_options.is_a? Hash
|
34
41
|
end
|
35
42
|
end
|
36
43
|
|
@@ -39,9 +46,10 @@ class NameSimilarityParameters
|
|
39
46
|
# Returns the new Hash.
|
40
47
|
def load_params
|
41
48
|
validate_params
|
42
|
-
to_hash
|
43
|
-
|
44
|
-
|
49
|
+
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
|
45
53
|
end
|
46
54
|
|
47
55
|
# Converts this class to Hash.
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'rosette_api_error'
|
2
4
|
|
3
5
|
# This class encapsulates parameters that are needed for name-translation in
|
@@ -11,7 +13,8 @@ class NameTranslationParameters
|
|
11
13
|
attr_accessor :name
|
12
14
|
# Rosette API options (optional, should be a hash)
|
13
15
|
attr_accessor :rosette_options
|
14
|
-
# ISO 693-3 code of the name's native language the name originates in
|
16
|
+
# ISO 693-3 code of the name's native language the name originates in
|
17
|
+
# (optional)
|
15
18
|
attr_accessor :source_language_of_origin
|
16
19
|
# ISO 693-3 code of the name's language of use (optional)
|
17
20
|
attr_accessor :source_language_of_use
|
@@ -47,10 +50,12 @@ class NameTranslationParameters
|
|
47
50
|
@target_script = options[:target_script]
|
48
51
|
end
|
49
52
|
|
50
|
-
# Validates the parameters by checking if rosette_options is an instance
|
53
|
+
# Validates the parameters by checking if rosette_options is an instance
|
54
|
+
# of a Hash.
|
51
55
|
def validate_params
|
56
|
+
msg = 'rosette_options can only be an instance of a Hash'
|
52
57
|
if @rosette_options
|
53
|
-
raise BadRequestError.new(
|
58
|
+
raise BadRequestError.new(msg) unless @rosette_options.is_a? Hash
|
54
59
|
end
|
55
60
|
end
|
56
61
|
|
@@ -59,9 +64,10 @@ class NameTranslationParameters
|
|
59
64
|
# Returns the new Hash.
|
60
65
|
def load_params
|
61
66
|
validate_params
|
62
|
-
to_hash
|
63
|
-
|
64
|
-
|
67
|
+
to_hash
|
68
|
+
.select { |_key, value| value }
|
69
|
+
.map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] }
|
70
|
+
.to_h
|
65
71
|
end
|
66
72
|
|
67
73
|
# Converts this class to Hash.
|
data/lib/request_builder.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'net/http'
|
3
4
|
require 'net/https'
|
4
5
|
require 'json'
|
@@ -17,15 +18,20 @@ class RequestBuilder
|
|
17
18
|
attr_accessor :user_key
|
18
19
|
# Rosette API binding version
|
19
20
|
attr_accessor :binding_version
|
21
|
+
# User-Agent string
|
22
|
+
attr_reader :user_agent
|
20
23
|
|
21
|
-
def initialize(user_key, alternate_url, http_client,
|
24
|
+
def initialize(user_key, alternate_url, http_client, binding_version,
|
25
|
+
params = {}, url_parameters = nil)
|
22
26
|
@user_key = user_key
|
23
27
|
@alternate_url = alternate_url
|
24
28
|
@http_client = http_client
|
25
|
-
@params = params
|
26
29
|
@binding_version = binding_version
|
30
|
+
@params = params
|
31
|
+
@user_agent = 'Ruby/' + binding_version + '/' + RUBY_VERSION
|
27
32
|
|
28
33
|
return unless url_parameters
|
34
|
+
|
29
35
|
@alternate_url = @alternate_url + '?' + URI.encode_www_form(url_parameters)
|
30
36
|
end
|
31
37
|
|
@@ -40,19 +46,27 @@ class RequestBuilder
|
|
40
46
|
begin
|
41
47
|
uri = URI.parse @alternate_url
|
42
48
|
request = Net::HTTP::Post.new uri.request_uri
|
43
|
-
rescue
|
44
|
-
|
49
|
+
rescue StandardError
|
50
|
+
# Not ideal. Consider switching to a different library.
|
51
|
+
# https://stackoverflow.com/a/11802674
|
52
|
+
raise RosetteAPIError.new(
|
53
|
+
'connectionError',
|
54
|
+
'Failed to establish connection with Rosette server.'
|
55
|
+
)
|
45
56
|
end
|
46
57
|
|
47
58
|
custom_headers = params['customHeaders']
|
48
59
|
|
49
60
|
if custom_headers
|
50
61
|
keys_array = custom_headers.keys
|
51
|
-
|
62
|
+
keys_array.each do |key|
|
52
63
|
if key.to_s =~ /^X-RosetteAPI-/
|
53
64
|
request[key] = custom_headers[key]
|
54
65
|
else
|
55
|
-
raise RosetteAPIError.new
|
66
|
+
raise RosetteAPIError.new(
|
67
|
+
'invalidHeader',
|
68
|
+
'Custom header must begin with "X-RosetteAPI-"'
|
69
|
+
)
|
56
70
|
end
|
57
71
|
end
|
58
72
|
params.delete 'customHeaders'
|
@@ -61,6 +75,7 @@ class RequestBuilder
|
|
61
75
|
request['X-RosetteAPI-Key'] = @user_key
|
62
76
|
request['Content-Type'] = 'application/json'
|
63
77
|
request['Accept'] = 'application/json'
|
78
|
+
request['User-Agent'] = @user_agent
|
64
79
|
request['X-RosetteAPI-Binding'] = 'ruby'
|
65
80
|
request['X-RosetteAPI-Binding-Version'] = @binding_version
|
66
81
|
request.body = params.to_json
|
@@ -79,8 +94,8 @@ class RequestBuilder
|
|
79
94
|
begin
|
80
95
|
file = File.open params['filePath'], 'r'
|
81
96
|
text = file.read
|
82
|
-
rescue =>
|
83
|
-
raise
|
97
|
+
rescue StandardError => e
|
98
|
+
raise RosetteAPIError.new('readMultipartError', e)
|
84
99
|
end
|
85
100
|
|
86
101
|
boundary = SecureRandom.hex
|
@@ -90,7 +105,8 @@ class RequestBuilder
|
|
90
105
|
|
91
106
|
# Add the content data
|
92
107
|
post_body << "--#{boundary}\r\n"
|
93
|
-
post_body <<
|
108
|
+
post_body << 'Content-Disposition: form-data; name="content"; ' \
|
109
|
+
"filename=\"#{File.basename(file)}\"\r\n"
|
94
110
|
post_body << "Content-Type: text/plain\r\n\r\n"
|
95
111
|
post_body << text
|
96
112
|
|
@@ -105,24 +121,34 @@ class RequestBuilder
|
|
105
121
|
begin
|
106
122
|
uri = URI.parse @alternate_url
|
107
123
|
request = Net::HTTP::Post.new uri.request_uri
|
108
|
-
rescue
|
109
|
-
|
124
|
+
rescue StandardError
|
125
|
+
# Not ideal. Consider switching to a different library.
|
126
|
+
# https://stackoverflow.com/a/11802674
|
127
|
+
raise RosetteAPIError.new(
|
128
|
+
'connectionError',
|
129
|
+
'Failed to establish connection with Rosette API server.'
|
130
|
+
)
|
110
131
|
end
|
111
132
|
|
112
133
|
# add any custom headers from the user
|
113
134
|
unless params['customHeaders'].nil?
|
114
135
|
keys_array = params['customHeaders'].keys
|
115
|
-
|
136
|
+
keys_array.each do |k|
|
116
137
|
if k.to_s =~ /^X-RosetteAPI-/
|
117
138
|
request.add_field k, params['customHeaders'][k]
|
118
139
|
else
|
119
|
-
raise RosetteAPIError.new
|
140
|
+
raise RosetteAPIError.new(
|
141
|
+
'invalidHeader',
|
142
|
+
'Custom header must begin with "X-RosetteAPI-"'
|
143
|
+
)
|
120
144
|
end
|
121
145
|
end
|
122
146
|
params.delete 'customHeaders'
|
123
147
|
end
|
124
148
|
|
125
|
-
request.add_field 'Content-Type',
|
149
|
+
request.add_field 'Content-Type',
|
150
|
+
"multipart/form-data; boundary=#{boundary}"
|
151
|
+
request.add_field 'User-Agent', @user_agent
|
126
152
|
request.add_field 'X-RosetteAPI-Key', @user_key
|
127
153
|
request.add_field 'X-RosetteAPI-Binding', 'ruby'
|
128
154
|
request.add_field 'X-RosetteAPI-Binding-Version', @binding_version
|
@@ -137,12 +163,17 @@ class RequestBuilder
|
|
137
163
|
def send_get_request
|
138
164
|
begin
|
139
165
|
uri = URI.parse @alternate_url
|
140
|
-
|
141
166
|
request = Net::HTTP::Get.new uri.request_uri
|
142
|
-
rescue
|
143
|
-
|
167
|
+
rescue StandardError
|
168
|
+
# Not ideal. Consider switching to a different library.
|
169
|
+
# https://stackoverflow.com/a/11802674
|
170
|
+
raise RosetteAPIError.new(
|
171
|
+
'connectionError',
|
172
|
+
'Failed to establish connection with Rosette API server.'
|
173
|
+
)
|
144
174
|
end
|
145
175
|
request['X-RosetteAPI-Key'] = @user_key
|
176
|
+
request['User-Agent'] = @user_agent
|
146
177
|
|
147
178
|
get_response @http_client, request
|
148
179
|
end
|
data/lib/rosette_api.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'request_builder'
|
2
4
|
require_relative 'document_parameters'
|
3
5
|
require_relative 'name_deduplication_parameters'
|
4
6
|
require_relative 'name_translation_parameters'
|
5
7
|
require_relative 'name_similarity_parameters'
|
8
|
+
require_relative 'address_similarity_parameters'
|
6
9
|
require_relative 'rosette_api_error'
|
7
10
|
require_relative 'bad_request_error'
|
8
11
|
require_relative 'bad_request_format_error'
|
@@ -10,42 +13,47 @@ require_relative 'bad_request_format_error'
|
|
10
13
|
# This class allows you to access all Rosette API endpoints.
|
11
14
|
class RosetteAPI
|
12
15
|
# Version of Ruby binding
|
13
|
-
BINDING_VERSION = '1.
|
16
|
+
BINDING_VERSION = '1.14.4'
|
14
17
|
# Rosette API language endpoint
|
15
|
-
LANGUAGE_ENDPOINT = '/language'
|
18
|
+
LANGUAGE_ENDPOINT = '/language'
|
16
19
|
# Rosette API morphology endpoint
|
17
|
-
MORPHOLOGY_ENDPOINT = '/morphology'
|
20
|
+
MORPHOLOGY_ENDPOINT = '/morphology'
|
18
21
|
# Rosette API entities endpoint
|
19
|
-
ENTITIES_ENDPOINT = '/entities'
|
22
|
+
ENTITIES_ENDPOINT = '/entities'
|
20
23
|
# Rosette API categories endpoint
|
21
|
-
CATEGORIES_ENDPOINT = '/categories'
|
24
|
+
CATEGORIES_ENDPOINT = '/categories'
|
22
25
|
# Rosette API relationships endpoint
|
23
|
-
RELATIONSHIPS_ENDPOINT = '/relationships'
|
26
|
+
RELATIONSHIPS_ENDPOINT = '/relationships'
|
24
27
|
# Rosette API sentiment endpoint
|
25
|
-
SENTIMENT_ENDPOINT = '/sentiment'
|
28
|
+
SENTIMENT_ENDPOINT = '/sentiment'
|
26
29
|
# Name Deduplication endpoint
|
27
|
-
NAME_DEDUPLICATION_ENDPOINT = '/name-deduplication'
|
30
|
+
NAME_DEDUPLICATION_ENDPOINT = '/name-deduplication'
|
28
31
|
# Rosette API name-translation endpoint
|
29
|
-
NAME_TRANSLATION_ENDPOINT = '/name-translation'
|
32
|
+
NAME_TRANSLATION_ENDPOINT = '/name-translation'
|
30
33
|
# Rosette API name-similarity endpoint
|
31
|
-
NAME_SIMILARITY_ENDPOINT = '/name-similarity'
|
34
|
+
NAME_SIMILARITY_ENDPOINT = '/name-similarity'
|
35
|
+
# Rosette API address-similarity endpoint
|
36
|
+
ADDRESS_SIMILARITY_ENDPOINT = '/address-similarity'
|
32
37
|
# Rosette API tokens endpoint
|
33
|
-
TOKENS_ENDPOINT = '/tokens'
|
38
|
+
TOKENS_ENDPOINT = '/tokens'
|
34
39
|
# Rosette API sentences endpoint
|
35
|
-
SENTENCES_ENDPOINT = '/sentences'
|
40
|
+
SENTENCES_ENDPOINT = '/sentences'
|
36
41
|
# Rosette API info endpoint
|
37
|
-
INFO = '/info'
|
42
|
+
INFO = '/info'
|
38
43
|
# Rosette API ping endpoint
|
39
|
-
PING = '/ping'
|
40
|
-
# Text Embedding endpoint
|
41
|
-
TEXT_EMBEDDING = '/text-embedding'
|
44
|
+
PING = '/ping'
|
45
|
+
# Text Embedding endpoint (deprecated)
|
46
|
+
TEXT_EMBEDDING = '/text-embedding'
|
47
|
+
# Semantic Vectors endpoint (replaces /text-embedding)
|
48
|
+
SEMANTIC_VECTORS = '/semantics/vector'
|
49
|
+
# Similar Terms endpoint
|
50
|
+
SIMILAR_TERMS_ENDPOINT = '/semantics/similar'
|
42
51
|
# Syntactic Dependencies endpoint
|
43
|
-
SYNTACTIC_DEPENDENCIES_ENDPOINT = '/syntax/dependencies'
|
52
|
+
SYNTACTIC_DEPENDENCIES_ENDPOINT = '/syntax/dependencies'
|
44
53
|
# Transliteration endpoint
|
45
|
-
TRANSLITERATION_ENDPOINT = '/transliteration'
|
54
|
+
TRANSLITERATION_ENDPOINT = '/transliteration'
|
46
55
|
# Topics endpoint
|
47
|
-
TOPICS_ENDPOINT = '/topics'
|
48
|
-
|
56
|
+
TOPICS_ENDPOINT = '/topics'
|
49
57
|
|
50
58
|
# Rosette API key
|
51
59
|
attr_accessor :user_key
|
@@ -74,7 +82,8 @@ class RosetteAPI
|
|
74
82
|
#
|
75
83
|
# ==== Attributes
|
76
84
|
#
|
77
|
-
# * +params+ - DocumentParameters helps to build the request body in
|
85
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
86
|
+
# RequestBuilder.
|
78
87
|
#
|
79
88
|
# Returns list of candidate languages in order of descending confidence.
|
80
89
|
def get_language(params)
|
@@ -82,7 +91,8 @@ class RosetteAPI
|
|
82
91
|
|
83
92
|
params = params.load_params
|
84
93
|
|
85
|
-
RequestBuilder.new(@user_key, @alternate_url + LANGUAGE_ENDPOINT,
|
94
|
+
RequestBuilder.new(@user_key, @alternate_url + LANGUAGE_ENDPOINT,
|
95
|
+
@http_client, BINDING_VERSION, params, @url_parameters)
|
86
96
|
.send_post_request
|
87
97
|
end
|
88
98
|
|
@@ -91,7 +101,8 @@ class RosetteAPI
|
|
91
101
|
#
|
92
102
|
# ==== Attributes
|
93
103
|
#
|
94
|
-
# * +params+ - DocumentParameters helps to build the request body in
|
104
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
105
|
+
# RequestBuilder.
|
95
106
|
#
|
96
107
|
# Returns the lemmas, compound components, Han-readings, and parts-of-speech
|
97
108
|
# tags of the input for supported languages.
|
@@ -100,7 +111,9 @@ class RosetteAPI
|
|
100
111
|
|
101
112
|
params = params.load_params
|
102
113
|
|
103
|
-
|
114
|
+
endpoint = MORPHOLOGY_ENDPOINT + '/complete'
|
115
|
+
RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client,
|
116
|
+
BINDING_VERSION, params, @url_parameters)
|
104
117
|
.send_post_request
|
105
118
|
end
|
106
119
|
|
@@ -108,7 +121,8 @@ class RosetteAPI
|
|
108
121
|
#
|
109
122
|
# ==== Attributes
|
110
123
|
#
|
111
|
-
# * +params+ - DocumentParameters helps to build the request body in
|
124
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
125
|
+
# RequestBuilder.
|
112
126
|
#
|
113
127
|
# Returns list of components for each compound word of the input for supported
|
114
128
|
# languages.
|
@@ -117,7 +131,9 @@ class RosetteAPI
|
|
117
131
|
|
118
132
|
params = params.load_params
|
119
133
|
|
120
|
-
|
134
|
+
endpoint = MORPHOLOGY_ENDPOINT + '/compound-components'
|
135
|
+
RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client,
|
136
|
+
BINDING_VERSION, params, @url_parameters)
|
121
137
|
.send_post_request
|
122
138
|
end
|
123
139
|
|
@@ -125,7 +141,8 @@ class RosetteAPI
|
|
125
141
|
#
|
126
142
|
# ==== Attributes
|
127
143
|
#
|
128
|
-
# * +params+ - DocumentParameters helps to build the request body in
|
144
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
145
|
+
# RequestBuilder.
|
129
146
|
#
|
130
147
|
# Returns list of Han-readings which provide pronunciation information for
|
131
148
|
# Han script, in both Chinese and Japanese input text.
|
@@ -134,7 +151,9 @@ class RosetteAPI
|
|
134
151
|
|
135
152
|
params = params.load_params
|
136
153
|
|
137
|
-
|
154
|
+
endpoint = MORPHOLOGY_ENDPOINT + '/han-readings'
|
155
|
+
RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client,
|
156
|
+
BINDING_VERSION, params, @url_parameters)
|
138
157
|
.send_post_request
|
139
158
|
end
|
140
159
|
|
@@ -142,7 +161,8 @@ class RosetteAPI
|
|
142
161
|
#
|
143
162
|
# ==== Attributes
|
144
163
|
#
|
145
|
-
# * +params+ - DocumentParameters helps to build the request body in
|
164
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
165
|
+
# RequestBuilder.
|
146
166
|
#
|
147
167
|
# Returns list of lemmas for each token of the input for supported languages.
|
148
168
|
def get_lemmas(params)
|
@@ -150,7 +170,9 @@ class RosetteAPI
|
|
150
170
|
|
151
171
|
params = params.load_params
|
152
172
|
|
153
|
-
|
173
|
+
endpoint = MORPHOLOGY_ENDPOINT + '/lemmas'
|
174
|
+
RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client,
|
175
|
+
BINDING_VERSION, params, @url_parameters)
|
154
176
|
.send_post_request
|
155
177
|
end
|
156
178
|
|
@@ -158,7 +180,8 @@ class RosetteAPI
|
|
158
180
|
#
|
159
181
|
# ==== Attributes
|
160
182
|
#
|
161
|
-
# * +params+ - DocumentParameters helps to build the request body in
|
183
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
184
|
+
# RequestBuilder.
|
162
185
|
#
|
163
186
|
# Returns list of part-of-speech (POS) tags for each of the words of the
|
164
187
|
# input, depending on the context of how it is used.
|
@@ -167,7 +190,9 @@ class RosetteAPI
|
|
167
190
|
|
168
191
|
params = params.load_params
|
169
192
|
|
170
|
-
|
193
|
+
endpoint = MORPHOLOGY_ENDPOINT + '/parts-of-speech'
|
194
|
+
RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client,
|
195
|
+
BINDING_VERSION, params, @url_parameters)
|
171
196
|
.send_post_request
|
172
197
|
end
|
173
198
|
|
@@ -175,7 +200,8 @@ class RosetteAPI
|
|
175
200
|
#
|
176
201
|
# ==== Attributes
|
177
202
|
#
|
178
|
-
# * +params+ - DocumentParameters helps to build the request body in
|
203
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
204
|
+
# RequestBuilder.
|
179
205
|
#
|
180
206
|
# Returns each entity extracted from the input.
|
181
207
|
def get_entities(params)
|
@@ -184,7 +210,8 @@ class RosetteAPI
|
|
184
210
|
params = params.load_params
|
185
211
|
|
186
212
|
endpoint = ENTITIES_ENDPOINT
|
187
|
-
RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client,
|
213
|
+
RequestBuilder.new(@user_key, @alternate_url + endpoint, @http_client,
|
214
|
+
BINDING_VERSION, params, @url_parameters)
|
188
215
|
.send_post_request
|
189
216
|
end
|
190
217
|
|
@@ -192,7 +219,8 @@ class RosetteAPI
|
|
192
219
|
#
|
193
220
|
# ==== Attributes
|
194
221
|
#
|
195
|
-
# * +params+ - DocumentParameters helps to build the request body in
|
222
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
223
|
+
# RequestBuilder.
|
196
224
|
#
|
197
225
|
# Returns the contextual categories identified in the input.
|
198
226
|
def get_categories(params)
|
@@ -200,7 +228,8 @@ class RosetteAPI
|
|
200
228
|
|
201
229
|
params = params.load_params
|
202
230
|
|
203
|
-
RequestBuilder.new(@user_key, @alternate_url + CATEGORIES_ENDPOINT,
|
231
|
+
RequestBuilder.new(@user_key, @alternate_url + CATEGORIES_ENDPOINT,
|
232
|
+
@http_client, BINDING_VERSION, params, @url_parameters)
|
204
233
|
.send_post_request
|
205
234
|
end
|
206
235
|
|
@@ -208,7 +237,8 @@ class RosetteAPI
|
|
208
237
|
#
|
209
238
|
# ==== Attributes
|
210
239
|
#
|
211
|
-
# * +params+ - DocumentParameters helps to build the request body in
|
240
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
241
|
+
# RequestBuilder.
|
212
242
|
#
|
213
243
|
# Returns each relationship extracted from the input.
|
214
244
|
def get_relationships(params)
|
@@ -216,7 +246,8 @@ class RosetteAPI
|
|
216
246
|
|
217
247
|
params = params.load_params
|
218
248
|
|
219
|
-
RequestBuilder.new(@user_key, @alternate_url + RELATIONSHIPS_ENDPOINT,
|
249
|
+
RequestBuilder.new(@user_key, @alternate_url + RELATIONSHIPS_ENDPOINT,
|
250
|
+
@http_client, BINDING_VERSION, params, @url_parameters)
|
220
251
|
.send_post_request
|
221
252
|
end
|
222
253
|
|
@@ -224,7 +255,8 @@ class RosetteAPI
|
|
224
255
|
#
|
225
256
|
# ==== Attributes
|
226
257
|
#
|
227
|
-
# * +params+ - DocumentParameters helps to build the request body in
|
258
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
259
|
+
# RequestBuilder.
|
228
260
|
#
|
229
261
|
# Returns sentiment analysis results.
|
230
262
|
def get_sentiment(params)
|
@@ -232,7 +264,8 @@ class RosetteAPI
|
|
232
264
|
|
233
265
|
params = params.load_params
|
234
266
|
|
235
|
-
RequestBuilder.new(@user_key, @alternate_url + SENTIMENT_ENDPOINT,
|
267
|
+
RequestBuilder.new(@user_key, @alternate_url + SENTIMENT_ENDPOINT,
|
268
|
+
@http_client, BINDING_VERSION, params, @url_parameters)
|
236
269
|
.send_post_request
|
237
270
|
end
|
238
271
|
|
@@ -240,15 +273,19 @@ class RosetteAPI
|
|
240
273
|
#
|
241
274
|
# ==== Attributes
|
242
275
|
#
|
243
|
-
# * +params+ - NameDeduplicationParameters helps to build the request body in
|
276
|
+
# * +params+ - NameDeduplicationParameters helps to build the request body in
|
277
|
+
# RequestBuilder.
|
244
278
|
#
|
245
279
|
# Returns the list of deduplicated names.
|
246
280
|
def get_name_deduplication(params)
|
247
|
-
check_params params,
|
281
|
+
check_params params,
|
282
|
+
'Expects a NameDeduplicationParameters type as an argument',
|
283
|
+
NameDeduplicationParameters
|
248
284
|
|
249
285
|
params = params.load_params
|
250
286
|
|
251
|
-
RequestBuilder.new(@user_key, @alternate_url + NAME_DEDUPLICATION_ENDPOINT,
|
287
|
+
RequestBuilder.new(@user_key, @alternate_url + NAME_DEDUPLICATION_ENDPOINT,
|
288
|
+
@http_client, BINDING_VERSION, params, @url_parameters)
|
252
289
|
.send_post_request
|
253
290
|
end
|
254
291
|
|
@@ -256,15 +293,19 @@ class RosetteAPI
|
|
256
293
|
#
|
257
294
|
# ==== Attributes
|
258
295
|
#
|
259
|
-
# * +params+ - NameTranslationParameters helps to build the request body in
|
296
|
+
# * +params+ - NameTranslationParameters helps to build the request body in
|
297
|
+
# RequestBuilder.
|
260
298
|
#
|
261
299
|
# Returns the translation of a name.
|
262
300
|
def get_name_translation(params)
|
263
|
-
check_params params,
|
301
|
+
check_params params,
|
302
|
+
'Expects a NameTranslationParameters type as an argument',
|
303
|
+
NameTranslationParameters
|
264
304
|
|
265
305
|
params = params.load_params
|
266
306
|
|
267
|
-
RequestBuilder.new(@user_key, @alternate_url + NAME_TRANSLATION_ENDPOINT,
|
307
|
+
RequestBuilder.new(@user_key, @alternate_url + NAME_TRANSLATION_ENDPOINT,
|
308
|
+
@http_client, BINDING_VERSION, params, @url_parameters)
|
268
309
|
.send_post_request
|
269
310
|
end
|
270
311
|
|
@@ -273,15 +314,39 @@ class RosetteAPI
|
|
273
314
|
#
|
274
315
|
# ==== Attributes
|
275
316
|
#
|
276
|
-
# * +params+ - NameSimilarityParameters helps to build the request body in
|
317
|
+
# * +params+ - NameSimilarityParameters helps to build the request body in
|
318
|
+
# RequestBuilder.
|
277
319
|
#
|
278
320
|
# Returns the confidence score of matching 2 names.
|
279
321
|
def get_name_similarity(params)
|
280
|
-
check_params params,
|
322
|
+
check_params params,
|
323
|
+
'Expects a NameSimilarityParameters type as an argument',
|
324
|
+
NameSimilarityParameters
|
281
325
|
|
282
326
|
params = params.load_params
|
283
327
|
|
284
|
-
RequestBuilder.new(@user_key, @alternate_url + NAME_SIMILARITY_ENDPOINT,
|
328
|
+
RequestBuilder.new(@user_key, @alternate_url + NAME_SIMILARITY_ENDPOINT,
|
329
|
+
@http_client, BINDING_VERSION, params, @url_parameters)
|
330
|
+
.send_post_request
|
331
|
+
end
|
332
|
+
|
333
|
+
# Compares two addresses and returns a match score from 0 to 1.
|
334
|
+
#
|
335
|
+
# ==== Attributes
|
336
|
+
#
|
337
|
+
# * +params+ - AddressSimilarityParameters helps to build the request body in
|
338
|
+
# RequestBuilder.
|
339
|
+
#
|
340
|
+
# Returns the confidence score of matching 2 addresses.
|
341
|
+
def get_address_similarity(params)
|
342
|
+
check_params params,
|
343
|
+
'Expects a AddressSimilarityParameters type as an argument',
|
344
|
+
AddressSimilarityParameters
|
345
|
+
|
346
|
+
params = params.load_params
|
347
|
+
|
348
|
+
RequestBuilder.new(@user_key, @alternate_url + ADDRESS_SIMILARITY_ENDPOINT,
|
349
|
+
@http_client, BINDING_VERSION, params, @url_parameters)
|
285
350
|
.send_post_request
|
286
351
|
end
|
287
352
|
|
@@ -289,7 +354,8 @@ class RosetteAPI
|
|
289
354
|
#
|
290
355
|
# ==== Attributes
|
291
356
|
#
|
292
|
-
# * +params+ - DocumentParameters helps to build the request body in
|
357
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
358
|
+
# RequestBuilder.
|
293
359
|
#
|
294
360
|
# Returns list of tokens of the input.
|
295
361
|
def get_tokens(params)
|
@@ -297,7 +363,8 @@ class RosetteAPI
|
|
297
363
|
|
298
364
|
params = params.load_params
|
299
365
|
|
300
|
-
RequestBuilder.new(@user_key, @alternate_url + TOKENS_ENDPOINT,
|
366
|
+
RequestBuilder.new(@user_key, @alternate_url + TOKENS_ENDPOINT,
|
367
|
+
@http_client, BINDING_VERSION, params, @url_parameters)
|
301
368
|
.send_post_request
|
302
369
|
end
|
303
370
|
|
@@ -305,7 +372,8 @@ class RosetteAPI
|
|
305
372
|
#
|
306
373
|
# ==== Attributes
|
307
374
|
#
|
308
|
-
# * +params+ - DocumentParameters helps to build the request body in
|
375
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
376
|
+
# RequestBuilder.
|
309
377
|
#
|
310
378
|
# Returns list of linguistic sentences of the input.
|
311
379
|
def get_sentences(params)
|
@@ -313,24 +381,29 @@ class RosetteAPI
|
|
313
381
|
|
314
382
|
params = params.load_params
|
315
383
|
|
316
|
-
RequestBuilder.new(@user_key, @alternate_url + SENTENCES_ENDPOINT,
|
384
|
+
RequestBuilder.new(@user_key, @alternate_url + SENTENCES_ENDPOINT,
|
385
|
+
@http_client, BINDING_VERSION, params, @url_parameters)
|
317
386
|
.send_post_request
|
318
387
|
end
|
319
388
|
|
320
389
|
#
|
321
390
|
# Returns the vectors associated with the text
|
322
391
|
#
|
392
|
+
# Deprecated. Please use `get_semantic_vectors` instead
|
393
|
+
#
|
323
394
|
# ==== Attributes
|
324
395
|
#
|
325
|
-
# * +params+ - DocumentParameters helps to build the request body in
|
396
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
397
|
+
# RequestBuilder.
|
326
398
|
#
|
327
|
-
# Returns
|
399
|
+
# Returns the text embedding representation of the input.
|
328
400
|
def get_text_embedding(params)
|
329
401
|
check_params params
|
330
402
|
|
331
403
|
params = params.load_params
|
332
404
|
|
333
|
-
RequestBuilder.new(@user_key, @alternate_url + TEXT_EMBEDDING, @http_client,
|
405
|
+
RequestBuilder.new(@user_key, @alternate_url + TEXT_EMBEDDING, @http_client,
|
406
|
+
BINDING_VERSION, params, @url_parameters)
|
334
407
|
.send_post_request
|
335
408
|
end
|
336
409
|
|
@@ -339,7 +412,25 @@ class RosetteAPI
|
|
339
412
|
#
|
340
413
|
# ==== Attributes
|
341
414
|
#
|
342
|
-
# * +params+ - DocumentParameters helps to build the request body in
|
415
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
416
|
+
# RequestBuilder.
|
417
|
+
#
|
418
|
+
# Returns the text embedding representation of the input.
|
419
|
+
def get_semantic_vectors(params)
|
420
|
+
check_params params
|
421
|
+
params = params.load_params
|
422
|
+
RequestBuilder.new(@user_key, @alternate_url + SEMANTIC_VECTORS,
|
423
|
+
@http_client, BINDING_VERSION, params, @url_parameters)
|
424
|
+
.send_post_request
|
425
|
+
end
|
426
|
+
|
427
|
+
#
|
428
|
+
# Returns the syntactic structure of the text
|
429
|
+
#
|
430
|
+
# ==== Attributes
|
431
|
+
#
|
432
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
433
|
+
# RequestBuilder.
|
343
434
|
#
|
344
435
|
# Returns list of linguistic sentences of the input.
|
345
436
|
def get_syntax_dependencies(params)
|
@@ -347,7 +438,9 @@ class RosetteAPI
|
|
347
438
|
|
348
439
|
params = params.load_params
|
349
440
|
|
350
|
-
RequestBuilder.new(@user_key,
|
441
|
+
RequestBuilder.new(@user_key,
|
442
|
+
@alternate_url + SYNTACTIC_DEPENDENCIES_ENDPOINT,
|
443
|
+
@http_client, BINDING_VERSION, params, @url_parameters)
|
351
444
|
.send_post_request
|
352
445
|
end
|
353
446
|
|
@@ -356,15 +449,19 @@ class RosetteAPI
|
|
356
449
|
#
|
357
450
|
# ==== Attributes
|
358
451
|
#
|
359
|
-
# * +params+ - DocumentParameters helps to build the request body in
|
452
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
453
|
+
# RequestBuilder.
|
360
454
|
#
|
361
455
|
# Returns the transliteration of the input.
|
362
456
|
def get_transliteration(params)
|
363
|
-
check_params params,
|
457
|
+
check_params params,
|
458
|
+
'Expects a DocumentParameters type as an argument',
|
459
|
+
DocumentParameters
|
364
460
|
|
365
461
|
params = params.load_params
|
366
462
|
|
367
|
-
RequestBuilder.new(@user_key, @alternate_url + TRANSLITERATION_ENDPOINT,
|
463
|
+
RequestBuilder.new(@user_key, @alternate_url + TRANSLITERATION_ENDPOINT,
|
464
|
+
@http_client, BINDING_VERSION, params, @url_parameters)
|
368
465
|
.send_post_request
|
369
466
|
end
|
370
467
|
|
@@ -372,7 +469,8 @@ class RosetteAPI
|
|
372
469
|
#
|
373
470
|
# ==== Attributes
|
374
471
|
#
|
375
|
-
# * +params+ - DocumentParameters helps to build the request body in
|
472
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
473
|
+
# RequestBuilder.
|
376
474
|
#
|
377
475
|
# Returns list of topics of the input.
|
378
476
|
def get_topics(params)
|
@@ -380,28 +478,57 @@ class RosetteAPI
|
|
380
478
|
|
381
479
|
params = params.load_params
|
382
480
|
|
383
|
-
RequestBuilder.new(@user_key, @alternate_url + TOPICS_ENDPOINT,
|
481
|
+
RequestBuilder.new(@user_key, @alternate_url + TOPICS_ENDPOINT,
|
482
|
+
@http_client, BINDING_VERSION, params, @url_parameters)
|
483
|
+
.send_post_request
|
484
|
+
end
|
485
|
+
|
486
|
+
# Returns the terms similar to the input
|
487
|
+
#
|
488
|
+
# ==== Attributes
|
489
|
+
#
|
490
|
+
# * +params+ - DocumentParameters helps to build the request body in
|
491
|
+
# RequestBuilder.
|
492
|
+
#
|
493
|
+
# Returns a mapping of languageCode to similar terms
|
494
|
+
def get_similar_terms(params)
|
495
|
+
check_params params
|
496
|
+
|
497
|
+
params = params.load_params
|
498
|
+
|
499
|
+
RequestBuilder.new(@user_key, @alternate_url + SIMILAR_TERMS_ENDPOINT,
|
500
|
+
@http_client, BINDING_VERSION, params, @url_parameters)
|
384
501
|
.send_post_request
|
385
502
|
end
|
386
503
|
|
387
504
|
# Gets information about the Rosette API, returns name, build number
|
388
505
|
# and build time.
|
389
506
|
def info
|
390
|
-
RequestBuilder.new(@user_key, @alternate_url + INFO, @http_client,
|
507
|
+
RequestBuilder.new(@user_key, @alternate_url + INFO, @http_client,
|
508
|
+
BINDING_VERSION, @url_parameters)
|
391
509
|
.send_get_request
|
392
510
|
end
|
393
511
|
|
394
512
|
# Pings the Rosette API for a response indicting that the service is
|
395
513
|
# available.
|
396
514
|
def ping
|
397
|
-
RequestBuilder.new(@user_key, @alternate_url + PING, @http_client,
|
515
|
+
RequestBuilder.new(@user_key, @alternate_url + PING, @http_client,
|
516
|
+
BINDING_VERSION, @url_parameters)
|
398
517
|
.send_get_request
|
399
518
|
end
|
400
519
|
|
520
|
+
# Gets the User-Agent string
|
521
|
+
def user_agent
|
522
|
+
RequestBuilder.new(@user_key, @alternate_url + PING, @http_client,
|
523
|
+
BINDING_VERSION, @url_parameters).user_agent
|
524
|
+
end
|
525
|
+
|
401
526
|
private
|
402
527
|
|
403
528
|
# Checks that the right parameter type is being passed in.
|
404
|
-
def check_params(params,
|
529
|
+
def check_params(params,
|
530
|
+
message = 'Expects a DocumentParameters type as an argument',
|
531
|
+
type = DocumentParameters)
|
405
532
|
raise BadRequestError.new message unless params.is_a? type
|
406
533
|
end
|
407
534
|
end
|