From 1600d24d4c4ff5c90920f2023fe970845707c4b0 Mon Sep 17 00:00:00 2001 From: Sameeksha Vaity Date: Wed, 18 Dec 2019 14:44:53 -0800 Subject: [PATCH] Update models (#31) --- .../TextAnalyticsAsyncClient.java | 720 +++++++++++------- .../ai/textanalytics/TextAnalyticsClient.java | 102 +-- .../models/DocumentResultCollection.java | 6 +- .../azure/ai/textanalytics/models/Error.java | 12 +- ...esult.java => ExtractKeyPhraseResult.java} | 6 +- ...sult.java => RecognizeEntitiesResult.java} | 8 +- ...ava => RecognizeLinkedEntitiesResult.java} | 8 +- .../models/RecognizePiiEntitiesResult.java | 39 + ....java => TextDocumentBatchStatistics.java} | 10 +- .../batch/AnalyzeSentimentBatchDocuments.java | 4 +- .../batch/DetectLanguageBatchDocuments.java | 4 +- .../ExtractKeyPhrasesBatchDocuments.java | 12 +- .../RecognizeEntitiesBatchDocuments.java | 12 +- ...RecognizeLinkedEntitiesBatchDocuments.java | 10 +- .../batch/RecognizePiiBatchDocuments.java | 8 +- .../TextAnalyticsAsyncClientTest.java | 16 +- .../TextAnalyticsClientTest.java | 16 +- .../TextAnalyticsClientTestBase.java | 128 ++-- 18 files changed, 645 insertions(+), 476 deletions(-) rename sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/{KeyPhraseResult.java => ExtractKeyPhraseResult.java} (81%) rename sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/{NamedEntityResult.java => RecognizeEntitiesResult.java} (74%) rename sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/{LinkedEntityResult.java => RecognizeLinkedEntitiesResult.java} (71%) create mode 100644 sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/RecognizePiiEntitiesResult.java rename sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/{TextBatchStatistics.java => TextDocumentBatchStatistics.java} (90%) 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 d25b1469dcdcc..07c0b8d5e137a 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 @@ -10,24 +10,39 @@ import com.azure.ai.textanalytics.implementation.models.DocumentLanguage; import com.azure.ai.textanalytics.implementation.models.DocumentLinkedEntities; import com.azure.ai.textanalytics.implementation.models.DocumentSentiment; +import com.azure.ai.textanalytics.implementation.models.DocumentStatistics; import com.azure.ai.textanalytics.implementation.models.EntitiesResult; +import com.azure.ai.textanalytics.implementation.models.Entity; import com.azure.ai.textanalytics.implementation.models.EntityLinkingResult; +import com.azure.ai.textanalytics.implementation.models.KeyPhraseResult; import com.azure.ai.textanalytics.implementation.models.LanguageBatchInput; +import com.azure.ai.textanalytics.implementation.models.LanguageInput; import com.azure.ai.textanalytics.implementation.models.LanguageResult; +import com.azure.ai.textanalytics.implementation.models.LinkedEntity; +import com.azure.ai.textanalytics.implementation.models.Match; import com.azure.ai.textanalytics.implementation.models.MultiLanguageBatchInput; +import com.azure.ai.textanalytics.implementation.models.MultiLanguageInput; +import com.azure.ai.textanalytics.implementation.models.RequestStatistics; import com.azure.ai.textanalytics.implementation.models.SentenceSentiment; import com.azure.ai.textanalytics.implementation.models.SentimentConfidenceScorePerLabel; import com.azure.ai.textanalytics.implementation.models.SentimentResponse; +import com.azure.ai.textanalytics.implementation.models.TextAnalyticsError; import com.azure.ai.textanalytics.models.DetectLanguageInput; import com.azure.ai.textanalytics.models.DetectLanguageResult; +import com.azure.ai.textanalytics.models.DetectedLanguage; import com.azure.ai.textanalytics.models.DocumentResultCollection; import com.azure.ai.textanalytics.models.Error; -import com.azure.ai.textanalytics.models.KeyPhraseResult; -import com.azure.ai.textanalytics.models.LinkedEntityResult; -import com.azure.ai.textanalytics.models.NamedEntityResult; +import com.azure.ai.textanalytics.models.ExtractKeyPhraseResult; +import com.azure.ai.textanalytics.models.InnerError; +import com.azure.ai.textanalytics.models.LinkedEntityMatch; +import com.azure.ai.textanalytics.models.NamedEntity; +import com.azure.ai.textanalytics.models.RecognizeLinkedEntitiesResult; +import com.azure.ai.textanalytics.models.RecognizeEntitiesResult; import com.azure.ai.textanalytics.models.TextAnalyticsClientOptions; import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions; +import com.azure.ai.textanalytics.models.TextDocumentBatchStatistics; import com.azure.ai.textanalytics.models.TextDocumentInput; +import com.azure.ai.textanalytics.models.TextDocumentStatistics; import com.azure.ai.textanalytics.models.TextSentiment; import com.azure.ai.textanalytics.models.TextSentimentClass; import com.azure.ai.textanalytics.models.TextSentimentResult; @@ -75,22 +90,22 @@ public final class TextAnalyticsAsyncClient { private final String defaultLanguage; /** - * Create a {@code TextAnalyticsAsyncClient} that sends requests to the Text Analytics services's endpoint. - * Each service call goes through the {@link TextAnalyticsClientBuilder#pipeline http pipeline}. + * Create a {@code TextAnalyticsAsyncClient} that sends requests to the Text Analytics services's endpoint. Each + * service call goes through the {@link TextAnalyticsClientBuilder#pipeline http pipeline}. * * @param service The proxy service used to perform REST calls. * @param serviceVersion The versions of Azure Text Analytics supported by this client library. * @param clientOptions The {@link TextAnalyticsClientOptions client option} contains * {@link TextAnalyticsClientOptions#getDefaultLanguage default language} and - * {@link TextAnalyticsClientOptions#getDefaultCountryHint()} default country hint} - * that could be used as default values for each request. + * {@link TextAnalyticsClientOptions#getDefaultCountryHint()} default country hint} that could be used as default + * values for each request. */ TextAnalyticsAsyncClient(TextAnalyticsClientImpl service, TextAnalyticsServiceVersion serviceVersion, TextAnalyticsClientOptions clientOptions) { this.service = service; this.serviceVersion = serviceVersion; defaultCountryHint = clientOptions == null ? null : clientOptions.getDefaultCountryHint(); - defaultLanguage = clientOptions == null ? null : clientOptions.getDefaultLanguage(); + defaultLanguage = clientOptions == null ? null : clientOptions.getDefaultLanguage(); } /** @@ -109,6 +124,7 @@ public TextAnalyticsServiceVersion getServiceVersion() { * @param text The text to be analyzed. * * @return A {@link Mono} containing the {@link DetectLanguageResult detected language} of the text. + * * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -117,15 +133,16 @@ public Mono detectLanguage(String text) { } /** - * Returns a {@link Response} containing the detected language and a numeric score between zero and one. - * Scores close to one indicate 100% certainty that the identified language is true. + * Returns a {@link Response} containing the detected language and a numeric score between zero and one. Scores + * close to one indicate 100% certainty that the identified language is true. * * @param text The text to be analyzed. * @param countryHint Accepts two letter country codes specified by ISO 3166-1 alpha-2. Defaults to "US" if not * specified. * - * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} has the - * {@link DetectLanguageResult detected language} of the text. + * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} has the {@link + * DetectLanguageResult detected language} of the text. + * * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -154,8 +171,9 @@ Mono> detectLanguageWithResponse(String text, Str * * @param textInputs The list of texts to be analyzed. * - * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link DetectLanguageResult detected languages}. + * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link DetectLanguageResult + * detected languages}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -167,11 +185,12 @@ public Mono> detectLanguages(List * Returns the detected language for a batch of input with the provided country hint. * * @param textInputs The list of texts to be analyzed. - * @param countryHint A country hint for the entire batch. Accepts two letter country codes specified by ISO 3166-1 - * alpha-2. Defaults to "US" if not specified. + * @param countryHint A country hint for the entire batch. Accepts two letter country codes specified by ISO + * 3166-1 alpha-2. Defaults to "US" if not specified. + * + * @return A {@link Response} of {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link + * DetectLanguageResult detected languages}. * - * @return A {@link Response} of {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link DetectLanguageResult detected languages}. * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -197,8 +216,9 @@ Mono>> detectLanguagesWi * * @param textInputs The list of {@link DetectLanguageInput inputs/documents} to be analyzed. * - * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link DetectLanguageResult detected languages}. + * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link DetectLanguageResult + * detected languages}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -214,8 +234,9 @@ public Mono> detectBatchLanguages * @param options The {@link TextAnalyticsRequestOptions options} to configure the scoring model for documents * and show statistics. * - * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the - * {@link DocumentResultCollection batch} of {@link DetectLanguageResult detected languages}. + * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the {@link + * DocumentResultCollection batch} of {@link DetectLanguageResult detected languages}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -231,7 +252,8 @@ public Mono>> detectBatc Mono>> detectBatchLanguagesWithResponse( List textInputs, TextAnalyticsRequestOptions options, Context context) { - final LanguageBatchInput languageBatchInput = new LanguageBatchInput().setDocuments(textInputs); + + final LanguageBatchInput languageBatchInput = new LanguageBatchInput().setDocuments(convertToLanguageInput(textInputs)); return service.languagesWithRestResponseAsync( languageBatchInput, options == null ? null : options.getModelVersion(), options == null ? null : options.showStatistics(), context) @@ -244,34 +266,35 @@ Mono>> detectBatchLangua // Named Entity /** - * Returns a list of general named entities in the provided text. - * For a list of supported entity types, check: https://aka.ms/taner - * For a list of enabled languages, check: https://aka.ms/talangs + * Returns a list of general named entities in the provided text. For a list of supported entity types, check: + * https://aka.ms/taner For a list of enabled languages, check: https://aka.ms/talangs * * @param text the text to recognize entities for. * - * @return A {@link Mono} containing the {@link NamedEntityResult named entity} of the text. + * @return A {@link Mono} containing the {@link RecognizeEntitiesResult named entity} of the text. + * * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono recognizeEntities(String text) { + public Mono recognizeEntities(String text) { return recognizeEntitiesWithResponse(text, defaultLanguage).flatMap(FluxUtil::toMono); } /** - * Returns a list of general named entities in the provided text. - * For a list of supported entity types, check: https://aka.ms/taner - * For a list of enabled languages, check: https://aka.ms/talangs + * Returns a list of general named entities in the provided text. For a list of supported entity types, check: + * https://aka.ms/taner For a list of enabled languages, check: https://aka.ms/talangs * * @param text the text to recognize entities for. - * @param language The 2 letter ISO 639-1 representation of language. If not set, uses "en" for English as default. + * @param language The 2 letter ISO 639-1 representation of language. If not set, uses "en" for English as + * default. + * + * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} has the {@link + * RecognizeEntitiesResult named entity} of the text. * - * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} has the - * {@link NamedEntityResult named entity} of the text. * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> recognizeEntitiesWithResponse(String text, String language) { + public Mono> recognizeEntitiesWithResponse(String text, String language) { try { return withContext(context -> recognizeEntitiesWithResponse(text, language, context)); } catch (RuntimeException ex) { @@ -279,17 +302,14 @@ public Mono> recognizeEntitiesWithResponse(String te } } - Mono> recognizeEntitiesWithResponse(String text, String language, Context context) { + Mono> recognizeEntitiesWithResponse(String text, String language, + Context context) { return recognizeBatchEntitiesWithResponse( Arrays.asList(new TextDocumentInput(Integer.toString(0), text, language)), null, context) - .flatMap(response -> { - Iterator responseItem = response.getValue().iterator(); - if (responseItem.hasNext()) { - return Mono.just(new SimpleResponse<>(response, responseItem.next())); - } - return monoError(logger, - new RuntimeException("Unable to recognize entities for the provided text.")); - }); + .flatMap(response -> { + Iterator responseItem = response.getValue().iterator(); + return Mono.just(new SimpleResponse<>(response, responseItem.next())); + }); } /** @@ -297,12 +317,13 @@ Mono> recognizeEntitiesWithResponse(String text, Str * * @param textInputs A list of texts to recognize entities for. * - * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link NamedEntityResult named entity} of the text. + * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link + * RecognizeEntitiesResult named entity} of the text. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> recognizeEntities(List textInputs) { + public Mono> recognizeEntities(List textInputs) { return recognizeEntitiesWithResponse(textInputs, defaultLanguage).flatMap(FluxUtil::toMono); } @@ -310,14 +331,16 @@ public Mono> recognizeEntities(List< * Returns a list of general named entities for the provided list of texts. * * @param textInputs A list of texts to recognize entities for. - * @param language The 2 letter ISO 639-1 representation of language. If not set, uses "en" for English as default. + * @param language The 2 letter ISO 639-1 representation of language. If not set, uses "en" for English as + * default. + * + * @return A {@link Response} of {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link + * RecognizeEntitiesResult named entity}. * - * @return A {@link Response} of {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link NamedEntityResult named entity}. * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono>> recognizeEntitiesWithResponse( + public Mono>> recognizeEntitiesWithResponse( List textInputs, String language) { try { return withContext(context -> recognizeEntitiesWithResponse(textInputs, language, context)); @@ -326,7 +349,7 @@ public Mono>> recognizeEnti } } - Mono>> recognizeEntitiesWithResponse( + Mono>> recognizeEntitiesWithResponse( List textInputs, String language, Context context) { List documentInputs = mapByIndex(textInputs, (index, value) -> new TextDocumentInput(index, value, language)); @@ -338,12 +361,13 @@ Mono>> recognizeEntitiesWit * * @param textInputs A list of {@link TextDocumentInput inputs/documents} to recognize entities for. * - * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link NamedEntityResult named entity}. + * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link + * RecognizeEntitiesResult named entity}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> recognizeBatchEntities( + public Mono> recognizeBatchEntities( List textInputs) { return recognizeBatchEntitiesWithResponse(textInputs, null).flatMap(FluxUtil::toMono); } @@ -355,12 +379,13 @@ public Mono> recognizeBatchEntities( * @param options The {@link TextAnalyticsRequestOptions options} to configure the scoring model for documents * and show statistics. * - * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the - * {@link DocumentResultCollection batch} of {@link NamedEntityResult named entity}. + * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the {@link + * DocumentResultCollection batch} of {@link RecognizeEntitiesResult named entity}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono>> recognizeBatchEntitiesWithResponse( + public Mono>> recognizeBatchEntitiesWithResponse( List textInputs, TextAnalyticsRequestOptions options) { try { return withContext(context -> recognizeBatchEntitiesWithResponse(textInputs, options, context)); @@ -369,9 +394,9 @@ public Mono>> recognizeBatc } } - Mono>> recognizeBatchEntitiesWithResponse( - List document, TextAnalyticsRequestOptions options, Context context) { - final MultiLanguageBatchInput batchInput = new MultiLanguageBatchInput().setDocuments(document); + Mono>> recognizeBatchEntitiesWithResponse( + List documents, TextAnalyticsRequestOptions options, Context context) { + final MultiLanguageBatchInput batchInput = new MultiLanguageBatchInput().setDocuments(convertToMultiLanguageInput(documents)); return service.entitiesRecognitionGeneralWithRestResponseAsync( batchInput, options == null ? null : options.getModelVersion(), @@ -383,36 +408,39 @@ Mono>> recognizeBatchEntiti } // PII Entity + /** - * Returns a list of personal information entities ("SSN", "Bank Account", etc) in the text. - * For the list of supported entity types, check https://aka.ms/tanerpii. - * See https://aka.ms/talangs for the list of enabled languages. + * Returns a list of personal information entities ("SSN", "Bank Account", etc) in the text. For the list of + * supported entity types, check https://aka.ms/tanerpii. See https://aka.ms/talangs for the list of enabled + * languages. * * @param text the text to recognize PII entities for. * - * @return A {@link Mono} containing the {@link NamedEntityResult PII entity} of the text. + * @return A {@link Mono} containing the {@link RecognizeEntitiesResult PII entity} of the text. + * * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono recognizePiiEntities(String text) { + public Mono recognizePiiEntities(String text) { return recognizePiiEntitiesWithResponse(text, defaultLanguage).flatMap(FluxUtil::toMono); } /** - * Returns a list of personal information entities ("SSN", "Bank Account", etc) in the text. - * For the list of supported entity types, check https://aka.ms/tanerpii. - * See https://aka.ms/talangs for the list of enabled languages. + * Returns a list of personal information entities ("SSN", "Bank Account", etc) in the text. For the list of + * supported entity types, check https://aka.ms/tanerpii. See https://aka.ms/talangs for the list of enabled + * languages. * * @param text the text to recognize PII entities for. * @param language The 2 letter ISO 639-1 representation of language for the text. If not set, uses "en" for * English as default. * - * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} has the - * {@link NamedEntityResult named entity} of the text. + * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} has the {@link + * RecognizeEntitiesResult named entity} of the text. + * * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> recognizePiiEntitiesWithResponse(String text, String language) { + public Mono> recognizePiiEntitiesWithResponse(String text, String language) { try { return withContext(context -> recognizePiiEntitiesWithResponse(text, language, context)); } catch (RuntimeException ex) { @@ -420,51 +448,50 @@ public Mono> recognizePiiEntitiesWithResponse(String } } - Mono> recognizePiiEntitiesWithResponse(String text, String language, Context context) { + Mono> recognizePiiEntitiesWithResponse(String text, String language, + Context context) { return recognizeBatchPiiEntitiesWithResponse( Arrays.asList(new TextDocumentInput(Integer.toString(0), text, language)), null, context) - .flatMap(response -> { - Iterator responseItem = response.getValue().iterator(); - if (responseItem.hasNext()) { - return Mono.just(new SimpleResponse<>(response, responseItem.next())); - } - return monoError(logger, - new RuntimeException("Unable to recognize PII entities for the provided text.")); - }); + .flatMap(response -> { + Iterator responseItem = response.getValue().iterator(); + return Mono.just(new SimpleResponse<>(response, responseItem.next())); + }); } /** - * Returns a list of personal information entities ("SSN", "Bank Account", etc) in the list of texts. - * For the list of supported entity types, check https://aka.ms/tanerpii. - * See https://aka.ms/talangs for the list of enabled languages. + * Returns a list of personal information entities ("SSN", "Bank Account", etc) in the list of texts. For the list + * of supported entity types, check https://aka.ms/tanerpii. See https://aka.ms/talangs for the list of enabled + * languages. * * @param textInputs A list of text to recognize PII entities for. * - * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link NamedEntityResult named entity} of the text. + * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link + * RecognizeEntitiesResult named entity} of the text. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> recognizePiiEntities(List textInputs) { + public Mono> recognizePiiEntities(List textInputs) { return recognizePiiEntitiesWithResponse(textInputs, defaultLanguage) .flatMap(FluxUtil::toMono); } /** - * Returns a list of personal information entities ("SSN", "Bank Account", etc) in the list of texts. - * For the list of supported entity types, check https://aka.ms/tanerpii. - * See https://aka.ms/talangs for the list of enabled languages. + * Returns a list of personal information entities ("SSN", "Bank Account", etc) in the list of texts. For the list + * of supported entity types, check https://aka.ms/tanerpii. See https://aka.ms/talangs for the list of enabled + * languages. * * @param textInputs A list of text to recognize PII entities for. * @param language The 2 letter ISO 639-1 representation of language for the text. If not set, uses "en" for * English as default. * - * @return A {@link Response} of {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link NamedEntityResult named entity}. + * @return A {@link Response} of {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link + * RecognizeEntitiesResult named entity}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono>> recognizePiiEntitiesWithResponse( + public Mono>> recognizePiiEntitiesWithResponse( List textInputs, String language) { try { return withContext(context -> recognizePiiEntitiesWithResponse(textInputs, language, context)); @@ -473,7 +500,7 @@ public Mono>> recognizePiiE } } - Mono>> recognizePiiEntitiesWithResponse( + Mono>> recognizePiiEntitiesWithResponse( List textInputs, String language, Context context) { List documentInputs = mapByIndex(textInputs, (index, value) -> new TextDocumentInput(index, value, language)); @@ -481,37 +508,39 @@ Mono>> recognizePiiEntities } /** - * Returns a list of personal information entities ("SSN", "Bank Account", etc) in the batch of document inputs. - * For the list of supported entity types, check https://aka.ms/tanerpii. - * See https://aka.ms/talangs for the list of enabled languages. + * Returns a list of personal information entities ("SSN", "Bank Account", etc) in the batch of document inputs. For + * the list of supported entity types, check https://aka.ms/tanerpii. See https://aka.ms/talangs for the list of + * enabled languages. * * @param textInputs A list of {@link TextDocumentInput inputs/documents} to recognize PII entities for. * - * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link NamedEntityResult named entity}. + * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link + * RecognizeEntitiesResult named entity}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> recognizeBatchPiiEntities( + public Mono> recognizeBatchPiiEntities( List textInputs) { return recognizeBatchPiiEntitiesWithResponse(textInputs, null).flatMap(FluxUtil::toMono); } /** - * Returns a list of personal information entities ("SSN", "Bank Account", etc) in the batch of document inputs. - * For the list of supported entity types, check https://aka.ms/tanerpii. - * See https://aka.ms/talangs for the list of enabled languages. + * Returns a list of personal information entities ("SSN", "Bank Account", etc) in the batch of document inputs. For + * the list of supported entity types, check https://aka.ms/tanerpii. See https://aka.ms/talangs for the list of + * enabled languages. * * @param textInputs A list of {@link TextDocumentInput inputs/documents} to recognize PII entities for. * @param options The {@link TextAnalyticsRequestOptions options} to configure the scoring model for documents * and show statistics. * - * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the - * {@link DocumentResultCollection batch} of {@link NamedEntityResult named entity}. + * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the {@link + * DocumentResultCollection batch} of {@link RecognizeEntitiesResult named entity}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono>> recognizeBatchPiiEntitiesWithResponse( + public Mono>> recognizeBatchPiiEntitiesWithResponse( List textInputs, TextAnalyticsRequestOptions options) { try { return withContext(context -> recognizeBatchPiiEntitiesWithResponse(textInputs, options, context)); @@ -520,9 +549,9 @@ public Mono>> recognizeBatc } } - Mono>> recognizeBatchPiiEntitiesWithResponse( - List document, TextAnalyticsRequestOptions options, Context context) { - final MultiLanguageBatchInput batchInput = new MultiLanguageBatchInput().setDocuments(document); + Mono>> recognizeBatchPiiEntitiesWithResponse( + List documents, TextAnalyticsRequestOptions options, Context context) { + final MultiLanguageBatchInput batchInput = new MultiLanguageBatchInput().setDocuments(convertToMultiLanguageInput(documents)); return service.entitiesRecognitionPiiWithRestResponseAsync( batchInput, options == null ? null : options.getModelVersion(), @@ -534,33 +563,38 @@ Mono>> recognizeBatchPiiEnt } // Linked Entity + /** - * Returns a list of recognized entities with links to a well-known knowledge base for the provided text. - * See https://aka.ms/talangs for supported languages in Text Analytics API. + * Returns a list of recognized entities with links to a well-known knowledge base for the provided text. See + * https://aka.ms/talangs for supported languages in Text Analytics API. * * @param text the text to recognize linked entities for. - * @return A {@link Mono} containing the {@link LinkedEntityResult linked entity} of the text. + * + * @return A {@link Mono} containing the {@link RecognizeLinkedEntitiesResult linked entity} of the text. + * * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono recognizeLinkedEntities(String text) { + public Mono recognizeLinkedEntities(String text) { return recognizeLinkedEntitiesWithResponse(text, defaultLanguage).flatMap(FluxUtil::toMono); } /** - * Returns a list of recognized entities with links to a well-known knowledge base for the provided text. - * See https://aka.ms/talangs for supported languages in Text Analytics API. + * Returns a list of recognized entities with links to a well-known knowledge base for the provided text. See + * https://aka.ms/talangs for supported languages in Text Analytics API. * * @param text the text to recognize linked entities for. * @param language The 2 letter ISO 639-1 representation of language for the text. If not set, uses "en" for * English as default. * - * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} has the - * {@link LinkedEntityResult named entity} of the text. + * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} has the {@link + * RecognizeLinkedEntitiesResult named entity} of the text. + * * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> recognizeLinkedEntitiesWithResponse(String text, String language) { + public Mono> recognizeLinkedEntitiesWithResponse(String text, + String language) { try { return withContext(context -> recognizeLinkedEntitiesWithResponse(text, language, context)); } catch (RuntimeException ex) { @@ -568,50 +602,49 @@ public Mono> recognizeLinkedEntitiesWithResponse(St } } - Mono> recognizeLinkedEntitiesWithResponse(String text, String language, + Mono> recognizeLinkedEntitiesWithResponse(String text, String language, Context context) { return recognizeBatchLinkedEntitiesWithResponse( Arrays.asList(new TextDocumentInput(Integer.toString(0), text, language)), null, context) - .flatMap(response -> { - Iterator responseItem = response.getValue().iterator(); - if (responseItem.hasNext()) { - return Mono.just(new SimpleResponse<>(response, responseItem.next())); - } - return monoError(logger, - new RuntimeException("Unable to recognize linked entities for the provided text.")); - }); + .flatMap(response -> { + Iterator responseItem = response.getValue().iterator(); + return Mono.just(new SimpleResponse<>(response, responseItem.next())); + }); } /** - * Returns a list of recognized entities with links to a well-known knowledge base for the list of texts. - * See https://aka.ms/talangs for supported languages in Text Analytics API. + * Returns a list of recognized entities with links to a well-known knowledge base for the list of texts. See + * https://aka.ms/talangs for supported languages in Text Analytics API. * * @param textInputs A list of text to recognize linked entities for. * - * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link LinkedEntityResult linked entity} of the text. + * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link + * RecognizeLinkedEntitiesResult linked entity} of the text. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> recognizeLinkedEntities(List textInputs) { + public Mono> recognizeLinkedEntities( + List textInputs) { return recognizeLinkedEntitiesWithResponse(textInputs, defaultLanguage) .flatMap(FluxUtil::toMono); } /** - * Returns a list of recognized entities with links to a well-known knowledge base for the list of texts. - * See https://aka.ms/talangs for supported languages in Text Analytics API. + * Returns a list of recognized entities with links to a well-known knowledge base for the list of texts. See + * https://aka.ms/talangs for supported languages in Text Analytics API. * * @param textInputs A list of text to recognize linked entities for. * @param language The 2 letter ISO 639-1 representation of language for the text. If not set, uses "en" for * English as default. * - * @return A {@link Response} of {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link LinkedEntityResult linked entity}. + * @return A {@link Response} of {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link + * RecognizeLinkedEntitiesResult linked entity}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono>> recognizeLinkedEntitiesWithResponse( + public Mono>> recognizeLinkedEntitiesWithResponse( List textInputs, String language) { try { return withContext(context -> recognizeLinkedEntitiesWithResponse(textInputs, language, context)); @@ -620,7 +653,7 @@ public Mono>> recognizeLin } } - Mono>> recognizeLinkedEntitiesWithResponse( + Mono>> recognizeLinkedEntitiesWithResponse( List textInputs, String language, Context context) { List documentInputs = mapByIndex(textInputs, (index, value) -> new TextDocumentInput(index, value, language)); @@ -628,35 +661,37 @@ Mono>> recognizeLinkedEnti } /** - * Returns a list of recognized entities with links to a well-known knowledge base for the list of inputs. - * See https://aka.ms/talangs for supported languages in Text Analytics API. + * Returns a list of recognized entities with links to a well-known knowledge base for the list of inputs. See + * https://aka.ms/talangs for supported languages in Text Analytics API. * * @param textInputs A list of {@link TextDocumentInput inputs/documents} to recognize linked entities for. * - * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link LinkedEntityResult linked entity}. + * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link + * RecognizeLinkedEntitiesResult linked entity}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> recognizeBatchLinkedEntities( + public Mono> recognizeBatchLinkedEntities( List textInputs) { return recognizeBatchLinkedEntitiesWithResponse(textInputs, null).flatMap(FluxUtil::toMono); } /** - * Returns a list of recognized entities with links to a well-known knowledge base for the list of inputs. - * See https://aka.ms/talangs for supported languages in Text Analytics API. + * Returns a list of recognized entities with links to a well-known knowledge base for the list of inputs. See + * https://aka.ms/talangs for supported languages in Text Analytics API. * * @param textInputs A list of {@link TextDocumentInput inputs/documents} to recognize linked entities for. * @param options The {@link TextAnalyticsRequestOptions options} to configure the scoring model for documents * and show statistics. * - * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the - * {@link DocumentResultCollection batch} of {@link LinkedEntityResult linked entity}. + * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the {@link + * DocumentResultCollection batch} of {@link RecognizeLinkedEntitiesResult linked entity}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono>> recognizeBatchLinkedEntitiesWithResponse( + public Mono>> recognizeBatchLinkedEntitiesWithResponse( List textInputs, TextAnalyticsRequestOptions options) { try { return withContext(context -> recognizeBatchLinkedEntitiesWithResponse(textInputs, options, context)); @@ -665,9 +700,9 @@ public Mono>> recognizeBat } } - Mono>> recognizeBatchLinkedEntitiesWithResponse( + Mono>> recognizeBatchLinkedEntitiesWithResponse( List textInputs, TextAnalyticsRequestOptions options, Context context) { - final MultiLanguageBatchInput batchInput = new MultiLanguageBatchInput().setDocuments(textInputs); + final MultiLanguageBatchInput batchInput = new MultiLanguageBatchInput().setDocuments(convertToMultiLanguageInput(textInputs)); return service.entitiesLinkingWithRestResponseAsync( batchInput, options == null ? null : options.getModelVersion(), @@ -678,60 +713,60 @@ Mono>> recognizeBatchLinke .map(response -> new SimpleResponse<>(response, toDocumentResultCollection(response.getValue()))); } - private DocumentResultCollection toDocumentResultCollection( + private DocumentResultCollection toDocumentResultCollection( final EntityLinkingResult entityLinkingResult) { return new DocumentResultCollection<>(getDocumentLinkedEntities(entityLinkingResult), - entityLinkingResult.getModelVersion(), entityLinkingResult.getStatistics()); - } - - private List getDocumentLinkedEntities(final EntityLinkingResult entitiesResult) { - Stream validDocumentList = entitiesResult.getDocuments().stream() - .map(this::convertToLinkedEntityResult); - Stream errorDocumentList = entitiesResult.getErrors().stream() - .map(this::convertToErrorLinkedEntityResult); - - return Stream.concat(validDocumentList, errorDocumentList).collect(Collectors.toList()); + entityLinkingResult.getModelVersion(), mapBatchStatistics(entityLinkingResult.getStatistics())); } - private LinkedEntityResult convertToLinkedEntityResult(final DocumentLinkedEntities documentLinkedEntities) { - return new LinkedEntityResult(documentLinkedEntities.getId(), documentLinkedEntities.getStatistics(), - null, documentLinkedEntities.getEntities()); + private List getDocumentLinkedEntities(final EntityLinkingResult entitiesResult) { + List validDocumentList = new ArrayList<>(); + for (DocumentLinkedEntities documentLinkedEntities : entitiesResult.getDocuments()) { + validDocumentList.add(new RecognizeLinkedEntitiesResult(documentLinkedEntities.getId(), convertToTextDocumentStatistics(documentLinkedEntities.getStatistics()), + null, mapLinkedEntity(documentLinkedEntities.getEntities()))); + } + List errorDocumentList = new ArrayList<>(); + for (DocumentError documentError : entitiesResult.getErrors()) { + final Error serviceError = convertToError(documentError.getError()); + final Error error = new Error().setCode(serviceError.getCode()).setMessage(serviceError.getMessage()) + .setTarget(serviceError.getTarget()); + errorDocumentList.add(new RecognizeLinkedEntitiesResult(documentError.getId(), null, error, null)); + } + return Stream.concat(validDocumentList.stream(), errorDocumentList.stream()).collect(Collectors.toList()); } - private LinkedEntityResult convertToErrorLinkedEntityResult(final DocumentError documentError) { - final Error serviceError = documentError.getError(); - final Error error = new Error().setCode(serviceError.getCode()).setMessage(serviceError.getMessage()) - .setTarget(serviceError.getTarget()); - return new LinkedEntityResult(documentError.getId(), null, error, null); - } // Key Phrases + /** * Returns a list of strings denoting the key phrases in the input text. * * @param text the text to be analyzed. - * @return A {@link Mono} containing the {@link KeyPhraseResult key phrases} of the text. + * + * @return A {@link Mono} containing the {@link ExtractKeyPhraseResult key phrases} of the text. + * * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono extractKeyPhrases(String text) { + public Mono extractKeyPhrases(String text) { return extractKeyPhrasesWithResponse(text, defaultLanguage).flatMap(FluxUtil::toMono); } /** - * Returns a list of strings denoting the key phrases in the input text. - * See https://aka.ms/talangs for the list of enabled languages. + * Returns a list of strings denoting the key phrases in the input text. See https://aka.ms/talangs for the list of + * enabled languages. * * @param text the text to be analyzed. * @param language The 2 letter ISO 639-1 representation of language for the text. If not set, uses "en" for * English as default. * - * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} has the - * {@link KeyPhraseResult key phrases} of the text. + * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} has the {@link + * ExtractKeyPhraseResult key phrases} of the text. + * * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> extractKeyPhrasesWithResponse(String text, String language) { + public Mono> extractKeyPhrasesWithResponse(String text, String language) { try { return withContext(context -> extractKeyPhrasesWithResponse(text, language, context)); } catch (RuntimeException ex) { @@ -739,17 +774,14 @@ public Mono> extractKeyPhrasesWithResponse(String text } } - Mono> extractKeyPhrasesWithResponse(String text, String language, Context context) { + Mono> extractKeyPhrasesWithResponse(String text, String language, + Context context) { return extractBatchKeyPhrasesWithResponse( Arrays.asList(new TextDocumentInput(Integer.toString(0), text, language)), null, context) - .flatMap(response -> { - Iterator responseItem = response.getValue().iterator(); - if (responseItem.hasNext()) { - return Mono.just(new SimpleResponse<>(response, responseItem.next())); - } - return monoError(logger, - new RuntimeException("Unable to extract key phrases for the provided text.")); - }); + .flatMap(response -> { + Iterator responseItem = response.getValue().iterator(); + return Mono.just(new SimpleResponse<>(response, responseItem.next())); + }); } /** @@ -757,29 +789,31 @@ Mono> extractKeyPhrasesWithResponse(String text, Strin * * @param textInputs A list of text to be analyzed. * - * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link KeyPhraseResult key phrases} of the text. + * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link ExtractKeyPhraseResult + * key phrases} of the text. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> extractKeyPhrases(List textInputs) { + public Mono> extractKeyPhrases(List textInputs) { return extractKeyPhrasesWithResponse(textInputs, defaultLanguage).flatMap(FluxUtil::toMono); } /** - * Returns a list of strings denoting the key phrases in the input text. - * See https://aka.ms/talangs for the list of enabled languages. + * Returns a list of strings denoting the key phrases in the input text. See https://aka.ms/talangs for the list of + * enabled languages. * * @param textInputs A list of text to be analyzed. * @param language The 2 letter ISO 639-1 representation of language for the text. If not set, uses "en" for * English as default. * - * @return A {@link Response} of {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link KeyPhraseResult key phrases}. + * @return A {@link Response} of {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link + * ExtractKeyPhraseResult key phrases}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono>> extractKeyPhrasesWithResponse( + public Mono>> extractKeyPhrasesWithResponse( List textInputs, String language) { try { return withContext(context -> extractKeyPhrasesWithResponse(textInputs, language, context)); @@ -788,7 +822,7 @@ public Mono>> extractKeyPhras } } - Mono>> extractKeyPhrasesWithResponse( + Mono>> extractKeyPhrasesWithResponse( List textInputs, String language, Context context) { List documentInputs = mapByIndex(textInputs, (index, value) -> new TextDocumentInput(index, value, language)); @@ -800,29 +834,32 @@ Mono>> extractKeyPhrasesWithR * * @param textInputs A list of {@link TextDocumentInput inputs/documents} to be analyzed. * - * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link KeyPhraseResult key phrases}. + * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link ExtractKeyPhraseResult + * key phrases}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> extractBatchKeyPhrases(List textInputs) { + public Mono> extractBatchKeyPhrases( + List textInputs) { return extractBatchKeyPhrasesWithResponse(textInputs, null).flatMap(FluxUtil::toMono); } /** - * Returns a list of strings denoting the key phrases in the input text. - * See https://aka.ms/talangs for the list of enabled languages. + * Returns a list of strings denoting the key phrases in the input text. See https://aka.ms/talangs for the list of + * enabled languages. * * @param textInputs A list of {@link TextDocumentInput inputs/documents} to be analyzed. * @param options The {@link TextAnalyticsRequestOptions options} to configure the scoring model for documents * and show statistics. * - * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the - * {@link DocumentResultCollection batch} of {@link KeyPhraseResult key phrases}. + * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the {@link + * DocumentResultCollection batch} of {@link ExtractKeyPhraseResult key phrases}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono>> extractBatchKeyPhrasesWithResponse( + public Mono>> extractBatchKeyPhrasesWithResponse( List textInputs, TextAnalyticsRequestOptions options) { try { return withContext(context -> extractBatchKeyPhrasesWithResponse(textInputs, options, context)); @@ -831,9 +868,9 @@ public Mono>> extractBatchKey } } - Mono>> extractBatchKeyPhrasesWithResponse( - List document, TextAnalyticsRequestOptions options, Context context) { - final MultiLanguageBatchInput batchInput = new MultiLanguageBatchInput().setDocuments(document); + Mono>> extractBatchKeyPhrasesWithResponse( + List documents, TextAnalyticsRequestOptions options, Context context) { + final MultiLanguageBatchInput batchInput = new MultiLanguageBatchInput().setDocuments(convertToMultiLanguageInput(documents)); return service.keyPhrasesWithRestResponseAsync( batchInput, options == null ? null : options.getModelVersion(), @@ -844,42 +881,41 @@ Mono>> extractBatchKeyPhrases .map(response -> new SimpleResponse<>(response, toDocumentResultCollection(response.getValue()))); } - private DocumentResultCollection toDocumentResultCollection( + private DocumentResultCollection toDocumentResultCollection( final com.azure.ai.textanalytics.implementation.models.KeyPhraseResult keyPhraseResult) { - return new DocumentResultCollection<>(getDocumentNamedEntities(keyPhraseResult), - keyPhraseResult.getModelVersion(), keyPhraseResult.getStatistics()); + return new DocumentResultCollection<>(getKeyPhraseResults(keyPhraseResult), + keyPhraseResult.getModelVersion(), mapBatchStatistics(keyPhraseResult.getStatistics())); } - private List getDocumentNamedEntities( + private List getKeyPhraseResults( final com.azure.ai.textanalytics.implementation.models.KeyPhraseResult keyPhraseResult) { - Stream validDocumentList = keyPhraseResult.getDocuments().stream() - .map(this::convertToKeyPhraseResult); - Stream errorDocumentList = keyPhraseResult.getErrors().stream() - .map(this::convertToErrorKeyPhraseResult); - - return Stream.concat(validDocumentList, errorDocumentList).collect(Collectors.toList()); - } - - private KeyPhraseResult convertToKeyPhraseResult(final DocumentKeyPhrases documentKeyPhrases) { - return new KeyPhraseResult(documentKeyPhrases.getId(), documentKeyPhrases.getStatistics(), null, - documentKeyPhrases.getKeyPhrases()); - } + List validDocumentList = new ArrayList<>(); + for (DocumentKeyPhrases documentKeyPhrases : keyPhraseResult.getDocuments()) { + validDocumentList.add(new ExtractKeyPhraseResult(documentKeyPhrases.getId(), + convertToTextDocumentStatistics(documentKeyPhrases.getStatistics()), null, + documentKeyPhrases.getKeyPhrases())); + } + List errorDocumentList = new ArrayList<>(); - private KeyPhraseResult convertToErrorKeyPhraseResult(final DocumentError documentError) { - final Error serviceError = documentError.getError(); - final Error error = new Error().setCode(serviceError.getCode()).setMessage(serviceError.getMessage()) - .setTarget(serviceError.getTarget()); - return new KeyPhraseResult(documentError.getId(), null, error, null); + for (DocumentError documentError : keyPhraseResult.getErrors()) { + final Error serviceError = convertToError(documentError.getError()); + final Error error = new Error().setCode(serviceError.getCode()).setMessage(serviceError.getMessage()) + .setTarget(serviceError.getTarget()); + errorDocumentList.add(new ExtractKeyPhraseResult(documentError.getId(), null, error, null)); + } + return Stream.concat(validDocumentList.stream(), errorDocumentList.stream()).collect(Collectors.toList()); } // Sentiment /** - * Returns a sentiment prediction, as well as sentiment scores for each sentiment class - * (Positive, Negative, and Neutral) for the document and each sentence within i + * Returns a sentiment prediction, as well as sentiment scores for each sentiment class (Positive, Negative, and + * Neutral) for the document and each sentence within i * * @param text the text to be analyzed. + * * @return A {@link Mono} containing the {@link TextSentimentResult text sentiment} of the text. + * * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -888,15 +924,16 @@ public Mono analyzeSentiment(String text) { } /** - * Returns a sentiment prediction, as well as sentiment scores for each sentiment class - * (Positive, Negative, and Neutral) for the document and each sentence within i + * Returns a sentiment prediction, as well as sentiment scores for each sentiment class (Positive, Negative, and + * Neutral) for the document and each sentence within i * * @param text the text to be analyzed. * @param language The 2 letter ISO 639-1 representation of language for the text. If not set, uses "en" for * English as default. * - * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} has the - * {@link TextSentimentResult text sentiment} of the text. + * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} has the {@link + * TextSentimentResult text sentiment} of the text. + * * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -911,24 +948,21 @@ public Mono> analyzeSentimentWithResponse(String t Mono> analyzeSentimentWithResponse(String text, String language, Context context) { return analyzeBatchSentimentWithResponse( Arrays.asList(new TextDocumentInput(Integer.toString(0), text, language)), null, context) - .flatMap(response -> { - Iterator responseItem = response.getValue().iterator(); - if (responseItem.hasNext()) { - return Mono.just(new SimpleResponse<>(response, responseItem.next())); - } - return monoError(logger, - new RuntimeException("Unable to analyze sentiment for the provided text.")); - }); + .flatMap(response -> { + Iterator responseItem = response.getValue().iterator(); + return Mono.just(new SimpleResponse<>(response, responseItem.next())); + }); } /** - * Returns a sentiment prediction, as well as sentiment scores for each sentiment class - * (Positive, Negative, and Neutral) for the document and each sentence within it. + * Returns a sentiment prediction, as well as sentiment scores for each sentiment class (Positive, Negative, and + * Neutral) for the document and each sentence within it. * * @param textInputs A list of text to be analyzed. * - * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link TextSentimentResult text sentiment} of the text. + * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link TextSentimentResult + * text sentiment} of the text. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -937,15 +971,16 @@ public Mono> analyzeSentiment(List } /** - * Returns a sentiment prediction, as well as sentiment scores for each sentiment class - * (Positive, Negative, and Neutral) for the document and each sentence within it. + * Returns a sentiment prediction, as well as sentiment scores for each sentiment class (Positive, Negative, and + * Neutral) for the document and each sentence within it. * * @param textInputs A list of text to be analyzed. * @param language The 2 letter ISO 639-1 representation of language for the text. If not set, uses "en" for * English as default. * - * @return A {@link Response} of {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link TextSentimentResult text sentiment}. + * @return A {@link Response} of {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link + * TextSentimentResult text sentiment}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -966,13 +1001,14 @@ Mono>> analyzeSentimentWi } /** - * Returns a sentiment prediction, as well as sentiment scores for each sentiment class - * (Positive, Negative, and Neutral) for the document and each sentence within it. + * Returns a sentiment prediction, as well as sentiment scores for each sentiment class (Positive, Negative, and + * Neutral) for the document and each sentence within it. * * @param textInputs A list of {@link TextDocumentInput inputs/documents} to be analyzed. * - * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the - * {@link TextSentimentResult text sentiment}. + * @return A {@link Mono} containing the {@link DocumentResultCollection batch} of the {@link TextSentimentResult + * text sentiment}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -982,15 +1018,16 @@ public Mono> analyzeBatchSentiment } /** - * Returns a sentiment prediction, as well as sentiment scores for each sentiment class - * (Positive, Negative, and Neutral) for the document and each sentence within it. + * Returns a sentiment prediction, as well as sentiment scores for each sentiment class (Positive, Negative, and + * Neutral) for the document and each sentence within it. * * @param textInputs A list of {@link TextDocumentInput inputs/documents} to be analyzed. * @param options The {@link TextAnalyticsRequestOptions options} to configure the scoring model for documents * and show statistics. * - * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the - * {@link DocumentResultCollection batch} of {@link TextSentimentResult text sentiment}. + * @return A {@link Mono} containing a {@link Response} whose {@link Response#getValue() value} contains the {@link + * DocumentResultCollection batch} of {@link TextSentimentResult text sentiment}. + * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -1004,8 +1041,8 @@ public Mono>> analyzeBatc } Mono>> analyzeBatchSentimentWithResponse( - List document, TextAnalyticsRequestOptions options, Context context) { - final MultiLanguageBatchInput batchInput = new MultiLanguageBatchInput().setDocuments(document); + List documents, TextAnalyticsRequestOptions options, Context context) { + final MultiLanguageBatchInput batchInput = new MultiLanguageBatchInput().setDocuments(convertToMultiLanguageInput(documents)); return service.sentimentWithRestResponseAsync( batchInput, options == null ? null : options.getModelVersion(), @@ -1016,28 +1053,28 @@ Mono>> analyzeBatchSentim .map(response -> new SimpleResponse<>(response, toDocumentResultCollection(response.getValue()))); } - /** - * Get default country hint code. - * - * @return the default country hint code - */ - public String getDefaultCountryHint() { - return defaultCountryHint; + private List convertToLanguageInput(List textInputs) { + List languageInputList = new ArrayList<>(); + for (DetectLanguageInput detectLanguageInput : textInputs) { + languageInputList.add(new LanguageInput().setId(detectLanguageInput.getId()) + .setText(detectLanguageInput.getText()).setCountryHint(detectLanguageInput.getCountryHint())); + } + return languageInputList; } - /** - * Get default language when the builder is setup. - * - * @return the default language - */ - public String getDefaultLanguage() { - return defaultLanguage; + private List convertToMultiLanguageInput(List textInputs) { + List multiLanguageInputs = new ArrayList<>(); + for (TextDocumentInput textDocumentInput : textInputs) { + multiLanguageInputs.add(new MultiLanguageInput().setId(textDocumentInput.getId()) + .setText(textDocumentInput.getText()).setLanguage(textDocumentInput.getLanguage())); + } + return multiLanguageInputs; } private DocumentResultCollection toDocumentResultCollection( final SentimentResponse sentimentResponse) { return new DocumentResultCollection<>(getDocumentTextSentiment(sentimentResponse), - sentimentResponse.getModelVersion(), sentimentResponse.getStatistics()); + sentimentResponse.getModelVersion(), mapBatchStatistics(sentimentResponse.getStatistics())); } private List getDocumentTextSentiment(final SentimentResponse sentimentResponse) { @@ -1063,7 +1100,7 @@ private TextSentimentResult convertToTextSentimentResult(final DocumentSentiment final List sentenceSentimentTexts = convertToSentenceSentiments(documentSentiment.getSentences()); - return new TextSentimentResult(documentSentiment.getId(), documentSentiment.getStatistics(), null, + return new TextSentimentResult(documentSentiment.getId(), convertToTextDocumentStatistics(documentSentiment.getStatistics()), null, new TextSentiment(documentSentimentClass, sentimentScores[0], sentimentScores[1], sentimentScores[2], sentenceSentimentTexts.stream().mapToInt(TextSentiment::getLength).sum(), 0), sentenceSentimentTexts); @@ -1129,7 +1166,7 @@ private TextSentimentClass convertToTextSentimentClass(final String sentiment) { } private TextSentimentResult convertToErrorTextSentimentResult(final DocumentError documentError) { - final Error serviceError = documentError.getError(); + final Error serviceError = convertToError(documentError.getError()); final Error error = new Error().setCode(serviceError.getCode()).setMessage(serviceError.getMessage()) .setTarget(serviceError.getTarget()); return new TextSentimentResult(documentError.getId(), null, error, null, @@ -1145,8 +1182,8 @@ private TextSentimentResult convertToErrorTextSentimentResult(final DocumentErro */ private DocumentResultCollection toDocumentResultCollection( final LanguageResult languageResult) { - return new DocumentResultCollection<>(getDocumentLanguages(languageResult), languageResult.getModelVersion(), - languageResult.getStatistics()); + return new DocumentResultCollection(getDocumentLanguages(languageResult), languageResult.getModelVersion(), + mapBatchStatistics(languageResult.getStatistics())); } /** @@ -1156,15 +1193,17 @@ private DocumentResultCollection toDocumentResultCollectio * * @return the combined error and document list. */ - private static List getDocumentLanguages(final LanguageResult languageResult) { + private List getDocumentLanguages(final LanguageResult languageResult) { List validDocumentList = new ArrayList<>(); - for (DocumentLanguage documentLanguage: languageResult.getDocuments()) { - validDocumentList.add(new DetectLanguageResult(documentLanguage.getId(), documentLanguage.getStatistics(), - null, documentLanguage.getDetectedLanguages().get(0), documentLanguage.getDetectedLanguages())); + for (DocumentLanguage documentLanguage : languageResult.getDocuments()) { + validDocumentList.add(new DetectLanguageResult(documentLanguage.getId(), + convertToTextDocumentStatistics(documentLanguage.getStatistics()), + null, setPrimaryLanguage(documentLanguage.getDetectedLanguages()), + convertToDetectLanguages(documentLanguage.getDetectedLanguages()))); } List errorDocumentList = new ArrayList<>(); - for (DocumentError documentError: languageResult.getErrors()) { - Error serviceError = documentError.getError(); + for (DocumentError documentError : languageResult.getErrors()) { + Error serviceError = convertToError(documentError.getError()); Error error = new Error().setCode(serviceError.getCode()).setMessage(serviceError.getMessage()) .setTarget(serviceError.getTarget()); errorDocumentList.add(new DetectLanguageResult(documentError.getId(), null, error, null, @@ -1173,31 +1212,122 @@ private static List getDocumentLanguages(final LanguageRes return Stream.concat(validDocumentList.stream(), errorDocumentList.stream()).collect(Collectors.toList()); } - private DocumentResultCollection toDocumentResultCollection( + private List convertToDetectLanguages( + List detectedLanguages) { + List detectedLanguagesList = new ArrayList<>(); + for (com.azure.ai.textanalytics.implementation.models.DetectedLanguage detectedLanguage : detectedLanguages) { + detectedLanguagesList.add(new DetectedLanguage().setName(detectedLanguage.getName()) + .setIso6391Name(detectedLanguage.getIso6391Name()).setScore(detectedLanguage.getScore())); + } + return detectedLanguagesList; + } + + private DetectedLanguage setPrimaryLanguage( + List detectedLanguages) { + if (detectedLanguages.size() > 1) { + com.azure.ai.textanalytics.implementation.models.DetectedLanguage detectedLanguageResult = detectedLanguages.get(0); + return new DetectedLanguage().setName(detectedLanguageResult.getName()) + .setIso6391Name(detectedLanguageResult.getIso6391Name()).setScore(detectedLanguageResult.getScore()); + } + return null; + } + + private TextDocumentBatchStatistics mapBatchStatistics(RequestStatistics statistics) { + return new TextDocumentBatchStatistics().setDocumentCount(statistics.getDocumentsCount()) + .setErroneousDocumentCount(statistics.getErroneousDocumentsCount()) + .setTransactionCount(statistics.getTransactionsCount()) + .setValidDocumentCount(statistics.getValidDocumentsCount()); + } + + private DocumentResultCollection toDocumentResultCollection( final EntitiesResult entitiesResult) { return new DocumentResultCollection<>(getDocumentNamedEntities(entitiesResult), - entitiesResult.getModelVersion(), entitiesResult.getStatistics()); + entitiesResult.getModelVersion(), mapBatchStatistics(entitiesResult.getStatistics())); } - private List getDocumentNamedEntities(final EntitiesResult entitiesResult) { - List validDocumentList = new ArrayList<>(); - for (DocumentEntities documentEntities: entitiesResult.getDocuments()) { - validDocumentList.add(new NamedEntityResult(documentEntities.getId(), documentEntities.getStatistics(), - null, documentEntities.getEntities())); + private List getDocumentNamedEntities(final EntitiesResult entitiesResult) { + List validDocumentList = new ArrayList<>(); + for (DocumentEntities documentEntities : entitiesResult.getDocuments()) { + validDocumentList.add(new RecognizeEntitiesResult(documentEntities.getId(), convertToTextDocumentStatistics(documentEntities.getStatistics()), + null, mapToNamedEntities(documentEntities.getEntities()))); } - List errorDocumentList = new ArrayList<>(); - for (DocumentError documentError: entitiesResult.getErrors()) { - final Error serviceError = documentError.getError(); + List errorDocumentList = new ArrayList<>(); + for (DocumentError documentError : entitiesResult.getErrors()) { + final Error serviceError = convertToError(documentError.getError()); final Error error = new Error().setCode(serviceError.getCode()).setMessage(serviceError.getMessage()) .setTarget(serviceError.getTarget()); - errorDocumentList.add(new NamedEntityResult(documentError.getId(), null, error, null)); + errorDocumentList.add(new RecognizeEntitiesResult(documentError.getId(), null, error, null)); } return Stream.concat(validDocumentList.stream(), errorDocumentList.stream()).collect(Collectors.toList()); } + private List mapToNamedEntities(List entities) { + List namedEntityList = new ArrayList<>(); + for (Entity entity : entities) { + namedEntityList.add(new NamedEntity().setScore(entity.getScore()).setSubtype(entity.getSubtype()) + .setType(entity.getType()).setLength(entity.getLength()).setOffset(entity.getOffset()) + .setText(entity.getText())); + } + return namedEntityList; + } + private static List mapByIndex(List textInputs, BiFunction mappingFunction) { return IntStream.range(0, textInputs.size()) .mapToObj(index -> mappingFunction.apply(String.valueOf(index), textInputs.get(index))) .collect(Collectors.toList()); } + + private TextDocumentStatistics convertToTextDocumentStatistics(DocumentStatistics statistics) { + return new TextDocumentStatistics().setCharacterCount(statistics.getCharactersCount()).setTransactionCount(statistics.getTransactionsCount()); + } + + private List mapLinkedEntity(List linkedEntities) { + List linkedEntitiesList = new ArrayList<>(); + for (LinkedEntity linkedEntity : linkedEntities) { + linkedEntitiesList.add(new com.azure.ai.textanalytics.models.LinkedEntity().setDataSource(linkedEntity.getDataSource()).setId(linkedEntity.getId()).setLanguage(linkedEntity.getLanguage()).setName(linkedEntity.getName()).setLinkedEntityMatches(mapLinkedEntityMatches(linkedEntity.getMatches())).setUrl(linkedEntity.getUrl())); + } + return linkedEntitiesList; + } + + private List mapLinkedEntityMatches(List matches) { + List linkedEntityMatchesList = new ArrayList<>(); + for (Match match : matches) { + linkedEntityMatchesList.add(new LinkedEntityMatch().setScore(match.getScore()).setLength(match.getLength()).setText(match.getText()).setOffset(match.getOffset())); + } + return linkedEntityMatchesList; + } + + private Error convertToError(TextAnalyticsError textAnalyticsError) { + return new Error().setCode(textAnalyticsError.getCode().toString()).setMessage(textAnalyticsError.getMessage()).setTarget(textAnalyticsError.getTarget()).setDetails(setErrors(textAnalyticsError.getDetails())).setInnerError(mapInnerError(textAnalyticsError.getInnerError())); + } + + private InnerError mapInnerError(com.azure.ai.textanalytics.implementation.models.InnerError innerError) { + return new InnerError().setCode(innerError.getCode().toString()).setInnererror(mapInnerError(innerError.getInnerError())).setMessage(innerError.getMessage()).setTarget(innerError.getTarget()); + } + + private List setErrors(List details) { + List detailsList = new ArrayList<>(); + for (TextAnalyticsError error : details) { + detailsList.add(new Error().setCode(error.getCode().toString()).setMessage(error.getMessage()).setTarget(error.getTarget()).setDetails(setErrors(error.getDetails())).setInnerError(mapInnerError(error.getInnerError()))); + } + return detailsList; + } + + /** + * Get default country hint code. + * + * @return the default country hint code + */ + public String getDefaultCountryHint() { + return defaultCountryHint; + } + + /** + * Get default language when the builder is setup. + * + * @return the default language + */ + public String getDefaultLanguage() { + return defaultLanguage; + } } 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 5970ef21640c8..2677adaed753c 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 @@ -6,9 +6,9 @@ import com.azure.ai.textanalytics.models.DetectLanguageInput; import com.azure.ai.textanalytics.models.DetectLanguageResult; import com.azure.ai.textanalytics.models.DocumentResultCollection; -import com.azure.ai.textanalytics.models.KeyPhraseResult; -import com.azure.ai.textanalytics.models.LinkedEntityResult; -import com.azure.ai.textanalytics.models.NamedEntityResult; +import com.azure.ai.textanalytics.models.ExtractKeyPhraseResult; +import com.azure.ai.textanalytics.models.RecognizeLinkedEntitiesResult; +import com.azure.ai.textanalytics.models.RecognizeEntitiesResult; import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions; import com.azure.ai.textanalytics.models.TextDocumentInput; import com.azure.ai.textanalytics.models.TextSentimentResult; @@ -167,11 +167,11 @@ public Response> detectBatchLangu * * @param text the text to recognize entities for. * - * @return the {@link NamedEntityResult named entity} of the text. + * @return the {@link RecognizeEntitiesResult named entity} of the text. * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public NamedEntityResult recognizeEntities(String text) { + public RecognizeEntitiesResult recognizeEntities(String text) { return recognizeEntitiesWithResponse(text, defaultLanguage, Context.NONE).getValue(); } @@ -184,11 +184,11 @@ public NamedEntityResult recognizeEntities(String text) { * @param language The 2 letter ISO 639-1 representation of language. If not set, uses "en" for English as default. * @param context Additional context that is passed through the Http pipeline during the service call. * - * @return A {@link Response} containing the {@link NamedEntityResult named entity} of the text. + * @return A {@link Response} containing the {@link RecognizeEntitiesResult named entity} of the text. * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response recognizeEntitiesWithResponse(String text, String language, Context context) { + public Response recognizeEntitiesWithResponse(String text, String language, Context context) { return client.recognizeEntitiesWithResponse(text, language, context).block(); } @@ -198,11 +198,11 @@ public Response recognizeEntitiesWithResponse(String text, St * @param textInputs A list of texts to recognize entities for. * * @return A {@link DocumentResultCollection batch} containing the list of - * {@link NamedEntityResult named entity} of the text. + * {@link RecognizeEntitiesResult named entity} of the text. * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public DocumentResultCollection recognizeEntities(List textInputs) { + public DocumentResultCollection recognizeEntities(List textInputs) { return recognizeEntitiesWithResponse(textInputs, defaultLanguage, Context.NONE).getValue(); } @@ -214,11 +214,11 @@ public DocumentResultCollection recognizeEntities(List> recognizeEntitiesWithResponse( + public Response> recognizeEntitiesWithResponse( List textInputs, String language, Context context) { return client.recognizeEntitiesWithResponse(textInputs, language, context).block(); } @@ -228,11 +228,11 @@ public Response> recognizeEntitiesWi * * @param textInputs A list of {@link TextDocumentInput inputs/documents} to recognize entities for. * - * @return A {@link DocumentResultCollection batch} of the {@link NamedEntityResult named entity}. + * @return A {@link DocumentResultCollection batch} of the {@link RecognizeEntitiesResult named entity}. * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public DocumentResultCollection recognizeBatchEntities(List textInputs) { + public DocumentResultCollection recognizeBatchEntities(List textInputs) { return recognizeBatchEntitiesWithResponse(textInputs, null, Context.NONE).getValue(); } @@ -245,11 +245,11 @@ public DocumentResultCollection recognizeBatchEntities(List> recognizeBatchEntitiesWithResponse( + public Response> recognizeBatchEntitiesWithResponse( List textInputs, TextAnalyticsRequestOptions options, Context context) { return client.recognizeBatchEntitiesWithResponse(textInputs, options, context).block(); } @@ -261,12 +261,12 @@ public Response> recognizeBatchEntit * See https://aka.ms/talangs for the list of enabled languages. * * @param text the text to recognize pii entities for. - * @return A {@link NamedEntityResult PII entity} of the text. + * @return A {@link RecognizeEntitiesResult PII entity} of the text. * * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public NamedEntityResult recognizePiiEntities(String text) { + public RecognizeEntitiesResult recognizePiiEntities(String text) { return recognizePiiEntitiesWithResponse(text, defaultLanguage, Context.NONE).getValue(); } @@ -280,12 +280,12 @@ public NamedEntityResult recognizePiiEntities(String text) { * English as default. * @param context Additional context that is passed through the Http pipeline during the service call. * - * @return A {@link Response} whose {@link Response#getValue() value} has the {@link NamedEntityResult named entity} + * @return A {@link Response} whose {@link Response#getValue() value} has the {@link RecognizeEntitiesResult named entity} * of the text. * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response recognizePiiEntitiesWithResponse(String text, String language, Context context) { + public Response recognizePiiEntitiesWithResponse(String text, String language, Context context) { return client.recognizePiiEntitiesWithResponse(text, language, context).block(); } @@ -296,11 +296,11 @@ public Response recognizePiiEntitiesWithResponse(String text, * * @param textInputs A list of text to recognize pii entities for. * - * @return A {@link DocumentResultCollection batch} of the {@link NamedEntityResult named entity} of the text. + * @return A {@link DocumentResultCollection batch} of the {@link RecognizeEntitiesResult named entity} of the text. * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public DocumentResultCollection recognizePiiEntities(List textInputs) { + public DocumentResultCollection recognizePiiEntities(List textInputs) { return recognizePiiEntitiesWithResponse(textInputs, defaultLanguage, Context.NONE).getValue(); } @@ -315,11 +315,11 @@ public DocumentResultCollection recognizePiiEntities(List> recognizePiiEntitiesWithResponse( + public Response> recognizePiiEntitiesWithResponse( List textInputs, String language, Context context) { return client.recognizePiiEntitiesWithResponse(textInputs, language, context).block(); } @@ -331,11 +331,11 @@ public Response> recognizePiiEntitie * * @param textInputs A list of {@link TextDocumentInput inputs/documents} to recognize pii entities for. * - * @return A {@link DocumentResultCollection batch} of the {@link NamedEntityResult named entity}. + * @return A {@link DocumentResultCollection batch} of the {@link RecognizeEntitiesResult named entity}. * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public DocumentResultCollection recognizeBatchPiiEntities(List textInputs) { + public DocumentResultCollection recognizeBatchPiiEntities(List textInputs) { return recognizeBatchPiiEntitiesWithResponse(textInputs, null, Context.NONE).getValue(); } @@ -350,11 +350,11 @@ public DocumentResultCollection recognizeBatchPiiEntities(Lis * @param context Additional context that is passed through the Http pipeline during the service call. * * @return A {@link Response} whose {@link Response#getValue() value} contains the - * {@link DocumentResultCollection batch} of {@link NamedEntityResult named entity}. + * {@link DocumentResultCollection batch} of {@link RecognizeEntitiesResult named entity}. * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response> recognizeBatchPiiEntitiesWithResponse( + public Response> recognizeBatchPiiEntitiesWithResponse( List textInputs, TextAnalyticsRequestOptions options, Context context) { return client.recognizeBatchPiiEntitiesWithResponse(textInputs, options, context).block(); } @@ -367,11 +367,11 @@ public Response> recognizeBatchPiiEn * * @param text the text to recognize linked entities for. * - * @return A {@link LinkedEntityResult linked entity} of the text. + * @return A {@link RecognizeLinkedEntitiesResult linked entity} of the text. * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public LinkedEntityResult recognizeLinkedEntities(String text) { + public RecognizeLinkedEntitiesResult recognizeLinkedEntities(String text) { return recognizeLinkedEntitiesWithResponse(text, defaultLanguage, Context.NONE).getValue(); } @@ -385,11 +385,11 @@ public LinkedEntityResult recognizeLinkedEntities(String text) { * @param context Additional context that is passed through the Http pipeline during the service call. * * @return A {@link Response} whose {@link Response#getValue() value} has the - * {@link LinkedEntityResult named entity} of the text. + * {@link RecognizeLinkedEntitiesResult named entity} of the text. * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response recognizeLinkedEntitiesWithResponse(String text, String language, + public Response recognizeLinkedEntitiesWithResponse(String text, String language, Context context) { return client.recognizeLinkedEntitiesWithResponse(text, language, context).block(); } @@ -400,11 +400,11 @@ public Response recognizeLinkedEntitiesWithResponse(String t * * @param textInputs A list of text to recognize linked entities for. * - * @return A {@link DocumentResultCollection batch} of the {@link LinkedEntityResult linked entity} of the text. + * @return A {@link DocumentResultCollection batch} of the {@link RecognizeLinkedEntitiesResult linked entity} of the text. * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public DocumentResultCollection recognizeLinkedEntities(List textInputs) { + public DocumentResultCollection recognizeLinkedEntities(List textInputs) { return recognizeLinkedEntitiesWithResponse(textInputs, defaultLanguage, Context.NONE).getValue(); } @@ -418,11 +418,11 @@ public DocumentResultCollection recognizeLinkedEntities(List * @param context Additional context that is passed through the Http pipeline during the service call. * * @return A {@link Response} containing the {@link DocumentResultCollection batch} of the - * {@link LinkedEntityResult linked entity}. + * {@link RecognizeLinkedEntitiesResult linked entity}. * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response> recognizeLinkedEntitiesWithResponse( + public Response> recognizeLinkedEntitiesWithResponse( List textInputs, String language, Context context) { return client.recognizeLinkedEntitiesWithResponse(textInputs, language, context).block(); } @@ -433,11 +433,11 @@ public Response> recognizeLinkedEnt * * @param textInputs A list of {@link TextDocumentInput inputs/documents} to recognize linked entities for. * - * @return A {@link DocumentResultCollection batch} of the {@link LinkedEntityResult linked entity}. + * @return A {@link DocumentResultCollection batch} of the {@link RecognizeLinkedEntitiesResult linked entity}. * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public DocumentResultCollection recognizeBatchLinkedEntities( + public DocumentResultCollection recognizeBatchLinkedEntities( List textInputs) { return recognizeBatchLinkedEntitiesWithResponse(textInputs, null, Context.NONE).getValue(); } @@ -452,11 +452,11 @@ public DocumentResultCollection recognizeBatchLinkedEntities * @param context Additional context that is passed through the Http pipeline during the service call. * * @return A {@link Response} whose {@link Response#getValue() value} contains the - * {@link DocumentResultCollection batch} of {@link LinkedEntityResult linked entity}. + * {@link DocumentResultCollection batch} of {@link RecognizeLinkedEntitiesResult linked entity}. * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response> recognizeBatchLinkedEntitiesWithResponse( + public Response> recognizeBatchLinkedEntitiesWithResponse( List textInputs, TextAnalyticsRequestOptions options, Context context) { return client.recognizeBatchLinkedEntitiesWithResponse(textInputs, options, context).block(); } @@ -468,11 +468,11 @@ public Response> recognizeBatchLink * * @param text the text to be analyzed. * - * @return A {@link KeyPhraseResult key phrases} of the text. + * @return A {@link ExtractKeyPhraseResult key phrases} of the text. * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public KeyPhraseResult extractKeyPhrases(String text) { + public ExtractKeyPhraseResult extractKeyPhrases(String text) { return extractKeyPhrasesWithResponse(text, defaultLanguage, Context.NONE).getValue(); } @@ -485,12 +485,12 @@ public KeyPhraseResult extractKeyPhrases(String text) { * English as default. * @param context Additional context that is passed through the Http pipeline during the service call. * - * @return A {@link Response} whose {@link Response#getValue() value} has the {@link KeyPhraseResult key phrases} + * @return A {@link Response} whose {@link Response#getValue() value} has the {@link ExtractKeyPhraseResult key phrases} * of the text. * @throws NullPointerException if {@code text} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response extractKeyPhrasesWithResponse(String text, String language, Context context) { + public Response extractKeyPhrasesWithResponse(String text, String language, Context context) { return client.extractKeyPhrasesWithResponse(text, language, context).block(); } @@ -498,12 +498,12 @@ public Response extractKeyPhrasesWithResponse(String text, Stri * Returns a list of strings denoting the key phrases in the input text. * * @param textInputs A list of text to be analyzed. - * @return A {@link DocumentResultCollection batch} of the {@link KeyPhraseResult key phrases} of the text. + * @return A {@link DocumentResultCollection batch} of the {@link ExtractKeyPhraseResult key phrases} of the text. * * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public DocumentResultCollection extractKeyPhrases(List textInputs) { + public DocumentResultCollection extractKeyPhrases(List textInputs) { return extractKeyPhrasesWithResponse(textInputs, defaultLanguage, Context.NONE).getValue(); } @@ -517,11 +517,11 @@ public DocumentResultCollection extractKeyPhrases(List * @param context Additional context that is passed through the Http pipeline during the service call. * * @return A {@link Response} containing the {@link DocumentResultCollection batch} of the - * {@link KeyPhraseResult key phrases}. + * {@link ExtractKeyPhraseResult key phrases}. * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response> extractKeyPhrasesWithResponse( + public Response> extractKeyPhrasesWithResponse( List textInputs, String language, Context context) { return client.extractKeyPhrasesWithResponse(textInputs, language, context).block(); } @@ -531,11 +531,11 @@ public Response> extractKeyPhrasesWith * * @param textInputs A list of {@link TextDocumentInput inputs/documents} to be analyzed. * - * @return A {@link DocumentResultCollection batch} of the {@link KeyPhraseResult key phrases}. + * @return A {@link DocumentResultCollection batch} of the {@link ExtractKeyPhraseResult key phrases}. * @throws NullPointerException if {@code textInputs} is {@code null}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public DocumentResultCollection extractBatchKeyPhrases(List textInputs) { + public DocumentResultCollection extractBatchKeyPhrases(List textInputs) { return extractBatchKeyPhrasesWithResponse(textInputs, null, Context.NONE).getValue(); } @@ -549,11 +549,11 @@ public DocumentResultCollection extractBatchKeyPhrases(List> extractBatchKeyPhrasesWithResponse( + public Response> extractBatchKeyPhrasesWithResponse( List textInputs, TextAnalyticsRequestOptions options, Context context) { return client.extractBatchKeyPhrasesWithResponse(textInputs, options, context).block(); } diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/DocumentResultCollection.java b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/DocumentResultCollection.java index f831a57bd9609..0e58389fab32a 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/DocumentResultCollection.java +++ b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/DocumentResultCollection.java @@ -15,7 +15,7 @@ public class DocumentResultCollection extends IterableStream { private final String modelVersion; - private final TextBatchStatistics statistics; + private final TextDocumentBatchStatistics statistics; /** * Create a document result collection @@ -24,7 +24,7 @@ public class DocumentResultCollection extends IterableStream { * @param modelVersion model version * @param statistics Text batch statistics */ - public DocumentResultCollection(Iterable iterable, String modelVersion, TextBatchStatistics statistics) { + public DocumentResultCollection(Iterable iterable, String modelVersion, TextDocumentBatchStatistics statistics) { super(iterable); this.modelVersion = modelVersion; this.statistics = statistics; @@ -44,7 +44,7 @@ public String getModelVersion() { * * @return the statistics of the batch documents */ - public TextBatchStatistics getStatistics() { + public TextDocumentBatchStatistics getStatistics() { return statistics; } } diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/Error.java b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/Error.java index 6922055e1bfd1..496b1f36a7049 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/Error.java +++ b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/Error.java @@ -37,7 +37,7 @@ public final class Error { * Inner error contains more specific information. */ @JsonProperty(value = "innererror") - private InnerError innererror; + private InnerError innerError; /* * Details about specific errors that led to this reported error. @@ -115,19 +115,19 @@ public Error setTarget(String target) { * * @return the innererror value. */ - public InnerError getInnererror() { - return this.innererror; + public InnerError getInnerError() { + return this.innerError; } /** * Set the innererror property: Inner error contains more specific * information. * - * @param innererror the innererror value to set. + * @param innerError the innererror value to set. * @return the Error object itself. */ - public Error setInnererror(InnerError innererror) { - this.innererror = innererror; + public Error setInnerError(InnerError innerError) { + this.innerError = innerError; return this; } diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/KeyPhraseResult.java b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/ExtractKeyPhraseResult.java similarity index 81% rename from sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/KeyPhraseResult.java rename to sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/ExtractKeyPhraseResult.java index 5929bf10c63b7..f124922481eda 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/KeyPhraseResult.java +++ b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/ExtractKeyPhraseResult.java @@ -8,10 +8,10 @@ import java.util.List; /** - * The KeyPhraseResult model. + * The ExtractKeyPhraseResult model. */ @Immutable -public final class KeyPhraseResult extends DocumentResult { +public final class ExtractKeyPhraseResult extends DocumentResult { private final List keyPhrases; /** @@ -22,7 +22,7 @@ public final class KeyPhraseResult extends DocumentResult { * @param error the document error. * @param keyPhrases a list of key phrases string */ - public KeyPhraseResult(String id, TextDocumentStatistics textDocumentStatistics, Error error, + public ExtractKeyPhraseResult(String id, TextDocumentStatistics textDocumentStatistics, Error error, List keyPhrases) { super(id, textDocumentStatistics, error); this.keyPhrases = keyPhrases; diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/NamedEntityResult.java b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/RecognizeEntitiesResult.java similarity index 74% rename from sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/NamedEntityResult.java rename to sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/RecognizeEntitiesResult.java index 394ef367e5c8c..aa0154a872710 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/NamedEntityResult.java +++ b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/RecognizeEntitiesResult.java @@ -8,21 +8,21 @@ import java.util.List; /** - * The NamedEntityResult model. + * The RecognizeEntitiesResult model. */ @Immutable -public final class NamedEntityResult extends DocumentResult { +public final class RecognizeEntitiesResult extends DocumentResult { private final List namedEntities; /** - * Creates a {@code NamedEntityResult} model that describes recognized entities result + * Creates a {@code RecognizeEntitiesResult} model that describes recognized entities result * * @param id unique, non-empty document identifier * @param textDocumentStatistics text document statistics * @param error the document error * @param namedEntities a list of {@link NamedEntity} */ - public NamedEntityResult(String id, TextDocumentStatistics textDocumentStatistics, Error error, + public RecognizeEntitiesResult(String id, TextDocumentStatistics textDocumentStatistics, Error error, List namedEntities) { super(id, textDocumentStatistics, error); this.namedEntities = namedEntities; diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/LinkedEntityResult.java b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/RecognizeLinkedEntitiesResult.java similarity index 71% rename from sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/LinkedEntityResult.java rename to sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/RecognizeLinkedEntitiesResult.java index f366695caf26e..dec40530216d1 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/LinkedEntityResult.java +++ b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/RecognizeLinkedEntitiesResult.java @@ -8,21 +8,21 @@ import java.util.List; /** - * The LinkedEntityResult model. + * The RecognizeLinkedEntitiesResult model. */ @Immutable -public final class LinkedEntityResult extends DocumentResult { +public final class RecognizeLinkedEntitiesResult extends DocumentResult { private final List linkedEntities; /** - * Creates a {@code LinkedEntityResult} model that describes recognized linked entities result + * Creates a {@code RecognizeLinkedEntitiesResult} model that describes recognized linked entities result * * @param id unique, non-empty document identifier * @param textDocumentStatistics text document statistics * @param error the document error * @param linkedEntities a list of linked entities */ - public LinkedEntityResult(String id, TextDocumentStatistics textDocumentStatistics, Error error, + public RecognizeLinkedEntitiesResult(String id, TextDocumentStatistics textDocumentStatistics, Error error, List linkedEntities) { super(id, textDocumentStatistics, error); this.linkedEntities = linkedEntities; diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/RecognizePiiEntitiesResult.java b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/RecognizePiiEntitiesResult.java new file mode 100644 index 0000000000000..6af4d2b810aa2 --- /dev/null +++ b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/RecognizePiiEntitiesResult.java @@ -0,0 +1,39 @@ +// 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 java.util.List; + +/** + * The RecognizePiiEntitiesResult model. + */ +@Immutable +public final class RecognizePiiEntitiesResult extends DocumentResult { + private final List namedEntities; + + /** + * Creates a {@code RecognizePiiEntitiesResult} model that describes recognized entities result + * + * @param id unique, non-empty document identifier + * @param textDocumentStatistics text document statistics + * @param error the document error + * @param namedEntities a list of {@link NamedEntity} + */ + public RecognizePiiEntitiesResult(String id, TextDocumentStatistics textDocumentStatistics, Error error, + List namedEntities) { + super(id, textDocumentStatistics, error); + this.namedEntities = namedEntities; + } + + /** + * Get a list of named entities string + * + * @return a list of {@link NamedEntity} + */ + public List getNamedEntities() { + return namedEntities; + } +} diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/TextBatchStatistics.java b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/TextDocumentBatchStatistics.java similarity index 90% rename from sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/TextBatchStatistics.java rename to sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/TextDocumentBatchStatistics.java index c4155fd4ff1fa..0df40116b6141 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/TextBatchStatistics.java +++ b/sdk/textanalytics/azure-ai-textanalytics/src/main/java/com/azure/ai/textanalytics/models/TextDocumentBatchStatistics.java @@ -12,7 +12,7 @@ * information about the request payload. */ @Fluent -public final class TextBatchStatistics { +public final class TextDocumentBatchStatistics { /* * Number of documents submitted in the request. */ @@ -56,7 +56,7 @@ public int getDocumentCount() { * @param documentCount the documentCount value to set. * @return the TextBatchStatistics object itself. */ - public TextBatchStatistics setDocumentCount(int documentCount) { + public TextDocumentBatchStatistics setDocumentCount(int documentCount) { this.documentCount = documentCount; return this; } @@ -78,7 +78,7 @@ public int getValidDocumentCount() { * @param validDocumentCount the validDocumentCount value to set. * @return the TextBatchStatistics object itself. */ - public TextBatchStatistics setValidDocumentCount(int validDocumentCount) { + public TextDocumentBatchStatistics setValidDocumentCount(int validDocumentCount) { this.validDocumentCount = validDocumentCount; return this; } @@ -102,7 +102,7 @@ public int getErroneousDocumentCount() { * @param erroneousDocumentCount the erroneousDocumentCount value to set. * @return the TextBatchStatistics object itself. */ - public TextBatchStatistics setErroneousDocumentCount(int erroneousDocumentCount) { + public TextDocumentBatchStatistics setErroneousDocumentCount(int erroneousDocumentCount) { this.erroneousDocumentCount = erroneousDocumentCount; return this; } @@ -124,7 +124,7 @@ public long getTransactionCount() { * @param transactionCount the transactionCount value to set. * @return the TextBatchStatistics object itself. */ - public TextBatchStatistics setTransactionCount(long transactionCount) { + public TextDocumentBatchStatistics setTransactionCount(long transactionCount) { this.transactionCount = transactionCount; return this; } diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/AnalyzeSentimentBatchDocuments.java b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/AnalyzeSentimentBatchDocuments.java index fc6327f62fa2e..82248c4bd13fb 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/AnalyzeSentimentBatchDocuments.java +++ b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/AnalyzeSentimentBatchDocuments.java @@ -7,7 +7,7 @@ import com.azure.ai.textanalytics.TextAnalyticsClientBuilder; import com.azure.ai.textanalytics.models.DocumentResultCollection; import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions; -import com.azure.ai.textanalytics.models.TextBatchStatistics; +import com.azure.ai.textanalytics.models.TextDocumentBatchStatistics; import com.azure.ai.textanalytics.models.TextDocumentInput; import com.azure.ai.textanalytics.models.TextSentiment; import com.azure.ai.textanalytics.models.TextSentimentResult; @@ -42,7 +42,7 @@ public static void main(String[] args) { DocumentResultCollection detectedBatchResult = client.analyzeBatchSentimentWithResponse(inputs, requestOptions, Context.NONE).getValue(); System.out.printf("Model version: %s%n", detectedBatchResult.getModelVersion()); - final TextBatchStatistics batchStatistics = detectedBatchResult.getStatistics(); + final TextDocumentBatchStatistics batchStatistics = detectedBatchResult.getStatistics(); System.out.printf("A batch of document statistics, document count: %s, erroneous document count: %s, transaction count: %s, valid document count: %s.%n", batchStatistics.getDocumentCount(), batchStatistics.getErroneousDocumentCount(), diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/DetectLanguageBatchDocuments.java b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/DetectLanguageBatchDocuments.java index 9620eb838ae97..fbf76134e5f7b 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/DetectLanguageBatchDocuments.java +++ b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/DetectLanguageBatchDocuments.java @@ -10,7 +10,7 @@ import com.azure.ai.textanalytics.models.DetectedLanguage; import com.azure.ai.textanalytics.models.DocumentResultCollection; import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions; -import com.azure.ai.textanalytics.models.TextBatchStatistics; +import com.azure.ai.textanalytics.models.TextDocumentBatchStatistics; import com.azure.core.util.Context; import java.util.Arrays; @@ -42,7 +42,7 @@ public static void main(String[] args) { final DocumentResultCollection detectedBatchResult = client.detectBatchLanguagesWithResponse(inputs, requestOptions, Context.NONE).getValue(); System.out.printf("Model version: %s%n", detectedBatchResult.getModelVersion()); - final TextBatchStatistics batchStatistics = detectedBatchResult.getStatistics(); + final TextDocumentBatchStatistics batchStatistics = detectedBatchResult.getStatistics(); System.out.printf("Batch statistics, document count: %s, erroneous document count: %s, transaction count: %s, valid document count: %s.%n", batchStatistics.getDocumentCount(), batchStatistics.getErroneousDocumentCount(), diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/ExtractKeyPhrasesBatchDocuments.java b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/ExtractKeyPhrasesBatchDocuments.java index 333712785c99b..4ba8ed1233daf 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/ExtractKeyPhrasesBatchDocuments.java +++ b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/ExtractKeyPhrasesBatchDocuments.java @@ -6,9 +6,9 @@ import com.azure.ai.textanalytics.TextAnalyticsClient; import com.azure.ai.textanalytics.TextAnalyticsClientBuilder; import com.azure.ai.textanalytics.models.DocumentResultCollection; -import com.azure.ai.textanalytics.models.KeyPhraseResult; +import com.azure.ai.textanalytics.models.ExtractKeyPhraseResult; import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions; -import com.azure.ai.textanalytics.models.TextBatchStatistics; +import com.azure.ai.textanalytics.models.TextDocumentBatchStatistics; import com.azure.ai.textanalytics.models.TextDocumentInput; import com.azure.core.util.Context; @@ -38,10 +38,10 @@ public static void main(String[] args) { ); final TextAnalyticsRequestOptions requestOptions = new TextAnalyticsRequestOptions().setShowStatistics(true); - final DocumentResultCollection detectedBatchResult = client.extractBatchKeyPhrasesWithResponse(inputs, requestOptions, Context.NONE).getValue(); + final DocumentResultCollection detectedBatchResult = client.extractBatchKeyPhrasesWithResponse(inputs, requestOptions, Context.NONE).getValue(); System.out.printf("Model version: %s%n", detectedBatchResult.getModelVersion()); - final TextBatchStatistics batchStatistics = detectedBatchResult.getStatistics(); + final TextDocumentBatchStatistics batchStatistics = detectedBatchResult.getStatistics(); System.out.printf("A batch of document statistics, document count: %s, erroneous document count: %s, transaction count: %s, valid document count: %s.%n", batchStatistics.getDocumentCount(), batchStatistics.getErroneousDocumentCount(), @@ -49,8 +49,8 @@ public static void main(String[] args) { batchStatistics.getValidDocumentCount()); // Detecting key phrase for each of document from a batch of documents - for (KeyPhraseResult keyPhraseResult: detectedBatchResult) { - for (String keyPhrases : keyPhraseResult.getKeyPhrases()) { + for (ExtractKeyPhraseResult extractKeyPhraseResult : detectedBatchResult) { + for (String keyPhrases : extractKeyPhraseResult.getKeyPhrases()) { System.out.printf("Recognized Phrases: %s.%n", keyPhrases); } } diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizeEntitiesBatchDocuments.java b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizeEntitiesBatchDocuments.java index d24a4b29431f8..f9540371aa8b9 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizeEntitiesBatchDocuments.java +++ b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizeEntitiesBatchDocuments.java @@ -7,9 +7,9 @@ import com.azure.ai.textanalytics.TextAnalyticsClientBuilder; import com.azure.ai.textanalytics.models.DocumentResultCollection; import com.azure.ai.textanalytics.models.NamedEntity; -import com.azure.ai.textanalytics.models.NamedEntityResult; +import com.azure.ai.textanalytics.models.RecognizeEntitiesResult; import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions; -import com.azure.ai.textanalytics.models.TextBatchStatistics; +import com.azure.ai.textanalytics.models.TextDocumentBatchStatistics; import com.azure.ai.textanalytics.models.TextDocumentInput; import com.azure.core.util.Context; @@ -39,19 +39,19 @@ public static void main(String[] args) { ); final TextAnalyticsRequestOptions requestOptions = new TextAnalyticsRequestOptions().setShowStatistics(true); - final DocumentResultCollection detectedBatchResult = + final DocumentResultCollection detectedBatchResult = client.recognizeBatchEntitiesWithResponse(inputs, requestOptions, Context.NONE).getValue(); System.out.printf("Model version: %s%n", detectedBatchResult.getModelVersion()); - final TextBatchStatistics batchStatistics = detectedBatchResult.getStatistics(); + final TextDocumentBatchStatistics batchStatistics = detectedBatchResult.getStatistics(); System.out.printf("A batch of document statistics, document count: %s, erroneous document count: %s, transaction count: %s, valid document count: %s.%n", batchStatistics.getDocumentCount(), batchStatistics.getErroneousDocumentCount(), batchStatistics.getTransactionCount(), batchStatistics.getValidDocumentCount()); - for (NamedEntityResult namedEntityResult : detectedBatchResult) { - for (NamedEntity entity : namedEntityResult.getNamedEntities()) { + for (RecognizeEntitiesResult recognizeEntitiesResult : detectedBatchResult) { + for (NamedEntity entity : recognizeEntitiesResult.getNamedEntities()) { System.out.printf("Recognized NamedEntity: %s, NamedEntity Type: %s, NamedEntity Subtype: %s, Offset: %s, Length: %s, Score: %s.%n", entity.getText(), entity.getType(), diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizeLinkedEntitiesBatchDocuments.java b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizeLinkedEntitiesBatchDocuments.java index 1f986712f9b35..06b3528812407 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizeLinkedEntitiesBatchDocuments.java +++ b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizeLinkedEntitiesBatchDocuments.java @@ -7,9 +7,9 @@ import com.azure.ai.textanalytics.TextAnalyticsClientBuilder; import com.azure.ai.textanalytics.models.DocumentResultCollection; import com.azure.ai.textanalytics.models.LinkedEntity; -import com.azure.ai.textanalytics.models.LinkedEntityResult; +import com.azure.ai.textanalytics.models.RecognizeLinkedEntitiesResult; import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions; -import com.azure.ai.textanalytics.models.TextBatchStatistics; +import com.azure.ai.textanalytics.models.TextDocumentBatchStatistics; import com.azure.ai.textanalytics.models.TextDocumentInput; import com.azure.core.util.Context; @@ -39,10 +39,10 @@ public static void main(String[] args) { ); final TextAnalyticsRequestOptions requestOptions = new TextAnalyticsRequestOptions().setShowStatistics(true); - final DocumentResultCollection detectedBatchResult = client.recognizeBatchLinkedEntitiesWithResponse(inputs, requestOptions, Context.NONE).getValue(); + final DocumentResultCollection detectedBatchResult = client.recognizeBatchLinkedEntitiesWithResponse(inputs, requestOptions, Context.NONE).getValue(); System.out.printf("Model version: %s%n", detectedBatchResult.getModelVersion()); - final TextBatchStatistics batchStatistics = detectedBatchResult.getStatistics(); + final TextDocumentBatchStatistics batchStatistics = detectedBatchResult.getStatistics(); System.out.printf("A batch of document statistics, document count: %s, erroneous document count: %s, transaction count: %s, valid document count: %s.%n", batchStatistics.getDocumentCount(), batchStatistics.getErroneousDocumentCount(), @@ -50,7 +50,7 @@ public static void main(String[] args) { batchStatistics.getValidDocumentCount()); // Detecting linked entities from a batch of documents - for (LinkedEntityResult linkedEntityDocumentResult : detectedBatchResult) { + for (RecognizeLinkedEntitiesResult linkedEntityDocumentResult : detectedBatchResult) { for (LinkedEntity linkedEntity : linkedEntityDocumentResult.getLinkedEntities()) { System.out.printf("Recognized Linked NamedEntity: %s, URL: %s, Data Source: %s%n", linkedEntity.getName(), linkedEntity.getUri(), linkedEntity.getDataSource()); diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiBatchDocuments.java b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiBatchDocuments.java index 5accaa2af0f69..23f9f59e3abee 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiBatchDocuments.java +++ b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiBatchDocuments.java @@ -6,9 +6,9 @@ import com.azure.ai.textanalytics.TextAnalyticsClient; import com.azure.ai.textanalytics.TextAnalyticsClientBuilder; import com.azure.ai.textanalytics.models.DocumentResultCollection; -import com.azure.ai.textanalytics.models.NamedEntityResult; +import com.azure.ai.textanalytics.models.RecognizeEntitiesResult; import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions; -import com.azure.ai.textanalytics.models.TextBatchStatistics; +import com.azure.ai.textanalytics.models.TextDocumentBatchStatistics; import com.azure.ai.textanalytics.models.TextDocumentInput; import com.azure.core.util.Context; @@ -38,10 +38,10 @@ public static void main(String[] args) { ); final TextAnalyticsRequestOptions requestOptions = new TextAnalyticsRequestOptions().setShowStatistics(true); - final DocumentResultCollection detectedBatchResult = client.recognizeBatchPiiEntitiesWithResponse(inputs, requestOptions, Context.NONE).getValue(); + final DocumentResultCollection detectedBatchResult = client.recognizeBatchPiiEntitiesWithResponse(inputs, requestOptions, Context.NONE).getValue(); System.out.printf("Model version: %s%n", detectedBatchResult.getModelVersion()); - final TextBatchStatistics batchStatistics = detectedBatchResult.getStatistics(); + final TextDocumentBatchStatistics batchStatistics = detectedBatchResult.getStatistics(); System.out.printf("A batch of document statistics, document count: %s, erroneous document count: %s, transaction count: %s, valid document count: %s.%n", batchStatistics.getDocumentCount(), batchStatistics.getErroneousDocumentCount(), 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 2fa84d09e1b1b..4b4f162f4aab2 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 @@ -7,9 +7,9 @@ import com.azure.ai.textanalytics.models.Error; import com.azure.ai.textanalytics.models.LinkedEntity; import com.azure.ai.textanalytics.models.LinkedEntityMatch; -import com.azure.ai.textanalytics.models.LinkedEntityResult; +import com.azure.ai.textanalytics.models.RecognizeLinkedEntitiesResult; import com.azure.ai.textanalytics.models.NamedEntity; -import com.azure.ai.textanalytics.models.NamedEntityResult; +import com.azure.ai.textanalytics.models.RecognizeEntitiesResult; import com.azure.ai.textanalytics.models.TextSentiment; import com.azure.ai.textanalytics.models.TextSentimentClass; import com.azure.core.exception.HttpResponseException; @@ -146,9 +146,9 @@ public void detectLanguageDuplicateIdInput() { public void recognizeEntitiesForTextInput() { NamedEntity namedEntity1 = new NamedEntity().setText("Seattle").setType("Location").setOffset(26).setLength(7).setScore(0.80624294281005859); NamedEntity namedEntity2 = new NamedEntity().setText("last week").setType("DateTime").setSubtype("DateRange").setOffset(34).setLength(9).setScore(0.8); - NamedEntityResult namedEntityResultList = new NamedEntityResult("0", null, null, Arrays.asList(namedEntity1, namedEntity2)); + RecognizeEntitiesResult recognizeEntitiesResultList = new RecognizeEntitiesResult("0", null, null, Arrays.asList(namedEntity1, namedEntity2)); StepVerifier.create(client.recognizeEntities("I had a wonderful trip to Seattle last week.")) - .assertNext(response -> validateNamedEntities(namedEntityResultList.getNamedEntities(), response.getNamedEntities())) + .assertNext(response -> validateNamedEntities(recognizeEntitiesResultList.getNamedEntities(), response.getNamedEntities())) .verifyComplete(); } @@ -209,10 +209,10 @@ public void recognizeEntitiesForListLanguageHint() { public void recognizeLinkedEntitiesForTextInput() { LinkedEntityMatch linkedEntityMatch1 = new LinkedEntityMatch().setText("Seattle").setLength(7).setOffset(26).setScore(0.11472424095537814); LinkedEntity linkedEntity1 = new LinkedEntity().setName("Seattle").setUrl("https://en.wikipedia.org/wiki/Seattle").setDataSource("Wikipedia").setLinkedEntityMatches(Collections.singletonList(linkedEntityMatch1)).setLanguage("en").setId("Seattle"); - LinkedEntityResult linkedEntityResultList = new LinkedEntityResult("0", null, null, Collections.singletonList(linkedEntity1)); + RecognizeLinkedEntitiesResult recognizeLinkedEntitiesResultList = new RecognizeLinkedEntitiesResult("0", null, null, Collections.singletonList(linkedEntity1)); StepVerifier.create(client.recognizeLinkedEntities("I had a wonderful trip to Seattle last week.")) - .assertNext(response -> validateLinkedEntities(linkedEntityResultList.getLinkedEntities(), response.getLinkedEntities())) + .assertNext(response -> validateLinkedEntities(recognizeLinkedEntitiesResultList.getLinkedEntities(), response.getLinkedEntities())) .verifyComplete(); } @@ -271,10 +271,10 @@ public void recognizeLinkedEntitiesForListLanguageHint() { @Test public void recognizePiiEntitiesForTextInput() { NamedEntity namedEntity1 = new NamedEntity().setText("859-98-0987").setType("U.S. Social Security Number (SSN)").setSubtype("").setOffset(28).setLength(11).setScore(0.65); - NamedEntityResult namedEntityResultList = new NamedEntityResult("0", null, null, Collections.singletonList(namedEntity1)); + RecognizeEntitiesResult recognizeEntitiesResultList = new RecognizeEntitiesResult("0", null, null, Collections.singletonList(namedEntity1)); StepVerifier.create(client.recognizePiiEntities("Microsoft employee with ssn 859-98-0987 is using our awesome API's.")) - .assertNext(response -> validateNamedEntities(namedEntityResultList.getNamedEntities(), response.getNamedEntities())) + .assertNext(response -> validateNamedEntities(recognizeEntitiesResultList.getNamedEntities(), response.getNamedEntities())) .verifyComplete(); } 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 de661929c4c65..67287f6fc9cc7 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,9 +8,9 @@ import com.azure.ai.textanalytics.models.Error; import com.azure.ai.textanalytics.models.LinkedEntity; import com.azure.ai.textanalytics.models.LinkedEntityMatch; -import com.azure.ai.textanalytics.models.LinkedEntityResult; +import com.azure.ai.textanalytics.models.RecognizeLinkedEntitiesResult; import com.azure.ai.textanalytics.models.NamedEntity; -import com.azure.ai.textanalytics.models.NamedEntityResult; +import com.azure.ai.textanalytics.models.RecognizeEntitiesResult; import com.azure.core.exception.HttpResponseException; import com.azure.core.util.Context; import org.junit.jupiter.api.Disabled; @@ -141,8 +141,8 @@ public void detectLanguageDuplicateIdInput() { public void recognizeEntitiesForTextInput() { NamedEntity namedEntity1 = new NamedEntity().setText("Seattle").setType("Location").setOffset(26).setLength(7).setScore(0.80624294281005859); NamedEntity namedEntity2 = new NamedEntity().setText("last week").setType("DateTime").setSubtype("DateRange").setOffset(34).setLength(9).setScore(0.8); - NamedEntityResult namedEntityResultList = new NamedEntityResult("0", null, null, Arrays.asList(namedEntity1, namedEntity2)); - validateNamedEntities(namedEntityResultList.getNamedEntities(), + RecognizeEntitiesResult recognizeEntitiesResultList = new RecognizeEntitiesResult("0", null, null, Arrays.asList(namedEntity1, namedEntity2)); + validateNamedEntities(recognizeEntitiesResultList.getNamedEntities(), client.recognizeEntities("I had a wonderful trip to Seattle last week.").getNamedEntities()); } @@ -173,8 +173,8 @@ public void recognizeEntitiesForBatchInputShowStatistics() { @Test public void recognizePiiEntitiesForTextInput() { NamedEntity namedEntity1 = new NamedEntity().setText("859-98-0987").setType("U.S. Social Security Number (SSN)").setSubtype("").setOffset(28).setLength(11).setScore(0.65); - NamedEntityResult namedEntityResultList = new NamedEntityResult("0", null, null, Collections.singletonList(namedEntity1)); - validateNamedEntities(namedEntityResultList.getNamedEntities(), + RecognizeEntitiesResult recognizeEntitiesResultList = new RecognizeEntitiesResult("0", null, null, Collections.singletonList(namedEntity1)); + validateNamedEntities(recognizeEntitiesResultList.getNamedEntities(), client.recognizePiiEntities("Microsoft employee with ssn 859-98-0987 is using our awesome API's.").getNamedEntities()); } @@ -235,9 +235,9 @@ public void recognizeEntitiesForListLanguageHint() { public void recognizeLinkedEntitiesForTextInput() { LinkedEntityMatch linkedEntityMatch1 = new LinkedEntityMatch().setText("Seattle").setLength(7).setOffset(26).setScore(0.11472424095537814); LinkedEntity linkedEntity1 = new LinkedEntity().setName("Seattle").setUrl("https://en.wikipedia.org/wiki/Seattle").setDataSource("Wikipedia").setLinkedEntityMatches(Collections.singletonList(linkedEntityMatch1)).setLanguage("en").setId("Seattle"); - LinkedEntityResult linkedEntityResultList = new LinkedEntityResult("0", null, null, Collections.singletonList(linkedEntity1)); + RecognizeLinkedEntitiesResult recognizeLinkedEntitiesResultList = new RecognizeLinkedEntitiesResult("0", null, null, Collections.singletonList(linkedEntity1)); - validateLinkedEntities(linkedEntityResultList.getLinkedEntities(), client.recognizeLinkedEntities("I had a wonderful trip to Seattle last week.").getLinkedEntities()); + validateLinkedEntities(recognizeLinkedEntitiesResultList.getLinkedEntities(), client.recognizeLinkedEntities("I had a wonderful trip to Seattle last week.").getLinkedEntities()); } @Test 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 c5bc8edda0159..0cc496c8da987 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 @@ -8,14 +8,14 @@ import com.azure.ai.textanalytics.models.DetectedLanguage; import com.azure.ai.textanalytics.models.DocumentResultCollection; import com.azure.ai.textanalytics.models.Error; -import com.azure.ai.textanalytics.models.KeyPhraseResult; +import com.azure.ai.textanalytics.models.ExtractKeyPhraseResult; import com.azure.ai.textanalytics.models.LinkedEntity; import com.azure.ai.textanalytics.models.LinkedEntityMatch; -import com.azure.ai.textanalytics.models.LinkedEntityResult; +import com.azure.ai.textanalytics.models.RecognizeLinkedEntitiesResult; import com.azure.ai.textanalytics.models.NamedEntity; -import com.azure.ai.textanalytics.models.NamedEntityResult; +import com.azure.ai.textanalytics.models.RecognizeEntitiesResult; import com.azure.ai.textanalytics.models.TextAnalyticsRequestOptions; -import com.azure.ai.textanalytics.models.TextBatchStatistics; +import com.azure.ai.textanalytics.models.TextDocumentBatchStatistics; import com.azure.ai.textanalytics.models.TextDocumentInput; import com.azure.ai.textanalytics.models.TextDocumentStatistics; import com.azure.ai.textanalytics.models.TextSentiment; @@ -516,22 +516,22 @@ private void validateDocuments(DocumentResultCollection expectedResult, }); break; case NAMED_ENTITY: - final List namedEntityResults = expectedResult.stream() - .filter(element -> element instanceof NamedEntityResult) - .map(element -> (NamedEntityResult) element) + final List recognizeEntitiesResults = expectedResult.stream() + .filter(element -> element instanceof RecognizeEntitiesResult) + .map(element -> (RecognizeEntitiesResult) element) .collect(Collectors.toList()); - final List actualNamedEntityResults = actualResult.stream() - .filter(element -> element instanceof NamedEntityResult) - .map(element -> (NamedEntityResult) element) + final List actualRecognizeEntitiesResults = actualResult.stream() + .filter(element -> element instanceof RecognizeEntitiesResult) + .map(element -> (RecognizeEntitiesResult) element) .collect(Collectors.toList()); - assertEquals(namedEntityResults.size(), actualNamedEntityResults.size()); + assertEquals(recognizeEntitiesResults.size(), actualRecognizeEntitiesResults.size()); - actualNamedEntityResults.forEach(actualItem -> { - Optional optionalExpectedItem = namedEntityResults.stream().filter( + actualRecognizeEntitiesResults.forEach(actualItem -> { + Optional optionalExpectedItem = recognizeEntitiesResults.stream().filter( expectedEachItem -> actualItem.getId().equals(expectedEachItem.getId())).findFirst(); assertTrue(optionalExpectedItem.isPresent()); - NamedEntityResult expectedItem = optionalExpectedItem.get(); + RecognizeEntitiesResult expectedItem = optionalExpectedItem.get(); if (actualItem.getError() == null) { if (this.showStatistics) { validateDocumentStatistics(expectedItem.getStatistics(), actualItem.getStatistics()); @@ -541,22 +541,22 @@ private void validateDocuments(DocumentResultCollection expectedResult, }); break; case LINKED_ENTITY: - final List linkedEntityResults = expectedResult.stream() - .filter(element -> element instanceof LinkedEntityResult) - .map(element -> (LinkedEntityResult) element) + final List recognizeLinkedEntitiesResults = expectedResult.stream() + .filter(element -> element instanceof RecognizeLinkedEntitiesResult) + .map(element -> (RecognizeLinkedEntitiesResult) element) .collect(Collectors.toList()); - final List actualLinkedEntityResults = actualResult.stream() - .filter(element -> element instanceof LinkedEntityResult) - .map(element -> (LinkedEntityResult) element) + final List actualRecognizeLinkedEntitiesResults = actualResult.stream() + .filter(element -> element instanceof RecognizeLinkedEntitiesResult) + .map(element -> (RecognizeLinkedEntitiesResult) element) .collect(Collectors.toList()); - assertEquals(linkedEntityResults.size(), actualLinkedEntityResults.size()); + assertEquals(recognizeLinkedEntitiesResults.size(), actualRecognizeLinkedEntitiesResults.size()); - actualLinkedEntityResults.forEach(actualItem -> { - Optional optionalExpectedItem = linkedEntityResults.stream().filter( + actualRecognizeLinkedEntitiesResults.forEach(actualItem -> { + Optional optionalExpectedItem = recognizeLinkedEntitiesResults.stream().filter( expectedEachItem -> actualItem.getId().equals(expectedEachItem.getId())).findFirst(); assertTrue(optionalExpectedItem.isPresent()); - LinkedEntityResult expectedItem = optionalExpectedItem.get(); + RecognizeLinkedEntitiesResult expectedItem = optionalExpectedItem.get(); if (actualItem.getError() == null) { if (this.showStatistics) { validateDocumentStatistics(expectedItem.getStatistics(), actualItem.getStatistics()); @@ -566,22 +566,22 @@ private void validateDocuments(DocumentResultCollection expectedResult, }); break; case KEY_PHRASES: - final List keyPhraseResults = expectedResult.stream() - .filter(element -> element instanceof KeyPhraseResult) - .map(element -> (KeyPhraseResult) element) + final List extractKeyPhraseResults = expectedResult.stream() + .filter(element -> element instanceof ExtractKeyPhraseResult) + .map(element -> (ExtractKeyPhraseResult) element) .collect(Collectors.toList()); - final List actualKeyPhraseResults = actualResult.stream() - .filter(element -> element instanceof KeyPhraseResult) - .map(element -> (KeyPhraseResult) element) + final List actualExtractKeyPhraseResults = actualResult.stream() + .filter(element -> element instanceof ExtractKeyPhraseResult) + .map(element -> (ExtractKeyPhraseResult) element) .collect(Collectors.toList()); - assertEquals(keyPhraseResults.size(), actualKeyPhraseResults.size()); + assertEquals(extractKeyPhraseResults.size(), actualExtractKeyPhraseResults.size()); - actualKeyPhraseResults.forEach(actualItem -> { - Optional optionalExpectedItem = keyPhraseResults.stream().filter( + actualExtractKeyPhraseResults.forEach(actualItem -> { + Optional optionalExpectedItem = extractKeyPhraseResults.stream().filter( expectedEachItem -> actualItem.getId().equals(expectedEachItem.getId())).findFirst(); assertTrue(optionalExpectedItem.isPresent()); - KeyPhraseResult expectedItem = optionalExpectedItem.get(); + ExtractKeyPhraseResult expectedItem = optionalExpectedItem.get(); if (actualItem.getError() == null) { if (this.showStatistics) { validateDocumentStatistics(expectedItem.getStatistics(), actualItem.getStatistics()); @@ -633,8 +633,8 @@ private void validateDocuments(DocumentResultCollection expectedResult, * @param expectedStatistics the expected value for TextBatchStatistics. * @param actualStatistics the value returned by API. */ - private static void validateBatchStatistics(TextBatchStatistics expectedStatistics, - TextBatchStatistics actualStatistics) { + private static void validateBatchStatistics(TextDocumentBatchStatistics expectedStatistics, + TextDocumentBatchStatistics actualStatistics) { assertEquals(expectedStatistics.getDocumentCount(), actualStatistics.getDocumentCount()); assertEquals(expectedStatistics.getErroneousDocumentCount(), actualStatistics.getErroneousDocumentCount()); assertEquals(expectedStatistics.getValidDocumentCount(), actualStatistics.getValidDocumentCount()); @@ -684,7 +684,7 @@ static void validateErrorDocument(Error expectedError, Error actualError) { assertEquals(expectedError.getCode(), actualError.getCode()); assertEquals(expectedError.getMessage(), actualError.getMessage()); assertEquals(expectedError.getTarget(), actualError.getTarget()); - assertEquals(expectedError.getInnererror(), actualError.getInnererror()); + assertEquals(expectedError.getInnerError(), actualError.getInnerError()); } /** @@ -873,13 +873,13 @@ static DocumentResultCollection getExpectedBatchDetectedLa DetectLanguageResult detectLanguageResult2 = new DetectLanguageResult("1", textDocumentStatistics2, null, detectedLanguage2, detectedLanguageList2); DetectLanguageResult detectLanguageResult3 = new DetectLanguageResult("2", textDocumentStatistics3, null, detectedLanguage3, detectedLanguageList3); - TextBatchStatistics textBatchStatistics = new TextBatchStatistics().setDocumentCount(3).setErroneousDocumentCount(0).setTransactionCount(3).setValidDocumentCount(3); + TextDocumentBatchStatistics textDocumentBatchStatistics = new TextDocumentBatchStatistics().setDocumentCount(3).setErroneousDocumentCount(0).setTransactionCount(3).setValidDocumentCount(3); List detectLanguageResultList = Arrays.asList(detectLanguageResult1, detectLanguageResult2, detectLanguageResult3); - return new DocumentResultCollection<>(detectLanguageResultList, MODEL_VERSION, textBatchStatistics); + return new DocumentResultCollection<>(detectLanguageResultList, MODEL_VERSION, textDocumentBatchStatistics); } - static DocumentResultCollection getExpectedBatchNamedEntities() { + static DocumentResultCollection getExpectedBatchNamedEntities() { NamedEntity namedEntity1 = new NamedEntity().setText("Seattle").setType("Location").setOffset(26).setLength(7).setScore(0.80624294281005859); NamedEntity namedEntity2 = new NamedEntity().setText("last week").setType("DateTime").setSubtype("DateRange").setOffset(34).setLength(9).setScore(0.8); NamedEntity namedEntity3 = new NamedEntity().setText("Microsoft").setType("Organization").setOffset(10).setLength(9).setScore(0.99983596801757812); @@ -890,16 +890,16 @@ static DocumentResultCollection getExpectedBatchNamedEntities TextDocumentStatistics textDocumentStatistics1 = new TextDocumentStatistics().setCharacterCount(44).setTransactionCount(1); TextDocumentStatistics textDocumentStatistics2 = new TextDocumentStatistics().setCharacterCount(20).setTransactionCount(1); - NamedEntityResult namedEntityResult1 = new NamedEntityResult("0", textDocumentStatistics1, null, namedEntityList1); - NamedEntityResult namedEntityResult2 = new NamedEntityResult("1", textDocumentStatistics2, null, namedEntityList2); + RecognizeEntitiesResult recognizeEntitiesResult1 = new RecognizeEntitiesResult("0", textDocumentStatistics1, null, namedEntityList1); + RecognizeEntitiesResult recognizeEntitiesResult2 = new RecognizeEntitiesResult("1", textDocumentStatistics2, null, namedEntityList2); - TextBatchStatistics textBatchStatistics = new TextBatchStatistics().setDocumentCount(2).setErroneousDocumentCount(0).setTransactionCount(2).setValidDocumentCount(2); - List namedEntityResultList = Arrays.asList(namedEntityResult1, namedEntityResult2); + TextDocumentBatchStatistics textDocumentBatchStatistics = new TextDocumentBatchStatistics().setDocumentCount(2).setErroneousDocumentCount(0).setTransactionCount(2).setValidDocumentCount(2); + List recognizeEntitiesResultList = Arrays.asList(recognizeEntitiesResult1, recognizeEntitiesResult2); - return new DocumentResultCollection<>(namedEntityResultList, MODEL_VERSION, textBatchStatistics); + return new DocumentResultCollection<>(recognizeEntitiesResultList, MODEL_VERSION, textDocumentBatchStatistics); } - static DocumentResultCollection getExpectedBatchPiiEntities() { + static DocumentResultCollection getExpectedBatchPiiEntities() { NamedEntity namedEntity1 = new NamedEntity().setText("859-98-0987").setType("U.S. Social Security Number (SSN)").setSubtype("").setOffset(28).setLength(11).setScore(0.65); NamedEntity namedEntity2 = new NamedEntity().setText("111000025").setType("ABA Routing Number").setSubtype("").setOffset(18).setLength(9).setScore(0.75); @@ -909,16 +909,16 @@ static DocumentResultCollection getExpectedBatchPiiEntities() TextDocumentStatistics textDocumentStatistics1 = new TextDocumentStatistics().setCharacterCount(67).setTransactionCount(1); TextDocumentStatistics textDocumentStatistics2 = new TextDocumentStatistics().setCharacterCount(105).setTransactionCount(1); - NamedEntityResult namedEntityResult1 = new NamedEntityResult("0", textDocumentStatistics1, null, namedEntityList1); - NamedEntityResult namedEntityResult2 = new NamedEntityResult("1", textDocumentStatistics2, null, namedEntityList2); + RecognizeEntitiesResult recognizeEntitiesResult1 = new RecognizeEntitiesResult("0", textDocumentStatistics1, null, namedEntityList1); + RecognizeEntitiesResult recognizeEntitiesResult2 = new RecognizeEntitiesResult("1", textDocumentStatistics2, null, namedEntityList2); - TextBatchStatistics textBatchStatistics = new TextBatchStatistics().setDocumentCount(2).setErroneousDocumentCount(0).setTransactionCount(2).setValidDocumentCount(2); - List namedEntityResultList = Arrays.asList(namedEntityResult1, namedEntityResult2); + TextDocumentBatchStatistics textDocumentBatchStatistics = new TextDocumentBatchStatistics().setDocumentCount(2).setErroneousDocumentCount(0).setTransactionCount(2).setValidDocumentCount(2); + List recognizeEntitiesResultList = Arrays.asList(recognizeEntitiesResult1, recognizeEntitiesResult2); - return new DocumentResultCollection<>(namedEntityResultList, MODEL_VERSION, textBatchStatistics); + return new DocumentResultCollection<>(recognizeEntitiesResultList, MODEL_VERSION, textDocumentBatchStatistics); } - static DocumentResultCollection getExpectedBatchLinkedEntities() { + static DocumentResultCollection getExpectedBatchLinkedEntities() { LinkedEntityMatch linkedEntityMatch1 = new LinkedEntityMatch().setText("Seattle").setLength(7).setOffset(26).setScore(0.11472424095537814); LinkedEntityMatch linkedEntityMatch2 = new LinkedEntityMatch().setText("Microsoft").setLength(9).setOffset(10).setScore(0.18693659716732069); @@ -944,29 +944,29 @@ static DocumentResultCollection getExpectedBatchLinkedEntiti TextDocumentStatistics textDocumentStatistics1 = new TextDocumentStatistics().setCharacterCount(44).setTransactionCount(1); TextDocumentStatistics textDocumentStatistics2 = new TextDocumentStatistics().setCharacterCount(20).setTransactionCount(1); - LinkedEntityResult linkedEntityResult1 = new LinkedEntityResult("0", textDocumentStatistics1, null, linkedEntityList1); - LinkedEntityResult linkedEntityResult2 = new LinkedEntityResult("1", textDocumentStatistics2, null, linkedEntityList2); + RecognizeLinkedEntitiesResult recognizeLinkedEntitiesResult1 = new RecognizeLinkedEntitiesResult("0", textDocumentStatistics1, null, linkedEntityList1); + RecognizeLinkedEntitiesResult recognizeLinkedEntitiesResult2 = new RecognizeLinkedEntitiesResult("1", textDocumentStatistics2, null, linkedEntityList2); - TextBatchStatistics textBatchStatistics = new TextBatchStatistics().setDocumentCount(2).setErroneousDocumentCount(0).setTransactionCount(2).setValidDocumentCount(2); - List linkedEntityResultList = Arrays.asList(linkedEntityResult1, linkedEntityResult2); + TextDocumentBatchStatistics textDocumentBatchStatistics = new TextDocumentBatchStatistics().setDocumentCount(2).setErroneousDocumentCount(0).setTransactionCount(2).setValidDocumentCount(2); + List recognizeLinkedEntitiesResultList = Arrays.asList(recognizeLinkedEntitiesResult1, recognizeLinkedEntitiesResult2); - return new DocumentResultCollection<>(linkedEntityResultList, MODEL_VERSION, textBatchStatistics); + return new DocumentResultCollection<>(recognizeLinkedEntitiesResultList, MODEL_VERSION, textDocumentBatchStatistics); } - static DocumentResultCollection getExpectedBatchKeyPhrases() { + static DocumentResultCollection getExpectedBatchKeyPhrases() { List keyPhrasesList1 = Arrays.asList("input text", "world"); List keyPhrasesList2 = Arrays.asList("monde"); TextDocumentStatistics textDocumentStatistics1 = new TextDocumentStatistics().setCharacterCount(49).setTransactionCount(1); TextDocumentStatistics textDocumentStatistics2 = new TextDocumentStatistics().setCharacterCount(21).setTransactionCount(1); - KeyPhraseResult keyPhraseResult1 = new KeyPhraseResult("0", textDocumentStatistics1, null, keyPhrasesList1); - KeyPhraseResult keyPhraseResult2 = new KeyPhraseResult("1", textDocumentStatistics2, null, keyPhrasesList2); + ExtractKeyPhraseResult extractKeyPhraseResult1 = new ExtractKeyPhraseResult("0", textDocumentStatistics1, null, keyPhrasesList1); + ExtractKeyPhraseResult extractKeyPhraseResult2 = new ExtractKeyPhraseResult("1", textDocumentStatistics2, null, keyPhrasesList2); - TextBatchStatistics textBatchStatistics = new TextBatchStatistics().setDocumentCount(2).setErroneousDocumentCount(0).setTransactionCount(2).setValidDocumentCount(2); - List keyPhraseResultList = Arrays.asList(keyPhraseResult1, keyPhraseResult2); + TextDocumentBatchStatistics textDocumentBatchStatistics = new TextDocumentBatchStatistics().setDocumentCount(2).setErroneousDocumentCount(0).setTransactionCount(2).setValidDocumentCount(2); + List extractKeyPhraseResultList = Arrays.asList(extractKeyPhraseResult1, extractKeyPhraseResult2); - return new DocumentResultCollection<>(keyPhraseResultList, MODEL_VERSION, textBatchStatistics); + return new DocumentResultCollection<>(extractKeyPhraseResultList, MODEL_VERSION, textDocumentBatchStatistics); } static DocumentResultCollection getExpectedBatchTextSentiment() { @@ -996,7 +996,7 @@ static DocumentResultCollection getExpectedBatchTextSentime return new DocumentResultCollection<>(Arrays.asList(textSentimentResult1, textSentimentResult2), MODEL_VERSION, - new TextBatchStatistics().setDocumentCount(2).setErroneousDocumentCount(0) + new TextDocumentBatchStatistics().setDocumentCount(2).setErroneousDocumentCount(0) .setTransactionCount(2).setValidDocumentCount(2)); }