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