Exemplo n.º 1
0
def suggest(alp):
    autocomplete.load()
    l = autocomplete.predict('the', alp)
    i = 0
    while (i < 5 and i < len(l)):
        print(l[i][0])
        i = i + 1
Exemplo n.º 2
0
def test_fnc(seed_word = 'the',roughly_number_words=100 ):
    import autocomplete
    reload(autocomplete)
    from random import randint
    import string
    import random

    autocomplete.load()

    #the seed for the poem
    prior_word = seed_word

    #the prose you generate
    poem = prior_word

    for i in range(0,roughly_number_words):
        random_seed = random.choice(string.letters)
        x = randint(0,9)
        if x <= 1:
            poem = poem + '\n'
        else:
            new_prediction=autocomplete.predict(prior_word, random_seed)
            if len(new_prediction)>=1:
                y = randint(0,len(new_prediction)-1)
                new_word = new_prediction[y][0]
                poem = poem + ' ' + new_word

    print "\n\n****Words of inspiration:****\n\n"
    print poem
Exemplo n.º 3
0
 def __init__(self) -> None:
     # with open('../../data/PhraseSets/big_mackenzie2.txt', 'r') as myfile:
     #     autocomplete.models.train_models(myfile.read())
     autocomplete.load()
     super().__init__()
     self.checking_char_dict2list = {
         'q': ['a', 'z'],
         'a': ['q', 'z'],
         'z': ['a', 'q'],
         'w': ['s', 'x'],
         's': ['w', 'x'],
         'x': ['s', 'w'],
         'e': ['d', 'c'],
         'd': ['e', 'c'],
         'c': ['d', 'e'],
         'r': ['f', 'v'],
         'f': ['r', 'v'],
         'v': ['f', 'r'],
         't': ['g', 'b'],
         'g': ['t', 'b'],
         'b': ['g', 't'],
         'y': ['h', 'n'],
         'h': ['y', 'n'],
         'n': ['h', 'y'],
         'u': ['j', 'm'],
         'j': ['u', 'm'],
         'm': ['j', 'u'],
         'i': ['k'],
         'k': ['i'],
         'p': [],
         'o': ['l'],
         'l': ['o']
     }
Exemplo n.º 4
0
 def lastwords(self):
     autocomplete.load()
     if len(self._label.cget("text").split("_")) > 1:
         a = self._label.cget("text").split("_")[-2:]
         print(autocomplete.predict(a[0], a[1]))
         return autocomplete.predict(a[0], a[1])
     else:
         return [("", 1), ("", 1), ("", 1)]
Exemplo n.º 5
0
def autocomplete_word(text):
    try:
        autocomplete.load()
        autoword = autocomplete.predict_currword(text)
        autoword = re.sub(r'[^\w]', ' ', str(autoword[0]))
        autoword = re.sub(r'\d+', ' ', autoword)
        return True,autoword.strip()
    except:
        return False,"Can not predict word"
Exemplo n.º 6
0
def suggest_word(previous, current):
    """Given the previous word and the current partially typed
    word, suggest some possibilities for the word being typed.
    Returns a list of tuples containing the suggested word and
    the number of times it showed up as a followup in the training
    corpus.
    """
    if not suggest_word.is_loaded:  #Don't train more than once
        autocomplete.load()
        suggest_word.is_loaded = True
    return autocomplete.predict(previous, current)
def startup():
    autocomplete.load()
    return DEFAULTPREDICTION
Exemplo n.º 8
0
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.popup import Popup
from kivy.uix.button import Button
from kivy.uix.togglebutton import ToggleButton
from kivy.uix.textinput import TextInput
from kivy.uix.progressbar import ProgressBar
from kivy.properties import NumericProperty, ObjectProperty, StringProperty, \
                            BooleanProperty, OptionProperty, ListProperty, \
                            DictProperty

from collections import OrderedDict
import json

import autocomplete
autocomplete.load()

from src.components.LabTextInput import LabTextInput

__all__ = ('KeyboardToggleButton', 'NumericKeyboard', 'KeyboardButton')


class KeyboardButton(Button):
    '''
    Track Keyboard buttons.
    Color and other styles defined in `settings.kv`.
    '''
    pass


class KeyboardToggleButton(ToggleButton):
Exemplo n.º 9
0
    def test_load_models(self):
        import autocomplete

        is_loaded = autocomplete.load()
        self.assertTrue(is_loaded)
Exemplo n.º 10
0
if __name__ == '__main__':
    # setup logging
    logging.basicConfig(filename='logs/main_execution.log', filemode='w', level=logging.DEBUG)
    # init Arduino adapter
    my_adapter = ArduinoAdapter()
    # connect adapter and arduino
    my_adapter.connect()

    # init trie
    t9 = pred.Trie()
    # train trie
    training_set_location = "./training_sets/smsCorpus_en_2015.03.09_all.json"
    t9.json_train_adapter(training_set_location)

    # train swapnil model
    ac.load()

    # init tkinter main window
    root = tk.Tk()
    # init a text entry to store already typed text
    T = tk.Text(root, height=10, width=50)
    # init interactive entry
    entry = AutocompleteEntry(root,
#                              matchesFunction=t9.predict,
                              matchesFunction=autocomplete_predictor_wrapper,
                              arduino_adapter=my_adapter,
                              width=32)
    entry.grid(row=0, column=0)
    T.grid(column=0)
    root.mainloop()
Exemplo n.º 11
0
    def test_load_models(self):
        import autocomplete

        is_loaded = autocomplete.load()
        self.assertTrue(is_loaded)
Exemplo n.º 12
0
def test_autocomplete(beginning, letters):
    autocomplete.load()
    print(autocomplete.predict(beginning, letters))