-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[text analytics] change return type of analyze actions to list of list #18994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
d4f55d4
0307a4a
86f8294
f192e29
917305d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -532,72 +532,56 @@ poller = text_analytics_client.begin_analyze_actions( | |
| ) | ||
|
|
||
| # returns multiple actions results in the same order as the inputted actions | ||
| result = poller.result() | ||
|
|
||
| first_action_result = next(result) | ||
| print("Results of Entities Recognition action:") | ||
| docs = [doc for doc in first_action_result.document_results if not doc.is_error] | ||
|
|
||
| for idx, doc in enumerate(docs): | ||
| print("\nDocument text: {}".format(documents[idx])) | ||
| for entity in doc.entities: | ||
| print("Entity: {}".format(entity.text)) | ||
| print("...Category: {}".format(entity.category)) | ||
| print("...Confidence Score: {}".format(entity.confidence_score)) | ||
| print("...Offset: {}".format(entity.offset)) | ||
| print("------------------------------------------") | ||
|
|
||
| second_action_result = next(result) | ||
| print("Results of PII Entities Recognition action:") | ||
| docs = [doc for doc in second_action_result.document_results if not doc.is_error] | ||
|
|
||
| for idx, doc in enumerate(docs): | ||
| print("Document text: {}".format(documents[idx])) | ||
| for entity in doc.entities: | ||
| print("Entity: {}".format(entity.text)) | ||
| print("Category: {}".format(entity.category)) | ||
| print("Confidence Score: {}\n".format(entity.confidence_score)) | ||
| print("------------------------------------------") | ||
|
|
||
| third_action_result = next(result) | ||
| print("Results of Key Phrase Extraction action:") | ||
| docs = [doc for doc in third_action_result.document_results if not doc.is_error] | ||
|
|
||
| for idx, doc in enumerate(docs): | ||
| print("Document text: {}\n".format(documents[idx])) | ||
| print("Key Phrases: {}\n".format(doc.key_phrases)) | ||
| print("------------------------------------------") | ||
|
|
||
| fourth_action_result = next(result) | ||
| print("Results of Linked Entities Recognition action:") | ||
| docs = [doc for doc in fourth_action_result.document_results if not doc.is_error] | ||
|
|
||
| for idx, doc in enumerate(docs): | ||
| print("Document text: {}\n".format(documents[idx])) | ||
| for linked_entity in doc.entities: | ||
| print("Entity name: {}".format(linked_entity.name)) | ||
| print("...Data source: {}".format(linked_entity.data_source)) | ||
| print("...Data source language: {}".format(linked_entity.language)) | ||
| print("...Data source entity ID: {}".format(linked_entity.data_source_entity_id)) | ||
| print("...Data source URL: {}".format(linked_entity.url)) | ||
| print("...Document matches:") | ||
| pages = poller.result() | ||
|
|
||
| for doc, document_results in zip(documents, pages): | ||
| print("\nDocument text: {}".format(doc)) | ||
| recognize_entities_result = document_results[0] | ||
| assert not recognize_entities_result.is_error | ||
|
||
| print("...Results of Recognize Entities Action:") | ||
| for entity in recognize_entities_result.entities: | ||
| print("......Entity: {}".format(entity.text)) | ||
| print(".........Category: {}".format(entity.category)) | ||
| print(".........Confidence Score: {}".format(entity.confidence_score)) | ||
| print(".........Offset: {}".format(entity.offset)) | ||
|
|
||
| recognize_pii_entities_result = document_results[1] | ||
| assert not recognize_pii_entities_result.is_error | ||
| print("...Results of Recognize PII Entities action:") | ||
| for entity in recognize_pii_entities_result.entities: | ||
| print("......Entity: {}".format(entity.text)) | ||
| print(".........Category: {}".format(entity.category)) | ||
| print(".........Confidence Score: {}".format(entity.confidence_score)) | ||
|
|
||
| extract_key_phrases_result = document_results[2] | ||
| assert not extract_key_phrases_result.is_error | ||
| print("...Results of Extract Key Phrases action:") | ||
| print("......Key Phrases: {}".format(extract_key_phrases_result.key_phrases)) | ||
|
|
||
| recognize_linked_entities_result = document_results[3] | ||
| assert not recognize_linked_entities_result.is_error | ||
| print("...Results of Recognize Linked Entities action:") | ||
| for linked_entity in recognize_linked_entities_result.entities: | ||
| print("......Entity name: {}".format(linked_entity.name)) | ||
| print(".........Data source: {}".format(linked_entity.data_source)) | ||
| print(".........Data source language: {}".format(linked_entity.language)) | ||
| print(".........Data source entity ID: {}".format(linked_entity.data_source_entity_id)) | ||
| print(".........Data source URL: {}".format(linked_entity.url)) | ||
| print(".........Document matches:") | ||
| for match in linked_entity.matches: | ||
| print("......Match text: {}".format(match.text)) | ||
| print(".........Confidence Score: {}".format(match.confidence_score)) | ||
| print(".........Offset: {}".format(match.offset)) | ||
| print(".........Length: {}".format(match.length)) | ||
| print("------------------------------------------") | ||
|
|
||
| fifth_action_result = next(result) | ||
| print("Results of Sentiment Analysis action:") | ||
| docs = [doc for doc in fifth_action_result.document_results if not doc.is_error] | ||
|
|
||
| for doc in docs: | ||
| print("Overall sentiment: {}".format(doc.sentiment)) | ||
| print("Scores: positive={}; neutral={}; negative={} \n".format( | ||
| doc.confidence_scores.positive, | ||
| doc.confidence_scores.neutral, | ||
| doc.confidence_scores.negative, | ||
| print("............Match text: {}".format(match.text)) | ||
| print("............Confidence Score: {}".format(match.confidence_score)) | ||
| print("............Offset: {}".format(match.offset)) | ||
| print("............Length: {}".format(match.length)) | ||
|
|
||
| analyze_sentiment_result = document_results[4] | ||
| assert not analyze_sentiment_result.is_error | ||
| print("...Results of Analyze Sentiment action:") | ||
| print("......Overall sentiment: {}".format(analyze_sentiment_result.sentiment)) | ||
| print("......Scores: positive={}; neutral={}; negative={} \n".format( | ||
| analyze_sentiment_result.confidence_scores.positive, | ||
| analyze_sentiment_result.confidence_scores.neutral, | ||
| analyze_sentiment_result.confidence_scores.negative, | ||
| )) | ||
| print("------------------------------------------") | ||
| ``` | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.