Exemplo n.º 1
0
 def _makeNormalQuestion(self, qChoice):
     nWrong = self.numAnsOptions - self.numCorrect
     # Answer Options = [Wrong Answers] + [Correct Answers]
     wAns = sample(qChoice['wrongAnswers'], size=nWrong)
     cAns = sample(qChoice['answers'], size=self.numCorrect)
     # The correct answers always appear first
     ansOpts = cAns + wAns
     self._nextQuestion.answerOptions = ansOpts
     self._nextQuestion.answer = range(self.numCorrect)
     return self._nextQuestion
 def _makeNormalQuestion(self, qChoice):
     nWrong = self.numAnsOptions - self.numCorrect
     # Answer Options = [Wrong Answers] + [Correct Answers]
     wAns = sample(qChoice['wrongAnswers'], size=nWrong)
     cAns = sample(qChoice['answers'], size=self.numCorrect)
     # The correct answers always appear first
     ansOpts = cAns + wAns
     self._nextQuestion.answerOptions = ansOpts
     self._nextQuestion.answer = range(self.numCorrect)
     return self._nextQuestion
Exemplo n.º 3
0
 def getNextQuestion(self):
     qChoices = self._getQChoices()
     qChoice = sample(qChoices)
     qChoice = dict(zip(['title', 'body', 'answers', 'explanation', 'wrongAnswers'], qChoice))
     # Decide what kind of question to make
     if self.useNAC:
         # Choose one of AOTA, NOTA, combo or normal based on their frequencies
         freqs = [self.AOTAFreq, self.NOTAFreq, self.comboFreq, self.normalFreq]
         nacToUse = sample(['AOTA', 'NOTA', 'combo', 'normal'], p=freqs)
         question = self._makeQuestion(qChoice, qType=nacToUse)
     else:
         question = self._makeQuestion(qChoice)
     self.questionID += 1
     return question
 def _makeXOTAQuestion(self, qChoice, qType):
     nAnsOpts = self.numAnsOptions
     if self.extraAnswerNAC:
         nAnsOpts += 1
     if qType == 'AOTA':
         ansList = qChoice['answers']
         ansText = self.AOTAtext
     elif qType == 'NOTA':
         ansList = qChoice['wrongAnswers']
         ansText = self.NOTAtext
     else:
         raise ValueError('qType must be one of "NOTA" or "AOTA"')
     # Decide if the XOTA option is the correct answer
     cAnsIndex = random.randint(nAnsOpts)
     # If the correct answer is not the last answer, then
     # the question is a 'normal' question with an extra
     # option at the end
     if cAnsIndex != nAnsOpts - 1:
         # Temporarily modify self.numAnsOptions so
         # _makeNormalQuestion does not make the wrong
         # number of options
         nAnsOptsCopy = self.numAnsOptions
         self.numAnsOptions = nAnsOpts - 1
         question = self._makeNormalQuestion(qChoice)
         self.numAnsOptions = nAnsOptsCopy
         question.answerOptions += [ansText]
         return question
     else:  #If the last answer is correct, then XOTA option is correct
         nAns = nAnsOpts - 1
         ansOpts = sample(ansList, size=nAns)
         ansOpts += [ansText]
         self._nextQuestion.answerOptions = ansOpts
         # AOTA/NOTA is the last answer option
         self._nextQuestion.answer = [len(ansOpts) - 1]
         return self._nextQuestion
Exemplo n.º 5
0
 def _makeXOTAQuestion(self, qChoice, qType):
     nAnsOpts = self.numAnsOptions
     if self.extraAnswerNAC:
         nAnsOpts += 1
     if qType=='AOTA':
         ansList = qChoice['answers']
         ansText = self.AOTAtext
     elif qType=='NOTA':
         ansList = qChoice['wrongAnswers']
         ansText = self.NOTAtext
     else:
         raise ValueError('qType must be one of "NOTA" or "AOTA"')
     # Decide if the XOTA option is the correct answer
     cAnsIndex = random.randint(nAnsOpts)
     # If the correct answer is not the last answer, then
     # the question is a 'normal' question with an extra
     # option at the end
     if cAnsIndex != nAnsOpts - 1:
         # Temporarily modify self.numAnsOptions so
         # _makeNormalQuestion does not make the wrong
         # number of options
         nAnsOptsCopy = self.numAnsOptions
         self.numAnsOptions = nAnsOpts - 1
         question = self._makeNormalQuestion(qChoice)
         self.numAnsOptions = nAnsOptsCopy
         question.answerOptions += [ansText]
         return question
     else:  #If the last answer is correct, then XOTA option is correct
         nAns = nAnsOpts - 1
         ansOpts = sample(ansList, size=nAns)
         ansOpts += [ansText]
         self._nextQuestion.answerOptions = ansOpts
         # AOTA/NOTA is the last answer option
         self._nextQuestion.answer = [len(ansOpts) - 1]
         return self._nextQuestion
 def _makeComboQuestion(self, qChoice):
     nAnsOpts = self.numAnsOptions
     if self.extraAnswerNAC:
         nAnsOpts += 1
     cAnsIndex = random.randint(nAnsOpts)
     # If the correct answer is not the last answer, then
     # the question is a 'normal' question with an extra
     # option at the end
     if cAnsIndex != nAnsOpts - 1:
         # Temporarily modify self.numAnsOptions so
         # _makeNormalQuestion does not make the wrong
         # number of options
         nAnsOptsCopy = self.numAnsOptions
         self.numAnsOptions = nAnsOpts - 1
         question = self._makeNormalQuestion(qChoice)
         self.numAnsOptions = nAnsOptsCopy
         # Modify the answer text to indicate random options
         ansOptIndices = sample(range(nAnsOpts - 1), self.numComboAnswers)
         ansOptIndices.sort()
         ansText = self._getComboAnsText(ansOptIndices)
         question.answerOptions += [ansText]
         return question
     nAns = nAnsOpts - 1
     nWAns = nAns - self.numComboAnswers
     cAns = sample(qChoice['answers'], self.numComboAnswers)
     wAns = sample(qChoice['wrongAnswers'], nWAns)
     ansOpts = cAns + wAns
     # Shuffle the answer options, keep track of the correct answers
     ansOptsIndices = range(len(ansOpts))
     random.shuffle(ansOptsIndices)
     cAnsIndices = []
     # Find the correct answer indices, they are the first len(cAns) items
     for i in range(len(cAns)):
         cAnsIndices += [ansOptsIndices.index(i)]
     cAnsIndices.sort()
     # Shuffle the answers according to ansOptsIndices
     ansOptsShuffled = list(ansOpts)  # Make a copy
     for i in range(len(ansOptsIndices)):
         ansOptsShuffled[i] = ansOpts[ansOptsIndices[i]]
     ansOpts = ansOptsShuffled
     # Modify the answer text to indicate where the correct answers are
     ansText = self._getComboAnsText(cAnsIndices)
     ansOpts += [ansText]
     self._nextQuestion.answerOptions = ansOpts
     self._nextQuestion.answer = [len(ansOpts) - 1]
     return self._nextQuestion
