azure_cognitiveservices_textanalytics 0.17.2 → 0.17.3

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.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/lib/azure_cognitiveservices_textanalytics.rb +1 -0
  3. data/lib/profiles/latest/modules/textanalytics_profile_module.rb +60 -52
  4. data/lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb +1 -1
  5. data/lib/v2.1-preview/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb +1 -1
  6. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics.rb +47 -0
  7. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/detected_language.rb +72 -0
  8. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/document_statistics.rb +58 -0
  9. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/entities_batch_result.rb +93 -0
  10. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/entities_batch_result_item.rb +82 -0
  11. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/entity_record.rb +138 -0
  12. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/error_record.rb +58 -0
  13. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/error_response.rb +81 -0
  14. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/internal_error.rb +70 -0
  15. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/key_phrase_batch_result.rb +93 -0
  16. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/key_phrase_batch_result_item.rb +83 -0
  17. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/language_batch_input.rb +56 -0
  18. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/language_batch_result.rb +93 -0
  19. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/language_batch_result_item.rb +81 -0
  20. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/language_input.rb +69 -0
  21. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/match_record.rb +97 -0
  22. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/multi_language_batch_input.rb +56 -0
  23. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/multi_language_input.rb +70 -0
  24. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/request_statistics.rb +82 -0
  25. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/sentiment_batch_result.rb +93 -0
  26. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/models/sentiment_batch_result_item.rb +75 -0
  27. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/module_definition.rb +9 -0
  28. data/lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb +614 -0
  29. data/lib/version.rb +1 -1
  30. metadata +24 -1
