diff --git a/sdk/textanalytics/azure-ai-textanalytics/README.md b/sdk/textanalytics/azure-ai-textanalytics/README.md index 3658bd1bc0b8..67d4391f5d04 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/README.md +++ b/sdk/textanalytics/azure-ai-textanalytics/README.md @@ -1,11 +1,15 @@ # Azure Text Analytics client library for Java Text Analytics is a cloud-based service that provides advanced natural language processing over raw text, -and includes four main functions: +and includes six main functions: -- Sentiment Analysis -- Named Entity Recognition - Language Detection +- Sentiment Analysis - Key Phrase Extraction +- Named Entity Recognition +- Recognition of Personally Identifiable Information +- Linked Entity Recognition + +[Source code][source_code] | [API reference documentation][api_reference_doc] | [Product Documentation][product_documentation] | [Samples][samples_readme] ## Getting started @@ -177,6 +181,28 @@ TextAnalyticsClient client = new TextAnalyticsClientBuilder() ## Key concepts +### Text Input +A text input, sometimes called a `document`, is a single unit of input to be analyzed by the predictive models +in the Text Analytics service. Operations on Text Analytics client may take a single text input or a collection +of inputs to be analyzed as a batch. + +### Operation Result +An operation result, such as `AnalyzeSentimentResult`, is the result of a Text Analytics operation, containing a +prediction or predictions about a single text input. An operation's result type also may optionally include information +about the input document and how it was processed. + +### Operation Result Collection +An operation result collection, such as `DocumentResultCollection`, which is the collection of +the result of a Text Analytics analyzing sentiment operation. `DocumentResultCollection` includes the model version of +the operation and statistics of the batch documents. Since `DocumentResultCollection` extends `IterableStream`, +the list of item can be retrieved by streaming or iterating the list. + +### Operation Overloads +For each supported operation, the Text Analytics client provides method overloads to take a single text input, a batch +of text inputs as strings, or a batch of either `TextDocumentInput` or `DetectLanguageInput` objects. The overload +taking the `TextDocumentInput` or `DetectLanguageInput` batch allows callers to give each document a unique ID, or +indicate that the documents in the batch are written in different languages. + The following are types of text analysis that the service offers: 1. [Sentiment Analysis](https://docs.microsoft.com/azure/cognitive-services/text-analytics/how-tos/text-analytics-how-to-sentiment-analysis) @@ -210,8 +236,16 @@ The following are types of text analysis that the service offers: See [Language and regional support](https://docs.microsoft.com/azure/cognitive-services/text-analytics/language-support) for what is currently available for each operation. +## Examples +The following sections provide several code snippets covering some of the most common text analytics tasks, including: + ### Text Analytics Client +Text analytics support both synchronous and asynchronous client creation by using +`TextAnalyticsClientBuilder`, + ``` java +// An example of creating a synchronous client + TextAnalyticsClient client = new TextAnalyticsClientBuilder() .subscriptionKey("subscription-key") .endpoint("https://servicename.cognitiveservices.azure.com/") @@ -219,15 +253,14 @@ TextAnalyticsClient client = new TextAnalyticsClientBuilder() ``` ``` java +// An example of creating an asynchronous client + TextAnalyticsAsyncClient client = new TextAnalyticsClientBuilder() .subscriptionKey("subscription-key") .endpoint("https://servicename.cognitiveservices.azure.com/") .buildAsyncClient(); ``` -## Examples -The following sections provide several code snippets covering some of the most common text analytics tasks, including: - ### Detect language Detect language in a batch of documents. @@ -248,6 +281,7 @@ for(DetectedLanguage detectedLanguage : client.detectLanguage(text, "US").getDet ``` ### Recognize entity + ```java TextAnalyticsClient client = new TextAnalyticsClientBuilder() .subscriptionKey("subscription-key") @@ -338,10 +372,12 @@ This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For m [azure_subscription]: https://azure.microsoft.com/free +[api_reference_doc]: https://azure.github.io/azure-sdk-for-java/cognitiveservices.html [cla]: https://cla.microsoft.com [coc]: https://opensource.microsoft.com/codeofconduct/ [coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ [coc_contact]: mailto:opencode@microsoft.com +[product_documentation]: https://docs.microsoft.com/azure/cognitive-services/text-analytics/overview [samples_readme]: src/samples/README.md [source_code]: src diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/samples/README.md b/sdk/textanalytics/azure-ai-textanalytics/src/samples/README.md index 66f00a95a29c..4d4112db8782 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/src/samples/README.md +++ b/sdk/textanalytics/azure-ai-textanalytics/src/samples/README.md @@ -50,18 +50,18 @@ Guidelines](../../CONTRIBUTING.md) for more information. [SDK_README_DEPENDENCY]: ../../README.md#adding-the-package-to-your-product [SDK_README_NEXT_STEPS]: ../../README.md#next-steps -[sample_hello_world]: java/com/azure/cs/textanalytics/HelloWorld.java -[sample_entities]: java/com/azure/cs/textanalytics/RecognizeEntities.java -[sample_pii_entities]: java/com/azure/cs/textanalytics/RecognizePII.java -[sample_linked_entities]: java/com/azure/cs/textanalytics/RecognizeLinkedEntities.java -[sample_key_phrases]: java/com/azure/cs/textanalytics/RecognizeKeyPhrases.java -[sample_sentiment]: java/com/azure/cs/textanalytics/DetectSentiment.java +[sample_hello_world]: java/com/azure/ai/textanalytics/HelloWorld.java +[sample_entities]: java/com/azure/ai/textanalytics/RecognizeEntities.java +[sample_pii_entities]: java/com/azure/ai/textanalytics/RecognizePii.java +[sample_linked_entities]: java/com/azure/ai/textanalytics/RecognizeLinkedEntities.java +[sample_key_phrases]: java/com/azure/ai/textanalytics/ExtractKeyPhrases.java +[sample_sentiment]: java/com/azure/ai/textanalytics/AnalyzeSentiment.java -[sample_language_batch]: java/com/azure/cs/textanalytics/batch/DetectLanguageBatchDocuments.java -[sample_entities_batch]: java/com/azure/cs/textanalytics/batch/RecognizeEntitiesBatchDocuments.java -[sample_pii_entities_batch]: java/com/azure/cs/textanalytics/batch/RecognizePiiBatchDocuments.java -[sample_linked_entities_batch]: java/com/azure/cs/textanalytics/batch/RecognizeLinkedEntitiesBatchDocuments.java -[sample_key_phrases_batch]: java/com/azure/cs/textanalytics/batch/RecognizeKeyPhrasesBatchDocuments.java -[sample_sentiment_batch]: java/com/azure/cs/textanalytics/batch/DetectSentimentBatchDocuments.java +[sample_language_batch]: java/com/azure/ai/textanalytics/batch/DetectLanguageBatchDocuments.java +[sample_entities_batch]: java/com/azure/ai/textanalytics/batch/RecognizeEntitiesBatchDocuments.java +[sample_pii_entities_batch]: java/com/azure/ai/textanalytics/batch/RecognizePiiBatchDocuments.java +[sample_linked_entities_batch]: java/com/azure/ai/textanalytics/batch/RecognizeLinkedEntitiesBatchDocuments.java +[sample_key_phrases_batch]: java/com/azure/ai/textanalytics/batch/ExtractKeyPhrasesBatchDocuments.java +[sample_sentiment_batch]: java/com/azure/ai/textanalytics/batch/AnalyzeSentimentBatchDocuments.java ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Ftextanalytics%2Fazure-ai-textanalytics%2FREADME.png) diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/RecognizeEntities.java b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/RecognizeEntities.java index bda25d0026e0..274bf1e90f46 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/RecognizeEntities.java +++ b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/RecognizeEntities.java @@ -29,7 +29,7 @@ public static void main(String[] args) { "Recognized NamedEntity: %s, NamedEntity Type: %s, NamedEntity Subtype: %s, Offset: %s, Length: %s, Score: %s.%n", entity.getText(), entity.getType(), - entity.getSubtype(), + entity.getSubtype() == null || entity.getSubtype().isEmpty() ? "N/A" : entity.getSubtype(), entity.getOffset(), entity.getLength(), entity.getScore()); diff --git a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/RecognizePii.java b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/RecognizePii.java index 5470ffdc6ef0..257da41ea72b 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/RecognizePii.java +++ b/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/RecognizePii.java @@ -28,8 +28,10 @@ public static void main(String[] args) { System.out.printf( "Recognized PII Entity: %s, Entity Type: %s, Entity Subtype: %s, Offset: %s, Length: %s, Score: %s.%n", entity.getText(), - entity.getType(), - entity.getSubtype(), + entity.getType() , + entity.getSubtype() == null || entity.getSubtype().isEmpty() ? "N/A" : entity.getSubtype(), + entity.getOffset(), + entity.getLength(), entity.getScore()); } }