| | 1 | | // |
| | 2 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 3 | | // Licensed under the MIT License. See License.txt in the project root for |
| | 4 | | // license information. |
| | 5 | | // |
| | 6 | |
|
| | 7 | | namespace Microsoft.Azure.CognitiveServices.Language.TextAnalytics |
| | 8 | | { |
| | 9 | | using Models; |
| | 10 | | using System.Collections; |
| | 11 | | using System.Collections.Generic; |
| | 12 | | using System.Threading; |
| | 13 | | using System.Threading.Tasks; |
| | 14 | |
|
| | 15 | | /// <summary> |
| | 16 | | /// Extension methods for TextAnalyticsClient. |
| | 17 | | /// </summary> |
| | 18 | | public static partial class TextAnalyticsClientExtensions |
| | 19 | | { |
| | 20 | | /// <summary> |
| | 21 | | /// The API returns the detected language and a numeric score between 0 and 1. |
| | 22 | | /// </summary> |
| | 23 | | /// <remarks> |
| | 24 | | /// Scores close to 1 indicate 100% certainty that the identified language is |
| | 25 | | /// true. A total of 120 languages are supported. |
| | 26 | | /// </remarks> |
| | 27 | | /// <param name='operations'> |
| | 28 | | /// The operations group for this extension method. |
| | 29 | | /// </param> |
| | 30 | | /// <param name='showStats'> |
| | 31 | | /// (optional) if set to true, response will contain input and document level |
| | 32 | | /// statistics. |
| | 33 | | /// </param> |
| | 34 | | /// <param name='languageBatchInput'> |
| | 35 | | /// Collection of documents to analyze. |
| | 36 | | /// </param> |
| | 37 | | /// <param name='cancellationToken'> |
| | 38 | | /// The cancellation token. |
| | 39 | | /// </param> |
| | 40 | | public static async Task<LanguageBatchResult> DetectLanguageBatchAsync(this ITextAnalyticsClient operations, |
| | 41 | | { |
| 1 | 42 | | using (var _result = await operations.DetectLanguageWithHttpMessagesAsync(showStats, languageBatchInput, |
| | 43 | | { |
| 1 | 44 | | return _result.Body; |
| | 45 | | } |
| 1 | 46 | | } |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// The API returns a list of recognized entities in a given document. |
| | 50 | | /// </summary> |
| | 51 | | /// <remarks> |
| | 52 | | /// To get even more information on each recognized entity we recommend using |
| | 53 | | /// the Bing Entity Search API by querying for the recognized entities names. |
| | 54 | | /// See the <a |
| | 55 | | /// href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported- |
| | 56 | | /// languages in Text Analytics API</a> for the list of enabled |
| | 57 | | /// languages. |
| | 58 | | /// </remarks> |
| | 59 | | /// <param name='operations'> |
| | 60 | | /// The operations group for this extension method. |
| | 61 | | /// </param> |
| | 62 | | /// <param name='showStats'> |
| | 63 | | /// (optional) if set to true, response will contain input and document level |
| | 64 | | /// statistics. |
| | 65 | | /// </param> |
| | 66 | | /// <param name='multiLanguageBatchInput'> |
| | 67 | | /// Collection of documents to analyze. |
| | 68 | | /// </param> |
| | 69 | | /// <param name='cancellationToken'> |
| | 70 | | /// The cancellation token. |
| | 71 | | /// </param> |
| | 72 | | public static async Task<EntitiesBatchResult> EntitiesBatchAsync(this ITextAnalyticsClient operations, Multi |
| | 73 | | { |
| 1 | 74 | | using (var _result = await operations.EntitiesWithHttpMessagesAsync(showStats, multiLanguageBatchInput, |
| | 75 | | { |
| 1 | 76 | | return _result.Body; |
| | 77 | | } |
| 1 | 78 | | } |
| | 79 | |
|
| | 80 | | /// <summary> |
| | 81 | | /// The API returns a list of strings denoting the key talking points in the |
| | 82 | | /// input text. |
| | 83 | | /// </summary> |
| | 84 | | /// <remarks> |
| | 85 | | /// See the <a |
| | 86 | | /// href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-langua |
| | 87 | | /// Analytics Documentation</a> for details about the languages that are |
| | 88 | | /// supported by key phrase extraction. |
| | 89 | | /// </remarks> |
| | 90 | | /// <param name='operations'> |
| | 91 | | /// The operations group for this extension method. |
| | 92 | | /// </param> |
| | 93 | | /// <param name='showStats'> |
| | 94 | | /// (optional) if set to true, response will contain input and document level |
| | 95 | | /// statistics. |
| | 96 | | /// </param> |
| | 97 | | /// <param name='multiLanguageBatchInput'> |
| | 98 | | /// Collection of documents to analyze. Documents can now contain a language |
| | 99 | | /// field to indicate the text language |
| | 100 | | /// </param> |
| | 101 | | /// <param name='cancellationToken'> |
| | 102 | | /// The cancellation token. |
| | 103 | | /// </param> |
| | 104 | | public static async Task<KeyPhraseBatchResult> KeyPhrasesBatchAsync(this ITextAnalyticsClient operations, Mu |
| | 105 | | { |
| 1 | 106 | | using (var _result = await operations.KeyPhrasesWithHttpMessagesAsync(showStats, multiLanguageBatchInput |
| | 107 | | { |
| 1 | 108 | | return _result.Body; |
| | 109 | | } |
| 1 | 110 | | } |
| | 111 | |
|
| | 112 | | /// <summary> |
| | 113 | | /// The API returns a numeric score between 0 and 1. |
| | 114 | | /// </summary> |
| | 115 | | /// <remarks> |
| | 116 | | /// Scores close to 1 indicate positive sentiment, while scores close to 0 |
| | 117 | | /// indicate negative sentiment. A score of 0.5 indicates the lack of sentiment |
| | 118 | | /// (e.g. a factoid statement). See the <a |
| | 119 | | /// href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-langua |
| | 120 | | /// Analytics Documentation</a> for details about the languages that are |
| | 121 | | /// supported by sentiment analysis. |
| | 122 | | /// </remarks> |
| | 123 | | /// <param name='operations'> |
| | 124 | | /// The operations group for this extension method. |
| | 125 | | /// </param> |
| | 126 | | /// <param name='showStats'> |
| | 127 | | /// (optional) if set to true, response will contain input and document level |
| | 128 | | /// statistics. |
| | 129 | | /// </param> |
| | 130 | | /// <param name='multiLanguageBatchInput'> |
| | 131 | | /// Collection of documents to analyze. |
| | 132 | | /// </param> |
| | 133 | | /// <param name='cancellationToken'> |
| | 134 | | /// The cancellation token. |
| | 135 | | /// </param> |
| | 136 | | public static async Task<SentimentBatchResult> SentimentBatchAsync(this ITextAnalyticsClient operations, Mul |
| | 137 | | { |
| 1 | 138 | | using (var _result = await operations.SentimentWithHttpMessagesAsync(showStats, multiLanguageBatchInput, |
| | 139 | | { |
| 1 | 140 | | return _result.Body; |
| | 141 | | } |
| 1 | 142 | | } |
| | 143 | |
|
| | 144 | | /// <summary> |
| | 145 | | /// The API returns the detected language and a numeric score between 0 and 1. |
| | 146 | | /// </summary> |
| | 147 | | /// <remarks> |
| | 148 | | /// Scores close to 1 indicate 100% certainty that the identified language is |
| | 149 | | /// true. A total of 120 languages are supported. |
| | 150 | | /// </remarks> |
| | 151 | | /// <param name='operations'> |
| | 152 | | /// The operations group for this extension method. |
| | 153 | | /// </param> |
| | 154 | | /// <param name='showStats'> |
| | 155 | | /// (optional) if set to true, response will contain input and document level |
| | 156 | | /// statistics. |
| | 157 | | /// </param> |
| | 158 | | /// <param name='inputText'> |
| | 159 | | /// Input text of one document. |
| | 160 | | /// </param> |
| | 161 | | /// <param name='countryHint'> |
| | 162 | | /// Contry hint. |
| | 163 | | /// </param> |
| | 164 | | /// <param name='cancellationToken'> |
| | 165 | | /// The cancellation token. |
| | 166 | | /// </param> |
| | 167 | | public static async Task<LanguageResult> DetectLanguageAsync( |
| | 168 | | this ITextAnalyticsClient operations, |
| | 169 | | string inputText = default, |
| | 170 | | string countryHint = "US", |
| | 171 | | bool? showStats = default, |
| | 172 | | CancellationToken cancellationToken = default) |
| | 173 | | { |
| 1 | 174 | | var languageBatchInput = new LanguageBatchInput(new List<LanguageInput> { new LanguageInput("1", inputText, |
| 1 | 175 | | using (var _result = await operations.DetectLanguageWithHttpMessagesAsync(showStats, languageBatchInput, nul |
| | 176 | | { |
| 1 | 177 | | IList<DetectedLanguage> languages = _result.Body.Documents.Count > 0 ? _result.Body.Documents[0].Detecte |
| 1 | 178 | | string errorMessage = _result.Body.Errors.Count > 0 ? _result.Body.Errors[0].Message : null; |
| 1 | 179 | | RequestStatistics stats = _result.Body.Statistics; |
| | 180 | |
|
| 1 | 181 | | return new LanguageResult(languages, errorMessage, stats); |
| | 182 | | } |
| 1 | 183 | | } |
| | 184 | |
|
| | 185 | | /// <summary> |
| | 186 | | /// The API returns a list of recognized entities in a given document. |
| | 187 | | /// </summary> |
| | 188 | | /// <remarks> |
| | 189 | | /// To get even more information on each recognized entity we recommend using |
| | 190 | | /// the Bing Entity Search API by querying for the recognized entities names. |
| | 191 | | /// See the <a |
| | 192 | | /// href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported-lang |
| | 193 | | /// languages in Text Analytics API</a> for the list of enabled |
| | 194 | | /// languages. |
| | 195 | | /// </remarks> |
| | 196 | | /// <param name='operations'> |
| | 197 | | /// The operations group for this extension method. |
| | 198 | | /// </param> |
| | 199 | | /// <param name='showStats'> |
| | 200 | | /// (optional) if set to true, response will contain input and document level |
| | 201 | | /// statistics. |
| | 202 | | /// </param> |
| | 203 | | /// <param name='inputText'> |
| | 204 | | /// Input text of one document. |
| | 205 | | /// </param> |
| | 206 | | /// <param name='language'> |
| | 207 | | /// Language code. |
| | 208 | | /// </param> |
| | 209 | | /// <param name='cancellationToken'> |
| | 210 | | /// The cancellation token. |
| | 211 | | /// </param> |
| | 212 | | public static async Task<EntitiesResult> EntitiesAsync( |
| | 213 | | this ITextAnalyticsClient operations, |
| | 214 | | string inputText = default, |
| | 215 | | string language = "en", |
| | 216 | | bool? showStats = default, |
| | 217 | | CancellationToken cancellationToken = default) |
| | 218 | | { |
| 1 | 219 | | var multiLanguageBatchInput = new MultiLanguageBatchInput(new List<MultiLanguageInput> { new MultiLanguageIn |
| 1 | 220 | | using (var _result = await operations.EntitiesWithHttpMessagesAsync(showStats, multiLanguageBatchInput, null |
| | 221 | | { |
| 1 | 222 | | IList<EntityRecord> entities = _result.Body.Documents.Count > 0 ? _result.Body.Documents[0].Entities : n |
| 1 | 223 | | string errorMessage = _result.Body.Errors.Count > 0 ? _result.Body.Errors[0].Message : null; |
| 1 | 224 | | RequestStatistics stats = _result.Body.Statistics; |
| | 225 | |
|
| 1 | 226 | | return new EntitiesResult(entities, errorMessage, stats); |
| | 227 | | } |
| 1 | 228 | | } |
| | 229 | |
|
| | 230 | | /// <summary> |
| | 231 | | /// The API returns a list of strings denoting the key talking points in the |
| | 232 | | /// input text. |
| | 233 | | /// </summary> |
| | 234 | | /// <remarks> |
| | 235 | | /// See the <a |
| | 236 | | /// href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages" |
| | 237 | | /// Analytics Documentation</a> for details about the languages that are |
| | 238 | | /// supported by key phrase extraction. |
| | 239 | | /// </remarks> |
| | 240 | | /// <param name='operations'> |
| | 241 | | /// The operations group for this extension method. |
| | 242 | | /// </param> |
| | 243 | | /// <param name='showStats'> |
| | 244 | | /// (optional) if set to true, response will contain input and document level |
| | 245 | | /// statistics. |
| | 246 | | /// </param> |
| | 247 | | /// <param name='inputText'> |
| | 248 | | /// Input text of one document. |
| | 249 | | /// </param> |
| | 250 | | /// <param name='language'> |
| | 251 | | /// Language code. |
| | 252 | | /// </param> |
| | 253 | | /// <param name='cancellationToken'> |
| | 254 | | /// The cancellation token. |
| | 255 | | /// </param> |
| | 256 | | public static async Task<KeyPhraseResult> KeyPhrasesAsync( |
| | 257 | | this ITextAnalyticsClient operations, |
| | 258 | | string inputText = default, |
| | 259 | | string language = "en", |
| | 260 | | bool? showStats = default, |
| | 261 | | CancellationToken cancellationToken = default) |
| | 262 | | { |
| 1 | 263 | | var multiLanguageBatchInput = new MultiLanguageBatchInput(new List<MultiLanguageInput> { new MultiLanguageIn |
| 1 | 264 | | using (var _result = await operations.KeyPhrasesWithHttpMessagesAsync(showStats, multiLanguageBatchInput, nu |
| | 265 | | { |
| 1 | 266 | | IList<string> keyPhrases = _result.Body.Documents.Count > 0 ? _result.Body.Documents[0].KeyPhrases : nul |
| 1 | 267 | | string errorMessage = _result.Body.Errors.Count > 0 ? _result.Body.Errors[0].Message : null; |
| 1 | 268 | | RequestStatistics stats = _result.Body.Statistics; |
| | 269 | |
|
| 1 | 270 | | return new KeyPhraseResult(keyPhrases, errorMessage, stats); |
| | 271 | | } |
| 1 | 272 | | } |
| | 273 | |
|
| | 274 | | /// <summary> |
| | 275 | | /// The API returns a numeric score between 0 and 1. |
| | 276 | | /// </summary> |
| | 277 | | /// <remarks> |
| | 278 | | /// Scores close to 1 indicate positive sentiment, while scores close to 0 |
| | 279 | | /// indicate negative sentiment. A score of 0.5 indicates the lack of sentiment |
| | 280 | | /// (e.g. a factoid statement). See the <a |
| | 281 | | /// href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages" |
| | 282 | | /// Analytics Documentation</a> for details about the languages that are |
| | 283 | | /// supported by sentiment analysis. |
| | 284 | | /// </remarks> |
| | 285 | | /// <param name='operations'> |
| | 286 | | /// The operations group for this extension method. |
| | 287 | | /// </param> |
| | 288 | | /// <param name='showStats'> |
| | 289 | | /// (optional) if set to true, response will contain input and document level |
| | 290 | | /// statistics. |
| | 291 | | /// </param> |
| | 292 | | /// <param name='inputText'> |
| | 293 | | /// Input text of one document. |
| | 294 | | /// </param> |
| | 295 | | /// <param name='language'> |
| | 296 | | /// Language code. |
| | 297 | | /// </param> |
| | 298 | | /// <param name='cancellationToken'> |
| | 299 | | /// The cancellation token. |
| | 300 | | /// </param> |
| | 301 | | public static async Task<SentimentResult> SentimentAsync( |
| | 302 | | this ITextAnalyticsClient operations, |
| | 303 | | string inputText = default, |
| | 304 | | string language = "en", |
| | 305 | | bool? showStats = default, |
| | 306 | | CancellationToken cancellationToken = default) |
| | 307 | | { |
| 1 | 308 | | var multiLanguageBatchInput = new MultiLanguageBatchInput(new List<MultiLanguageInput> { new MultiLanguageIn |
| 1 | 309 | | using (var _result = await operations.SentimentWithHttpMessagesAsync(showStats, multiLanguageBatchInput, nul |
| | 310 | | { |
| 1 | 311 | | double? score = _result.Body.Documents.Count > 0 ? _result.Body.Documents[0].Score : null; |
| 1 | 312 | | string errorMessage = _result.Body.Errors.Count > 0 ? _result.Body.Errors[0].Message : null; |
| 1 | 313 | | RequestStatistics stats = _result.Body.Statistics; |
| | 314 | |
|
| 1 | 315 | | return new SentimentResult(score, errorMessage, stats); |
| | 316 | | } |
| 1 | 317 | | } |
| | 318 | |
|
| | 319 | | /// <summary> |
| | 320 | | /// The API returns the detected language and a numeric score between 0 and 1. |
| | 321 | | /// </summary> |
| | 322 | | /// <remarks> |
| | 323 | | /// Scores close to 1 indicate 100% certainty that the identified language is |
| | 324 | | /// true. A total of 120 languages are supported. |
| | 325 | | /// </remarks> |
| | 326 | | /// <param name='operations'> |
| | 327 | | /// The operations group for this extension method. |
| | 328 | | /// </param> |
| | 329 | | /// <param name='showStats'> |
| | 330 | | /// (optional) if set to true, response will contain input and document level |
| | 331 | | /// statistics. |
| | 332 | | /// </param> |
| | 333 | | /// <param name='languageBatchInput'> |
| | 334 | | /// Collection of documents to analyze. |
| | 335 | | /// </param> |
| | 336 | | /// <param name='cancellationToken'> |
| | 337 | | /// The cancellation token. |
| | 338 | | /// </param> |
| | 339 | | public static LanguageBatchResult DetectLanguageBatch(this ITextAnalyticsClient operations, LanguageBatchInput l |
| | 340 | | { |
| 1 | 341 | | var _result = operations.DetectLanguageWithHttpMessagesAsync(showStats, languageBatchInput, null, cancellati |
| 1 | 342 | | return _result.Body; |
| | 343 | | } |
| | 344 | |
|
| | 345 | | /// <summary> |
| | 346 | | /// The API returns a list of recognized entities in a given document. |
| | 347 | | /// </summary> |
| | 348 | | /// <remarks> |
| | 349 | | /// To get even more information on each recognized entity we recommend using |
| | 350 | | /// the Bing Entity Search API by querying for the recognized entities names. |
| | 351 | | /// See the <a |
| | 352 | | /// href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported-lang |
| | 353 | | /// languages in Text Analytics API</a> for the list of enabled |
| | 354 | | /// languages. |
| | 355 | | /// </remarks> |
| | 356 | | /// <param name='operations'> |
| | 357 | | /// The operations group for this extension method. |
| | 358 | | /// </param> |
| | 359 | | /// <param name='showStats'> |
| | 360 | | /// (optional) if set to true, response will contain input and document level |
| | 361 | | /// statistics. |
| | 362 | | /// </param> |
| | 363 | | /// <param name='multiLanguageBatchInput'> |
| | 364 | | /// Collection of documents to analyze. |
| | 365 | | /// </param> |
| | 366 | | /// <param name='cancellationToken'> |
| | 367 | | /// The cancellation token. |
| | 368 | | /// </param> |
| | 369 | | public static EntitiesBatchResult EntitiesBatch(this ITextAnalyticsClient operations, MultiLanguageBatchInput mu |
| | 370 | | { |
| 1 | 371 | | var _result = operations.EntitiesWithHttpMessagesAsync(showStats, multiLanguageBatchInput, null, cancellatio |
| 1 | 372 | | return _result.Body; |
| | 373 | | } |
| | 374 | |
|
| | 375 | | /// <summary> |
| | 376 | | /// The API returns a list of strings denoting the key talking points in the |
| | 377 | | /// input text. |
| | 378 | | /// </summary> |
| | 379 | | /// <remarks> |
| | 380 | | /// See the <a |
| | 381 | | /// href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages" |
| | 382 | | /// Analytics Documentation</a> for details about the languages that are |
| | 383 | | /// supported by key phrase extraction. |
| | 384 | | /// </remarks> |
| | 385 | | /// <param name='operations'> |
| | 386 | | /// The operations group for this extension method. |
| | 387 | | /// </param> |
| | 388 | | /// <param name='showStats'> |
| | 389 | | /// (optional) if set to true, response will contain input and document level |
| | 390 | | /// statistics. |
| | 391 | | /// </param> |
| | 392 | | /// <param name='multiLanguageBatchInput'> |
| | 393 | | /// Collection of documents to analyze. Documents can now contain a language |
| | 394 | | /// field to indicate the text language |
| | 395 | | /// </param> |
| | 396 | | /// <param name='cancellationToken'> |
| | 397 | | /// The cancellation token. |
| | 398 | | /// </param> |
| | 399 | | public static KeyPhraseBatchResult KeyPhrasesBatch(this ITextAnalyticsClient operations, MultiLanguageBatchInput |
| | 400 | | { |
| 1 | 401 | | var _result = operations.KeyPhrasesWithHttpMessagesAsync(showStats, multiLanguageBatchInput, null, cancellat |
| 1 | 402 | | return _result.Body; |
| | 403 | | } |
| | 404 | |
|
| | 405 | | /// <summary> |
| | 406 | | /// The API returns a numeric score between 0 and 1. |
| | 407 | | /// </summary> |
| | 408 | | /// <remarks> |
| | 409 | | /// Scores close to 1 indicate positive sentiment, while scores close to 0 |
| | 410 | | /// indicate negative sentiment. A score of 0.5 indicates the lack of sentiment |
| | 411 | | /// (e.g. a factoid statement). See the <a |
| | 412 | | /// href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages" |
| | 413 | | /// Analytics Documentation</a> for details about the languages that are |
| | 414 | | /// supported by sentiment analysis. |
| | 415 | | /// </remarks> |
| | 416 | | /// <param name='operations'> |
| | 417 | | /// The operations group for this extension method. |
| | 418 | | /// </param> |
| | 419 | | /// <param name='showStats'> |
| | 420 | | /// (optional) if set to true, response will contain input and document level |
| | 421 | | /// statistics. |
| | 422 | | /// </param> |
| | 423 | | /// <param name='multiLanguageBatchInput'> |
| | 424 | | /// Collection of documents to analyze. |
| | 425 | | /// </param> |
| | 426 | | /// <param name='cancellationToken'> |
| | 427 | | /// The cancellation token. |
| | 428 | | /// </param> |
| | 429 | | public static SentimentBatchResult SentimentBatch(this ITextAnalyticsClient operations, MultiLanguageBatchInput |
| | 430 | | { |
| 1 | 431 | | var _result = operations.SentimentWithHttpMessagesAsync(showStats, multiLanguageBatchInput, null, cancellati |
| 1 | 432 | | return _result.Body; |
| | 433 | | } |
| | 434 | |
|
| | 435 | | /// <summary> |
| | 436 | | /// The API returns the detected language and a numeric score between 0 and 1. |
| | 437 | | /// </summary> |
| | 438 | | /// <remarks> |
| | 439 | | /// Scores close to 1 indicate 100% certainty that the identified language is |
| | 440 | | /// true. A total of 120 languages are supported. |
| | 441 | | /// </remarks> |
| | 442 | | /// <param name='operations'> |
| | 443 | | /// The operations group for this extension method. |
| | 444 | | /// </param> |
| | 445 | | /// <param name='showStats'> |
| | 446 | | /// (optional) if set to true, response will contain input and document level |
| | 447 | | /// statistics. |
| | 448 | | /// </param> |
| | 449 | | /// <param name='inputText'> |
| | 450 | | /// Input text of one document. |
| | 451 | | /// </param> |
| | 452 | | /// <param name='countryHint'> |
| | 453 | | /// Contry hint. |
| | 454 | | /// </param> |
| | 455 | | /// <param name='cancellationToken'> |
| | 456 | | /// The cancellation token. |
| | 457 | | /// </param> |
| | 458 | | public static LanguageResult DetectLanguage( |
| | 459 | | this ITextAnalyticsClient operations, |
| | 460 | | string inputText = default, |
| | 461 | | string countryHint = "US", |
| | 462 | | bool? showStats = default, |
| | 463 | | CancellationToken cancellationToken = default) |
| | 464 | | { |
| 1 | 465 | | var languageBatchInput = new LanguageBatchInput(new List<LanguageInput> { new LanguageInput("1", inputText, |
| 1 | 466 | | var _result = operations.DetectLanguageWithHttpMessagesAsync(showStats, languageBatchInput, null, cancellati |
| | 467 | |
|
| 1 | 468 | | IList<DetectedLanguage> languages = _result.Body.Documents.Count > 0 ? _result.Body.Documents[0].DetectedLan |
| 1 | 469 | | string errorMessage = _result.Body.Errors.Count > 0 ? _result.Body.Errors[0].Message : null; |
| 1 | 470 | | RequestStatistics stats = _result.Body.Statistics; |
| | 471 | |
|
| 1 | 472 | | return new LanguageResult(languages, errorMessage, stats); |
| | 473 | | } |
| | 474 | |
|
| | 475 | | /// <summary> |
| | 476 | | /// The API returns a list of recognized entities in a given document. |
| | 477 | | /// </summary> |
| | 478 | | /// <remarks> |
| | 479 | | /// To get even more information on each recognized entity we recommend using |
| | 480 | | /// the Bing Entity Search API by querying for the recognized entities names. |
| | 481 | | /// See the <a |
| | 482 | | /// href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported-lang |
| | 483 | | /// languages in Text Analytics API</a> for the list of enabled |
| | 484 | | /// languages. |
| | 485 | | /// </remarks> |
| | 486 | | /// <param name='operations'> |
| | 487 | | /// The operations group for this extension method. |
| | 488 | | /// </param> |
| | 489 | | /// <param name='showStats'> |
| | 490 | | /// (optional) if set to true, response will contain input and document level |
| | 491 | | /// statistics. |
| | 492 | | /// </param> |
| | 493 | | /// <param name='inputText'> |
| | 494 | | /// Input text of one document. |
| | 495 | | /// </param> |
| | 496 | | /// <param name='language'> |
| | 497 | | /// Language code. |
| | 498 | | /// </param> |
| | 499 | | /// <param name='cancellationToken'> |
| | 500 | | /// The cancellation token. |
| | 501 | | /// </param> |
| | 502 | | public static EntitiesResult Entities( |
| | 503 | | this ITextAnalyticsClient operations, |
| | 504 | | string inputText = default, |
| | 505 | | string language = "en", |
| | 506 | | bool? showStats = default, |
| | 507 | | CancellationToken cancellationToken = default) |
| | 508 | | { |
| 1 | 509 | | var multiLanguageBatchInput = new MultiLanguageBatchInput(new List<MultiLanguageInput> { new MultiLanguageIn |
| 1 | 510 | | var _result = operations.EntitiesWithHttpMessagesAsync(showStats, multiLanguageBatchInput, null, cancellatio |
| | 511 | |
|
| 1 | 512 | | IList<EntityRecord> entities = _result.Body.Documents.Count > 0 ? _result.Body.Documents[0].Entities : null; |
| 1 | 513 | | string errorMessage = _result.Body.Errors.Count > 0 ? _result.Body.Errors[0].Message : null; |
| 1 | 514 | | RequestStatistics stats = _result.Body.Statistics; |
| | 515 | |
|
| 1 | 516 | | return new EntitiesResult(entities, errorMessage, stats); |
| | 517 | | } |
| | 518 | |
|
| | 519 | | /// <summary> |
| | 520 | | /// The API returns a list of strings denoting the key talking points in the |
| | 521 | | /// input text. |
| | 522 | | /// </summary> |
| | 523 | | /// <remarks> |
| | 524 | | /// See the <a |
| | 525 | | /// href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages" |
| | 526 | | /// Analytics Documentation</a> for details about the languages that are |
| | 527 | | /// supported by key phrase extraction. |
| | 528 | | /// </remarks> |
| | 529 | | /// <param name='operations'> |
| | 530 | | /// The operations group for this extension method. |
| | 531 | | /// </param> |
| | 532 | | /// <param name='showStats'> |
| | 533 | | /// (optional) if set to true, response will contain input and document level |
| | 534 | | /// statistics. |
| | 535 | | /// </param> |
| | 536 | | /// <param name='inputText'> |
| | 537 | | /// Input text of one document. |
| | 538 | | /// </param> |
| | 539 | | /// <param name='language'> |
| | 540 | | /// Language code. |
| | 541 | | /// </param> |
| | 542 | | /// <param name='cancellationToken'> |
| | 543 | | /// The cancellation token. |
| | 544 | | /// </param> |
| | 545 | | public static KeyPhraseResult KeyPhrases( |
| | 546 | | this ITextAnalyticsClient operations, |
| | 547 | | string inputText = default, |
| | 548 | | string language = "en", |
| | 549 | | bool? showStats = default, |
| | 550 | | CancellationToken cancellationToken = default) |
| | 551 | | { |
| 1 | 552 | | var multiLanguageBatchInput = new MultiLanguageBatchInput(new List<MultiLanguageInput> { new MultiLanguageIn |
| 1 | 553 | | var _result = operations.KeyPhrasesWithHttpMessagesAsync(showStats, multiLanguageBatchInput, null, cancellat |
| | 554 | |
|
| 1 | 555 | | IList<string> keyPhrases = _result.Body.Documents.Count > 0 ? _result.Body.Documents[0].KeyPhrases : null; |
| 1 | 556 | | string errorMessage = _result.Body.Errors.Count > 0 ? _result.Body.Errors[0].Message : null; |
| 1 | 557 | | RequestStatistics stats = _result.Body.Statistics; |
| | 558 | |
|
| 1 | 559 | | return new KeyPhraseResult(keyPhrases, errorMessage, stats); |
| | 560 | | } |
| | 561 | |
|
| | 562 | | /// <summary> |
| | 563 | | /// The API returns a numeric score between 0 and 1. |
| | 564 | | /// </summary> |
| | 565 | | /// <remarks> |
| | 566 | | /// Scores close to 1 indicate positive sentiment, while scores close to 0 |
| | 567 | | /// indicate negative sentiment. A score of 0.5 indicates the lack of sentiment |
| | 568 | | /// (e.g. a factoid statement). See the <a |
| | 569 | | /// href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages" |
| | 570 | | /// Analytics Documentation</a> for details about the languages that are |
| | 571 | | /// supported by sentiment analysis. |
| | 572 | | /// </remarks> |
| | 573 | | /// <param name='operations'> |
| | 574 | | /// The operations group for this extension method. |
| | 575 | | /// </param> |
| | 576 | | /// <param name='showStats'> |
| | 577 | | /// (optional) if set to true, response will contain input and document level |
| | 578 | | /// statistics. |
| | 579 | | /// </param> |
| | 580 | | /// <param name='inputText'> |
| | 581 | | /// Input text of one document. |
| | 582 | | /// </param> |
| | 583 | | /// <param name='language'> |
| | 584 | | /// Language code. |
| | 585 | | /// </param> |
| | 586 | | /// <param name='cancellationToken'> |
| | 587 | | /// The cancellation token. |
| | 588 | | /// </param> |
| | 589 | | public static SentimentResult Sentiment( |
| | 590 | | this ITextAnalyticsClient operations, |
| | 591 | | string inputText = default, |
| | 592 | | string language = "en", |
| | 593 | | bool? showStats = default, |
| | 594 | | CancellationToken cancellationToken = default) |
| | 595 | | { |
| 1 | 596 | | var multiLanguageBatchInput = new MultiLanguageBatchInput(new List<MultiLanguageInput> { new MultiLanguageIn |
| 1 | 597 | | var _result = operations.SentimentWithHttpMessagesAsync(showStats, multiLanguageBatchInput, null, cancellati |
| | 598 | |
|
| 1 | 599 | | double? score = _result.Body.Documents.Count > 0 ? _result.Body.Documents[0].Score : null; |
| 1 | 600 | | string errorMessage = _result.Body.Errors.Count > 0 ? _result.Body.Errors[0].Message : null; |
| 1 | 601 | | RequestStatistics stats = _result.Body.Statistics; |
| | 602 | |
|
| 1 | 603 | | return new SentimentResult(score, errorMessage, stats); |
| | 604 | | } |
| | 605 | | } |
| | 606 | | } |