q&a working
This commit is contained in:
parent
4623fe2884
commit
09a4b427c2
3 changed files with 35 additions and 766 deletions
|
|
@ -1,728 +0,0 @@
|
||||||
hi /nboo /n
|
|
||||||
|
|
||||||
test
|
|
||||||
test2
|
|
||||||
test123
|
|
||||||
Testing exit code
|
|
||||||
boo
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
test
|
|
||||||
testing
|
|
||||||
joe
|
|
||||||
fred
|
|
||||||
fras
|
|
||||||
/usr/local/bin/python3 "/Volumes/GoogleDrive-100976413726208790908/My Drive/UNI/INFS 2048 - System Design and Realisation/Assessment 2B/main.py"
|
|
||||||
h
|
|
||||||
test
|
|
||||||
hello
|
|
||||||
/usr/local/bin/python3 "/Volumes/GoogleDrive-100976413726208790908/My Drive/UNI/INFS 2048 - System Design and Realisation/Assessment 2B/main.py"
|
|
||||||
/usr/local/bin/python3 "/Volumes/GoogleDrive-100976413726208790908/My Drive/UNI/INFS 2048 - System Design and Realisation/Assessment 2B/main.py"
|
|
||||||
/usr/local/bin/python3 "/Volumes/GoogleDrive-100976413726208790908/My Drive/UNI/INFS 2048 - System Design and Realisation/Assessment 2B/main.py"
|
|
||||||
/usr/local/bin/python3 "/Volumes/GoogleDrive-100976413726208790908/My Drive/UNI/INFS 2048 - System Design and Realisation/Assessment 2B/main.py"
|
|
||||||
/usr/local/bin/python3 "/Volumes/GoogleDrive-100976413726208790908/My Drive/UNI/INFS 2048 - System Design and Realisation/Assessment 2B/main.py"
|
|
||||||
/usr/local/bin/python3 "/Volumes/GoogleDrive-100976413726208790908/My Drive/UNI/INFS 2048 - System Design and Realisation/Assessment 2B/main.py"
|
|
||||||
/usr/local/bin/python3 "/Volumes/GoogleDrive-100976413726208790908/My Drive/UNI/INFS 2048 - System Design and Realisation/Assessment 2B/main.py"
|
|
||||||
hello
|
|
||||||
is
|
|
||||||
me
|
|
||||||
you
|
|
||||||
/usr/local/bin/python3 "/Volumes/GoogleDrive-100976413726208790908/My Drive/UNI/INFS 2048 - System Design and Realisation/Assessment 2B/main.py"
|
|
||||||
test 2
|
|
||||||
test 3
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test 2
|
|
||||||
/usr/local/bin/python3 "/Volumes/GoogleDrive-100976413726208790908/My Drive/UNI/INFS 2048 - System Design and Realisation/Assessment 2B/main.py"
|
|
||||||
test
|
|
||||||
test 1
|
|
||||||
test 2
|
|
||||||
test 3
|
|
||||||
test 1
|
|
||||||
test
|
|
||||||
test 2
|
|
||||||
test 3
|
|
||||||
test 4
|
|
||||||
hello
|
|
||||||
/usr/local/bin/python3 "/Volumes/GoogleDrive-100976413726208790908/My Drive/UNI/INFS 2048 - System Design and Realisation/Assessment 2B/main.py"
|
|
||||||
test 1
|
|
||||||
test 2
|
|
||||||
test 3
|
|
||||||
what is the weather like today
|
|
||||||
how are you
|
|
||||||
what is your name
|
|
||||||
4
faq.json
4
faq.json
|
|
@ -6,5 +6,9 @@
|
||||||
{
|
{
|
||||||
"question": "What is the weather like today?",
|
"question": "What is the weather like today?",
|
||||||
"answer": "Same as yesterday."
|
"answer": "Same as yesterday."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"question": "What is your birthday?",
|
||||||
|
"answer": "April."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
69
main.py
69
main.py
|
|
@ -1,24 +1,32 @@
|
||||||
import json
|
import json
|
||||||
print("Hello, I am a question answering bot.\n")
|
|
||||||
#question = str(input("Please enter a question, and press the ENTER key:\n"))
|
def jaccard_similarity(userQuestion, questionBank):
|
||||||
#if question.isalpha():
|
s1 = set(userQuestion)
|
||||||
# print ("I think that you asked " + (question))
|
s2 = set(questionBank)
|
||||||
# # Open the file in append & read mode ('a+')
|
return float(len(s1.intersection(s2)) / len(s1.union(s2)))
|
||||||
# with open("asked_questions_log.txt", "a+") as file_object:
|
|
||||||
# # Move read cursor to the start of file.
|
def most_likely(userQuestion):
|
||||||
# file_object.seek(0)
|
likelihoodScore = []
|
||||||
# # If file is not empty then append '\n'
|
fileObject = open("faq.json", "r")
|
||||||
# data = file_object.read(100)
|
jsonContent = fileObject.read()
|
||||||
# if len(data) > 0 :
|
aList = json.loads(jsonContent)
|
||||||
# file_object.write("\n")
|
for json_object in aList:
|
||||||
# # Append text at the end of file
|
likelihoodScore.append(jaccard_similarity(userQuestion, json_object['question']))
|
||||||
# file_object.write(question)
|
#print(likelihoodScore)
|
||||||
userQuestion = ''
|
|
||||||
while True:
|
mostLikelyIndex = likelihoodScore.index(max(likelihoodScore))
|
||||||
#question = input('')
|
mostLikely = aList[mostLikelyIndex]
|
||||||
userQuestion = input('Please enter a question, and press the ENTER key: ').strip()
|
|
||||||
|
return mostLikely
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print("Hello, I am a question answering bot.\n")
|
||||||
|
userQuestion = ''
|
||||||
|
while True:
|
||||||
|
userQuestion = input('Please enter a question, and press the ENTER key: \n').strip()
|
||||||
if userQuestion:
|
if userQuestion:
|
||||||
print ("I think that you asked " + (userQuestion))
|
likelyQuestion = most_likely(userQuestion)
|
||||||
|
print ("I think that you asked " + "'" + (likelyQuestion['question']) + "'" + " and conclude that the answer is " + "'" + (likelyQuestion['answer']) + "'.\n")
|
||||||
# Open the file in append & read mode ('a+')
|
# Open the file in append & read mode ('a+')
|
||||||
with open("asked_questions_log.txt", "a+") as file_object:
|
with open("asked_questions_log.txt", "a+") as file_object:
|
||||||
file_object.seek(0) # Move read cursor to the start of file.
|
file_object.seek(0) # Move read cursor to the start of file.
|
||||||
|
|
@ -27,26 +35,11 @@ while True:
|
||||||
# Append text at the end of file
|
# Append text at the end of file
|
||||||
file_object.write("\n")
|
file_object.write("\n")
|
||||||
file_object.write(userQuestion)
|
file_object.write(userQuestion)
|
||||||
|
|
||||||
|
|
||||||
else :
|
else :
|
||||||
print ("Goodbye!")
|
print ("Goodbye!")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
#else:
|
if __name__ == "__main__":
|
||||||
# sys.exit()
|
main()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#def jaccard_similarity(list1, list2):
|
|
||||||
# s1 = set(list1)
|
|
||||||
# s2 = set(list2)
|
|
||||||
# return float(len(s1.intersection(s2)) / len(s1.union(s2)))
|
|
||||||
#list1 = ['dog', 'cat', 'cat', 'rat']
|
|
||||||
#list2 = ['dog', 'cat', 'mouse']
|
|
||||||
#jaccard_similarity(list1, list2)
|
|
||||||
|
|
||||||
|
|
||||||
#with open('faq.json', 'r') as f:
|
|
||||||
# questionBank = json.load(f)
|
|
||||||
|
|
||||||
# Output json file for testing
|
|
||||||
#print(questionBank)
|
|
||||||
Loading…
Reference in a new issue