Skip to content

Commit

Permalink
renames, modify types, test cleanup (Azure#18421)
Browse files Browse the repository at this point in the history
  • Loading branch information
maririos authored and jongio committed Feb 9, 2021
1 parent 0eb2ebd commit 670114e
Show file tree
Hide file tree
Showing 28 changed files with 79 additions and 1,679 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public partial class AnalyzeHealthcareEntitiesOperation : Azure.AI.TextAnalytics
{
public AnalyzeHealthcareEntitiesOperation(string operationId, Azure.AI.TextAnalytics.TextAnalyticsClient client) { }
public System.DateTimeOffset CreatedOn { get { throw null; } }
public System.DateTimeOffset ExpiresOn { get { throw null; } }
public System.DateTimeOffset? ExpiresOn { get { throw null; } }
public override bool HasCompleted { get { throw null; } }
public override bool HasValue { get { throw null; } }
public override string Id { get { throw null; } }
Expand Down Expand Up @@ -167,16 +167,6 @@ public EntitiesTaskParameters() { }
public string ModelVersion { get { throw null; } set { } }
public Azure.AI.TextAnalytics.StringIndexType StringIndexType { get { throw null; } set { } }
}
public partial class Entity
{
internal Entity() { }
public string 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; } }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct EntityCategory : System.IEquatable<Azure.AI.TextAnalytics.EntityCategory>
{
Expand Down Expand Up @@ -242,15 +232,18 @@ internal HealthcareEntity() { }
public System.Collections.Generic.IReadOnlyCollection<Azure.AI.TextAnalytics.EntityDataSource> DataSources { get { throw null; } }
public int Length { get { throw null; } }
public int Offset { get { throw null; } }
public System.Collections.Generic.Dictionary<Azure.AI.TextAnalytics.HealthcareEntity, Azure.AI.TextAnalytics.HealthcareEntityRelationType> RelatedEntities { get { throw null; } }
public System.Collections.Generic.IDictionary<Azure.AI.TextAnalytics.HealthcareEntity, Azure.AI.TextAnalytics.HealthcareEntityRelationType> RelatedEntities { get { throw null; } }
public string SubCategory { get { throw null; } }
public string Text { get { throw null; } }
}
public partial class HealthcareEntityRelationType : System.IEquatable<Azure.AI.TextAnalytics.HealthcareEntityRelationType>
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct HealthcareEntityRelationType : System.IEquatable<Azure.AI.TextAnalytics.HealthcareEntityRelationType>
{
internal HealthcareEntityRelationType() { }
private readonly object _dummy;
private readonly int _dummyPrimitive;
public static readonly Azure.AI.TextAnalytics.HealthcareEntityRelationType DirectionOfBodyStructure;
public static readonly Azure.AI.TextAnalytics.HealthcareEntityRelationType DirectionOfExamination;
public static readonly Azure.AI.TextAnalytics.HealthcareEntityRelationType DosageOfMedication;
public static readonly Azure.AI.TextAnalytics.HealthcareEntityRelationType RelationOfExamination;
public static readonly Azure.AI.TextAnalytics.HealthcareEntityRelationType TimeOfExamination;
public bool Equals(Azure.AI.TextAnalytics.HealthcareEntityRelationType other) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ public class AnalyzeHealthcareEntitiesOperation : PageableOperation<AnalyzeHealt
public override string Id { get; }

/// <summary>
/// CreatedOn
/// Time when the operation was created on.
/// </summary>
public DateTimeOffset CreatedOn { get; }
public DateTimeOffset CreatedOn => _createdOn;

/// <summary>
/// ExpiresOn
/// Time when the operation will expire.
/// </summary>
public DateTimeOffset ExpiresOn { get; }
public DateTimeOffset? ExpiresOn => _expiresOn;

/// <summary>
/// LastModified
/// Time when the operation was last modified on
/// </summary>
public DateTimeOffset LastModified { get; }
public DateTimeOffset LastModified => _lastModified;

/// <summary>
/// Gets the status of the operation.
Expand Down Expand Up @@ -80,6 +80,21 @@ public class AnalyzeHealthcareEntitiesOperation : PageableOperation<AnalyzeHealt

private readonly string _apiVersion;

/// <summary>
/// Time when the operation will expire.
/// </summary>
private DateTimeOffset? _expiresOn;

/// <summary>
/// Time when the operation was last modified on.
/// </summary>
private DateTimeOffset _lastModified;

/// <summary>
/// Time when the operation was created on.
/// </summary>
private DateTimeOffset _createdOn;

/// <summary>
/// Provides the input to be part of AnalyzeHealthcareEntitiesOperation class
/// </summary>
Expand Down Expand Up @@ -201,11 +216,14 @@ private async ValueTask<Response> UpdateStatusAsync(bool async, CancellationToke

_response = update.GetRawResponse();
_status = update.Value.Status;
_createdOn = update.Value.CreatedDateTime;
_expiresOn = update.Value.ExpirationDateTime;
_lastModified = update.Value.LastUpdateDateTime;

if (_status == TextAnalyticsOperationStatus.Succeeded)
{
var nextLink = update.Value.NextLink;
var value = Transforms.ConvertToRecognizeHealthcareEntitiesResultCollection(update.Value.Results, _idToIndexMap);
var value = Transforms.ConvertToAnalyzeHealthcareEntitiesResultCollection(update.Value.Results, _idToIndexMap);
_firstPage = Page.FromValues(new List<AnalyzeHealthcareEntitiesResultCollection>() { value }, nextLink, _response);
_hasCompleted = true;
}
Expand Down Expand Up @@ -295,7 +313,7 @@ async Task<Page<AnalyzeHealthcareEntitiesResultCollection>> NextPageFunc(string
{
Response<HealthcareJobState> jobState = await _serviceClient.HealthStatusNextPageAsync(_apiVersion, nextLink, _showStats).ConfigureAwait(false);

AnalyzeHealthcareEntitiesResultCollection result = Transforms.ConvertToRecognizeHealthcareEntitiesResultCollection(jobState.Value.Results, _idToIndexMap);
AnalyzeHealthcareEntitiesResultCollection result = Transforms.ConvertToAnalyzeHealthcareEntitiesResultCollection(jobState.Value.Results, _idToIndexMap);
return Page.FromValues(new List<AnalyzeHealthcareEntitiesResultCollection>() { result }, jobState.Value.NextLink, jobState.GetRawResponse());
}
catch (Exception)
Expand Down Expand Up @@ -327,7 +345,7 @@ Page<AnalyzeHealthcareEntitiesResultCollection> NextPageFunc(string nextLink, in
{
Response<HealthcareJobState> jobState = _serviceClient.HealthStatusNextPage(_apiVersion, nextLink, _showStats);

AnalyzeHealthcareEntitiesResultCollection result = Transforms.ConvertToRecognizeHealthcareEntitiesResultCollection(jobState.Value.Results, _idToIndexMap);
AnalyzeHealthcareEntitiesResultCollection result = Transforms.ConvertToAnalyzeHealthcareEntitiesResultCollection(jobState.Value.Results, _idToIndexMap);
return Page.FromValues(new List<AnalyzeHealthcareEntitiesResultCollection>() { result }, jobState.Value.NextLink, jobState.GetRawResponse());
}
catch (Exception)
Expand Down
16 changes: 0 additions & 16 deletions sdk/textanalytics/Azure.AI.TextAnalytics/src/Entity.cs

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal HealthcareEntity(HealthcareEntityInternal entity)
Offset = entity.Offset;
Length = entity.Length;
DataSources = entity.Links;
RelatedEntities = new Dictionary<HealthcareEntity, HealthcareEntityRelationType>(entity.RelatedEntities);
RelatedEntities = new Dictionary<HealthcareEntity, HealthcareEntityRelationType>();
}
/// <summary>
/// Gets the entity text as it appears in the input document.
Expand Down Expand Up @@ -67,6 +67,6 @@ internal HealthcareEntity(HealthcareEntityInternal entity)
/// <summary>
/// Gets the entities and the relationship between the entities.
/// </summary>
public Dictionary<HealthcareEntity, HealthcareEntityRelationType> RelatedEntities { get; }
public IDictionary<HealthcareEntity, HealthcareEntityRelationType> RelatedEntities { get; internal set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,5 @@ namespace Azure.AI.TextAnalytics
/// HealthcareEntity.
/// </summary>
[CodeGenModel("HealthcareEntity")]
internal partial class HealthcareEntityInternal
{
/// <summary>
/// Gets the dictionary for related entity with mapped relation type for each.
/// </summary>
internal Dictionary<HealthcareEntity, HealthcareEntityRelationType> RelatedEntities { get; } = new Dictionary<HealthcareEntity, HealthcareEntityRelationType>();
}
internal partial class HealthcareEntityInternal { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Azure.AI.TextAnalytics
/// <summary>
/// HealthcareEntityRelationType
/// </summary>
public class HealthcareEntityRelationType : IEquatable<HealthcareEntityRelationType>
public readonly struct HealthcareEntityRelationType : IEquatable<HealthcareEntityRelationType>
{
/// <summary>
/// Specifies the relation type DirectionOfBodyStructure.
Expand All @@ -32,6 +32,11 @@ public class HealthcareEntityRelationType : IEquatable<HealthcareEntityRelationT
/// </summary>
public static readonly HealthcareEntityRelationType TimeOfExamination = new HealthcareEntityRelationType("TimeOfExamination");

/// <summary>
/// Specifies the relation type DosageOfMedication.
/// </summary>
public static readonly HealthcareEntityRelationType DosageOfMedication = new HealthcareEntityRelationType("DosageOfMedication");

private readonly string _value;

private HealthcareEntityRelationType(string relationtype)
Expand Down
2 changes: 2 additions & 0 deletions sdk/textanalytics/Azure.AI.TextAnalytics/src/PiiEntity.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.AI.TextAnalytics.Models;

namespace Azure.AI.TextAnalytics
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion sdk/textanalytics/Azure.AI.TextAnalytics/src/Transforms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ internal static List<HealthcareEntity> ConvertToHealthcareEntityCollection(IEnum
return entities;
}

internal static AnalyzeHealthcareEntitiesResultCollection ConvertToRecognizeHealthcareEntitiesResultCollection(HealthcareResult results, IDictionary<string, int> idToIndexMap)
internal static AnalyzeHealthcareEntitiesResultCollection ConvertToAnalyzeHealthcareEntitiesResultCollection(HealthcareResult results, IDictionary<string, int> idToIndexMap)
{
var healthcareEntititesResults = new List<AnalyzeHealthcareEntitiesResult>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public async Task RecognizeHealthcareEntitiesTest()

await operation.WaitForCompletionAsync(PollingInterval);

ValidateOperationProperties(operation);

List<AnalyzeHealthcareEntitiesResultCollection> resultInPages = operation.Value.ToEnumerableAsync().Result;
Assert.AreEqual(1, resultInPages.Count);

Expand Down Expand Up @@ -94,9 +96,7 @@ public async Task RecognizeHealthcareEntitiesTest()
Assert.AreEqual(9, relatedEntity.Length);
Assert.AreEqual(27, relatedEntity.Offset);
Assert.AreEqual(1.0, relatedEntity.ConfidenceScore);

// TODO - DosageOfMedication is not in relation types and is returned from the service. Need to add to swagger.
//Assert.AreEqual(HealthcareEntityRelationType.DosageOfMedication, entity.RelatedEntities.ElementAt(0).Value);
Assert.AreEqual(HealthcareEntityRelationType.DosageOfMedication, entity.RelatedEntities.FirstOrDefault().Value);
}
}
}
Expand All @@ -110,6 +110,8 @@ public async Task RecognizeHealthcareEntitiesWithLanguageTest()

await operation.WaitForCompletionAsync(PollingInterval);

ValidateOperationProperties(operation);

//Take the first page
AnalyzeHealthcareEntitiesResultCollection resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

Expand Down Expand Up @@ -137,6 +139,8 @@ public async Task RecognizeHealthcareEntitiesBatchWithErrorTest()

await operation.WaitForCompletionAsync(PollingInterval);

ValidateOperationProperties(operation);

//Take the first page
AnalyzeHealthcareEntitiesResultCollection resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

Expand All @@ -159,6 +163,8 @@ public async Task RecognizeHealthcareEntitiesBatchConvenienceTest()

await operation.WaitForCompletionAsync(PollingInterval);

ValidateOperationProperties(operation);

//Take the first page
AnalyzeHealthcareEntitiesResultCollection resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

Expand All @@ -185,6 +191,8 @@ public async Task RecognizeHealthcareEntitiesBatchConvenienceWithStatisticsTest(

await operation.WaitForCompletionAsync(PollingInterval);

ValidateOperationProperties(operation);

//Take the first page
AnalyzeHealthcareEntitiesResultCollection resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

Expand All @@ -206,6 +214,8 @@ public async Task RecognizeHealthcareEntitiesBatchTest()

await operation.WaitForCompletionAsync(PollingInterval);

ValidateOperationProperties(operation);

//Take the first page
AnalyzeHealthcareEntitiesResultCollection resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

Expand All @@ -232,6 +242,8 @@ public async Task RecognizeHealthcareEntitiesBatchWithStatisticsTest()

await operation.WaitForCompletionAsync(PollingInterval);

ValidateOperationProperties(operation);

//Take the first page
AnalyzeHealthcareEntitiesResultCollection resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

Expand Down Expand Up @@ -297,6 +309,8 @@ public async Task AnalyzeHealthcareEntitiesPagination()
Assert.IsTrue(operation.HasCompleted);
Assert.IsTrue(operation.HasValue);

ValidateOperationProperties(operation);

// try async
//There most be 1 page
List<AnalyzeHealthcareEntitiesResultCollection> asyncPages = operation.Value.ToEnumerableAsync().Result;
Expand Down Expand Up @@ -372,5 +386,16 @@ private void ValidateBatchDocumentsResult(AnalyzeHealthcareEntitiesResultCollect
ValidateInDocumenResult(entitiesInDocument.Entities, minimumExpectedOutput[entitiesInDocument.Id]);
}
}

private void ValidateOperationProperties(AnalyzeHealthcareEntitiesOperation operation)
{
Assert.AreNotEqual(new DateTimeOffset(), operation.CreatedOn);
Assert.AreNotEqual(new DateTimeOffset(), operation.LastModified);

if (operation.ExpiresOn.HasValue)
{
Assert.AreNotEqual(new DateTimeOffset(), operation.ExpiresOn.Value);
}
}
}
}
Loading

0 comments on commit 670114e

Please sign in to comment.