use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping 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.node.item.response.declaration.Mapping 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.response.declaration.Mapping 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.response.declaration.Mapping in project openolat by klemens.
the class HotspotAssessmentItemBuilder method extractScoreEvaluationMode.
private void extractScoreEvaluationMode() {
boolean hasMapping = false;
if (hotspotInteraction != null) {
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(hotspotInteraction.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 IdentifierValue) {
Identifier identifier = ((IdentifierValue) sValue).identifierValue();
scoreMapping.put(identifier, entry.getMappedValue());
}
}
}
}
}
scoreEvaluation = hasMapping ? ScoreEvaluation.perAnswer : ScoreEvaluation.allCorrectAnswers;
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping 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