| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | // <auto-generated/> |
| | 5 | |
|
| | 6 | | #nullable disable |
| | 7 | |
|
| | 8 | | using System; |
| | 9 | | using System.Text.Json; |
| | 10 | | using System.Threading; |
| | 11 | | using System.Threading.Tasks; |
| | 12 | | using Azure; |
| | 13 | | using Azure.AI.TextAnalytics.Models; |
| | 14 | | using Azure.Core; |
| | 15 | | using Azure.Core.Pipeline; |
| | 16 | |
|
| | 17 | | namespace Azure.AI.TextAnalytics |
| | 18 | | { |
| | 19 | | internal partial class ServiceRestClient |
| | 20 | | { |
| | 21 | | private string endpoint; |
| | 22 | | private ClientDiagnostics _clientDiagnostics; |
| | 23 | | private HttpPipeline _pipeline; |
| | 24 | |
|
| | 25 | | /// <summary> Initializes a new instance of ServiceRestClient. </summary> |
| | 26 | | /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> |
| | 27 | | /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> |
| | 28 | | /// <param name="endpoint"> Supported Cognitive Services endpoints (protocol and hostname, for example: https:// |
| | 29 | | /// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> is null. </exception> |
| 180 | 30 | | public ServiceRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, string endpoint) |
| | 31 | | { |
| 180 | 32 | | if (endpoint == null) |
| | 33 | | { |
| 0 | 34 | | throw new ArgumentNullException(nameof(endpoint)); |
| | 35 | | } |
| | 36 | |
|
| 180 | 37 | | this.endpoint = endpoint; |
| 180 | 38 | | _clientDiagnostics = clientDiagnostics; |
| 180 | 39 | | _pipeline = pipeline; |
| 180 | 40 | | } |
| | 41 | |
|
| | 42 | | internal HttpMessage CreateEntitiesRecognitionGeneralRequest(MultiLanguageBatchInput input, string modelVersion, |
| | 43 | | { |
| 0 | 44 | | var message = _pipeline.CreateMessage(); |
| 0 | 45 | | var request = message.Request; |
| 0 | 46 | | request.Method = RequestMethod.Post; |
| 0 | 47 | | var uri = new RawRequestUriBuilder(); |
| 0 | 48 | | uri.AppendRaw(endpoint, false); |
| 0 | 49 | | uri.AppendRaw("/text/analytics/v3.1-preview.1", false); |
| 0 | 50 | | uri.AppendPath("/entities/recognition/general", false); |
| 0 | 51 | | if (modelVersion != null) |
| | 52 | | { |
| 0 | 53 | | uri.AppendQuery("model-version", modelVersion, true); |
| | 54 | | } |
| 0 | 55 | | if (showStats != null) |
| | 56 | | { |
| 0 | 57 | | uri.AppendQuery("showStats", showStats.Value, true); |
| | 58 | | } |
| 0 | 59 | | request.Uri = uri; |
| 0 | 60 | | request.Headers.Add("Content-Type", "application/json"); |
| 0 | 61 | | var content = new Utf8JsonRequestContent(); |
| 0 | 62 | | content.JsonWriter.WriteObjectValue(input); |
| 0 | 63 | | request.Content = content; |
| 0 | 64 | | return message; |
| | 65 | | } |
| | 66 | |
|
| | 67 | | /// <summary> The API returns a list of general named entities in a given document. For the list of supported en |
| | 68 | | /// <param name="input"> Collection of documents to analyze. </param> |
| | 69 | | /// <param name="modelVersion"> (Optional) This value indicates which model will be used for scoring. If a model |
| | 70 | | /// <param name="showStats"> (Optional) if set to true, response will contain input and document level statistic |
| | 71 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 72 | | /// <exception cref="ArgumentNullException"> <paramref name="input"/> is null. </exception> |
| | 73 | | public async Task<Response<EntitiesResult>> EntitiesRecognitionGeneralAsync(MultiLanguageBatchInput input, strin |
| | 74 | | { |
| 0 | 75 | | if (input == null) |
| | 76 | | { |
| 0 | 77 | | throw new ArgumentNullException(nameof(input)); |
| | 78 | | } |
| | 79 | |
|
| 0 | 80 | | using var message = CreateEntitiesRecognitionGeneralRequest(input, modelVersion, showStats); |
| 0 | 81 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 82 | | switch (message.Response.Status) |
| | 83 | | { |
| | 84 | | case 200: |
| | 85 | | { |
| | 86 | | EntitiesResult value = default; |
| 0 | 87 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 88 | | value = EntitiesResult.DeserializeEntitiesResult(document.RootElement); |
| 0 | 89 | | return Response.FromValue(value, message.Response); |
| | 90 | | } |
| | 91 | | default: |
| 0 | 92 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 93 | | } |
| 0 | 94 | | } |
| | 95 | |
|
| | 96 | | /// <summary> The API returns a list of general named entities in a given document. For the list of supported en |
| | 97 | | /// <param name="input"> Collection of documents to analyze. </param> |
| | 98 | | /// <param name="modelVersion"> (Optional) This value indicates which model will be used for scoring. If a model |
| | 99 | | /// <param name="showStats"> (Optional) if set to true, response will contain input and document level statistic |
| | 100 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 101 | | /// <exception cref="ArgumentNullException"> <paramref name="input"/> is null. </exception> |
| | 102 | | public Response<EntitiesResult> EntitiesRecognitionGeneral(MultiLanguageBatchInput input, string modelVersion = |
| | 103 | | { |
| 0 | 104 | | if (input == null) |
| | 105 | | { |
| 0 | 106 | | throw new ArgumentNullException(nameof(input)); |
| | 107 | | } |
| | 108 | |
|
| 0 | 109 | | using var message = CreateEntitiesRecognitionGeneralRequest(input, modelVersion, showStats); |
| 0 | 110 | | _pipeline.Send(message, cancellationToken); |
| 0 | 111 | | switch (message.Response.Status) |
| | 112 | | { |
| | 113 | | case 200: |
| | 114 | | { |
| | 115 | | EntitiesResult value = default; |
| 0 | 116 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 117 | | value = EntitiesResult.DeserializeEntitiesResult(document.RootElement); |
| 0 | 118 | | return Response.FromValue(value, message.Response); |
| | 119 | | } |
| | 120 | | default: |
| 0 | 121 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 122 | | } |
| 0 | 123 | | } |
| | 124 | |
|
| | 125 | | internal HttpMessage CreateEntitiesRecognitionPiiRequest(MultiLanguageBatchInput input, string modelVersion, boo |
| | 126 | | { |
| 0 | 127 | | var message = _pipeline.CreateMessage(); |
| 0 | 128 | | var request = message.Request; |
| 0 | 129 | | request.Method = RequestMethod.Post; |
| 0 | 130 | | var uri = new RawRequestUriBuilder(); |
| 0 | 131 | | uri.AppendRaw(endpoint, false); |
| 0 | 132 | | uri.AppendRaw("/text/analytics/v3.1-preview.1", false); |
| 0 | 133 | | uri.AppendPath("/entities/recognition/pii", false); |
| 0 | 134 | | if (modelVersion != null) |
| | 135 | | { |
| 0 | 136 | | uri.AppendQuery("model-version", modelVersion, true); |
| | 137 | | } |
| 0 | 138 | | if (showStats != null) |
| | 139 | | { |
| 0 | 140 | | uri.AppendQuery("showStats", showStats.Value, true); |
| | 141 | | } |
| 0 | 142 | | if (domain != null) |
| | 143 | | { |
| 0 | 144 | | uri.AppendQuery("domain", domain, true); |
| | 145 | | } |
| 0 | 146 | | request.Uri = uri; |
| 0 | 147 | | request.Headers.Add("Content-Type", "application/json"); |
| 0 | 148 | | var content = new Utf8JsonRequestContent(); |
| 0 | 149 | | content.JsonWriter.WriteObjectValue(input); |
| 0 | 150 | | request.Content = content; |
| 0 | 151 | | return message; |
| | 152 | | } |
| | 153 | |
|
| | 154 | | /// <summary> |
| | 155 | | /// The API returns a list of entities with personal information (\"SSN\", \"Bank Account\" |
| | 156 | | /// . |
| | 157 | | /// </summary> |
| | 158 | | /// <param name="input"> Collection of documents to analyze. </param> |
| | 159 | | /// <param name="modelVersion"> (Optional) This value indicates which model will be used for scoring. If a model |
| | 160 | | /// <param name="showStats"> (Optional) if set to true, response will contain input and document level statistic |
| | 161 | | /// <param name="domain"> (Optional) if set to 'PHI', response will contain only PHI entities. </param |
| | 162 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 163 | | /// <exception cref="ArgumentNullException"> <paramref name="input"/> is null. </exception> |
| | 164 | | public async Task<Response<EntitiesResult>> EntitiesRecognitionPiiAsync(MultiLanguageBatchInput input, string mo |
| | 165 | | { |
| 0 | 166 | | if (input == null) |
| | 167 | | { |
| 0 | 168 | | throw new ArgumentNullException(nameof(input)); |
| | 169 | | } |
| | 170 | |
|
| 0 | 171 | | using var message = CreateEntitiesRecognitionPiiRequest(input, modelVersion, showStats, domain); |
| 0 | 172 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 173 | | switch (message.Response.Status) |
| | 174 | | { |
| | 175 | | case 200: |
| | 176 | | { |
| | 177 | | EntitiesResult value = default; |
| 0 | 178 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 179 | | value = EntitiesResult.DeserializeEntitiesResult(document.RootElement); |
| 0 | 180 | | return Response.FromValue(value, message.Response); |
| | 181 | | } |
| | 182 | | default: |
| 0 | 183 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 184 | | } |
| 0 | 185 | | } |
| | 186 | |
|
| | 187 | | /// <summary> |
| | 188 | | /// The API returns a list of entities with personal information (\"SSN\", \"Bank Account\" |
| | 189 | | /// . |
| | 190 | | /// </summary> |
| | 191 | | /// <param name="input"> Collection of documents to analyze. </param> |
| | 192 | | /// <param name="modelVersion"> (Optional) This value indicates which model will be used for scoring. If a model |
| | 193 | | /// <param name="showStats"> (Optional) if set to true, response will contain input and document level statistic |
| | 194 | | /// <param name="domain"> (Optional) if set to 'PHI', response will contain only PHI entities. </param |
| | 195 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 196 | | /// <exception cref="ArgumentNullException"> <paramref name="input"/> is null. </exception> |
| | 197 | | public Response<EntitiesResult> EntitiesRecognitionPii(MultiLanguageBatchInput input, string modelVersion = null |
| | 198 | | { |
| 0 | 199 | | if (input == null) |
| | 200 | | { |
| 0 | 201 | | throw new ArgumentNullException(nameof(input)); |
| | 202 | | } |
| | 203 | |
|
| 0 | 204 | | using var message = CreateEntitiesRecognitionPiiRequest(input, modelVersion, showStats, domain); |
| 0 | 205 | | _pipeline.Send(message, cancellationToken); |
| 0 | 206 | | switch (message.Response.Status) |
| | 207 | | { |
| | 208 | | case 200: |
| | 209 | | { |
| | 210 | | EntitiesResult value = default; |
| 0 | 211 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 212 | | value = EntitiesResult.DeserializeEntitiesResult(document.RootElement); |
| 0 | 213 | | return Response.FromValue(value, message.Response); |
| | 214 | | } |
| | 215 | | default: |
| 0 | 216 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 217 | | } |
| 0 | 218 | | } |
| | 219 | |
|
| | 220 | | internal HttpMessage CreateEntitiesLinkingRequest(MultiLanguageBatchInput input, string modelVersion, bool? show |
| | 221 | | { |
| 0 | 222 | | var message = _pipeline.CreateMessage(); |
| 0 | 223 | | var request = message.Request; |
| 0 | 224 | | request.Method = RequestMethod.Post; |
| 0 | 225 | | var uri = new RawRequestUriBuilder(); |
| 0 | 226 | | uri.AppendRaw(endpoint, false); |
| 0 | 227 | | uri.AppendRaw("/text/analytics/v3.1-preview.1", false); |
| 0 | 228 | | uri.AppendPath("/entities/linking", false); |
| 0 | 229 | | if (modelVersion != null) |
| | 230 | | { |
| 0 | 231 | | uri.AppendQuery("model-version", modelVersion, true); |
| | 232 | | } |
| 0 | 233 | | if (showStats != null) |
| | 234 | | { |
| 0 | 235 | | uri.AppendQuery("showStats", showStats.Value, true); |
| | 236 | | } |
| 0 | 237 | | request.Uri = uri; |
| 0 | 238 | | request.Headers.Add("Content-Type", "application/json"); |
| 0 | 239 | | var content = new Utf8JsonRequestContent(); |
| 0 | 240 | | content.JsonWriter.WriteObjectValue(input); |
| 0 | 241 | | request.Content = content; |
| 0 | 242 | | return message; |
| | 243 | | } |
| | 244 | |
|
| | 245 | | /// <summary> The API returns a list of recognized entities with links to a well-known knowledge base. See the & |
| | 246 | | /// <param name="input"> Collection of documents to analyze. </param> |
| | 247 | | /// <param name="modelVersion"> (Optional) This value indicates which model will be used for scoring. If a model |
| | 248 | | /// <param name="showStats"> (Optional) if set to true, response will contain input and document level statistic |
| | 249 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 250 | | /// <exception cref="ArgumentNullException"> <paramref name="input"/> is null. </exception> |
| | 251 | | public async Task<Response<EntityLinkingResult>> EntitiesLinkingAsync(MultiLanguageBatchInput input, string mode |
| | 252 | | { |
| 0 | 253 | | if (input == null) |
| | 254 | | { |
| 0 | 255 | | throw new ArgumentNullException(nameof(input)); |
| | 256 | | } |
| | 257 | |
|
| 0 | 258 | | using var message = CreateEntitiesLinkingRequest(input, modelVersion, showStats); |
| 0 | 259 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 260 | | switch (message.Response.Status) |
| | 261 | | { |
| | 262 | | case 200: |
| | 263 | | { |
| | 264 | | EntityLinkingResult value = default; |
| 0 | 265 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 266 | | value = EntityLinkingResult.DeserializeEntityLinkingResult(document.RootElement); |
| 0 | 267 | | return Response.FromValue(value, message.Response); |
| | 268 | | } |
| | 269 | | default: |
| 0 | 270 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 271 | | } |
| 0 | 272 | | } |
| | 273 | |
|
| | 274 | | /// <summary> The API returns a list of recognized entities with links to a well-known knowledge base. See the & |
| | 275 | | /// <param name="input"> Collection of documents to analyze. </param> |
| | 276 | | /// <param name="modelVersion"> (Optional) This value indicates which model will be used for scoring. If a model |
| | 277 | | /// <param name="showStats"> (Optional) if set to true, response will contain input and document level statistic |
| | 278 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 279 | | /// <exception cref="ArgumentNullException"> <paramref name="input"/> is null. </exception> |
| | 280 | | public Response<EntityLinkingResult> EntitiesLinking(MultiLanguageBatchInput input, string modelVersion = null, |
| | 281 | | { |
| 0 | 282 | | if (input == null) |
| | 283 | | { |
| 0 | 284 | | throw new ArgumentNullException(nameof(input)); |
| | 285 | | } |
| | 286 | |
|
| 0 | 287 | | using var message = CreateEntitiesLinkingRequest(input, modelVersion, showStats); |
| 0 | 288 | | _pipeline.Send(message, cancellationToken); |
| 0 | 289 | | switch (message.Response.Status) |
| | 290 | | { |
| | 291 | | case 200: |
| | 292 | | { |
| | 293 | | EntityLinkingResult value = default; |
| 0 | 294 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 295 | | value = EntityLinkingResult.DeserializeEntityLinkingResult(document.RootElement); |
| 0 | 296 | | return Response.FromValue(value, message.Response); |
| | 297 | | } |
| | 298 | | default: |
| 0 | 299 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 300 | | } |
| 0 | 301 | | } |
| | 302 | |
|
| | 303 | | internal HttpMessage CreateKeyPhrasesRequest(MultiLanguageBatchInput input, string modelVersion, bool? showStats |
| | 304 | | { |
| 0 | 305 | | var message = _pipeline.CreateMessage(); |
| 0 | 306 | | var request = message.Request; |
| 0 | 307 | | request.Method = RequestMethod.Post; |
| 0 | 308 | | var uri = new RawRequestUriBuilder(); |
| 0 | 309 | | uri.AppendRaw(endpoint, false); |
| 0 | 310 | | uri.AppendRaw("/text/analytics/v3.1-preview.1", false); |
| 0 | 311 | | uri.AppendPath("/keyPhrases", false); |
| 0 | 312 | | if (modelVersion != null) |
| | 313 | | { |
| 0 | 314 | | uri.AppendQuery("model-version", modelVersion, true); |
| | 315 | | } |
| 0 | 316 | | if (showStats != null) |
| | 317 | | { |
| 0 | 318 | | uri.AppendQuery("showStats", showStats.Value, true); |
| | 319 | | } |
| 0 | 320 | | request.Uri = uri; |
| 0 | 321 | | request.Headers.Add("Content-Type", "application/json"); |
| 0 | 322 | | var content = new Utf8JsonRequestContent(); |
| 0 | 323 | | content.JsonWriter.WriteObjectValue(input); |
| 0 | 324 | | request.Content = content; |
| 0 | 325 | | return message; |
| | 326 | | } |
| | 327 | |
|
| | 328 | | /// <summary> The API returns a list of strings denoting the key phrases in the input text. See the <a href=& |
| | 329 | | /// <param name="input"> Collection of documents to analyze. Documents can now contain a language field to indic |
| | 330 | | /// <param name="modelVersion"> (Optional) This value indicates which model will be used for scoring. If a model |
| | 331 | | /// <param name="showStats"> (Optional) if set to true, response will contain input and document level statistic |
| | 332 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 333 | | /// <exception cref="ArgumentNullException"> <paramref name="input"/> is null. </exception> |
| | 334 | | public async Task<Response<KeyPhraseResult>> KeyPhrasesAsync(MultiLanguageBatchInput input, string modelVersion |
| | 335 | | { |
| 0 | 336 | | if (input == null) |
| | 337 | | { |
| 0 | 338 | | throw new ArgumentNullException(nameof(input)); |
| | 339 | | } |
| | 340 | |
|
| 0 | 341 | | using var message = CreateKeyPhrasesRequest(input, modelVersion, showStats); |
| 0 | 342 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 343 | | switch (message.Response.Status) |
| | 344 | | { |
| | 345 | | case 200: |
| | 346 | | { |
| | 347 | | KeyPhraseResult value = default; |
| 0 | 348 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 349 | | value = KeyPhraseResult.DeserializeKeyPhraseResult(document.RootElement); |
| 0 | 350 | | return Response.FromValue(value, message.Response); |
| | 351 | | } |
| | 352 | | default: |
| 0 | 353 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 354 | | } |
| 0 | 355 | | } |
| | 356 | |
|
| | 357 | | /// <summary> The API returns a list of strings denoting the key phrases in the input text. See the <a href=& |
| | 358 | | /// <param name="input"> Collection of documents to analyze. Documents can now contain a language field to indic |
| | 359 | | /// <param name="modelVersion"> (Optional) This value indicates which model will be used for scoring. If a model |
| | 360 | | /// <param name="showStats"> (Optional) if set to true, response will contain input and document level statistic |
| | 361 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 362 | | /// <exception cref="ArgumentNullException"> <paramref name="input"/> is null. </exception> |
| | 363 | | public Response<KeyPhraseResult> KeyPhrases(MultiLanguageBatchInput input, string modelVersion = null, bool? sho |
| | 364 | | { |
| 0 | 365 | | if (input == null) |
| | 366 | | { |
| 0 | 367 | | throw new ArgumentNullException(nameof(input)); |
| | 368 | | } |
| | 369 | |
|
| 0 | 370 | | using var message = CreateKeyPhrasesRequest(input, modelVersion, showStats); |
| 0 | 371 | | _pipeline.Send(message, cancellationToken); |
| 0 | 372 | | switch (message.Response.Status) |
| | 373 | | { |
| | 374 | | case 200: |
| | 375 | | { |
| | 376 | | KeyPhraseResult value = default; |
| 0 | 377 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 378 | | value = KeyPhraseResult.DeserializeKeyPhraseResult(document.RootElement); |
| 0 | 379 | | return Response.FromValue(value, message.Response); |
| | 380 | | } |
| | 381 | | default: |
| 0 | 382 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 383 | | } |
| 0 | 384 | | } |
| | 385 | |
|
| | 386 | | internal HttpMessage CreateLanguagesRequest(LanguageBatchInput input, string modelVersion, bool? showStats) |
| | 387 | | { |
| 52 | 388 | | var message = _pipeline.CreateMessage(); |
| 52 | 389 | | var request = message.Request; |
| 52 | 390 | | request.Method = RequestMethod.Post; |
| 52 | 391 | | var uri = new RawRequestUriBuilder(); |
| 52 | 392 | | uri.AppendRaw(endpoint, false); |
| 52 | 393 | | uri.AppendRaw("/text/analytics/v3.1-preview.1", false); |
| 52 | 394 | | uri.AppendPath("/languages", false); |
| 52 | 395 | | if (modelVersion != null) |
| | 396 | | { |
| 16 | 397 | | uri.AppendQuery("model-version", modelVersion, true); |
| | 398 | | } |
| 52 | 399 | | if (showStats != null) |
| | 400 | | { |
| 20 | 401 | | uri.AppendQuery("showStats", showStats.Value, true); |
| | 402 | | } |
| 52 | 403 | | request.Uri = uri; |
| 52 | 404 | | request.Headers.Add("Content-Type", "application/json"); |
| 52 | 405 | | var content = new Utf8JsonRequestContent(); |
| 52 | 406 | | content.JsonWriter.WriteObjectValue(input); |
| 52 | 407 | | request.Content = content; |
| 52 | 408 | | return message; |
| | 409 | | } |
| | 410 | |
|
| | 411 | | /// <summary> The API returns the detected language and a numeric score between 0 and 1. Scores close to 1 indic |
| | 412 | | /// <param name="input"> Collection of documents to analyze. </param> |
| | 413 | | /// <param name="modelVersion"> (Optional) This value indicates which model will be used for scoring. If a model |
| | 414 | | /// <param name="showStats"> (Optional) if set to true, response will contain input and document level statistic |
| | 415 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 416 | | /// <exception cref="ArgumentNullException"> <paramref name="input"/> is null. </exception> |
| | 417 | | public async Task<Response<LanguageResult>> LanguagesAsync(LanguageBatchInput input, string modelVersion = null, |
| | 418 | | { |
| 26 | 419 | | if (input == null) |
| | 420 | | { |
| 0 | 421 | | throw new ArgumentNullException(nameof(input)); |
| | 422 | | } |
| | 423 | |
|
| 26 | 424 | | using var message = CreateLanguagesRequest(input, modelVersion, showStats); |
| 26 | 425 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 26 | 426 | | switch (message.Response.Status) |
| | 427 | | { |
| | 428 | | case 200: |
| | 429 | | { |
| | 430 | | LanguageResult value = default; |
| 24 | 431 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 24 | 432 | | value = LanguageResult.DeserializeLanguageResult(document.RootElement); |
| 24 | 433 | | return Response.FromValue(value, message.Response); |
| | 434 | | } |
| | 435 | | default: |
| 2 | 436 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 437 | | } |
| 24 | 438 | | } |
| | 439 | |
|
| | 440 | | /// <summary> The API returns the detected language and a numeric score between 0 and 1. Scores close to 1 indic |
| | 441 | | /// <param name="input"> Collection of documents to analyze. </param> |
| | 442 | | /// <param name="modelVersion"> (Optional) This value indicates which model will be used for scoring. If a model |
| | 443 | | /// <param name="showStats"> (Optional) if set to true, response will contain input and document level statistic |
| | 444 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 445 | | /// <exception cref="ArgumentNullException"> <paramref name="input"/> is null. </exception> |
| | 446 | | public Response<LanguageResult> Languages(LanguageBatchInput input, string modelVersion = null, bool? showStats |
| | 447 | | { |
| 26 | 448 | | if (input == null) |
| | 449 | | { |
| 0 | 450 | | throw new ArgumentNullException(nameof(input)); |
| | 451 | | } |
| | 452 | |
|
| 26 | 453 | | using var message = CreateLanguagesRequest(input, modelVersion, showStats); |
| 26 | 454 | | _pipeline.Send(message, cancellationToken); |
| 26 | 455 | | switch (message.Response.Status) |
| | 456 | | { |
| | 457 | | case 200: |
| | 458 | | { |
| | 459 | | LanguageResult value = default; |
| 24 | 460 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 24 | 461 | | value = LanguageResult.DeserializeLanguageResult(document.RootElement); |
| 24 | 462 | | return Response.FromValue(value, message.Response); |
| | 463 | | } |
| | 464 | | default: |
| 2 | 465 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 466 | | } |
| 24 | 467 | | } |
| | 468 | |
|
| | 469 | | internal HttpMessage CreateSentimentRequest(MultiLanguageBatchInput input, string modelVersion, bool? showStats, |
| | 470 | | { |
| 0 | 471 | | var message = _pipeline.CreateMessage(); |
| 0 | 472 | | var request = message.Request; |
| 0 | 473 | | request.Method = RequestMethod.Post; |
| 0 | 474 | | var uri = new RawRequestUriBuilder(); |
| 0 | 475 | | uri.AppendRaw(endpoint, false); |
| 0 | 476 | | uri.AppendRaw("/text/analytics/v3.1-preview.1", false); |
| 0 | 477 | | uri.AppendPath("/sentiment", false); |
| 0 | 478 | | if (modelVersion != null) |
| | 479 | | { |
| 0 | 480 | | uri.AppendQuery("model-version", modelVersion, true); |
| | 481 | | } |
| 0 | 482 | | if (showStats != null) |
| | 483 | | { |
| 0 | 484 | | uri.AppendQuery("showStats", showStats.Value, true); |
| | 485 | | } |
| 0 | 486 | | if (opinionMining != null) |
| | 487 | | { |
| 0 | 488 | | uri.AppendQuery("opinionMining", opinionMining.Value, true); |
| | 489 | | } |
| 0 | 490 | | request.Uri = uri; |
| 0 | 491 | | request.Headers.Add("Content-Type", "application/json"); |
| 0 | 492 | | var content = new Utf8JsonRequestContent(); |
| 0 | 493 | | content.JsonWriter.WriteObjectValue(input); |
| 0 | 494 | | request.Content = content; |
| 0 | 495 | | return message; |
| | 496 | | } |
| | 497 | |
|
| | 498 | | /// <summary> The API returns a detailed sentiment analysis for the input text. The analysis is done in multiple |
| | 499 | | /// <param name="input"> Collection of documents to analyze. </param> |
| | 500 | | /// <param name="modelVersion"> (Optional) This value indicates which model will be used for scoring. If a model |
| | 501 | | /// <param name="showStats"> (Optional) if set to true, response will contain input and document level statistic |
| | 502 | | /// <param name="opinionMining"> (Optional) if set to true, response will contain input and document level stati |
| | 503 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 504 | | /// <exception cref="ArgumentNullException"> <paramref name="input"/> is null. </exception> |
| | 505 | | public async Task<Response<SentimentResponse>> SentimentAsync(MultiLanguageBatchInput input, string modelVersion |
| | 506 | | { |
| 0 | 507 | | if (input == null) |
| | 508 | | { |
| 0 | 509 | | throw new ArgumentNullException(nameof(input)); |
| | 510 | | } |
| | 511 | |
|
| 0 | 512 | | using var message = CreateSentimentRequest(input, modelVersion, showStats, opinionMining); |
| 0 | 513 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 514 | | switch (message.Response.Status) |
| | 515 | | { |
| | 516 | | case 200: |
| | 517 | | { |
| | 518 | | SentimentResponse value = default; |
| 0 | 519 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 520 | | value = SentimentResponse.DeserializeSentimentResponse(document.RootElement); |
| 0 | 521 | | return Response.FromValue(value, message.Response); |
| | 522 | | } |
| | 523 | | default: |
| 0 | 524 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 525 | | } |
| 0 | 526 | | } |
| | 527 | |
|
| | 528 | | /// <summary> The API returns a detailed sentiment analysis for the input text. The analysis is done in multiple |
| | 529 | | /// <param name="input"> Collection of documents to analyze. </param> |
| | 530 | | /// <param name="modelVersion"> (Optional) This value indicates which model will be used for scoring. If a model |
| | 531 | | /// <param name="showStats"> (Optional) if set to true, response will contain input and document level statistic |
| | 532 | | /// <param name="opinionMining"> (Optional) if set to true, response will contain input and document level stati |
| | 533 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 534 | | /// <exception cref="ArgumentNullException"> <paramref name="input"/> is null. </exception> |
| | 535 | | public Response<SentimentResponse> Sentiment(MultiLanguageBatchInput input, string modelVersion = null, bool? sh |
| | 536 | | { |
| 0 | 537 | | if (input == null) |
| | 538 | | { |
| 0 | 539 | | throw new ArgumentNullException(nameof(input)); |
| | 540 | | } |
| | 541 | |
|
| 0 | 542 | | using var message = CreateSentimentRequest(input, modelVersion, showStats, opinionMining); |
| 0 | 543 | | _pipeline.Send(message, cancellationToken); |
| 0 | 544 | | switch (message.Response.Status) |
| | 545 | | { |
| | 546 | | case 200: |
| | 547 | | { |
| | 548 | | SentimentResponse value = default; |
| 0 | 549 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 550 | | value = SentimentResponse.DeserializeSentimentResponse(document.RootElement); |
| 0 | 551 | | return Response.FromValue(value, message.Response); |
| | 552 | | } |
| | 553 | | default: |
| 0 | 554 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 555 | | } |
| 0 | 556 | | } |
| | 557 | | } |
| | 558 | | } |