Exemplo n.º 1
0
def predictText( string):
    words = string.split(' ')
    if len(words[-1]) > 0: 
        w1 = word_predictor.correct(words[-1])
        w2 = words[-1] + 'ing'
        w3 = words[-1] + 'ed'
    else:
        rick = "never gonna give" # you up
        [w1,w2,w3] = rick.split(' ')
    return [w1, w2, w3]
Exemplo n.º 2
0
    def updatePredictiveText(self):
        ## Predictive text
        word = ((self.current_text).split(" "))[-1]  # Get only last word
        corrected_text = word_predictor.correct(word)

        ypos = keyboardPositionTop - (0) * (keyboardPositionTop / 5)
        xpos = 0 * width / 6 + width / 40
        temp0 = pyglet.text.Label(
            corrected_text[0],
            font_name="Courier New",
            font_size=keyboardFontSize,
            color=(keyboardFontColour[0], keyboardFontColour[1], keyboardFontColour[2], keyboardFontColour[3]),
            x=xpos,
            y=ypos,
            anchor_x="left",
            anchor_y="bottom",
        )

        ypos = keyboardPositionTop - (0) * (keyboardPositionTop / 5)
        xpos = 1 * width / 6 + width / 40
        temp1 = pyglet.text.Label(
            corrected_text[1],
            font_name="Courier New",
            font_size=keyboardFontSize,
            color=(keyboardFontColour[0], keyboardFontColour[1], keyboardFontColour[2], keyboardFontColour[3]),
            x=xpos,
            y=ypos,
            anchor_x="left",
            anchor_y="bottom",
        )

        ypos = keyboardPositionTop - (0) * (keyboardPositionTop / 5)
        xpos = 2 * width / 6 + width / 40
        temp2 = pyglet.text.Label(
            corrected_text[2],
            font_name="Courier New",
            font_size=keyboardFontSize,
            color=(keyboardFontColour[0], keyboardFontColour[1], keyboardFontColour[2], keyboardFontColour[3]),
            x=xpos,
            y=ypos,
            anchor_x="left",
            anchor_y="bottom",
        )

        for i in range(len(self.matrices)):  # Need to update for all matrices
            self.matrices[i][0][0] = temp0
            self.matrices[i][0][1] = temp1
            self.matrices[i][0][2] = temp2
            self.text[i][0][0] = corrected_text[0]
            self.text[i][0][1] = corrected_text[1]
            self.text[i][0][2] = corrected_text[2]
        return
Exemplo n.º 3
0
    def updatePredictiveText(self):
        ## Predictive text
        word = ((self.current_text).split(" "))[-1] # Get only last word
        if (len(word)>5): 
            word = word[0:5] # Limit the length of the word to predict so it won't slow things down
        corrected_text = word_predictor.correct(word)

        ypos = keyboardPositionTop - (0)*(keyboardPositionTop/6) - (keyboardPositionTop/6)/2
        xpos  = 0*width/6 + (width/6)/2
        temp0 = pyglet.text.Label(corrected_text[0], 
                font_name='Courier New',
                font_size=keyboardFontSize,
                color=(keyboardFontColour[0],keyboardFontColour[1],keyboardFontColour[2],keyboardFontColour[3]),
                x=xpos, y=ypos,
                anchor_x='center', anchor_y='center')
       
        ypos = keyboardPositionTop - (0)*(keyboardPositionTop/6) - (keyboardPositionTop/6)/2
        xpos  = 1*width/6 + (width/6)/2
        temp1 = pyglet.text.Label(corrected_text[1], 
                font_name='Courier New',
                font_size=keyboardFontSize,
                color=(keyboardFontColour[0],keyboardFontColour[1],keyboardFontColour[2],keyboardFontColour[3]),
                x=xpos, y=ypos,
                anchor_x='center', anchor_y='center')
        
        ypos = keyboardPositionTop - (0)*(keyboardPositionTop/6) - (keyboardPositionTop/6)/2
        xpos  = 2*width/6 + (width/6)/2
        temp2 = pyglet.text.Label(corrected_text[2], 
                font_name='Courier New',
                font_size=keyboardFontSize,
                color=(keyboardFontColour[0],keyboardFontColour[1],keyboardFontColour[2],keyboardFontColour[3]),
                x=xpos, y=ypos,
                anchor_x='center', anchor_y='center')

        for i in range(len(self.matrices)): # Need to update for all matrices
            self.matrices[i][0][0] = temp0
            self.matrices[i][0][1] = temp1
            self.matrices[i][0][2] = temp2
            self.text[i][0][0] = corrected_text[0]
            self.text[i][0][1] = corrected_text[1]
            self.text[i][0][2] = corrected_text[2]
        return
