33
44# # Meet Robo: your friend
55
6- # In[3]:
7-
8-
96import nltk
107
11-
12- # In[ ]:
13-
14-
158# nltk.download() # for downloading packages
169
17-
18- # In[1]:
19-
20-
2110import numpy as np
2211import random
2312import string # to process standard python strings
2413
2514
26- # In[4]:
27-
28-
2915f = open ('corpus.txt' ,'r' ,errors = 'ignore' )
3016raw = f .read ()
3117raw = raw .lower ()# converts to lowercase
3521word_tokens = nltk .word_tokenize (raw )# converts to list of words
3622
3723
38- # In[5]:
39-
40-
4124sent_tokens [:2 ]
4225
4326
44- # In[6]:
45-
46-
4727word_tokens [:5 ]
4828
4929
50- # In[7]:
51-
52-
5330lemmer = nltk .stem .WordNetLemmatizer ()
5431def LemTokens (tokens ):
5532 return [lemmer .lemmatize (token ) for token in tokens ]
@@ -58,15 +35,10 @@ def LemNormalize(text):
5835 return LemTokens (nltk .word_tokenize (text .lower ().translate (remove_punct_dict )))
5936
6037
61- # In[8]:
62-
63-
6438GREETING_INPUTS = ("hello" , "hi" , "greetings" , "sup" , "what's up" ,"hey" ,)
6539GREETING_RESPONSES = ["hi" , "hey" , "*nods*" , "hi there" , "hello" , "I am glad! You are talking to me" ]
6640
6741
68- # In[9]:
69-
7042
7143# Checking for greetings
7244def greeting (sentence ):
@@ -76,16 +48,10 @@ def greeting(sentence):
7648 return random .choice (GREETING_RESPONSES )
7749
7850
79- # In[10]:
80-
81-
8251from sklearn .feature_extraction .text import TfidfVectorizer
8352from sklearn .metrics .pairwise import cosine_similarity
8453
8554
86- # In[11]:
87-
88-
8955# Generating response
9056def response (user_response ):
9157 robo_response = ''
@@ -104,9 +70,6 @@ def response(user_response):
10470 return robo_response
10571
10672
107- # In[12]:
108-
109-
11073flag = True
11174print ("ROBO: My name is Robo. I will answer your queries about Chatbots. If you want to exit, type Bye!" )
11275
0 commit comments