Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TA] Expose Length property again as now we have StringIndexType #18505

Merged
merged 1 commit into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing from PR #17968


### Breaking changes
- Renamed `RecognizeHealthcareEntitiesResultCollection` to `AnalyzeHealthcareEntitiesResultCollection`.
Expand Down
3 changes: 3 additions & 0 deletions sdk/textanalytics/Azure.AI.TextAnalytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down Expand Up @@ -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("");
Expand Down Expand Up @@ -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}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; } }
Expand All @@ -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; } }
Expand Down Expand Up @@ -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; } }
}
Expand All @@ -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; } }
Expand All @@ -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; } }
Expand Down Expand Up @@ -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<Azure.AI.TextAnalytics.MinedOpinion> MinedOpinions { get { throw null; } }
public int Offset { get { throw null; } }
public Azure.AI.TextAnalytics.TextSentiment Sentiment { get { throw null; } }
Expand Down Expand Up @@ -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<Azure.AI.TextAnalytics.AnalyzeSentimentResult> 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; }
Expand All @@ -627,9 +633,9 @@ public static partial class TextAnalyticsModelFactory
public static Azure.AI.TextAnalytics.LinkedEntityCollection LinkedEntityCollection(System.Collections.Generic.IList<Azure.AI.TextAnalytics.LinkedEntity> entities, System.Collections.Generic.IList<Azure.AI.TextAnalytics.TextAnalyticsWarning> 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<Azure.AI.TextAnalytics.OpinionSentiment> 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<Azure.AI.TextAnalytics.PiiEntity> entities, string redactedText, System.Collections.Generic.IList<Azure.AI.TextAnalytics.TextAnalyticsWarning> warnings = null) { throw null; }
public static Azure.AI.TextAnalytics.RecognizeEntitiesResult RecognizeEntitiesResult(string id, Azure.AI.TextAnalytics.TextAnalyticsError error) { throw null; }
Expand All @@ -643,7 +649,7 @@ public static partial class TextAnalyticsModelFactory
public static Azure.AI.TextAnalytics.RecognizePiiEntitiesResultCollection RecognizePiiEntitiesResultCollection(System.Collections.Generic.IEnumerable<Azure.AI.TextAnalytics.RecognizePiiEntitiesResult> 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<Azure.AI.TextAnalytics.MinedOpinion> 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<Azure.AI.TextAnalytics.MinedOpinion> 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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down Expand Up @@ -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}");
Expand Down Expand Up @@ -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}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand Down Expand Up @@ -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("");
Expand Down Expand Up @@ -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("");
Expand Down
11 changes: 9 additions & 2 deletions sdk/textanalytics/Azure.AI.TextAnalytics/src/AspectSentiment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}

/// <summary>
Expand All @@ -57,8 +59,13 @@ internal AspectSentiment(SentenceAspect sentenceAspect)
public SentimentConfidenceScores ConfidenceScores { get; }

/// <summary>
/// Gets the starting position (in UTF-16 code units) for the aspect text.
/// Gets the starting position for the aspect text.
/// </summary>
public int Offset { get; }

/// <summary>
/// Gets the length of the aspect text.
/// </summary>
public int Length { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal CategorizedEntity(Entity entity)
SubCategory = entity.Subcategory;
ConfidenceScore = entity.ConfidenceScore;
Offset = entity.Offset;
Length = entity.Length;
}

/// <summary>
Expand Down Expand Up @@ -53,8 +54,13 @@ internal CategorizedEntity(Entity entity)
public double ConfidenceScore { get; }

/// <summary>
/// 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.
/// </summary>
public int Offset { get; }

/// <summary>
/// Gets the length of the matching text in the input document.
/// </summary>
public int Length { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal HealthcareEntity(HealthcareEntityInternal entity)
public double ConfidenceScore { get; }

/// <summary>
/// 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.
/// </summary>
public int Offset { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
Expand All @@ -39,13 +35,13 @@ internal LinkedEntityMatch(double confidenceScore, string text, int offset)
public double ConfidenceScore { get; }

/// <summary>
/// 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.
/// </summary>
public int Offset { get; }

/// <summary>
/// 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.
/// </summary>
private int Length { get; }
public int Length { get; }
}
}
11 changes: 9 additions & 2 deletions sdk/textanalytics/Azure.AI.TextAnalytics/src/OpinionSentiment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}

/// <summary>
Expand Down Expand Up @@ -63,8 +65,13 @@ internal OpinionSentiment(SentenceOpinion opinion)
public bool IsNegated { get; }

/// <summary>
/// Gets the starting position (in UTF-16 code units) for the opinion text.
/// Gets the starting position for the opinion text.
/// </summary>
public int Offset { get; }

/// <summary>
/// Gets the length of the opinion text.
/// </summary>
public int Length { get; }
}
}
8 changes: 7 additions & 1 deletion sdk/textanalytics/Azure.AI.TextAnalytics/src/PiiEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal PiiEntity(Entity entity)
SubCategory = entity.Subcategory;
ConfidenceScore = entity.ConfidenceScore;
Offset = entity.Offset;
Length = entity.Length;
}

/// <summary>
Expand Down Expand Up @@ -51,8 +52,13 @@ internal PiiEntity(Entity entity)
public double ConfidenceScore { get; }

/// <summary>
/// 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.
/// </summary>
public int Offset { get; }

/// <summary>
/// Gets the length of the matching text in the input document.
/// </summary>
public int Length { get; }
}
}
Loading