Exemplo n.º 7
0
 def _makeComboQuestion(self, qChoice):
     nAnsOpts = self.numAnsOptions
     if self.extraAnswerNAC:
         nAnsOpts += 1
     cAnsIndex = random.randint(nAnsOpts)
     # If the correct answer is not the last answer, then
     # the question is a 'normal' question with an extra
     # option at the end
     if cAnsIndex != nAnsOpts - 1:
         # Temporarily modify self.numAnsOptions so
         # _makeNormalQuestion does not make the wrong
         # number of options
         nAnsOptsCopy = self.numAnsOptions
         self.numAnsOptions = nAnsOpts - 1
         question = self._makeNormalQuestion(qChoice)
         self.numAnsOptions = nAnsOptsCopy
         # Modify the answer text to indicate random options
         ansOptIndices = sample(range(nAnsOpts-1), self.numComboAnswers)
         ansOptIndices.sort()
         ansText = self._getComboAnsText(ansOptIndices)
         question.answerOptions += [ansText]
         return question
     nAns = nAnsOpts - 1
     nWAns = nAns - self.numComboAnswers
     cAns = sample(qChoice['answers'], self.numComboAnswers)
     wAns = sample(qChoice['wrongAnswers'], nWAns)
     ansOpts = cAns + wAns
     # Shuffle the answer options, keep track of the correct answers
     ansOptsIndices = range(len(ansOpts))
     random.shuffle(ansOptsIndices)
     cAnsIndices = []
     # Find the correct answer indices, they are the first len(cAns) items
     for i in range(len(cAns)):
         cAnsIndices += [ansOptsIndices.index(i)]
     cAnsIndices.sort()
     # Shuffle the answers according to ansOptsIndices
     ansOptsShuffled = list(ansOpts) # Make a copy
     for i in range(len(ansOptsIndices)):
         ansOptsShuffled[i] = ansOpts[ansOptsIndices[i]]
     ansOpts = ansOptsShuffled
     # Modify the answer text to indicate where the correct answers are
     ansText = self._getComboAnsText(cAnsIndices)
     ansOpts += [ansText]
     self._nextQuestion.answerOptions = ansOpts
     self._nextQuestion.answer = [len(ansOpts) - 1]
     return self._nextQuestion
 def getNextQuestion(self):
     qChoices = self._getQChoices()
     qChoice = sample(qChoices)
     qChoice = dict(
         zip(['title', 'body', 'answers', 'explanation', 'wrongAnswers'],
             qChoice))
     # Decide what kind of question to make
     if self.useNAC:
         # Choose one of AOTA, NOTA, combo or normal based on their frequencies
         freqs = [
             self.AOTAFreq, self.NOTAFreq, self.comboFreq, self.normalFreq
         ]
         nacToUse = sample(['AOTA', 'NOTA', 'combo', 'normal'], p=freqs)
         question = self._makeQuestion(qChoice, qType=nacToUse)
     else:
         question = self._makeQuestion(qChoice)
     self.questionID += 1
     return question
Exemplo n.º 9
0
 def getNextQuestion(self):
     '''
     Generates a new question, and returns it as a Question object. Then increments questionID.
     '''
     q = Question()
     qChoices = self._getQChoices()
     c = sample(qChoices)
     q.title = c[0]
     q.body = c[1]
     q.answer = c[2]
     q.explanation = c[3]
     q.id = self.questionID
     self.questionID += 1
     return q
Exemplo n.º 10
0
 def getNextQuestion(self):
     '''
     Generates a new question, and returns it as a Question object. Then increments questionID.
     '''
     q = Question()
     qChoices = self._getQChoices()
     c = sample(qChoices)
     q.title = c[0]
     q.body = c[1]
     q.answer = c[2]
     q.explanation = c[3]
     q.id = self.questionID
     self.questionID += 1
     return q