@param OpenQuestion $question
@param string       $answer

@return CorrectedAnswer
186903
public function correctAnswer(AbstractItem $question, $answer)
    {
        $corrected = new CorrectedAnswer();
        foreach ($question->getKeywords() as $keyword) {
            if ($this->containKeyword($answer, $keyword)) {
                if (0 < $keyword->getScore()) {
                    $corrected->addExpected($keyword);
                } else {
                    $corrected->addUnexpected($keyword);
                }
            } elseif (0 < $keyword->getScore()) {
                $corrected->addMissing($keyword);
            }
        }

        return $corrected;
    }
1350997
protected function question(string $question, $default = null)
	{
		return (new Question($this->input, $this->output))->ask($question, $default);
	}
184290
protected function askWithForcedAnswers($question, $answers)
	{
		// Ask the question
		do $answer = $this->ask($question.' ('.implode('|', $answers).')');

		// Continue to ask the question until we get a valid answer
		while (!in_array($answer, $answers));

		// Return the answer
		return $answer;
	}
257900
protected function askYn( $question ) {
		$answer = $this->ask( $question .' [Y/n] ');
		while ( ! in_array( strtolower( $answer ), [ 'y', 'n', 'yes', 'no' ] ) ) {
			$answer = $this->ask('Please choose either yes or no. ');
		}
		return in_array( strtolower( $answer ), [ 'y', 'yes' ] );
	}
64469
protected function ask($question, $default = null)
    {
        $defaultComment = '';
        
        if ($default !== null) {
            $defaultComment = ' [<comment>' . $default . '</comment>]';
        }
        
        $question = preg_replace('/(?:(\?)\s*$|(\?)?\s+$)|(?<!\s|\?)$/', $defaultComment . '$1 ', $question);
        
        return $this->io->ask($question, $default);
    }
913505
public function validateAnswer($answer, AbstractItem $question, array $options = [])
    {
        $options[Validation::QUESTION] = $question;

        return $this->getAnswerValidator()->validate($answer, $options);
    }
223183
private function parseXML($answer)
    {
        // Disable default error handling of SimpleXML (Do not throw E_WARNINGs).
        libxml_use_internal_errors(true);
        libxml_clear_errors();
        try {
            return new \SimpleXMLElement($answer);
        } catch (\Exception $e) {
            // Invalid xml format. This happens in case OpenWeatherMap returns an error.
            // OpenWeatherMap always uses json for errors, even if one specifies xml as format.
            $error = json_decode($answer, true);
            if (isset($error['message'])) {
                throw new OWMException($error['message'], isset($error['cod']) ? $error['cod'] : 0);
            } else {
                throw new OWMException('Unknown fatal error: OpenWeatherMap returned the following json object: ' . $answer);
            }
        }
    }
129295
public function ask($question)
    {
        //Show required message
        echo "\n";
        echo "\t", $this->colorize($question, 'info');
        echo "\n";
        //Get user input
        echo "\t"; $response = trim(fgets(STDIN));

        return $response;
    }
259801
public function update(Item $question, Answer $answer, array $answerData, $noFlush = false)
    {
        $errors = $this->validator->validate($answerData, [Validation::QUESTION => $question->getInteraction()]);
        if (count($errors) > 0) {
            throw new InvalidDataException('Answer is not valid', $errors);
        }

        // Update Answer with new data
        $this->serializer->deserialize($answerData, $answer);

        // Save to DB
        $this->om->persist($answer);

        if (!$noFlush) {
            $this->om->flush();
        }

        return $answer;
    }
11378
public function process_essay($quest, &$questions) {

        $question = $this->process_common($quest);
        $question->qtype = 'essay';

        $question->feedback = array();
        // Not sure where to get the correct answer from?
        foreach ($quest->feedback as $feedback) {
            // Added this code to put the possible solution that the
            // instructor gives as the Moodle answer for an essay question.
            if ($feedback->ident == 'solution') {
                $question->graderinfo = $this->cleaned_text_field($feedback->text);
            }
        }
        // Added because essay/questiontype.php:save_question_option is expecting a
        // fraction property - CT 8/10/06.
        $question->fraction[] = 1;
        $question->defaultmark = 1;
        $question->responseformat = 'editor';
        $question->responserequired = 1;
        $question->responsefieldlines = 15;
        $question->attachments = 0;
        $question->attachmentsrequired = 0;
        $question->responsetemplate = $this->text_field('');

        $questions[] = $question;
    }
