Skip to content

Commit

Permalink
simplify read me (#33914)
Browse files Browse the repository at this point in the history
  • Loading branch information
mssfang authored Mar 8, 2023
1 parent 5cf2390 commit c9ceb82
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 474 deletions.
4 changes: 1 addition & 3 deletions sdk/textanalytics/azure-ai-textanalytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release History

## 5.3.0-beta.2 (Unreleased)
## 5.3.0-beta.2 (2023-03-07)

### Features Added
- Added the following methods for performing abstractive summarization and extractive summarization actions:
Expand All @@ -17,8 +17,6 @@
- Removed class `BooleanResolution` and enum value `BooleanResolution` in the class `ResolutionKind`.
- Renamed `maxSentenceCount` to `sentenceCount` in abstractive summarization.

### Bugs Fixed

### Other Changes
- Integrate synchronous workflow for sync clients so that they do not block on async client APIs.
It simplifies stack traces and improves debugging experience.
Expand Down
229 changes: 18 additions & 211 deletions sdk/textanalytics/azure-ai-textanalytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,99 +336,17 @@ Please refer to the service documentation for a conceptual discussion of [entity
### Analyze healthcare entities
Text Analytics for health is a containerized service that extracts and labels relevant medical information from
unstructured texts such as doctor's notes, discharge summaries, clinical documents, and electronic health records.

- [Healthcare entities recognition][recognize_healthcare_entities_sample]

For more information see [How to: Use Text Analytics for health][healthcare].
```java readme-sample-recognizeHealthcareEntities
List<TextDocumentInput> documents = Arrays.asList(new TextDocumentInput("0",
"RECORD #333582770390100 | MH | 85986313 | | 054351 | 2/14/2001 12:00:00 AM | "
+ "CORONARY ARTERY DISEASE | Signed | DIS | Admission Date: 5/22/2001 "
+ "Report Status: Signed Discharge Date: 4/24/2001 ADMISSION DIAGNOSIS: "
+ "CORONARY ARTERY DISEASE. HISTORY OF PRESENT ILLNESS: "
+ "The patient is a 54-year-old gentleman with a history of progressive angina over the past"
+ " several months. The patient had a cardiac catheterization in July of this year revealing total"
+ " occlusion of the RCA and 50% left main disease , with a strong family history of coronary"
+ " artery disease with a brother dying at the age of 52 from a myocardial infarction and another"
+ " brother who is status post coronary artery bypass grafting. The patient had a stress"
+ " echocardiogram done on July , 2001 , which showed no wall motion abnormalities,"
+ " but this was a difficult study due to body habitus. The patient went for six minutes with"
+ " minimal ST depressions in the anterior lateral leads , thought due to fatigue and wrist pain,"
+ " his anginal equivalent. Due to the patient's increased symptoms and family history and"
+ " history left main disease with total occasional of his RCA was referred"
+ " for revascularization with open heart surgery."
));
AnalyzeHealthcareEntitiesOptions options = new AnalyzeHealthcareEntitiesOptions().setIncludeStatistics(true);
SyncPoller<AnalyzeHealthcareEntitiesOperationDetail, AnalyzeHealthcareEntitiesPagedIterable>
syncPoller = textAnalyticsClient.beginAnalyzeHealthcareEntities(documents, options, Context.NONE);
syncPoller.waitForCompletion();
syncPoller.getFinalResult().forEach(
analyzeHealthcareEntitiesResultCollection -> analyzeHealthcareEntitiesResultCollection.forEach(
healthcareEntitiesResult -> {
System.out.println("Document entities: ");
AtomicInteger ct = new AtomicInteger();
healthcareEntitiesResult.getEntities().forEach(healthcareEntity -> {
System.out.printf("\ti = %d, Text: %s, category: %s, subcategory: %s, confidence score: %f.%n",
ct.getAndIncrement(), healthcareEntity.getText(), healthcareEntity.getCategory(),
healthcareEntity.getSubcategory(), healthcareEntity.getConfidenceScore());
IterableStream<EntityDataSource> healthcareEntityDataSources =
healthcareEntity.getDataSources();
if (healthcareEntityDataSources != null) {
healthcareEntityDataSources.forEach(healthcareEntityLink -> System.out.printf(
"\t\tEntity ID in data source: %s, data source: %s.%n",
healthcareEntityLink.getEntityId(), healthcareEntityLink.getName()));
}
});
// Healthcare entity relation groups
healthcareEntitiesResult.getEntityRelations().forEach(entityRelation -> {
System.out.printf("\tRelation type: %s.%n", entityRelation.getRelationType());
entityRelation.getRoles().forEach(role -> {
final HealthcareEntity entity = role.getEntity();
System.out.printf("\t\tEntity text: %s, category: %s, role: %s.%n",
entity.getText(), entity.getCategory(), role.getName());
});
System.out.printf("\tRelation confidence score: %f.%n", entityRelation.getConfidenceScore());
});
}));
```

### Custom entities recognition
Custom NER is one of the custom features offered by Azure Cognitive Service for Language. It is a cloud-based API
service that applies machine-learning intelligence to enable you to build custom models for custom named entity
recognition tasks.

```java readme-sample-custom-entities-recognition
List<String> documents = new ArrayList<>();
documents.add(
"A recent report by the Government Accountability Office (GAO) found that the dramatic increase "
+ "in oil and natural gas development on federal lands over the past six years has stretched the"
+ " staff of the BLM to a point that it has been unable to meet its environmental protection "
+ "responsibilities.");
documents.add(
"David Schmidt, senior vice president--Food Safety, International Food"
+ " Information Council (IFIC), Washington, D.C., discussed the physical activity component."
);

// See the service documentation for regional support and how to train a model to recognize the custom entities,
// see https://aka.ms/azsdk/textanalytics/customentityrecognition
SyncPoller<RecognizeCustomEntitiesOperationDetail, RecognizeCustomEntitiesPagedIterable> syncPoller =
textAnalyticsClient.beginRecognizeCustomEntities(documents, "{project_name}", "{deployment_name}");
syncPoller.waitForCompletion();
syncPoller.getFinalResult().forEach(documentsResults -> {
System.out.printf("Project name: %s, deployment name: %s.%n",
documentsResults.getProjectName(), documentsResults.getDeploymentName());
for (RecognizeEntitiesResult documentResult : documentsResults) {
System.out.println("Document ID: " + documentResult.getId());
if (!documentResult.isError()) {
for (CategorizedEntity entity : documentResult.getEntities()) {
System.out.printf(
"\tText: %s, category: %s, confidence score: %f.%n",
entity.getText(), entity.getCategory(), entity.getConfidenceScore());
}
} else {
System.out.printf("\tCannot recognize custom entities. Error: %s%n",
documentResult.getError().getMessage());
}
}
});
```
- [Custom entities recognition][recognize_custom_entities_sample]

For more information see [How to use: Custom Entities Recognition][custom_entities_recognition_overview].

Expand All @@ -437,76 +355,9 @@ Custom text classification is one of the custom features offered by Azure Cognit
cloud-based API service that applies machine-learning intelligence to enable you to build custom models for text
classification tasks.

- Single label classification
```java readme-sample-single-label-classification
List<String> documents = new ArrayList<>();
documents.add(
"A recent report by the Government Accountability Office (GAO) found that the dramatic increase "
+ "in oil and natural gas development on federal lands over the past six years has stretched the"
+ " staff of the BLM to a point that it has been unable to meet its environmental protection "
+ "responsibilities.");
documents.add(
"David Schmidt, senior vice president--Food Safety, International Food"
+ " Information Council (IFIC), Washington, D.C., discussed the physical activity component."
);
documents.add(
"I need a reservation for an indoor restaurant in China. Please don't stop the music. Play music "
+ "and add it to my playlist"
);

// See the service documentation for regional support and how to train a model to classify your documents,
// see https://aka.ms/azsdk/textanalytics/customfunctionalities
SyncPoller<ClassifyDocumentOperationDetail, ClassifyDocumentPagedIterable> syncPoller =
textAnalyticsClient.beginSingleLabelClassify(documents, "{project_name}", "{deployment_name}");
syncPoller.waitForCompletion();
syncPoller.getFinalResult().forEach(documentsResults -> {
System.out.printf("Project name: %s, deployment name: %s.%n",
documentsResults.getProjectName(), documentsResults.getDeploymentName());
for (ClassifyDocumentResult documentResult : documentsResults) {
System.out.println("Document ID: " + documentResult.getId());
if (!documentResult.isError()) {
for (ClassificationCategory classification : documentResult.getClassifications()) {
System.out.printf("\tCategory: %s, confidence score: %f.%n",
classification.getCategory(), classification.getConfidenceScore());
}
} else {
System.out.printf("\tCannot classify category of document. Error: %s%n",
documentResult.getError().getMessage());
}
}
});
```

- Multi label classification
```java readme-sample-multi-label-classification
List<String> documents = new ArrayList<>();
documents.add(
"I need a reservation for an indoor restaurant in China. Please don't stop the music."
+ " Play music and add it to my playlist"
);
- [Single label classification][single_label_classification_sample]

// See the service documentation for regional support and how to train a model to classify your documents,
// see https://aka.ms/azsdk/textanalytics/customfunctionalities
SyncPoller<ClassifyDocumentOperationDetail, ClassifyDocumentPagedIterable> syncPoller =
textAnalyticsClient.beginMultiLabelClassify(documents, "{project_name}", "{deployment_name}");
syncPoller.waitForCompletion();
syncPoller.getFinalResult().forEach(documentsResults -> {
System.out.printf("Project name: %s, deployment name: %s.%n",
documentsResults.getProjectName(), documentsResults.getDeploymentName());
for (ClassifyDocumentResult documentResult : documentsResults) {
System.out.println("Document ID: " + documentResult.getId());
if (!documentResult.isError()) {
for (ClassificationCategory classification : documentResult.getClassifications()) {
System.out.printf("\tCategory: %s, confidence score: %f.%n",
classification.getCategory(), classification.getConfidenceScore());
}
} else {
System.out.printf("\tCannot classify category of document. Error: %s%n",
documentResult.getError().getMessage());
}
}
});
```
- [Multi label classification][multi_label_classification_sample]

For more information see [How to use: Custom Text Classification][custom_text_classification_overview].

Expand All @@ -526,58 +377,9 @@ set of documents. Currently, the supported features are:
- Abstractive Text Summarization (API version 2022-10-01-preview and newer)
- Extractive Text Summarization (API version 2022-10-01-preview and newer)

```java readme-sample-analyzeActions
List<TextDocumentInput> documents = Arrays.asList(
new TextDocumentInput("0",
"We went to Contoso Steakhouse located at midtown NYC last week for a dinner party, and we adore"
+ " the spot! They provide marvelous food and they have a great menu. The chief cook happens to be"
+ " the owner (I think his name is John Doe) and he is super nice, coming out of the kitchen and "
+ "greeted us all. We enjoyed very much dining in the place! The Sirloin steak I ordered was tender"
+ " and juicy, and the place was impeccably clean. You can even pre-order from their online menu at"
+ " www.contososteakhouse.com, call 312-555-0176 or send email to [email protected]! The"
+ " only complaint I have is the food didn't come fast enough. Overall I highly recommend it!")
);

SyncPoller<AnalyzeActionsOperationDetail, AnalyzeActionsResultPagedIterable> syncPoller =
textAnalyticsClient.beginAnalyzeActions(documents,
new TextAnalyticsActions().setDisplayName("{tasks_display_name}")
.setExtractKeyPhrasesActions(new ExtractKeyPhrasesAction())
.setRecognizePiiEntitiesActions(new RecognizePiiEntitiesAction()),
new AnalyzeActionsOptions().setIncludeStatistics(false),
Context.NONE);
syncPoller.waitForCompletion();
syncPoller.getFinalResult().forEach(analyzeActionsResult -> {
System.out.println("Key phrases extraction action results:");
analyzeActionsResult.getExtractKeyPhrasesResults().forEach(actionResult -> {
AtomicInteger counter = new AtomicInteger();
if (!actionResult.isError()) {
for (ExtractKeyPhraseResult extractKeyPhraseResult : actionResult.getDocumentsResults()) {
System.out.printf("%n%s%n", documents.get(counter.getAndIncrement()));
System.out.println("Extracted phrases:");
extractKeyPhraseResult.getKeyPhrases()
.forEach(keyPhrases -> System.out.printf("\t%s.%n", keyPhrases));
}
}
});
System.out.println("PII entities recognition action results:");
analyzeActionsResult.getRecognizePiiEntitiesResults().forEach(actionResult -> {
AtomicInteger counter = new AtomicInteger();
if (!actionResult.isError()) {
for (RecognizePiiEntitiesResult entitiesResult : actionResult.getDocumentsResults()) {
System.out.printf("%n%s%n", documents.get(counter.getAndIncrement()));
PiiEntityCollection piiEntityCollection = entitiesResult.getEntities();
System.out.printf("Redacted Text: %s%n", piiEntityCollection.getRedactedText());
piiEntityCollection.forEach(entity -> System.out.printf(
"Recognized Personally Identifiable Information entity: %s, entity category: %s, "
+ "entity subcategory: %s, offset: %s, confidence score: %f.%n",
entity.getText(), entity.getCategory(), entity.getSubcategory(), entity.getOffset(),
entity.getConfidenceScore()));
}
}
});
});
}
```

Sample: [Multiple action analysis][multiple_actions_analysis_sample]

For more examples, such as asynchronous samples, refer to [here][samples_readme].

## Troubleshooting
Expand Down Expand Up @@ -673,15 +475,20 @@ This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For m
[LogLevels]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/core/azure-core/src/main/java/com/azure/core/util/logging/ClientLogger.java

[samples_readme]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/README.md
[detect_language_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/DetectLanguageBatchDocuments.java
[abstractive_summary_action_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/lro/AbstractiveSummarization.java
[analyze_sentiment_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/AnalyzeSentimentBatchDocuments.java
[analyze_sentiment_with_opinion_mining_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/AnalyzeSentimentWithOpinionMining.java
[detect_language_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/DetectLanguageBatchDocuments.java
[dynamic_classification_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/DynamicClassifyBatchDocuments.java
[extract_key_phrases_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/ExtractKeyPhrasesBatchDocuments.java
[extractive_summary_action_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/lro/ExtractiveSummarization.java
[multi_label_classification_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/lro/MultiLabelClassifyDocument.java
[multiple_actions_analysis_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/lro/AnalyzeActions.java
[recognize_entities_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizeEntitiesBatchDocuments.java
[recognize_pii_entities_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizePiiEntitiesBatchDocuments.java
[recognize_linked_entities_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/RecognizeLinkedEntitiesBatchDocuments.java
[abstractive_summary_action_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/lro/AbstractiveSummarization.java
[extractive_summary_action_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/lro/ExtractiveSummarization.java
[dynamic_classification_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/batch/DynamicClassifyBatchDocuments.java
[recognize_healthcare_entities_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/lro/AnalyzeHealthcareEntities.java
[recognize_custom_entities_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/lro/RecognizeCustomEntities.java
[single_label_classification_sample]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics/lro/SingleLabelClassifyDocument.java

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Ftextanalytics%2Fazure-ai-textanalytics%2FREADME.png)
Loading

0 comments on commit c9ceb82

Please sign in to comment.