use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project OpenOLAT by OpenOLAT.
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);
}
}
use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method appendPairMapping.
public static Mapping appendPairMapping(ResponseDeclaration responseDeclaration, Map<DirectedPairValue, Double> map) {
Mapping mapping = new Mapping(responseDeclaration);
mapping.setDefaultValue(0d);
responseDeclaration.setMapping(mapping);
for (Map.Entry<DirectedPairValue, Double> entry : map.entrySet()) {
MapEntry mapEntry = new MapEntry(mapping);
mapEntry.setMapKey(entry.getKey());
mapEntry.setMappedValue(entry.getValue());
mapping.getMapEntries().add(mapEntry);
}
return mapping;
}
use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method appendAssociationKPrimResponseDeclaration.
public static ResponseDeclaration appendAssociationKPrimResponseDeclaration(ResponseDeclaration responseDeclaration, Map<Identifier, Identifier> associations, double maxScore) {
responseDeclaration.setCardinality(Cardinality.MULTIPLE);
responseDeclaration.setBaseType(BaseType.DIRECTED_PAIR);
// correct response
CorrectResponse correctResponse = new CorrectResponse(responseDeclaration);
responseDeclaration.setCorrectResponse(correctResponse);
for (Map.Entry<Identifier, Identifier> association : associations.entrySet()) {
Identifier choiceId = association.getKey();
Identifier correctwrongId = association.getValue();
DirectedPairValue dpValue = new DirectedPairValue(choiceId, correctwrongId);
FieldValue fValue = new FieldValue(correctResponse, dpValue);
correctResponse.getFieldValues().add(fValue);
}
double mappedValue = maxScore;
if (associations.size() > 0) {
mappedValue = maxScore / associations.size();
}
// mapping
Mapping mapping = new Mapping(responseDeclaration);
mapping.setDefaultValue(-mappedValue);
responseDeclaration.setMapping(mapping);
for (Map.Entry<Identifier, Identifier> association : associations.entrySet()) {
Identifier choiceId = association.getKey();
Identifier correctwrongId = association.getValue();
MapEntry mapEntry = new MapEntry(mapping);
mapEntry.setMapKey(new DirectedPairValue(choiceId, correctwrongId));
mapEntry.setMappedValue(mappedValue);
mapping.getMapEntries().add(mapEntry);
}
return responseDeclaration;
}
use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project OpenOLAT by OpenOLAT.
the class QtiNodesExtractor method extractIdentifiersFromCorrectResponse.
public static void extractIdentifiersFromCorrectResponse(CorrectResponse correctResponse, Map<Identifier, List<Identifier>> correctAnswers) {
if (correctResponse != null) {
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 targetId = dpValue.destValue();
List<Identifier> targetIds = correctAnswers.get(sourceId);
if (targetIds == null) {
targetIds = new ArrayList<>();
correctAnswers.put(sourceId, targetIds);
}
targetIds.add(targetId);
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.value.DirectedPairValue in project openolat by klemens.
the class MatchAssessmentItemBuilder method extractScoreEvaluationMode.
private void extractScoreEvaluationMode() {
boolean hasMapping = false;
if (matchInteraction != null) {
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(matchInteraction.getResponseIdentifier());
if (responseDeclaration != null) {
Mapping mapping = responseDeclaration.getMapping();
hasMapping = (mapping != null && mapping.getMapEntries() != null && mapping.getMapEntries().size() > 0);
if (hasMapping) {
scoreMapping = new HashMap<>();
for (MapEntry entry : mapping.getMapEntries()) {
SingleValue sValue = entry.getMapKey();
if (sValue instanceof DirectedPairValue) {
Identifier sourceIdentifier = ((DirectedPairValue) sValue).sourceValue();
Identifier destIdentifier = ((DirectedPairValue) sValue).destValue();
scoreMapping.put(new DirectedPairValue(sourceIdentifier, destIdentifier), entry.getMappedValue());
}
}
}
}
}
scoreEvaluation = hasMapping ? ScoreEvaluation.perAnswer : ScoreEvaluation.allCorrectAnswers;
}
Aggregations