diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/RecognizePiiEntityAsyncClient.java b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/RecognizePiiEntityAsyncClient.java
index 47df7ab157d55..9c10176e32471 100644
--- a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/RecognizePiiEntityAsyncClient.java
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/RecognizePiiEntityAsyncClient.java
@@ -13,8 +13,9 @@
import com.azure.ai.textanalytics.models.EntityCategory;
import com.azure.ai.textanalytics.models.PiiEntity;
import com.azure.ai.textanalytics.models.PiiEntityCollection;
+import com.azure.ai.textanalytics.models.PiiEntityDomainType;
import com.azure.ai.textanalytics.models.RecognizePiiEntitiesResult;
-import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions;
+import com.azure.ai.textanalytics.models.RecognizePiiEntityOptions;
import com.azure.ai.textanalytics.models.TextAnalyticsWarning;
import com.azure.ai.textanalytics.models.TextDocumentInput;
import com.azure.ai.textanalytics.models.WarningCode;
@@ -67,14 +68,17 @@ class RecognizePiiEntityAsyncClient {
*
* @param document A single document.
* @param language The language code.
+ * @param options The additional configurable {@link RecognizePiiEntityOptions options} that may be passed when
+ * recognizing PII entities.
*
* @return The {@link Mono} of {@link PiiEntityCollection}.
*/
- Mono recognizePiiEntities(String document, String language) {
+ Mono recognizePiiEntities(String document, String language,
+ RecognizePiiEntityOptions options) {
try {
Objects.requireNonNull(document, "'document' cannot be null.");
return recognizePiiEntitiesBatch(
- Collections.singletonList(new TextDocumentInput("0", document).setLanguage(language)), null)
+ Collections.singletonList(new TextDocumentInput("0", document).setLanguage(language)), options)
.map(resultCollectionResponse -> {
PiiEntityCollection entityCollection = null;
// for each loop will have only one entry inside
@@ -97,12 +101,13 @@ Mono recognizePiiEntities(String document, String language)
* Helper function for calling service with max overloaded parameters.
*
* @param documents The list of documents to recognize Personally Identifiable Information entities for.
- * @param options The {@link TextAnalyticsRequestOptions} request options.
+ * @param options The additional configurable {@link RecognizePiiEntityOptions options} that may be passed when
+ * recognizing PII entities.
*
* @return A mono {@link Response} that contains {@link RecognizePiiEntitiesResultCollection}.
*/
Mono> recognizePiiEntitiesBatch(
- Iterable documents, TextAnalyticsRequestOptions options) {
+ Iterable documents, RecognizePiiEntityOptions options) {
try {
inputDocumentsValidation(documents);
return withContext(context -> getRecognizePiiEntitiesResponse(documents, options, context));
@@ -115,13 +120,14 @@ Mono> recognizePiiEntitiesBatch(
* Helper function for calling service with max overloaded parameters with {@link Context} is given.
*
* @param documents The list of documents to recognize Personally Identifiable Information entities for.
- * @param options The {@link TextAnalyticsRequestOptions} request options.
+ * @param options The additional configurable {@link RecognizePiiEntityOptions options} that may be passed when
+ * recognizing PII entities.
* @param context Additional context that is passed through the Http pipeline during the service call.
*
* @return A mono {@link Response} that contains {@link RecognizePiiEntitiesResultCollection}.
*/
Mono> recognizePiiEntitiesBatchWithContext(
- Iterable documents, TextAnalyticsRequestOptions options, Context context) {
+ Iterable documents, RecognizePiiEntityOptions options, Context context) {
try {
inputDocumentsValidation(documents);
return getRecognizePiiEntitiesResponse(documents, options, context);
@@ -184,19 +190,28 @@ private Response toRecognizePiiEntitiesRes
* {@link RecognizePiiEntitiesResultCollection} from a {@link SimpleResponse} of {@link EntitiesResult}.
*
* @param documents The list of documents to recognize Personally Identifiable Information entities for.
- * @param options The {@link TextAnalyticsRequestOptions} request options.
+ * @param options The additional configurable {@link RecognizePiiEntityOptions options} that may be passed when
+ * recognizing PII entities.
* @param context Additional context that is passed through the Http pipeline during the service call.
*
* @return A mono {@link Response} that contains {@link RecognizePiiEntitiesResultCollection}.
*/
private Mono> getRecognizePiiEntitiesResponse(
- Iterable documents, TextAnalyticsRequestOptions options, Context context) {
+ Iterable documents, RecognizePiiEntityOptions options, Context context) {
+ String modelVersion = null;
+ Boolean includeStatistics = null;
+ String domainFilter = null;
+ if (options != null) {
+ modelVersion = options.getModelVersion();
+ includeStatistics = options.isIncludeStatistics();
+ final PiiEntityDomainType domainType = options.getDomainFilter();
+ if (domainType != null) {
+ domainFilter = domainType.toString();
+ }
+ }
return service.entitiesRecognitionPiiWithResponseAsync(
new MultiLanguageBatchInput().setDocuments(toMultiLanguageInput(documents)),
- options == null ? null : options.getModelVersion(),
- options == null ? null : options.isIncludeStatistics(),
- null,
- StringIndexType.UTF16CODE_UNIT,
+ modelVersion, includeStatistics, domainFilter, StringIndexType.UTF16CODE_UNIT,
context.addData(AZ_TRACING_NAMESPACE_KEY, COGNITIVE_TRACING_NAMESPACE_VALUE))
.doOnSubscribe(ignoredValue -> logger.info(
"Start recognizing Personally Identifiable Information entities for a batch of documents."))
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/TextAnalyticsAsyncClient.java b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/TextAnalyticsAsyncClient.java
index a41dc79c274ae..0453a2e026d55 100644
--- a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/TextAnalyticsAsyncClient.java
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/TextAnalyticsAsyncClient.java
@@ -14,6 +14,7 @@
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.RecognizePiiEntityOptions;
import com.azure.ai.textanalytics.models.TextAnalyticsError;
import com.azure.ai.textanalytics.models.TextAnalyticsException;
import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions;
@@ -427,7 +428,38 @@ public Mono recognizePiiEntities(String document) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono recognizePiiEntities(String document, String language) {
- return recognizePiiEntityAsyncClient.recognizePiiEntities(document, language);
+ return recognizePiiEntityAsyncClient.recognizePiiEntities(document, language, null);
+ }
+
+ /**
+ * Returns a list of Personally Identifiable Information(PII) entities in the provided document
+ * with provided language code.
+ *
+ * For a list of supported entity types, check: this.
+ * For a list of enabled languages, check: this.
+ *
+ * Code sample
+ * Recognize the PII entities details in a document with provided language code and RecognizePiiEntityOptions.
+ * Subscribes to the call asynchronously and prints out the entity details when a response is received.
+ *
+ * {@codesnippet com.azure.ai.textanalytics.TextAnalyticsAsyncClient.recognizePiiEntities#string-string-RecognizePiiEntityOptions}
+ *
+ * @param document the text to recognize PII entities details for.
+ * For text length limits, maximum batch size, and supported text encoding, see
+ * data limits.
+ * @param language The 2 letter ISO 639-1 representation of language. If not set, uses "en" for English as default.
+ * @param options The additional configurable {@link RecognizePiiEntityOptions options} that may be passed when
+ * recognizing PII entities.
+ *
+ * @return A {@link Mono} contains a {@link PiiEntityCollection recognized PII entities collection}.
+ *
+ * @throws NullPointerException if {@code document} is null.
+ * @throws TextAnalyticsException if the response returned with an {@link TextAnalyticsError error}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public Mono recognizePiiEntities(String document, String language,
+ RecognizePiiEntityOptions options) {
+ return recognizePiiEntityAsyncClient.recognizePiiEntities(document, language, options);
}
/**
@@ -438,14 +470,14 @@ public Mono recognizePiiEntities(String document, String la
* Recognize Personally Identifiable Information entities in a document with the provided language code.
* Subscribes to the call asynchronously and prints out the entity details when a response is received.
*
- * {@codesnippet com.azure.ai.textanalytics.TextAnalyticsAsyncClient.recognizePiiEntitiesBatch#Iterable-String-TextAnalyticsRequestOptions}
+ * {@codesnippet com.azure.ai.textanalytics.TextAnalyticsAsyncClient.recognizePiiEntitiesBatch#Iterable-String-RecognizePiiEntityOptions}
*
* @param documents A list of documents to recognize PII entities for.
* For text length limits, maximum batch size, and supported text encoding, see
* data limits.
* @param language The 2 letter ISO 639-1 representation of language. If not set, uses "en" for English as default.
- * @param options The {@link TextAnalyticsRequestOptions options} to configure the scoring model for documents
- * and show statistics.
+ * @param options The additional configurable {@link RecognizePiiEntityOptions options} that may be passed when
+ * recognizing PII entities.
*
* @return A {@link Mono} contains a {@link RecognizePiiEntitiesResultCollection}.
*
@@ -454,7 +486,7 @@ public Mono recognizePiiEntities(String document, String la
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono recognizePiiEntitiesBatch(
- Iterable documents, String language, TextAnalyticsRequestOptions options) {
+ Iterable documents, String language, RecognizePiiEntityOptions options) {
try {
inputDocumentsValidation(documents);
return recognizePiiEntitiesBatchWithResponse(
@@ -477,13 +509,13 @@ public Mono recognizePiiEntitiesBatch(
* with provided request options.
* Subscribes to the call asynchronously and prints out the entity details when a response is received.
*
- * {@codesnippet com.azure.ai.textanalytics.TextAnalyticsAsyncClient.recognizePiiEntitiesBatch#Iterable-TextAnalyticsRequestOptions}
+ * {@codesnippet com.azure.ai.textanalytics.TextAnalyticsAsyncClient.recognizePiiEntitiesBatch#Iterable-RecognizePiiEntityOptions}
*
* @param documents A list of {@link TextDocumentInput documents} to recognize PII entities for.
* For text length limits, maximum batch size, and supported text encoding, see
* data limits.
- * @param options The {@link TextAnalyticsRequestOptions options} to configure the scoring model for documents
- * and show statistics.
+ * @param options The additional configurable {@link RecognizePiiEntityOptions options} that may be passed when
+ * recognizing PII entities.
*
* @return A {@link Mono} contains a {@link Response} which contains a {@link RecognizePiiEntitiesResultCollection}.
*
@@ -492,7 +524,7 @@ public Mono recognizePiiEntitiesBatch(
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono> recognizePiiEntitiesBatchWithResponse(
- Iterable documents, TextAnalyticsRequestOptions options) {
+ Iterable documents, RecognizePiiEntityOptions options) {
return recognizePiiEntityAsyncClient.recognizePiiEntitiesBatch(documents, options);
}
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/TextAnalyticsClient.java b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/TextAnalyticsClient.java
index 360baf9aacaff..194577388a9d2 100644
--- a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/TextAnalyticsClient.java
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/TextAnalyticsClient.java
@@ -13,6 +13,7 @@
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.RecognizePiiEntityOptions;
import com.azure.ai.textanalytics.models.TextAnalyticsError;
import com.azure.ai.textanalytics.models.TextAnalyticsException;
import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions;
@@ -233,7 +234,6 @@ public CategorizedEntityCollection recognizeEntities(String document) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public CategorizedEntityCollection recognizeEntities(String document, String language) {
- Objects.requireNonNull(document, "'document' cannot be null.");
return client.recognizeEntities(document, language).block();
}
@@ -344,10 +344,40 @@ public PiiEntityCollection recognizePiiEntities(String document) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public PiiEntityCollection recognizePiiEntities(String document, String language) {
- Objects.requireNonNull(document, "'document' cannot be null.");
return client.recognizePiiEntities(document, language).block();
}
+ /**
+ * Returns a list of Personally Identifiable Information(PII) entities in the provided document
+ * with provided language code.
+ *
+ * For a list of supported entity types, check: this
+ * For a list of enabled languages, check: this
+ *
+ * Code Sample
+ * Recognizes the PII entities details in a document with a provided language code and
+ * RecognizePiiEntityOptions.
+ *
+ * {@codesnippet com.azure.ai.textanalytics.TextAnalyticsClient.recognizePiiEntities#String-String-RecognizePiiEntityOptions}
+ *
+ * @param document The document to recognize PII entities details for.
+ * For text length limits, maximum batch size, and supported text encoding, see
+ * data limits.
+ * @param language The 2 letter ISO 639-1 representation of language. If not set, uses "en" for English as default.
+ * @param options The additional configurable {@link RecognizePiiEntityOptions options} that may be passed when
+ * recognizing PII entities.
+ *
+ * @return The {@link PiiEntityCollection recognized PII entities collection}.
+ *
+ * @throws NullPointerException if {@code document} is null.
+ * @throws TextAnalyticsException if the response returned with an {@link TextAnalyticsError error}.
+ */
+ @ServiceMethod(returns = ReturnType.SINGLE)
+ public PiiEntityCollection recognizePiiEntities(String document, String language,
+ RecognizePiiEntityOptions options) {
+ return client.recognizePiiEntities(document, language, options).block();
+ }
+
/**
* Returns a list of Personally Identifiable Information(PII) entities for the provided list of documents with
* provided language code and request options.
@@ -356,14 +386,14 @@ public PiiEntityCollection recognizePiiEntities(String document, String language
* Recognizes the PII entities details in a list of documents with a provided language code
* and request options.
*
- * {@codesnippet com.azure.ai.textanalytics.TextAnalyticsClient.recognizePiiEntitiesBatch#Iterable-String-TextAnalyticsRequestOptions}
+ * {@codesnippet com.azure.ai.textanalytics.TextAnalyticsClient.recognizePiiEntitiesBatch#Iterable-String-RecognizePiiEntityOptions}
*
* @param documents A list of documents to recognize PII entities for.
* For text length limits, maximum batch size, and supported text encoding, see
* data limits.
* @param language The 2 letter ISO 639-1 representation of language. If not set, uses "en" for English as default.
- * @param options The {@link TextAnalyticsRequestOptions options} to configure the scoring model for documents
- * and show statistics.
+ * @param options The additional configurable {@link RecognizePiiEntityOptions options} that may be passed when
+ * recognizing PII entities.
*
* @return A {@link RecognizePiiEntitiesResultCollection}.
*
@@ -372,7 +402,7 @@ public PiiEntityCollection recognizePiiEntities(String document, String language
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public RecognizePiiEntitiesResultCollection recognizePiiEntitiesBatch(
- Iterable documents, String language, TextAnalyticsRequestOptions options) {
+ Iterable documents, String language, RecognizePiiEntityOptions options) {
return client.recognizePiiEntitiesBatch(documents, language, options).block();
}
@@ -384,13 +414,13 @@ public RecognizePiiEntitiesResultCollection recognizePiiEntitiesBatch(
* Recognizes the PII entities details with http response in a list of {@link TextDocumentInput document}
* with provided request options.
*
- * {@codesnippet com.azure.ai.textanalytics.TextAnalyticsClient.recognizePiiEntitiesBatch#Iterable-TextAnalyticsRequestOptions-Context}
+ * {@codesnippet com.azure.ai.textanalytics.TextAnalyticsClient.recognizePiiEntitiesBatch#Iterable-RecognizePiiEntityOptions-Context}
*
* @param documents A list of {@link TextDocumentInput documents} to recognize PII entities for.
* For text length limits, maximum batch size, and supported text encoding, see
* data limits.
- * @param options The {@link TextAnalyticsRequestOptions options} to configure the scoring model for documents
- * and show statistics.
+ * @param options The additional configurable {@link RecognizePiiEntityOptions options} that may be passed when
+ * recognizing PII entities.
* @param context Additional context that is passed through the Http pipeline during the service call.
*
* @return A {@link Response} that contains a {@link RecognizePiiEntitiesResultCollection}.
@@ -400,7 +430,7 @@ public RecognizePiiEntitiesResultCollection recognizePiiEntitiesBatch(
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response recognizePiiEntitiesBatchWithResponse(
- Iterable documents, TextAnalyticsRequestOptions options, Context context) {
+ Iterable documents, RecognizePiiEntityOptions options, Context context) {
return client.recognizePiiEntityAsyncClient.recognizePiiEntitiesBatchWithContext(documents, options,
context).block();
}
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/PiiEntityDomainType.java b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/PiiEntityDomainType.java
new file mode 100644
index 0000000000000..14ecd715bc674
--- /dev/null
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/PiiEntityDomainType.java
@@ -0,0 +1,30 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.azure.ai.textanalytics.models;
+
+import com.azure.core.annotation.Immutable;
+import com.azure.core.util.ExpandableStringEnum;
+import com.fasterxml.jackson.annotation.JsonCreator;
+
+/**
+ * Defines values for PiiEntityDomainType.
+ */
+@Immutable
+public final class PiiEntityDomainType extends ExpandableStringEnum {
+ /**
+ * Protected health information (PHI) as the PiiEntityDomainType.
+ */
+ public static final PiiEntityDomainType PROTECTED_HEALTH_INFORMATION = fromString("PHI");
+
+ /**
+ * Creates or finds a {@link EntityCategory} from its string representation.
+ *
+ * @param name The string name to look for.
+ * @return The corresponding {@link EntityCategory}.
+ */
+ @JsonCreator
+ public static PiiEntityDomainType fromString(String name) {
+ return fromString(name, PiiEntityDomainType.class);
+ }
+}
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/RecognizePiiEntityOptions.java b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/RecognizePiiEntityOptions.java
new file mode 100644
index 0000000000000..0de35c0c888cb
--- /dev/null
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/RecognizePiiEntityOptions.java
@@ -0,0 +1,67 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+package com.azure.ai.textanalytics.models;
+
+import com.azure.core.annotation.Fluent;
+
+/**
+ * The {@link RecognizePiiEntityOptions} model.
+ */
+@Fluent
+public class RecognizePiiEntityOptions extends TextAnalyticsRequestOptions {
+ private PiiEntityDomainType domainFilter;
+
+ /**
+ * Set the model version. This value indicates which model will be used for scoring, e.g. "latest", "2019-10-01".
+ * If a model-version is not specified, the API will default to the latest, non-preview version.
+ *
+ * @param modelVersion The model version.
+ *
+ * @return The {@link RecognizePiiEntityOptions} object itself.
+ */
+ @Override
+ public RecognizePiiEntityOptions setModelVersion(String modelVersion) {
+ super.setModelVersion(modelVersion);
+ return this;
+ }
+
+ /**
+ * Set the value of {@code includeStatistics}.
+ *
+ * @param includeStatistics If a boolean value was specified in the request this field will contain
+ * information about the document payload.
+ *
+ * @return the {@link RecognizePiiEntityOptions} object itself.
+ */
+ @Override
+ public RecognizePiiEntityOptions setIncludeStatistics(boolean includeStatistics) {
+ super.setIncludeStatistics(includeStatistics);
+ return this;
+ }
+
+ /**
+ * Get the value of domainFilter. It filters the response entities to ones only included in the specified domain.
+ * I.e., if set to 'PHI', will only return entities in the Protected Healthcare Information domain.
+ * See https://aka.ms/tanerpii for more information.
+ *
+ * @return The value of domainFilter.
+ */
+ public PiiEntityDomainType getDomainFilter() {
+ return domainFilter;
+ }
+
+ /**
+ * Set the value of domainFilter. It filters the response entities to ones only included in the specified domain.
+ * I.e., if set to 'PHI', will only return entities in the Protected Healthcare Information domain.
+ * See https://aka.ms/tanerpii for more information.
+ *
+ * @param domainFilter It filters the response entities to ones only included in the specified domain.
+ *
+ * @return The RecognizePiiEntityOptions object itself.
+ */
+ public RecognizePiiEntityOptions setDomainFilter(PiiEntityDomainType domainFilter) {
+ this.domainFilter = domainFilter;
+ return this;
+ }
+}
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/TextAnalyticsAsyncClientJavaDocCodeSnippets.java b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/TextAnalyticsAsyncClientJavaDocCodeSnippets.java
index c5ee6138c9f45..5dc10185aaa58 100644
--- a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/TextAnalyticsAsyncClientJavaDocCodeSnippets.java
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/TextAnalyticsAsyncClientJavaDocCodeSnippets.java
@@ -12,6 +12,8 @@
import com.azure.ai.textanalytics.models.ExtractKeyPhraseResult;
import com.azure.ai.textanalytics.models.OpinionSentiment;
import com.azure.ai.textanalytics.models.PiiEntityCollection;
+import com.azure.ai.textanalytics.models.PiiEntityDomainType;
+import com.azure.ai.textanalytics.models.RecognizePiiEntityOptions;
import com.azure.ai.textanalytics.models.SentenceSentiment;
import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions;
import com.azure.ai.textanalytics.models.TextDocumentBatchStatistics;
@@ -275,17 +277,35 @@ public void recognizePiiEntitiesWithLanguage() {
}
/**
- * Code snippet for {@link TextAnalyticsAsyncClient#recognizePiiEntitiesBatch(Iterable, String, TextAnalyticsRequestOptions)}
+ * Code snippet for {@link TextAnalyticsAsyncClient#recognizePiiEntities(String, String, RecognizePiiEntityOptions)}
+ */
+ public void recognizePiiEntitiesWithRecognizePiiEntityOptions() {
+ // BEGIN: com.azure.ai.textanalytics.TextAnalyticsAsyncClient.recognizePiiEntities#string-string-RecognizePiiEntityOptions
+ String document = "My SSN is 859-98-0987";
+ textAnalyticsAsyncClient.recognizePiiEntities(document, "en",
+ new RecognizePiiEntityOptions().setDomainFilter(PiiEntityDomainType.PROTECTED_HEALTH_INFORMATION))
+ .subscribe(piiEntityCollection -> {
+ System.out.printf("Redacted Text: %s%n", piiEntityCollection.getRedactedText());
+ piiEntityCollection.forEach(entity -> System.out.printf(
+ "Recognized Personally Identifiable Information entity: %s, entity category: %s,"
+ + " entity subcategory: %s, confidence score: %f.%n",
+ entity.getText(), entity.getCategory(), entity.getSubcategory(), entity.getConfidenceScore()));
+ });
+ // END: com.azure.ai.textanalytics.TextAnalyticsAsyncClient.recognizePiiEntities#string-string-RecognizePiiEntityOptions
+ }
+
+ /**
+ * Code snippet for {@link TextAnalyticsAsyncClient#recognizePiiEntitiesBatch(Iterable, String, RecognizePiiEntityOptions)}
*/
public void recognizePiiEntitiesStringListWithOptions() {
- // BEGIN: com.azure.ai.textanalytics.TextAnalyticsAsyncClient.recognizePiiEntitiesBatch#Iterable-String-TextAnalyticsRequestOptions
+ // BEGIN: com.azure.ai.textanalytics.TextAnalyticsAsyncClient.recognizePiiEntitiesBatch#Iterable-String-RecognizePiiEntityOptions
List documents = Arrays.asList(
"My SSN is 859-98-0987.",
"Visa card 0111 1111 1111 1111."
);
- // Request options: show statistics and model version
- TextAnalyticsRequestOptions requestOptions = new TextAnalyticsRequestOptions().setIncludeStatistics(true)
+ // Show statistics and model version
+ RecognizePiiEntityOptions requestOptions = new RecognizePiiEntityOptions().setIncludeStatistics(true)
.setModelVersion("latest");
textAnalyticsAsyncClient.recognizePiiEntitiesBatch(documents, "en", requestOptions)
@@ -304,21 +324,22 @@ public void recognizePiiEntitiesStringListWithOptions() {
entity.getText(), entity.getCategory(), entity.getSubcategory(), entity.getConfidenceScore()));
});
});
- // END: com.azure.ai.textanalytics.TextAnalyticsAsyncClient.recognizePiiEntitiesBatch#Iterable-String-TextAnalyticsRequestOptions
+ // END: com.azure.ai.textanalytics.TextAnalyticsAsyncClient.recognizePiiEntitiesBatch#Iterable-String-RecognizePiiEntityOptions
}
/**
* Code snippet for {@link TextAnalyticsAsyncClient#recognizePiiEntitiesBatchWithResponse(Iterable,
- * TextAnalyticsRequestOptions)}
+ * RecognizePiiEntityOptions)}
*/
public void recognizeBatchPiiEntitiesMaxOverload() {
- // BEGIN: com.azure.ai.textanalytics.TextAnalyticsAsyncClient.recognizePiiEntitiesBatch#Iterable-TextAnalyticsRequestOptions
+ // BEGIN: com.azure.ai.textanalytics.TextAnalyticsAsyncClient.recognizePiiEntitiesBatch#Iterable-RecognizePiiEntityOptions
List textDocumentInputs1 = Arrays.asList(
new TextDocumentInput("0", "My SSN is 859-98-0987."),
new TextDocumentInput("1", "Visa card 0111 1111 1111 1111."));
- // Request options: show statistics and model version
- TextAnalyticsRequestOptions requestOptions = new TextAnalyticsRequestOptions().setIncludeStatistics(true);
+ // Show statistics and model version
+ RecognizePiiEntityOptions requestOptions = new RecognizePiiEntityOptions().setIncludeStatistics(true)
+ .setModelVersion("latest");
textAnalyticsAsyncClient.recognizePiiEntitiesBatchWithResponse(textDocumentInputs1, requestOptions)
.subscribe(response -> {
@@ -337,7 +358,7 @@ public void recognizeBatchPiiEntitiesMaxOverload() {
entity.getText(), entity.getCategory(), entity.getSubcategory(), entity.getConfidenceScore()));
});
});
- // END: com.azure.ai.textanalytics.TextAnalyticsAsyncClient.recognizePiiEntitiesBatch#Iterable-TextAnalyticsRequestOptions
+ // END: com.azure.ai.textanalytics.TextAnalyticsAsyncClient.recognizePiiEntitiesBatch#Iterable-RecognizePiiEntityOptions
}
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/TextAnalyticsClientJavaDocCodeSnippets.java b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/TextAnalyticsClientJavaDocCodeSnippets.java
index 58ddf611b1d3e..b9e562f69a794 100644
--- a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/TextAnalyticsClientJavaDocCodeSnippets.java
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/TextAnalyticsClientJavaDocCodeSnippets.java
@@ -13,6 +13,8 @@
import com.azure.ai.textanalytics.models.OpinionSentiment;
import com.azure.ai.textanalytics.models.PiiEntity;
import com.azure.ai.textanalytics.models.PiiEntityCollection;
+import com.azure.ai.textanalytics.models.PiiEntityDomainType;
+import com.azure.ai.textanalytics.models.RecognizePiiEntityOptions;
import com.azure.ai.textanalytics.models.SentenceSentiment;
import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions;
import com.azure.ai.textanalytics.models.TextDocumentBatchStatistics;
@@ -279,17 +281,33 @@ public void recognizePiiEntitiesWithLanguage() {
}
/**
- * Code snippet for {@link TextAnalyticsClient#recognizePiiEntitiesBatch(Iterable, String, TextAnalyticsRequestOptions)}
+ * Code snippet for {@link TextAnalyticsClient#recognizePiiEntities(String, String, RecognizePiiEntityOptions)}
+ */
+ public void recognizePiiEntitiesWithRecognizePiiEntityOptions() {
+ // BEGIN: com.azure.ai.textanalytics.TextAnalyticsClient.recognizePiiEntities#String-String-RecognizePiiEntityOptions
+ PiiEntityCollection piiEntityCollection = textAnalyticsClient.recognizePiiEntities(
+ "My SSN is 859-98-0987", "en",
+ new RecognizePiiEntityOptions().setDomainFilter(PiiEntityDomainType.PROTECTED_HEALTH_INFORMATION));
+ System.out.printf("Redacted Text: %s%n", piiEntityCollection.getRedactedText());
+ piiEntityCollection.forEach(entity -> System.out.printf(
+ "Recognized Personally Identifiable Information entity: %s, entity category: %s,"
+ + " entity subcategory: %s, confidence score: %f.%n",
+ entity.getText(), entity.getCategory(), entity.getSubcategory(), entity.getConfidenceScore()));
+ // END: com.azure.ai.textanalytics.TextAnalyticsClient.recognizePiiEntities#String-String-RecognizePiiEntityOptions
+ }
+
+ /**
+ * Code snippet for {@link TextAnalyticsClient#recognizePiiEntitiesBatch(Iterable, String, RecognizePiiEntityOptions)}
*/
public void recognizePiiEntitiesStringListWithOptions() {
- // BEGIN: com.azure.ai.textanalytics.TextAnalyticsClient.recognizePiiEntitiesBatch#Iterable-String-TextAnalyticsRequestOptions
+ // BEGIN: com.azure.ai.textanalytics.TextAnalyticsClient.recognizePiiEntitiesBatch#Iterable-String-RecognizePiiEntityOptions
List documents = Arrays.asList(
"My SSN is 859-98-0987",
"Visa card 4111 1111 1111 1111"
);
RecognizePiiEntitiesResultCollection resultCollection = textAnalyticsClient.recognizePiiEntitiesBatch(
- documents, "en", new TextAnalyticsRequestOptions().setIncludeStatistics(true));
+ documents, "en", new RecognizePiiEntityOptions().setIncludeStatistics(true));
// Batch statistics
TextDocumentBatchStatistics batchStatistics = resultCollection.getStatistics();
@@ -304,14 +322,14 @@ public void recognizePiiEntitiesStringListWithOptions() {
+ " entity subcategory: %s, confidence score: %f.%n",
entity.getText(), entity.getCategory(), entity.getSubcategory(), entity.getConfidenceScore()));
});
- // END: com.azure.ai.textanalytics.TextAnalyticsClient.recognizePiiEntitiesBatch#Iterable-String-TextAnalyticsRequestOptions
+ // END: com.azure.ai.textanalytics.TextAnalyticsClient.recognizePiiEntitiesBatch#Iterable-String-RecognizePiiEntityOptions
}
/**
- * Code snippet for {@link TextAnalyticsClient#recognizePiiEntitiesBatchWithResponse(Iterable, TextAnalyticsRequestOptions, Context)}
+ * Code snippet for {@link TextAnalyticsClient#recognizePiiEntitiesBatchWithResponse(Iterable, RecognizePiiEntityOptions, Context)}
*/
public void recognizeBatchPiiEntitiesMaxOverload() {
- // BEGIN: com.azure.ai.textanalytics.TextAnalyticsClient.recognizePiiEntitiesBatch#Iterable-TextAnalyticsRequestOptions-Context
+ // BEGIN: com.azure.ai.textanalytics.TextAnalyticsClient.recognizePiiEntitiesBatch#Iterable-RecognizePiiEntityOptions-Context
List textDocumentInputs = Arrays.asList(
new TextDocumentInput("0", "My SSN is 859-98-0987"),
new TextDocumentInput("1", "Visa card 4111 1111 1111 1111")
@@ -319,7 +337,7 @@ public void recognizeBatchPiiEntitiesMaxOverload() {
Response response =
textAnalyticsClient.recognizePiiEntitiesBatchWithResponse(textDocumentInputs,
- new TextAnalyticsRequestOptions().setIncludeStatistics(true), Context.NONE);
+ new RecognizePiiEntityOptions().setIncludeStatistics(true), Context.NONE);
RecognizePiiEntitiesResultCollection resultCollection = response.getValue();
@@ -336,7 +354,7 @@ public void recognizeBatchPiiEntitiesMaxOverload() {
+ " entity subcategory: %s, confidence score: %f.%n",
entity.getText(), entity.getCategory(), entity.getSubcategory(), entity.getConfidenceScore()));
});
- // END: com.azure.ai.textanalytics.TextAnalyticsClient.recognizePiiEntitiesBatch#Iterable-TextAnalyticsRequestOptions-Context
+ // END: com.azure.ai.textanalytics.TextAnalyticsClient.recognizePiiEntitiesBatch#Iterable-RecognizePiiEntityOptions-Context
}
// Linked Entity
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchDocuments.java b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchDocuments.java
index a3e7512ec877d..dff74e566dee6 100644
--- a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchDocuments.java
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchDocuments.java
@@ -7,7 +7,7 @@
import com.azure.ai.textanalytics.TextAnalyticsClientBuilder;
import com.azure.ai.textanalytics.models.PiiEntityCollection;
import com.azure.ai.textanalytics.models.RecognizePiiEntitiesResult;
-import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions;
+import com.azure.ai.textanalytics.models.RecognizePiiEntityOptions;
import com.azure.ai.textanalytics.models.TextDocumentBatchStatistics;
import com.azure.ai.textanalytics.models.TextDocumentInput;
import com.azure.ai.textanalytics.util.RecognizePiiEntitiesResultCollection;
@@ -42,12 +42,12 @@ public static void main(String[] args) {
new TextDocumentInput("2", "Visa card 4111 1111 1111 1111").setLanguage("en")
);
- // Request options: show statistics and model version
- TextAnalyticsRequestOptions requestOptions = new TextAnalyticsRequestOptions().setIncludeStatistics(true).setModelVersion("latest");
+ // Show statistics and model version
+ RecognizePiiEntityOptions options = new RecognizePiiEntityOptions().setIncludeStatistics(true).setModelVersion("latest");
// Recognizing Personally Identifiable Information entities for each document in a batch of documents
Response piiEntitiesBatchResultResponse =
- client.recognizePiiEntitiesBatchWithResponse(documents, requestOptions, Context.NONE);
+ client.recognizePiiEntitiesBatchWithResponse(documents, options, Context.NONE);
// Response's status code
System.out.printf("Status code of request response: %d%n", piiEntitiesBatchResultResponse.getStatusCode());
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchDocumentsAsync.java b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchDocumentsAsync.java
index 867166b0d4670..d6bc1e86c4cf6 100644
--- a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchDocumentsAsync.java
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchDocumentsAsync.java
@@ -7,7 +7,7 @@
import com.azure.ai.textanalytics.TextAnalyticsClientBuilder;
import com.azure.ai.textanalytics.models.PiiEntityCollection;
import com.azure.ai.textanalytics.models.RecognizePiiEntitiesResult;
-import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions;
+import com.azure.ai.textanalytics.models.RecognizePiiEntityOptions;
import com.azure.ai.textanalytics.models.TextDocumentBatchStatistics;
import com.azure.ai.textanalytics.models.TextDocumentInput;
import com.azure.ai.textanalytics.util.RecognizePiiEntitiesResultCollection;
@@ -41,11 +41,11 @@ public static void main(String[] args) {
new TextDocumentInput("2", "Visa card 4111 1111 1111 1111").setLanguage("en")
);
- // Request options: show statistics and model version
- TextAnalyticsRequestOptions requestOptions = new TextAnalyticsRequestOptions().setIncludeStatistics(true).setModelVersion("latest");
+ // Show statistics and model version
+ RecognizePiiEntityOptions options = new RecognizePiiEntityOptions().setIncludeStatistics(true).setModelVersion("latest");
// Recognizing Personally Identifiable Information entities for each document in a batch of documents
- client.recognizePiiEntitiesBatchWithResponse(documents, requestOptions).subscribe(
+ client.recognizePiiEntitiesBatchWithResponse(documents, options).subscribe(
entitiesBatchResultResponse -> {
// Response's status code
System.out.printf("Status code of request response: %d%n", entitiesBatchResultResponse.getStatusCode());
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchStringDocuments.java b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchStringDocuments.java
index 8df44607f383a..99004a677d1f9 100644
--- a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchStringDocuments.java
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchStringDocuments.java
@@ -7,7 +7,7 @@
import com.azure.ai.textanalytics.TextAnalyticsClientBuilder;
import com.azure.ai.textanalytics.models.PiiEntityCollection;
import com.azure.ai.textanalytics.models.RecognizePiiEntitiesResult;
-import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions;
+import com.azure.ai.textanalytics.models.RecognizePiiEntityOptions;
import com.azure.ai.textanalytics.models.TextDocumentBatchStatistics;
import com.azure.ai.textanalytics.util.RecognizePiiEntitiesResultCollection;
import com.azure.core.credential.AzureKeyCredential;
@@ -39,11 +39,11 @@ public static void main(String[] args) {
"Visa card 4111 1111 1111 1111"
);
- // Request options: show statistics and model version
- TextAnalyticsRequestOptions requestOptions = new TextAnalyticsRequestOptions().setIncludeStatistics(true).setModelVersion("latest");
+ // Show statistics and model version
+ RecognizePiiEntityOptions options = new RecognizePiiEntityOptions().setIncludeStatistics(true).setModelVersion("latest");
// Recognizing Personally Identifiable Information entities for each document in a batch of documents
- RecognizePiiEntitiesResultCollection recognizePiiEntitiesResultCollection = client.recognizePiiEntitiesBatch(documents, "en", requestOptions);
+ RecognizePiiEntitiesResultCollection recognizePiiEntitiesResultCollection = client.recognizePiiEntitiesBatch(documents, "en", options);
// Model version
System.out.printf("Results of Azure Text Analytics \"Personally Identifiable Information Entities Recognition\" Model, version: %s%n", recognizePiiEntitiesResultCollection.getModelVersion());
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchStringDocumentsAsync.java b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchStringDocumentsAsync.java
index 73e621ef14515..76e17975e2438 100644
--- a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchStringDocumentsAsync.java
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchStringDocumentsAsync.java
@@ -7,7 +7,7 @@
import com.azure.ai.textanalytics.TextAnalyticsClientBuilder;
import com.azure.ai.textanalytics.models.PiiEntityCollection;
import com.azure.ai.textanalytics.models.RecognizePiiEntitiesResult;
-import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions;
+import com.azure.ai.textanalytics.models.RecognizePiiEntityOptions;
import com.azure.ai.textanalytics.models.TextDocumentBatchStatistics;
import com.azure.core.credential.AzureKeyCredential;
@@ -39,12 +39,12 @@ public static void main(String[] args) {
"Visa card 4111 1111 1111 1111"
);
- // Request options: show statistics and model version
- TextAnalyticsRequestOptions requestOptions = new TextAnalyticsRequestOptions().setIncludeStatistics(true).setModelVersion("latest");
+ // Show statistics and model version
+ RecognizePiiEntityOptions options = new RecognizePiiEntityOptions().setIncludeStatistics(true).setModelVersion("latest");
// Recognizing Personally Identifiable Information entities for each document in a batch of documents
AtomicInteger counter = new AtomicInteger();
- client.recognizePiiEntitiesBatch(documents, "en", requestOptions).subscribe(
+ client.recognizePiiEntitiesBatch(documents, "en", options).subscribe(
recognizePiiEntitiesResultCollection -> {
// Model version
System.out.printf("Results of Azure Text Analytics \"Personally Identifiable Information Entities Recognition\" Model, version: %s%n", recognizePiiEntitiesResultCollection.getModelVersion());
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/test/java/com/azure/ai/textanalytics/TestUtils.java b/sdk/textanalytics/azure-ai-textanalytics/src/test/java/com/azure/ai/textanalytics/TestUtils.java
index 1cc804da9f57f..9ffa80b854bb0 100644
--- a/sdk/textanalytics/azure-ai-textanalytics/src/test/java/com/azure/ai/textanalytics/TestUtils.java
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/test/java/com/azure/ai/textanalytics/TestUtils.java
@@ -247,6 +247,27 @@ static RecognizePiiEntitiesResultCollection getExpectedBatchPiiEntities() {
new TextDocumentBatchStatistics(2, 2, 0, 2));
}
+ /**
+ * Helper method to get the expected batch of Personally Identifiable Information entities for domain filter
+ */
+ static RecognizePiiEntitiesResultCollection getExpectedBatchPiiEntitiesForDomainFilter() {
+ PiiEntityCollection piiEntityCollection = new PiiEntityCollection(
+ new IterableStream<>(Arrays.asList(getPiiEntitiesList1().get(1))),
+ "Microsoft employee with ssn *********** is using our awesome API's.", null);
+ PiiEntityCollection piiEntityCollection2 = new PiiEntityCollection(
+ new IterableStream<>(Arrays.asList(getPiiEntitiesList2().get(0), getPiiEntitiesList2().get(1), getPiiEntitiesList2().get(2))),
+ "Your ABA number - ********* - is the first 9 digits in the lower left hand corner of your personal check.", null);
+ TextDocumentStatistics textDocumentStatistics1 = new TextDocumentStatistics(67, 1);
+ TextDocumentStatistics textDocumentStatistics2 = new TextDocumentStatistics(105, 1);
+ RecognizePiiEntitiesResult recognizeEntitiesResult1 = new RecognizePiiEntitiesResult("0", textDocumentStatistics1, null, piiEntityCollection);
+ RecognizePiiEntitiesResult recognizeEntitiesResult2 = new RecognizePiiEntitiesResult("1", textDocumentStatistics2, null, piiEntityCollection2);
+
+ return new RecognizePiiEntitiesResultCollection(
+ asList(recognizeEntitiesResult1, recognizeEntitiesResult2),
+ DEFAULT_MODEL_VERSION,
+ new TextDocumentBatchStatistics(2, 2, 0, 2));
+ }
+
/**
* Helper method to get the expected Categorized Entities List 1
*/
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/test/java/com/azure/ai/textanalytics/TextAnalyticsAsyncClientTest.java b/sdk/textanalytics/azure-ai-textanalytics/src/test/java/com/azure/ai/textanalytics/TextAnalyticsAsyncClientTest.java
index eaea7f9d9d599..f12b48da5ddde 100644
--- a/sdk/textanalytics/azure-ai-textanalytics/src/test/java/com/azure/ai/textanalytics/TextAnalyticsAsyncClientTest.java
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/test/java/com/azure/ai/textanalytics/TextAnalyticsAsyncClientTest.java
@@ -5,6 +5,8 @@
import com.azure.ai.textanalytics.models.AnalyzeSentimentOptions;
import com.azure.ai.textanalytics.models.DocumentSentiment;
+import com.azure.ai.textanalytics.models.PiiEntityDomainType;
+import com.azure.ai.textanalytics.models.RecognizePiiEntityOptions;
import com.azure.ai.textanalytics.models.SentenceSentiment;
import com.azure.ai.textanalytics.models.SentimentConfidenceScores;
import com.azure.ai.textanalytics.models.TextAnalyticsError;
@@ -37,6 +39,7 @@
import static com.azure.ai.textanalytics.TestUtils.getExpectedBatchKeyPhrases;
import static com.azure.ai.textanalytics.TestUtils.getExpectedBatchLinkedEntities;
import static com.azure.ai.textanalytics.TestUtils.getExpectedBatchPiiEntities;
+import static com.azure.ai.textanalytics.TestUtils.getExpectedBatchPiiEntitiesForDomainFilter;
import static com.azure.ai.textanalytics.TestUtils.getExpectedBatchTextSentiment;
import static com.azure.ai.textanalytics.TestUtils.getExpectedDocumentSentiment;
import static com.azure.ai.textanalytics.TestUtils.getLinkedEntitiesList1;
@@ -739,6 +742,39 @@ public void recognizePiiEntitiesZalgoText(HttpClient httpClient, TextAnalyticsSe
);
}
+ @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
+ @MethodSource("com.azure.ai.textanalytics.TestUtils#getTestParameters")
+ public void recognizePiiEntitiesForDomainFilter(HttpClient httpClient, TextAnalyticsServiceVersion serviceVersion) {
+ client = getTextAnalyticsAsyncClient(httpClient, serviceVersion);
+ recognizePiiDomainFilterRunner((document, options) ->
+ StepVerifier.create(client.recognizePiiEntities(document, "en", options))
+ .assertNext(response -> validatePiiEntities(Arrays.asList(getPiiEntitiesList1().get(1)),
+ response.stream().collect(Collectors.toList())))
+ .verifyComplete());
+ }
+
+ @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
+ @MethodSource("com.azure.ai.textanalytics.TestUtils#getTestParameters")
+ public void recognizePiiEntitiesForBatchInputStringForDomainFilter(HttpClient httpClient, TextAnalyticsServiceVersion serviceVersion) {
+ client = getTextAnalyticsAsyncClient(httpClient, serviceVersion);
+ recognizePiiLanguageHintRunner((inputs, language) ->
+ StepVerifier.create(client.recognizePiiEntitiesBatch(inputs, language,
+ new RecognizePiiEntityOptions().setDomainFilter(PiiEntityDomainType.PROTECTED_HEALTH_INFORMATION)))
+ .assertNext(response -> validatePiiEntitiesResultCollection(false, getExpectedBatchPiiEntitiesForDomainFilter(), response))
+ .verifyComplete());
+ }
+
+ @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
+ @MethodSource("com.azure.ai.textanalytics.TestUtils#getTestParameters")
+ public void recognizePiiEntitiesForBatchInputForDomainFilter(HttpClient httpClient, TextAnalyticsServiceVersion serviceVersion) {
+ client = getTextAnalyticsAsyncClient(httpClient, serviceVersion);
+ recognizeBatchPiiEntitiesRunner((inputs) ->
+ StepVerifier.create(client.recognizePiiEntitiesBatchWithResponse(inputs,
+ new RecognizePiiEntityOptions().setDomainFilter(PiiEntityDomainType.PROTECTED_HEALTH_INFORMATION)))
+ .assertNext(response -> validatePiiEntitiesResultCollectionWithResponse(false, getExpectedBatchPiiEntitiesForDomainFilter(), 200, response))
+ .verifyComplete());
+ }
+
// Linked Entities
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.textanalytics.TestUtils#getTestParameters")
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/test/java/com/azure/ai/textanalytics/TextAnalyticsClientTest.java b/sdk/textanalytics/azure-ai-textanalytics/src/test/java/com/azure/ai/textanalytics/TextAnalyticsClientTest.java
index 8eeec4158af8e..a629245699734 100644
--- a/sdk/textanalytics/azure-ai-textanalytics/src/test/java/com/azure/ai/textanalytics/TextAnalyticsClientTest.java
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/test/java/com/azure/ai/textanalytics/TextAnalyticsClientTest.java
@@ -8,6 +8,8 @@
import com.azure.ai.textanalytics.models.DocumentSentiment;
import com.azure.ai.textanalytics.models.LinkedEntity;
import com.azure.ai.textanalytics.models.PiiEntityCollection;
+import com.azure.ai.textanalytics.models.PiiEntityDomainType;
+import com.azure.ai.textanalytics.models.RecognizePiiEntityOptions;
import com.azure.ai.textanalytics.models.SentenceSentiment;
import com.azure.ai.textanalytics.models.SentimentConfidenceScores;
import com.azure.ai.textanalytics.models.TextAnalyticsError;
@@ -42,6 +44,7 @@
import static com.azure.ai.textanalytics.TestUtils.getExpectedBatchKeyPhrases;
import static com.azure.ai.textanalytics.TestUtils.getExpectedBatchLinkedEntities;
import static com.azure.ai.textanalytics.TestUtils.getExpectedBatchPiiEntities;
+import static com.azure.ai.textanalytics.TestUtils.getExpectedBatchPiiEntitiesForDomainFilter;
import static com.azure.ai.textanalytics.TestUtils.getExpectedBatchTextSentiment;
import static com.azure.ai.textanalytics.TestUtils.getExpectedDocumentSentiment;
import static com.azure.ai.textanalytics.TestUtils.getLinkedEntitiesList1;
@@ -713,6 +716,38 @@ public void recognizePiiEntitiesZalgoText(HttpClient httpClient, TextAnalyticsSe
}, PII_ENTITY_OFFSET_INPUT);
}
+ @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
+ @MethodSource("com.azure.ai.textanalytics.TestUtils#getTestParameters")
+ public void recognizePiiEntitiesForDomainFilter(HttpClient httpClient, TextAnalyticsServiceVersion serviceVersion) {
+ client = getTextAnalyticsClient(httpClient, serviceVersion);
+ recognizePiiDomainFilterRunner((document, options) -> {
+ final PiiEntityCollection entities = client.recognizePiiEntities(document, "en", options);
+ validatePiiEntities(Arrays.asList(getPiiEntitiesList1().get(1)), entities.stream().collect(Collectors.toList()));
+ });
+ }
+
+ @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
+ @MethodSource("com.azure.ai.textanalytics.TestUtils#getTestParameters")
+ public void recognizePiiEntitiesForBatchInputStringForDomainFilter(HttpClient httpClient, TextAnalyticsServiceVersion serviceVersion) {
+ client = getTextAnalyticsClient(httpClient, serviceVersion);
+ recognizePiiLanguageHintRunner((inputs, language) -> {
+ final RecognizePiiEntitiesResultCollection response = client.recognizePiiEntitiesBatch(inputs, language,
+ new RecognizePiiEntityOptions().setDomainFilter(PiiEntityDomainType.PROTECTED_HEALTH_INFORMATION));
+ validatePiiEntitiesResultCollection(false, getExpectedBatchPiiEntitiesForDomainFilter(), response);
+ });
+ }
+
+ @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
+ @MethodSource("com.azure.ai.textanalytics.TestUtils#getTestParameters")
+ public void recognizePiiEntitiesForBatchInputForDomainFilter(HttpClient httpClient, TextAnalyticsServiceVersion serviceVersion) {
+ client = getTextAnalyticsClient(httpClient, serviceVersion);
+ recognizeBatchPiiEntitiesRunner((inputs) -> {
+ final Response response = client.recognizePiiEntitiesBatchWithResponse(inputs,
+ new RecognizePiiEntityOptions().setDomainFilter(PiiEntityDomainType.PROTECTED_HEALTH_INFORMATION), Context.NONE);
+ validatePiiEntitiesResultCollectionWithResponse(false, getExpectedBatchPiiEntitiesForDomainFilter(), 200, response);
+ });
+ }
+
// Recognize linked entity
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/test/java/com/azure/ai/textanalytics/TextAnalyticsClientTestBase.java b/sdk/textanalytics/azure-ai-textanalytics/src/test/java/com/azure/ai/textanalytics/TextAnalyticsClientTestBase.java
index b03c9a39779a5..843411186104c 100644
--- a/sdk/textanalytics/azure-ai-textanalytics/src/test/java/com/azure/ai/textanalytics/TextAnalyticsClientTestBase.java
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/test/java/com/azure/ai/textanalytics/TextAnalyticsClientTestBase.java
@@ -15,6 +15,8 @@
import com.azure.ai.textanalytics.models.OpinionSentiment;
import com.azure.ai.textanalytics.models.PiiEntity;
import com.azure.ai.textanalytics.models.PiiEntityCollection;
+import com.azure.ai.textanalytics.models.PiiEntityDomainType;
+import com.azure.ai.textanalytics.models.RecognizePiiEntityOptions;
import com.azure.ai.textanalytics.models.SentenceSentiment;
import com.azure.ai.textanalytics.models.TextAnalyticsError;
import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions;
@@ -157,6 +159,15 @@ public abstract class TextAnalyticsClientTestBase extends TestBase {
@Test
abstract void recognizePiiEntitiesBatchTooManyDocuments(HttpClient httpClient, TextAnalyticsServiceVersion serviceVersion);
+ @Test
+ abstract void recognizePiiEntitiesForDomainFilter(HttpClient httpClient, TextAnalyticsServiceVersion serviceVersion);
+
+ @Test
+ abstract void recognizePiiEntitiesForBatchInputStringForDomainFilter(HttpClient httpClient, TextAnalyticsServiceVersion serviceVersion);
+
+ @Test
+ abstract void recognizePiiEntitiesForBatchInputForDomainFilter(HttpClient httpClient, TextAnalyticsServiceVersion serviceVersion);
+
// Linked Entities
@Test
abstract void recognizeLinkedEntitiesForTextInput(HttpClient httpClient, TextAnalyticsServiceVersion serviceVersion);
@@ -369,6 +380,11 @@ void recognizePiiSingleDocumentRunner(Consumer testRunner) {
testRunner.accept(PII_ENTITY_INPUTS.get(0));
}
+ void recognizePiiDomainFilterRunner(BiConsumer testRunner) {
+ testRunner.accept(PII_ENTITY_INPUTS.get(0),
+ new RecognizePiiEntityOptions().setDomainFilter(PiiEntityDomainType.PROTECTED_HEALTH_INFORMATION));
+ }
+
void recognizePiiLanguageHintRunner(BiConsumer, String> testRunner) {
testRunner.accept(PII_ENTITY_INPUTS, "en");
}
@@ -391,16 +407,16 @@ void recognizeBatchPiiEntitiesRunner(Consumer> testRunne
}
void recognizeBatchPiiEntitiesShowStatsRunner(
- BiConsumer, TextAnalyticsRequestOptions> testRunner) {
+ BiConsumer, RecognizePiiEntityOptions> testRunner) {
final List textDocumentInputs = TestUtils.getTextDocumentInputs(PII_ENTITY_INPUTS);
- TextAnalyticsRequestOptions options = new TextAnalyticsRequestOptions().setIncludeStatistics(true);
+ RecognizePiiEntityOptions options = new RecognizePiiEntityOptions().setIncludeStatistics(true);
testRunner.accept(textDocumentInputs, options);
}
void recognizeStringBatchPiiEntitiesShowStatsRunner(
- BiConsumer, TextAnalyticsRequestOptions> testRunner) {
- testRunner.accept(PII_ENTITY_INPUTS, new TextAnalyticsRequestOptions().setIncludeStatistics(true));
+ BiConsumer, RecognizePiiEntityOptions> testRunner) {
+ testRunner.accept(PII_ENTITY_INPUTS, new RecognizePiiEntityOptions().setIncludeStatistics(true));
}
// Linked Entity runner
@@ -439,7 +455,7 @@ void recognizeBatchLinkedEntityDuplicateIdRunner(Consumer testRunner) {
testRunner.accept(KEY_PHRASE_INPUTS.get(1));
- };
+ }
void extractBatchStringKeyPhrasesShowStatsRunner(BiConsumer, TextAnalyticsRequestOptions> testRunner) {
testRunner.accept(KEY_PHRASE_INPUTS, new TextAnalyticsRequestOptions().setIncludeStatistics(true));
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/test/resources/session-records/recognizePiiEntitiesForBatchInputForDomainFilter.json b/sdk/textanalytics/azure-ai-textanalytics/src/test/resources/session-records/recognizePiiEntitiesForBatchInputForDomainFilter.json
new file mode 100644
index 0000000000000..daf76590799c6
--- /dev/null
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/test/resources/session-records/recognizePiiEntitiesForBatchInputForDomainFilter.json
@@ -0,0 +1,26 @@
+{
+ "networkCallRecords" : [ {
+ "Method" : "POST",
+ "Uri" : "https://REDACTED.azure-api.net/text/analytics/v3.1-preview.2//entities/recognition/pii?showStats=false&domain=PHI&stringIndexType=Utf16CodeUnit",
+ "Headers" : {
+ "User-Agent" : "azsdk-java-azure-ai-textanalytics/5.1.0-beta.1 (11.0.7; Windows 10; 10.0)",
+ "x-ms-client-request-id" : "d12860b5-4b4d-4277-9064-1512b84f289c",
+ "Content-Type" : "application/json"
+ },
+ "Response" : {
+ "Transfer-Encoding" : "chunked",
+ "x-envoy-upstream-service-time" : "122",
+ "Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload",
+ "x-content-type-options" : "nosniff",
+ "csp-billing-usage" : "CognitiveServices.TextAnalytics.BatchScoring=2",
+ "apim-request-id" : "8eddd6a4-0d46-438e-b359-16ef4b9085ec",
+ "retry-after" : "0",
+ "StatusCode" : "200",
+ "Body" : "{\"documents\":[{\"redactedText\":\"Microsoft employee with ssn *********** is using our awesome API's.\",\"id\":\"0\",\"entities\":[{\"text\":\"859-98-0987\",\"category\":\"U.S. Social Security Number (SSN)\",\"offset\":28,\"length\":11,\"confidenceScore\":0.65}],\"warnings\":[]},{\"redactedText\":\"Your ABA number - ********* - is the first 9 digits in the lower left hand corner of your personal check.\",\"id\":\"1\",\"entities\":[{\"text\":\"111000025\",\"category\":\"Phone Number\",\"offset\":18,\"length\":9,\"confidenceScore\":0.8},{\"text\":\"111000025\",\"category\":\"ABA Routing Number\",\"offset\":18,\"length\":9,\"confidenceScore\":0.75},{\"text\":\"111000025\",\"category\":\"New Zealand Social Welfare Number\",\"offset\":18,\"length\":9,\"confidenceScore\":0.65}],\"warnings\":[]}],\"errors\":[],\"modelVersion\":\"2020-07-01\"}",
+ "Date" : "Thu, 03 Sep 2020 22:35:33 GMT",
+ "Content-Type" : "application/json; charset=utf-8"
+ },
+ "Exception" : null
+ } ],
+ "variables" : [ ]
+}
\ No newline at end of file
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/test/resources/session-records/recognizePiiEntitiesForBatchInputStringForDomainFilter.json b/sdk/textanalytics/azure-ai-textanalytics/src/test/resources/session-records/recognizePiiEntitiesForBatchInputStringForDomainFilter.json
new file mode 100644
index 0000000000000..d6a86af10902e
--- /dev/null
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/test/resources/session-records/recognizePiiEntitiesForBatchInputStringForDomainFilter.json
@@ -0,0 +1,26 @@
+{
+ "networkCallRecords" : [ {
+ "Method" : "POST",
+ "Uri" : "https://REDACTED.azure-api.net/text/analytics/v3.1-preview.2//entities/recognition/pii?showStats=false&domain=PHI&stringIndexType=Utf16CodeUnit",
+ "Headers" : {
+ "User-Agent" : "azsdk-java-azure-ai-textanalytics/5.1.0-beta.1 (11.0.7; Windows 10; 10.0)",
+ "x-ms-client-request-id" : "7051662f-b272-4857-951f-327fd231943c",
+ "Content-Type" : "application/json"
+ },
+ "Response" : {
+ "Transfer-Encoding" : "chunked",
+ "x-envoy-upstream-service-time" : "123",
+ "Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload",
+ "x-content-type-options" : "nosniff",
+ "csp-billing-usage" : "CognitiveServices.TextAnalytics.BatchScoring=2",
+ "apim-request-id" : "43ac1d18-4460-4fef-8dbc-9f8b0371e11d",
+ "retry-after" : "0",
+ "StatusCode" : "200",
+ "Body" : "{\"documents\":[{\"redactedText\":\"Microsoft employee with ssn *********** is using our awesome API's.\",\"id\":\"0\",\"entities\":[{\"text\":\"859-98-0987\",\"category\":\"U.S. Social Security Number (SSN)\",\"offset\":28,\"length\":11,\"confidenceScore\":0.65}],\"warnings\":[]},{\"redactedText\":\"Your ABA number - ********* - is the first 9 digits in the lower left hand corner of your personal check.\",\"id\":\"1\",\"entities\":[{\"text\":\"111000025\",\"category\":\"Phone Number\",\"offset\":18,\"length\":9,\"confidenceScore\":0.8},{\"text\":\"111000025\",\"category\":\"ABA Routing Number\",\"offset\":18,\"length\":9,\"confidenceScore\":0.75},{\"text\":\"111000025\",\"category\":\"New Zealand Social Welfare Number\",\"offset\":18,\"length\":9,\"confidenceScore\":0.65}],\"warnings\":[]}],\"errors\":[],\"modelVersion\":\"2020-07-01\"}",
+ "Date" : "Thu, 03 Sep 2020 22:35:52 GMT",
+ "Content-Type" : "application/json; charset=utf-8"
+ },
+ "Exception" : null
+ } ],
+ "variables" : [ ]
+}
\ No newline at end of file
diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/test/resources/session-records/recognizePiiEntitiesForDomainFilter.json b/sdk/textanalytics/azure-ai-textanalytics/src/test/resources/session-records/recognizePiiEntitiesForDomainFilter.json
new file mode 100644
index 0000000000000..49046bfa7c2e3
--- /dev/null
+++ b/sdk/textanalytics/azure-ai-textanalytics/src/test/resources/session-records/recognizePiiEntitiesForDomainFilter.json
@@ -0,0 +1,26 @@
+{
+ "networkCallRecords" : [ {
+ "Method" : "POST",
+ "Uri" : "https://REDACTED.azure-api.net/text/analytics/v3.1-preview.2//entities/recognition/pii?showStats=false&domain=PHI&stringIndexType=Utf16CodeUnit",
+ "Headers" : {
+ "User-Agent" : "azsdk-java-azure-ai-textanalytics/5.1.0-beta.1 (11.0.7; Windows 10; 10.0)",
+ "x-ms-client-request-id" : "8be63659-d554-4018-87e4-60c9d3d6fcf6",
+ "Content-Type" : "application/json"
+ },
+ "Response" : {
+ "Transfer-Encoding" : "chunked",
+ "x-envoy-upstream-service-time" : "100",
+ "Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload",
+ "x-content-type-options" : "nosniff",
+ "csp-billing-usage" : "CognitiveServices.TextAnalytics.BatchScoring=1",
+ "apim-request-id" : "ccca32ce-1053-4ad0-b7ef-adec5308bd68",
+ "retry-after" : "0",
+ "StatusCode" : "200",
+ "Body" : "{\"documents\":[{\"redactedText\":\"Microsoft employee with ssn *********** is using our awesome API's.\",\"id\":\"0\",\"entities\":[{\"text\":\"859-98-0987\",\"category\":\"U.S. Social Security Number (SSN)\",\"offset\":28,\"length\":11,\"confidenceScore\":0.65}],\"warnings\":[]}],\"errors\":[],\"modelVersion\":\"2020-07-01\"}",
+ "Date" : "Thu, 03 Sep 2020 22:35:58 GMT",
+ "Content-Type" : "application/json; charset=utf-8"
+ },
+ "Exception" : null
+ } ],
+ "variables" : [ ]
+}
\ No newline at end of file