protected function getMapResponseTemplateValidation() { $mapEntryValueMap = []; foreach ($this->responseDeclaration->getMapping()->getMapEntries() as $mapEntry) { /** @var MapEntry $mapEntry */ $mapEntryValueMap[] = ['key' => $this->hottextComponents[$mapEntry->getMapKey()], 'score' => $mapEntry->getMappedValue()]; } $combinations = ArrayUtil::combinations($mapEntryValueMap); $correctResponses = []; foreach ($combinations as $combination) { if (count($combination) > 0 && count($combination) <= $this->maxChoices) { $score = array_sum(array_column($combination, 'score')); $value = array_column($combination, 'key'); $correctResponses[] = new ValidResponse($score, $value); } } return ValidationBuilder::build('tokenhighlight', 'exactMatch', $correctResponses); }
protected function getMapResponseTemplateValidation() { $validResponses = []; foreach ($this->responseDeclaration->getMapping()->getMapEntries() as $mapEntry) { /** @var MapEntry $mapEntry */ if (!isset($this->options[$mapEntry->getMapKey()])) { LogService::log('Invalid choice `' . $mapEntry->getMapKey() . '`'); continue; } if ($mapEntry->getMappedValue() < 0) { LogService::log('Invalid score ` ' . $mapEntry->getMappedValue() . ' `. Negative score is ignored'); continue; } $validResponses[] = new ValidResponse($mapEntry->getMappedValue(), [$mapEntry->getMapKey()]); } // Handle `multiple` cardinality if ($this->responseDeclaration->getCardinality() === Cardinality::MULTIPLE) { $combinationChoicesCount = $this->maxChoices === 0 ? count($validResponses) : $this->maxChoices; $combinationResponses = ArrayUtil::combinations($validResponses, $combinationChoicesCount); $validResponses = ArrayUtil::combineValidResponsesWithSummedScore($combinationResponses); } return ValidationBuilder::build('mcq', 'exactMatch', $validResponses); }