Detecting the dominant language in a text#
1raise SystemExit("Stop right there!");
An exception has occurred, use %tb to see the full traceback.
SystemExit: Stop right there!
1# import the AWS SDK for python (boto3) -
2# http://boto3.readthedocs.io/en/latest/
3import boto3
4
5# import json module to serialize JSON -
6# https://docs.python.org/3.6/library/json.html
7import json
1# Instantiating a new comprehend client
2comprehend = boto3.client(service_name="comprehend")
3
4# provide english and spanish text to analyze
5english_string = "Humans, eh? Think they" "re lords of creation."
6spanish_string = "Los humanos, ¿eh? Se creen los señores de la creación."
7
8print("Calling DetectDominantLanguage")
9
10print("english_string result:")
11# json.dumps() writes JSON data to a Python string
12print(
13 json.dumps(
14 comprehend.detect_dominant_language(Text=english_string),
15 sort_keys=True,
16 indent=4,
17 )
18)
19
20print("\n spanish_string result:")
21print(
22 json.dumps(
23 comprehend.detect_dominant_language(Text=spanish_string),
24 sort_keys=True,
25 indent=4,
26 )
27)
28
29print("End of DetectDominantLanguage\n")
Calling DetectDominantLanguage
english_string result:
{
"Languages": [
{
"LanguageCode": "en",
"Score": 0.9121910333633423
}
],
"ResponseMetadata": {
"HTTPHeaders": {
"content-length": "64",
"content-type": "application/x-amz-json-1.1",
"date": "Sun, 27 Mar 2022 23:53:45 GMT",
"x-amzn-requestid": "7c12b286-ac52-49a4-ba11-1152d25bd54c"
},
"HTTPStatusCode": 200,
"RequestId": "7c12b286-ac52-49a4-ba11-1152d25bd54c",
"RetryAttempts": 0
}
}
spanish_string result:
{
"Languages": [
{
"LanguageCode": "es",
"Score": 0.9952653646469116
}
],
"ResponseMetadata": {
"HTTPHeaders": {
"content-length": "64",
"content-type": "application/x-amz-json-1.1",
"date": "Sun, 27 Mar 2022 23:53:45 GMT",
"x-amzn-requestid": "44144520-dbd4-4561-8ce5-b2d6f9ba92e1"
},
"HTTPStatusCode": 200,
"RequestId": "44144520-dbd4-4561-8ce5-b2d6f9ba92e1",
"RetryAttempts": 0
}
}
End of DetectDominantLanguage