use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project OpenOLAT by OpenOLAT.
the class KPrimAssessmentItemBuilder method extractCorrectResponse.
private void extractCorrectResponse() {
associations = new HashMap<>();
if (matchInteraction != null) {
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(matchInteraction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
List<FieldValue> values = correctResponse.getFieldValues();
for (FieldValue value : values) {
SingleValue sValue = value.getSingleValue();
if (sValue instanceof DirectedPairValue) {
DirectedPairValue dpValue = (DirectedPairValue) sValue;
Identifier sourceId = dpValue.sourceValue();
Identifier destinationId = dpValue.destValue();
associations.put(sourceId, destinationId);
}
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method appendAssociationMatchResponseDeclaration.
public static ResponseDeclaration appendAssociationMatchResponseDeclaration(ResponseDeclaration responseDeclaration, Map<Identifier, List<Identifier>> associations) {
responseDeclaration.setCardinality(Cardinality.MULTIPLE);
responseDeclaration.setBaseType(BaseType.DIRECTED_PAIR);
// correct response
CorrectResponse correctResponse = new CorrectResponse(responseDeclaration);
responseDeclaration.setCorrectResponse(correctResponse);
for (Map.Entry<Identifier, List<Identifier>> association : associations.entrySet()) {
Identifier sourceChoiceId = association.getKey();
List<Identifier> targetChoiceIds = association.getValue();
for (Identifier targetChoiceId : targetChoiceIds) {
DirectedPairValue dpValue = new DirectedPairValue(sourceChoiceId, targetChoiceId);
FieldValue fValue = new FieldValue(correctResponse, dpValue);
correctResponse.getFieldValues().add(fValue);
}
}
return responseDeclaration;
}
use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project OpenOLAT by OpenOLAT.
the class CSVToAssessmentItemConverter method processChoice_match.
private void processChoice_match(String[] parts, MatchAssessmentItemBuilder matchBuilder) {
List<SimpleAssociableChoice> targetChoices = matchBuilder.getTargetChoices();
if (targetChoices == null || targetChoices.isEmpty()) {
for (int i = 1; i < parts.length; i++) {
String answer = parts[i];
SimpleAssociableChoice choice = AssessmentItemFactory.createSimpleAssociableChoice(answer, matchBuilder.getTargetMatchSet());
targetChoices.add(choice);
}
} else {
String answer = parts[0];
if (StringHelper.containsNonWhitespace(answer)) {
SimpleAssociableChoice sourceChoice = AssessmentItemFactory.createSimpleAssociableChoice(answer, matchBuilder.getSourceMatchSet());
matchBuilder.getSourceChoices().add(sourceChoice);
// correct answer and points
for (int i = 1; i < parts.length && i < (targetChoices.size() + 1); i++) {
double point = parseFloat(parts[i], 0.0f);
SimpleAssociableChoice targetChoice = targetChoices.get(i - 1);
DirectedPairValue directedPair = new DirectedPairValue(sourceChoice.getIdentifier(), targetChoice.getIdentifier());
matchBuilder.addScore(directedPair, Double.valueOf(point));
if (point > 0.0) {
matchBuilder.addAssociation(sourceChoice.getIdentifier(), targetChoice.getIdentifier());
}
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project openolat by klemens.
the class KPrimAssessmentItemBuilder method extractCorrectResponse.
private void extractCorrectResponse() {
associations = new HashMap<>();
if (matchInteraction != null) {
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(matchInteraction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
List<FieldValue> values = correctResponse.getFieldValues();
for (FieldValue value : values) {
SingleValue sValue = value.getSingleValue();
if (sValue instanceof DirectedPairValue) {
DirectedPairValue dpValue = (DirectedPairValue) sValue;
Identifier sourceId = dpValue.sourceValue();
Identifier destinationId = dpValue.destValue();
associations.put(sourceId, destinationId);
}
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project openolat by klemens.
the class MatchAssessmentItemBuilder method buildResponseAndOutcomeDeclarations.
@Override
protected void buildResponseAndOutcomeDeclarations() {
// refresh correct response
ResponseDeclaration responseDeclaration;
if (assessmentItem.getResponseDeclaration(responseIdentifier) != null) {
responseDeclaration = assessmentItem.getResponseDeclaration(responseIdentifier);
appendAssociationMatchResponseDeclaration(responseDeclaration, associations);
} else {
responseDeclaration = createMatchResponseDeclaration(assessmentItem, responseIdentifier, associations);
assessmentItem.getResponseDeclarations().add(responseDeclaration);
}
if (scoreEvaluation == ScoreEvaluation.perAnswer) {
Map<DirectedPairValue, Double> pairMapping = new HashMap<>();
if (scoreMapping != null && scoreMapping.size() > 0) {
for (Map.Entry<DirectedPairValue, Double> entry : scoreMapping.entrySet()) {
DirectedPairValue sdKey = entry.getKey();
pairMapping.put(new DirectedPairValue(sdKey.sourceValue(), sdKey.destValue()), entry.getValue());
}
}
AssessmentItemFactory.appendPairMapping(responseDeclaration, pairMapping);
} else {
// make sure there isn't any mapping
responseDeclaration.setMapping(null);
}
}
Aggregations