Detecting key phrases#
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# Instatiating a new comprehend client
2comprehend = boto3.client(service_name="comprehend")
1# Providing english text to analyze
2english_string = (
3 "To get the walkthrough, you have to take the sponge from Nanny Ogg"
4 "''s pantry and stick it in the ear of the troll with the tutu, then "
5 "take the lumps and put them in the pouch with the zombie"
6 "''s razor."
7)
8
9print("Calling DetectKeyPhrases")
10# json.dumps() writes JSON data to a Python string
11print(
12 json.dumps(
13 comprehend.detect_key_phrases(Text=english_string, LanguageCode="en"),
14 sort_keys=True,
15 indent=4,
16 )
17)
18print("End of DetectKeyPhrases\n")
Calling DetectKeyPhrases
{
"KeyPhrases": [
{
"BeginOffset": 7,
"EndOffset": 22,
"Score": 0.9999029040336609,
"Text": "the walkthrough"
},
{
"BeginOffset": 41,
"EndOffset": 51,
"Score": 0.9995512366294861,
"Text": "the sponge"
},
{
"BeginOffset": 57,
"EndOffset": 74,
"Score": 0.9953102469444275,
"Text": "Nanny Oggs pantry"
},
{
"BeginOffset": 91,
"EndOffset": 98,
"Score": 0.9999185800552368,
"Text": "the ear"
},
{
"BeginOffset": 102,
"EndOffset": 111,
"Score": 0.9999034404754639,
"Text": "the troll"
},
{
"BeginOffset": 117,
"EndOffset": 125,
"Score": 0.9999624490737915,
"Text": "the tutu"
},
{
"BeginOffset": 137,
"EndOffset": 146,
"Score": 0.9999021887779236,
"Text": "the lumps"
},
{
"BeginOffset": 163,
"EndOffset": 172,
"Score": 0.9999018907546997,
"Text": "the pouch"
},
{
"BeginOffset": 178,
"EndOffset": 195,
"Score": 0.9992954134941101,
"Text": "the zombies razor"
}
],
"ResponseMetadata": {
"HTTPHeaders": {
"content-length": "765",
"content-type": "application/x-amz-json-1.1",
"date": "Mon, 28 Mar 2022 01:39:07 GMT",
"x-amzn-requestid": "5a9480c0-30f0-451a-859f-cc311c935f2a"
},
"HTTPStatusCode": 200,
"RequestId": "5a9480c0-30f0-451a-859f-cc311c935f2a",
"RetryAttempts": 0
}
}
End of DetectKeyPhrases