Detecting named entities 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# instantiate a new comprehend client
2comprehend = boto3.client(service_name="comprehend")
3
4# Providing english text to analyze
5english_string = (
6 "In Reading [England] there is this thing called the IDR, short for "
7 "'Inner Distribution Road', which is bureaucratese for 'Big thing "
8 "that cost a lot of money and relieves traffic problems, provided "
9 "all your traffic wants to orbit the town centre permanently.'"
10)
11
12print("Calling DetectEntities")
13# json.dumps() writes JSON data to a Python string
14print(
15 json.dumps(
16 comprehend.detect_entities(Text=english_string, LanguageCode="en"),
17 sort_keys=True,
18 indent=4,
19 )
20)
21print("End of DetectEntities\n")
Calling DetectEntities
{
"Entities": [
{
"BeginOffset": 3,
"EndOffset": 10,
"Score": 0.9961724877357483,
"Text": "Reading",
"Type": "LOCATION"
},
{
"BeginOffset": 12,
"EndOffset": 19,
"Score": 0.9655429124832153,
"Text": "England",
"Type": "LOCATION"
},
{
"BeginOffset": 52,
"EndOffset": 55,
"Score": 0.8363457322120667,
"Text": "IDR",
"Type": "OTHER"
},
{
"BeginOffset": 67,
"EndOffset": 90,
"Score": 0.8960779309272766,
"Text": "Inner Distribution Road",
"Type": "LOCATION"
},
{
"BeginOffset": 140,
"EndOffset": 154,
"Score": 0.9770320057868958,
"Text": "a lot of money",
"Type": "QUANTITY"
},
{
"BeginOffset": 195,
"EndOffset": 211,
"Score": 0.568979024887085,
"Text": "all your traffic",
"Type": "QUANTITY"
}
],
"ResponseMetadata": {
"HTTPHeaders": {
"content-length": "617",
"content-type": "application/x-amz-json-1.1",
"date": "Mon, 28 Mar 2022 00:10:42 GMT",
"x-amzn-requestid": "ab78d204-4e87-4999-bbd4-e05b243b972f"
},
"HTTPStatusCode": 200,
"RequestId": "ab78d204-4e87-4999-bbd4-e05b243b972f",
"RetryAttempts": 0
}
}
End of DetectEntities