use of uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse in project openolat by klemens.
the class MatchAssessmentItemBuilder 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 targetId = dpValue.destValue();
List<Identifier> targetIds = associations.get(sourceId);
if (targetIds == null) {
targetIds = new ArrayList<>();
associations.put(sourceId, targetIds);
}
targetIds.add(targetId);
}
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse in project openolat by klemens.
the class AssessmentItemFactory method createTextEntryResponseDeclaration.
/**
* For the all answers get the point
* @param assessmentItem
* @param declarationId
* @param response
* @param alternatives
* @return
*/
public static ResponseDeclaration createTextEntryResponseDeclaration(AssessmentItem assessmentItem, Identifier declarationId, String response, List<TextEntryAlternative> alternatives) {
ResponseDeclaration responseDeclaration = new ResponseDeclaration(assessmentItem);
responseDeclaration.setIdentifier(declarationId);
responseDeclaration.setCardinality(Cardinality.SINGLE);
responseDeclaration.setBaseType(BaseType.STRING);
// correct response
CorrectResponse correctResponse = new CorrectResponse(responseDeclaration);
responseDeclaration.setCorrectResponse(correctResponse);
appendStringValue(correctResponse, response);
if (alternatives != null) {
for (TextEntryAlternative alternative : alternatives) {
appendStringValue(correctResponse, alternative.getAlternative());
}
}
return responseDeclaration;
}
use of uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse in project openolat by klemens.
the class AssessmentItemFactory method createNumericalEntryResponseDeclaration.
public static ResponseDeclaration createNumericalEntryResponseDeclaration(AssessmentItem assessmentItem, Identifier declarationId, double response) {
ResponseDeclaration responseDeclaration = new ResponseDeclaration(assessmentItem);
responseDeclaration.setIdentifier(declarationId);
responseDeclaration.setCardinality(Cardinality.SINGLE);
responseDeclaration.setBaseType(BaseType.FLOAT);
// correct response
CorrectResponse correctResponse = new CorrectResponse(responseDeclaration);
responseDeclaration.setCorrectResponse(correctResponse);
appendFloatValue(correctResponse, response);
return responseDeclaration;
}
use of uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse in project openolat by klemens.
the class AssessmentItemFactory method createHotspotCorrectResponseDeclaration.
public static ResponseDeclaration createHotspotCorrectResponseDeclaration(AssessmentItem assessmentItem, Identifier declarationId, List<Identifier> correctResponseIds, Cardinality cardinality) {
ResponseDeclaration responseDeclaration = new ResponseDeclaration(assessmentItem);
responseDeclaration.setIdentifier(declarationId);
if (cardinality != null && (cardinality == Cardinality.SINGLE || cardinality == Cardinality.MULTIPLE)) {
responseDeclaration.setCardinality(cardinality);
} else if (correctResponseIds == null || correctResponseIds.size() == 0 || correctResponseIds.size() > 1) {
responseDeclaration.setCardinality(Cardinality.MULTIPLE);
} else {
responseDeclaration.setCardinality(Cardinality.SINGLE);
}
responseDeclaration.setBaseType(BaseType.IDENTIFIER);
CorrectResponse correctResponse = new CorrectResponse(responseDeclaration);
responseDeclaration.setCorrectResponse(correctResponse);
for (Identifier correctResponseId : correctResponseIds) {
appendIdentifierValue(correctResponse, correctResponseId);
}
return responseDeclaration;
}
use of uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse in project openolat by klemens.
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;
}
Aggregations