Пример #1
0
def predict(statement=[]):
    sentence = "".join(statement).split(" ")
    choices = []

    one = None
    two = None
    if len(sentence) > 1:
        length = len(
            autocomplete.predict_currword_given_lastword(
                sentence[-2], sentence[-1]))
        if length >= 1:
            one = autocomplete.predict_currword_given_lastword(
                sentence[-2], sentence[-1])[0]
        if length >= 2:
            two = autocomplete.predict_currword_given_lastword(
                sentence[-2], sentence[-1])[1]
    else:
        length = len(autocomplete.predict_currword(sentence[-1]))
        if length >= 1: one = autocomplete.predict_currword(sentence[-1])[0]
        if length >= 2: two = autocomplete.predict_currword(sentence[-1])[1]

    if one is not None: one = extract(one)
    if two is not None: two = extract(two)

    if one is not None: choices.append(one)
    else: choices.append("N/A")
    choices.append(sentence[-1])
    if two is not None: choices.append(two)
    else: choices.append("N/A")

    print " - ".join(choices)
    return choices
def predict_word(text, max_suggestions=10):
    if " " not in text:
        results = [
            x[0] for x in autocomplete.predict_currword(text.lower(),
                                                        top_n=max_suggestions)
        ]
    else:
        words = text.lower().split(" ")
        results = [
            x[0] for x in autocomplete.predict_currword_given_lastword(
                words[-2], words[-1], top_n=max_suggestions)
        ]
    return results
Пример #3
0
	def __init__(self, word, prev_word, num_choices):
		if prev_word is None:
			word_list = autocomplete.predict_currword(word,num_choice)
		else:
			tmp_wordlist1 = autocomplete.predict_currword(word,num_choice)
			tmp_wordlist2 = autocomplete.predict_currword_given_lastword(prev_word, word, num_choice)
			if len(tmp_wordlist1) > len(tmp_wordlist2):
				word_list = tmp_wordlist1
			else:
				word_list = tmp_wordlist2	
		self.w_size = len(word_list)
		for i in range(0, len(word_list)-1):
			(word_list[i])[1] = (len(word_list)/2 - 1)+((-1)^(i+1))*i
		self.make_wordTree(word_list)
def predict_character(text, max_suggestions=27):
    if " " not in text:
        results = autocomplete.predict_currword(text.lower(),
                                                top_n=max_suggestions)
        characters = [
            x[0][len(text)] if not x[0][len(text):] == "" else " "
            for x in results
        ]
    else:
        words = text.lower().split(" ")
        results = autocomplete.predict_currword_given_lastword(
            words[-2], words[-1], top_n=max_suggestions)
        characters = [
            x[0][len(words[-1])] if not x[0][len(words[-1]):] == "" else " "
            for x in results
        ]
    probabilities = [x[1] for x in results]
    character_dict = {}
    for character in range(len(characters)):
        character_dict[characters[character]] = sum([
            probabilities[x] for x in range(len(characters))
            if characters[character] == characters[x]
        ])
    return sorted(character_dict, key=character_dict.__getitem__, reverse=True)