def parse(self, source): """ parses a question source. Comments should be removed first""" # split according to the answer match = utils.reAnswer.match(source) if not match: # it is a description self.answers = pgans.Description(self) self._parseHead(source) else: self.tail = utils.stripMatch(match, 'tail') self._parseHead(match.group('head')) self.generalFeedback = utils.stripMatch(match, 'generalfeedback') # replace \n self.generalFeedback = re.sub(r'\\n', '\n', self.generalFeedback) self._parseAnswer(match.group('answer'))
def _parseNumericText(self, text): m = utils.reAnswerNumericInterval.match(text) if m: a = pgans.NumericAnswerMinMax(m) else: m = utils.reAnswerNumericValue.match(text) if m: a = pgans.NumericAnswer(m) else: self.valid = False return None a.feedback = utils.stripMatch(m, "feedback") return a
def __init__(self, match): if not match: return self.answer = match.group('answer').strip() self.feedback = stripMatch(match, "feedback") # At least one = sign => selects (radio buttons) self.select = match.group('sign') == "=" # fractions if match.group('fraction'): self.fraction = float(match.group('fraction')) else: if match.group('sign') == "=": self.fraction = 100 else: self.fraction = 0 # matching match = reMatch.match(self.answer) self.isMatching = match is not None if self.isMatching: self.answer = match.group('answer') self.question = match.group('question')
def _parseNumericAnswers(self, answer): self.numeric = True answers = [] for match in utils.reAnswerMultipleChoices.finditer(answer): a = self._parseNumericText(match.group('answer')) if not a: return # fractions if match.group('fraction'): a.fraction = float(match.group('fraction')) else: if match.group('sign') == "=": a.fraction = 100 else: a.fraction = 0 a.feedback = utils.stripMatch(match, "feedback") answers.append(a) if len(answers) == 0: a = self._parseNumericText(answer) if a: a.fraction = 100 answers.append(a) self.answers = pgans.NumericAnswerSet(self, answers)
def __init__(self, question, match): AnswerSet.__init__(self, question) self.answer = match.group('answer').startswith('T') self.feedbackWrong = stripMatch(match, "feedback") self.feedbackCorrect = stripMatch(match, "feedback2") self.cc_profile = 'TRUEFALSE'