diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md b/sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md index ac0f62d10bb6..97dd9d745166 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md @@ -1,7 +1,10 @@ # Release History ## 1.0.0-preview.3 (Unreleased) - +- Renamed type `SentimentScorePerLabel` to `SentimentConfidenceScorePerLabel`. +- In both `DocumentSentiment` and `SentenceSentiment` property `SentimentScores` has been renamed to `ConfidenceScores`. +- In `LinkedEntity`, property `Id` has been renamed to `DataSourceEntityId`. +- Added `DetectLanguageInput.None` for user convenience, instead of passing empty string to `CountryHint`. ## 1.0.0-preview.2 (2020-02-11) ### Breaking changes diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample1_DetectLanguage.md b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample1_DetectLanguage.md index a191f58e2198..950bd1abd2c0 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample1_DetectLanguage.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample1_DetectLanguage.md @@ -51,7 +51,7 @@ var inputs = new List }, new DetectLanguageInput("4", ":) :( :D") { - CountryHint = "us", + CountryHint = DetectLanguageInput.None, } }; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/DetectLanguageInput.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/DetectLanguageInput.cs index e98597eb5389..befa0f6235d7 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/DetectLanguageInput.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/DetectLanguageInput.cs @@ -11,6 +11,12 @@ namespace Azure.AI.TextAnalytics /// public class DetectLanguageInput { + /// + /// A wildcard that allows to set CountryHint to None + /// so the servide model doesn't use any default CountryHint. + /// + public const string None = ""; + /// /// Initializes a new instance of the /// class. @@ -34,9 +40,8 @@ public DetectLanguageInput(string id, string text) /// Gets or sets a hint to assist the text analytics model in predicting /// the language the document is written in. If unspecified, this value /// will be set to the default country hint in - /// in the request sent to the service. If set to an empty string, the - /// service will apply a model where the country is explicitly set to - /// "None". + /// in the request sent to the service. + /// To remove this behavior, set to . /// public string CountryHint { get; set; } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs index 4f5b7a319eef..92f60cc9cb20 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs @@ -120,9 +120,8 @@ public TextAnalyticsClient(Uri endpoint, TextAnalyticsApiKeyCredential credentia /// input to assist the text analytics model in predicting the language /// it is written in. If unspecified, this value will be set to the /// default country hint in - /// in the request sent to the service. If set to an empty string, the - /// service will apply a model where the country is explicitly set to - /// "None". + /// in the request sent to the service. + /// To remove this behavior, set to . /// A /// controlling the request lifetime. /// A result containing the detected language or an error if @@ -180,9 +179,8 @@ public virtual async Task> DetectLanguageAsync(string /// input to assist the text analytics model in predicting the language /// it is written in. If unspecified, this value will be set to the /// default country hint in - /// in the request sent to the service. If set to an empty string, the - /// service will apply a model where the country is explicitly set to - /// "None". + /// in the request sent to the service. + /// To remove this behavior, set to . /// A /// controlling the request lifetime. /// A result containing the detected language or an error if @@ -240,10 +238,8 @@ public virtual Response DetectLanguage(string inputText, strin /// the input strings to assist the text analytics model in predicting /// the language they is written in. If unspecified, this value will be /// set to the default country hint in - /// in the request sent to the service. If set to an empty string, the - /// service will apply a model where the country is explicitly set to - /// "None". The same country hint is applied to all strings in the - /// input collection. + /// in the request sent to the service. + /// To remove this behavior, set to . /// used to /// select the version of the predictive model to run, and whether /// statistics are returned in the response. @@ -276,10 +272,8 @@ public virtual async Task> DetectLangua /// the input strings to assist the text analytics model in predicting /// the language they is written in. If unspecified, this value will be /// set to the default country hint in - /// in the request sent to the service. If set to an empty string, the - /// service will apply a model where the country is explicitly set to - /// "None". The same country hint is applied to all strings in the - /// input collection. + /// in the request sent to the service. + /// To remove this behavior, set to . /// used to /// select the version of the predictive model to run, and whether /// statistics are returned in the response. diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClientOptions.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClientOptions.cs index 623defdc7d9b..e6624af46172 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClientOptions.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClientOptions.cs @@ -36,10 +36,15 @@ public enum ServiceVersion internal ServiceVersion Version { get; } /// + /// Default country hint value to use in all client calls. + /// If no value is specified, "us" is set as default. + /// To remove this behavior, set to . /// public string DefaultCountryHint { get; set; } = "us"; /// + /// Default language value to use in all client calls. + /// If no value is specified, "en" is set as default. /// public string DefaultLanguage { get; set; } = "en"; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/TextAnalyticsClientLiveTests/DetectLanguageWithNoneCountryHintTest.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/TextAnalyticsClientLiveTests/DetectLanguageWithNoneCountryHintTest.json new file mode 100644 index 000000000000..4c2644143af8 --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/TextAnalyticsClientLiveTests/DetectLanguageWithNoneCountryHintTest.json @@ -0,0 +1,61 @@ +{ + "Entries": [ + { + "RequestUri": "https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/languages", + "RequestMethod": "POST", + "RequestHeaders": { + "Content-Length": "93", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-09035d864e8bae41af464332a16222c3-f080ae6b0a95094b-00", + "User-Agent": [ + "azsdk-net-AI.TextAnalytics/1.0.0-dev.20200218.1", + "(.NET Core 4.6.28207.04; Microsoft Windows 10.0.18363 )" + ], + "x-ms-client-request-id": "21f90272ac1b5edd287b2c95dfd55dfc", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "countryHint": "", + "id": "0", + "text": "Este documento est\u00E1 en espa\u00F1ol" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "305f5020-8cbd-4ef0-a594-719a4d11b0b1", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=1", + "Date": "Tue, 18 Feb 2020 22:51:31 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "X-Content-Type-Options": "nosniff", + "x-envoy-upstream-service-time": "3" + }, + "ResponseBody": { + "documents": [ + { + "id": "0", + "detectedLanguages": [ + { + "name": "Spanish", + "iso6391Name": "es", + "score": 1.0 + } + ] + } + ], + "errors": [], + "modelVersion": "2019-10-01" + } + } + ], + "Variables": { + "RandomSeed": "1506448079", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://westus2.api.cognitive.microsoft.com/" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/TextAnalyticsClientLiveTests/DetectLanguageWithNoneCountryHintTestAsync.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/TextAnalyticsClientLiveTests/DetectLanguageWithNoneCountryHintTestAsync.json new file mode 100644 index 000000000000..699d147e8f20 --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/TextAnalyticsClientLiveTests/DetectLanguageWithNoneCountryHintTestAsync.json @@ -0,0 +1,61 @@ +{ + "Entries": [ + { + "RequestUri": "https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/languages", + "RequestMethod": "POST", + "RequestHeaders": { + "Content-Length": "93", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-9dc4b56177c47c41bb53b5f12c5dd0e2-b03d8cb7c04fb048-00", + "User-Agent": [ + "azsdk-net-AI.TextAnalytics/1.0.0-dev.20200218.1", + "(.NET Core 4.6.28207.04; Microsoft Windows 10.0.18363 )" + ], + "x-ms-client-request-id": "9f218ecc079bbb07efa03cff76c0cb21", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "countryHint": "", + "id": "0", + "text": "Este documento est\u00E1 en espa\u00F1ol" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "d7048faa-5466-4aa8-a45d-0ab22f34609a", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=1", + "Date": "Tue, 18 Feb 2020 22:51:54 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "X-Content-Type-Options": "nosniff", + "x-envoy-upstream-service-time": "3" + }, + "ResponseBody": { + "documents": [ + { + "id": "0", + "detectedLanguages": [ + { + "name": "Spanish", + "iso6391Name": "es", + "score": 1.0 + } + ] + } + ], + "errors": [], + "modelVersion": "2019-10-01" + } + } + ], + "Variables": { + "RandomSeed": "1763080044", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://westus2.api.cognitive.microsoft.com/" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/TextAnalyticsClientLiveTests/DetectLanguageWithNoneDefaultCountryHintTest.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/TextAnalyticsClientLiveTests/DetectLanguageWithNoneDefaultCountryHintTest.json new file mode 100644 index 000000000000..a4434ee9615d --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/TextAnalyticsClientLiveTests/DetectLanguageWithNoneDefaultCountryHintTest.json @@ -0,0 +1,61 @@ +{ + "Entries": [ + { + "RequestUri": "https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/languages", + "RequestMethod": "POST", + "RequestHeaders": { + "Content-Length": "93", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-4c8b60097076ef4ca92ecc6bd8506f69-1d7e8c0dbba37c43-00", + "User-Agent": [ + "azsdk-net-AI.TextAnalytics/1.0.0-dev.20200218.1", + "(.NET Core 4.6.28207.04; Microsoft Windows 10.0.18363 )" + ], + "x-ms-client-request-id": "523ecc7d4e4fcb6c09c6d5511730541e", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "countryHint": "", + "id": "0", + "text": "Este documento est\u00E1 en espa\u00F1ol" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "f568a739-5812-4de4-9cf8-97a9a194408d", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=1", + "Date": "Tue, 18 Feb 2020 22:51:32 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "X-Content-Type-Options": "nosniff", + "x-envoy-upstream-service-time": "3" + }, + "ResponseBody": { + "documents": [ + { + "id": "0", + "detectedLanguages": [ + { + "name": "Spanish", + "iso6391Name": "es", + "score": 1.0 + } + ] + } + ], + "errors": [], + "modelVersion": "2019-10-01" + } + } + ], + "Variables": { + "RandomSeed": "2065732164", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://westus2.api.cognitive.microsoft.com/" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/TextAnalyticsClientLiveTests/DetectLanguageWithNoneDefaultCountryHintTestAsync.json b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/TextAnalyticsClientLiveTests/DetectLanguageWithNoneDefaultCountryHintTestAsync.json new file mode 100644 index 000000000000..a104bb5ebd27 --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/TextAnalyticsClientLiveTests/DetectLanguageWithNoneDefaultCountryHintTestAsync.json @@ -0,0 +1,61 @@ +{ + "Entries": [ + { + "RequestUri": "https://westus2.api.cognitive.microsoft.com/text/analytics/v3.0-preview.1/languages", + "RequestMethod": "POST", + "RequestHeaders": { + "Content-Length": "93", + "Content-Type": "application/json", + "Ocp-Apim-Subscription-Key": "Sanitized", + "traceparent": "00-740a8232ad83be4a81dcf13e282a7092-e7dd50c0dc36944a-00", + "User-Agent": [ + "azsdk-net-AI.TextAnalytics/1.0.0-dev.20200218.1", + "(.NET Core 4.6.28207.04; Microsoft Windows 10.0.18363 )" + ], + "x-ms-client-request-id": "7d93a4fb797636345bac973fd732473f", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": { + "documents": [ + { + "countryHint": "", + "id": "0", + "text": "Este documento est\u00E1 en espa\u00F1ol" + } + ] + }, + "StatusCode": 200, + "ResponseHeaders": { + "apim-request-id": "24898f53-a89c-4f6f-8ab1-e4ef1e339565", + "Content-Type": "application/json; charset=utf-8", + "csp-billing-usage": "CognitiveServices.TextAnalytics.BatchScoring=1", + "Date": "Tue, 18 Feb 2020 22:51:55 GMT", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", + "Transfer-Encoding": "chunked", + "X-Content-Type-Options": "nosniff", + "x-envoy-upstream-service-time": "3" + }, + "ResponseBody": { + "documents": [ + { + "id": "0", + "detectedLanguages": [ + { + "name": "Spanish", + "iso6391Name": "es", + "score": 1.0 + } + ] + } + ], + "errors": [], + "modelVersion": "2019-10-01" + } + } + ], + "Variables": { + "RandomSeed": "585137755", + "TEXT_ANALYTICS_API_KEY": "Sanitized", + "TEXT_ANALYTICS_ENDPOINT": "https://westus2.api.cognitive.microsoft.com/" + } +} \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientLiveTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientLiveTests.cs index bd958103a267..c72b82e86d95 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientLiveTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientLiveTests.cs @@ -21,15 +21,16 @@ public TextAnalyticsClientLiveTests(bool isAsync) : base(isAsync) Matcher = new RecordMatcher(Sanitizer); } - public TextAnalyticsClient GetClient(TextAnalyticsApiKeyCredential credential = default) + public TextAnalyticsClient GetClient(TextAnalyticsApiKeyCredential credential = default, TextAnalyticsClientOptions options = default) { string apiKey = Recording.GetVariableFromEnvironment(ApiKeyEnvironmentVariable); credential ??= new TextAnalyticsApiKeyCredential(apiKey); + options ??= new TextAnalyticsClientOptions(); return InstrumentClient ( new TextAnalyticsClient( new Uri(Recording.GetVariableFromEnvironment(EndpointEnvironmentVariable)), credential, - Recording.InstrumentClientOptions(new TextAnalyticsClientOptions())) + Recording.InstrumentClientOptions(options)) ); } @@ -67,6 +68,31 @@ public void DetectLanguageWithErrorCountryHintTest() Assert.AreEqual("InvalidCountryHint", ex.ErrorCode); } + [Test] + public async Task DetectLanguageWithNoneCountryHintTest() + { + TextAnalyticsClient client = GetClient(); + string input = "Este documento está en español"; + + DetectedLanguage language = await client.DetectLanguageAsync(input, DetectLanguageInput.None); + Assert.AreEqual("Spanish", language.Name); + } + + [Test] + public async Task DetectLanguageWithNoneDefaultCountryHintTest() + { + var options = new TextAnalyticsClientOptions() + { + DefaultCountryHint = DetectLanguageInput.None + }; + + TextAnalyticsClient client = GetClient(options: options); + string input = "Este documento está en español"; + + DetectedLanguage language = await client.DetectLanguageAsync(input, DetectLanguageInput.None); + Assert.AreEqual("Spanish", language.Name); + } + [Test] public async Task DetectLanguageBatchConvenienceTest() { diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample1_DetectLanguageBatch.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample1_DetectLanguageBatch.cs index 62a2e4a71e55..fc474365db27 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample1_DetectLanguageBatch.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample1_DetectLanguageBatch.cs @@ -38,7 +38,7 @@ public void DetectLanguageBatch() }, new DetectLanguageInput("4", ":) :( :D") { - CountryHint = "us", + CountryHint = DetectLanguageInput.None, } };