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
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions backend/scripts/nlp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Question/No question lambda function documentation
// To be complete
zmagar marked this conversation as resolved.
Show resolved Hide resolved


API Endpoint: https://050l3ftzue.execute-api.us-west-2.amazonaws.com/default/ab-isQuestion

56 changes: 56 additions & 0 deletions backend/scripts/nlp/lambda_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
""" 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.download('punkt')





def lambda_handler(event=None, context=None):
sentence = "Who am I"
zmagar marked this conversation as resolved.
Show resolved Hide resolved
# sentence = event["sentence"]

print(sentence)
tokens = nltk.word_tokenize(sentence.lower())
tokenlist = ''
firstword = tokens[0]
print(firstword)
zmagar marked this conversation as resolved.
Show resolved Hide resolved

isQuestion = False



for s in tokens:
tokenlist += s

print(tokenlist)

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
print(isQuestion)

answer = ''
zmagar marked this conversation as resolved.
Show resolved Hide resolved
if (isQuestion):
answer = 'This is a question'
else:
answer = "This is not a question"

return answer
# return {
# 'statusCode': 200,
# 'answer': answer
# # 'body': json.dumps(answer)
# }
print(lambda_handler())