From 50942eb8911ed5cc8ab8a6b90bc640845c21b4ae Mon Sep 17 00:00:00 2001 From: Mariana Rios Flores Date: Fri, 5 Feb 2021 16:45:28 -0800 Subject: [PATCH] expose length again --- .../Azure.AI.TextAnalytics/CHANGELOG.md | 3 +++ .../Azure.AI.TextAnalytics/README.md | 3 +++ .../Azure.AI.TextAnalytics.netstandard2.0.cs | 14 +++++++---- .../samples/Sample4_RecognizeEntities.md | 3 +++ .../Sample6_RecognizeLinkedEntities.md | 3 +++ .../src/AspectSentiment.cs | 11 +++++++-- .../src/CategorizedEntity.cs | 8 ++++++- .../src/HealthcareEntity.cs | 2 +- .../src/LinkedEntityMatch.cs | 12 ++++------ .../src/OpinionSentiment.cs | 11 +++++++-- .../Azure.AI.TextAnalytics/src/PiiEntity.cs | 8 ++++++- .../src/SentenceSentiment.cs | 11 +++++++-- .../src/TextAnalyticsModelFactory.cs | 24 +++++++++++-------- .../tests/AnalyzeSentimentTests.cs | 2 ++ .../tests/RecognizeEntitiesTests.cs | 1 + .../tests/RecognizeLinkedEntitiesTests.cs | 1 + .../tests/RecognizePiiEntitiesTests.cs | 1 + .../tests/TextAnalyticsClientLiveTests.cs | 5 ++++ .../samples/Sample4_RecognizeEntities.cs | 1 + .../samples/Sample4_RecognizeEntitiesAsync.cs | 1 + .../samples/Sample4_RecognizeEntitiesBatch.cs | 1 + .../Sample4_RecognizeEntitiesBatchAsync.cs | 1 + ...mple4_RecognizeEntitiesBatchConvenience.cs | 1 + ..._RecognizeEntitiesBatchConvenienceAsync.cs | 1 + .../Sample6_RecognizeLinkedEntities.cs | 1 + .../Sample6_RecognizeLinkedEntitiesAsync.cs | 1 + .../Sample6_RecognizeLinkedEntitiesBatch.cs | 1 + ...mple6_RecognizeLinkedEntitiesBatchAsync.cs | 1 + ...RecognizeLinkedEntitiesBatchConvenience.cs | 1 + ...nizeLinkedEntitiesBatchConvenienceAsync.cs | 1 + 30 files changed, 104 insertions(+), 31 deletions(-) diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md b/sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md index 31e9ab56c8eff..e6bd97b5d6090 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md @@ -1,6 +1,9 @@ # Release History ## 5.1.0-beta.4 (Unreleased) +### New features +- Added property `Length` to `CategorizedEntity`, `SentenceSentiment`, `LinkedEntityMatch`, `AspectSentiment`, `OpinionSentiment`, and `PiiEntity`. +- `StringIndexType` has been added to all endpoints as a new option to control how the `Offset` and `Length` are calculated by the service. ### Breaking changes - Renamed `RecognizeHealthcareEntitiesResultCollection` to `AnalyzeHealthcareEntitiesResultCollection`. diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/README.md b/sdk/textanalytics/Azure.AI.TextAnalytics/README.md index 7e0cede5f9eae..3ff50a3ffd1c3 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/README.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/README.md @@ -252,6 +252,7 @@ try { Console.WriteLine($" Text: {entity.Text}"); Console.WriteLine($" Offset: {entity.Offset}"); + Console.WriteLine($" Length: {entity.Length}"); Console.WriteLine($" Category: {entity.Category}"); if (!string.IsNullOrEmpty(entity.SubCategory)) Console.WriteLine($" SubCategory: {entity.SubCategory}"); @@ -333,6 +334,7 @@ try { Console.WriteLine($" Match Text: {match.Text}"); Console.WriteLine($" Offset: {match.Offset}"); + Console.WriteLine($" Length: {match.Length}"); Console.WriteLine($" Confidence score: {match.ConfidenceScore}"); } Console.WriteLine(""); @@ -394,6 +396,7 @@ try { Console.WriteLine($" Text: {entity.Text}"); Console.WriteLine($" Offset: {entity.Offset}"); + Console.WriteLine($" Length: {entity.Length}"); Console.WriteLine($" Category: {entity.Category}"); if (!string.IsNullOrEmpty(entity.SubCategory)) Console.WriteLine($" SubCategory: {entity.SubCategory}"); 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 c886dd3defc5b..03a016092e640 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 @@ -103,6 +103,7 @@ public readonly partial struct AspectSentiment private readonly object _dummy; private readonly int _dummyPrimitive; public Azure.AI.TextAnalytics.SentimentConfidenceScores ConfidenceScores { get { throw null; } } + public int Length { get { throw null; } } public int Offset { get { throw null; } } public Azure.AI.TextAnalytics.TextSentiment Sentiment { get { throw null; } } public string Text { get { throw null; } } @@ -114,6 +115,7 @@ public readonly partial struct CategorizedEntity private readonly int _dummyPrimitive; public Azure.AI.TextAnalytics.EntityCategory Category { get { throw null; } } public double ConfidenceScore { get { throw null; } } + public int Length { get { throw null; } } public int Offset { get { throw null; } } public string SubCategory { get { throw null; } } public string Text { get { throw null; } } @@ -310,6 +312,7 @@ public readonly partial struct LinkedEntityMatch private readonly object _dummy; private readonly int _dummyPrimitive; public double ConfidenceScore { get { throw null; } } + public int Length { get { throw null; } } public int Offset { get { throw null; } } public string Text { get { throw null; } } } @@ -328,6 +331,7 @@ public readonly partial struct OpinionSentiment private readonly int _dummyPrimitive; public Azure.AI.TextAnalytics.SentimentConfidenceScores ConfidenceScores { get { throw null; } } public bool IsNegated { get { throw null; } } + public int Length { get { throw null; } } public int Offset { get { throw null; } } public Azure.AI.TextAnalytics.TextSentiment Sentiment { get { throw null; } } public string Text { get { throw null; } } @@ -346,6 +350,7 @@ public readonly partial struct PiiEntity private readonly int _dummyPrimitive; public Azure.AI.TextAnalytics.EntityCategory Category { get { throw null; } } public double ConfidenceScore { get { throw null; } } + public int Length { get { throw null; } } public int Offset { get { throw null; } } public string SubCategory { get { throw null; } } public string Text { get { throw null; } } @@ -434,6 +439,7 @@ public readonly partial struct SentenceSentiment private readonly object _dummy; private readonly int _dummyPrimitive; public Azure.AI.TextAnalytics.SentimentConfidenceScores ConfidenceScores { get { throw null; } } + public int Length { get { throw null; } } public System.Collections.Generic.IReadOnlyCollection MinedOpinions { get { throw null; } } public int Offset { get { throw null; } } public Azure.AI.TextAnalytics.TextSentiment Sentiment { get { throw null; } } @@ -607,7 +613,7 @@ public static partial class TextAnalyticsModelFactory public static Azure.AI.TextAnalytics.AnalyzeSentimentResult AnalyzeSentimentResult(string id, Azure.AI.TextAnalytics.TextAnalyticsError error) { throw null; } public static Azure.AI.TextAnalytics.AnalyzeSentimentResult AnalyzeSentimentResult(string id, Azure.AI.TextAnalytics.TextDocumentStatistics statistics, Azure.AI.TextAnalytics.DocumentSentiment documentSentiment) { throw null; } public static Azure.AI.TextAnalytics.AnalyzeSentimentResultCollection AnalyzeSentimentResultCollection(System.Collections.Generic.IEnumerable list, Azure.AI.TextAnalytics.TextDocumentBatchStatistics statistics, string modelVersion) { throw null; } - public static Azure.AI.TextAnalytics.AspectSentiment AspectSentiment(Azure.AI.TextAnalytics.TextSentiment sentiment, string text, double positiveScore, double negativeScore, int offset) { throw null; } + public static Azure.AI.TextAnalytics.AspectSentiment AspectSentiment(Azure.AI.TextAnalytics.TextSentiment sentiment, string text, double positiveScore, double negativeScore, int offset, int length) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.AI.TextAnalytics.CategorizedEntity CategorizedEntity(string text, string category, string subCategory, double score) { throw null; } public static Azure.AI.TextAnalytics.CategorizedEntity CategorizedEntity(string text, string category, string subCategory, double score, int offset) { throw null; } @@ -627,9 +633,9 @@ public static partial class TextAnalyticsModelFactory public static Azure.AI.TextAnalytics.LinkedEntityCollection LinkedEntityCollection(System.Collections.Generic.IList entities, System.Collections.Generic.IList warnings = null) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.AI.TextAnalytics.LinkedEntityMatch LinkedEntityMatch(string text, double score) { throw null; } - public static Azure.AI.TextAnalytics.LinkedEntityMatch LinkedEntityMatch(string text, double score, int offset) { throw null; } + public static Azure.AI.TextAnalytics.LinkedEntityMatch LinkedEntityMatch(string text, double score, int offset, int length) { throw null; } public static Azure.AI.TextAnalytics.MinedOpinion MinedOpinion(Azure.AI.TextAnalytics.AspectSentiment aspect, System.Collections.Generic.IReadOnlyList opinions) { throw null; } - public static Azure.AI.TextAnalytics.OpinionSentiment OpinionSentiment(Azure.AI.TextAnalytics.TextSentiment sentiment, double positiveScore, double negativeScore, string text, bool isNegated, int offset) { throw null; } + public static Azure.AI.TextAnalytics.OpinionSentiment OpinionSentiment(Azure.AI.TextAnalytics.TextSentiment sentiment, double positiveScore, double negativeScore, string text, bool isNegated, int offset, int length) { throw null; } public static Azure.AI.TextAnalytics.PiiEntity PiiEntity(string text, string category, string subCategory, double score, int offset) { throw null; } public static Azure.AI.TextAnalytics.PiiEntityCollection PiiEntityCollection(System.Collections.Generic.IList entities, string redactedText, System.Collections.Generic.IList warnings = null) { throw null; } public static Azure.AI.TextAnalytics.RecognizeEntitiesResult RecognizeEntitiesResult(string id, Azure.AI.TextAnalytics.TextAnalyticsError error) { throw null; } @@ -643,7 +649,7 @@ public static partial class TextAnalyticsModelFactory public static Azure.AI.TextAnalytics.RecognizePiiEntitiesResultCollection RecognizePiiEntitiesResultCollection(System.Collections.Generic.IEnumerable list, Azure.AI.TextAnalytics.TextDocumentBatchStatistics statistics, string modelVersion) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.AI.TextAnalytics.SentenceSentiment SentenceSentiment(Azure.AI.TextAnalytics.TextSentiment sentiment, string text, double positiveScore, double neutralScore, double negativeScore) { throw null; } - public static Azure.AI.TextAnalytics.SentenceSentiment SentenceSentiment(Azure.AI.TextAnalytics.TextSentiment sentiment, string text, double positiveScore, double neutralScore, double negativeScore, int offset, System.Collections.Generic.IReadOnlyList minedOpinions) { throw null; } + public static Azure.AI.TextAnalytics.SentenceSentiment SentenceSentiment(Azure.AI.TextAnalytics.TextSentiment sentiment, string text, double positiveScore, double neutralScore, double negativeScore, int offset, int length, System.Collections.Generic.IReadOnlyList minedOpinions) { throw null; } public static Azure.AI.TextAnalytics.SentimentConfidenceScores SentimentConfidenceScores(double positiveScore, double neutralScore, double negativeScore) { throw null; } public static Azure.AI.TextAnalytics.TextAnalyticsError TextAnalyticsError(string code, string message, string target = null) { throw null; } public static Azure.AI.TextAnalytics.TextAnalyticsWarning TextAnalyticsWarning(string code, string message) { throw null; } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample4_RecognizeEntities.md b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample4_RecognizeEntities.md index 3118a7bffe283..480cee4ccbcc1 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample4_RecognizeEntities.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample4_RecognizeEntities.md @@ -35,6 +35,7 @@ try { Console.WriteLine($" Text: {entity.Text}"); Console.WriteLine($" Offset: {entity.Offset}"); + Console.WriteLine($" Length: {entity.Length}"); Console.WriteLine($" Category: {entity.Category}"); if (!string.IsNullOrEmpty(entity.SubCategory)) Console.WriteLine($" SubCategory: {entity.SubCategory}"); @@ -107,6 +108,7 @@ foreach (RecognizeEntitiesResult entitiesInDocument in entititesPerDocuments) { Console.WriteLine($" Text: {entity.Text}"); Console.WriteLine($" Offset: {entity.Offset}"); + Console.WriteLine($" Length: {entity.Length}"); Console.WriteLine($" Category: {entity.Category}"); if (!string.IsNullOrEmpty(entity.SubCategory)) Console.WriteLine($" SubCategory: {entity.SubCategory}"); @@ -184,6 +186,7 @@ foreach (RecognizeEntitiesResult entitiesInDocument in entitiesInDocuments) { Console.WriteLine($" Text: {entity.Text}"); Console.WriteLine($" Offset: {entity.Offset}"); + Console.WriteLine($" Length: {entity.Length}"); Console.WriteLine($" Category: {entity.Category}"); if (!string.IsNullOrEmpty(entity.SubCategory)) Console.WriteLine($" SubCategory: {entity.SubCategory}"); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample6_RecognizeLinkedEntities.md b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample6_RecognizeLinkedEntities.md index 37ee460cb9d31..7782cc07c7cc0 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample6_RecognizeLinkedEntities.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample6_RecognizeLinkedEntities.md @@ -41,6 +41,7 @@ try { Console.WriteLine($" Match Text: {match.Text}"); Console.WriteLine($" Offset: {match.Offset}"); + Console.WriteLine($" Length: {match.Length}"); Console.WriteLine($" Confidence score: {match.ConfidenceScore}"); } Console.WriteLine(""); @@ -110,6 +111,7 @@ foreach (RecognizeLinkedEntitiesResult entitiesInDocument in entitiesInDocuments { Console.WriteLine($" Match Text: {match.Text}"); Console.WriteLine($" Offset: {match.Offset}"); + Console.WriteLine($" Length: {match.Length}"); Console.WriteLine($" Confidence score: {match.ConfidenceScore}"); } Console.WriteLine(""); @@ -187,6 +189,7 @@ foreach (RecognizeLinkedEntitiesResult entitiesInDocument in entitiesPerDocument { Console.WriteLine($" Match Text: {match.Text}"); Console.WriteLine($" Offset: {match.Offset}"); + Console.WriteLine($" Length: {match.Length}"); Console.WriteLine($" Confidence score: {match.ConfidenceScore}"); } Console.WriteLine(""); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/AspectSentiment.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/AspectSentiment.cs index 0aad2de5bab74..c5da6d655d974 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/AspectSentiment.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/AspectSentiment.cs @@ -17,12 +17,13 @@ public readonly struct AspectSentiment { private const double _neutralValue = 0d; - internal AspectSentiment(TextSentiment sentiment, string text, double positiveScore, double negativeScore, int offset) + internal AspectSentiment(TextSentiment sentiment, string text, double positiveScore, double negativeScore, int offset, int length) { Sentiment = sentiment; Text = text; ConfidenceScores = new SentimentConfidenceScores(positiveScore, _neutralValue, negativeScore); Offset = offset; + Length = length; } internal AspectSentiment(SentenceAspect sentenceAspect) @@ -33,6 +34,7 @@ internal AspectSentiment(SentenceAspect sentenceAspect) ConfidenceScores = new SentimentConfidenceScores(sentenceAspect.ConfidenceScores.Positive, _neutralValue, sentenceAspect.ConfidenceScores.Negative); Sentiment = (TextSentiment)Enum.Parse(typeof(TextSentiment), sentenceAspect.Sentiment, ignoreCase: true); Offset = sentenceAspect.Offset; + Length = sentenceAspect.Length; } /// @@ -57,8 +59,13 @@ internal AspectSentiment(SentenceAspect sentenceAspect) public SentimentConfidenceScores ConfidenceScores { get; } /// - /// Gets the starting position (in UTF-16 code units) for the aspect text. + /// Gets the starting position for the aspect text. /// public int Offset { get; } + + /// + /// Gets the length of the aspect text. + /// + public int Length { get; } } } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/CategorizedEntity.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/CategorizedEntity.cs index 68f3f23bb109d..d2307480a8000 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/CategorizedEntity.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/CategorizedEntity.cs @@ -22,6 +22,7 @@ internal CategorizedEntity(Entity entity) SubCategory = entity.Subcategory; ConfidenceScore = entity.ConfidenceScore; Offset = entity.Offset; + Length = entity.Length; } /// @@ -53,8 +54,13 @@ internal CategorizedEntity(Entity entity) public double ConfidenceScore { get; } /// - /// Gets the starting position (in UTF-16 code units) for the matching text in the input document. + /// Gets the starting position for the matching text in the input document. /// public int Offset { get; } + + /// + /// Gets the length of the matching text in the input document. + /// + public int Length { get; } } } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/HealthcareEntity.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/HealthcareEntity.cs index e2f6335c263b4..0f42dbee0adb3 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/HealthcareEntity.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/HealthcareEntity.cs @@ -50,7 +50,7 @@ internal HealthcareEntity(HealthcareEntityInternal entity) public double ConfidenceScore { get; } /// - /// Gets the starting position (in UTF-16 code units) for the matching text in the input document. + /// Gets the starting position for the matching text in the input document. /// public int Offset { get; } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/LinkedEntityMatch.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/LinkedEntityMatch.cs index 20f777922e992..804405c6ad38f 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/LinkedEntityMatch.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/LinkedEntityMatch.cs @@ -13,18 +13,14 @@ namespace Azure.AI.TextAnalytics [CodeGenModel("Match")] public readonly partial struct LinkedEntityMatch { - // use for deserialization internal LinkedEntityMatch(double confidenceScore, string text, int offset, int length) - : this(confidenceScore, text, offset) => Length = length; - - internal LinkedEntityMatch(double confidenceScore, string text, int offset) { // We shipped TA 5.0.0 Text == string.Empty if the service returned a null value for Text. // Because we don't want to introduce a breaking change, we are transforming that null to string.Empty Text = text ?? string.Empty; ConfidenceScore = confidenceScore; Offset = offset; - Length = default; + Length = length; } /// @@ -39,13 +35,13 @@ internal LinkedEntityMatch(double confidenceScore, string text, int offset) public double ConfidenceScore { get; } /// - /// Gets the starting position (in UTF-16 code units) for the matching text in the document. + /// Gets the starting position for the matching text in the document. /// public int Offset { get; } /// - /// Gets the length (in UTF-16 code units) of the matching text in the sentence. + /// Gets the length of the matching text in the sentence. /// - private int Length { get; } + public int Length { get; } } } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/OpinionSentiment.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/OpinionSentiment.cs index f1b285d450668..efa6a9bfd2dfd 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/OpinionSentiment.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/OpinionSentiment.cs @@ -15,13 +15,14 @@ public readonly struct OpinionSentiment { private const double _neutralValue = 0d; - internal OpinionSentiment(TextSentiment sentiment, double positiveScore, double negativeScore, string text, bool isNegated, int offset) + internal OpinionSentiment(TextSentiment sentiment, double positiveScore, double negativeScore, string text, bool isNegated, int offset, int length) { Sentiment = sentiment; ConfidenceScores = new SentimentConfidenceScores(positiveScore, _neutralValue, negativeScore); Text = text; IsNegated = isNegated; Offset = offset; + Length = length; } internal OpinionSentiment(SentenceOpinion opinion) @@ -33,6 +34,7 @@ internal OpinionSentiment(SentenceOpinion opinion) Sentiment = (TextSentiment)Enum.Parse(typeof(TextSentiment), opinion.Sentiment, ignoreCase: true); IsNegated = opinion.IsNegated; Offset = opinion.Offset; + Length = opinion.Length; } /// @@ -63,8 +65,13 @@ internal OpinionSentiment(SentenceOpinion opinion) public bool IsNegated { get; } /// - /// Gets the starting position (in UTF-16 code units) for the opinion text. + /// Gets the starting position for the opinion text. /// public int Offset { get; } + + /// + /// Gets the length of the opinion text. + /// + public int Length { get; } } } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/PiiEntity.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/PiiEntity.cs index dae6b20bd38a1..857f7d61e7e12 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/PiiEntity.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/PiiEntity.cs @@ -20,6 +20,7 @@ internal PiiEntity(Entity entity) SubCategory = entity.Subcategory; ConfidenceScore = entity.ConfidenceScore; Offset = entity.Offset; + Length = entity.Length; } /// @@ -51,8 +52,13 @@ internal PiiEntity(Entity entity) public double ConfidenceScore { get; } /// - /// Gets the starting position (in UTF-16 code units) for the matching text in the input document. + /// Gets the starting position for the matching text in the input document. /// public int Offset { get; } + + /// + /// Gets the length of the matching text in the input document. + /// + public int Length { get; } } } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/SentenceSentiment.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/SentenceSentiment.cs index f19a0067abaa3..6e73d8c21184a 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/SentenceSentiment.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/SentenceSentiment.cs @@ -17,12 +17,13 @@ namespace Azure.AI.TextAnalytics /// public readonly struct SentenceSentiment { - internal SentenceSentiment(TextSentiment sentiment, string text, double positiveScore, double neutralScore, double negativeScore, int offset, IReadOnlyList minedOpinions) + internal SentenceSentiment(TextSentiment sentiment, string text, double positiveScore, double neutralScore, double negativeScore, int offset, int length, IReadOnlyList minedOpinions) { Sentiment = sentiment; Text = text; ConfidenceScores = new SentimentConfidenceScores(positiveScore, neutralScore, negativeScore); Offset = offset; + Length = length; MinedOpinions = new List(minedOpinions); } @@ -36,6 +37,7 @@ internal SentenceSentiment(SentenceSentimentInternal sentenceSentiment, IReadOnl Sentiment = (TextSentiment)Enum.Parse(typeof(TextSentiment), sentenceSentiment.Sentiment, ignoreCase: true); MinedOpinions = ConvertToMinedOpinions(sentenceSentiment, allSentences); Offset = sentenceSentiment.Offset; + Length = sentenceSentiment.Length; } /// @@ -61,10 +63,15 @@ internal SentenceSentiment(SentenceSentimentInternal sentenceSentiment, IReadOnl public IReadOnlyCollection MinedOpinions { get; } /// - /// Gets the starting position (in UTF-16 code units) for the matching text in the sentence. + /// Gets the starting position for the matching text in the sentence. /// public int Offset { get; } + /// + /// Gets the length the matching text in the sentence. + /// + public int Length { get; } + private static IReadOnlyCollection ConvertToMinedOpinions(SentenceSentimentInternal sentence, IReadOnlyList allSentences) { var minedOpinions = new List(); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsModelFactory.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsModelFactory.cs index 0a22ca07aa8f2..54cd5a62eaf33 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsModelFactory.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsModelFactory.cs @@ -105,7 +105,7 @@ public static DocumentSentiment DocumentSentiment(TextSentiment sentiment, doubl [EditorBrowsable(EditorBrowsableState.Never)] public static SentenceSentiment SentenceSentiment(TextSentiment sentiment, string text, double positiveScore, double neutralScore, double negativeScore) { - return new SentenceSentiment(sentiment, text, positiveScore, neutralScore, negativeScore, default, new List()); + return new SentenceSentiment(sentiment, text, positiveScore, neutralScore, negativeScore, default, default, new List()); } /// @@ -117,12 +117,13 @@ public static SentenceSentiment SentenceSentiment(TextSentiment sentiment, strin /// Sets the property. /// Sets the property. /// Sets the property. + /// Sets the property. /// Sets the property. /// A new instance of for mocking purposes. - public static SentenceSentiment SentenceSentiment(TextSentiment sentiment, string text, double positiveScore, double neutralScore, double negativeScore, int offset, IReadOnlyList minedOpinions) + public static SentenceSentiment SentenceSentiment(TextSentiment sentiment, string text, double positiveScore, double neutralScore, double negativeScore, int offset, int length, IReadOnlyList minedOpinions) { minedOpinions ??= new List(); - return new SentenceSentiment(sentiment, text, positiveScore, neutralScore, negativeScore, offset, minedOpinions); + return new SentenceSentiment(sentiment, text, positiveScore, neutralScore, negativeScore, offset, length, minedOpinions); } /// @@ -133,10 +134,11 @@ public static SentenceSentiment SentenceSentiment(TextSentiment sentiment, strin /// Sets the property. /// Sets the property. /// Sets the property. + /// Sets the property. /// >A new instance of for mocking purposes. - public static AspectSentiment AspectSentiment(TextSentiment sentiment, string text, double positiveScore, double negativeScore, int offset) + public static AspectSentiment AspectSentiment(TextSentiment sentiment, string text, double positiveScore, double negativeScore, int offset, int length) { - return new AspectSentiment(sentiment, text, positiveScore, negativeScore, offset); + return new AspectSentiment(sentiment, text, positiveScore, negativeScore, offset, length); } /// @@ -148,10 +150,11 @@ public static AspectSentiment AspectSentiment(TextSentiment sentiment, string te /// Sets the property. /// Sets the property. /// Sets the property. + /// Sets the property. /// A new instance of for mocking purposes. - public static OpinionSentiment OpinionSentiment(TextSentiment sentiment, double positiveScore, double negativeScore, string text, bool isNegated, int offset) + public static OpinionSentiment OpinionSentiment(TextSentiment sentiment, double positiveScore, double negativeScore, string text, bool isNegated, int offset, int length) { - return new OpinionSentiment(sentiment, positiveScore, negativeScore, text, isNegated, offset); + return new OpinionSentiment(sentiment, positiveScore, negativeScore, text, isNegated, offset, length); } /// @@ -489,7 +492,7 @@ public static LinkedEntity LinkedEntity(string name, string dataSourceEntityId, [EditorBrowsable(EditorBrowsableState.Never)] public static LinkedEntityMatch LinkedEntityMatch(string text, double score) { - return new LinkedEntityMatch(score, text, default); + return new LinkedEntityMatch(score, text, default, default); } /// @@ -498,10 +501,11 @@ public static LinkedEntityMatch LinkedEntityMatch(string text, double score) /// Sets the property. /// Sets the property. /// Sets the property. + /// Sets the property. /// A new instance of for mocking purposes. - public static LinkedEntityMatch LinkedEntityMatch(string text, double score, int offset) + public static LinkedEntityMatch LinkedEntityMatch(string text, double score, int offset, int length) { - return new LinkedEntityMatch(score, text, offset); + return new LinkedEntityMatch(score, text, offset, length); } /// diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeSentimentTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeSentimentTests.cs index e2fb524129e7f..540bb7dc3f426 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeSentimentTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeSentimentTests.cs @@ -455,6 +455,7 @@ private void CheckAnalyzeSentimentProperties(DocumentSentiment doc, bool opinion Assert.AreEqual(0, minedOpinions.Aspect.ConfidenceScores.Neutral); Assert.IsTrue(CheckTotalConfidenceScoreValue(minedOpinions.Aspect.ConfidenceScores)); Assert.IsNotNull(minedOpinions.Aspect.Offset); + Assert.IsNotNull(minedOpinions.Aspect.Length); // Opinions Assert.IsNotNull(minedOpinions.Opinions); @@ -469,6 +470,7 @@ private void CheckAnalyzeSentimentProperties(DocumentSentiment doc, bool opinion Assert.IsTrue(CheckTotalConfidenceScoreValue(opinion.ConfidenceScores)); Assert.IsNotNull(opinion.IsNegated); Assert.IsNotNull(opinion.Offset); + Assert.IsNotNull(opinion.Length); } } } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeEntitiesTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeEntitiesTests.cs index 293c874201f2b..655c4fb5bd78d 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeEntitiesTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeEntitiesTests.cs @@ -231,6 +231,7 @@ private void ValidateInDocumenResult(CategorizedEntityCollection entities, List< Assert.IsNotNull(entity.Category); Assert.GreaterOrEqual(entity.ConfidenceScore, 0.0); Assert.GreaterOrEqual(entity.Offset, 0); + Assert.Greater(entity.Length, 0); if (entity.SubCategory != null) { diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeLinkedEntitiesTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeLinkedEntitiesTests.cs index c3c53707d0289..06b8a77f58071 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeLinkedEntitiesTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeLinkedEntitiesTests.cs @@ -229,6 +229,7 @@ private void ValidateInDocumenResult(LinkedEntityCollection entities, List Assert.IsNotNull(entity.Category); Assert.GreaterOrEqual(entity.ConfidenceScore, 0.0); Assert.GreaterOrEqual(entity.Offset, 0); + Assert.Greater(entity.Length, 0); if (entity.SubCategory != null) { diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientLiveTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientLiveTests.cs index 89f387d196097..93d1b6e3f511a 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientLiveTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientLiveTests.cs @@ -23,6 +23,7 @@ public async Task TextWithEmoji() Assert.AreEqual(1, entities.Count); Assert.AreEqual("Microsoft", entities.FirstOrDefault().Text); Assert.AreEqual(3, entities.FirstOrDefault().Offset); + Assert.AreEqual(9, entities.FirstOrDefault().Length); } [Test] @@ -40,10 +41,12 @@ public async Task TextWithStringIndexType() Assert.AreEqual(1, entitiesWithUnicodeCodePoint.Count); Assert.AreEqual("Microsoft", entitiesWithUnicodeCodePoint.FirstOrDefault().Text); Assert.AreEqual(2, entitiesWithUnicodeCodePoint.FirstOrDefault().Offset); + Assert.AreEqual(9, entitiesWithUnicodeCodePoint.FirstOrDefault().Length); Assert.AreEqual(1, entitiesWithUtf16CodeUnit.Count); Assert.AreEqual("Microsoft", entitiesWithUtf16CodeUnit.FirstOrDefault().Text); Assert.AreEqual(3, entitiesWithUtf16CodeUnit.FirstOrDefault().Offset); + Assert.AreEqual(9, entitiesWithUtf16CodeUnit.FirstOrDefault().Length); } [Test] @@ -57,6 +60,7 @@ public async Task TextWithDiacriticsNFC() Assert.AreEqual(1, entities.Count); Assert.AreEqual("Microsoft", entities.FirstOrDefault().Text); Assert.AreEqual(4, entities.FirstOrDefault().Offset); + Assert.AreEqual(9, entities.FirstOrDefault().Length); } [Test] @@ -70,6 +74,7 @@ public async Task TextInKoreanNFC() Assert.AreEqual(1, entities.Count); Assert.AreEqual("Bill Gates", entities.FirstOrDefault().Text); Assert.AreEqual(3, entities.FirstOrDefault().Offset); + Assert.AreEqual(10, entities.FirstOrDefault().Length); } [Test] diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntities.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntities.cs index 216d53efb3b6a..b71aac5438d40 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntities.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntities.cs @@ -36,6 +36,7 @@ We tried again today and it was amazing. Everyone in my family liked the trail a { Console.WriteLine($" Text: {entity.Text}"); Console.WriteLine($" Offset: {entity.Offset}"); + Console.WriteLine($" Length: {entity.Length}"); Console.WriteLine($" Category: {entity.Category}"); if (!string.IsNullOrEmpty(entity.SubCategory)) Console.WriteLine($" SubCategory: {entity.SubCategory}"); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesAsync.cs index 30b4723c9f2fe..20bbfd6ae196b 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesAsync.cs @@ -38,6 +38,7 @@ We tried again today and it was amazing. Everyone in my family liked the trail a { Console.WriteLine($" Text: {entity.Text}"); Console.WriteLine($" Offset: {entity.Offset}"); + Console.WriteLine($" Length: {entity.Length}"); Console.WriteLine($" Category: {entity.Category}"); if (!string.IsNullOrEmpty(entity.SubCategory)) Console.WriteLine($" SubCategory: {entity.SubCategory}"); 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 2d40b9e0284f3..9e4ce22a1e50a 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatch.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatch.cs @@ -85,6 +85,7 @@ The spa was clean and felt very peaceful. Overall the whole experience was great { Console.WriteLine($" Text: {entity.Text}"); Console.WriteLine($" Offset: {entity.Offset}"); + Console.WriteLine($" Length: {entity.Length}"); Console.WriteLine($" Category: {entity.Category}"); if (!string.IsNullOrEmpty(entity.SubCategory)) Console.WriteLine($" SubCategory: {entity.SubCategory}"); 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 38e16d2418ee9..67a423072704d 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchAsync.cs @@ -85,6 +85,7 @@ The spa was clean and felt very peaceful. Overall the whole experience was great { Console.WriteLine($" Text: {entity.Text}"); Console.WriteLine($" Offset: {entity.Offset}"); + Console.WriteLine($" Length: {entity.Length}"); Console.WriteLine($" Category: {entity.Category}"); if (!string.IsNullOrEmpty(entity.SubCategory)) Console.WriteLine($" SubCategory: {entity.SubCategory}"); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchConvenience.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchConvenience.cs index a3f2812eaf051..53c5b151ba678 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchConvenience.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchConvenience.cs @@ -76,6 +76,7 @@ The spa was clean and felt very peaceful. Overall the whole experience was great { Console.WriteLine($" Text: {entity.Text}"); Console.WriteLine($" Offset: {entity.Offset}"); + Console.WriteLine($" Length: {entity.Length}"); Console.WriteLine($" Category: {entity.Category}"); if (!string.IsNullOrEmpty(entity.SubCategory)) Console.WriteLine($" SubCategory: {entity.SubCategory}"); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchConvenienceAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchConvenienceAsync.cs index e897966d9c652..51d29c4e62282 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchConvenienceAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchConvenienceAsync.cs @@ -75,6 +75,7 @@ The spa was clean and felt very peaceful. Overall the whole experience was great { Console.WriteLine($" Text: {entity.Text}"); Console.WriteLine($" Offset: {entity.Offset}"); + Console.WriteLine($" Length: {entity.Length}"); Console.WriteLine($" Category: {entity.Category}"); if (!string.IsNullOrEmpty(entity.SubCategory)) Console.WriteLine($" SubCategory: {entity.SubCategory}"); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntities.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntities.cs index 2a50c79c2d8ae..1ef8490a236c7 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntities.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntities.cs @@ -42,6 +42,7 @@ public void ExtractEntityLinking() { Console.WriteLine($" Match Text: {match.Text}"); Console.WriteLine($" Offset: {match.Offset}"); + Console.WriteLine($" Length: {match.Length}"); Console.WriteLine($" Confidence score: {match.ConfidenceScore}"); } Console.WriteLine(""); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesAsync.cs index 8b75ebdc83ffc..b4c3bd62d4e1e 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesAsync.cs @@ -42,6 +42,7 @@ public async Task ExtractEntityLinkingAsync() { Console.WriteLine($" Match Text: {match.Text}"); Console.WriteLine($" Offset: {match.Offset}"); + Console.WriteLine($" Length: {match.Length}"); Console.WriteLine($" Confidence score: {match.ConfidenceScore}"); } Console.WriteLine(""); 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 31f3c6a4a4717..2e4fa0f4ffeef 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatch.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatch.cs @@ -86,6 +86,7 @@ public void ExtractEntityLinkingBatch() { Console.WriteLine($" Match Text: {match.Text}"); Console.WriteLine($" Offset: {match.Offset}"); + Console.WriteLine($" Length: {match.Length}"); Console.WriteLine($" Confidence score: {match.ConfidenceScore}"); } Console.WriteLine(""); 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 5d41a5a5b16c2..e6760275f0b0b 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchAsync.cs @@ -86,6 +86,7 @@ public async Task ExtractEntityLinkingBatchAsync() { Console.WriteLine($" Match Text: {match.Text}"); Console.WriteLine($" Offset: {match.Offset}"); + Console.WriteLine($" Length: {match.Length}"); Console.WriteLine($" Confidence score: {match.ConfidenceScore}"); } Console.WriteLine(""); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchConvenience.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchConvenience.cs index ede887ad254a6..04886d5106669 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchConvenience.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchConvenience.cs @@ -73,6 +73,7 @@ public void ExtractEntityLinkingBatchConvenience() { Console.WriteLine($" Match Text: {match.Text}"); Console.WriteLine($" Offset: {match.Offset}"); + Console.WriteLine($" Length: {match.Length}"); Console.WriteLine($" Confidence score: {match.ConfidenceScore}"); } Console.WriteLine(""); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchConvenienceAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchConvenienceAsync.cs index 1a74b5adacded..c4eceaa70a15c 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchConvenienceAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchConvenienceAsync.cs @@ -73,6 +73,7 @@ public async Task ExtractEntityLinkingBatchConvenienceAsync() { Console.WriteLine($" Match Text: {match.Text}"); Console.WriteLine($" Offset: {match.Offset}"); + Console.WriteLine($" Length: {match.Length}"); Console.WriteLine($" Confidence score: {match.ConfidenceScore}"); } Console.WriteLine("");