From 09d20a1077a6f4fd4b5d308508d8d351d727562f Mon Sep 17 00:00:00 2001 From: Mariana Rios Flores Date: Thu, 27 Aug 2020 13:40:15 -0700 Subject: [PATCH 1/3] add flags enum for OM --- .../Azure.AI.TextAnalytics.netstandard2.0.cs | 8 +++++- .../src/AnalyzeSentimentOptions.cs | 8 +++--- .../src/AnalyzeSentimentType.cs | 26 +++++++++++++++++++ .../src/SentenceSentiment.cs | 2 +- .../src/TextAnalyticsClient.cs | 15 +++++++---- 5 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentType.cs 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 37fe0463fd460..aab9d5d993bd2 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 @@ -3,7 +3,7 @@ namespace Azure.AI.TextAnalytics public partial class AnalyzeSentimentOptions : Azure.AI.TextAnalytics.TextAnalyticsRequestOptions { public AnalyzeSentimentOptions() { } - public bool IncludeOpinionMining { get { throw null; } set { } } + public Azure.AI.TextAnalytics.AnalyzeSentimentType IncludeAnalysis { get { throw null; } set { } } } public partial class AnalyzeSentimentResult : Azure.AI.TextAnalytics.TextAnalyticsResult { @@ -16,6 +16,12 @@ internal AnalyzeSentimentResultCollection() : base (default(System.Collections.G public string ModelVersion { get { throw null; } } public Azure.AI.TextAnalytics.TextDocumentBatchStatistics Statistics { get { throw null; } } } + [System.FlagsAttribute] + public enum AnalyzeSentimentType + { + None = 0, + OpinionMining = 1, + } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct AspectSentiment { diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentOptions.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentOptions.cs index 18f2fede2c624..54552866d5256 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentOptions.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentOptions.cs @@ -23,9 +23,9 @@ internal AnalyzeSentimentOptions(TextAnalyticsRequestOptions options) } /// - /// If set to true, response will contain Opinion Mining sentiment analysis results. - /// Only available for Text Analytics Service version v3.1-preview.1 and above. + /// Specifies the types of analysis to apply, like for example, + /// Opinion mining. /// - public bool IncludeOpinionMining { get; set; } = false; - } + public AnalyzeSentimentType IncludeAnalysis { get; set; } +} } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentType.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentType.cs new file mode 100644 index 0000000000000..43d8d85d22af1 --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentType.cs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; + +namespace Azure.AI.TextAnalytics +{ + /// + /// Specialized types of Sentiment Analysis, like for example Opinion Mining. + /// + [Flags] + public enum AnalyzeSentimentType + { + /// + /// Sentiment analysis for documents and its sentences. + /// + None = 0, + + /// + /// Sentiment analysis results with Opinion Mining, + /// also known as Aspect-based Sentiment Analysis. + /// Only available for Text Analytics Service version v3.1-preview.1 and above. + /// + OpinionMining = 1, + } +} diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/SentenceSentiment.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/SentenceSentiment.cs index 8c279cfe84135..3a349a44fba4b 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/SentenceSentiment.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/SentenceSentiment.cs @@ -57,7 +57,7 @@ internal SentenceSentiment(SentenceSentimentInternal sentenceSentiment, IReadOnl /// /// Gets the mined opinions of a sentence. This is only returned if - /// is set to true. + /// is set in . /// public IReadOnlyCollection MinedOpinions { get; } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs index 491271d0893cf..3567a528646c1 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs @@ -788,11 +788,12 @@ public virtual async Task> AnalyzeSentimentAsync(str try { var documents = new List() { ConvertToMultiLanguageInput(document, language) }; + bool opinionMining = options.IncludeAnalysis.HasFlag(AnalyzeSentimentType.OpinionMining) ? true : false; Response result = await _serviceRestClient.SentimentAsync( new MultiLanguageBatchInput(documents), options.ModelVersion, options.IncludeStatistics, - options.IncludeOpinionMining, + opinionMining, _stringCodeUnit, cancellationToken).ConfigureAwait(false); Response response = result.GetRawResponse(); @@ -848,11 +849,12 @@ public virtual Response AnalyzeSentiment(string document, str try { var documents = new List() { ConvertToMultiLanguageInput(document, language) }; + bool opinionMining = options.IncludeAnalysis.HasFlag(AnalyzeSentimentType.OpinionMining) ? true : false; Response result = _serviceRestClient.Sentiment( new MultiLanguageBatchInput(documents), options.ModelVersion, options.IncludeStatistics, - options.IncludeOpinionMining, + opinionMining, _stringCodeUnit, cancellationToken); Response response = result.GetRawResponse(); @@ -1126,11 +1128,12 @@ private async Task> AnalyzeSentimentB try { + bool opinionMining = options.IncludeAnalysis.HasFlag(AnalyzeSentimentType.OpinionMining) ? true : false; Response result = await _serviceRestClient.SentimentAsync( batchInput, options.ModelVersion, options.IncludeStatistics, - options.IncludeOpinionMining, + opinionMining, _stringCodeUnit, cancellationToken).ConfigureAwait(false); var response = result.GetRawResponse(); @@ -1153,10 +1156,12 @@ private Response AnalyzeSentimentBatch(MultiLa try { - Response result = _serviceRestClient.Sentiment(batchInput, + bool opinionMining = options.IncludeAnalysis.HasFlag(AnalyzeSentimentType.OpinionMining) ? true : false; + Response result = _serviceRestClient.Sentiment( + batchInput, options.ModelVersion, options.IncludeStatistics, - options.IncludeOpinionMining, + opinionMining, _stringCodeUnit, cancellationToken); var response = result.GetRawResponse(); From 84f7d7b86567dc78a7dd61cc32aaf6295f53425f Mon Sep 17 00:00:00 2001 From: Mariana Rios Flores Date: Tue, 1 Sep 2020 11:36:50 -0700 Subject: [PATCH 2/3] PR feedback --- ...SentimentType.cs => AdditionalSentimentAnalyses.cs} | 9 +++++---- .../src/AnalyzeSentimentOptions.cs | 6 +++--- .../Azure.AI.TextAnalytics/src/SentenceSentiment.cs | 2 +- .../Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs | 8 ++++---- .../tests/AnalyzeSentimentTests.cs | 10 +++++----- 5 files changed, 18 insertions(+), 17 deletions(-) rename sdk/textanalytics/Azure.AI.TextAnalytics/src/{AnalyzeSentimentType.cs => AdditionalSentimentAnalyses.cs} (60%) diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentType.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/AdditionalSentimentAnalyses.cs similarity index 60% rename from sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentType.cs rename to sdk/textanalytics/Azure.AI.TextAnalytics/src/AdditionalSentimentAnalyses.cs index 43d8d85d22af1..2773ef2f1a7a5 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentType.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/AdditionalSentimentAnalyses.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. + // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. using System; @@ -6,13 +6,14 @@ namespace Azure.AI.TextAnalytics { /// - /// Specialized types of Sentiment Analysis, like for example Opinion Mining. + /// Additional types of Sentiment Analysis to be applied to the + /// AnalyzeSentiment method, like for example Opinion Mining. /// [Flags] - public enum AnalyzeSentimentType + public enum AdditionalSentimentAnalyses { /// - /// Sentiment analysis for documents and its sentences. + /// Use standard sentiment analysis for documents and its sentences. /// None = 0, diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentOptions.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentOptions.cs index 54552866d5256..692011829b59f 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentOptions.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentOptions.cs @@ -23,9 +23,9 @@ internal AnalyzeSentimentOptions(TextAnalyticsRequestOptions options) } /// - /// Specifies the types of analysis to apply, like for example, - /// Opinion mining. + /// Additional types of Sentiment Analysis to be applied to the + /// AnalyzeSentiment method, like for example Opinion Mining. /// - public AnalyzeSentimentType IncludeAnalysis { get; set; } + public AdditionalSentimentAnalyses AdditionalSentimentAnalyses { get; set; } } } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/SentenceSentiment.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/SentenceSentiment.cs index 3a349a44fba4b..aa53b55323acb 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/SentenceSentiment.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/SentenceSentiment.cs @@ -57,7 +57,7 @@ internal SentenceSentiment(SentenceSentimentInternal sentenceSentiment, IReadOnl /// /// Gets the mined opinions of a sentence. This is only returned if - /// is set in . + /// is set in . /// public IReadOnlyCollection MinedOpinions { get; } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs index 3567a528646c1..20a120ac9cc60 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs @@ -788,7 +788,7 @@ public virtual async Task> AnalyzeSentimentAsync(str try { var documents = new List() { ConvertToMultiLanguageInput(document, language) }; - bool opinionMining = options.IncludeAnalysis.HasFlag(AnalyzeSentimentType.OpinionMining) ? true : false; + bool opinionMining = options.AdditionalSentimentAnalyses.HasFlag(AdditionalSentimentAnalyses.OpinionMining); Response result = await _serviceRestClient.SentimentAsync( new MultiLanguageBatchInput(documents), options.ModelVersion, @@ -849,7 +849,7 @@ public virtual Response AnalyzeSentiment(string document, str try { var documents = new List() { ConvertToMultiLanguageInput(document, language) }; - bool opinionMining = options.IncludeAnalysis.HasFlag(AnalyzeSentimentType.OpinionMining) ? true : false; + bool opinionMining = options.AdditionalSentimentAnalyses.HasFlag(AdditionalSentimentAnalyses.OpinionMining); Response result = _serviceRestClient.Sentiment( new MultiLanguageBatchInput(documents), options.ModelVersion, @@ -1128,7 +1128,7 @@ private async Task> AnalyzeSentimentB try { - bool opinionMining = options.IncludeAnalysis.HasFlag(AnalyzeSentimentType.OpinionMining) ? true : false; + bool opinionMining = options.AdditionalSentimentAnalyses.HasFlag(AdditionalSentimentAnalyses.OpinionMining); Response result = await _serviceRestClient.SentimentAsync( batchInput, options.ModelVersion, @@ -1156,7 +1156,7 @@ private Response AnalyzeSentimentBatch(MultiLa try { - bool opinionMining = options.IncludeAnalysis.HasFlag(AnalyzeSentimentType.OpinionMining) ? true : false; + bool opinionMining = options.AdditionalSentimentAnalyses.HasFlag(AdditionalSentimentAnalyses.OpinionMining); Response result = _serviceRestClient.Sentiment( batchInput, options.ModelVersion, diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeSentimentTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeSentimentTests.cs index 606bfd0cf936d..6089a82ab501d 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeSentimentTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeSentimentTests.cs @@ -65,7 +65,7 @@ public async Task AnalyzeSentimentWithOpinionMining() TextAnalyticsClient client = GetClient(); string document = "The park was clean and pretty. The bathrooms and restaurant were not clean."; - DocumentSentiment docSentiment = await client.AnalyzeSentimentAsync(document, options: new AnalyzeSentimentOptions() { IncludeOpinionMining = true }); + DocumentSentiment docSentiment = await client.AnalyzeSentimentAsync(document, options: new AnalyzeSentimentOptions() { AdditionalSentimentAnalyses = AdditionalSentimentAnalyses.OpinionMining }); CheckAnalyzeSentimentProperties(docSentiment, opinionMining: true); Assert.AreEqual("Mixed", docSentiment.Sentiment.ToString()); @@ -77,7 +77,7 @@ public async Task AnalyzeSentimentWithOpinionMiningEmpty() TextAnalyticsClient client = GetClient(); string document = singleEnglish; - DocumentSentiment docSentiment = await client.AnalyzeSentimentAsync(document, "en", new AnalyzeSentimentOptions() { IncludeOpinionMining = true }); + DocumentSentiment docSentiment = await client.AnalyzeSentimentAsync(document, "en", new AnalyzeSentimentOptions() { AdditionalSentimentAnalyses = AdditionalSentimentAnalyses.OpinionMining }); CheckAnalyzeSentimentProperties(docSentiment); Assert.AreEqual("Positive", docSentiment.Sentiment.ToString()); @@ -89,7 +89,7 @@ public async Task AnalyzeSentimentWithOpinionMiningNegated() TextAnalyticsClient client = GetClient(); string document = "The bathrooms are not clean."; - DocumentSentiment docSentiment = await client.AnalyzeSentimentAsync(document, options: new AnalyzeSentimentOptions() { IncludeOpinionMining = true }); + DocumentSentiment docSentiment = await client.AnalyzeSentimentAsync(document, options: new AnalyzeSentimentOptions() { AdditionalSentimentAnalyses = AdditionalSentimentAnalyses.OpinionMining }); CheckAnalyzeSentimentProperties(docSentiment, opinionMining: true); MinedOpinion minedOpinion = docSentiment.Sentences.FirstOrDefault().MinedOpinions.FirstOrDefault(); @@ -151,7 +151,7 @@ public async Task AnalyzeSentimentBatchConvenienceWithOpinionMiningTest() "The food and service is not good." }; - AnalyzeSentimentResultCollection results = await client.AnalyzeSentimentBatchAsync(documents, options: new AnalyzeSentimentOptions() { IncludeOpinionMining = true }); + AnalyzeSentimentResultCollection results = await client.AnalyzeSentimentBatchAsync(documents, options: new AnalyzeSentimentOptions() { AdditionalSentimentAnalyses = AdditionalSentimentAnalyses.OpinionMining }); foreach (AnalyzeSentimentResult docs in results) { @@ -334,7 +334,7 @@ public async Task AnalyzeSentimentBatchWithOpinionMiningTest() } }; - AnalyzeSentimentResultCollection results = await client.AnalyzeSentimentBatchAsync(documents, options: new AnalyzeSentimentOptions() { IncludeOpinionMining = true }); + AnalyzeSentimentResultCollection results = await client.AnalyzeSentimentBatchAsync(documents, options: new AnalyzeSentimentOptions() { AdditionalSentimentAnalyses = AdditionalSentimentAnalyses.OpinionMining }); foreach (AnalyzeSentimentResult docs in results) { From f71a4c930a9ff4d44f48566de104171ae342ac5c Mon Sep 17 00:00:00 2001 From: Mariana Rios Flores Date: Tue, 1 Sep 2020 11:56:09 -0700 Subject: [PATCH 3/3] export-api --- .../api/Azure.AI.TextAnalytics.netstandard2.0.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 aab9d5d993bd2..be7a68e8e6c5b 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 @@ -1,9 +1,15 @@ namespace Azure.AI.TextAnalytics { + [System.FlagsAttribute] + public enum AdditionalSentimentAnalyses + { + None = 0, + OpinionMining = 1, + } public partial class AnalyzeSentimentOptions : Azure.AI.TextAnalytics.TextAnalyticsRequestOptions { public AnalyzeSentimentOptions() { } - public Azure.AI.TextAnalytics.AnalyzeSentimentType IncludeAnalysis { get { throw null; } set { } } + public Azure.AI.TextAnalytics.AdditionalSentimentAnalyses AdditionalSentimentAnalyses { get { throw null; } set { } } } public partial class AnalyzeSentimentResult : Azure.AI.TextAnalytics.TextAnalyticsResult { @@ -16,12 +22,6 @@ internal AnalyzeSentimentResultCollection() : base (default(System.Collections.G public string ModelVersion { get { throw null; } } public Azure.AI.TextAnalytics.TextDocumentBatchStatistics Statistics { get { throw null; } } } - [System.FlagsAttribute] - public enum AnalyzeSentimentType - { - None = 0, - OpinionMining = 1, - } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct AspectSentiment {