def secondCheck(main_string, current_position): result = {"website_word": "", "remaining": ""} website_words = get_current_flows(current_position) if website_words is None: result['website_word'] = None result['remaining'] = main_string return result score = 0 website_word_id = None main_string = ps.stem(main_string + " ") for id, word in website_words.items(): current_score = 0 current_score += similarity(word["command"], main_string) current_score += SequenceMatcher(None, main_string.lower(), word["command"].lower()).ratio() current_score = current_score / 2 if current_score > score and current_score > 0.15: if (id == -1 or id == 0) and current_score < 0.30: pass score = current_score website_word_id = str(id) if score != 0 and website_word_id is not None: result['website_word'] = website_word_id result['remaining'] = "" return result else: result['website_word'] = None result['remaining'] = main_string return result
def getAction(message): accuracy = {} for k, v in common_actions.items(): local_accuracy = [] for line in v: local_accuracy.append(similarity(message, line)) accuracy[k] = max(local_accuracy) accuracy = sorted(accuracy.items(), key=lambda x: x[1], reverse=True) action = accuracy[0] return action
def getSimilar(flows, word): similar_words = [] for k, v in flows.items(): score = similarity(v["command"], word) # print(l,word,score) if score > 0.25: similar_words.append(k) if len(similar_words) < 1: similar_words = list(flows.keys()) return similar_words