3
3
4
4
# # Meet Robo: your friend
5
5
6
- # In[3]:
7
-
8
-
9
6
import nltk
10
7
11
-
12
- # In[ ]:
13
-
14
-
15
8
# nltk.download() # for downloading packages
16
9
17
-
18
- # In[1]:
19
-
20
-
21
10
import numpy as np
22
11
import random
23
12
import string # to process standard python strings
24
13
25
14
26
- # In[4]:
27
-
28
-
29
15
f = open ('corpus.txt' ,'r' ,errors = 'ignore' )
30
16
raw = f .read ()
31
17
raw = raw .lower ()# converts to lowercase
35
21
word_tokens = nltk .word_tokenize (raw )# converts to list of words
36
22
37
23
38
- # In[5]:
39
-
40
-
41
24
sent_tokens [:2 ]
42
25
43
26
44
- # In[6]:
45
-
46
-
47
27
word_tokens [:5 ]
48
28
49
29
50
- # In[7]:
51
-
52
-
53
30
lemmer = nltk .stem .WordNetLemmatizer ()
54
31
def LemTokens (tokens ):
55
32
return [lemmer .lemmatize (token ) for token in tokens ]
@@ -58,15 +35,10 @@ def LemNormalize(text):
58
35
return LemTokens (nltk .word_tokenize (text .lower ().translate (remove_punct_dict )))
59
36
60
37
61
- # In[8]:
62
-
63
-
64
38
GREETING_INPUTS = ("hello" , "hi" , "greetings" , "sup" , "what's up" ,"hey" ,)
65
39
GREETING_RESPONSES = ["hi" , "hey" , "*nods*" , "hi there" , "hello" , "I am glad! You are talking to me" ]
66
40
67
41
68
- # In[9]:
69
-
70
42
71
43
# Checking for greetings
72
44
def greeting (sentence ):
@@ -76,16 +48,10 @@ def greeting(sentence):
76
48
return random .choice (GREETING_RESPONSES )
77
49
78
50
79
- # In[10]:
80
-
81
-
82
51
from sklearn .feature_extraction .text import TfidfVectorizer
83
52
from sklearn .metrics .pairwise import cosine_similarity
84
53
85
54
86
- # In[11]:
87
-
88
-
89
55
# Generating response
90
56
def response (user_response ):
91
57
robo_response = ''
@@ -104,9 +70,6 @@ def response(user_response):
104
70
return robo_response
105
71
106
72
107
- # In[12]:
108
-
109
-
110
73
flag = True
111
74
print ("ROBO: My name is Robo. I will answer your queries about Chatbots. If you want to exit, type Bye!" )
112
75
0 commit comments