My scenario, I am trying to get particular AWS S3 stored text file
word count
and its language detection
using AWS lambda
python code. Here, below code I am trying. It is providing line count but I don't know how to get word count and language detection. Please provide some idea for get file word count and language detection.
I tried for line count
import boto3
def lambda_handler(event, context):
# create the s3 resource
s3 = boto3.resource('s3')
# get the file object
obj = s3.Object('bucket name', 'sample.txt')
# read the file contents in memory
file_contents = obj.get()["Body"].read()
# print the occurrences of the new line character to get the number of lines
# print file_contents.count('\n')
# TODO implement
return {
'Line Count': file_contents.count('\n')
}
Current Response: { "Line Count": 48, }
Expected Response: { "Line Count": 48, "Word Count": : ?, // Here I want to show word count "Language": ? // Here language name }