Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Python-Chatbot/MyDictionary.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
44 lines (41 sloc)
1.55 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''Data referenced from https://apps.worldwritable.com/tutorials/chatbot/ ''' | |
# Sentences for responding the user | |
MyDictionary={ | |
"GREETING_KEYWORDS":["hello", "hi", "greetings", "sup", "what's up"], | |
"GREETING_RESPONSES":["'sup bro", "hey", "*nods*", "hey you get my snap?"], | |
"REFUSE":["no","nah","not"], | |
"AGREE":["yes","sure","agreed","why not"], | |
"EMOTION_POSITIVE":["happy","thrilled","enjoyed","yo","high spirits"], | |
"EMOTION_NEGATIVE":["sad","blue","dissatisfied","heck","hell no"] | |
} | |
'''Referenced data ends here''' | |
def ref(category): | |
catName=[] | |
for j,k in MyDictionary.items(): #listing a whole dictionary | |
catName.append(j) | |
for i in catName: | |
if (category.upper()).strip() == i: | |
return i | |
if (category.upper()).strip() not in catName: | |
return False | |
'''Function checks if a value is in a specified dictionary''' | |
def isRef(word): | |
try: | |
for j,k in MyDictionary.items(): #listing a whole dictionary | |
for i in k: #looping through the dictionary | |
for p in word.split(): | |
if (p.lower()).strip()==i: | |
return True | |
else: | |
continue | |
continue | |
continue | |
except: | |
print("Invalid input!") | |
print("Type of i: ",type(i),";type of p: ",type(p)) | |
else: | |
return False | |
'''Debugger''' | |
#print(isRef(input("Test a word: "))) | |
#print(ref(input("Test a word: "))) | |
'''Debugger ends here''' |