def loadLibraries(self):
     # loads a new object, thus only runs at the start of a new quiz
     self.idleMode = False
     self.vocabBuilder = VocabBuilder(
     )  # new object of VocabBuilder created
     self.vocabBuilder.loadQuestion()
     self.progressLabel.text = str(self.vocabBuilder.currentWord) + "/100"
     self.questionLabel.text = self.vocabBuilder.question
     self.aLabel.text = self.vocabBuilder.answers[0]
     self.bLabel.text = self.vocabBuilder.answers[1]
     self.cLabel.text = self.vocabBuilder.answers[2]
     self.dLabel.text = self.vocabBuilder.answers[3]
     self.eLabel.text = self.vocabBuilder.answers[4]
示例#2
0
 def iwslt15Test(start="<START>", end="<END>", unknown="<UNKNOWN>"):
     from VocabBuilder import VocabBuilder
     sourceVocab, targetVocab = VocabBuilder.iwslt15(start=start,
                                                     end=end,
                                                     unknown=unknown)
     source = []
     import io
     with io.open("datasets/iwslt15/tst2012.en", mode="r",
                  encoding="utf-8") as f:
         lines = f.readlines()
         source = [line.split() for line in lines]
     target = []
     with io.open("datasets/iwslt15/tst2012.vi", mode="r",
                  encoding="utf-8") as f:
         lines = f.readlines()
         target = [line.split() for line in lines]
     return (Tokens2Indices(sourceVocab=sourceVocab,
                            targetVocab=targetVocab,
                            source=source,
                            target=target).map(start=None,
                                               end=None,
                                               unknown="<UNKNOWN>"),
             (sourceVocab[start], sourceVocab[end], sourceVocab[unknown],
              len(sourceVocab)), (targetVocab[start], targetVocab[end],
                                  targetVocab[unknown], len(targetVocab)))
 def loadLibraries(self):
         # loads a new object, thus only runs at the start of a new quiz
         self.idleMode = False
         self.vocabBuilder = VocabBuilder() # new object of VocabBuilder created
         self.vocabBuilder.loadQuestion()
         self.progressLabel.text = str(self.vocabBuilder.currentWord) + "/100"
         self.questionLabel.text = self.vocabBuilder.question
         self.aLabel.text = self.vocabBuilder.answers[0]
         self.bLabel.text = self.vocabBuilder.answers[1]
         self.cLabel.text = self.vocabBuilder.answers[2]
         self.dLabel.text = self.vocabBuilder.answers[3]
         self.eLabel.text = self.vocabBuilder.answers[4]
 def showTopScore(self):
     # aka IDLE MODE
     self.vocabBuilder = VocabBuilder()
     self.idleMode = True
     self.progressLabel = self.ids['progress_label']
     self.statusLabel = self.ids['status_label']
     self.scoreLabel = self.ids['score_label']
     self.questionLabel = self.ids['question_label']
     self.titleLabel = self.ids['title_label']
     self.aLabel = self.ids['a_label']
     self.bLabel = self.ids['b_label']
     self.cLabel = self.ids['c_label']
     self.dLabel = self.ids['d_label']
     self.eLabel = self.ids['e_label']
     self.progressLabel.text = "100/100"
     self.questionLabel.text = "Top Score: " + str(
         self.vocabBuilder.highScore)
     self.statusLabel.text = ""
     self.titleLabel.text = "100 Words Every Graduate Should Know"
     self.aLabel.text = "press any button to start..."
     self.bLabel.text = ""
     self.cLabel.text = ""
     self.dLabel.text = ""
     self.eLabel.text = ""
 def showTopScore(self):
         # aka IDLE MODE
         self.vocabBuilder = VocabBuilder()
         self.idleMode = True
         self.progressLabel = self.ids['progress_label']
         self.statusLabel = self.ids['status_label']
         self.scoreLabel = self.ids['score_label']
         self.questionLabel = self.ids['question_label']
         self.titleLabel = self.ids['title_label']
         self.aLabel = self.ids['a_label']
         self.bLabel = self.ids['b_label']
         self.cLabel = self.ids['c_label']
         self.dLabel = self.ids['d_label']
         self.eLabel = self.ids['e_label']
         self.progressLabel.text = "100/100"
         self.questionLabel.text = "Top Score: " + str(self.vocabBuilder.highScore)
         self.statusLabel.text = ""
         self.titleLabel.text = "100 Words Every Graduate Should Know"
         self.aLabel.text = "press any button to start..."
         self.bLabel.text = ""
         self.cLabel.text = ""
         self.dLabel.text = ""
         self.eLabel.text = ""
