def filter_search(string): output = [] category = "other" terms = string.split() for term in terms: lower_term = term.lower() if lower_term in TYPES: if lower_term == "beer" or lower_term == "wine" or lower_term == "spirits" or lower_term == "cider": output.append(("Type: " + lower_term, "Category: " + category)) elif lower_term in SPIRITS: category = "spirits" output.append(("Type: " + lower_term, "Category: " + category)) else: output.append(("Type: " + lower_term, "Category: " + category)) return output # at this point none of the search terms are spirits, beer/wine/cider. Autocorrect words to check. for term in terms: corrected_term = SpellChecker().correction(term) lower_term = corrected_term.lower() if lower_term in TYPES: if lower_term == "beer" or lower_term == "wine" or lower_term == "spirits" or lower_term == "cider": output.append(("Type: " + lower_term, "Category: " + category)) elif lower_term in SPIRITS: category = "spirits" output.append(("Type: " + lower_term, "Category: " + category)) else: output.append(("Type: " + lower_term, "Category: " + category)) return output # at this point no type or category has been found. Check for other terms like mL sizes???-> how would we handle? return "No alcohol specifications found."
def nlpcode(pred_var, mode, pred_text, pred_word, pred_list, hog_w, hog_sw, hog_l, engine, hog_mod): cf = 0 if mode == 0: print(pred_var) pred_list.append(pred_var) elif mode == 1: print(pred_var) pred_list.append(pred_var) if len(pred_list) == 20: max_char = max(pred_list, key=pred_list.count) print(pred_list) if max_char == '#': mode = (mode + 1) % 2 if (mode == 0): hog_mod.setText("Mode:" + "\n" + "Alphabet" + "\n" + "(Alphabets,Space," + "\n" + "Switch,End sign)") else: hog_mod.setText("Mode:" + "\n" + "Number" + "\n" + "(Numbers,End Sign)") print(mode) print('#################....... MODE CHANGE .......##############') else: if max_char == ' ': #pred_text='' if not pred_word.isnumeric(): #pred_word = nlpmod.correction(pred_word.lower()) #pred_word = TextBlob(pred_word.lower()).correct() #pred_word=str(pred_word) pred_word = SpellChecker().correction(pred_word.lower()) print('Correction Done') pred_text += pred_word pred_text += ' ' hog_sw.setText("Corrected Word:" + "\n" + pred_word) pred_word = '' print('Corrected : ............' + pred_text + '............') elif max_char == '&': hog_w.setText("Recognized Word:" + "\n" + pred_word) #pred_word = nlpmod.correction(pred_word.lower()) #pred_word = TextBlob(pred_word.lower()).correct() #pred_word=str(pred_word) pred_word = SpellChecker().correction(pred_word.lower()) pred_text += pred_word print('..........' + pred_word + '...........') hog_sw.setText("Corrected Word:" + "\n" + pred_word) print(pred_text) engine.say(str(pred_text)) engine.runAndWait() hog_l.setText("Sentence: " + pred_text) pred_word = '' pred_text = '' pred_list = [] cf = 1 else: pred_word += max_char print('..........' + pred_word + '...........') hog_w.setText("Recognized Word:" + "\n" + pred_word) pred_list = [] pred_list = [] hog_l.setText("Sentence: " + pred_text) return mode, pred_text, pred_word, pred_list