@@ -0,0 +1,56 @@
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
7
+ module Models
8
+ #
9
+ # Model object.
10
+ #
11
+ #
12
+ class MultiLanguageBatchInput
13
+
14
+ include MsRestAzure
15
+
16
+ # @return [Array<MultiLanguageInput>]
17
+ attr_accessor :documents
18
+
19
+
20
+ #
21
+ # Mapper for MultiLanguageBatchInput class as Ruby Hash.
22
+ # This will be used for serialization/deserialization.
23
+ #
24
+ def self.mapper()
25
+ {
26
+ client_side_validation: true,
27
+ required: false,
28
+ serialized_name: 'MultiLanguageBatchInput',
29
+ type: {
30
+ name: 'Composite',
31
+ class_name: 'MultiLanguageBatchInput',
32
+ model_properties: {
33
+ documents: {
34
+ client_side_validation: true,
35
+ required: false,
36
+ serialized_name: 'documents',
37
+ type: {
38
+ name: 'Sequence',
39
+ element: {
40
+ client_side_validation: true,
41
+ required: false,
42
+ serialized_name: 'MultiLanguageInputElementType',
43
+ type: {
44
+ name: 'Composite',
45
+ class_name: 'MultiLanguageInput'
46
+ }
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ }
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,70 @@
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
7
+ module Models
8
+ #
9
+ # Model object.
10
+ #
11
+ #
12
+ class MultiLanguageInput
13
+
14
+ include MsRestAzure
15
+
16
+ # @return [String] This is the 2 letter ISO 639-1 representation of a
17
+ # language. For example, use "en" for English; "es" for Spanish etc.,
18
+ attr_accessor :language
19
+
20
+ # @return [String] Unique, non-empty document identifier.
21
+ attr_accessor :id
22
+
23
+ # @return [String]
24
+ attr_accessor :text
25
+
26
+
27
+ #
28
+ # Mapper for MultiLanguageInput class as Ruby Hash.
29
+ # This will be used for serialization/deserialization.
30
+ #
31
+ def self.mapper()
32
+ {
33
+ client_side_validation: true,
34
+ required: false,
35
+ serialized_name: 'MultiLanguageInput',
36
+ type: {
37
+ name: 'Composite',
38
+ class_name: 'MultiLanguageInput',
39
+ model_properties: {
40
+ language: {
41
+ client_side_validation: true,
42
+ required: false,
43
+ serialized_name: 'language',
44
+ type: {
45
+ name: 'String'
46
+ }
47
+ },
48
+ id: {
49
+ client_side_validation: true,
50
+ required: false,
51
+ serialized_name: 'id',
52
+ type: {
53
+ name: 'String'
54
+ }
55
+ },
56
+ text: {
57
+ client_side_validation: true,
58
+ required: false,
59
+ serialized_name: 'text',
60
+ type: {
61
+ name: 'String'
62
+ }
63
+ }
64
+ }
65
+ }
66
+ }
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,82 @@
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
7
+ module Models
8
+ #
9
+ # Model object.
10
+ #
11
+ #
12
+ class RequestStatistics
13
+
14
+ include MsRestAzure
15
+
16
+ # @return [Integer] Number of documents submitted in the request.
17
+ attr_accessor :documents_count
18
+
19
+ # @return [Integer] Number of valid documents. This excludes empty,
20
+ # over-size limit or non-supported languages documents.
21
+ attr_accessor :valid_documents_count
22
+
23
+ # @return [Integer] Number of invalid documents. This includes empty,
24
+ # over-size limit or non-supported languages documents.
25
+ attr_accessor :erroneous_documents_count
26
+
27
+ # @return [Integer] Number of transactions for the request.
28
+ attr_accessor :transactions_count
29
+
30
+
31
+ #
32
+ # Mapper for RequestStatistics class as Ruby Hash.
33
+ # This will be used for serialization/deserialization.
34
+ #
35
+ def self.mapper()
36
+ {
37
+ client_side_validation: true,
38
+ required: false,
39
+ serialized_name: 'RequestStatistics',
40
+ type: {
41
+ name: 'Composite',
42
+ class_name: 'RequestStatistics',
43
+ model_properties: {
44
+ documents_count: {
45
+ client_side_validation: true,
46
+ required: false,
47
+ serialized_name: 'documentsCount',
48
+ type: {
49
+ name: 'Number'
50
+ }
51
+ },
52
+ valid_documents_count: {
53
+ client_side_validation: true,
54
+ required: false,
55
+ serialized_name: 'validDocumentsCount',
56
+ type: {
57
+ name: 'Number'
58
+ }
59
+ },
60
+ erroneous_documents_count: {
61
+ client_side_validation: true,
62
+ required: false,
63
+ serialized_name: 'erroneousDocumentsCount',
64
+ type: {
65
+ name: 'Number'
66
+ }
67
+ },
68
+ transactions_count: {
69
+ client_side_validation: true,
70
+ required: false,
71
+ serialized_name: 'transactionsCount',
72
+ type: {
73
+ name: 'Number'
74
+ }
75
+ }
76
+ }
77
+ }
78
+ }
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,93 @@
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
7
+ module Models
8
+ #
9
+ # Model object.
10
+ #
11
+ #
12
+ class SentimentBatchResult
13
+
14
+ include MsRestAzure
15
+
16
+ # @return [Array<SentimentBatchResultItem>] Response by document
17
+ attr_accessor :documents
18
+
19
+ # @return [Array<ErrorRecord>] Errors and Warnings by document
20
+ attr_accessor :errors
21
+
22
+ # @return [RequestStatistics] (Optional) if showStats=true was specified
23
+ # in the request this field will contain information about the request
24
+ # payload.
25
+ attr_accessor :statistics
26
+
27
+
28
+ #
29
+ # Mapper for SentimentBatchResult class as Ruby Hash.
30
+ # This will be used for serialization/deserialization.
31
+ #
32
+ def self.mapper()
33
+ {
34
+ client_side_validation: true,
35
+ required: false,
36
+ serialized_name: 'SentimentBatchResult',
37
+ type: {
38
+ name: 'Composite',
39
+ class_name: 'SentimentBatchResult',
40
+ model_properties: {
41
+ documents: {
42
+ client_side_validation: true,
43
+ required: false,
44
+ read_only: true,
45
+ serialized_name: 'documents',
46
+ type: {
47
+ name: 'Sequence',
48
+ element: {
49
+ client_side_validation: true,
50
+ required: false,
51
+ serialized_name: 'SentimentBatchResultItemElementType',
52
+ type: {
53
+ name: 'Composite',
54
+ class_name: 'SentimentBatchResultItem'
55
+ }
56
+ }
57
+ }
58
+ },
59
+ errors: {
60
+ client_side_validation: true,
61
+ required: false,
62
+ read_only: true,
63
+ serialized_name: 'errors',
64
+ type: {
65
+ name: 'Sequence',
66
+ element: {
67
+ client_side_validation: true,
68
+ required: false,
69
+ serialized_name: 'ErrorRecordElementType',
70
+ type: {
71
+ name: 'Composite',
72
+ class_name: 'ErrorRecord'
73
+ }
74
+ }
75
+ }
76
+ },
77
+ statistics: {
78
+ client_side_validation: true,
79
+ required: false,
80
+ read_only: true,
81
+ serialized_name: 'statistics',
82
+ type: {
83
+ name: 'Composite',
84
+ class_name: 'RequestStatistics'
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,75 @@
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
7
+ module Models
8
+ #
9
+ # Model object.
10
+ #
11
+ #
12
+ class SentimentBatchResultItem
13
+
14
+ include MsRestAzure
15
+
16
+ # @return [String] Unique, non-empty document identifier.
17
+ attr_accessor :id
18
+
19
+ # @return [Float] A decimal number between 0 and 1 denoting the sentiment
20
+ # of the document. A score above 0.7 usually refers to a positive
21
+ # document while a score below 0.3 normally has a negative connotation.
22
+ # Mid values refer to neutral text.
23
+ attr_accessor :score
24
+
25
+ # @return [DocumentStatistics] (Optional) if showStats=true was specified
26
+ # in the request this field will contain information about the document
27
+ # payload.
28
+ attr_accessor :statistics
29
+
30
+
31
+ #
32
+ # Mapper for SentimentBatchResultItem class as Ruby Hash.
33
+ # This will be used for serialization/deserialization.
34
+ #
35
+ def self.mapper()
36
+ {
37
+ client_side_validation: true,
38
+ required: false,
39
+ serialized_name: 'SentimentBatchResultItem',
40
+ type: {
41
+ name: 'Composite',
42
+ class_name: 'SentimentBatchResultItem',
43
+ model_properties: {
44
+ id: {
45
+ client_side_validation: true,
46
+ required: false,
47
+ serialized_name: 'id',
48
+ type: {
49
+ name: 'String'
50
+ }
51
+ },
52
+ score: {
53
+ client_side_validation: true,
54
+ required: false,
55
+ serialized_name: 'score',
56
+ type: {
57
+ name: 'Double'
58
+ }
59
+ },
60
+ statistics: {
61
+ client_side_validation: true,
62
+ required: false,
63
+ serialized_name: 'statistics',
64
+ type: {
65
+ name: 'Composite',
66
+ class_name: 'DocumentStatistics'
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ end
73
+ end
74
+ end
75
+ 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 end
@@ -0,0 +1,614 @@
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
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'
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 the detected language and a numeric score between 0 and 1.
118
+ #
119
+ # Scores close to 1 indicate 100% certainty that the identified language is
120
+ # true. A total of 120 languages are supported.
121
+ #
122
+ # @param show_stats [Boolean] (optional) if set to true, response will contain
123
+ # input and document level statistics.
124
+ # @param language_batch_input [LanguageBatchInput] Collection of documents to
125
+ # analyze.
126
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
127
+ # will be added to the HTTP request.
128
+ #
129
+ # @return [LanguageBatchResult] operation results.
130
+ #
131
+ def detect_language(show_stats:nil, language_batch_input:nil, custom_headers:nil)
132
+ response = detect_language_async(show_stats:show_stats, language_batch_input:language_batch_input, custom_headers:custom_headers).value!
133
+ response.body unless response.nil?
134
+ end
135
+
136
+ #
137
+ # The API returns the detected language and a numeric score between 0 and 1.
138
+ #
139
+ # Scores close to 1 indicate 100% certainty that the identified language is
140
+ # true. A total of 120 languages are supported.
141
+ #
142
+ # @param show_stats [Boolean] (optional) if set to true, response will contain
143
+ # input and document level statistics.
144
+ # @param language_batch_input [LanguageBatchInput] Collection of documents to
145
+ # analyze.
146
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
147
+ # will be added to the HTTP request.
148
+ #
149
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
150
+ #
151
+ def detect_language_with_http_info(show_stats:nil, language_batch_input:nil, custom_headers:nil)
152
+ detect_language_async(show_stats:show_stats, language_batch_input:language_batch_input, custom_headers:custom_headers).value!
153
+ end
154
+
155
+ #
156
+ # The API returns the detected language and a numeric score between 0 and 1.
157
+ #
158
+ # Scores close to 1 indicate 100% certainty that the identified language is
159
+ # true. A total of 120 languages are supported.
160
+ #
161
+ # @param show_stats [Boolean] (optional) if set to true, response will contain
162
+ # input and document level statistics.
163
+ # @param language_batch_input [LanguageBatchInput] Collection of documents to
164
+ # analyze.
165
+ # @param [Hash{String => String}] A hash of custom headers that will be added
166
+ # to the HTTP request.
167
+ #
168
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
169
+ #
170
+ def detect_language_async(show_stats:nil, language_batch_input:nil, custom_headers:nil)
171
+ fail ArgumentError, 'endpoint is nil' if endpoint.nil?
172
+
173
+
174
+ request_headers = {}
175
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
176
+
177
+ # Set Headers
178
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
179
+ request_headers['accept-language'] = accept_language unless accept_language.nil?
180
+
181
+ # Serialize Request
182
+ request_mapper = Azure::CognitiveServices::TextAnalytics::V2_1::Models::LanguageBatchInput.mapper()
183
+ request_content = self.serialize(request_mapper, language_batch_input)
184
+ request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
185
+
186
+ path_template = 'languages'
187
+
188
+ request_url = @base_url || self.base_url
189
+ request_url = request_url.gsub('{Endpoint}', endpoint)
190
+
191
+ options = {
192
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
193
+ query_params: {'showStats' => show_stats},
194
+ body: request_content,
195
+ headers: request_headers.merge(custom_headers || {}),
196
+ base_url: request_url
197
+ }
198
+ promise = self.make_request_async(:post, path_template, options)
199
+
200
+ promise = promise.then do |result|
201
+ http_response = result.response
202
+ status_code = http_response.status
203
+ response_content = http_response.body
204
+ unless status_code == 200
205
+ error_model = JSON.load(response_content)
206
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
207
+ end
208
+
209
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
210
+ # Deserialize Response
211
+ if status_code == 200
212
+ begin
213
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
214
+ result_mapper = Azure::CognitiveServices::TextAnalytics::V2_1::Models::LanguageBatchResult.mapper()
215
+ result.body = self.deserialize(result_mapper, parsed_response)
216
+ rescue Exception => e
217
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
218
+ end
219
+ end
220
+
221
+ result
222
+ end
223
+
224
+ promise.execute
225
+ end
226
+
227
+ #
228
+ # The API returns a list of recognized entities in a given document.
229
+ #
230
+ # To get even more information on each recognized entity we recommend using the
231
+ # Bing Entity Search API by querying for the recognized entities names. See the
232
+ # <a
233
+ # href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported-languages">Supported
234
+ # languages in Text Analytics API</a> for the list of enabled languages.
235
+ #
236
+ # @param show_stats [Boolean] (optional) if set to true, response will contain
237
+ # input and document level statistics.
238
+ # @param multi_language_batch_input [MultiLanguageBatchInput] Collection of
239
+ # documents to analyze.
240
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
241
+ # will be added to the HTTP request.
242
+ #
243
+ # @return [EntitiesBatchResult] operation results.
244
+ #
245
+ def entities(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
246
+ response = entities_async(show_stats:show_stats, multi_language_batch_input:multi_language_batch_input, custom_headers:custom_headers).value!
247
+ response.body unless response.nil?
248
+ end
249
+
250
+ #
251
+ # The API returns a list of recognized entities in a given document.
252
+ #
253
+ # To get even more information on each recognized entity we recommend using the
254
+ # Bing Entity Search API by querying for the recognized entities names. See the
255
+ # <a
256
+ # href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported-languages">Supported
257
+ # languages in Text Analytics API</a> for the list of enabled languages.
258
+ #
259
+ # @param show_stats [Boolean] (optional) if set to true, response will contain
260
+ # input and document level statistics.
261
+ # @param multi_language_batch_input [MultiLanguageBatchInput] Collection of
262
+ # documents to analyze.
263
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
264
+ # will be added to the HTTP request.
265
+ #
266
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
267
+ #
268
+ def entities_with_http_info(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
269
+ entities_async(show_stats:show_stats, multi_language_batch_input:multi_language_batch_input, custom_headers:custom_headers).value!
270
+ end
271
+
272
+ #
273
+ # The API returns a list of recognized entities in a given document.
274
+ #
275
+ # To get even more information on each recognized entity we recommend using the
276
+ # Bing Entity Search API by querying for the recognized entities names. See the
277
+ # <a
278
+ # href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported-languages">Supported
279
+ # languages in Text Analytics API</a> for the list of enabled languages.
280
+ #
281
+ # @param show_stats [Boolean] (optional) if set to true, response will contain
282
+ # input and document level statistics.
283
+ # @param multi_language_batch_input [MultiLanguageBatchInput] Collection of
284
+ # documents to analyze.
285
+ # @param [Hash{String => String}] A hash of custom headers that will be added
286
+ # to the HTTP request.
287
+ #
288
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
289
+ #
290
+ def entities_async(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
291
+ fail ArgumentError, 'endpoint is nil' if endpoint.nil?
292
+
293
+
294
+ request_headers = {}
295
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
296
+
297
+ # Set Headers
298
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
299
+ request_headers['accept-language'] = accept_language unless accept_language.nil?
300
+
301
+ # Serialize Request
302
+ request_mapper = Azure::CognitiveServices::TextAnalytics::V2_1::Models::MultiLanguageBatchInput.mapper()
303
+ request_content = self.serialize(request_mapper, multi_language_batch_input)
304
+ request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
305
+
306
+ path_template = 'entities'
307
+
308
+ request_url = @base_url || self.base_url
309
+ request_url = request_url.gsub('{Endpoint}', endpoint)
310
+
311
+ options = {
312
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
313
+ query_params: {'showStats' => show_stats},
314
+ body: request_content,
315
+ headers: request_headers.merge(custom_headers || {}),
316
+ base_url: request_url
317
+ }
318
+ promise = self.make_request_async(:post, path_template, options)
319
+
320
+ promise = promise.then do |result|
321
+ http_response = result.response
322
+ status_code = http_response.status
323
+ response_content = http_response.body
324
+ unless status_code == 200
325
+ error_model = JSON.load(response_content)
326
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
327
+ end
328
+
329
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
330
+ # Deserialize Response
331
+ if status_code == 200
332
+ begin
333
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
334
+ result_mapper = Azure::CognitiveServices::TextAnalytics::V2_1::Models::EntitiesBatchResult.mapper()
335
+ result.body = self.deserialize(result_mapper, parsed_response)
336
+ rescue Exception => e
337
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
338
+ end
339
+ end
340
+
341
+ result
342
+ end
343
+
344
+ promise.execute
345
+ end
346
+
347
+ #
348
+ # The API returns a list of strings denoting the key talking points in the
349
+ # input text.
350
+ #
351
+ # See the <a
352
+ # href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages">Text
353
+ # Analytics Documentation</a> for details about the languages that are
354
+ # supported by key phrase extraction.
355
+ #
356
+ # @param show_stats [Boolean] (optional) if set to true, response will contain
357
+ # input and document level statistics.
358
+ # @param multi_language_batch_input [MultiLanguageBatchInput] Collection of
359
+ # documents to analyze. Documents can now contain a language field to indicate
360
+ # the text language
361
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
362
+ # will be added to the HTTP request.
363
+ #
364
+ # @return [KeyPhraseBatchResult] operation results.
365
+ #
366
+ def key_phrases(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
367
+ response = key_phrases_async(show_stats:show_stats, multi_language_batch_input:multi_language_batch_input, custom_headers:custom_headers).value!
368
+ response.body unless response.nil?
369
+ end
370
+
371
+ #
372
+ # The API returns a list of strings denoting the key talking points in the
373
+ # input text.
374
+ #
375
+ # See the <a
376
+ # href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages">Text
377
+ # Analytics Documentation</a> for details about the languages that are
378
+ # supported by key phrase extraction.
379
+ #
380
+ # @param show_stats [Boolean] (optional) if set to true, response will contain
381
+ # input and document level statistics.
382
+ # @param multi_language_batch_input [MultiLanguageBatchInput] Collection of
383
+ # documents to analyze. Documents can now contain a language field to indicate
384
+ # the text language
385
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
386
+ # will be added to the HTTP request.
387
+ #
388
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
389
+ #
390
+ def key_phrases_with_http_info(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
391
+ key_phrases_async(show_stats:show_stats, multi_language_batch_input:multi_language_batch_input, custom_headers:custom_headers).value!
392
+ end
393
+
394
+ #
395
+ # The API returns a list of strings denoting the key talking points in the
396
+ # input text.
397
+ #
398
+ # See the <a
399
+ # href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages">Text
400
+ # Analytics Documentation</a> for details about the languages that are
401
+ # supported by key phrase extraction.
402
+ #
403
+ # @param show_stats [Boolean] (optional) if set to true, response will contain
404
+ # input and document level statistics.
405
+ # @param multi_language_batch_input [MultiLanguageBatchInput] Collection of
406
+ # documents to analyze. Documents can now contain a language field to indicate
407
+ # the text language
408
+ # @param [Hash{String => String}] A hash of custom headers that will be added
409
+ # to the HTTP request.
410
+ #
411
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
412
+ #
413
+ def key_phrases_async(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
414
+ fail ArgumentError, 'endpoint is nil' if endpoint.nil?
415
+
416
+
417
+ request_headers = {}
418
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
419
+
420
+ # Set Headers
421
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
422
+ request_headers['accept-language'] = accept_language unless accept_language.nil?
423
+
424
+ # Serialize Request
425
+ request_mapper = Azure::CognitiveServices::TextAnalytics::V2_1::Models::MultiLanguageBatchInput.mapper()
426
+ request_content = self.serialize(request_mapper, multi_language_batch_input)
427
+ request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
428
+
429
+ path_template = 'keyPhrases'
430
+
431
+ request_url = @base_url || self.base_url
432
+ request_url = request_url.gsub('{Endpoint}', endpoint)
433
+
434
+ options = {
435
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
436
+ query_params: {'showStats' => show_stats},
437
+ body: request_content,
438
+ headers: request_headers.merge(custom_headers || {}),
439
+ base_url: request_url
440
+ }
441
+ promise = self.make_request_async(:post, path_template, options)
442
+
443
+ promise = promise.then do |result|
444
+ http_response = result.response
445
+ status_code = http_response.status
446
+ response_content = http_response.body
447
+ unless status_code == 200
448
+ error_model = JSON.load(response_content)
449
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
450
+ end
451
+
452
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
453
+ # Deserialize Response
454
+ if status_code == 200
455
+ begin
456
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
457
+ result_mapper = Azure::CognitiveServices::TextAnalytics::V2_1::Models::KeyPhraseBatchResult.mapper()
458
+ result.body = self.deserialize(result_mapper, parsed_response)
459
+ rescue Exception => e
460
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
461
+ end
462
+ end
463
+
464
+ result
465
+ end
466
+
467
+ promise.execute
468
+ end
469
+
470
+ #
471
+ # The API returns a numeric score between 0 and 1.
472
+ #
473
+ # Scores close to 1 indicate positive sentiment, while scores close to 0
474
+ # indicate negative sentiment. A score of 0.5 indicates the lack of sentiment
475
+ # (e.g. a factoid statement). See the <a
476
+ # href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages">Text
477
+ # Analytics Documentation</a> for details about the languages that are
478
+ # supported by sentiment analysis.
479
+ #
480
+ # @param show_stats [Boolean] (optional) if set to true, response will contain
481
+ # input and document level statistics.
482
+ # @param multi_language_batch_input [MultiLanguageBatchInput] Collection of
483
+ # documents to analyze.
484
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
485
+ # will be added to the HTTP request.
486
+ #
487
+ # @return [Object] operation results.
488
+ #
489
+ def sentiment(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
490
+ response = sentiment_async(show_stats:show_stats, multi_language_batch_input:multi_language_batch_input, custom_headers:custom_headers).value!
491
+ response.body unless response.nil?
492
+ end
493
+
494
+ #
495
+ # The API returns a numeric score between 0 and 1.
496
+ #
497
+ # Scores close to 1 indicate positive sentiment, while scores close to 0
498
+ # indicate negative sentiment. A score of 0.5 indicates the lack of sentiment
499
+ # (e.g. a factoid statement). See the <a
500
+ # href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages">Text
501
+ # Analytics Documentation</a> for details about the languages that are
502
+ # supported by sentiment analysis.
503
+ #
504
+ # @param show_stats [Boolean] (optional) if set to true, response will contain
505
+ # input and document level statistics.
506
+ # @param multi_language_batch_input [MultiLanguageBatchInput] Collection of
507
+ # documents to analyze.
508
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
509
+ # will be added to the HTTP request.
510
+ #
511
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
512
+ #
513
+ def sentiment_with_http_info(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
514
+ sentiment_async(show_stats:show_stats, multi_language_batch_input:multi_language_batch_input, custom_headers:custom_headers).value!
515
+ end
516
+
517
+ #
518
+ # The API returns a numeric score between 0 and 1.
519
+ #
520
+ # Scores close to 1 indicate positive sentiment, while scores close to 0
521
+ # indicate negative sentiment. A score of 0.5 indicates the lack of sentiment
522
+ # (e.g. a factoid statement). See the <a
523
+ # href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages">Text
524
+ # Analytics Documentation</a> for details about the languages that are
525
+ # supported by sentiment analysis.
526
+ #
527
+ # @param show_stats [Boolean] (optional) if set to true, response will contain
528
+ # input and document level statistics.
529
+ # @param multi_language_batch_input [MultiLanguageBatchInput] Collection of
530
+ # 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 sentiment_async(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
537
+ fail ArgumentError, 'endpoint is nil' if endpoint.nil?
538
+
539
+
540
+ request_headers = {}
541
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
542
+
543
+ # Set Headers
544
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
545
+ request_headers['accept-language'] = accept_language unless accept_language.nil?
546
+
547
+ # Serialize Request
548
+ request_mapper = Azure::CognitiveServices::TextAnalytics::V2_1::Models::MultiLanguageBatchInput.mapper()
549
+ request_content = self.serialize(request_mapper, multi_language_batch_input)
550
+ request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
551
+
552
+ path_template = 'sentiment'
553
+
554
+ request_url = @base_url || self.base_url
555
+ request_url = request_url.gsub('{Endpoint}', endpoint)
556
+
557
+ options = {
558
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
559
+ query_params: {'showStats' => show_stats},
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 || status_code == 500
571
+ error_model = JSON.load(response_content)
572
+ fail MsRestAzure::AzureOperationError.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::Models::SentimentBatchResult.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
+ # Deserialize Response
587
+ if status_code == 500
588
+ begin
589
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
590
+ result_mapper = Azure::CognitiveServices::TextAnalytics::V2_1::Models::ErrorResponse.mapper()
591
+ result.body = self.deserialize(result_mapper, parsed_response)
592
+ rescue Exception => e
593
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
594
+ end
595
+ end
596
+
597
+ result
598
+ end
599
+
600
+ promise.execute
601
+ end
602
+
603
+
604
+ private
605
+ #
606
+ # Adds telemetry information.
607
+ #
608
+ def add_telemetry
609
+ sdk_information = 'azure_cognitiveservices_textanalytics'
610
+ sdk_information = "#{sdk_information}/0.17.3"
611
+ add_user_agent_information(sdk_information)
612
+ end
613
+ end
614
+ end