Skip to content

Commit c55bc6a

Browse files
committed
added predict method and comments
1 parent e91a13a commit c55bc6a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

AutoComplete_App/backend.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import sqlite3
2-
# import test_data
3-
# import ast
42
import json
53

64
class 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

106120
if __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"))

0 commit comments

Comments
 (0)