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 11import sqlite3
2- # import test_data
3- # import ast
42import json
53
64class AutoComplete :
@@ -101,6 +99,22 @@ def train(self, sentence):
10199 cur .execute ("UPDATE WordPrediction SET value = (?) WHERE name='predictions'" , (predictions ,))
102100 return ("training complete" )
103101
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+
104118
105119
106120if __name__ == "__main__" :
@@ -109,4 +123,4 @@ def train(self, sentence):
109123 all these new weapons in your arsenal, we would better get those profits fired up"
110124 ac = AutoComplete ()
111125 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