Skip to content

Commit bec8b88

Browse files
authored
Update chatbot.py
1 parent cf252cf commit bec8b88

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

chatbot.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,42 @@
11

2-
# coding: utf-8
3-
4-
# # Meet Robo: your friend
2+
#Meet Robo: your friend
53

4+
#import necessary libraries
65
import io
76
import random
87
import string # to process standard python strings
98
import warnings
10-
9+
import numpy as np
1110
from sklearn.feature_extraction.text import TfidfVectorizer
1211
from sklearn.metrics.pairwise import cosine_similarity
1312

14-
import numpy as np
15-
1613
import nltk
1714
from nltk.stem import WordNetLemmatizer
18-
19-
warnings.filterwarnings("ignore")
20-
2115
nltk.download('popular', quiet=True) # for downloading packages
22-
# Includes the following already.
16+
17+
# uncomment the following only the first time
2318
#nltk.download('punkt') # first-time use only
2419
#nltk.download('wordnet') # first-time use only
2520

21+
22+
#Reading in the corpus
2623
with open('chatbot.txt','r', encoding='utf8', errors ='ignore') as fin:
2724
raw = fin.read().lower()
2825

26+
#Calculating the tokens
2927
sent_tokens = nltk.sent_tokenize(raw)# converts to list of sentences
3028
word_tokens = nltk.word_tokenize(raw)# converts to list of words
3129

32-
3330
sent_tokens[:2]
34-
35-
3631
word_tokens[:5]
3732

38-
3933
lemmer = WordNetLemmatizer()
4034
def LemTokens(tokens):
4135
return [lemmer.lemmatize(token) for token in tokens]
4236
remove_punct_dict = dict((ord(punct), None) for punct in string.punctuation)
4337
def LemNormalize(text):
4438
return LemTokens(nltk.word_tokenize(text.lower().translate(remove_punct_dict)))
4539

46-
4740
GREETING_INPUTS = ("hello", "hi", "greetings", "sup", "what's up","hey",)
4841
GREETING_RESPONSES = ["hi", "hey", "*nods*", "hi there", "hello", "I am glad! You are talking to me"]
4942

@@ -57,8 +50,6 @@ def greeting(sentence):
5750
return random.choice(GREETING_RESPONSES)
5851

5952

60-
61-
6253
# Generating response
6354
def response(user_response):
6455
robo_response=''
@@ -80,7 +71,6 @@ def response(user_response):
8071

8172
flag=True
8273
print("ROBO: My name is Robo. I will answer your queries about Chatbots. If you want to exit, type Bye!")
83-
8474
while(flag==True):
8575
user_response = input()
8676
user_response=user_response.lower()

0 commit comments

Comments
 (0)