class ExternalLayout(BoxLayout):
        
        def loadLibraries(self):
                # loads a new object, thus only runs at the start of a new quiz
                self.idleMode = False
                self.vocabBuilder = VocabBuilder() # new object of VocabBuilder created
                self.vocabBuilder.loadQuestion()
                self.progressLabel.text = str(self.vocabBuilder.currentWord) + "/100"
                self.questionLabel.text = self.vocabBuilder.question
                self.aLabel.text = self.vocabBuilder.answers[0]
                self.bLabel.text = self.vocabBuilder.answers[1]
                self.cLabel.text = self.vocabBuilder.answers[2]
                self.dLabel.text = self.vocabBuilder.answers[3]
                self.eLabel.text = self.vocabBuilder.answers[4]
                
        def showTopScore(self):
                # aka IDLE MODE
                self.vocabBuilder = VocabBuilder()
                self.idleMode = True
                self.progressLabel = self.ids['progress_label']
                self.statusLabel = self.ids['status_label']
                self.scoreLabel = self.ids['score_label']
                self.questionLabel = self.ids['question_label']
                self.titleLabel = self.ids['title_label']
                self.aLabel = self.ids['a_label']
                self.bLabel = self.ids['b_label']
                self.cLabel = self.ids['c_label']
                self.dLabel = self.ids['d_label']
                self.eLabel = self.ids['e_label']
                self.progressLabel.text = "100/100"
                self.questionLabel.text = "Top Score: " + str(self.vocabBuilder.highScore)
                self.statusLabel.text = ""
                self.titleLabel.text = "100 Words Every Graduate Should Know"
                self.aLabel.text = "press any button to start..."
                self.bLabel.text = ""
                self.cLabel.text = ""
                self.dLabel.text = ""
                self.eLabel.text = ""

        def chooseAnswer(self, reply, *args):
                # if the user was in idleMode and they clicked a button
                # then load up a new session
                if self.idleMode:
                        self.statusLabel.text = ""
                        self.idleMode = False
                        self.loadLibraries()
                
                # if the user is not in idle mode
                # then run this ElSE block
                else:
                        print self.vocabBuilder.currentWord
                        self.progressLabel.text = str(self.vocabBuilder.currentWord + 1) + "/100"
                        self.vocabBuilder.addScore(int(reply) - 1)

                        # if answer correct display CORRECT on screen
                        if (self.vocabBuilder.isCorrect(int(reply) - 1)):
                                print 'Correct'
                                self.titleLabel.text = "[color=00ff08]Correct[/color] "  + self.vocabBuilder.question + " = \n" + self.vocabBuilder.answer
                                self.scoreLabel.text = str(self.vocabBuilder.getScore()) + " correct"
                                
                        # if answer is incorrect display INCORRECT on screen
                        else:
                                print 'Incorrect'
                                print 'Answer', self.vocabBuilder.answer
                                print 'Current score', str(self.vocabBuilder.getScore())
                                self.titleLabel.text = "[color=ff0000]Incorrect[/color] " + self.vocabBuilder.question + " = \n" + self.vocabBuilder.answer
                                self.scoreLabel.text = str(self.vocabBuilder.getScore()) + " correct"

                        # when there are no more questions display score, save score
                        # and go to idle mode
                        if self.vocabBuilder.noMoreLeft():
                                # Thu Oct  8 16:19:35 AEDT 2015
                                #TODO go to the scores screen
                                print 'Questions correct', str(self.vocabBuilder.getScore()), 'out of 100'
                                self.vocabBuilder.saveHighScore()
                                self.showTopScore() # this is idle mode

                        # if there are more questions to go, load a new question
                        else:
                                self.vocabBuilder.loadQuestion() # this loads the new questions
                                # the actual answer is stored in self.vocabBuilder.answer
                                self.questionLabel.text = self.vocabBuilder.question
                                self.aLabel.text = self.vocabBuilder.answers[0]
                                self.bLabel.text = self.vocabBuilder.answers[1]
                                self.cLabel.text = self.vocabBuilder.answers[2]
                                self.dLabel.text = self.vocabBuilder.answers[3]
                                self.eLabel.text = self.vocabBuilder.answers[4]
