use of uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse in project OpenOLAT by OpenOLAT.
the class FIBAssessmentItemBuilder method extractTextEntrySettingsFromResponseDeclaration.
/**
* All the needed informations are in the responseDeclaration, the list of alternatives
* is in the mapping with case sensitivity options and score.
*
* @param textEntry
* @param responseDeclaration
* @param countAlternatives
* @param mappedScore
*/
public static void extractTextEntrySettingsFromResponseDeclaration(TextEntry textEntry, ResponseDeclaration responseDeclaration, AtomicInteger countAlternatives, DoubleAdder mappedScore) {
String solution = null;
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
if (correctResponse != null && correctResponse.getFieldValues().size() > 0) {
List<FieldValue> fValues = correctResponse.getFieldValues();
SingleValue sValue = fValues.get(0).getSingleValue();
if (sValue instanceof StringValue) {
solution = ((StringValue) sValue).stringValue();
textEntry.setSolution(solution);
}
if (correctResponse.getFieldValues().size() > 1) {
List<TextEntryAlternative> alternatives = new ArrayList<>();
for (int i = 1; i < correctResponse.getFieldValues().size(); i++) {
SingleValue aValue = fValues.get(i).getSingleValue();
if (aValue instanceof StringValue) {
TextEntryAlternative alternative = new TextEntryAlternative();
alternative.setAlternative(((StringValue) aValue).stringValue());
alternatives.add(alternative);
}
}
textEntry.setAlternatives(alternatives);
}
}
Mapping mapping = responseDeclaration.getMapping();
if (mapping != null) {
boolean caseSensitive = true;
List<TextEntryAlternative> alternatives = new ArrayList<>();
List<MapEntry> mapEntries = mapping.getMapEntries();
for (MapEntry mapEntry : mapEntries) {
TextEntryAlternative alternative = new TextEntryAlternative();
SingleValue sValue = mapEntry.getMapKey();
if (sValue instanceof StringValue) {
String alt = ((StringValue) sValue).stringValue();
if (solution == null || !solution.equals(alt)) {
alternative.setAlternative(alt);
alternative.setScore(mapEntry.getMappedValue());
alternatives.add(alternative);
} else if (alt.equals(solution)) {
try {
textEntry.setScore(mapEntry.getMappedValue());
} catch (QtiAttributeException e) {
log.error("", e);
}
}
countAlternatives.incrementAndGet();
mappedScore.add(mapEntry.getMappedValue());
}
caseSensitive &= mapEntry.getCaseSensitive();
}
textEntry.setCaseSensitive(caseSensitive);
textEntry.setAlternatives(alternatives);
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse in project openolat by klemens.
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.item.CorrectResponse in project openolat by klemens.
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.item.CorrectResponse in project openolat by klemens.
the class FIBAssessmentItemBuilder method extractTextEntrySettingsFromResponseDeclaration.
/**
* All the needed informations are in the responseDeclaration, the list of alternatives
* is in the mapping with case sensitivity options and score.
*
* @param textEntry
* @param responseDeclaration
* @param countAlternatives
* @param mappedScore
*/
public static void extractTextEntrySettingsFromResponseDeclaration(TextEntry textEntry, ResponseDeclaration responseDeclaration, AtomicInteger countAlternatives, DoubleAdder mappedScore) {
String solution = null;
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
if (correctResponse != null && correctResponse.getFieldValues().size() > 0) {
List<FieldValue> fValues = correctResponse.getFieldValues();
SingleValue sValue = fValues.get(0).getSingleValue();
if (sValue instanceof StringValue) {
solution = ((StringValue) sValue).stringValue();
textEntry.setSolution(solution);
}
if (correctResponse.getFieldValues().size() > 1) {
List<TextEntryAlternative> alternatives = new ArrayList<>();
for (int i = 1; i < correctResponse.getFieldValues().size(); i++) {
SingleValue aValue = fValues.get(i).getSingleValue();
if (aValue instanceof StringValue) {
TextEntryAlternative alternative = new TextEntryAlternative();
alternative.setAlternative(((StringValue) aValue).stringValue());
alternatives.add(alternative);
}
}
textEntry.setAlternatives(alternatives);
}
}
Mapping mapping = responseDeclaration.getMapping();
if (mapping != null) {
boolean caseSensitive = true;
List<TextEntryAlternative> alternatives = new ArrayList<>();
List<MapEntry> mapEntries = mapping.getMapEntries();
for (MapEntry mapEntry : mapEntries) {
TextEntryAlternative alternative = new TextEntryAlternative();
SingleValue sValue = mapEntry.getMapKey();
if (sValue instanceof StringValue) {
String alt = ((StringValue) sValue).stringValue();
if (solution == null || !solution.equals(alt)) {
alternative.setAlternative(alt);
alternative.setScore(mapEntry.getMappedValue());
alternatives.add(alternative);
} else if (alt.equals(solution)) {
try {
textEntry.setScore(mapEntry.getMappedValue());
} catch (QtiAttributeException e) {
log.error("", e);
}
}
countAlternatives.incrementAndGet();
mappedScore.add(mapEntry.getMappedValue());
}
caseSensitive &= mapEntry.getCaseSensitive();
}
textEntry.setCaseSensitive(caseSensitive);
textEntry.setAlternatives(alternatives);
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse in project openolat by klemens.
the class FIBAssessmentItemBuilder method extractNumericalEntrySettings.
public static void extractNumericalEntrySettings(AssessmentItem item, NumericalEntry numericalEntry, ResponseDeclaration responseDeclaration, AtomicInteger countAlternatives, DoubleAdder mappedScore) {
Double solution = null;
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
if (correctResponse != null && correctResponse.getFieldValues().size() > 0) {
List<FieldValue> fValues = correctResponse.getFieldValues();
SingleValue sValue = fValues.get(0).getSingleValue();
if (sValue instanceof FloatValue) {
solution = ((FloatValue) sValue).doubleValue();
numericalEntry.setSolution(solution);
}
}
// search the equal
List<ResponseRule> responseRules = item.getResponseProcessing().getResponseRules();
a_a: for (ResponseRule responseRule : responseRules) {
if (responseRule instanceof ResponseCondition) {
ResponseCondition condition = (ResponseCondition) responseRule;
ResponseIf responseIf = condition.getResponseIf();
if (responseIf != null && responseIf.getExpressions().size() > 0) {
// first is an and/equal/
Expression potentialEqualOrAnd = responseIf.getExpressions().get(0);
if (potentialEqualOrAnd instanceof And) {
And and = (And) potentialEqualOrAnd;
for (Expression potentialEqual : and.getExpressions()) {
if (potentialEqual instanceof Equal && potentialEqual.getExpressions().size() == 2 && extractNumericalEntrySettings(numericalEntry, (Equal) potentialEqual)) {
break a_a;
}
}
} else if (potentialEqualOrAnd instanceof Equal) {
if (extractNumericalEntrySettings(numericalEntry, (Equal) potentialEqualOrAnd)) {
// find to score as outcome value
if (responseIf.getResponseRules() != null && responseIf.getResponseRules().size() == 1 && responseIf.getResponseRules().get(0) instanceof SetOutcomeValue) {
SetOutcomeValue outcomeValue = (SetOutcomeValue) responseIf.getResponseRules().get(0);
if (outcomeValue.getExpressions() != null && outcomeValue.getExpressions().size() == 1 && outcomeValue.getExpressions().get(0) instanceof BaseValue) {
BaseValue bValue = (BaseValue) outcomeValue.getExpressions().get(0);
SingleValue sValue = bValue.getSingleValue();
if (sValue instanceof FloatValue) {
FloatValue fValue = (FloatValue) sValue;
numericalEntry.setScore(fValue.doubleValue());
mappedScore.add(fValue.doubleValue());
countAlternatives.incrementAndGet();
}
}
}
break a_a;
}
}
}
}
}
// toleranceMode cannot be empty
if (numericalEntry.getToleranceMode() == null) {
numericalEntry.setToleranceMode(ToleranceMode.EXACT);
}
}
Aggregations