-
Notifications
You must be signed in to change notification settings - Fork 330
Expand file tree
/
Copy pathlambda_comprehend.py
More file actions
35 lines (27 loc) · 904 Bytes
/
lambda_comprehend.py
File metadata and controls
35 lines (27 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
-*- coding: utf-8 -*-
========================
AWS Lambda
========================
Contributor: Chirag Rathod (Srce Cde)
========================
"""
import boto3
from pprint import pprint
def lambda_handler(event, context):
s3 = boto3.client("s3")
bucket = "bucket-name"
key = "filename.txt"
file = s3.get_object(Bucket=bucket, Key=key)
paragraph = str(file["Body"].read())
comprehend = boto3.client("comprehend")
# Extracting sentiments using comprehend
sentiment = comprehend.detect_sentiment(Text=paragraph, LanguageCode="en")
print(sentiment)
# Extracting entities using comprehend
entities = comprehend.detect_entities(Text=paragraph, LanguageCode="en")
pprint(entities)
# Extracting keyphrase using comprehend
keyphrase = comprehend.detect_key_phrases(Text=paragraph, LanguageCode="en")
pprint(keyphrase)
return "Thanks"