Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question / no question lambda function and the endpoint #171

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions backend/scripts/nlp/lambda_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
""" This is a copy of the Lambda function that was uploaded to AWS, it is not intended to run locally
and it will not work without modification"""

import json
import nltk
import requests
nltk.data.path.append("/tmp")

nltk.download('punkt', download_dir="/tmp")





def lambda_handler(event, context):
answer = {}
invalidReq = False
try:
sentence = event["sentence"]
except:
answer = {
"error": "not a valid input"
}
invalidReq = True
if not invalidReq:

tokens = nltk.word_tokenize(sentence.lower())
tokenlist = ''
firstword = tokens[0]

isQuestion = False



for s in tokens:
tokenlist += s



if '?' in tokenlist:
isQuestion = True

wh_question = ['what', 'when', 'where', 'who',
'whom', 'which', 'whose', 'why', 'how']
yN_question = ["am", "is", "are", "do", "does", "did", "have", "has", "was", "were", "can", "cannot", "could",
"couldn't", "dare", "may", "might", "must", "need", "ought", "shall", "should", "shouldn't", "will", "would"]

if firstword in wh_question or firstword in yN_question:
isQuestion = True

answer = False
if (isQuestion):
answer = True


return {
'answer': answer
}