Skip to content

Commit b8cb9a4

Browse files
authored
[Text Analytics] Added entity linking tasks to analyze operation (Azure#19168)
# All SDK Contribution checklist: This checklist is used to make sure that common guidelines for a pull request are followed. - [ ] **Please open PR in `Draft` mode if it is:** - Work in progress or not intended to be merged. - Encountering multiple pipeline failures and working on fixes. - [ ] If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above. - [ ] **I have read the [contribution guidelines](https://github.com/Azure/azure-sdk-for-net/blob/master/CONTRIBUTING.md).** - [ ] **The pull request does not introduce [breaking changes](https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/breaking-change-rules.md).** ### [General Guidelines and Best Practices](https://github.com/Azure/azure-sdk-for-net/blob/master/CONTRIBUTING.md#general-guidelines) - [ ] Title of the pull request is clear and informative. - [ ] There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, [see this page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md). ### [Testing Guidelines](https://github.com/Azure/azure-sdk-for-net/blob/master/CONTRIBUTING.md#testing-guidelines) - [ ] Pull request includes test coverage for the included changes. ### [SDK Generation Guidelines](https://github.com/Azure/azure-sdk-for-net/blob/master/CONTRIBUTING.md#sdk-generation-guidelines) - [ ] The generate.cmd file for the SDK has been updated with the version of AutoRest, as well as the commitid of your swagger spec or link to the swagger spec, used to generate the code. (Track 2 only) - [ ] The `*.csproj` and `AssemblyInfo.cs` files have been updated with the new version of the SDK. Please double check nuget.org current release version. ## Additional management plane SDK specific contribution checklist: Note: Only applies to `Microsoft.Azure.Management.[RP]` or `Azure.ResourceManager.[RP]` - [ ] Include updated [management metadata](https://github.com/Azure/azure-sdk-for-net/tree/master/eng/mgmt/mgmtmetadata). - [ ] Update AzureRP.props to add/remove version info to maintain up to date API versions. ### Management plane SDK Troubleshooting - If this is very first SDK for a services and you are adding new service folders directly under /SDK, please add `new service` label and/or contact assigned reviewer. - If the check fails at the `Verify Code Generation` step, please ensure: - Do not modify any code in generated folders. - Do not selectively include/remove generated files in the PR. - Do use `generate.ps1/cmd` to generate this PR instead of calling `autorest` directly. Please pay attention to the @microsoft.csharp version output after running generate.ps1. If it is lower than current released version (2.3.82), please run it again as it should pull down the latest version, ### Old outstanding PR cleanup Please note: If PRs (including draft) has been out for more than 60 days and there are no responses from our query or followups, they will be closed to maintain a concise list for our reviewers.
1 parent 7dadde7 commit b8cb9a4

26 files changed

+29587
-11370
lines changed

sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
## 5.1.0-beta.5 (Unreleased)
44
### New features
55
- Added ability to filter the categories returned in a Personally Identifiable Information recognition with the optional parameter `CategoriesFilter` in `RecognizePiiEntitiesOptions`.
6+
- Added the ability to recognize linked entities under `StartAnalyzeBatchActions`.
7+
- Added `RecognizeLinkedEntitiesOptions` to `TextAnalyticsActions`.
8+
- Added `RecognizeLinkedEntitiesActionsResults` to `AnalyzeBatchActionsResult`.
69
- `AnalyzeHealthcareEntitiesResult`, now exposes the property `EntityRelations`of type `HealthcareEntityRelation`.
710
- Introduced `HealthcareEntityRelation` class which will determine all the different relations between the entities as `Roles`.
811
- Added `HealthcareEntityRelationRole`, which exposes `Name` and `Entity` of type `string` and `HealthcareEntity` respectively.

sdk/textanalytics/Azure.AI.TextAnalytics/README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ Text Analytics for health is a containerized service that extracts and labels re
494494
```
495495

496496
### Run Analyze Operation Asynchronously
497-
The Analyze functionality allows to choose which of the supported Text Analytics features to execute in the same set of documents. Currently the supported features are: entity recognition, key phrase extraction, and Personally Identifiable Information (PII) Recognition. For more information see [How to: Use Text Analytics for analyze operation][analyze_operation_howto].
497+
The Analyze functionality allows to choose which of the supported Text Analytics features to execute in the same set of documents. Currently the supported features are: entity recognition, linked entity recognition, key phrase extraction, and Personally Identifiable Information (PII) Recognition. For more information see [How to: Use Text Analytics for analyze operation][analyze_operation_howto].
498498

499499
```C# Snippet:AnalyzeOperationBatchConvenienceAsync
500500
string documentA = @"We love this trail and make the trip every year. The views are breathtaking and well
@@ -526,6 +526,7 @@ The Analyze functionality allows to choose which of the supported Text Analytics
526526
ExtractKeyPhrasesOptions = new List<ExtractKeyPhrasesOptions>() { new ExtractKeyPhrasesOptions() },
527527
RecognizeEntitiesOptions = new List<RecognizeEntitiesOptions>() { new RecognizeEntitiesOptions() },
528528
RecognizePiiEntitiesOptions = new List<RecognizePiiEntitiesOptions>() { new RecognizePiiEntitiesOptions() },
529+
RecognizeLinkedEntitiesOptions = new List<RecognizeLinkedEntitiesOptions>() { new RecognizeLinkedEntitiesOptions() },
529530
DisplayName = "AnalyzeOperationSample"
530531
};
531532

