use of uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse 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.node.item.CorrectResponse in project openolat by klemens.
the class MultipleChoiceAssessmentItemBuilder method extract.
@Override
public void extract() {
super.extract();
correctAnswers = new ArrayList<>(5);
if (choiceInteraction != null) {
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(choiceInteraction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
Value value = FieldValue.computeValue(Cardinality.MULTIPLE, correctResponse.getFieldValues());
if (value instanceof MultipleValue) {
MultipleValue multiValue = (MultipleValue) value;
for (SingleValue sValue : multiValue.getAll()) {
if (sValue instanceof IdentifierValue) {
IdentifierValue identifierValue = (IdentifierValue) sValue;
Identifier correctAnswer = identifierValue.identifierValue();
correctAnswers.add(correctAnswer);
}
}
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse in project openolat by klemens.
the class SingleChoiceAssessmentItemBuilder method extract.
@Override
public void extract() {
super.extract();
if (choiceInteraction != null) {
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(choiceInteraction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
List<FieldValue> values = correctResponse.getFieldValues();
Value value = FieldValue.computeValue(Cardinality.SINGLE, values);
if (value instanceof IdentifierValue) {
IdentifierValue identifierValue = (IdentifierValue) value;
correctAnswer = identifierValue.identifierValue();
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse in project openolat by klemens.
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.node.item.CorrectResponse in project openolat by klemens.
the class AssessmentItemFactory method createHottextCorrectResponseDeclaration.
public static ResponseDeclaration createHottextCorrectResponseDeclaration(AssessmentItem assessmentItem, Identifier declarationId, List<Identifier> correctResponseIds) {
ResponseDeclaration responseDeclaration = new ResponseDeclaration(assessmentItem);
responseDeclaration.setIdentifier(declarationId);
responseDeclaration.setCardinality(Cardinality.MULTIPLE);
responseDeclaration.setBaseType(BaseType.IDENTIFIER);
CorrectResponse correctResponse = new CorrectResponse(responseDeclaration);
responseDeclaration.setCorrectResponse(correctResponse);
for (Identifier correctResponseId : correctResponseIds) {
appendIdentifierValue(correctResponse, correctResponseId);
}
return responseDeclaration;
}
Aggregations