Skip to content

Commit fb658d0

Browse files
authored
Update chatbot.py
1 parent a0bcf3e commit fb658d0

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

chatbot.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,23 @@
2525
with open('chatbot.txt','r', encoding='utf8', errors ='ignore') as fin:
2626
raw = fin.read().lower()
2727

28-
#Calculating the tokens
28+
#TOkenisation
2929
sent_tokens = nltk.sent_tokenize(raw)# converts to list of sentences
3030
word_tokens = nltk.word_tokenize(raw)# converts to list of words
3131

32-
sent_tokens[:2]
33-
word_tokens[:5]
34-
32+
# Preprocessing
3533
lemmer = WordNetLemmatizer()
3634
def LemTokens(tokens):
3735
return [lemmer.lemmatize(token) for token in tokens]
3836
remove_punct_dict = dict((ord(punct), None) for punct in string.punctuation)
3937
def LemNormalize(text):
4038
return LemTokens(nltk.word_tokenize(text.lower().translate(remove_punct_dict)))
4139

40+
41+
# Keyword Matching
4242
GREETING_INPUTS = ("hello", "hi", "greetings", "sup", "what's up","hey",)
4343
GREETING_RESPONSES = ["hi", "hey", "*nods*", "hi there", "hello", "I am glad! You are talking to me"]
4444

45-
46-
47-
# Checking for greetings
4845
def greeting(sentence):
4946
"""If user's input is a greeting, return a greeting response"""
5047
for word in sentence.split():

0 commit comments

Comments
 (0)