class ExternalLayout(BoxLayout):
    def loadLibraries(self):
        # loads a new object, thus only runs at the start of a new quiz
        self.idleMode = False
        self.vocabBuilder = VocabBuilder(
        )  # new object of VocabBuilder created
        self.vocabBuilder.loadQuestion()
        self.progressLabel.text = str(self.vocabBuilder.currentWord) + "/100"
        self.questionLabel.text = self.vocabBuilder.question
        self.aLabel.text = self.vocabBuilder.answers[0]
        self.bLabel.text = self.vocabBuilder.answers[1]
        self.cLabel.text = self.vocabBuilder.answers[2]
        self.dLabel.text = self.vocabBuilder.answers[3]
        self.eLabel.text = self.vocabBuilder.answers[4]

    def showTopScore(self):
        # aka IDLE MODE
        self.vocabBuilder = VocabBuilder()
        self.idleMode = True
        self.progressLabel = self.ids['progress_label']
        self.statusLabel = self.ids['status_label']
        self.scoreLabel = self.ids['score_label']
        self.questionLabel = self.ids['question_label']
        self.titleLabel = self.ids['title_label']
        self.aLabel = self.ids['a_label']
        self.bLabel = self.ids['b_label']
        self.cLabel = self.ids['c_label']
        self.dLabel = self.ids['d_label']
        self.eLabel = self.ids['e_label']
        self.progressLabel.text = "100/100"
        self.questionLabel.text = "Top Score: " + str(
            self.vocabBuilder.highScore)
        self.statusLabel.text = ""
        self.titleLabel.text = "100 Words Every Graduate Should Know"
        self.aLabel.text = "press any button to start..."
        self.bLabel.text = ""
        self.cLabel.text = ""
        self.dLabel.text = ""
        self.eLabel.text = ""

    def chooseAnswer(self, reply, *args):
        # if the user was in idleMode and they clicked a button
        # then load up a new session
        if self.idleMode:
            self.statusLabel.text = ""
            self.idleMode = False
            self.loadLibraries()

        # if the user is not in idle mode
        # then run this ElSE block
        else:
            print self.vocabBuilder.currentWord
            self.progressLabel.text = str(self.vocabBuilder.currentWord +
                                          1) + "/100"
            self.vocabBuilder.addScore(int(reply) - 1)

            # if answer correct display CORRECT on screen
            if (self.vocabBuilder.isCorrect(int(reply) - 1)):
                print 'Correct'
                self.titleLabel.text = "[color=00ff08]Correct[/color] " + self.vocabBuilder.question + " = \n" + self.vocabBuilder.answer
                self.scoreLabel.text = str(
                    self.vocabBuilder.getScore()) + " correct"

            # if answer is incorrect display INCORRECT on screen
            else:
                print 'Incorrect'
                print 'Answer', self.vocabBuilder.answer
                print 'Current score', str(self.vocabBuilder.getScore())
                self.titleLabel.text = "[color=ff0000]Incorrect[/color] " + self.vocabBuilder.question + " = \n" + self.vocabBuilder.answer
                self.scoreLabel.text = str(
                    self.vocabBuilder.getScore()) + " correct"

            # when there are no more questions display score, save score
            # and go to idle mode
            if self.vocabBuilder.noMoreLeft():
                # Thu Oct  8 16:19:35 AEDT 2015
                #TODO go to the scores screen
                print 'Questions correct', str(
                    self.vocabBuilder.getScore()), 'out of 100'
                self.vocabBuilder.saveHighScore()
                self.showTopScore()  # this is idle mode

            # if there are more questions to go, load a new question
            else:
                self.vocabBuilder.loadQuestion(
                )  # this loads the new questions
                # the actual answer is stored in self.vocabBuilder.answer
                self.questionLabel.text = self.vocabBuilder.question
                self.aLabel.text = self.vocabBuilder.answers[0]
                self.bLabel.text = self.vocabBuilder.answers[1]
                self.cLabel.text = self.vocabBuilder.answers[2]
                self.dLabel.text = self.vocabBuilder.answers[3]
                self.eLabel.text = self.vocabBuilder.answers[4]