1148370
private function askForPassword($question)
    {
        $questionHelper = new QuestionHelper();

        $question = new Question($question);
        $question->setHidden(true);
        $question->setHiddenFallback(false);

        $password = $questionHelper->ask($this->input, $this->output, $question);
        $this->output->writeln('');

        return $password;
    }
346079
function (question, answer) {
  var choiceValues = _.map(question.choices, 'value');
  var choiceIndex = choiceValues.indexOf(answer);

  // Check if answer is not equal to default value
  if (question.default !== choiceIndex) {
    return true;
  }

  return false;
}
69282
public function ask(SimpleQuestion $question)
    {
        return $this->question->ask(
            $this->input,
            $this->output,
            new Question(
                $this->buildQuestionText($question),
                $this->getPreResponse($question)
            )
        );
    }
1327465
public function setAnswer(\Lyon1\Bundle\PoobleBundle\Entity\SurveyAnswer $answer = null)
    {
        $this->answer = $answer;

        return $this;
    }
685368
public function serialize(OpenQuestion $openQuestion, array $options = [])
    {
        $serialized = [
            'contentType' => 'text',
            'maxLength' => $openQuestion->getAnswerMaxLength(),
        ];

        if (in_array(Transfer::INCLUDE_SOLUTIONS, $options)) {
            $serialized['solutions'] = [];
        }

        return $serialized;
    }
831829
protected function data_preprocessing_answers($question, $withanswerfiles = false) {
        if (empty($question->options->answers)) {
            return $question;
        }

        $key = 0;
        foreach ($question->options->answers as $answer) {
            if ($withanswerfiles) {
                // Prepare the feedback editor to display files in draft area.
                $draftitemid = file_get_submitted_draft_itemid('answer['.$key.']');
                $question->answer[$key]['text'] = file_prepare_draft_area(
                    $draftitemid,          // Draftid
                    $this->context->id,    // context
                    'question',            // component
                    'answer',              // filarea
                    !empty($answer->id) ? (int) $answer->id : null, // itemid
                    $this->fileoptions,    // options
                    $answer->answer        // text.
                );
                $question->answer[$key]['itemid'] = $draftitemid;
                $question->answer[$key]['format'] = $answer->answerformat;
            } else {
                $question->answer[$key] = $answer->answer;
            }

            $question->fraction[$key] = 0 + $answer->fraction;
            $question->feedback[$key] = array();

            // Evil hack alert. Formslib can store defaults in two ways for
            // repeat elements:
            //   ->_defaultValues['fraction[0]'] and
            //   ->_defaultValues['fraction'][0].
            // The $repeatedoptions['fraction']['default'] = 0 bit above means
            // that ->_defaultValues['fraction[0]'] has already been set, but we
            // are using object notation here, so we will be setting
            // ->_defaultValues['fraction'][0]. That does not work, so we have
            // to unset ->_defaultValues['fraction[0]'].
            unset($this->_form->_defaultValues["fraction[{$key}]"]);

            // Prepare the feedback editor to display files in draft area.
            $draftitemid = file_get_submitted_draft_itemid('feedback['.$key.']');
            $question->feedback[$key]['text'] = file_prepare_draft_area(
                $draftitemid,          // Draftid
                $this->context->id,    // context
                'question',            // component
                'answerfeedback',      // filarea
                !empty($answer->id) ? (int) $answer->id : null, // itemid
                $this->fileoptions,    // options
                $answer->feedback      // text.
            );
            $question->feedback[$key]['itemid'] = $draftitemid;
            $question->feedback[$key]['format'] = $answer->feedbackformat;
            $key++;
        }

        // Now process extra answer fields.
        $extraanswerfields = question_bank::get_qtype($question->qtype)->extra_answer_fields();
        if (is_array($extraanswerfields)) {
            // Omit table name.
            array_shift($extraanswerfields);
            $question = $this->data_preprocessing_extra_answer_fields($question, $extraanswerfields);
        }

        return $question;
    }
1142690
protected function expandQuestion($question, $questions) {
        if ($question->qtype == 'randomsamatch') {
            $subquestions = [];
            foreach ($questions as $otherquestion) {
                if ($otherquestion->qtype == 'shortanswer') {
                    foreach ($otherquestion->answers as $answer) {
                        if (intval($answer->fraction) === 1) {
                            array_push(
                                $subquestions, 
                                (object) [
                                    "id" => $answer->id,
                                    "questiontext" => $otherquestion->questiontext,
                                    "answertext" => $answer->answer
                                ]
                            );
                            // Only take the first correct answer because that's what Moodle does. 
                            break;
                        }
                    }
                } 
            }

            $question->match = (object) [
             'subquestions' => $subquestions
            ];
        }
        return $question;
    }