use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project OpenOLAT by OpenOLAT.
the class CorrectResponsesUtil method getCorrectOrderedIdentifierResponses.
public static final List<Identifier> getCorrectOrderedIdentifierResponses(AssessmentItem assessmentItem, Interaction interaction) {
List<Identifier> correctAnswers = new ArrayList<>(5);
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
if (correctResponse.getCardinality().isOneOf(Cardinality.ORDERED)) {
List<FieldValue> values = correctResponse.getFieldValues();
Value value = FieldValue.computeValue(Cardinality.ORDERED, values);
if (value instanceof OrderedValue) {
OrderedValue multiValue = (OrderedValue) value;
multiValue.forEach(oValue -> {
if (oValue instanceof IdentifierValue) {
IdentifierValue identifierValue = (IdentifierValue) oValue;
Identifier correctAnswer = identifierValue.identifierValue();
correctAnswers.add(correctAnswer);
}
});
}
}
}
return correctAnswers;
}
use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project OpenOLAT by OpenOLAT.
the class CorrectResponsesUtil method getCorrectIdentifierResponses.
public static final List<Identifier> getCorrectIdentifierResponses(AssessmentItem assessmentItem, Identifier responseIdentifier) {
List<Identifier> correctAnswers = new ArrayList<>(5);
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(responseIdentifier);
if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
if (correctResponse.getCardinality().isOneOf(Cardinality.SINGLE)) {
List<FieldValue> values = correctResponse.getFieldValues();
Value value = FieldValue.computeValue(Cardinality.SINGLE, values);
if (value instanceof IdentifierValue) {
IdentifierValue identifierValue = (IdentifierValue) value;
Identifier correctAnswer = identifierValue.identifierValue();
correctAnswers.add(correctAnswer);
}
} else if (correctResponse.getCardinality().isOneOf(Cardinality.MULTIPLE)) {
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);
}
}
}
}
}
return correctAnswers;
}
use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project OpenOLAT by OpenOLAT.
the class CorrectResponsesUtil method getCorrectDirectPairResponses.
/**
* The list of correct associations
* @param assessmentItem
* @param interaction
* @return A list of string with [ and ] before and after!
*/
public static final Set<String> getCorrectDirectPairResponses(AssessmentItem assessmentItem, Interaction interaction, boolean withDelimiter) {
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
Set<String> correctAnswers = new HashSet<>();
// readable responses
if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
if (correctResponse.getCardinality().isOneOf(Cardinality.MULTIPLE)) {
List<FieldValue> values = correctResponse.getFieldValues();
Value value = FieldValue.computeValue(Cardinality.MULTIPLE, values);
if (value instanceof MultipleValue) {
MultipleValue multiValue = (MultipleValue) value;
multiValue.forEach(oValue -> {
if (oValue instanceof DirectedPairValue) {
DirectedPairValue pairValue = (DirectedPairValue) oValue;
String source = pairValue.sourceValue().toString();
String destination = pairValue.destValue().toString();
if (withDelimiter) {
correctAnswers.add("[" + source + " " + destination + "]");
} else {
correctAnswers.add(source + " " + destination);
}
}
});
}
}
}
return correctAnswers;
}
use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project OpenOLAT by OpenOLAT.
the class CorrectResponsesUtil method getCorrectMultiplePairResponses.
public static final List<String> getCorrectMultiplePairResponses(AssessmentItem assessmentItem, Interaction interaction, boolean withDelimiter) {
final List<String> correctAnswers = new ArrayList<>(5);
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
if (correctResponse.getCardinality().isOneOf(Cardinality.MULTIPLE)) {
List<FieldValue> values = correctResponse.getFieldValues();
Value value = FieldValue.computeValue(Cardinality.MULTIPLE, values);
if (value instanceof MultipleValue) {
MultipleValue multiValue = (MultipleValue) value;
multiValue.forEach(oValue -> {
if (oValue instanceof PairValue) {
PairValue pairValue = (PairValue) oValue;
String source = pairValue.sourceValue().toString();
String destination = pairValue.destValue().toString();
if (withDelimiter) {
correctAnswers.add("[" + source + " " + destination + "]");
} else {
correctAnswers.add(source + " " + destination);
}
}
});
}
}
}
return correctAnswers;
}
use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue 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);
}
}
}
}
}
Aggregations