From 36ceb1475804cc7ebeb0384eb6d10ff964d02b47 Mon Sep 17 00:00:00 2001 From: Heath Stewart Date: Thu, 1 Apr 2021 16:34:36 -0700 Subject: [PATCH 1/6] Add method-specific request options to TextAnalyticsClient Fixes #18482 --- .../src/TextAnalyticsClient.cs | 166 ++++++++++++++++- .../tests/RecognizeLinkedEntitiesTests.cs | 30 +++ ...zeLinkedEntitiesOptionsStatisticsTest.json | 160 ++++++++++++++++ ...kedEntitiesOptionsStatisticsTestAsync.json | 160 ++++++++++++++++ ...zeLinkedEntitiesOptionsStatisticsTest.json | 176 ++++++++++++++++++ ...kedEntitiesOptionsStatisticsTestAsync.json | 176 ++++++++++++++++++ .../tests/TextAnalyticsClientTests.cs | 40 +++- 7 files changed, 890 insertions(+), 18 deletions(-) create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeLinkedEntitiesTests/RecognizeLinkedEntitiesBatchConvenienceWithRecognizeLinkedEntitiesOptionsStatisticsTest.json create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeLinkedEntitiesTests/RecognizeLinkedEntitiesBatchConvenienceWithRecognizeLinkedEntitiesOptionsStatisticsTestAsync.json create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeLinkedEntitiesTests/RecognizeLinkedEntitiesBatchWithRecognizeLinkedEntitiesOptionsStatisticsTest.json create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeLinkedEntitiesTests/RecognizeLinkedEntitiesBatchWithRecognizeLinkedEntitiesOptionsStatisticsTestAsync.json diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs index d9df26005151b..16e658f5a52fc 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs @@ -1888,6 +1888,28 @@ public virtual Response RecognizeLinkedEntities(string d } } + /// + /// Runs a predictive model to identify a collection of entities + /// found in the passed-in documents, and include information linking the + /// entities to their corresponding entries in a well-known knowledge base. + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of entities identified + /// for each of the documents, as well as scores indicating the confidence + /// that a given entity correctly matches the identified substring. + /// Service returned a non-success + /// status code. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual async Task> RecognizeLinkedEntitiesBatchAsync(IEnumerable documents, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) => + await RecognizeLinkedEntitiesBatchAsync(documents, null, options, cancellationToken).ConfigureAwait(false); + /// /// Runs a predictive model to identify a collection of entities /// found in the passed-in documents, and include information linking the @@ -1913,15 +1935,66 @@ public virtual Response RecognizeLinkedEntities(string d /// that a given entity correctly matches the identified substring. /// Service returned a non-success /// status code. - public virtual async Task> RecognizeLinkedEntitiesBatchAsync(IEnumerable documents, string language = default, TextAnalyticsRequestOptions options = default, CancellationToken cancellationToken = default) + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual async Task> RecognizeLinkedEntitiesBatchAsync(IEnumerable documents, string language, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(documents, nameof(documents)); - options ??= new TextAnalyticsRequestOptions(); + options ??= new RecognizeLinkedEntitiesOptions(); MultiLanguageBatchInput documentInputs = ConvertToMultiLanguageInputs(documents, language); return await RecognizeLinkedEntitiesBatchAsync(documentInputs, options, cancellationToken).ConfigureAwait(false); } + /// + /// Runs a predictive model to identify a collection of entities + /// found in the passed-in documents, and include information linking the + /// entities to their corresponding entries in a well-known knowledge base. + /// For a list of languages supported by this operation, see + /// . + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// The language that the documents are written in. + /// If unspecified, this value will be set to the default language in + /// in the request sent to the + /// service. If set to an empty string, the service will apply a model + /// where the language is explicitly set to "None". + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of entities identified + /// for each of the documents, as well as scores indicating the confidence + /// that a given entity correctly matches the identified substring. + /// Service returned a non-success + /// status code. + public virtual async Task> RecognizeLinkedEntitiesBatchAsync(IEnumerable documents, string language = default, RecognizeLinkedEntitiesOptions options = default, CancellationToken cancellationToken = default) => + await RecognizeLinkedEntitiesBatchAsync(documents, language, (TextAnalyticsRequestOptions)options, cancellationToken).ConfigureAwait(false); + + /// + /// Runs a predictive model to identify a collection of entities + /// found in the passed-in documents, and include information linking the + /// entities to their corresponding entries in a well-known knowledge base. + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of entities identified + /// for each of the documents, as well as scores indicating the confidence + /// that a given entity correctly matches the identified substring. + /// Service returned a non-success + /// status code. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual Response RecognizeLinkedEntitiesBatch(IEnumerable documents, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) => + RecognizeLinkedEntitiesBatch(documents, null, options, cancellationToken); + /// /// Runs a predictive model to identify a collection of entities /// found in the passed-in documents, and include information linking the @@ -1947,15 +2020,44 @@ public virtual async Task> Rec /// that a given entity correctly matches the identified substring. /// Service returned a non-success /// status code. - public virtual Response RecognizeLinkedEntitiesBatch(IEnumerable documents, string language = default, TextAnalyticsRequestOptions options = default, CancellationToken cancellationToken = default) + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual Response RecognizeLinkedEntitiesBatch(IEnumerable documents, string language, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(documents, nameof(documents)); - options ??= new TextAnalyticsRequestOptions(); + options ??= new RecognizeLinkedEntitiesOptions(); MultiLanguageBatchInput documentInputs = ConvertToMultiLanguageInputs(documents, language); return RecognizeLinkedEntitiesBatch(documentInputs, options, cancellationToken); } + /// + /// Runs a predictive model to identify a collection of entities + /// found in the passed-in documents, and include information linking the + /// entities to their corresponding entries in a well-known knowledge base. + /// For a list of languages supported by this operation, see + /// . + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// The language that the documents are written in. + /// If unspecified, this value will be set to the default language in + /// in the request sent to the + /// service. If set to an empty string, the service will apply a model + /// where the language is explicitly set to "None". + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of entities identified + /// for each of the documents, as well as scores indicating the confidence + /// that a given entity correctly matches the identified substring. + /// Service returned a non-success + /// status code. + public virtual Response RecognizeLinkedEntitiesBatch(IEnumerable documents, string language = default, RecognizeLinkedEntitiesOptions options = default, CancellationToken cancellationToken = default) => + RecognizeLinkedEntitiesBatch(documents, language, (TextAnalyticsRequestOptions)options, cancellationToken); + /// /// Runs a predictive model to identify a collection of entities /// found in the passed-in documents, and include information linking the @@ -1976,15 +2078,39 @@ public virtual Response RecognizeLinked /// that a given entity correctly matches the identified substring. /// Service returned a non-success /// status code. - public virtual async Task> RecognizeLinkedEntitiesBatchAsync(IEnumerable documents, TextAnalyticsRequestOptions options = default, CancellationToken cancellationToken = default) + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual async Task> RecognizeLinkedEntitiesBatchAsync(IEnumerable documents, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(documents, nameof(documents)); - options ??= new TextAnalyticsRequestOptions(); + options ??= new RecognizeLinkedEntitiesOptions(); MultiLanguageBatchInput documentInputs = ConvertToMultiLanguageInputs(documents); return await RecognizeLinkedEntitiesBatchAsync(documentInputs, options, cancellationToken).ConfigureAwait(false); } + /// + /// Runs a predictive model to identify a collection of entities + /// found in the passed-in documents, and include information linking the + /// entities to their corresponding entries in a well-known knowledge base. + /// For a list of languages supported by this operation, see + /// . + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of entities identified + /// for each of the documents, as well as scores indicating the confidence + /// that a given entity correctly matches the identified substring. + /// Service returned a non-success + /// status code. + public virtual async Task> RecognizeLinkedEntitiesBatchAsync(IEnumerable documents, RecognizeLinkedEntitiesOptions options = default, CancellationToken cancellationToken = default) => + await RecognizeLinkedEntitiesBatchAsync(documents, (TextAnalyticsRequestOptions)options, cancellationToken).ConfigureAwait(false); + /// /// Runs a predictive model to identify a collection of entities /// found in the passed-in documents, and include information linking the @@ -2005,15 +2131,39 @@ public virtual async Task> Rec /// that a given entity correctly matches the identified substring. /// Service returned a non-success /// status code. - public virtual Response RecognizeLinkedEntitiesBatch(IEnumerable documents, TextAnalyticsRequestOptions options = default, CancellationToken cancellationToken = default) + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual Response RecognizeLinkedEntitiesBatch(IEnumerable documents, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(documents, nameof(documents)); - options ??= new TextAnalyticsRequestOptions(); + options ??= new RecognizeLinkedEntitiesOptions(); MultiLanguageBatchInput documentInputs = ConvertToMultiLanguageInputs(documents); return RecognizeLinkedEntitiesBatch(documentInputs, options, cancellationToken); } + /// + /// Runs a predictive model to identify a collection of entities + /// found in the passed-in documents, and include information linking the + /// entities to their corresponding entries in a well-known knowledge base. + /// For a list of languages supported by this operation, see + /// . + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of entities identified + /// for each of the documents, as well as scores indicating the confidence + /// that a given entity correctly matches the identified substring. + /// Service returned a non-success + /// status code. + public virtual Response RecognizeLinkedEntitiesBatch(IEnumerable documents, RecognizeLinkedEntitiesOptions options = default, CancellationToken cancellationToken = default) => + RecognizeLinkedEntitiesBatch(documents, (TextAnalyticsRequestOptions)options, cancellationToken); + private async Task> RecognizeLinkedEntitiesBatchAsync(MultiLanguageBatchInput batchInput, TextAnalyticsRequestOptions options, CancellationToken cancellationToken) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TextAnalyticsClient)}.{nameof(RecognizeLinkedEntitiesBatch)}"); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeLinkedEntitiesTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeLinkedEntitiesTests.cs index 06b8a77f58071..7f2d96ed4b352 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeLinkedEntitiesTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeLinkedEntitiesTests.cs @@ -148,6 +148,21 @@ public async Task RecognizeLinkedEntitiesBatchConvenienceWithStatisticsTest() ValidateBatchDocumentsResult(results, expectedOutput, includeStatistics: true); } + [Test] + public async Task RecognizeLinkedEntitiesBatchConvenienceWithRecognizeLinkedEntitiesOptionsStatisticsTest() + { + TextAnalyticsClient client = GetClient(); + RecognizeLinkedEntitiesResultCollection results = await client.RecognizeLinkedEntitiesBatchAsync(s_batchConvenienceDocuments, "en", new RecognizeLinkedEntitiesOptions { IncludeStatistics = true }); + + var expectedOutput = new Dictionary>() + { + { "0", s_document1ExpectedOutput }, + { "1", s_document2ExpectedOutput }, + }; + + ValidateBatchDocumentsResult(results, expectedOutput, includeStatistics: true); + } + [Test] public async Task RecognizeLinkedEntitiesBatchTest() { @@ -178,6 +193,21 @@ public async Task RecognizeLinkedEntitiesBatchWithStatisticsTest() ValidateBatchDocumentsResult(results, expectedOutput, includeStatistics: true); } + [Test] + public async Task RecognizeLinkedEntitiesBatchWithRecognizeLinkedEntitiesOptionsStatisticsTest() + { + TextAnalyticsClient client = GetClient(); + RecognizeLinkedEntitiesResultCollection results = await client.RecognizeLinkedEntitiesBatchAsync(s_batchDocuments, new RecognizeLinkedEntitiesOptions { IncludeStatistics = true }); + + var expectedOutput = new Dictionary>() + { + { "1", s_document1ExpectedOutput }, + { "3", s_document1ExpectedOutput }, + }; + + ValidateBatchDocumentsResult(results, expectedOutput, includeStatistics: true); + } + [Test] public void RecognizeLinkedEntitiesBatchWithNullIdTest() { diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeLinkedEntitiesTests/RecognizeLinkedEntitiesBatchConvenienceWithRecognizeLinkedEntitiesOptionsStatisticsTest.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeLinkedEntitiesTests/RecognizeLinkedEntitiesBatchConvenienceWithRecognizeLinkedEntitiesOptionsStatisticsTest.json new file mode 100644 index 0000000000000..e361105cdbcbf --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeLinkedEntitiesTests/RecognizeLinkedEntitiesBatchConvenienceWithRecognizeLinkedEntitiesOptionsStatisticsTest.json @@ -0,0 +1,160 @@ +{ + "Entries": [ + { + "RequestUri": "https://ta-s-westeurope.cognitiveservices.azure.com/text/analytics/v3.1-preview.4/entities/linking?showStats=true\u0026stringIndexType=Utf16CodeUnit", + "RequestMethod": "POST", + "RequestHeaders": { + "Accept": "application/json, text/json", + "Content-Length": "192", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-9165a72541277f4b8bbd51e3f7a19cab-5bd73057ee2b8744-00", + "User-Agent": "azsdk-net-AI.TextAnalytics/5.1.0-alpha.20210224.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19042 )", + "x-ms-client-request-id": "297e980ed9e8189820ebd45ff129bc5c", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "id": "0", + "text": "Microsoft was founded by Bill Gates and Paul Allen.", + "language": "en" + }, + { + "id": "1", + "text": "Pike place market is my favorite Seattle attraction.", + "language": "en" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "644a2848-9fc6-4c4f-bdfc-135300d8a638", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=2", + "Date": "Wed, 24 Feb 2021 16:57:32 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "x-content-type-options": "nosniff", + "x-envoy-upstream-service-time": "23" + }, + "ResponseBody": { + "statistics": { + "documentsCount": 2, + "validDocumentsCount": 2, + "erroneousDocumentsCount": 0, + "transactionsCount": 2 + }, + "documents": [ + { + "id": "0", + "statistics": { + "charactersCount": 51, + "transactionsCount": 1 + }, + "entities": [ + { + "bingId": "a093e9b9-90f5-a3d5-c4b8-5855e1b01f85", + "name": "Microsoft", + "matches": [ + { + "text": "Microsoft", + "offset": 0, + "length": 9, + "confidenceScore": 0.49 + } + ], + "language": "en", + "id": "Microsoft", + "url": "https://en.wikipedia.org/wiki/Microsoft", + "dataSource": "Wikipedia" + }, + { + "bingId": "0d47c987-0042-5576-15e8-97af601614fa", + "name": "Bill Gates", + "matches": [ + { + "text": "Bill Gates", + "offset": 25, + "length": 10, + "confidenceScore": 0.52 + } + ], + "language": "en", + "id": "Bill Gates", + "url": "https://en.wikipedia.org/wiki/Bill_Gates", + "dataSource": "Wikipedia" + }, + { + "bingId": "df2c4376-9923-6a54-893f-2ee5a5badbc7", + "name": "Paul Allen", + "matches": [ + { + "text": "Paul Allen", + "offset": 40, + "length": 10, + "confidenceScore": 0.54 + } + ], + "language": "en", + "id": "Paul Allen", + "url": "https://en.wikipedia.org/wiki/Paul_Allen", + "dataSource": "Wikipedia" + } + ], + "warnings": [] + }, + { + "id": "1", + "statistics": { + "charactersCount": 52, + "transactionsCount": 1 + }, + "entities": [ + { + "bingId": "38b9431e-cf91-93be-0584-c42a3ecbfdc7", + "name": "Pike Place Market", + "matches": [ + { + "text": "Pike place market", + "offset": 0, + "length": 17, + "confidenceScore": 0.86 + } + ], + "language": "en", + "id": "Pike Place Market", + "url": "https://en.wikipedia.org/wiki/Pike_Place_Market", + "dataSource": "Wikipedia" + }, + { + "bingId": "5fbba6b8-85e1-4d41-9444-d9055436e473", + "name": "Seattle", + "matches": [ + { + "text": "Seattle", + "offset": 33, + "length": 7, + "confidenceScore": 0.27 + } + ], + "language": "en", + "id": "Seattle", + "url": "https://en.wikipedia.org/wiki/Seattle", + "dataSource": "Wikipedia" + } + ], + "warnings": [] + } + ], + "errors": [], + "modelVersion": "2020-02-01" + } + } + ], + "Variables": { + "RandomSeed": "966684010", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://ta-s-westeurope.cognitiveservices.azure.com" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeLinkedEntitiesTests/RecognizeLinkedEntitiesBatchConvenienceWithRecognizeLinkedEntitiesOptionsStatisticsTestAsync.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeLinkedEntitiesTests/RecognizeLinkedEntitiesBatchConvenienceWithRecognizeLinkedEntitiesOptionsStatisticsTestAsync.json new file mode 100644 index 0000000000000..c278b8a7f2119 --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeLinkedEntitiesTests/RecognizeLinkedEntitiesBatchConvenienceWithRecognizeLinkedEntitiesOptionsStatisticsTestAsync.json @@ -0,0 +1,160 @@ +{ + "Entries": [ + { + "RequestUri": "https://ta-s-westeurope.cognitiveservices.azure.com/text/analytics/v3.1-preview.4/entities/linking?showStats=true\u0026stringIndexType=Utf16CodeUnit", + "RequestMethod": "POST", + "RequestHeaders": { + "Accept": "application/json, text/json", + "Content-Length": "192", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-f1ed184f8511cc4bab3f25735f13e8f6-b4d9214567a59042-00", + "User-Agent": "azsdk-net-AI.TextAnalytics/5.1.0-alpha.20210224.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19042 )", + "x-ms-client-request-id": "efbfe45b25f6d2a2775e1edd2fe4e7aa", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "id": "0", + "text": "Microsoft was founded by Bill Gates and Paul Allen.", + "language": "en" + }, + { + "id": "1", + "text": "Pike place market is my favorite Seattle attraction.", + "language": "en" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "52061967-7dc4-4260-a497-677f09b5deb0", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=2", + "Date": "Wed, 24 Feb 2021 16:57:36 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "x-content-type-options": "nosniff", + "x-envoy-upstream-service-time": "26" + }, + "ResponseBody": { + "statistics": { + "documentsCount": 2, + "validDocumentsCount": 2, + "erroneousDocumentsCount": 0, + "transactionsCount": 2 + }, + "documents": [ + { + "id": "0", + "statistics": { + "charactersCount": 51, + "transactionsCount": 1 + }, + "entities": [ + { + "bingId": "a093e9b9-90f5-a3d5-c4b8-5855e1b01f85", + "name": "Microsoft", + "matches": [ + { + "text": "Microsoft", + "offset": 0, + "length": 9, + "confidenceScore": 0.49 + } + ], + "language": "en", + "id": "Microsoft", + "url": "https://en.wikipedia.org/wiki/Microsoft", + "dataSource": "Wikipedia" + }, + { + "bingId": "0d47c987-0042-5576-15e8-97af601614fa", + "name": "Bill Gates", + "matches": [ + { + "text": "Bill Gates", + "offset": 25, + "length": 10, + "confidenceScore": 0.52 + } + ], + "language": "en", + "id": "Bill Gates", + "url": "https://en.wikipedia.org/wiki/Bill_Gates", + "dataSource": "Wikipedia" + }, + { + "bingId": "df2c4376-9923-6a54-893f-2ee5a5badbc7", + "name": "Paul Allen", + "matches": [ + { + "text": "Paul Allen", + "offset": 40, + "length": 10, + "confidenceScore": 0.54 + } + ], + "language": "en", + "id": "Paul Allen", + "url": "https://en.wikipedia.org/wiki/Paul_Allen", + "dataSource": "Wikipedia" + } + ], + "warnings": [] + }, + { + "id": "1", + "statistics": { + "charactersCount": 52, + "transactionsCount": 1 + }, + "entities": [ + { + "bingId": "38b9431e-cf91-93be-0584-c42a3ecbfdc7", + "name": "Pike Place Market", + "matches": [ + { + "text": "Pike place market", + "offset": 0, + "length": 17, + "confidenceScore": 0.86 + } + ], + "language": "en", + "id": "Pike Place Market", + "url": "https://en.wikipedia.org/wiki/Pike_Place_Market", + "dataSource": "Wikipedia" + }, + { + "bingId": "5fbba6b8-85e1-4d41-9444-d9055436e473", + "name": "Seattle", + "matches": [ + { + "text": "Seattle", + "offset": 33, + "length": 7, + "confidenceScore": 0.27 + } + ], + "language": "en", + "id": "Seattle", + "url": "https://en.wikipedia.org/wiki/Seattle", + "dataSource": "Wikipedia" + } + ], + "warnings": [] + } + ], + "errors": [], + "modelVersion": "2020-02-01" + } + } + ], + "Variables": { + "RandomSeed": "1003575897", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://ta-s-westeurope.cognitiveservices.azure.com" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeLinkedEntitiesTests/RecognizeLinkedEntitiesBatchWithRecognizeLinkedEntitiesOptionsStatisticsTest.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeLinkedEntitiesTests/RecognizeLinkedEntitiesBatchWithRecognizeLinkedEntitiesOptionsStatisticsTest.json new file mode 100644 index 0000000000000..2639fd2255d76 --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeLinkedEntitiesTests/RecognizeLinkedEntitiesBatchWithRecognizeLinkedEntitiesOptionsStatisticsTest.json @@ -0,0 +1,176 @@ +{ + "Entries": [ + { + "RequestUri": "https://ta-s-westeurope.cognitiveservices.azure.com/text/analytics/v3.1-preview.4/entities/linking?showStats=true\u0026stringIndexType=Utf16CodeUnit", + "RequestMethod": "POST", + "RequestHeaders": { + "Accept": "application/json, text/json", + "Content-Length": "190", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-6b7f7d13b53e324f97a4104b74b04c49-6d01eec9ad3f4a4d-00", + "User-Agent": "azsdk-net-AI.TextAnalytics/5.1.0-alpha.20210224.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19042 )", + "x-ms-client-request-id": "07178a1f00e9eae492911a1486f7f75f", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "id": "1", + "text": "Microsoft was founded by Bill Gates and Paul Allen.", + "language": "en" + }, + { + "id": "3", + "text": "Microsoft fue fundado por Bill Gates y Paul Allen.", + "language": "es" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "7675f493-d24c-46e2-a984-f1e5b6a13f11", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=2", + "Date": "Wed, 24 Feb 2021 16:57:34 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "x-content-type-options": "nosniff", + "x-envoy-upstream-service-time": "32" + }, + "ResponseBody": { + "statistics": { + "documentsCount": 2, + "validDocumentsCount": 2, + "erroneousDocumentsCount": 0, + "transactionsCount": 2 + }, + "documents": [ + { + "id": "1", + "statistics": { + "charactersCount": 51, + "transactionsCount": 1 + }, + "entities": [ + { + "bingId": "a093e9b9-90f5-a3d5-c4b8-5855e1b01f85", + "name": "Microsoft", + "matches": [ + { + "text": "Microsoft", + "offset": 0, + "length": 9, + "confidenceScore": 0.49 + } + ], + "language": "en", + "id": "Microsoft", + "url": "https://en.wikipedia.org/wiki/Microsoft", + "dataSource": "Wikipedia" + }, + { + "bingId": "0d47c987-0042-5576-15e8-97af601614fa", + "name": "Bill Gates", + "matches": [ + { + "text": "Bill Gates", + "offset": 25, + "length": 10, + "confidenceScore": 0.52 + } + ], + "language": "en", + "id": "Bill Gates", + "url": "https://en.wikipedia.org/wiki/Bill_Gates", + "dataSource": "Wikipedia" + }, + { + "bingId": "df2c4376-9923-6a54-893f-2ee5a5badbc7", + "name": "Paul Allen", + "matches": [ + { + "text": "Paul Allen", + "offset": 40, + "length": 10, + "confidenceScore": 0.54 + } + ], + "language": "en", + "id": "Paul Allen", + "url": "https://en.wikipedia.org/wiki/Paul_Allen", + "dataSource": "Wikipedia" + } + ], + "warnings": [] + }, + { + "id": "3", + "statistics": { + "charactersCount": 50, + "transactionsCount": 1 + }, + "entities": [ + { + "bingId": "a093e9b9-90f5-a3d5-c4b8-5855e1b01f85", + "name": "Microsoft", + "matches": [ + { + "text": "Microsoft", + "offset": 0, + "length": 9, + "confidenceScore": 0.38 + } + ], + "language": "es", + "id": "Microsoft", + "url": "https://es.wikipedia.org/wiki/Microsoft", + "dataSource": "Wikipedia" + }, + { + "bingId": "0d47c987-0042-5576-15e8-97af601614fa", + "name": "Bill Gates", + "matches": [ + { + "text": "Bill Gates", + "offset": 26, + "length": 10, + "confidenceScore": 0.37 + } + ], + "language": "es", + "id": "Bill Gates", + "url": "https://es.wikipedia.org/wiki/Bill_Gates", + "dataSource": "Wikipedia" + }, + { + "bingId": "df2c4376-9923-6a54-893f-2ee5a5badbc7", + "name": "Paul Allen", + "matches": [ + { + "text": "Paul Allen", + "offset": 39, + "length": 10, + "confidenceScore": 0.9 + } + ], + "language": "es", + "id": "Paul Allen", + "url": "https://es.wikipedia.org/wiki/Paul_Allen", + "dataSource": "Wikipedia" + } + ], + "warnings": [] + } + ], + "errors": [], + "modelVersion": "2020-02-01" + } + } + ], + "Variables": { + "RandomSeed": "775198464", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://ta-s-westeurope.cognitiveservices.azure.com" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeLinkedEntitiesTests/RecognizeLinkedEntitiesBatchWithRecognizeLinkedEntitiesOptionsStatisticsTestAsync.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeLinkedEntitiesTests/RecognizeLinkedEntitiesBatchWithRecognizeLinkedEntitiesOptionsStatisticsTestAsync.json new file mode 100644 index 0000000000000..06149fdeb7257 --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeLinkedEntitiesTests/RecognizeLinkedEntitiesBatchWithRecognizeLinkedEntitiesOptionsStatisticsTestAsync.json @@ -0,0 +1,176 @@ +{ + "Entries": [ + { + "RequestUri": "https://ta-s-westeurope.cognitiveservices.azure.com/text/analytics/v3.1-preview.4/entities/linking?showStats=true\u0026stringIndexType=Utf16CodeUnit", + "RequestMethod": "POST", + "RequestHeaders": { + "Accept": "application/json, text/json", + "Content-Length": "190", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-95f67674ad4fb44081d09f1041236c3b-9fa5ef699193254a-00", + "User-Agent": "azsdk-net-AI.TextAnalytics/5.1.0-alpha.20210224.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19042 )", + "x-ms-client-request-id": "c81f2c7c8424b466b144609b6251448a", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "id": "1", + "text": "Microsoft was founded by Bill Gates and Paul Allen.", + "language": "en" + }, + { + "id": "3", + "text": "Microsoft fue fundado por Bill Gates y Paul Allen.", + "language": "es" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "d5449c39-e433-4454-bffe-390bc877401c", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=2", + "Date": "Wed, 24 Feb 2021 16:57:38 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "x-content-type-options": "nosniff", + "x-envoy-upstream-service-time": "24" + }, + "ResponseBody": { + "statistics": { + "documentsCount": 2, + "validDocumentsCount": 2, + "erroneousDocumentsCount": 0, + "transactionsCount": 2 + }, + "documents": [ + { + "id": "1", + "statistics": { + "charactersCount": 51, + "transactionsCount": 1 + }, + "entities": [ + { + "bingId": "a093e9b9-90f5-a3d5-c4b8-5855e1b01f85", + "name": "Microsoft", + "matches": [ + { + "text": "Microsoft", + "offset": 0, + "length": 9, + "confidenceScore": 0.49 + } + ], + "language": "en", + "id": "Microsoft", + "url": "https://en.wikipedia.org/wiki/Microsoft", + "dataSource": "Wikipedia" + }, + { + "bingId": "0d47c987-0042-5576-15e8-97af601614fa", + "name": "Bill Gates", + "matches": [ + { + "text": "Bill Gates", + "offset": 25, + "length": 10, + "confidenceScore": 0.52 + } + ], + "language": "en", + "id": "Bill Gates", + "url": "https://en.wikipedia.org/wiki/Bill_Gates", + "dataSource": "Wikipedia" + }, + { + "bingId": "df2c4376-9923-6a54-893f-2ee5a5badbc7", + "name": "Paul Allen", + "matches": [ + { + "text": "Paul Allen", + "offset": 40, + "length": 10, + "confidenceScore": 0.54 + } + ], + "language": "en", + "id": "Paul Allen", + "url": "https://en.wikipedia.org/wiki/Paul_Allen", + "dataSource": "Wikipedia" + } + ], + "warnings": [] + }, + { + "id": "3", + "statistics": { + "charactersCount": 50, + "transactionsCount": 1 + }, + "entities": [ + { + "bingId": "a093e9b9-90f5-a3d5-c4b8-5855e1b01f85", + "name": "Microsoft", + "matches": [ + { + "text": "Microsoft", + "offset": 0, + "length": 9, + "confidenceScore": 0.38 + } + ], + "language": "es", + "id": "Microsoft", + "url": "https://es.wikipedia.org/wiki/Microsoft", + "dataSource": "Wikipedia" + }, + { + "bingId": "0d47c987-0042-5576-15e8-97af601614fa", + "name": "Bill Gates", + "matches": [ + { + "text": "Bill Gates", + "offset": 26, + "length": 10, + "confidenceScore": 0.37 + } + ], + "language": "es", + "id": "Bill Gates", + "url": "https://es.wikipedia.org/wiki/Bill_Gates", + "dataSource": "Wikipedia" + }, + { + "bingId": "df2c4376-9923-6a54-893f-2ee5a5badbc7", + "name": "Paul Allen", + "matches": [ + { + "text": "Paul Allen", + "offset": 39, + "length": 10, + "confidenceScore": 0.9 + } + ], + "language": "es", + "id": "Paul Allen", + "url": "https://es.wikipedia.org/wiki/Paul_Allen", + "dataSource": "Wikipedia" + } + ], + "warnings": [] + } + ], + "errors": [], + "modelVersion": "2020-02-01" + } + } + ], + "Variables": { + "RandomSeed": "1369620328", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://ta-s-westeurope.cognitiveservices.azure.com" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientTests.cs index 84c5a1ce94bb0..5ac07660ed012 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientTests.cs @@ -71,12 +71,21 @@ public void RecognizePiiEntitiesArgumentValidation() [Test] public void AnalyzeSentimentArgumentValidation() { - var documents = new List(); Assert.ThrowsAsync(() => Client.AnalyzeSentimentAsync("")); - Assert.ThrowsAsync(() => Client.AnalyzeSentimentAsync((string)null)); - Assert.ThrowsAsync(() => Client.AnalyzeSentimentBatchAsync((List)null)); - Assert.ThrowsAsync(() => Client.AnalyzeSentimentBatchAsync(documents)); + Assert.ThrowsAsync(() => Client.AnalyzeSentimentAsync(null)); + + Assert.ThrowsAsync(() => Client.AnalyzeSentimentBatchAsync((string[])null)); + Assert.ThrowsAsync(() => Client.AnalyzeSentimentBatchAsync((string[])null)); + Assert.ThrowsAsync(() => Client.AnalyzeSentimentBatchAsync(Array.Empty())); + Assert.ThrowsAsync(() => Client.AnalyzeSentimentBatchAsync(Array.Empty())); Assert.ThrowsAsync(() => Client.AnalyzeSentimentBatchAsync(null, new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.AnalyzeSentimentBatchAsync(null, new AnalyzeSentimentOptions())); + + // Variations to ensure call-compatibility after adding method-specific options class to parameters. + Assert.ThrowsAsync(() => Client.AnalyzeSentimentBatchAsync(null, options: new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.AnalyzeSentimentBatchAsync(null, null, new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.AnalyzeSentimentBatchAsync(null, new AnalyzeSentimentOptions())); + Assert.ThrowsAsync(() => Client.AnalyzeSentimentBatchAsync(null, null, new AnalyzeSentimentOptions())); } [Test] @@ -84,7 +93,7 @@ public void ExtractKeyPhrasesArgumentValidation() { var documents = new List(); Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesAsync("")); - Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesAsync((string)null)); + Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesAsync(null)); Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync((List)null)); Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync(documents)); Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync(null, new TextAnalyticsRequestOptions())); @@ -93,12 +102,23 @@ public void ExtractKeyPhrasesArgumentValidation() [Test] public void RecognizeLinkedEntitiesArgumentValidation() { - var documents = new List(); Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesAsync("")); - Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesAsync((string)null)); - Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesBatchAsync((List)null)); - Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesBatchAsync(documents)); - Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesBatchAsync(null, new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesAsync(null)); + Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesBatchAsync((string[])null)); + Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesBatchAsync((string[])null)); + Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesBatchAsync(Array.Empty())); + Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesBatchAsync(Array.Empty())); + Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesBatchAsync((string[])null, new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesBatchAsync((TextDocumentInput[])null, new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesBatchAsync((string[])null, new RecognizeLinkedEntitiesOptions())); + Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesBatchAsync(null, new RecognizeLinkedEntitiesOptions())); + + // Variations to ensure call-compatibility after adding method-specific options class to parameters. + Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesBatchAsync((string[])null, options: new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesBatchAsync((TextDocumentInput[])null, options: new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesBatchAsync(null, null, new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesBatchAsync(null, new RecognizeLinkedEntitiesOptions())); + Assert.ThrowsAsync(() => Client.RecognizeLinkedEntitiesBatchAsync(null, null, new RecognizeLinkedEntitiesOptions())); } } } From dc02f95ca0fcdcb5c5f50a589bb508344d2cf9e0 Mon Sep 17 00:00:00 2001 From: Heath Stewart Date: Thu, 1 Apr 2021 16:46:30 -0700 Subject: [PATCH 2/6] Assert options are no different --- .../tests/RecognizeLinkedEntitiesTests.cs | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeLinkedEntitiesTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeLinkedEntitiesTests.cs index 7f2d96ed4b352..a2b7f8d5a9445 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeLinkedEntitiesTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeLinkedEntitiesTests.cs @@ -136,8 +136,9 @@ public async Task RecognizeLinkedEntitiesBatchConvenienceTest() [Test] public async Task RecognizeLinkedEntitiesBatchConvenienceWithStatisticsTest() { + TextAnalyticsRequestOptions options = new TextAnalyticsRequestOptions { IncludeStatistics = true }; TextAnalyticsClient client = GetClient(); - RecognizeLinkedEntitiesResultCollection results = await client.RecognizeLinkedEntitiesBatchAsync(s_batchConvenienceDocuments, "en", new TextAnalyticsRequestOptions { IncludeStatistics = true }); + RecognizeLinkedEntitiesResultCollection results = await client.RecognizeLinkedEntitiesBatchAsync(s_batchConvenienceDocuments, "en", options); var expectedOutput = new Dictionary>() { @@ -146,13 +147,19 @@ public async Task RecognizeLinkedEntitiesBatchConvenienceWithStatisticsTest() }; ValidateBatchDocumentsResult(results, expectedOutput, includeStatistics: true); + + // Assert the options classes since overloads were added and the original now instantiates a RecognizeLinkedEntitiesOptions. + Assert.IsTrue(options.IncludeStatistics); + Assert.IsNull(options.ModelVersion); + Assert.AreEqual(StringIndexType.Utf16CodeUnit, options.StringIndexType); } [Test] public async Task RecognizeLinkedEntitiesBatchConvenienceWithRecognizeLinkedEntitiesOptionsStatisticsTest() { + RecognizeLinkedEntitiesOptions options = new RecognizeLinkedEntitiesOptions { IncludeStatistics = true }; TextAnalyticsClient client = GetClient(); - RecognizeLinkedEntitiesResultCollection results = await client.RecognizeLinkedEntitiesBatchAsync(s_batchConvenienceDocuments, "en", new RecognizeLinkedEntitiesOptions { IncludeStatistics = true }); + RecognizeLinkedEntitiesResultCollection results = await client.RecognizeLinkedEntitiesBatchAsync(s_batchConvenienceDocuments, "en", options); var expectedOutput = new Dictionary>() { @@ -161,6 +168,11 @@ public async Task RecognizeLinkedEntitiesBatchConvenienceWithRecognizeLinkedEnti }; ValidateBatchDocumentsResult(results, expectedOutput, includeStatistics: true); + + // Assert the options classes since overloads were added and the original now instantiates a RecognizeLinkedEntitiesOptions. + Assert.IsTrue(options.IncludeStatistics); + Assert.IsNull(options.ModelVersion); + Assert.AreEqual(StringIndexType.Utf16CodeUnit, options.StringIndexType); } [Test] @@ -181,8 +193,9 @@ public async Task RecognizeLinkedEntitiesBatchTest() [Test] public async Task RecognizeLinkedEntitiesBatchWithStatisticsTest() { + TextAnalyticsRequestOptions options = new TextAnalyticsRequestOptions { IncludeStatistics = true }; TextAnalyticsClient client = GetClient(); - RecognizeLinkedEntitiesResultCollection results = await client.RecognizeLinkedEntitiesBatchAsync(s_batchDocuments, new TextAnalyticsRequestOptions { IncludeStatistics = true }); + RecognizeLinkedEntitiesResultCollection results = await client.RecognizeLinkedEntitiesBatchAsync(s_batchDocuments, options); var expectedOutput = new Dictionary>() { @@ -191,13 +204,19 @@ public async Task RecognizeLinkedEntitiesBatchWithStatisticsTest() }; ValidateBatchDocumentsResult(results, expectedOutput, includeStatistics: true); + + // Assert the options classes since overloads were added and the original now instantiates a RecognizeLinkedEntitiesOptions. + Assert.IsTrue(options.IncludeStatistics); + Assert.IsNull(options.ModelVersion); + Assert.AreEqual(StringIndexType.Utf16CodeUnit, options.StringIndexType); } [Test] public async Task RecognizeLinkedEntitiesBatchWithRecognizeLinkedEntitiesOptionsStatisticsTest() { + RecognizeLinkedEntitiesOptions options = new RecognizeLinkedEntitiesOptions { IncludeStatistics = true }; TextAnalyticsClient client = GetClient(); - RecognizeLinkedEntitiesResultCollection results = await client.RecognizeLinkedEntitiesBatchAsync(s_batchDocuments, new RecognizeLinkedEntitiesOptions { IncludeStatistics = true }); + RecognizeLinkedEntitiesResultCollection results = await client.RecognizeLinkedEntitiesBatchAsync(s_batchDocuments, options); var expectedOutput = new Dictionary>() { @@ -206,6 +225,11 @@ public async Task RecognizeLinkedEntitiesBatchWithRecognizeLinkedEntitiesOptions }; ValidateBatchDocumentsResult(results, expectedOutput, includeStatistics: true); + + // Assert the options classes since overloads were added and the original now instantiates a RecognizeLinkedEntitiesOptions. + Assert.IsTrue(options.IncludeStatistics); + Assert.IsNull(options.ModelVersion); + Assert.AreEqual(StringIndexType.Utf16CodeUnit, options.StringIndexType); } [Test] From bfa34444d3c6679091f61cc89c539d553b92ef15 Mon Sep 17 00:00:00 2001 From: Heath Stewart Date: Thu, 1 Apr 2021 17:06:05 -0700 Subject: [PATCH 3/6] Fix build issues * Update public APIs * Fix nuget error in DemoApp by not packing it (non-shipping) --- .../demo/DemoApp.csproj | 1 + .../Azure.AI.TextAnalytics.netstandard2.0.cs | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics.Protocol/demo/DemoApp.csproj b/sdk/textanalytics/Azure.AI.TextAnalytics.Protocol/demo/DemoApp.csproj index 841cc5685d4d1..fa4831fd405ce 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics.Protocol/demo/DemoApp.csproj +++ b/sdk/textanalytics/Azure.AI.TextAnalytics.Protocol/demo/DemoApp.csproj @@ -3,6 +3,7 @@ Exe net5.0 + false diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/api/Azure.AI.TextAnalytics.netstandard2.0.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/api/Azure.AI.TextAnalytics.netstandard2.0.cs index 67a512568598c..0902360c011f9 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/api/Azure.AI.TextAnalytics.netstandard2.0.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/api/Azure.AI.TextAnalytics.netstandard2.0.cs @@ -734,10 +734,22 @@ public TextAnalyticsClient(System.Uri endpoint, Azure.Core.TokenCredential crede public virtual System.Threading.Tasks.Task> RecognizeEntitiesBatchAsync(System.Collections.Generic.IEnumerable documents, string language = null, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response RecognizeLinkedEntities(string document, string language = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> RecognizeLinkedEntitiesAsync(string document, string language = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RecognizeLinkedEntitiesBatch(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RecognizeLinkedEntitiesBatch(System.Collections.Generic.IEnumerable documents, string language = null, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RecognizeLinkedEntitiesBatchAsync(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RecognizeLinkedEntitiesBatchAsync(System.Collections.Generic.IEnumerable documents, string language = null, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RecognizeLinkedEntitiesBatch(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.RecognizeLinkedEntitiesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual Azure.Response RecognizeLinkedEntitiesBatch(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual Azure.Response RecognizeLinkedEntitiesBatch(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RecognizeLinkedEntitiesBatch(System.Collections.Generic.IEnumerable documents, string language = null, Azure.AI.TextAnalytics.RecognizeLinkedEntitiesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual Azure.Response RecognizeLinkedEntitiesBatch(System.Collections.Generic.IEnumerable documents, string language, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RecognizeLinkedEntitiesBatchAsync(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.RecognizeLinkedEntitiesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual System.Threading.Tasks.Task> RecognizeLinkedEntitiesBatchAsync(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual System.Threading.Tasks.Task> RecognizeLinkedEntitiesBatchAsync(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RecognizeLinkedEntitiesBatchAsync(System.Collections.Generic.IEnumerable documents, string language = null, Azure.AI.TextAnalytics.RecognizeLinkedEntitiesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual System.Threading.Tasks.Task> RecognizeLinkedEntitiesBatchAsync(System.Collections.Generic.IEnumerable documents, string language, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response RecognizePiiEntities(string document, string language = null, Azure.AI.TextAnalytics.RecognizePiiEntitiesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> RecognizePiiEntitiesAsync(string document, string language = null, Azure.AI.TextAnalytics.RecognizePiiEntitiesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response RecognizePiiEntitiesBatch(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.RecognizePiiEntitiesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } From 9c71b4a881899fcca32470879505063389badf90 Mon Sep 17 00:00:00 2001 From: Heath Stewart Date: Thu, 1 Apr 2021 18:16:38 -0700 Subject: [PATCH 4/6] Use RecognizeEntitiesOptions in new overloads --- .../Azure.AI.TextAnalytics.netstandard2.0.cs | 20 +- .../src/TextAnalyticsClient.cs | 178 +++++++++++++++++- .../tests/RecognizeEntitiesTests.cs | 92 ++++++++- ...ecognizeEntitiesOptionsStatisticsTest.json | 108 +++++++++++ ...izeEntitiesOptionsStatisticsTestAsync.json | 108 +++++++++++ ...ecognizeEntitiesOptionsStatisticsTest.json | 122 ++++++++++++ ...izeEntitiesOptionsStatisticsTestAsync.json | 122 ++++++++++++ ...cognizeEntitiesOptionsSubCategoryTest.json | 78 ++++++++ ...zeEntitiesOptionsSubCategoryTestAsync.json | 78 ++++++++ .../tests/TextAnalyticsClientTests.cs | 46 +++-- 10 files changed, 921 insertions(+), 31 deletions(-) create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesBatchConvenienceWithRecognizeEntitiesOptionsStatisticsTest.json create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesBatchConvenienceWithRecognizeEntitiesOptionsStatisticsTestAsync.json create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesBatchWithRecognizeEntitiesOptionsStatisticsTest.json create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesBatchWithRecognizeEntitiesOptionsStatisticsTestAsync.json create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesWithRecognizeEntitiesOptionsSubCategoryTest.json create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesWithRecognizeEntitiesOptionsSubCategoryTestAsync.json diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/api/Azure.AI.TextAnalytics.netstandard2.0.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/api/Azure.AI.TextAnalytics.netstandard2.0.cs index 0902360c011f9..f807c2d5cf1ac 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/api/Azure.AI.TextAnalytics.netstandard2.0.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/api/Azure.AI.TextAnalytics.netstandard2.0.cs @@ -728,10 +728,22 @@ public TextAnalyticsClient(System.Uri endpoint, Azure.Core.TokenCredential crede public override int GetHashCode() { throw null; } public virtual Azure.Response RecognizeEntities(string document, string language = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> RecognizeEntitiesAsync(string document, string language = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RecognizeEntitiesBatch(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response RecognizeEntitiesBatch(System.Collections.Generic.IEnumerable documents, string language = null, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RecognizeEntitiesBatchAsync(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> RecognizeEntitiesBatchAsync(System.Collections.Generic.IEnumerable documents, string language = null, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RecognizeEntitiesBatch(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.RecognizeEntitiesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual Azure.Response RecognizeEntitiesBatch(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual Azure.Response RecognizeEntitiesBatch(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response RecognizeEntitiesBatch(System.Collections.Generic.IEnumerable documents, string language = null, Azure.AI.TextAnalytics.RecognizeEntitiesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual Azure.Response RecognizeEntitiesBatch(System.Collections.Generic.IEnumerable documents, string language, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RecognizeEntitiesBatchAsync(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.RecognizeEntitiesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual System.Threading.Tasks.Task> RecognizeEntitiesBatchAsync(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual System.Threading.Tasks.Task> RecognizeEntitiesBatchAsync(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> RecognizeEntitiesBatchAsync(System.Collections.Generic.IEnumerable documents, string language = null, Azure.AI.TextAnalytics.RecognizeEntitiesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual System.Threading.Tasks.Task> RecognizeEntitiesBatchAsync(System.Collections.Generic.IEnumerable documents, string language, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response RecognizeLinkedEntities(string document, string language = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> RecognizeLinkedEntitiesAsync(string document, string language = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response RecognizeLinkedEntitiesBatch(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.RecognizeLinkedEntitiesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs index 16e658f5a52fc..e0755cb3749f6 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs @@ -501,6 +501,30 @@ public virtual Response RecognizeEntities(string do } } + /// + /// Runs a predictive model to identify a collection of named entities + /// in the passed-in documents, and categorize those entities into types + /// such as person, location, or organization. + /// For more information on available categories, see + /// . + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of entities identified + /// for each of the documents, as well as scores indicating the confidence + /// that a given entity correctly matches the identified substring. + /// Service returned a non-success + /// status code. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual async Task> RecognizeEntitiesBatchAsync(IEnumerable documents, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) => + await RecognizeEntitiesBatchAsync(documents, null, options, cancellationToken).ConfigureAwait(false); + /// /// Runs a predictive model to identify a collection of named entities /// in the passed-in documents, and categorize those entities into types @@ -528,10 +552,11 @@ public virtual Response RecognizeEntities(string do /// that a given entity correctly matches the identified substring. /// Service returned a non-success /// status code. - public virtual async Task> RecognizeEntitiesBatchAsync(IEnumerable documents, string language = default, TextAnalyticsRequestOptions options = default, CancellationToken cancellationToken = default) + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual async Task> RecognizeEntitiesBatchAsync(IEnumerable documents, string language, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(documents, nameof(documents)); - options ??= new TextAnalyticsRequestOptions(); + options ??= new RecognizeEntitiesOptions(); MultiLanguageBatchInput documentInputs = ConvertToMultiLanguageInputs(documents, language); return await RecognizeEntitiesBatchAsync(documentInputs, options, cancellationToken).ConfigureAwait(false); @@ -554,6 +579,29 @@ public virtual async Task> Recognize /// language in in the request /// sent to the service. If set to an empty string, the service will apply a model /// where the language is explicitly set to "None". + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of entities identified + /// for each of the documents, as well as scores indicating the confidence + /// that a given entity correctly matches the identified substring. + /// Service returned a non-success + /// status code. + public virtual async Task> RecognizeEntitiesBatchAsync(IEnumerable documents, string language = default, RecognizeEntitiesOptions options = default, CancellationToken cancellationToken = default) => + await RecognizeEntitiesBatchAsync(documents, language, (TextAnalyticsRequestOptions)options, cancellationToken).ConfigureAwait(false); + + /// + /// Runs a predictive model to identify a collection of named entities + /// in the passed-in documents, and categorize those entities into types + /// such as person, location, or organization. + /// For more information on available categories, see + /// . + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. /// used to /// select the version of the predictive model to run, and whether /// statistics are returned in the response. @@ -564,15 +612,77 @@ public virtual async Task> Recognize /// that a given entity correctly matches the identified substring. /// Service returned a non-success /// status code. - public virtual Response RecognizeEntitiesBatch(IEnumerable documents, string language = default, TextAnalyticsRequestOptions options = default, CancellationToken cancellationToken = default) + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual Response RecognizeEntitiesBatch(IEnumerable documents, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) => + RecognizeEntitiesBatch(documents, null, options, cancellationToken); + + /// + /// Runs a predictive model to identify a collection of named entities + /// in the passed-in documents, and categorize those entities into types + /// such as person, location, or organization. + /// For more information on available categories, see + /// . + /// For a list of languages supported by this operation, see + /// . + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// The language that all the documents are + /// written in. If unspecified, this value will be set to the default + /// language in in the request + /// sent to the service. If set to an empty string, the service will apply a model + /// where the language is explicitly set to "None". + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of entities identified + /// for each of the documents, as well as scores indicating the confidence + /// that a given entity correctly matches the identified substring. + /// Service returned a non-success + /// status code. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual Response RecognizeEntitiesBatch(IEnumerable documents, string language, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(documents, nameof(documents)); - options ??= new TextAnalyticsRequestOptions(); + options ??= new RecognizeEntitiesOptions(); MultiLanguageBatchInput documentInputs = ConvertToMultiLanguageInputs(documents, language); return RecognizeEntitiesBatch(documentInputs, options, cancellationToken); } + /// + /// Runs a predictive model to identify a collection of named entities + /// in the passed-in documents, and categorize those entities into types + /// such as person, location, or organization. + /// For more information on available categories, see + /// . + /// For a list of languages supported by this operation, see + /// . + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// The language that all the documents are + /// written in. If unspecified, this value will be set to the default + /// language in in the request + /// sent to the service. If set to an empty string, the service will apply a model + /// where the language is explicitly set to "None". + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of entities identified + /// for each of the documents, as well as scores indicating the confidence + /// that a given entity correctly matches the identified substring. + /// Service returned a non-success + /// status code. + public virtual Response RecognizeEntitiesBatch(IEnumerable documents, string language = default, RecognizeEntitiesOptions options = default, CancellationToken cancellationToken = default) => + RecognizeEntitiesBatch(documents, language, (TextAnalyticsRequestOptions)options, cancellationToken); + /// /// Runs a predictive model to identify a collection of named entities /// in the passed-in documents, and categorize those entities into types @@ -595,15 +705,41 @@ public virtual Response RecognizeEntitiesBatc /// that a given entity correctly matches the identified substring. /// Service returned a non-success /// status code. - public virtual async Task> RecognizeEntitiesBatchAsync(IEnumerable documents, TextAnalyticsRequestOptions options = default, CancellationToken cancellationToken = default) + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual async Task> RecognizeEntitiesBatchAsync(IEnumerable documents, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(documents, nameof(documents)); - options ??= new TextAnalyticsRequestOptions(); + options ??= new RecognizeEntitiesOptions(); MultiLanguageBatchInput documentInputs = ConvertToMultiLanguageInputs(documents); return await RecognizeEntitiesBatchAsync(documentInputs, options, cancellationToken).ConfigureAwait(false); } + /// + /// Runs a predictive model to identify a collection of named entities + /// in the passed-in documents, and categorize those entities into types + /// such as person, location, or organization. + /// For more information on available categories, see + /// . + /// For a list of languages supported by this operation, see + /// . + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of entities identified + /// for each of the documents, as well as scores indicating the confidence + /// that a given entity correctly matches the identified substring. + /// Service returned a non-success + /// status code. + public virtual async Task> RecognizeEntitiesBatchAsync(IEnumerable documents, RecognizeEntitiesOptions options = default, CancellationToken cancellationToken = default) => + await RecognizeEntitiesBatchAsync(documents, (TextAnalyticsRequestOptions)options, cancellationToken).ConfigureAwait(false); + /// /// Runs a predictive model to identify a collection of named entities /// in the passed-in documents, and categorize those entities into types @@ -626,15 +762,41 @@ public virtual async Task> Recognize /// that a given entity correctly matches the identified substring. /// Service returned a non-success /// status code. - public virtual Response RecognizeEntitiesBatch(IEnumerable documents, TextAnalyticsRequestOptions options = default, CancellationToken cancellationToken = default) + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual Response RecognizeEntitiesBatch(IEnumerable documents, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(documents, nameof(documents)); - options ??= new TextAnalyticsRequestOptions(); + options ??= new RecognizeEntitiesOptions(); MultiLanguageBatchInput documentInputs = ConvertToMultiLanguageInputs(documents); return RecognizeEntitiesBatch(documentInputs, options, cancellationToken); } + /// + /// Runs a predictive model to identify a collection of named entities + /// in the passed-in documents, and categorize those entities into types + /// such as person, location, or organization. + /// For more information on available categories, see + /// . + /// For a list of languages supported by this operation, see + /// . + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of entities identified + /// for each of the documents, as well as scores indicating the confidence + /// that a given entity correctly matches the identified substring. + /// Service returned a non-success + /// status code. + public virtual Response RecognizeEntitiesBatch(IEnumerable documents, RecognizeEntitiesOptions options = default, CancellationToken cancellationToken = default) => + RecognizeEntitiesBatch(documents, (TextAnalyticsRequestOptions)options, cancellationToken); + private async Task> RecognizeEntitiesBatchAsync(MultiLanguageBatchInput batchInput, TextAnalyticsRequestOptions options, CancellationToken cancellationToken) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TextAnalyticsClient)}.{nameof(RecognizeEntitiesBatch)}"); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeEntitiesTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeEntitiesTests.cs index 655c4fb5bd78d..786bdf6a8f64a 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeEntitiesTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeEntitiesTests.cs @@ -78,10 +78,11 @@ public async Task RecognizeEntitiesWithLanguageTest() [Test] public async Task RecognizeEntitiesWithSubCategoryTest() { + TextAnalyticsRequestOptions options = new TextAnalyticsRequestOptions() { ModelVersion = "2020-04-01" }; TextAnalyticsClient client = GetClient(); string document = "I had a wonderful trip to Seattle last week."; - RecognizeEntitiesResultCollection result = await client.RecognizeEntitiesBatchAsync(new List() { document }, options: new TextAnalyticsRequestOptions() { ModelVersion = "2020-04-01" } ); + RecognizeEntitiesResultCollection result = await client.RecognizeEntitiesBatchAsync(new List() { document }, options: options ); var documentResult = result.FirstOrDefault(); Assert.IsFalse(documentResult.HasError); @@ -93,6 +94,37 @@ public async Task RecognizeEntitiesWithSubCategoryTest() if (entity.Text == "last week") Assert.AreEqual("DateRange", entity.SubCategory); } + + // Assert the options classes since overloads were added and the original now instantiates a RecognizeEntitiesOptions. + Assert.IsFalse(options.IncludeStatistics); + Assert.AreEqual("2020-04-01", options.ModelVersion); + Assert.AreEqual(StringIndexType.Utf16CodeUnit, options.StringIndexType); + } + + [Test] + public async Task RecognizeEntitiesWithRecognizeEntitiesOptionsSubCategoryTest() + { + RecognizeEntitiesOptions options = new RecognizeEntitiesOptions() { ModelVersion = "2020-04-01" }; + TextAnalyticsClient client = GetClient(); + string document = "I had a wonderful trip to Seattle last week."; + + RecognizeEntitiesResultCollection result = await client.RecognizeEntitiesBatchAsync(new List() { document }, options: options ); + + var documentResult = result.FirstOrDefault(); + Assert.IsFalse(documentResult.HasError); + + Assert.GreaterOrEqual(documentResult.Entities.Count, 3); + + foreach (CategorizedEntity entity in documentResult.Entities) + { + if (entity.Text == "last week") + Assert.AreEqual("DateRange", entity.SubCategory); + } + + // Assert the options classes since overloads were added and the original now instantiates a RecognizeEntitiesOptions. + Assert.IsFalse(options.IncludeStatistics); + Assert.AreEqual("2020-04-01", options.ModelVersion); + Assert.AreEqual(StringIndexType.Utf16CodeUnit, options.StringIndexType); } [Test] @@ -155,8 +187,30 @@ public async Task RecognizeEntitiesBatchConvenienceTest() [Test] public async Task RecognizeEntitiesBatchConvenienceWithStatisticsTest() { + TextAnalyticsRequestOptions options = new TextAnalyticsRequestOptions { IncludeStatistics = true }; + TextAnalyticsClient client = GetClient(); + RecognizeEntitiesResultCollection results = await client.RecognizeEntitiesBatchAsync(s_batchConvenienceDocuments, "en", options); + + var expectedOutput = new Dictionary>() + { + { "0", s_document1ExpectedOutput }, + { "1", s_document2ExpectedOutput }, + }; + + ValidateBatchDocumentsResult(results, expectedOutput, includeStatistics: true); + + // Assert the options classes since overloads were added and the original now instantiates a RecognizeEntitiesOptions. + Assert.IsTrue(options.IncludeStatistics); + Assert.IsNull(options.ModelVersion); + Assert.AreEqual(StringIndexType.Utf16CodeUnit, options.StringIndexType); + } + + [Test] + public async Task RecognizeEntitiesBatchConvenienceWithRecognizeEntitiesOptionsStatisticsTest() + { + RecognizeEntitiesOptions options = new RecognizeEntitiesOptions { IncludeStatistics = true }; TextAnalyticsClient client = GetClient(); - RecognizeEntitiesResultCollection results = await client.RecognizeEntitiesBatchAsync(s_batchConvenienceDocuments, "en", new TextAnalyticsRequestOptions { IncludeStatistics = true }); + RecognizeEntitiesResultCollection results = await client.RecognizeEntitiesBatchAsync(s_batchConvenienceDocuments, "en", options); var expectedOutput = new Dictionary>() { @@ -165,6 +219,11 @@ public async Task RecognizeEntitiesBatchConvenienceWithStatisticsTest() }; ValidateBatchDocumentsResult(results, expectedOutput, includeStatistics: true); + + // Assert the options classes since overloads were added and the original now instantiates a RecognizeEntitiesOptions. + Assert.IsTrue(options.IncludeStatistics); + Assert.IsNull(options.ModelVersion); + Assert.AreEqual(StringIndexType.Utf16CodeUnit, options.StringIndexType); } [Test] @@ -185,8 +244,9 @@ public async Task RecognizeEntitiesBatchTest() [Test] public async Task RecognizeEntitiesBatchWithStatisticsTest() { + TextAnalyticsRequestOptions options = new TextAnalyticsRequestOptions { IncludeStatistics = true }; TextAnalyticsClient client = GetClient(); - RecognizeEntitiesResultCollection results = await client.RecognizeEntitiesBatchAsync(s_batchDocuments, new TextAnalyticsRequestOptions { IncludeStatistics = true }); + RecognizeEntitiesResultCollection results = await client.RecognizeEntitiesBatchAsync(s_batchDocuments, options); var expectedOutput = new Dictionary>() { @@ -195,6 +255,32 @@ public async Task RecognizeEntitiesBatchWithStatisticsTest() }; ValidateBatchDocumentsResult(results, expectedOutput, includeStatistics: true); + + // Assert the options classes since overloads were added and the original now instantiates a RecognizeEntitiesOptions. + Assert.IsTrue(options.IncludeStatistics); + Assert.IsNull(options.ModelVersion); + Assert.AreEqual(StringIndexType.Utf16CodeUnit, options.StringIndexType); + } + + [Test] + public async Task RecognizeEntitiesBatchWithRecognizeEntitiesOptionsStatisticsTest() + { + RecognizeEntitiesOptions options = new RecognizeEntitiesOptions { IncludeStatistics = true }; + TextAnalyticsClient client = GetClient(); + RecognizeEntitiesResultCollection results = await client.RecognizeEntitiesBatchAsync(s_batchDocuments, options); + + var expectedOutput = new Dictionary>() + { + { "1", s_document1ExpectedOutput }, + { "2", s_document1ExpectedOutput }, + }; + + ValidateBatchDocumentsResult(results, expectedOutput, includeStatistics: true); + + // Assert the options classes since overloads were added and the original now instantiates a RecognizeEntitiesOptions. + Assert.IsTrue(options.IncludeStatistics); + Assert.IsNull(options.ModelVersion); + Assert.AreEqual(StringIndexType.Utf16CodeUnit, options.StringIndexType); } [Test] diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesBatchConvenienceWithRecognizeEntitiesOptionsStatisticsTest.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesBatchConvenienceWithRecognizeEntitiesOptionsStatisticsTest.json new file mode 100644 index 0000000000000..434a1ed936d5d --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesBatchConvenienceWithRecognizeEntitiesOptionsStatisticsTest.json @@ -0,0 +1,108 @@ +{ + "Entries": [ + { + "RequestUri": "https://ta-s-westeurope.cognitiveservices.azure.com/text/analytics/v3.1-preview.4/entities/recognition/general?showStats=true\u0026stringIndexType=Utf16CodeUnit", + "RequestMethod": "POST", + "RequestHeaders": { + "Accept": "application/json, text/json", + "Content-Length": "191", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-f0e71c428611b54e877a60210ddb5074-559b26c13de00043-00", + "User-Agent": "azsdk-net-AI.TextAnalytics/5.1.0-alpha.20210224.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19042 )", + "x-ms-client-request-id": "67616e684f8b043d1e0c71e939770f42", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "id": "0", + "text": "Microsoft was founded by Bill Gates and Paul Allen.", + "language": "en" + }, + { + "id": "1", + "text": "My cat and my dog might need to see a veterinarian.", + "language": "en" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "7503b799-ace4-47bb-8340-ce348670d3aa", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=2", + "Date": "Wed, 24 Feb 2021 16:56:04 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "x-content-type-options": "nosniff", + "x-envoy-upstream-service-time": "59" + }, + "ResponseBody": { + "statistics": { + "documentsCount": 2, + "validDocumentsCount": 2, + "erroneousDocumentsCount": 0, + "transactionsCount": 2 + }, + "documents": [ + { + "id": "0", + "statistics": { + "charactersCount": 51, + "transactionsCount": 1 + }, + "entities": [ + { + "text": "Microsoft", + "category": "Organization", + "offset": 0, + "length": 9, + "confidenceScore": 0.97 + }, + { + "text": "Bill Gates", + "category": "Person", + "offset": 25, + "length": 10, + "confidenceScore": 1.0 + }, + { + "text": "Paul Allen", + "category": "Person", + "offset": 40, + "length": 10, + "confidenceScore": 0.99 + } + ], + "warnings": [] + }, + { + "id": "1", + "statistics": { + "charactersCount": 51, + "transactionsCount": 1 + }, + "entities": [ + { + "text": "veterinarian", + "category": "PersonType", + "offset": 38, + "length": 12, + "confidenceScore": 0.98 + } + ], + "warnings": [] + } + ], + "errors": [], + "modelVersion": "2021-01-15" + } + } + ], + "Variables": { + "RandomSeed": "706252555", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://ta-s-westeurope.cognitiveservices.azure.com" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesBatchConvenienceWithRecognizeEntitiesOptionsStatisticsTestAsync.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesBatchConvenienceWithRecognizeEntitiesOptionsStatisticsTestAsync.json new file mode 100644 index 0000000000000..39c9af3c1ca46 --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesBatchConvenienceWithRecognizeEntitiesOptionsStatisticsTestAsync.json @@ -0,0 +1,108 @@ +{ + "Entries": [ + { + "RequestUri": "https://ta-s-westeurope.cognitiveservices.azure.com/text/analytics/v3.1-preview.4/entities/recognition/general?showStats=true\u0026stringIndexType=Utf16CodeUnit", + "RequestMethod": "POST", + "RequestHeaders": { + "Accept": "application/json, text/json", + "Content-Length": "191", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-b09dab00c205ac4383497ec2db2bb12a-a4d9be2d8c8ebf41-00", + "User-Agent": "azsdk-net-AI.TextAnalytics/5.1.0-alpha.20210224.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19042 )", + "x-ms-client-request-id": "3d6191fdfe339ad3e9a9a23dfab389e2", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "id": "0", + "text": "Microsoft was founded by Bill Gates and Paul Allen.", + "language": "en" + }, + { + "id": "1", + "text": "My cat and my dog might need to see a veterinarian.", + "language": "en" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "eaa59371-2f65-4432-a23b-b3a9b2513b11", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=2", + "Date": "Wed, 24 Feb 2021 16:56:09 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "x-content-type-options": "nosniff", + "x-envoy-upstream-service-time": "53" + }, + "ResponseBody": { + "statistics": { + "documentsCount": 2, + "validDocumentsCount": 2, + "erroneousDocumentsCount": 0, + "transactionsCount": 2 + }, + "documents": [ + { + "id": "0", + "statistics": { + "charactersCount": 51, + "transactionsCount": 1 + }, + "entities": [ + { + "text": "Microsoft", + "category": "Organization", + "offset": 0, + "length": 9, + "confidenceScore": 0.97 + }, + { + "text": "Bill Gates", + "category": "Person", + "offset": 25, + "length": 10, + "confidenceScore": 1.0 + }, + { + "text": "Paul Allen", + "category": "Person", + "offset": 40, + "length": 10, + "confidenceScore": 0.99 + } + ], + "warnings": [] + }, + { + "id": "1", + "statistics": { + "charactersCount": 51, + "transactionsCount": 1 + }, + "entities": [ + { + "text": "veterinarian", + "category": "PersonType", + "offset": 38, + "length": 12, + "confidenceScore": 0.98 + } + ], + "warnings": [] + } + ], + "errors": [], + "modelVersion": "2021-01-15" + } + } + ], + "Variables": { + "RandomSeed": "915085791", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://ta-s-westeurope.cognitiveservices.azure.com" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesBatchWithRecognizeEntitiesOptionsStatisticsTest.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesBatchWithRecognizeEntitiesOptionsStatisticsTest.json new file mode 100644 index 0000000000000..5daf0c1b5cbfc --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesBatchWithRecognizeEntitiesOptionsStatisticsTest.json @@ -0,0 +1,122 @@ +{ + "Entries": [ + { + "RequestUri": "https://ta-s-westeurope.cognitiveservices.azure.com/text/analytics/v3.1-preview.4/entities/recognition/general?showStats=true\u0026stringIndexType=Utf16CodeUnit", + "RequestMethod": "POST", + "RequestHeaders": { + "Accept": "application/json, text/json", + "Content-Length": "190", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-3d8b12b3fc06514789ba36c53927c471-e2b196df0186df4c-00", + "User-Agent": "azsdk-net-AI.TextAnalytics/5.1.0-alpha.20210224.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19042 )", + "x-ms-client-request-id": "3c7b09ea57a0a9f84c938c05ff06e377", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "id": "1", + "text": "Microsoft was founded by Bill Gates and Paul Allen.", + "language": "en" + }, + { + "id": "2", + "text": "Microsoft fue fundado por Bill Gates y Paul Allen.", + "language": "es" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "4f026eb4-9949-4e33-8abe-771259c42cf4", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=2", + "Date": "Wed, 24 Feb 2021 16:56:06 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "x-content-type-options": "nosniff", + "x-envoy-upstream-service-time": "47" + }, + "ResponseBody": { + "statistics": { + "documentsCount": 2, + "validDocumentsCount": 2, + "erroneousDocumentsCount": 0, + "transactionsCount": 2 + }, + "documents": [ + { + "id": "1", + "statistics": { + "charactersCount": 51, + "transactionsCount": 1 + }, + "entities": [ + { + "text": "Microsoft", + "category": "Organization", + "offset": 0, + "length": 9, + "confidenceScore": 0.97 + }, + { + "text": "Bill Gates", + "category": "Person", + "offset": 25, + "length": 10, + "confidenceScore": 1.0 + }, + { + "text": "Paul Allen", + "category": "Person", + "offset": 40, + "length": 10, + "confidenceScore": 0.99 + } + ], + "warnings": [] + }, + { + "id": "2", + "statistics": { + "charactersCount": 50, + "transactionsCount": 1 + }, + "entities": [ + { + "text": "Microsoft", + "category": "Organization", + "offset": 0, + "length": 9, + "confidenceScore": 0.97 + }, + { + "text": "Bill Gates", + "category": "Person", + "offset": 26, + "length": 10, + "confidenceScore": 0.99 + }, + { + "text": "Paul Allen", + "category": "Person", + "offset": 39, + "length": 10, + "confidenceScore": 0.99 + } + ], + "warnings": [] + } + ], + "errors": [], + "modelVersion": "2021-01-15" + } + } + ], + "Variables": { + "RandomSeed": "541291504", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://ta-s-westeurope.cognitiveservices.azure.com" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesBatchWithRecognizeEntitiesOptionsStatisticsTestAsync.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesBatchWithRecognizeEntitiesOptionsStatisticsTestAsync.json new file mode 100644 index 0000000000000..95b28c7747485 --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesBatchWithRecognizeEntitiesOptionsStatisticsTestAsync.json @@ -0,0 +1,122 @@ +{ + "Entries": [ + { + "RequestUri": "https://ta-s-westeurope.cognitiveservices.azure.com/text/analytics/v3.1-preview.4/entities/recognition/general?showStats=true\u0026stringIndexType=Utf16CodeUnit", + "RequestMethod": "POST", + "RequestHeaders": { + "Accept": "application/json, text/json", + "Content-Length": "190", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-2f4c21569212df478ffe72e0efe85ea0-ce3b8f624c196947-00", + "User-Agent": "azsdk-net-AI.TextAnalytics/5.1.0-alpha.20210224.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19042 )", + "x-ms-client-request-id": "c386dc48f454868243af3522ce69cb86", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "id": "1", + "text": "Microsoft was founded by Bill Gates and Paul Allen.", + "language": "en" + }, + { + "id": "2", + "text": "Microsoft fue fundado por Bill Gates y Paul Allen.", + "language": "es" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "d81b2d0f-8652-426a-b7f0-0b09ba35f9be", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=2", + "Date": "Wed, 24 Feb 2021 16:56:11 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "x-content-type-options": "nosniff", + "x-envoy-upstream-service-time": "57" + }, + "ResponseBody": { + "statistics": { + "documentsCount": 2, + "validDocumentsCount": 2, + "erroneousDocumentsCount": 0, + "transactionsCount": 2 + }, + "documents": [ + { + "id": "1", + "statistics": { + "charactersCount": 51, + "transactionsCount": 1 + }, + "entities": [ + { + "text": "Microsoft", + "category": "Organization", + "offset": 0, + "length": 9, + "confidenceScore": 0.97 + }, + { + "text": "Bill Gates", + "category": "Person", + "offset": 25, + "length": 10, + "confidenceScore": 1.0 + }, + { + "text": "Paul Allen", + "category": "Person", + "offset": 40, + "length": 10, + "confidenceScore": 0.99 + } + ], + "warnings": [] + }, + { + "id": "2", + "statistics": { + "charactersCount": 50, + "transactionsCount": 1 + }, + "entities": [ + { + "text": "Microsoft", + "category": "Organization", + "offset": 0, + "length": 9, + "confidenceScore": 0.97 + }, + { + "text": "Bill Gates", + "category": "Person", + "offset": 26, + "length": 10, + "confidenceScore": 0.99 + }, + { + "text": "Paul Allen", + "category": "Person", + "offset": 39, + "length": 10, + "confidenceScore": 0.99 + } + ], + "warnings": [] + } + ], + "errors": [], + "modelVersion": "2021-01-15" + } + } + ], + "Variables": { + "RandomSeed": "438437791", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://ta-s-westeurope.cognitiveservices.azure.com" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesWithRecognizeEntitiesOptionsSubCategoryTest.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesWithRecognizeEntitiesOptionsSubCategoryTest.json new file mode 100644 index 0000000000000..e496e46bb741f --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesWithRecognizeEntitiesOptionsSubCategoryTest.json @@ -0,0 +1,78 @@ +{ + "Entries": [ + { + "RequestUri": "https://ta-s-westeurope.cognitiveservices.azure.com/text/analytics/v3.1-preview.4/entities/recognition/general?model-version=2020-04-01\u0026showStats=false\u0026stringIndexType=Utf16CodeUnit", + "RequestMethod": "POST", + "RequestHeaders": { + "Accept": "application/json, text/json", + "Content-Length": "96", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-02fbc8d6886b934493af61cbf8f49ac7-efaa7b935f434841-00", + "User-Agent": "azsdk-net-AI.TextAnalytics/5.1.0-alpha.20210224.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19042 )", + "x-ms-client-request-id": "c580665e455e125e80a821d61e9c3c18", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "id": "0", + "text": "I had a wonderful trip to Seattle last week.", + "language": "en" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "cc614fa9-f47c-4969-9191-0c02c5b8369a", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=1", + "Date": "Wed, 24 Feb 2021 16:56:08 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "x-content-type-options": "nosniff", + "x-envoy-upstream-service-time": "73" + }, + "ResponseBody": { + "documents": [ + { + "id": "0", + "entities": [ + { + "text": "trip", + "category": "Event", + "offset": 18, + "length": 4, + "confidenceScore": 0.61 + }, + { + "text": "Seattle", + "category": "Location", + "subcategory": "GPE", + "offset": 26, + "length": 7, + "confidenceScore": 0.82 + }, + { + "text": "last week", + "category": "DateTime", + "subcategory": "DateRange", + "offset": 34, + "length": 9, + "confidenceScore": 0.8 + } + ], + "warnings": [] + } + ], + "errors": [], + "modelVersion": "2020-04-01" + } + } + ], + "Variables": { + "RandomSeed": "1531566714", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://ta-s-westeurope.cognitiveservices.azure.com" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesWithRecognizeEntitiesOptionsSubCategoryTestAsync.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesWithRecognizeEntitiesOptionsSubCategoryTestAsync.json new file mode 100644 index 0000000000000..b31ef04c328f2 --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/RecognizeEntitiesTests/RecognizeEntitiesWithRecognizeEntitiesOptionsSubCategoryTestAsync.json @@ -0,0 +1,78 @@ +{ + "Entries": [ + { + "RequestUri": "https://ta-s-westeurope.cognitiveservices.azure.com/text/analytics/v3.1-preview.4/entities/recognition/general?model-version=2020-04-01\u0026showStats=false\u0026stringIndexType=Utf16CodeUnit", + "RequestMethod": "POST", + "RequestHeaders": { + "Accept": "application/json, text/json", + "Content-Length": "96", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-a53c2f7d23cad442813d9d1dbb8fcff5-b005f09a1e73b740-00", + "User-Agent": "azsdk-net-AI.TextAnalytics/5.1.0-alpha.20210224.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19042 )", + "x-ms-client-request-id": "3b4b745166e69035ddd947884a09aa87", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "id": "0", + "text": "I had a wonderful trip to Seattle last week.", + "language": "en" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "85c03987-f1ff-42bc-945c-aa737ff68691", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=1", + "Date": "Wed, 24 Feb 2021 16:56:13 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "x-content-type-options": "nosniff", + "x-envoy-upstream-service-time": "93" + }, + "ResponseBody": { + "documents": [ + { + "id": "0", + "entities": [ + { + "text": "trip", + "category": "Event", + "offset": 18, + "length": 4, + "confidenceScore": 0.61 + }, + { + "text": "Seattle", + "category": "Location", + "subcategory": "GPE", + "offset": 26, + "length": 7, + "confidenceScore": 0.82 + }, + { + "text": "last week", + "category": "DateTime", + "subcategory": "DateRange", + "offset": 34, + "length": 9, + "confidenceScore": 0.8 + } + ], + "warnings": [] + } + ], + "errors": [], + "modelVersion": "2020-04-01" + } + } + ], + "Variables": { + "RandomSeed": "1094081853", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://ta-s-westeurope.cognitiveservices.azure.com" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientTests.cs index 5ac07660ed012..96d0357e89f59 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientTests.cs @@ -38,33 +38,46 @@ public void CreateClientArgumentValidation() [Test] public void DetectLanguageArgumentValidation() { - var documents = new List(); Assert.ThrowsAsync(() => Client.DetectLanguageAsync("")); - Assert.ThrowsAsync(() => Client.DetectLanguageAsync((string)null)); - Assert.ThrowsAsync(() => Client.DetectLanguageBatchAsync((List)null)); - Assert.ThrowsAsync(() => Client.DetectLanguageBatchAsync(documents)); + Assert.ThrowsAsync(() => Client.DetectLanguageAsync(null)); + Assert.ThrowsAsync(() => Client.DetectLanguageBatchAsync((string[])null)); + Assert.ThrowsAsync(() => Client.DetectLanguageBatchAsync((DetectLanguageInput[])null)); + Assert.ThrowsAsync(() => Client.DetectLanguageBatchAsync(Array.Empty())); + Assert.ThrowsAsync(() => Client.DetectLanguageBatchAsync(Array.Empty())); Assert.ThrowsAsync(() => Client.DetectLanguageBatchAsync(null, new TextAnalyticsRequestOptions())); } [Test] public void RecognizeEntitiesArgumentValidation() { - var documents = new List(); Assert.ThrowsAsync(() => Client.RecognizeEntitiesAsync("")); - Assert.ThrowsAsync(() => Client.RecognizeEntitiesAsync((string)null)); - Assert.ThrowsAsync(() => Client.RecognizeEntitiesBatchAsync((List)null)); - Assert.ThrowsAsync(() => Client.RecognizeEntitiesBatchAsync(documents)); - Assert.ThrowsAsync(() => Client.RecognizeEntitiesBatchAsync(null, new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.RecognizeEntitiesAsync(null)); + Assert.ThrowsAsync(() => Client.RecognizeEntitiesBatchAsync((string[])null)); + Assert.ThrowsAsync(() => Client.RecognizeEntitiesBatchAsync((TextDocumentInput[])null)); + Assert.ThrowsAsync(() => Client.RecognizeEntitiesBatchAsync(Array.Empty())); + Assert.ThrowsAsync(() => Client.RecognizeEntitiesBatchAsync(Array.Empty())); + Assert.ThrowsAsync(() => Client.RecognizeEntitiesBatchAsync((string[])null, new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.RecognizeEntitiesBatchAsync((TextDocumentInput[])null, new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.RecognizeEntitiesBatchAsync((string[])null, new RecognizeEntitiesOptions())); + Assert.ThrowsAsync(() => Client.RecognizeEntitiesBatchAsync(null, new RecognizeEntitiesOptions())); + + // Variations to ensure call-compatibility after adding method-specific options class to parameters. + Assert.ThrowsAsync(() => Client.RecognizeEntitiesBatchAsync((string[])null, options: new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.RecognizeEntitiesBatchAsync((TextDocumentInput[])null, options: new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.RecognizeEntitiesBatchAsync(null, null, new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.RecognizeEntitiesBatchAsync(null, new RecognizeEntitiesOptions())); + Assert.ThrowsAsync(() => Client.RecognizeEntitiesBatchAsync(null, null, new RecognizeEntitiesOptions())); } [Test] public void RecognizePiiEntitiesArgumentValidation() { - var documents = new List(); Assert.ThrowsAsync(() => Client.RecognizePiiEntitiesAsync("")); - Assert.ThrowsAsync(() => Client.RecognizePiiEntitiesAsync((string)null)); - Assert.ThrowsAsync(() => Client.RecognizePiiEntitiesBatchAsync((List)null)); - Assert.ThrowsAsync(() => Client.RecognizePiiEntitiesBatchAsync(documents)); + Assert.ThrowsAsync(() => Client.RecognizePiiEntitiesAsync(null)); + Assert.ThrowsAsync(() => Client.RecognizePiiEntitiesBatchAsync((string[])null)); + Assert.ThrowsAsync(() => Client.RecognizePiiEntitiesBatchAsync((TextDocumentInput[])null)); + Assert.ThrowsAsync(() => Client.RecognizePiiEntitiesBatchAsync(Array.Empty())); + Assert.ThrowsAsync(() => Client.RecognizePiiEntitiesBatchAsync(Array.Empty())); Assert.ThrowsAsync(() => Client.RecognizePiiEntitiesBatchAsync(null, new RecognizePiiEntitiesOptions())); } @@ -91,11 +104,12 @@ public void AnalyzeSentimentArgumentValidation() [Test] public void ExtractKeyPhrasesArgumentValidation() { - var documents = new List(); Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesAsync("")); Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesAsync(null)); - Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync((List)null)); - Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync(documents)); + Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync((string[])null)); + Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync((TextDocumentInput[])null)); + Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync(Array.Empty())); + Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync(Array.Empty())); Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync(null, new TextAnalyticsRequestOptions())); } From c59a4e1c40f9efbf7753ff1fe32013e227885f2c Mon Sep 17 00:00:00 2001 From: Heath Stewart Date: Thu, 1 Apr 2021 18:20:41 -0700 Subject: [PATCH 5/6] Update samples --- .../Azure.AI.TextAnalytics/samples/Sample4_RecognizeEntities.md | 2 +- .../samples/Sample6_RecognizeLinkedEntities.md | 2 +- .../tests/samples/Sample4_RecognizeEntitiesBatch.cs | 2 +- .../tests/samples/Sample4_RecognizeEntitiesBatchAsync.cs | 2 +- .../tests/samples/Sample6_RecognizeLinkedEntitiesBatch.cs | 2 +- .../tests/samples/Sample6_RecognizeLinkedEntitiesBatchAsync.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample4_RecognizeEntities.md b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample4_RecognizeEntities.md index 480cee4ccbcc1..c9cc487eb1741 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample4_RecognizeEntities.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample4_RecognizeEntities.md @@ -158,7 +158,7 @@ var documents = new List new TextDocumentInput("4", string.Empty) }; -var options = new TextAnalyticsRequestOptions { IncludeStatistics = true }; +var options = new RecognizeEntitiesOptions { IncludeStatistics = true }; Response response = client.RecognizeEntitiesBatch(documents, options); RecognizeEntitiesResultCollection entitiesInDocuments = response.Value; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample6_RecognizeLinkedEntities.md b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample6_RecognizeLinkedEntities.md index 7782cc07c7cc0..4751f03018592 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample6_RecognizeLinkedEntities.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample6_RecognizeLinkedEntities.md @@ -155,7 +155,7 @@ var documents = new List new TextDocumentInput("4", string.Empty) }; -var options = new TextAnalyticsRequestOptions { IncludeStatistics = true }; +var options = new RecognizeLinkedEntitiesOptions { IncludeStatistics = true }; Response response = client.RecognizeLinkedEntitiesBatch(documents, options); RecognizeLinkedEntitiesResultCollection entitiesPerDocuments = response.Value; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatch.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatch.cs index 9e4ce22a1e50a..a350ed85a839b 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatch.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatch.cs @@ -57,7 +57,7 @@ The spa was clean and felt very peaceful. Overall the whole experience was great new TextDocumentInput("4", string.Empty) }; - var options = new TextAnalyticsRequestOptions { IncludeStatistics = true }; + var options = new RecognizeEntitiesOptions { IncludeStatistics = true }; Response response = client.RecognizeEntitiesBatch(documents, options); RecognizeEntitiesResultCollection entitiesInDocuments = response.Value; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchAsync.cs index 67a423072704d..346ec33d04a4d 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchAsync.cs @@ -57,7 +57,7 @@ The spa was clean and felt very peaceful. Overall the whole experience was great new TextDocumentInput("4", string.Empty) }; - var options = new TextAnalyticsRequestOptions { IncludeStatistics = true }; + var options = new RecognizeEntitiesOptions { IncludeStatistics = true }; Response response = await client.RecognizeEntitiesBatchAsync(documents, options); RecognizeEntitiesResultCollection entitiesInDocuments = response.Value; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatch.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatch.cs index 2e4fa0f4ffeef..12843f66161de 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatch.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatch.cs @@ -52,7 +52,7 @@ public void ExtractEntityLinkingBatch() new TextDocumentInput("4", string.Empty) }; - var options = new TextAnalyticsRequestOptions { IncludeStatistics = true }; + var options = new RecognizeLinkedEntitiesOptions { IncludeStatistics = true }; Response response = client.RecognizeLinkedEntitiesBatch(documents, options); RecognizeLinkedEntitiesResultCollection entitiesPerDocuments = response.Value; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchAsync.cs index e6760275f0b0b..f61c6a93d029a 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchAsync.cs @@ -52,7 +52,7 @@ public async Task ExtractEntityLinkingBatchAsync() new TextDocumentInput("4", string.Empty) }; - var options = new TextAnalyticsRequestOptions { IncludeStatistics = true }; + var options = new RecognizeLinkedEntitiesOptions { IncludeStatistics = true }; Response response = await client.RecognizeLinkedEntitiesBatchAsync(documents, options); RecognizeLinkedEntitiesResultCollection entitiesInDocuments = response.Value; From a977df626f67e883a7096c09a2a76677f0844b36 Mon Sep 17 00:00:00 2001 From: Heath Stewart Date: Fri, 2 Apr 2021 10:28:41 -0700 Subject: [PATCH 6/6] Add overloads for ExtractKeyPhrasesBatch(Async) --- .../Azure.AI.TextAnalytics/CHANGELOG.md | 5 +- .../Azure.AI.TextAnalytics.netstandard2.0.cs | 20 +- .../samples/Sample3_ExtractKeyPhrases.md | 2 +- .../src/TextAnalyticsClient.cs | 172 +++++++++++++++++- .../tests/ExtractKeyPhrasesTests.cs | 54 +++++- ...xtractKeyPhrasesOptionsStatisticsTest.json | 86 +++++++++ ...tKeyPhrasesOptionsStatisticsTestAsync.json | 86 +++++++++ ...ExtractKeyPhrasesOptionsSatisticsTest.json | 86 +++++++++ ...ctKeyPhrasesOptionsSatisticsTestAsync.json | 86 +++++++++ .../tests/TextAnalyticsClientTests.cs | 12 +- .../samples/Sample3_ExtractKeyPhrasesBatch.cs | 2 +- .../Sample3_ExtractKeyPhrasesBatchAsync.cs | 2 +- 12 files changed, 594 insertions(+), 19 deletions(-) create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/ExtractKeyPhrasesTests/ExtractKeyPhrasesBatchConvenienceWithExtractKeyPhrasesOptionsStatisticsTest.json create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/ExtractKeyPhrasesTests/ExtractKeyPhrasesBatchConvenienceWithExtractKeyPhrasesOptionsStatisticsTestAsync.json create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/ExtractKeyPhrasesTests/ExtractKeyPhrasesBatchWithExtractKeyPhrasesOptionsSatisticsTest.json create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/ExtractKeyPhrasesTests/ExtractKeyPhrasesBatchWithExtractKeyPhrasesOptionsSatisticsTestAsync.json diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md b/sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md index 9047fb06d6130..8f8dfc937bc37 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md @@ -1,7 +1,10 @@ # Release History ## 5.1.0-beta.6 (Unreleased) - +### New features +- Add overloads to `ExtractKeyPhrasesBatch` and `ExtractKeyPhrasesBatchAsync` to on `TextAnalyticsClient` to accept `ExtractKeyPhrasesOptions` and hid the previous methods (non-breaking change). +- Add overloads to `RecognizeEntitiesBatch` and `RecognizeEntitiesBatchAsync` to on `TextAnalyticsClient` to accept `RecognizeEntitiesOptions` and hid the previous methods (non-breaking change). +- Add overloads to `RecognizeLinkedEntitiesBatch` and `RecognizeLinkedEntitiesBatch` to on `TextAnalyticsClient` to accept `RecognizeLinkedEntitiesOptions` and hid the previous methods (non-breaking change). ## 5.1.0-beta.5 (2021-03-09) ### New features diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/api/Azure.AI.TextAnalytics.netstandard2.0.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/api/Azure.AI.TextAnalytics.netstandard2.0.cs index f807c2d5cf1ac..5e28b0955940c 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/api/Azure.AI.TextAnalytics.netstandard2.0.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/api/Azure.AI.TextAnalytics.netstandard2.0.cs @@ -720,10 +720,22 @@ public TextAnalyticsClient(System.Uri endpoint, Azure.Core.TokenCredential crede public override bool Equals(object obj) { throw null; } public virtual Azure.Response ExtractKeyPhrases(string document, string language = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> ExtractKeyPhrasesAsync(string document, string language = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response ExtractKeyPhrasesBatch(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Response ExtractKeyPhrasesBatch(System.Collections.Generic.IEnumerable documents, string language = null, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> ExtractKeyPhrasesBatchAsync(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task> ExtractKeyPhrasesBatchAsync(System.Collections.Generic.IEnumerable documents, string language = null, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response ExtractKeyPhrasesBatch(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.ExtractKeyPhrasesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual Azure.Response ExtractKeyPhrasesBatch(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual Azure.Response ExtractKeyPhrasesBatch(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response ExtractKeyPhrasesBatch(System.Collections.Generic.IEnumerable documents, string language = null, Azure.AI.TextAnalytics.ExtractKeyPhrasesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual Azure.Response ExtractKeyPhrasesBatch(System.Collections.Generic.IEnumerable documents, string language, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ExtractKeyPhrasesBatchAsync(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.ExtractKeyPhrasesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual System.Threading.Tasks.Task> ExtractKeyPhrasesBatchAsync(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual System.Threading.Tasks.Task> ExtractKeyPhrasesBatchAsync(System.Collections.Generic.IEnumerable documents, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ExtractKeyPhrasesBatchAsync(System.Collections.Generic.IEnumerable documents, string language = null, Azure.AI.TextAnalytics.ExtractKeyPhrasesOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public virtual System.Threading.Tasks.Task> ExtractKeyPhrasesBatchAsync(System.Collections.Generic.IEnumerable documents, string language, Azure.AI.TextAnalytics.TextAnalyticsRequestOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override int GetHashCode() { throw null; } public virtual Azure.Response RecognizeEntities(string document, string language = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample3_ExtractKeyPhrases.md b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample3_ExtractKeyPhrases.md index 005a18f3cf223..68a93b1dfb7fc 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample3_ExtractKeyPhrases.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample3_ExtractKeyPhrases.md @@ -144,7 +144,7 @@ var documents = new List new TextDocumentInput("4", string.Empty) }; -var options = new TextAnalyticsRequestOptions { IncludeStatistics = true }; +var options = new ExtractKeyPhrasesOptions { IncludeStatistics = true }; Response response = client.ExtractKeyPhrasesBatch(documents, options); ExtractKeyPhrasesResultCollection keyPhrasesInDocuments = response.Value; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs index e0755cb3749f6..4d19a5a199901 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs @@ -1762,6 +1762,29 @@ public virtual Response ExtractKeyPhrases(string document, } } + /// + /// Runs a model to identify a collection of significant phrases + /// found in the passed-in documents. + /// For example, for the document "The food was delicious and there + /// were wonderful staff", the API returns the main talking points: "food" + /// and "wonderful staff". + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of key phrases identified + /// in each of the documents. + /// Service returned a non-success + /// status code. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual async Task> ExtractKeyPhrasesBatchAsync(IEnumerable documents, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) => + await ExtractKeyPhrasesBatchAsync(documents, null, options, cancellationToken).ConfigureAwait(false); + /// /// Runs a model to identify a collection of significant phrases /// found in the passed-in documents. @@ -1788,15 +1811,68 @@ public virtual Response ExtractKeyPhrases(string document, /// in each of the documents. /// Service returned a non-success /// status code. - public virtual async Task> ExtractKeyPhrasesBatchAsync(IEnumerable documents, string language = default, TextAnalyticsRequestOptions options = default, CancellationToken cancellationToken = default) + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual async Task> ExtractKeyPhrasesBatchAsync(IEnumerable documents, string language, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(documents, nameof(documents)); - options ??= new TextAnalyticsRequestOptions(); + options ??= new ExtractKeyPhrasesOptions(); MultiLanguageBatchInput documentInputs = ConvertToMultiLanguageInputs(documents, language); return await ExtractKeyPhrasesBatchAsync(documentInputs, options, cancellationToken).ConfigureAwait(false); } + /// + /// Runs a model to identify a collection of significant phrases + /// found in the passed-in documents. + /// For example, for the document "The food was delicious and there + /// were wonderful staff", the API returns the main talking points: "food" + /// and "wonderful staff". + /// For a list of languages supported by this operation, see + /// . + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// The language that all the documents are + /// written in. If unspecified, this value will be set to the default + /// language in in the request + /// sent to the service. If set to an empty string, the service will apply a model + /// where the language is explicitly set to "None". + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of key phrases identified + /// in each of the documents. + /// Service returned a non-success + /// status code. + public virtual async Task> ExtractKeyPhrasesBatchAsync(IEnumerable documents, string language = default, ExtractKeyPhrasesOptions options = default, CancellationToken cancellationToken = default) => + await ExtractKeyPhrasesBatchAsync(documents, language, (TextAnalyticsRequestOptions)options, cancellationToken).ConfigureAwait(false); + + /// + /// Runs a model to identify a collection of significant phrases + /// found in the passed-in documents. + /// For example, for the document "The food was delicious and there + /// were wonderful staff", the API returns the main talking points: "food" + /// and "wonderful staff". + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of key phrases identified + /// in each of the documents. + /// Service returned a non-success + /// status code. + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual Response ExtractKeyPhrasesBatch(IEnumerable documents, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) => + ExtractKeyPhrasesBatch(documents, null, options, cancellationToken); + /// /// Runs a model to identify a collection of significant phrases /// found in the passed-in documents. @@ -1823,15 +1899,45 @@ public virtual async Task> ExtractKe /// in each of the documents. /// Service returned a non-success /// status code. - public virtual Response ExtractKeyPhrasesBatch(IEnumerable documents, string language = default, TextAnalyticsRequestOptions options = default, CancellationToken cancellationToken = default) + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual Response ExtractKeyPhrasesBatch(IEnumerable documents, string language, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(documents, nameof(documents)); - options ??= new TextAnalyticsRequestOptions(); + options ??= new ExtractKeyPhrasesOptions(); MultiLanguageBatchInput documentInputs = ConvertToMultiLanguageInputs(documents, language); return ExtractKeyPhrasesBatch(documentInputs, options, cancellationToken); } + /// + /// Runs a model to identify a collection of significant phrases + /// found in the passed-in documents. + /// For example, for the document "The food was delicious and there + /// were wonderful staff", the API returns the main talking points: "food" + /// and "wonderful staff". + /// For a list of languages supported by this operation, see + /// . + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// The language that all the documents are + /// written in. If unspecified, this value will be set to the default + /// language in in the request + /// sent to the service. If set to an empty string, the service will apply a model + /// where the language is explicitly set to "None". + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of key phrases identified + /// in each of the documents. + /// Service returned a non-success + /// status code. + public virtual Response ExtractKeyPhrasesBatch(IEnumerable documents, string language = default, ExtractKeyPhrasesOptions options = default, CancellationToken cancellationToken = default) => + ExtractKeyPhrasesBatch(documents, language, (TextAnalyticsRequestOptions)options, cancellationToken); + /// /// Runs a model to identify a collection of significant phrases /// found in the passed-in documents. @@ -1853,15 +1959,40 @@ public virtual Response ExtractKeyPhrasesBatc /// in each of the documents. /// Service returned a non-success /// status code. - public virtual async Task> ExtractKeyPhrasesBatchAsync(IEnumerable documents, TextAnalyticsRequestOptions options = default, CancellationToken cancellationToken = default) + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual async Task> ExtractKeyPhrasesBatchAsync(IEnumerable documents, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(documents, nameof(documents)); - options ??= new TextAnalyticsRequestOptions(); + options ??= new ExtractKeyPhrasesOptions(); MultiLanguageBatchInput documentInputs = ConvertToMultiLanguageInputs(documents); return await ExtractKeyPhrasesBatchAsync(documentInputs, options, cancellationToken).ConfigureAwait(false); } + /// + /// Runs a model to identify a collection of significant phrases + /// found in the passed-in documents. + /// For example, for the document "The food was delicious and there + /// were wonderful staff", the API returns the main talking points: "food" + /// and "wonderful staff". + /// For a list of languages supported by this operation, see + /// . + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of key phrases identified + /// in each of the documents. + /// Service returned a non-success + /// status code. + public virtual async Task> ExtractKeyPhrasesBatchAsync(IEnumerable documents, ExtractKeyPhrasesOptions options = default, CancellationToken cancellationToken = default) => + await ExtractKeyPhrasesBatchAsync(documents, (TextAnalyticsRequestOptions)options, cancellationToken).ConfigureAwait(false); + /// /// Runs a model to identify a collection of significant phrases /// found in the passed-in documents. @@ -1883,15 +2014,40 @@ public virtual async Task> ExtractKe /// in each of the documents. /// Service returned a non-success /// status code. - public virtual Response ExtractKeyPhrasesBatch(IEnumerable documents, TextAnalyticsRequestOptions options = default, CancellationToken cancellationToken = default) + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual Response ExtractKeyPhrasesBatch(IEnumerable documents, TextAnalyticsRequestOptions options, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(documents, nameof(documents)); - options ??= new TextAnalyticsRequestOptions(); + options ??= new ExtractKeyPhrasesOptions(); MultiLanguageBatchInput documentInputs = ConvertToMultiLanguageInputs(documents); return ExtractKeyPhrasesBatch(documentInputs, options, cancellationToken); } + /// + /// Runs a model to identify a collection of significant phrases + /// found in the passed-in documents. + /// For example, for the document "The food was delicious and there + /// were wonderful staff", the API returns the main talking points: "food" + /// and "wonderful staff". + /// For a list of languages supported by this operation, see + /// . + /// For document length limits, maximum batch size, and supported text encoding, see + /// . + /// + /// The documents to analyze. + /// used to + /// select the version of the predictive model to run, and whether + /// statistics are returned in the response. + /// A + /// controlling the request lifetime. + /// A result containing the collection of key phrases identified + /// in each of the documents. + /// Service returned a non-success + /// status code. + public virtual Response ExtractKeyPhrasesBatch(IEnumerable documents, ExtractKeyPhrasesOptions options = default, CancellationToken cancellationToken = default) => + ExtractKeyPhrasesBatch(documents, (TextAnalyticsRequestOptions)options, cancellationToken); + private async Task> ExtractKeyPhrasesBatchAsync(MultiLanguageBatchInput batchInput, TextAnalyticsRequestOptions options, CancellationToken cancellationToken) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(TextAnalyticsClient)}.{nameof(ExtractKeyPhrasesBatch)}"); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/ExtractKeyPhrasesTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/ExtractKeyPhrasesTests.cs index c1da10de7c4e6..27c69ecc528bc 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/ExtractKeyPhrasesTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/ExtractKeyPhrasesTests.cs @@ -125,14 +125,39 @@ public async Task ExtractKeyPhrasesBatchConvenienceTest() [Test] public async Task ExtractKeyPhrasesBatchConvenienceWithStatisticsTest() { + var options = new TextAnalyticsRequestOptions { IncludeStatistics = true }; TextAnalyticsClient client = GetClient(); var documents = batchConvenienceDocuments; - ExtractKeyPhrasesResultCollection results = await client.ExtractKeyPhrasesBatchAsync(documents, "en", new TextAnalyticsRequestOptions { IncludeStatistics = true }); + ExtractKeyPhrasesResultCollection results = await client.ExtractKeyPhrasesBatchAsync(documents, "en", options); ValidateBatchDocumentsResult(results, 3, includeStatistics: true); Assert.AreEqual(documents.Count, results.Statistics.DocumentCount); + + // Assert the options classes since overloads were added and the original now instantiates a RecognizeEntitiesOptions. + Assert.IsTrue(options.IncludeStatistics); + Assert.IsNull(options.ModelVersion); + Assert.AreEqual(StringIndexType.Utf16CodeUnit, options.StringIndexType); + } + + [Test] + public async Task ExtractKeyPhrasesBatchConvenienceWithExtractKeyPhrasesOptionsStatisticsTest() + { + var options = new ExtractKeyPhrasesOptions { IncludeStatistics = true }; + TextAnalyticsClient client = GetClient(); + var documents = batchConvenienceDocuments; + + ExtractKeyPhrasesResultCollection results = await client.ExtractKeyPhrasesBatchAsync(documents, "en", options); + + ValidateBatchDocumentsResult(results, 3, includeStatistics: true); + + Assert.AreEqual(documents.Count, results.Statistics.DocumentCount); + + // Assert the options classes since overloads were added and the original now instantiates a RecognizeEntitiesOptions. + Assert.IsTrue(options.IncludeStatistics); + Assert.IsNull(options.ModelVersion); + Assert.AreEqual(StringIndexType.Utf16CodeUnit, options.StringIndexType); } [Test] @@ -149,14 +174,39 @@ public async Task ExtractKeyPhrasesBatchTest() [Test] public async Task ExtractKeyPhrasesBatchWithSatisticsTest() { + var options = new TextAnalyticsRequestOptions { IncludeStatistics = true }; TextAnalyticsClient client = GetClient(); List documents = batchDocuments; - ExtractKeyPhrasesResultCollection results = await client.ExtractKeyPhrasesBatchAsync(documents, new TextAnalyticsRequestOptions { IncludeStatistics = true }); + ExtractKeyPhrasesResultCollection results = await client.ExtractKeyPhrasesBatchAsync(documents, options); ValidateBatchDocumentsResult(results, 3, includeStatistics: true); Assert.AreEqual(documents.Count, results.Statistics.DocumentCount); + + // Assert the options classes since overloads were added and the original now instantiates a RecognizeEntitiesOptions. + Assert.IsTrue(options.IncludeStatistics); + Assert.IsNull(options.ModelVersion); + Assert.AreEqual(StringIndexType.Utf16CodeUnit, options.StringIndexType); + } + + [Test] + public async Task ExtractKeyPhrasesBatchWithExtractKeyPhrasesOptionsSatisticsTest() + { + var options = new ExtractKeyPhrasesOptions { IncludeStatistics = true }; + TextAnalyticsClient client = GetClient(); + List documents = batchDocuments; + + ExtractKeyPhrasesResultCollection results = await client.ExtractKeyPhrasesBatchAsync(documents, options); + + ValidateBatchDocumentsResult(results, 3, includeStatistics: true); + + Assert.AreEqual(documents.Count, results.Statistics.DocumentCount); + + // Assert the options classes since overloads were added and the original now instantiates a RecognizeEntitiesOptions. + Assert.IsTrue(options.IncludeStatistics); + Assert.IsNull(options.ModelVersion); + Assert.AreEqual(StringIndexType.Utf16CodeUnit, options.StringIndexType); } [Test] diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/ExtractKeyPhrasesTests/ExtractKeyPhrasesBatchConvenienceWithExtractKeyPhrasesOptionsStatisticsTest.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/ExtractKeyPhrasesTests/ExtractKeyPhrasesBatchConvenienceWithExtractKeyPhrasesOptionsStatisticsTest.json new file mode 100644 index 0000000000000..3795cfc2917f2 --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/ExtractKeyPhrasesTests/ExtractKeyPhrasesBatchConvenienceWithExtractKeyPhrasesOptionsStatisticsTest.json @@ -0,0 +1,86 @@ +{ + "Entries": [ + { + "RequestUri": "https://ta-s-westeurope.cognitiveservices.azure.com/text/analytics/v3.1-preview.4/keyPhrases?showStats=true", + "RequestMethod": "POST", + "RequestHeaders": { + "Accept": "application/json, text/json", + "Content-Length": "191", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-776c462d9fabba488ba3d848c0b96a58-a65ef4deba6ec746-00", + "User-Agent": "azsdk-net-AI.TextAnalytics/5.1.0-alpha.20210224.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19042 )", + "x-ms-client-request-id": "4dfa2958a1568d79bc14e1b570d63d15", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "id": "0", + "text": "Microsoft was founded by Bill Gates and Paul Allen.", + "language": "en" + }, + { + "id": "1", + "text": "My cat and my dog might need to see a veterinarian.", + "language": "en" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "86f0c43c-2df3-4cb5-84b4-056e75ca9832", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=2", + "Date": "Wed, 24 Feb 2021 16:55:56 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "x-content-type-options": "nosniff", + "x-envoy-upstream-service-time": "10" + }, + "ResponseBody": { + "statistics": { + "documentsCount": 2, + "validDocumentsCount": 2, + "erroneousDocumentsCount": 0, + "transactionsCount": 2 + }, + "documents": [ + { + "id": "0", + "keyPhrases": [ + "Bill Gates", + "Paul Allen", + "Microsoft" + ], + "statistics": { + "charactersCount": 51, + "transactionsCount": 1 + }, + "warnings": [] + }, + { + "id": "1", + "keyPhrases": [ + "dog", + "cat", + "veterinarian" + ], + "statistics": { + "charactersCount": 51, + "transactionsCount": 1 + }, + "warnings": [] + } + ], + "errors": [], + "modelVersion": "2020-07-01" + } + } + ], + "Variables": { + "RandomSeed": "1074286074", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://ta-s-westeurope.cognitiveservices.azure.com" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/ExtractKeyPhrasesTests/ExtractKeyPhrasesBatchConvenienceWithExtractKeyPhrasesOptionsStatisticsTestAsync.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/ExtractKeyPhrasesTests/ExtractKeyPhrasesBatchConvenienceWithExtractKeyPhrasesOptionsStatisticsTestAsync.json new file mode 100644 index 0000000000000..a03a48d08e13e --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/ExtractKeyPhrasesTests/ExtractKeyPhrasesBatchConvenienceWithExtractKeyPhrasesOptionsStatisticsTestAsync.json @@ -0,0 +1,86 @@ +{ + "Entries": [ + { + "RequestUri": "https://ta-s-westeurope.cognitiveservices.azure.com/text/analytics/v3.1-preview.4/keyPhrases?showStats=true", + "RequestMethod": "POST", + "RequestHeaders": { + "Accept": "application/json, text/json", + "Content-Length": "191", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-e03f04c293702f47a356cf6f3a33ba73-0386ee1681c14d43-00", + "User-Agent": "azsdk-net-AI.TextAnalytics/5.1.0-alpha.20210224.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19042 )", + "x-ms-client-request-id": "f8f1e114d697e804255315d1c7e9b6ab", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "id": "0", + "text": "Microsoft was founded by Bill Gates and Paul Allen.", + "language": "en" + }, + { + "id": "1", + "text": "My cat and my dog might need to see a veterinarian.", + "language": "en" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "f96e3341-709c-4d67-8f49-24250f38a4ae", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=2", + "Date": "Wed, 24 Feb 2021 16:56:00 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "x-content-type-options": "nosniff", + "x-envoy-upstream-service-time": "11" + }, + "ResponseBody": { + "statistics": { + "documentsCount": 2, + "validDocumentsCount": 2, + "erroneousDocumentsCount": 0, + "transactionsCount": 2 + }, + "documents": [ + { + "id": "0", + "keyPhrases": [ + "Bill Gates", + "Paul Allen", + "Microsoft" + ], + "statistics": { + "charactersCount": 51, + "transactionsCount": 1 + }, + "warnings": [] + }, + { + "id": "1", + "keyPhrases": [ + "dog", + "cat", + "veterinarian" + ], + "statistics": { + "charactersCount": 51, + "transactionsCount": 1 + }, + "warnings": [] + } + ], + "errors": [], + "modelVersion": "2020-07-01" + } + } + ], + "Variables": { + "RandomSeed": "1602869274", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://ta-s-westeurope.cognitiveservices.azure.com" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/ExtractKeyPhrasesTests/ExtractKeyPhrasesBatchWithExtractKeyPhrasesOptionsSatisticsTest.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/ExtractKeyPhrasesTests/ExtractKeyPhrasesBatchWithExtractKeyPhrasesOptionsSatisticsTest.json new file mode 100644 index 0000000000000..7e8488a3ae158 --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/ExtractKeyPhrasesTests/ExtractKeyPhrasesBatchWithExtractKeyPhrasesOptionsSatisticsTest.json @@ -0,0 +1,86 @@ +{ + "Entries": [ + { + "RequestUri": "https://ta-s-westeurope.cognitiveservices.azure.com/text/analytics/v3.1-preview.4/keyPhrases?showStats=true", + "RequestMethod": "POST", + "RequestHeaders": { + "Accept": "application/json, text/json", + "Content-Length": "188", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-c263251feefbf04c9bbdf49cd848fea8-71f185a51513454b-00", + "User-Agent": "azsdk-net-AI.TextAnalytics/5.1.0-alpha.20210224.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19042 )", + "x-ms-client-request-id": "481340828d769a0d6f19ecfe6b0d9666", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "id": "1", + "text": "Microsoft was founded by Bill Gates and Paul Allen.", + "language": "en" + }, + { + "id": "2", + "text": "Mi perro y mi gato tienen que ir al veterinario.", + "language": "es" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "8d25e21c-b163-447a-a3b3-2f8e4ab55be5", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=2", + "Date": "Wed, 24 Feb 2021 16:55:58 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "x-content-type-options": "nosniff", + "x-envoy-upstream-service-time": "13" + }, + "ResponseBody": { + "statistics": { + "documentsCount": 2, + "validDocumentsCount": 2, + "erroneousDocumentsCount": 0, + "transactionsCount": 2 + }, + "documents": [ + { + "id": "1", + "keyPhrases": [ + "Bill Gates", + "Paul Allen", + "Microsoft" + ], + "statistics": { + "charactersCount": 51, + "transactionsCount": 1 + }, + "warnings": [] + }, + { + "id": "2", + "keyPhrases": [ + "gato", + "perro", + "veterinario" + ], + "statistics": { + "charactersCount": 48, + "transactionsCount": 1 + }, + "warnings": [] + } + ], + "errors": [], + "modelVersion": "2020-07-01" + } + } + ], + "Variables": { + "RandomSeed": "1134123605", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://ta-s-westeurope.cognitiveservices.azure.com" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/ExtractKeyPhrasesTests/ExtractKeyPhrasesBatchWithExtractKeyPhrasesOptionsSatisticsTestAsync.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/ExtractKeyPhrasesTests/ExtractKeyPhrasesBatchWithExtractKeyPhrasesOptionsSatisticsTestAsync.json new file mode 100644 index 0000000000000..082f5bf995bbc --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/ExtractKeyPhrasesTests/ExtractKeyPhrasesBatchWithExtractKeyPhrasesOptionsSatisticsTestAsync.json @@ -0,0 +1,86 @@ +{ + "Entries": [ + { + "RequestUri": "https://ta-s-westeurope.cognitiveservices.azure.com/text/analytics/v3.1-preview.4/keyPhrases?showStats=true", + "RequestMethod": "POST", + "RequestHeaders": { + "Accept": "application/json, text/json", + "Content-Length": "188", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-705a22de84b8c84eb9cb31cfd2e5c3c0-6e97e52a610c3c48-00", + "User-Agent": "azsdk-net-AI.TextAnalytics/5.1.0-alpha.20210224.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19042 )", + "x-ms-client-request-id": "fcabdefd3d51a89852601fc0d61f3468", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "id": "1", + "text": "Microsoft was founded by Bill Gates and Paul Allen.", + "language": "en" + }, + { + "id": "2", + "text": "Mi perro y mi gato tienen que ir al veterinario.", + "language": "es" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "3e818865-6477-4741-b7f2-ffe3ac5f3533", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=2", + "Date": "Wed, 24 Feb 2021 16:56:02 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "x-content-type-options": "nosniff", + "x-envoy-upstream-service-time": "10" + }, + "ResponseBody": { + "statistics": { + "documentsCount": 2, + "validDocumentsCount": 2, + "erroneousDocumentsCount": 0, + "transactionsCount": 2 + }, + "documents": [ + { + "id": "1", + "keyPhrases": [ + "Bill Gates", + "Paul Allen", + "Microsoft" + ], + "statistics": { + "charactersCount": 51, + "transactionsCount": 1 + }, + "warnings": [] + }, + { + "id": "2", + "keyPhrases": [ + "gato", + "perro", + "veterinario" + ], + "statistics": { + "charactersCount": 48, + "transactionsCount": 1 + }, + "warnings": [] + } + ], + "errors": [], + "modelVersion": "2020-07-01" + } + } + ], + "Variables": { + "RandomSeed": "1658669752", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://ta-s-westeurope.cognitiveservices.azure.com" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientTests.cs index 96d0357e89f59..b9001a3c63f5e 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientTests.cs @@ -110,7 +110,17 @@ public void ExtractKeyPhrasesArgumentValidation() Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync((TextDocumentInput[])null)); Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync(Array.Empty())); Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync(Array.Empty())); - Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync(null, new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync((string[])null, new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync((TextDocumentInput[])null, new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync((string[])null, new ExtractKeyPhrasesOptions())); + Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync(null, new ExtractKeyPhrasesOptions())); + + // Variations to ensure call-compatibility after adding method-specific options class to parameters. + Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync((string[])null, options: new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync((TextDocumentInput[])null, options: new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync(null, null, new TextAnalyticsRequestOptions())); + Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync(null, new ExtractKeyPhrasesOptions())); + Assert.ThrowsAsync(() => Client.ExtractKeyPhrasesBatchAsync(null, null, new ExtractKeyPhrasesOptions())); } [Test] diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample3_ExtractKeyPhrasesBatch.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample3_ExtractKeyPhrasesBatch.cs index 353908d81674d..ba1c9244178e7 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample3_ExtractKeyPhrasesBatch.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample3_ExtractKeyPhrasesBatch.cs @@ -57,7 +57,7 @@ The spa was clean and felt very peaceful. Overall the whole experience was great new TextDocumentInput("4", string.Empty) }; - var options = new TextAnalyticsRequestOptions { IncludeStatistics = true }; + var options = new ExtractKeyPhrasesOptions { IncludeStatistics = true }; Response response = client.ExtractKeyPhrasesBatch(documents, options); ExtractKeyPhrasesResultCollection keyPhrasesInDocuments = response.Value; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample3_ExtractKeyPhrasesBatchAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample3_ExtractKeyPhrasesBatchAsync.cs index dea65ada15f2b..caa5ea1e7fa00 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample3_ExtractKeyPhrasesBatchAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample3_ExtractKeyPhrasesBatchAsync.cs @@ -57,7 +57,7 @@ The spa was clean and felt very peaceful. Overall the whole experience was great new TextDocumentInput("4", string.Empty) }; - var options = new TextAnalyticsRequestOptions { IncludeStatistics = true }; + var options = new ExtractKeyPhrasesOptions { IncludeStatistics = true }; Response response = await client.ExtractKeyPhrasesBatchAsync(documents, options); ExtractKeyPhrasesResultCollection keyPhrasesInDocuments = response.Value;