@@ -541,6 +542,8 @@ The Analyze functionality allows to choose which of the supported Text Analytics
541542

542543
RecognizePiiEntitiesResultCollection piiResult = documentsInPage.RecognizePiiEntitiesActionsResults.FirstOrDefault().Result;
543544

545+
RecognizeLinkedEntitiesResultCollection elResult = documentsInPage.RecognizeLinkedEntitiesActionsResults.FirstOrDefault().Result;
546+
544547
Console.WriteLine("Recognized Entities");
545548

546549
foreach (RecognizeEntitiesResult result in entitiesResult)
@@ -587,6 +590,33 @@ The Analyze functionality allows to choose which of the supported Text Analytics
587590
}
588591
Console.WriteLine("");
589592
}
593+
594+
Console.WriteLine("Recognized Linked Entities");
595+
596+
foreach (RecognizeLinkedEntitiesResult result in elResult)
597+
{
598+
Console.WriteLine($" Recognized the following {result.Entities.Count} linked entities:");
599+
600+
foreach (LinkedEntity entity in result.Entities)
601+
{
602+
Console.WriteLine($" Entity: {entity.Name}");
603+
Console.WriteLine($" DataSource: {entity.DataSource}");
604+
Console.WriteLine($" DataSource EntityId: {entity.DataSourceEntityId}");
605+
Console.WriteLine($" Language: {entity.Language}");
606+
Console.WriteLine($" DataSource Url: {entity.Url}");
607+
608+
Console.WriteLine($" Total Matches: {entity.Matches.Count()}");
609+
foreach (LinkedEntityMatch match in entity.Matches)
610+
{
611+
Console.WriteLine($" Match Text: {match.Text}");
612+
Console.WriteLine($" ConfidenceScore: {match.ConfidenceScore}");
613+
Console.WriteLine($" Offset: {match.Offset}");
614+
Console.WriteLine($" Length: {match.Length}");
615+
}
616+
Console.WriteLine("");
617+
}
618+
Console.WriteLine("");
619+
}
590620
}
591621
}
592622
```

sdk/textanalytics/Azure.AI.TextAnalytics/api/Azure.AI.TextAnalytics.netstandard2.0.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public partial class AnalyzeBatchActionsResult
3434
internal AnalyzeBatchActionsResult() { }
3535
public System.Collections.Generic.IReadOnlyCollection<Azure.AI.TextAnalytics.ExtractKeyPhrasesActionResult> ExtractKeyPhrasesActionsResults { get { throw null; } }
3636
public System.Collections.Generic.IReadOnlyCollection<Azure.AI.TextAnalytics.RecognizeEntitiesActionResult> RecognizeEntitiesActionsResults { get { throw null; } }
37+
public System.Collections.Generic.IReadOnlyCollection<Azure.AI.TextAnalytics.RecognizeLinkedEntitiesActionResult> RecognizeLinkedEntitiesActionsResults { get { throw null; } }
3738
public System.Collections.Generic.IReadOnlyCollection<Azure.AI.TextAnalytics.RecognizePiiEntitiesActionResult> RecognizePiiEntitiesActionsResults { get { throw null; } }
3839
public Azure.AI.TextAnalytics.TextDocumentBatchStatistics Statistics { get { throw null; } }
3940
}
@@ -569,6 +570,15 @@ internal RecognizeEntitiesResultCollection() : base (default(System.Collections.
569570
public string ModelVersion { get { throw null; } }
570571
public Azure.AI.TextAnalytics.TextDocumentBatchStatistics Statistics { get { throw null; } }
571572
}
573+
public partial class RecognizeLinkedEntitiesActionResult : Azure.AI.TextAnalytics.TextAnalyticsActionDetails
574+
{
575+
internal RecognizeLinkedEntitiesActionResult() { }
576+
public Azure.AI.TextAnalytics.RecognizeLinkedEntitiesResultCollection Result { get { throw null; } }
577+
}
578+
public partial class RecognizeLinkedEntitiesOptions : Azure.AI.TextAnalytics.TextAnalyticsRequestOptions
579+
{
580+
public RecognizeLinkedEntitiesOptions() { }
581+
}
572582
public partial class RecognizeLinkedEntitiesResult : Azure.AI.TextAnalytics.TextAnalyticsResult
573583
{
574584
internal RecognizeLinkedEntitiesResult() { }
@@ -672,6 +682,7 @@ public TextAnalyticsActions() { }
672682
public string DisplayName { get { throw null; } set { } }
673683
public System.Collections.Generic.IReadOnlyCollection<Azure.AI.TextAnalytics.ExtractKeyPhrasesOptions> ExtractKeyPhrasesOptions { get { throw null; } set { } }
674684
public System.Collections.Generic.IReadOnlyCollection<Azure.AI.TextAnalytics.RecognizeEntitiesOptions> RecognizeEntitiesOptions { get { throw null; } set { } }
685+
public System.Collections.Generic.IReadOnlyCollection<Azure.AI.TextAnalytics.RecognizeLinkedEntitiesOptions> RecognizeLinkedEntitiesOptions { get { throw null; } set { } }
675686
public System.Collections.Generic.IReadOnlyCollection<Azure.AI.TextAnalytics.RecognizePiiEntitiesOptions> RecognizePiiEntitiesOptions { get { throw null; } set { } }
676687
}
677688
public partial class TextAnalyticsClient

sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_AnalyzeBatchActions.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ To run analyze operation in multiple documents, call `StartAnalyzeOperationBatch
4747
ExtractKeyPhrasesOptions = new List<ExtractKeyPhrasesOptions>() { new ExtractKeyPhrasesOptions() },
4848
RecognizeEntitiesOptions = new List<RecognizeEntitiesOptions>() { new RecognizeEntitiesOptions() },
4949
RecognizePiiEntitiesOptions = new List<RecognizePiiEntitiesOptions>() { new RecognizePiiEntitiesOptions() },
50+
RecognizeLinkedEntitiesOptions = new List<RecognizeLinkedEntitiesOptions>() { new RecognizeLinkedEntitiesOptions() },
5051
DisplayName = "AnalyzeOperationSample"
5152
};
5253

