<jupyter_start><jupyter_text>AWS Comprehend allows you to discover insights and relationships in texts for text analytics which includes sentiment analysis, entity detection, key phrases detection, language detection and topic modelling<jupyter_code>def detect_dominant_language(text):
    "Determines the dominant language of the input text for a batch of documents"
    client = boto3.client('comprehend')
    response = client.detect_dominant_language(
        Text = text
    )
    return response['Languages']

text = "Amazon.com, Inc. is located in Seattle, WA and was founded July 5th, 1994 by <NAME>, allowing customers to buy everything from books to blenders. Seattle is north of Portland and south of Vancouver, BC. Other notable Seattle - based companies are Starbucks and Boeing."
detect_dominant_language(text)
text = "<NAME>, sur un arbre perché, Tenait en son bec un fromage. <NAME>, par l’odeur alléché, Lui tint à peu près ce langage"
detect_dominant_language(text)
def detect_entities(text):
    'Inspects the text of a batch of documents for named entities and returns information about them. '
    client = boto3.client('comprehend')
    response = client.detect_entities(
        Text = text,
        LanguageCode ='en'
    )
    return response['Entities']

text = "Bob ordered two sandwiches and three ice cream cones today from a store in Seattle."
detect_entities(text)
def detect_key_phrases(text):
    response = client.detect_key_phrases(
        Text=text,
        LanguageCode='en'
    )
    
    return response['KeyPhrases']

text = "Bob ordered two sandwiches and three ice cream cones today from a store in Seattle."
detect_key_phrases(text)
def detect_sentiment(text):
    response = client.detect_sentiment(
        Text = text,
        LanguageCode='en'
    )
    return response['Sentiment']

text = "Bob ordered two sandwiches and three ice cream cones today from a store in Seattle"
detect_sentiment(text)
def detect_syntax(text):
    response = client.detect_syntax(
        Text= text,
        LanguageCode='en'
    )
    
    return response['SyntaxTokens']
text = "Bob ordered two sandwiches and three ice cream cones today from a store in Seattle."
detect_syntax(text)
import boto3
comprehendmedical = boto3.client('comprehendmedical')

text = "Pt is 40yo mother, software engineer HPI : Sleeping trouble on present dosage of Clonidine. Severe Rash  on face and leg, slightly itchy  Meds : Vyvanse  50 mgs po at breakfast daily, Clonidine 0.2 mgs -- 1 and 1 / 2 tabs po qhs HEENT :  Boggy inferior turbinates, No oropharyngeal lesion Lungs : clear Heart : Regular  rhythm Skin :  Papular mild erythematous eruption to hairline Follow-up as scheduled"
result = comprehendm.detect_entities(Text=text)
entities = result['Entities']
for entity in entities:
    print(entity)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07027406886858749, 'fraction_numerical': 0.006324666198172874, 'mean_word_length': 4.166969147005445, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '378766', 'license': 'MIT', 'n_tokens_mistral': 833, 'n_tokens_neox': 787, 'n_words': 317, 'path': 'Comprehend.ipynb', 'repo_name': 'jsalomon-mdsol/medihack-aws-code', 'size': '2865'}