<jupyter_start><jupyter_text>This notebooks demonstrate how to to AWS Boto3 APIs to invoke the various Comprehend actions<jupyter_code>from pprint import pprint
import boto3

items_to_show = 10

with open('data/comprehend_sample.txt') as sample_file:
        sample_text = sample_file.read()

comprehend_client = boto3.client('comprehend')
print("detecting dominant language")
languages = comprehend_client.detect_dominant_language(Text=sample_text)
lang_code = languages['Languages'][0]['LanguageCode']
pprint(lang_code)
print("Detecting entities using the pre-trained model.")
entities = comprehend_client.detect_entities(Text=sample_text, LanguageCode=lang_code)
print(f"The first {items_to_show} are:")
pprint(entities['Entities'][:items_to_show])
print("Detecting sentiment in text")
sentiment = comprehend_client.detect_sentiment(Text=sample_text, LanguageCode=lang_code)
pprint(sentiment['Sentiment'])
pprint(sentiment['SentimentScore'])
print("Detecting pii entities in text")
pii = comprehend_client.detect_pii_entities(Text=sample_text, LanguageCode=lang_code)
pprint(pii['Entities'][:items_to_show])
print('Dectecting key phrases')
key_phrases = comprehend_client.detect_key_phrases(
                Text=sample_text, LanguageCode=lang_code)
pprint(key_phrases['KeyPhrases'][:items_to_show])
print('Detecting syntax')
syntax = comprehend_client.detect_syntax(
                Text=sample_text, LanguageCode=lang_code)
pprint(syntax['SyntaxTokens'][:items_to_show])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10764119601328903, 'fraction_numerical': 0.003986710963455149, 'mean_word_length': 9.04, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '27817', 'license': 'MIT', 'n_tokens_mistral': 498, 'n_tokens_neox': 486, 'n_words': 85, 'path': 'Chapter12/comprehend.ipynb', 'repo_name': 'PacktPublishing/The-Machine-Learning-Solutions-Architect-Handbook', 'size': '1505'}