@@ -62,6 +63,8 @@ To run analyze operation in multiple documents, call `StartAnalyzeOperationBatch
6263

6364
RecognizePiiEntitiesResultCollection piiResult = documentsInPage.RecognizePiiEntitiesActionsResults.FirstOrDefault().Result;
6465

66+
RecognizeLinkedEntitiesResultCollection elResult = documentsInPage.RecognizeLinkedEntitiesActionsResults.FirstOrDefault().Result;
67+
6568
Console.WriteLine("Recognized Entities");
6669

6770
foreach (RecognizeEntitiesResult result in entitiesResult)
@@ -108,6 +111,33 @@ To run analyze operation in multiple documents, call `StartAnalyzeOperationBatch
108111
}
109112
Console.WriteLine("");
110113
}
114+
115+
Console.WriteLine("Recognized Linked Entities");
116+
117+
foreach (RecognizeLinkedEntitiesResult result in elResult)
118+
{
119+
Console.WriteLine($" Recognized the following {result.Entities.Count} linked entities:");
120+
121+
foreach (LinkedEntity entity in result.Entities)
122+
{
123+
Console.WriteLine($" Entity: {entity.Name}");
124+
Console.WriteLine($" DataSource: {entity.DataSource}");
125+
Console.WriteLine($" DataSource EntityId: {entity.DataSourceEntityId}");
126+
Console.WriteLine($" Language: {entity.Language}");
127+
Console.WriteLine($" DataSource Url: {entity.Url}");
128+
129+
Console.WriteLine($" Total Matches: {entity.Matches.Count()}");
130+
foreach (LinkedEntityMatch match in entity.Matches)
131+
{
132+
Console.WriteLine($" Match Text: {match.Text}");
133+
Console.WriteLine($" ConfidenceScore: {match.ConfidenceScore}");
134+
Console.WriteLine($" Offset: {match.Offset}");
135+
Console.WriteLine($" Length: {match.Length}");
136+
}
137+
Console.WriteLine("");
138+
}
139+
Console.WriteLine("");
140+
}
111141
}
112142
}
113143
```

sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeBatchActionsOperation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ private async ValueTask<Response> UpdateStatusAsync(bool async, CancellationToke
262262
_actionSucceeded = update.Value.Tasks.Completed;
263263
_totalActions = update.Value.Tasks.Total;
264264

265-
if (update.Value.Status == TextAnalyticsOperationStatus.Succeeded || update.Value.Status == TextAnalyticsOperationStatus.PartiallySucceeded)
265+
// TODO - Remove PartiallySucceeded once service deploys this to WestUS2
266+
if (update.Value.Status == TextAnalyticsOperationStatus.Succeeded || update.Value.Status == TextAnalyticsOperationStatus.PartiallySucceeded || update.Value.Status == TextAnalyticsOperationStatus.PartiallyCompleted)
266267
{
267268
// we need to first assign a value and then mark the operation as completed to avoid race conditions
268269
var nextLink = update.Value.NextLink;

sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeBatchActionsResult.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ namespace Azure.AI.TextAnalytics
1111
/// </summary>
1212
public class AnalyzeBatchActionsResult
1313
{
14-
internal AnalyzeBatchActionsResult(IReadOnlyCollection<ExtractKeyPhrasesActionResult> extractKeyPhrasesActionResult, IReadOnlyCollection<RecognizeEntitiesActionResult> recognizeEntitiesActionResults, IReadOnlyCollection<RecognizePiiEntitiesActionResult> recognizePiiEntitiesActionResults, TextDocumentBatchStatistics statistics)
14+
internal AnalyzeBatchActionsResult(
15+
IReadOnlyCollection<ExtractKeyPhrasesActionResult> extractKeyPhrasesActionResult,
16+
IReadOnlyCollection<RecognizeEntitiesActionResult> recognizeEntitiesActionResults,
17+
IReadOnlyCollection<RecognizePiiEntitiesActionResult> recognizePiiEntitiesActionResults,
18+
IReadOnlyCollection<RecognizeLinkedEntitiesActionResult> recognizeLinkedEntitiesActionsResults,
19+
TextDocumentBatchStatistics statistics)
1520
{
1621
ExtractKeyPhrasesActionsResults = extractKeyPhrasesActionResult;
1722
RecognizeEntitiesActionsResults = recognizeEntitiesActionResults;
1823
RecognizePiiEntitiesActionsResults = recognizePiiEntitiesActionResults;
24+
RecognizeLinkedEntitiesActionsResults = recognizeLinkedEntitiesActionsResults;
1925
Statistics = statistics;
2026
}
2127

@@ -25,6 +31,7 @@ internal AnalyzeBatchActionsResult(AnalyzeJobState jobState, IDictionary<string,
2531
ExtractKeyPhrasesActionsResults = actionResults.ExtractKeyPhrasesActionsResults;
2632
RecognizeEntitiesActionsResults = actionResults.RecognizeEntitiesActionsResults;
2733
RecognizePiiEntitiesActionsResults = actionResults.RecognizePiiEntitiesActionsResults;
34+
RecognizeLinkedEntitiesActionsResults = actionResults.RecognizeLinkedEntitiesActionsResults;
2835
Statistics = actionResults.Statistics;
2936
}
3037

@@ -43,6 +50,11 @@ internal AnalyzeBatchActionsResult(AnalyzeJobState jobState, IDictionary<string,
4350
/// </summary>
4451
public IReadOnlyCollection<RecognizePiiEntitiesActionResult> RecognizePiiEntitiesActionsResults { get; }
4552

53+
/// <summary>
54+
/// Determines the collection of RecognizeLinkedEntitiesActionsResult.
55+
/// </summary>
56+
public IReadOnlyCollection<RecognizeLinkedEntitiesActionResult> RecognizeLinkedEntitiesActionsResults { get; }
57+
4658
/// <summary>
4759
/// <summary> if showStats=true was specified in the request this field will contain information about the document payload. </summary>
4860
/// </summary>
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using Azure.AI.TextAnalytics.Models;
54
using Azure.Core;
65

7-
namespace Azure.AI.TextAnalytics
6+
namespace Azure.AI.TextAnalytics.Models
87
{
98
/// <summary>
109
/// EntityLinkingTaskParameters class.
1110
/// </summary>
1211
[CodeGenModel("EntityLinkingTaskParameters")]
1312
internal partial class EntityLinkingTaskParameters
14-
{
15-
/// <summary>
16-
/// ModelVersion
17-
/// </summary>
18-
public string ModelVersion { get; set; } = "latest";
19-
20-
/// <summary>
21-
/// StringIndexType
22-
/// </summary>
23-
public StringIndexType StringIndexType { get; set; } = StringIndexType.Utf16CodeUnit;
24-
}
13+
{ }
2514
}

sdk/textanalytics/Azure.AI.TextAnalytics/src/Generated/Models/EntityLinkingTask.cs

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/textanalytics/Azure.AI.TextAnalytics/src/Generated/Models/EntityLinkingTaskParameters.Serialization.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/textanalytics/Azure.AI.TextAnalytics/src/Generated/Models/EntityLinkingTaskParameters.cs

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)