-
Notifications
You must be signed in to change notification settings - Fork 2
/
Version_2.0
203 lines (172 loc) · 5.7 KB
/
Version_2.0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import sqlite3
import nltk
def connectDB():
connect = sqlite3.connect('data.sqlite')
cur = connect.cursor()
return connect, cur
connect, cur = connectDB()
def Noun(word, cur):
cur.execute('select rowid from words where noun1 IS NULL and new = 1;')
d = cur.fetchone()
if d:
cur.execute('update words set noun1=? where rowid=?;', (word, d[0]))
return
cur.execute('select rowid from words where noun2 IS NULL and new = 1;')
d = cur.fetchone()
if d:
cur.execute('update words set noun2=? where rowid=?;', (word, d[0]))
return
cur.execute('select rowid from words where noun3 IS NULL and new = 1;')
d = cur.fetchone()
if d:
cur.execute('update words set noun3=? where rowid=?;', (word, d[0]))
return
cur.execute('select rowid from words where noun4 IS NULL and new = 1;')
d = cur.fetchone()
if d:
cur.execute('update words set noun4=? where rowid=?;', (word, d[0]))
return
def Adjective(word,cur):
cur.execute('select rowid from words where adj1 IS NULL and new = 1;')
d = cur.fetchone()
if d:
cur.execute('update words set adj1=? where rowid=?;', (word, d[0]))
return
cur.execute('select rowid from words where adj2 IS NULL and new = 1;')
d = cur.fetchone()
if d:
cur.execute('update words set adj2=? where rowid=?;', (word, d[0]))
return
cur.execute('select rowid from words where adj3 IS NULL and new = 1;')
d = cur.fetchone()
if d:
cur.execute('update words set adj3=? where rowid=?;', (word, d[0]))
return
def Modal(word,cur):
cur.execute('select rowid from words where modal IS NULL and new = 1;')
d = cur.fetchone()
if d:
cur.execute('update words set modal=? where rowid=?;', (word, d[0]))
return
def Verb(word,cur):
cur.execute('select rowid from words where verb1 IS NULL and new = 1;')
d = cur.fetchone()
if d:
cur.execute('update words set verb1=? where rowid=?;', (word, d[0]))
return
cur.execute('select rowid from words where verb2 IS NULL and new = 1;')
d = cur.fetchone()
if d:
cur.execute('update words set verb2=? where rowid=?;', (word, d[0]))
return
cur.execute('select rowid from words where verb3 IS NULL and new = 1;')
d = cur.fetchone()
if d:
cur.execute('update words set verb3=? where rowid=?;', (word, d[0]))
return
def wh(word,cur):
cur.execute('select rowid from words where wh IS NULL and new = 1;')
d = cur.fetchone()
if d:
cur.execute('update words set wh=? where rowid=?', (word, d[0]))
return
def Adverb(word,cur):
cur.execute('select rowid from words where adv1 IS NULL and new = 1;')
d = cur.fetchone()
if d:
cur.execute('update words set adv1=? where rowid=?;', (word, d[0]))
return
cur.execute('select rowid from words where adv2 IS NULL and new = 1;')
d = cur.fetchone()
if d:
cur.execute('update words set adv2=? where rowid=?;', (word, d[0]))
return
flag = 0
pal = 'Hello'
li1 = [pal]
user = ''
print('Pal: ', pal)
print('You: ')
user = input()
li = [user]
cats = { 'N' : Noun,
'J' : Adjective,
'M' : Modal,
'V' : Verb,
'W' : wh,
'R' : Adverb,
'P' : Noun,
}
i=1resp = resp[0]
print('Pal: ', resp)
while (i):
cur.execute('SELECT Response FROM sents WHERE Input=?;', li)
flag = 0
resp = cur.fetchone()
if not resp:
wordlist = nltk.word_tokenize(user)
worddict = nltk.pos_tag(wordlist)
worddict = set(worddict)
worddict = dict(worddict)
wordlist = list(worddict.keys())
index = 0
cur.execute('insert into words (new) values (1);')
while(index<len(wordlist)):
#cur.execute('select rowid from words where new = 1;')
#Id = cur.fetchone()
#Id = Id[0]
word = wordlist[index]
char = worddict[word]
char = char[0]
if char[0] not in cats.keys():
index = index+1
continue
cats[char](word, cur)
index = index+1
connect.commit()
#cur.execute('select * from words where rowid = 2')
cur.execute('select rowid from words where new=1;')
m = cur.fetchone()
m = m[0]
cur.execute('update words set new = ? where rowid=?', (0, m))
connect.commit()
i = 0
'''cur.execute('SELECT rowid FROM sents WHERE Input=?;', li1)
d = cur.fetchone()
flag = 3
if not d:
cur.execute('SELECT Input FROM sents WHERE Response IS NULL;')
resp = cur.fetchone()
flag = 1
cur.execute('INSERT INTO sents (Input) VALUES (?);', li)
if resp == None:
resp = 'Let us change the topic.'
flag = 2
if flag==0:
li1 = [resp]
if flag==3:
d = d[0]
cur.execute('UPDATE sents SET Response =? WHERE rowid=?', (user, d))
cur.execute('SELECT Input FROM sents WHERE Response IS NULL;')
resp = cur.fetchone()
#cur.execute('INSERT INTO sents (Input) VALUES (?);', li)
if resp == None:
resp = 'Let us change the topic.'
li1 = ['']
else:
resp = resp[0]
li1 = [resp]
print('Pal: ', resp)
if flag==1:
resp = resp[0]
print('Pal: ', resp)
li1 = [resp]
if flag==2:
print('Pal: ', resp)
li1 = ['']
print('You: ')
user = input().lower()
#print(flag)
li = [user]
connect.commit()'''
connect.close()