Skip to content

Commit

Permalink
[TA] Healthcare Analyze feature (#17234)
Browse files Browse the repository at this point in the history
* Added support for Healthcare Analyze and Cancellation endpoints
  • Loading branch information
mssfang authored Nov 6, 2020
1 parent c704f38 commit 5dd341e
Show file tree
Hide file tree
Showing 48 changed files with 3,614 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,9 @@
<suppress checks="[a-zA-Z0-9]*" files="com.azure.data.schemaregistry.implementation.*"/>
<suppress checks="[a-zA-Z0-9]*" files="com.microsoft.opentelemetry.exporter.azuremonitor.implementation.*"/>

<!-- Use the logger in a Utility static method. -->
<suppress checks="com.azure.tools.checkstyle.checks.GoodLoggingCheck" files="com.azure.ai.textanalytics.implementation.Utility.java"/>

<!-- Suppress the check on code-gen classes -->
<suppress checks="LineLength" files="com.azure.ai.formrecognizer.implementation.FormRecognizerClientImplBuilder"/>
<suppress checks="LineLength" files="com.azure.ai.formrecognizer.implementation.FormRecognizerClientImpl"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,13 @@
<Bug pattern="UWF_UNWRITTEN_FIELD" />
</Match>

<!-- TextAnalyticsException fields re serializable -->
<Match>
<Class name="com.azure.ai.textanalytics.models.TextAnalyticsException" />
<Field name="errorInformationList" />
<Bug pattern="SE_BAD_FIELD" />
</Match>

<!-- Exception is required to catch, ref: code comment in the OrderbyRowComparer::compare() method -->
<Match>
<Class name="com.azure.cosmos.implementation.query.orderbyquery.OrderbyRowComparer"/>
Expand Down
3 changes: 2 additions & 1 deletion sdk/textanalytics/azure-ai-textanalytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Release History
## 5.1.0-beta.3 (Unreleased)

**New features**
- Added support for Healthcare analysis, it is a long-running operation, and the cancellation supported.

## 5.1.0-beta.2 (2020-10-06)
### Breaking changes
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
import com.azure.ai.textanalytics.models.DetectLanguageResult;
import com.azure.ai.textanalytics.models.DetectedLanguage;
import com.azure.ai.textanalytics.models.DocumentSentiment;
import com.azure.ai.textanalytics.models.HealthcareTaskResult;
import com.azure.ai.textanalytics.models.KeyPhrasesCollection;
import com.azure.ai.textanalytics.models.LinkedEntityCollection;
import com.azure.ai.textanalytics.models.PiiEntityCollection;
import com.azure.ai.textanalytics.models.RecognizeHealthcareEntityOptions;
import com.azure.ai.textanalytics.models.RecognizePiiEntityOptions;
import com.azure.ai.textanalytics.models.TextAnalyticsError;
import com.azure.ai.textanalytics.models.TextAnalyticsException;
import com.azure.ai.textanalytics.models.TextAnalyticsOperationResult;
import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions;
import com.azure.ai.textanalytics.models.TextDocumentInput;
import com.azure.ai.textanalytics.util.AnalyzeSentimentResultCollection;
Expand All @@ -28,13 +31,17 @@
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.polling.PollerFlux;
import reactor.core.publisher.Mono;

import java.util.Collections;
import java.util.Objects;
import java.util.UUID;

import static com.azure.ai.textanalytics.implementation.Utility.inputDocumentsValidation;
import static com.azure.ai.textanalytics.implementation.Utility.mapByIndex;
Expand Down Expand Up @@ -70,6 +77,7 @@ public final class TextAnalyticsAsyncClient {
final RecognizeEntityAsyncClient recognizeEntityAsyncClient;
final RecognizePiiEntityAsyncClient recognizePiiEntityAsyncClient;
final RecognizeLinkedEntityAsyncClient recognizeLinkedEntityAsyncClient;
final AnalyzeHealthcareAsyncClient analyzeHealthcareAsyncClient;

/**
* Create a {@link TextAnalyticsAsyncClient} that sends requests to the Text Analytics services's endpoint. Each
Expand All @@ -92,6 +100,7 @@ public final class TextAnalyticsAsyncClient {
this.recognizeEntityAsyncClient = new RecognizeEntityAsyncClient(service);
this.recognizePiiEntityAsyncClient = new RecognizePiiEntityAsyncClient(service);
this.recognizeLinkedEntityAsyncClient = new RecognizeLinkedEntityAsyncClient(service);
this.analyzeHealthcareAsyncClient = new AnalyzeHealthcareAsyncClient(service);
}

/**
Expand Down Expand Up @@ -1002,4 +1011,53 @@ public Mono<Response<AnalyzeSentimentResultCollection>> analyzeSentimentBatchWit
Iterable<TextDocumentInput> documents, AnalyzeSentimentOptions options) {
return analyzeSentimentAsyncClient.analyzeSentimentBatch(documents, options);
}

// Health Care
/**
* Analyze healthcare entities, entity linking, and entity relations in a list of
* {@link TextDocumentInput document} with provided request options.
*
* See <a href="https://aka.ms/talangs">this</a> supported languages in Text Analytics API.
*
* <p>Analyze healthcare entities, entity linking, and entity relations in a list of
* {@link TextDocumentInput document} and provided request options to
* show statistics. Subscribes to the call asynchronously and prints out the entity details when a response is
* received.</p>
*
* {@codesnippet com.azure.ai.textanalytics.TextAnalyticsAsyncClient.beginAnalyzeHealthcare#Iterable-RecognizeHealthcareEntityOptions}
*
* @param documents A list of {@link TextDocumentInput documents} to be analyzed.
* @param options The additional configurable {@link AnalyzeSentimentOptions options} that may be passed when
* analyzing sentiments.
*
* @return A {@link PollerFlux} that polls the analyze healthcare operation until it has completed, has failed,
* or has been cancelled. The completed operation returns a {@link PagedFlux} of {@link HealthcareTaskResult}.
*
* @throws TextAnalyticsException If analyze operation fails.
* @throws NullPointerException If {@code jobId} is null.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PollerFlux<TextAnalyticsOperationResult, PagedFlux<HealthcareTaskResult>> beginAnalyzeHealthcare(
Iterable<TextDocumentInput> documents, RecognizeHealthcareEntityOptions options) {
return analyzeHealthcareAsyncClient.beginAnalyzeHealthcare(documents, options, Context.NONE);
}

/**
* Cancel a long-running operation healthcare task by given job ID.
*
* <p><strong>Code Sample</strong></p>
* {@codesnippet com.azure.ai.textanalytics.TextAnalyticsAsyncClient.beginCancelAnalyzeHealthcare#UUID}
*
* @param jobId A job identification number.
*
* @return A {@link PollerFlux} that polls the analyze healthcare operation until it has completed, has failed,
* or has been cancelled.
*
* @throws TextAnalyticsException If analyze operation fails.
* @throws NullPointerException If {@code jobId} is null.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PollerFlux<TextAnalyticsOperationResult, Void> beginCancelAnalyzeHealthcare(UUID jobId) {
return analyzeHealthcareAsyncClient.beginCancelAnalyzeHealthcare(jobId, Context.NONE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import com.azure.ai.textanalytics.models.DetectLanguageInput;
import com.azure.ai.textanalytics.models.DetectedLanguage;
import com.azure.ai.textanalytics.models.DocumentSentiment;
import com.azure.ai.textanalytics.models.HealthcareTaskResult;
import com.azure.ai.textanalytics.models.KeyPhrasesCollection;
import com.azure.ai.textanalytics.models.LinkedEntity;
import com.azure.ai.textanalytics.models.LinkedEntityCollection;
import com.azure.ai.textanalytics.models.PiiEntityCollection;
import com.azure.ai.textanalytics.models.RecognizeHealthcareEntityOptions;
import com.azure.ai.textanalytics.models.RecognizePiiEntityOptions;
import com.azure.ai.textanalytics.models.TextAnalyticsError;
import com.azure.ai.textanalytics.models.TextAnalyticsException;
import com.azure.ai.textanalytics.models.TextAnalyticsOperationResult;
import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions;
import com.azure.ai.textanalytics.models.TextDocumentInput;
import com.azure.ai.textanalytics.util.AnalyzeSentimentResultCollection;
Expand All @@ -27,10 +30,13 @@
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.core.util.polling.SyncPoller;

import java.util.Objects;
import java.util.UUID;

import static com.azure.ai.textanalytics.implementation.Utility.inputDocumentsValidation;

Expand Down Expand Up @@ -866,4 +872,57 @@ public Response<AnalyzeSentimentResultCollection> analyzeSentimentBatchWithRespo
Iterable<TextDocumentInput> documents, AnalyzeSentimentOptions options, Context context) {
return client.analyzeSentimentAsyncClient.analyzeSentimentBatchWithContext(documents, options, context).block();
}

// Health Care

/**
* Analyze healthcare entities, entity linking, and entity relations in a list of
* {@link TextDocumentInput document} with provided request options.
*
* See <a href="https://aka.ms/talangs">this</a> supported languages in Text Analytics API.
*
* <p><strong>Code Sample</strong></p>
* <p>Analyze healthcare entities, entity linking, and entity relations in a list of
* {@link TextDocumentInput document} and provided request options to
* show statistics.</p>
*
* {@codesnippet com.azure.ai.textanalytics.TextAnalyticsClient.beginAnalyzeHealthcare#Iterable-RecognizeHealthcareEntityOptions-Context}
*
* @param documents A list of {@link TextDocumentInput documents} to be analyzed.
* @param options The additional configurable {@link AnalyzeSentimentOptions options} that may be passed when
* analyzing sentiments.
* @param context Additional context that is passed through the Http pipeline during the service call.
*
* @return A {@link SyncPoller} that polls the analyze healthcare operation until it has completed, has failed,
* or has been cancelled. The completed operation returns a {@link PagedIterable} of {@link HealthcareTaskResult}.
*
* @throws TextAnalyticsException If analyze operation fails.
* @throws NullPointerException If {@code jobId} is null.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public SyncPoller<TextAnalyticsOperationResult, PagedIterable<HealthcareTaskResult>> beginAnalyzeHealthcare(
Iterable<TextDocumentInput> documents, RecognizeHealthcareEntityOptions options, Context context) {
return client.analyzeHealthcareAsyncClient.beginAnalyzeHealthcarePagedIterable(documents, options, context)
.getSyncPoller();
}

/**
* Cancel a long-running operation healthcare task by given job ID.
*
* <p><strong>Code Sample</strong></p>
* {@codesnippet com.azure.ai.textanalytics.TextAnalyticsClient.beginCancelAnalyzeHealthcare#UUID-Context}
*
* @param jobId A job identification number.
* @param context Additional context that is passed through the Http pipeline during the service call.
*
* @return A {@link SyncPoller} that polls the analyze healthcare operation until it has completed, has failed,
* or has been cancelled.
*
* @throws TextAnalyticsException If analyze operation fails.
* @throws NullPointerException If {@code jobId} is null.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public SyncPoller<TextAnalyticsOperationResult, Void> beginCancelAnalyzeHealthcare(UUID jobId, Context context) {
return client.analyzeHealthcareAsyncClient.beginCancelAnalyzeHealthcare(jobId, context).getSyncPoller();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public enum TextAnalyticsServiceVersion implements ServiceVersion {
V3_0("v3.0"),
V3_1_PREVIEW_2("v3.1-preview.2");
V3_1_PREVIEW_3("v3.1-preview.3");

private final String version;

Expand All @@ -32,7 +32,7 @@ public String getVersion() {
* @return the latest {@link TextAnalyticsServiceVersion}
*/
public static TextAnalyticsServiceVersion getLatest() {
return V3_1_PREVIEW_2;
return V3_1_PREVIEW_3;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.ai.textanalytics.implementation;

import com.azure.ai.textanalytics.models.HealthcareEntityCollection;
import com.azure.ai.textanalytics.models.HealthcareEntityRelation;
import com.azure.ai.textanalytics.models.TextAnalyticsWarning;
import com.azure.core.util.IterableStream;

/**
* The helper class to set the non-public properties of an {@link HealthcareEntityCollection} instance.
*/
public final class HealthcareEntityCollectionPropertiesHelper {
private static HealthcareEntityCollectionAccessor accessor;

private HealthcareEntityCollectionPropertiesHelper() { }

/**
* Type defining the methods to set the non-public properties of an {@link HealthcareEntityCollection} instance.
*/
public interface HealthcareEntityCollectionAccessor {
void setWarnings(HealthcareEntityCollection healthcareEntityCollection,
IterableStream<TextAnalyticsWarning> warnings);
void setEntityRelations(HealthcareEntityCollection healthcareEntityCollection,
IterableStream<HealthcareEntityRelation> entityRelations);
}

/**
* The method called from {@link HealthcareEntityCollection} to set it's accessor.
*
* @param healthcareEntityCollectionAccessor The accessor.
*/
public static void setAccessor(final HealthcareEntityCollectionAccessor healthcareEntityCollectionAccessor) {
accessor = healthcareEntityCollectionAccessor;
}

public static void setWarnings(HealthcareEntityCollection healthcareEntityCollection,
IterableStream<TextAnalyticsWarning> warnings) {
accessor.setWarnings(healthcareEntityCollection, warnings);
}

public static void setEntityRelations(HealthcareEntityCollection healthcareEntityCollection,
IterableStream<HealthcareEntityRelation> entityRelations) {
accessor.setEntityRelations(healthcareEntityCollection, entityRelations);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.ai.textanalytics.implementation;

import com.azure.ai.textanalytics.models.HealthcareEntityLink;

/**
* The helper class to set the non-public properties of an {@link HealthcareEntityLink} instance.
*/
public final class HealthcareEntityLinkPropertiesHelper {
private static HealthcareEntityLinkAccessor accessor;

private HealthcareEntityLinkPropertiesHelper() { }

/**
* Type defining the methods to set the non-public properties of an {@link HealthcareEntityLink} instance.
*/
public interface HealthcareEntityLinkAccessor {
void setDataSource(HealthcareEntityLink healthcareEntityLink, String dataSource);
void setDataSourceId(HealthcareEntityLink healthcareEntityLink, String dataSourceId);
}

/**
* The method called from {@link HealthcareEntityLink} to set it's accessor.
*
* @param healthcareEntityLinkAccessor The accessor.
*/
public static void setAccessor(final HealthcareEntityLinkAccessor healthcareEntityLinkAccessor) {
accessor = healthcareEntityLinkAccessor;
}

public static void setDataSource(HealthcareEntityLink healthcareEntityLink, String dataSource) {
accessor.setDataSource(healthcareEntityLink, dataSource);
}

public static void setDataSourceId(HealthcareEntityLink healthcareEntityLink, String dataSourceId) {
accessor.setDataSourceId(healthcareEntityLink, dataSourceId);
}
}
Loading

0 comments on commit 5dd341e

Please sign in to comment.