azure_cognitiveservices_textanalytics 0.17.0 → 0.17.1
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/lib/azure_cognitiveservices_textanalytics.rb +1 -0
- data/lib/profiles/latest/modules/textanalytics_profile_module.rb +41 -41
- data/lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb +16 -5
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics.rb +45 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/batch_input.rb +56 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/detected_language.rb +72 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/entities_batch_result_item_v2dot1.rb +70 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/entities_batch_result_v2dot1.rb +78 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/entity_record_v2dot1.rb +138 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/error_record.rb +58 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/error_response.rb +81 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/input.rb +58 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/internal_error.rb +70 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/key_phrase_batch_result.rb +78 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/key_phrase_batch_result_item.rb +70 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/language_batch_result.rb +78 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/language_batch_result_item.rb +69 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/match_record_v2dot1.rb +71 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/multi_language_batch_input.rb +56 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/multi_language_input.rb +70 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/sentiment_batch_result.rb +78 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/models/sentiment_batch_result_item.rb +63 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/module_definition.rb +9 -0
- data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb +604 -0
- data/lib/version.rb +1 -1
- metadata +23 -2
@@ -0,0 +1,78 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Code generated by Microsoft (R) AutoRest Code Generator.
|
3
|
+
# Changes may cause incorrect behavior and will be lost if the code is
|
4
|
+
# regenerated.
|
5
|
+
|
6
|
+
module Azure::CognitiveServices::TextAnalytics::V2_1_preview
|
7
|
+
module Models
|
8
|
+
#
|
9
|
+
# Model object.
|
10
|
+
#
|
11
|
+
#
|
12
|
+
class SentimentBatchResult
|
13
|
+
|
14
|
+
include MsRestAzure
|
15
|
+
|
16
|
+
# @return [Array<SentimentBatchResultItem>]
|
17
|
+
attr_accessor :documents
|
18
|
+
|
19
|
+
# @return [Array<ErrorRecord>]
|
20
|
+
attr_accessor :errors
|
21
|
+
|
22
|
+
|
23
|
+
#
|
24
|
+
# Mapper for SentimentBatchResult class as Ruby Hash.
|
25
|
+
# This will be used for serialization/deserialization.
|
26
|
+
#
|
27
|
+
def self.mapper()
|
28
|
+
{
|
29
|
+
client_side_validation: true,
|
30
|
+
required: false,
|
31
|
+
serialized_name: 'SentimentBatchResult',
|
32
|
+
type: {
|
33
|
+
name: 'Composite',
|
34
|
+
class_name: 'SentimentBatchResult',
|
35
|
+
model_properties: {
|
36
|
+
documents: {
|
37
|
+
client_side_validation: true,
|
38
|
+
required: false,
|
39
|
+
read_only: true,
|
40
|
+
serialized_name: 'documents',
|
41
|
+
type: {
|
42
|
+
name: 'Sequence',
|
43
|
+
element: {
|
44
|
+
client_side_validation: true,
|
45
|
+
required: false,
|
46
|
+
serialized_name: 'SentimentBatchResultItemElementType',
|
47
|
+
type: {
|
48
|
+
name: 'Composite',
|
49
|
+
class_name: 'SentimentBatchResultItem'
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
},
|
54
|
+
errors: {
|
55
|
+
client_side_validation: true,
|
56
|
+
required: false,
|
57
|
+
read_only: true,
|
58
|
+
serialized_name: 'errors',
|
59
|
+
type: {
|
60
|
+
name: 'Sequence',
|
61
|
+
element: {
|
62
|
+
client_side_validation: true,
|
63
|
+
required: false,
|
64
|
+
serialized_name: 'ErrorRecordElementType',
|
65
|
+
type: {
|
66
|
+
name: 'Composite',
|
67
|
+
class_name: 'ErrorRecord'
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Code generated by Microsoft (R) AutoRest Code Generator.
|
3
|
+
# Changes may cause incorrect behavior and will be lost if the code is
|
4
|
+
# regenerated.
|
5
|
+
|
6
|
+
module Azure::CognitiveServices::TextAnalytics::V2_1_preview
|
7
|
+
module Models
|
8
|
+
#
|
9
|
+
# Model object.
|
10
|
+
#
|
11
|
+
#
|
12
|
+
class SentimentBatchResultItem
|
13
|
+
|
14
|
+
include MsRestAzure
|
15
|
+
|
16
|
+
# @return [Float] A decimal number between 0 and 1 denoting the sentiment
|
17
|
+
# of the document. A score above 0.7 usually refers to a positive
|
18
|
+
# document while a score below 0.3 normally has a negative connotation.
|
19
|
+
# Mid values refer to neutral text.
|
20
|
+
attr_accessor :score
|
21
|
+
|
22
|
+
# @return [String] Unique document identifier.
|
23
|
+
attr_accessor :id
|
24
|
+
|
25
|
+
|
26
|
+
#
|
27
|
+
# Mapper for SentimentBatchResultItem class as Ruby Hash.
|
28
|
+
# This will be used for serialization/deserialization.
|
29
|
+
#
|
30
|
+
def self.mapper()
|
31
|
+
{
|
32
|
+
client_side_validation: true,
|
33
|
+
required: false,
|
34
|
+
serialized_name: 'SentimentBatchResultItem',
|
35
|
+
type: {
|
36
|
+
name: 'Composite',
|
37
|
+
class_name: 'SentimentBatchResultItem',
|
38
|
+
model_properties: {
|
39
|
+
score: {
|
40
|
+
client_side_validation: true,
|
41
|
+
required: false,
|
42
|
+
read_only: true,
|
43
|
+
serialized_name: 'score',
|
44
|
+
type: {
|
45
|
+
name: 'Double'
|
46
|
+
}
|
47
|
+
},
|
48
|
+
id: {
|
49
|
+
client_side_validation: true,
|
50
|
+
required: false,
|
51
|
+
read_only: true,
|
52
|
+
serialized_name: 'id',
|
53
|
+
type: {
|
54
|
+
name: 'String'
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Code generated by Microsoft (R) AutoRest Code Generator.
|
3
|
+
# Changes may cause incorrect behavior and will be lost if the code is
|
4
|
+
# regenerated.
|
5
|
+
|
6
|
+
module Azure end
|
7
|
+
module Azure::CognitiveServices end
|
8
|
+
module Azure::CognitiveServices::TextAnalytics end
|
9
|
+
module Azure::CognitiveServices::TextAnalytics::V2_1_preview end
|
data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb
ADDED
@@ -0,0 +1,604 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Code generated by Microsoft (R) AutoRest Code Generator.
|
3
|
+
# Changes may cause incorrect behavior and will be lost if the code is
|
4
|
+
# regenerated.
|
5
|
+
|
6
|
+
module Azure::CognitiveServices::TextAnalytics::V2_1_preview
|
7
|
+
#
|
8
|
+
# A service client - single point of access to the REST API.
|
9
|
+
#
|
10
|
+
class TextAnalyticsClient < MsRestAzure::AzureServiceClient
|
11
|
+
include MsRestAzure
|
12
|
+
include MsRestAzure::Serialization
|
13
|
+
|
14
|
+
# @return [String] the base URI of the service.
|
15
|
+
attr_reader :base_url
|
16
|
+
|
17
|
+
# @return Credentials needed for the client to connect to Azure.
|
18
|
+
attr_reader :credentials1
|
19
|
+
|
20
|
+
# @return [String] Supported Cognitive Services endpoints (protocol and
|
21
|
+
# hostname, for example: https://westus.api.cognitive.microsoft.com).
|
22
|
+
attr_accessor :endpoint
|
23
|
+
|
24
|
+
# @return Subscription credentials which uniquely identify client
|
25
|
+
# subscription.
|
26
|
+
attr_accessor :credentials
|
27
|
+
|
28
|
+
# @return [String] The preferred language for the response.
|
29
|
+
attr_accessor :accept_language
|
30
|
+
|
31
|
+
# @return [Integer] The retry timeout in seconds for Long Running
|
32
|
+
# Operations. Default value is 30.
|
33
|
+
attr_accessor :long_running_operation_retry_timeout
|
34
|
+
|
35
|
+
# @return [Boolean] Whether a unique x-ms-client-request-id should be
|
36
|
+
# generated. When set to true a unique x-ms-client-request-id value is
|
37
|
+
# generated and included in each request. Default is true.
|
38
|
+
attr_accessor :generate_client_request_id
|
39
|
+
|
40
|
+
#
|
41
|
+
# Creates initializes a new instance of the TextAnalyticsClient class.
|
42
|
+
# @param credentials [MsRest::ServiceClientCredentials] credentials to authorize HTTP requests made by the service client.
|
43
|
+
# @param options [Array] filters to be applied to the HTTP requests.
|
44
|
+
#
|
45
|
+
def initialize(credentials = nil, options = nil)
|
46
|
+
super(credentials, options)
|
47
|
+
@base_url = '{Endpoint}/text/analytics/v2.1-preview'
|
48
|
+
|
49
|
+
fail ArgumentError, 'invalid type of credentials input parameter' unless credentials.is_a?(MsRest::ServiceClientCredentials) unless credentials.nil?
|
50
|
+
@credentials = credentials
|
51
|
+
|
52
|
+
@accept_language = 'en-US'
|
53
|
+
@long_running_operation_retry_timeout = 30
|
54
|
+
@generate_client_request_id = true
|
55
|
+
add_telemetry
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# Makes a request and returns the body of the response.
|
60
|
+
# @param method [Symbol] with any of the following values :get, :put, :post, :patch, :delete.
|
61
|
+
# @param path [String] the path, relative to {base_url}.
|
62
|
+
# @param options [Hash{String=>String}] specifying any request options like :body.
|
63
|
+
# @return [Hash{String=>String}] containing the body of the response.
|
64
|
+
# Example:
|
65
|
+
#
|
66
|
+
# request_content = "{'location':'westus','tags':{'tag1':'val1','tag2':'val2'}}"
|
67
|
+
# path = "/path"
|
68
|
+
# options = {
|
69
|
+
# body: request_content,
|
70
|
+
# query_params: {'api-version' => '2016-02-01'}
|
71
|
+
# }
|
72
|
+
# result = @client.make_request(:put, path, options)
|
73
|
+
#
|
74
|
+
def make_request(method, path, options = {})
|
75
|
+
result = make_request_with_http_info(method, path, options)
|
76
|
+
result.body unless result.nil?
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# Makes a request and returns the operation response.
|
81
|
+
# @param method [Symbol] with any of the following values :get, :put, :post, :patch, :delete.
|
82
|
+
# @param path [String] the path, relative to {base_url}.
|
83
|
+
# @param options [Hash{String=>String}] specifying any request options like :body.
|
84
|
+
# @return [MsRestAzure::AzureOperationResponse] Operation response containing the request, response and status.
|
85
|
+
#
|
86
|
+
def make_request_with_http_info(method, path, options = {})
|
87
|
+
result = make_request_async(method, path, options).value!
|
88
|
+
result.body = result.response.body.to_s.empty? ? nil : JSON.load(result.response.body)
|
89
|
+
result
|
90
|
+
end
|
91
|
+
|
92
|
+
#
|
93
|
+
# Makes a request asynchronously.
|
94
|
+
# @param method [Symbol] with any of the following values :get, :put, :post, :patch, :delete.
|
95
|
+
# @param path [String] the path, relative to {base_url}.
|
96
|
+
# @param options [Hash{String=>String}] specifying any request options like :body.
|
97
|
+
# @return [Concurrent::Promise] Promise object which holds the HTTP response.
|
98
|
+
#
|
99
|
+
def make_request_async(method, path, options = {})
|
100
|
+
fail ArgumentError, 'method is nil' if method.nil?
|
101
|
+
fail ArgumentError, 'path is nil' if path.nil?
|
102
|
+
|
103
|
+
request_url = options[:base_url] || @base_url
|
104
|
+
if(!options[:headers].nil? && !options[:headers]['Content-Type'].nil?)
|
105
|
+
@request_headers['Content-Type'] = options[:headers]['Content-Type']
|
106
|
+
end
|
107
|
+
|
108
|
+
request_headers = @request_headers
|
109
|
+
request_headers.merge!({'accept-language' => @accept_language}) unless @accept_language.nil?
|
110
|
+
options.merge!({headers: request_headers.merge(options[:headers] || {})})
|
111
|
+
options.merge!({credentials: @credentials}) unless @credentials.nil?
|
112
|
+
|
113
|
+
super(request_url, method, path, options)
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# The API returns a list of strings denoting the key talking points in the
|
118
|
+
# input text.
|
119
|
+
#
|
120
|
+
# See the <a
|
121
|
+
# href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages">Text
|
122
|
+
# Analytics Documentation</a> for details about the languages that are
|
123
|
+
# supported by key phrase extraction.
|
124
|
+
#
|
125
|
+
# @param input [MultiLanguageBatchInput] Collection of documents to analyze.
|
126
|
+
# Documents can now contain a language field to indicate the text language
|
127
|
+
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
128
|
+
# will be added to the HTTP request.
|
129
|
+
#
|
130
|
+
# @return [KeyPhraseBatchResult] operation results.
|
131
|
+
#
|
132
|
+
def key_phrases(input, custom_headers:nil)
|
133
|
+
response = key_phrases_async(input, custom_headers:custom_headers).value!
|
134
|
+
response.body unless response.nil?
|
135
|
+
end
|
136
|
+
|
137
|
+
#
|
138
|
+
# The API returns a list of strings denoting the key talking points in the
|
139
|
+
# input text.
|
140
|
+
#
|
141
|
+
# See the <a
|
142
|
+
# href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages">Text
|
143
|
+
# Analytics Documentation</a> for details about the languages that are
|
144
|
+
# supported by key phrase extraction.
|
145
|
+
#
|
146
|
+
# @param input [MultiLanguageBatchInput] Collection of documents to analyze.
|
147
|
+
# Documents can now contain a language field to indicate the text language
|
148
|
+
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
149
|
+
# will be added to the HTTP request.
|
150
|
+
#
|
151
|
+
# @return [MsRestAzure::AzureOperationResponse] HTTP response information.
|
152
|
+
#
|
153
|
+
def key_phrases_with_http_info(input, custom_headers:nil)
|
154
|
+
key_phrases_async(input, custom_headers:custom_headers).value!
|
155
|
+
end
|
156
|
+
|
157
|
+
#
|
158
|
+
# The API returns a list of strings denoting the key talking points in the
|
159
|
+
# input text.
|
160
|
+
#
|
161
|
+
# See the <a
|
162
|
+
# href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages">Text
|
163
|
+
# Analytics Documentation</a> for details about the languages that are
|
164
|
+
# supported by key phrase extraction.
|
165
|
+
#
|
166
|
+
# @param input [MultiLanguageBatchInput] Collection of documents to analyze.
|
167
|
+
# Documents can now contain a language field to indicate the text language
|
168
|
+
# @param [Hash{String => String}] A hash of custom headers that will be added
|
169
|
+
# to the HTTP request.
|
170
|
+
#
|
171
|
+
# @return [Concurrent::Promise] Promise object which holds the HTTP response.
|
172
|
+
#
|
173
|
+
def key_phrases_async(input, custom_headers:nil)
|
174
|
+
fail ArgumentError, 'endpoint is nil' if endpoint.nil?
|
175
|
+
fail ArgumentError, 'input is nil' if input.nil?
|
176
|
+
|
177
|
+
|
178
|
+
request_headers = {}
|
179
|
+
request_headers['Content-Type'] = 'application/json; charset=utf-8'
|
180
|
+
|
181
|
+
# Set Headers
|
182
|
+
request_headers['x-ms-client-request-id'] = SecureRandom.uuid
|
183
|
+
request_headers['accept-language'] = accept_language unless accept_language.nil?
|
184
|
+
|
185
|
+
# Serialize Request
|
186
|
+
request_mapper = Azure::CognitiveServices::TextAnalytics::V2_1_preview::Models::MultiLanguageBatchInput.mapper()
|
187
|
+
request_content = self.serialize(request_mapper, input)
|
188
|
+
request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
|
189
|
+
|
190
|
+
path_template = 'keyPhrases'
|
191
|
+
|
192
|
+
request_url = @base_url || self.base_url
|
193
|
+
request_url = request_url.gsub('{Endpoint}', endpoint)
|
194
|
+
|
195
|
+
options = {
|
196
|
+
middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
|
197
|
+
body: request_content,
|
198
|
+
headers: request_headers.merge(custom_headers || {}),
|
199
|
+
base_url: request_url
|
200
|
+
}
|
201
|
+
promise = self.make_request_async(:post, path_template, options)
|
202
|
+
|
203
|
+
promise = promise.then do |result|
|
204
|
+
http_response = result.response
|
205
|
+
status_code = http_response.status
|
206
|
+
response_content = http_response.body
|
207
|
+
unless status_code == 200
|
208
|
+
error_model = JSON.load(response_content)
|
209
|
+
fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
|
210
|
+
end
|
211
|
+
|
212
|
+
result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
|
213
|
+
# Deserialize Response
|
214
|
+
if status_code == 200
|
215
|
+
begin
|
216
|
+
parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
|
217
|
+
result_mapper = Azure::CognitiveServices::TextAnalytics::V2_1_preview::Models::KeyPhraseBatchResult.mapper()
|
218
|
+
result.body = self.deserialize(result_mapper, parsed_response)
|
219
|
+
rescue Exception => e
|
220
|
+
fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
result
|
225
|
+
end
|
226
|
+
|
227
|
+
promise.execute
|
228
|
+
end
|
229
|
+
|
230
|
+
#
|
231
|
+
# The API returns the detected language and a numeric score between 0 and 1.
|
232
|
+
#
|
233
|
+
# Scores close to 1 indicate 100% certainty that the identified language is
|
234
|
+
# true. A total of 120 languages are supported.
|
235
|
+
#
|
236
|
+
# @param input [BatchInput] Collection of documents to analyze.
|
237
|
+
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
238
|
+
# will be added to the HTTP request.
|
239
|
+
#
|
240
|
+
# @return [LanguageBatchResult] operation results.
|
241
|
+
#
|
242
|
+
def detect_language(input, custom_headers:nil)
|
243
|
+
response = detect_language_async(input, custom_headers:custom_headers).value!
|
244
|
+
response.body unless response.nil?
|
245
|
+
end
|
246
|
+
|
247
|
+
#
|
248
|
+
# The API returns the detected language and a numeric score between 0 and 1.
|
249
|
+
#
|
250
|
+
# Scores close to 1 indicate 100% certainty that the identified language is
|
251
|
+
# true. A total of 120 languages are supported.
|
252
|
+
#
|
253
|
+
# @param input [BatchInput] Collection of documents to analyze.
|
254
|
+
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
255
|
+
# will be added to the HTTP request.
|
256
|
+
#
|
257
|
+
# @return [MsRestAzure::AzureOperationResponse] HTTP response information.
|
258
|
+
#
|
259
|
+
def detect_language_with_http_info(input, custom_headers:nil)
|
260
|
+
detect_language_async(input, custom_headers:custom_headers).value!
|
261
|
+
end
|
262
|
+
|
263
|
+
#
|
264
|
+
# The API returns the detected language and a numeric score between 0 and 1.
|
265
|
+
#
|
266
|
+
# Scores close to 1 indicate 100% certainty that the identified language is
|
267
|
+
# true. A total of 120 languages are supported.
|
268
|
+
#
|
269
|
+
# @param input [BatchInput] Collection of documents to analyze.
|
270
|
+
# @param [Hash{String => String}] A hash of custom headers that will be added
|
271
|
+
# to the HTTP request.
|
272
|
+
#
|
273
|
+
# @return [Concurrent::Promise] Promise object which holds the HTTP response.
|
274
|
+
#
|
275
|
+
def detect_language_async(input, custom_headers:nil)
|
276
|
+
fail ArgumentError, 'endpoint is nil' if endpoint.nil?
|
277
|
+
fail ArgumentError, 'input is nil' if input.nil?
|
278
|
+
|
279
|
+
|
280
|
+
request_headers = {}
|
281
|
+
request_headers['Content-Type'] = 'application/json; charset=utf-8'
|
282
|
+
|
283
|
+
# Set Headers
|
284
|
+
request_headers['x-ms-client-request-id'] = SecureRandom.uuid
|
285
|
+
request_headers['accept-language'] = accept_language unless accept_language.nil?
|
286
|
+
|
287
|
+
# Serialize Request
|
288
|
+
request_mapper = Azure::CognitiveServices::TextAnalytics::V2_1_preview::Models::BatchInput.mapper()
|
289
|
+
request_content = self.serialize(request_mapper, input)
|
290
|
+
request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
|
291
|
+
|
292
|
+
path_template = 'languages'
|
293
|
+
|
294
|
+
request_url = @base_url || self.base_url
|
295
|
+
request_url = request_url.gsub('{Endpoint}', endpoint)
|
296
|
+
|
297
|
+
options = {
|
298
|
+
middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
|
299
|
+
body: request_content,
|
300
|
+
headers: request_headers.merge(custom_headers || {}),
|
301
|
+
base_url: request_url
|
302
|
+
}
|
303
|
+
promise = self.make_request_async(:post, path_template, options)
|
304
|
+
|
305
|
+
promise = promise.then do |result|
|
306
|
+
http_response = result.response
|
307
|
+
status_code = http_response.status
|
308
|
+
response_content = http_response.body
|
309
|
+
unless status_code == 200
|
310
|
+
error_model = JSON.load(response_content)
|
311
|
+
fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
|
312
|
+
end
|
313
|
+
|
314
|
+
result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
|
315
|
+
# Deserialize Response
|
316
|
+
if status_code == 200
|
317
|
+
begin
|
318
|
+
parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
|
319
|
+
result_mapper = Azure::CognitiveServices::TextAnalytics::V2_1_preview::Models::LanguageBatchResult.mapper()
|
320
|
+
result.body = self.deserialize(result_mapper, parsed_response)
|
321
|
+
rescue Exception => e
|
322
|
+
fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
result
|
327
|
+
end
|
328
|
+
|
329
|
+
promise.execute
|
330
|
+
end
|
331
|
+
|
332
|
+
#
|
333
|
+
# The API returns a numeric score between 0 and 1.
|
334
|
+
#
|
335
|
+
# Scores close to 1 indicate positive sentiment, while scores close to 0
|
336
|
+
# indicate negative sentiment. A score of 0.5 indicates the lack of sentiment
|
337
|
+
# (e.g. a factoid statement). See the <a
|
338
|
+
# href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages">Text
|
339
|
+
# Analytics Documentation</a> for details about the languages that are
|
340
|
+
# supported by sentiment analysis.
|
341
|
+
#
|
342
|
+
# @param input [MultiLanguageBatchInput] Collection of documents to analyze.
|
343
|
+
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
344
|
+
# will be added to the HTTP request.
|
345
|
+
#
|
346
|
+
# @return [SentimentBatchResult] operation results.
|
347
|
+
#
|
348
|
+
def sentiment(input, custom_headers:nil)
|
349
|
+
response = sentiment_async(input, custom_headers:custom_headers).value!
|
350
|
+
response.body unless response.nil?
|
351
|
+
end
|
352
|
+
|
353
|
+
#
|
354
|
+
# The API returns a numeric score between 0 and 1.
|
355
|
+
#
|
356
|
+
# Scores close to 1 indicate positive sentiment, while scores close to 0
|
357
|
+
# indicate negative sentiment. A score of 0.5 indicates the lack of sentiment
|
358
|
+
# (e.g. a factoid statement). See the <a
|
359
|
+
# href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages">Text
|
360
|
+
# Analytics Documentation</a> for details about the languages that are
|
361
|
+
# supported by sentiment analysis.
|
362
|
+
#
|
363
|
+
# @param input [MultiLanguageBatchInput] Collection of documents to analyze.
|
364
|
+
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
365
|
+
# will be added to the HTTP request.
|
366
|
+
#
|
367
|
+
# @return [MsRestAzure::AzureOperationResponse] HTTP response information.
|
368
|
+
#
|
369
|
+
def sentiment_with_http_info(input, custom_headers:nil)
|
370
|
+
sentiment_async(input, custom_headers:custom_headers).value!
|
371
|
+
end
|
372
|
+
|
373
|
+
#
|
374
|
+
# The API returns a numeric score between 0 and 1.
|
375
|
+
#
|
376
|
+
# Scores close to 1 indicate positive sentiment, while scores close to 0
|
377
|
+
# indicate negative sentiment. A score of 0.5 indicates the lack of sentiment
|
378
|
+
# (e.g. a factoid statement). See the <a
|
379
|
+
# href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages">Text
|
380
|
+
# Analytics Documentation</a> for details about the languages that are
|
381
|
+
# supported by sentiment analysis.
|
382
|
+
#
|
383
|
+
# @param input [MultiLanguageBatchInput] Collection of documents to analyze.
|
384
|
+
# @param [Hash{String => String}] A hash of custom headers that will be added
|
385
|
+
# to the HTTP request.
|
386
|
+
#
|
387
|
+
# @return [Concurrent::Promise] Promise object which holds the HTTP response.
|
388
|
+
#
|
389
|
+
def sentiment_async(input, custom_headers:nil)
|
390
|
+
fail ArgumentError, 'endpoint is nil' if endpoint.nil?
|
391
|
+
fail ArgumentError, 'input is nil' if input.nil?
|
392
|
+
|
393
|
+
|
394
|
+
request_headers = {}
|
395
|
+
request_headers['Content-Type'] = 'application/json; charset=utf-8'
|
396
|
+
|
397
|
+
# Set Headers
|
398
|
+
request_headers['x-ms-client-request-id'] = SecureRandom.uuid
|
399
|
+
request_headers['accept-language'] = accept_language unless accept_language.nil?
|
400
|
+
|
401
|
+
# Serialize Request
|
402
|
+
request_mapper = Azure::CognitiveServices::TextAnalytics::V2_1_preview::Models::MultiLanguageBatchInput.mapper()
|
403
|
+
request_content = self.serialize(request_mapper, input)
|
404
|
+
request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
|
405
|
+
|
406
|
+
path_template = 'sentiment'
|
407
|
+
|
408
|
+
request_url = @base_url || self.base_url
|
409
|
+
request_url = request_url.gsub('{Endpoint}', endpoint)
|
410
|
+
|
411
|
+
options = {
|
412
|
+
middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
|
413
|
+
body: request_content,
|
414
|
+
headers: request_headers.merge(custom_headers || {}),
|
415
|
+
base_url: request_url
|
416
|
+
}
|
417
|
+
promise = self.make_request_async(:post, path_template, options)
|
418
|
+
|
419
|
+
promise = promise.then do |result|
|
420
|
+
http_response = result.response
|
421
|
+
status_code = http_response.status
|
422
|
+
response_content = http_response.body
|
423
|
+
unless status_code == 200
|
424
|
+
error_model = JSON.load(response_content)
|
425
|
+
fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
|
426
|
+
end
|
427
|
+
|
428
|
+
result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
|
429
|
+
# Deserialize Response
|
430
|
+
if status_code == 200
|
431
|
+
begin
|
432
|
+
parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
|
433
|
+
result_mapper = Azure::CognitiveServices::TextAnalytics::V2_1_preview::Models::SentimentBatchResult.mapper()
|
434
|
+
result.body = self.deserialize(result_mapper, parsed_response)
|
435
|
+
rescue Exception => e
|
436
|
+
fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
result
|
441
|
+
end
|
442
|
+
|
443
|
+
promise.execute
|
444
|
+
end
|
445
|
+
|
446
|
+
#
|
447
|
+
# The API returns a list of recognized entities in a given document.
|
448
|
+
#
|
449
|
+
# The API returns a list of recognized entities in a given document. To get
|
450
|
+
# even more information on each recognized entity we recommend using the Bing
|
451
|
+
# Entity Search API by querying for the recognized entities names. See the <a
|
452
|
+
# href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported-languages">Supported
|
453
|
+
# languages in Text Analytics API</a> for the list of enabled languages.The API
|
454
|
+
# returns a list of known entities and general named entities ("Person",
|
455
|
+
# "Location", "Organization" etc) in a given document. Known entities are
|
456
|
+
# returned with Wikipedia Id and Wikipedia link, and also Bing Id which can be
|
457
|
+
# used in Bing Entity Search API. General named entities are returned with
|
458
|
+
# entity types. If a general named entity is also a known entity, then all
|
459
|
+
# information regarding it (Wikipedia Id, Bing Id, entity type etc) will be
|
460
|
+
# returned. See the <a
|
461
|
+
# href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/how-tos/text-analytics-how-to-entity-linking#supported-types-for-named-entity-recognition">Supported
|
462
|
+
# Entity Types in Text Analytics API</a> for the list of supported Entity
|
463
|
+
# Types. See the <a
|
464
|
+
# href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported-languages">Supported
|
465
|
+
# languages in Text Analytics API</a> for the list of enabled languages.
|
466
|
+
#
|
467
|
+
# @param input [MultiLanguageBatchInput] Collection of documents to analyze.
|
468
|
+
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
469
|
+
# will be added to the HTTP request.
|
470
|
+
#
|
471
|
+
# @return [EntitiesBatchResultV2dot1] operation results.
|
472
|
+
#
|
473
|
+
def entities(input, custom_headers:nil)
|
474
|
+
response = entities_async(input, custom_headers:custom_headers).value!
|
475
|
+
response.body unless response.nil?
|
476
|
+
end
|
477
|
+
|
478
|
+
#
|
479
|
+
# The API returns a list of recognized entities in a given document.
|
480
|
+
#
|
481
|
+
# The API returns a list of recognized entities in a given document. To get
|
482
|
+
# even more information on each recognized entity we recommend using the Bing
|
483
|
+
# Entity Search API by querying for the recognized entities names. See the <a
|
484
|
+
# href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported-languages">Supported
|
485
|
+
# languages in Text Analytics API</a> for the list of enabled languages.The API
|
486
|
+
# returns a list of known entities and general named entities ("Person",
|
487
|
+
# "Location", "Organization" etc) in a given document. Known entities are
|
488
|
+
# returned with Wikipedia Id and Wikipedia link, and also Bing Id which can be
|
489
|
+
# used in Bing Entity Search API. General named entities are returned with
|
490
|
+
# entity types. If a general named entity is also a known entity, then all
|
491
|
+
# information regarding it (Wikipedia Id, Bing Id, entity type etc) will be
|
492
|
+
# returned. See the <a
|
493
|
+
# href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/how-tos/text-analytics-how-to-entity-linking#supported-types-for-named-entity-recognition">Supported
|
494
|
+
# Entity Types in Text Analytics API</a> for the list of supported Entity
|
495
|
+
# Types. See the <a
|
496
|
+
# href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported-languages">Supported
|
497
|
+
# languages in Text Analytics API</a> for the list of enabled languages.
|
498
|
+
#
|
499
|
+
# @param input [MultiLanguageBatchInput] Collection of documents to analyze.
|
500
|
+
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
501
|
+
# will be added to the HTTP request.
|
502
|
+
#
|
503
|
+
# @return [MsRestAzure::AzureOperationResponse] HTTP response information.
|
504
|
+
#
|
505
|
+
def entities_with_http_info(input, custom_headers:nil)
|
506
|
+
entities_async(input, custom_headers:custom_headers).value!
|
507
|
+
end
|
508
|
+
|
509
|
+
#
|
510
|
+
# The API returns a list of recognized entities in a given document.
|
511
|
+
#
|
512
|
+
# The API returns a list of recognized entities in a given document. To get
|
513
|
+
# even more information on each recognized entity we recommend using the Bing
|
514
|
+
# Entity Search API by querying for the recognized entities names. See the <a
|
515
|
+
# href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported-languages">Supported
|
516
|
+
# languages in Text Analytics API</a> for the list of enabled languages.The API
|
517
|
+
# returns a list of known entities and general named entities ("Person",
|
518
|
+
# "Location", "Organization" etc) in a given document. Known entities are
|
519
|
+
# returned with Wikipedia Id and Wikipedia link, and also Bing Id which can be
|
520
|
+
# used in Bing Entity Search API. General named entities are returned with
|
521
|
+
# entity types. If a general named entity is also a known entity, then all
|
522
|
+
# information regarding it (Wikipedia Id, Bing Id, entity type etc) will be
|
523
|
+
# returned. See the <a
|
524
|
+
# href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/how-tos/text-analytics-how-to-entity-linking#supported-types-for-named-entity-recognition">Supported
|
525
|
+
# Entity Types in Text Analytics API</a> for the list of supported Entity
|
526
|
+
# Types. See the <a
|
527
|
+
# href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported-languages">Supported
|
528
|
+
# languages in Text Analytics API</a> for the list of enabled languages.
|
529
|
+
#
|
530
|
+
# @param input [MultiLanguageBatchInput] Collection of documents to analyze.
|
531
|
+
# @param [Hash{String => String}] A hash of custom headers that will be added
|
532
|
+
# to the HTTP request.
|
533
|
+
#
|
534
|
+
# @return [Concurrent::Promise] Promise object which holds the HTTP response.
|
535
|
+
#
|
536
|
+
def entities_async(input, custom_headers:nil)
|
537
|
+
fail ArgumentError, 'endpoint is nil' if endpoint.nil?
|
538
|
+
fail ArgumentError, 'input is nil' if input.nil?
|
539
|
+
|
540
|
+
|
541
|
+
request_headers = {}
|
542
|
+
request_headers['Content-Type'] = 'application/json; charset=utf-8'
|
543
|
+
|
544
|
+
# Set Headers
|
545
|
+
request_headers['x-ms-client-request-id'] = SecureRandom.uuid
|
546
|
+
request_headers['accept-language'] = accept_language unless accept_language.nil?
|
547
|
+
|
548
|
+
# Serialize Request
|
549
|
+
request_mapper = Azure::CognitiveServices::TextAnalytics::V2_1_preview::Models::MultiLanguageBatchInput.mapper()
|
550
|
+
request_content = self.serialize(request_mapper, input)
|
551
|
+
request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
|
552
|
+
|
553
|
+
path_template = 'entities'
|
554
|
+
|
555
|
+
request_url = @base_url || self.base_url
|
556
|
+
request_url = request_url.gsub('{Endpoint}', endpoint)
|
557
|
+
|
558
|
+
options = {
|
559
|
+
middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
|
560
|
+
body: request_content,
|
561
|
+
headers: request_headers.merge(custom_headers || {}),
|
562
|
+
base_url: request_url
|
563
|
+
}
|
564
|
+
promise = self.make_request_async(:post, path_template, options)
|
565
|
+
|
566
|
+
promise = promise.then do |result|
|
567
|
+
http_response = result.response
|
568
|
+
status_code = http_response.status
|
569
|
+
response_content = http_response.body
|
570
|
+
unless status_code == 200
|
571
|
+
error_model = JSON.load(response_content)
|
572
|
+
fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
|
573
|
+
end
|
574
|
+
|
575
|
+
result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
|
576
|
+
# Deserialize Response
|
577
|
+
if status_code == 200
|
578
|
+
begin
|
579
|
+
parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
|
580
|
+
result_mapper = Azure::CognitiveServices::TextAnalytics::V2_1_preview::Models::EntitiesBatchResultV2dot1.mapper()
|
581
|
+
result.body = self.deserialize(result_mapper, parsed_response)
|
582
|
+
rescue Exception => e
|
583
|
+
fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
|
584
|
+
end
|
585
|
+
end
|
586
|
+
|
587
|
+
result
|
588
|
+
end
|
589
|
+
|
590
|
+
promise.execute
|
591
|
+
end
|
592
|
+
|
593
|
+
|
594
|
+
private
|
595
|
+
#
|
596
|
+
# Adds telemetry information.
|
597
|
+
#
|
598
|
+
def add_telemetry
|
599
|
+
sdk_information = 'azure_cognitiveservices_textanalytics'
|
600
|
+
sdk_information = "#{sdk_information}/0.17.1"
|
601
|
+
add_user_agent_information(sdk_information)
|
602
|
+
end
|
603
|
+
end
|
604
|
+
end
|