File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 1
1
import sqlite3
2
- # import test_data
3
- # import ast
4
2
import json
5
3
6
4
class AutoComplete :
@@ -101,6 +99,22 @@ def train(self, sentence):
101
99
cur .execute ("UPDATE WordPrediction SET value = (?) WHERE name='predictions'" , (predictions ,))
102
100
return ("training complete" )
103
101
102
+ def predict (self , word ):
103
+ """
104
+ Returns - string
105
+ Input - string
106
+ ----------
107
+ Returns the completion word of the input word
108
+ - takes in a word
109
+ - retrieves the predictions map
110
+ - returns the completion word of the input word
111
+ """
112
+ cur = self .conn .cursor ()
113
+ predictions = cur .execute ("SELECT value FROM WordPrediction WHERE name='predictions'" ).fetchone ()[0 ]
114
+ predictions = json .loads (predictions )
115
+ completion_word = predictions [word .lower ()]['completion_word' ]
116
+ return completion_word
117
+
104
118
105
119
106
120
if __name__ == "__main__" :
@@ -109,4 +123,4 @@ def train(self, sentence):
109
123
all these new weapons in your arsenal, we would better get those profits fired up"
110
124
ac = AutoComplete ()
111
125
ac .train (input_ )
112
- # print(ac.predict("to"))
126
+ print (ac .predict ("to" ))
You can’t perform that action at this time.
0 commit comments