Exemplo n.º 4
0
    def process(self):  # Called on each box clock tick (this can be configured by right-clicking the box)

        if self.win.has_exit:
            self.endExperiment()
        else:
            self.win.dispatch_events()
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)  # Set up background

            self.current_text = self.current_text + self.text_input
            self.widget.caret.on_text(self.text_input)
            self.text_input = ""

            if self.keys[key.A]:
                self.text_input = self.alphabet[self.numberalph]
                self.current_text = self.current_text + self.text_input
                self.widget.caret.on_text(self.text_input)
                self.text_input = ""
                self.numberalph += 1
                self.numberalph = self.numberalph % 10

            ## Predictive text
            corrected_text = word_predictor.correct(self.current_text[1:].lower())
            ypos = keyboardPositionTop - (0) * (keyboardPositionTop / 5)
            xpos = 0 * width / 6
            temp0 = pyglet.text.Label(
                corrected_text[1].upper(),
                font_name="Courier New",
                font_size=keyboardFontSize,
                color=(keyboardFontColour[0], keyboardFontColour[1], keyboardFontColour[2], keyboardFontColour[3]),
                x=xpos,
                y=ypos,
                anchor_x="left",
                anchor_y="bottom",
            )

            ypos = keyboardPositionTop - (0) * (keyboardPositionTop / 5)
            xpos = 1 * width / 6
            temp1 = pyglet.text.Label(
                corrected_text[2].upper(),
                font_name="Courier New",
                font_size=keyboardFontSize,
                color=(keyboardFontColour[0], keyboardFontColour[1], keyboardFontColour[2], keyboardFontColour[3]),
                x=xpos,
                y=ypos,
                anchor_x="left",
                anchor_y="bottom",
            )

            ypos = keyboardPositionTop - (0) * (keyboardPositionTop / 5)
            xpos = 2 * width / 6
            temp2 = pyglet.text.Label(
                ".",
                font_name="Courier New",
                font_size=keyboardFontSize,
                color=(keyboardFontColour[0], keyboardFontColour[1], keyboardFontColour[2], keyboardFontColour[3]),
                x=xpos,
                y=ypos,
                anchor_x="left",
                anchor_y="bottom",
            )
            self.matrix[0][0] = temp0
            self.matrix[0][1] = temp1
            self.matrix[0][2] = temp2

            # Show a target for the first target
            if self.loopCounter <= targetDelay:
                if self.loopCounter == 0:
                    self.getNextTarget()
                    # self.sendOutput(2, self.target[0])
                    # self.sendOutput(2, self.target[1])
                    # Write NeuroSpell
                    self.text_input = self.alphabet[self.numberalph]
                    self.current_text = self.current_text + self.text_input
                    self.widget.caret.on_text(self.text_input)
                    self.text_input = ""
                    self.numberalph += 1
                    self.numberalph = self.numberalph % 10
                self.stopFlash(self.flash)
                self.target[0] = OVTK_StimulationId_Label_01
                self.target[1] = OVTK_StimulationId_Label_07
                # self.drawTarget(self.target[0], self.target[1])

            # Flash for the next 50 loops
            elif self.loopCounter <= targetDelay + 50:
                newStim = self.readFlash()
                # Aim row/column flash
                if 33025 <= newStim and newStim <= 33036:
                    self.flash = self.hashTable[newStim - OVTK_StimulationId_Label_00]
                # Start flash
                elif newStim == 32779:
                    self.startFlash(self.flash)
                # Stop flash
                elif newStim == 32780:
                    self.stopFlash(self.flash)

                # self.sendOutput(1, newStim)
                # Reset counter on last loop
                if self.loopCounter == targetDelay + 50:
                    self.loopCounter = -1

            # Draw keyboard matrix
            for r in range(0, len(self.matrix)):
                for c in range(0, len(self.matrix[r])):
                    self.matrix[r][c].draw()

            # Pyglet/GL updates
            self.batch.draw()

            self.win.flip()
            self.loopCounter += 1
        return