use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf in project OpenOLAT by OpenOLAT.
the class FIBAssessmentItemBuilder method buildMainScoreRuleAllCorrectAnswers.
private void buildMainScoreRuleAllCorrectAnswers(List<ResponseRule> responseRules) {
/*
<responseCondition>
<responseIf>
<and>
<match>
<value>-1.0</value>
<correct identifier="RESPONSE_1" />
</match>
<equal toleranceMode="relative" tolerance="0.1 0.1" includeLowerBound="true" includeUpperBound="true">
<correct identifier="RESPONSE_2" />
<variable identifier="RESPONSE_2" />
</equal>
</and>
<setOutcomeValue identifier="SCORE">
<sum>
<variable identifier="SCORE" />
<variable identifier="MAXSCORE" />
</sum>
</setOutcomeValue>
<setOutcomeValue identifier="FEEDBACKBASIC">
<baseValue baseType="identifier">
incorrect
</baseValue>
</setOutcomeValue>
</responseIf>
</responseCondition>
*/
// add condition
ResponseCondition rule = new ResponseCondition(assessmentItem.getResponseProcessing());
responseRules.add(0, rule);
{
// match all
ResponseIf responseElseIf = new ResponseIf(rule);
rule.setResponseIf(responseElseIf);
// rule.getResponseElseIfs().add(responseElseIf);
And and = new And(responseElseIf);
responseElseIf.setExpression(and);
for (Map.Entry<String, AbstractEntry> textEntryEntry : responseIdentifierToTextEntry.entrySet()) {
AbstractEntry abstractEntry = textEntryEntry.getValue();
if (abstractEntry instanceof TextEntry) {
Match match = new Match(and);
and.getExpressions().add(match);
TextEntry textEntry = (TextEntry) abstractEntry;
BaseValue variable = new BaseValue(match);
variable.setBaseTypeAttrValue(BaseType.FLOAT);
variable.setSingleValue(new FloatValue(-1.0d));
match.getExpressions().add(variable);
MapResponse correct = new MapResponse(match);
correct.setIdentifier(textEntry.getResponseIdentifier());
match.getExpressions().add(correct);
} else if (abstractEntry instanceof NumericalEntry) {
NumericalEntry numericalEntry = (NumericalEntry) abstractEntry;
Equal equal = new Equal(and);
equal.setToleranceMode(numericalEntry.getToleranceMode());
if (numericalEntry.getLowerTolerance() != null && numericalEntry.getUpperTolerance() != null) {
List<FloatOrVariableRef> tolerances = new ArrayList<>();
tolerances.add(new FloatOrVariableRef(numericalEntry.getLowerTolerance().doubleValue()));
tolerances.add(new FloatOrVariableRef(numericalEntry.getUpperTolerance().doubleValue()));
equal.setTolerances(tolerances);
}
equal.setIncludeLowerBound(Boolean.TRUE);
equal.setIncludeUpperBound(Boolean.TRUE);
and.getExpressions().add(equal);
ComplexReferenceIdentifier responseIdentifier = ComplexReferenceIdentifier.assumedLegal(numericalEntry.getResponseIdentifier().toString());
Correct correct = new Correct(equal);
correct.setIdentifier(responseIdentifier);
equal.getExpressions().add(correct);
Variable variable = new Variable(equal);
variable.setIdentifier(responseIdentifier);
equal.getExpressions().add(variable);
}
}
{
// outcome max score -> score
SetOutcomeValue scoreOutcomeValue = new SetOutcomeValue(responseElseIf);
scoreOutcomeValue.setIdentifier(QTI21Constants.SCORE_IDENTIFIER);
responseElseIf.getResponseRules().add(scoreOutcomeValue);
Sum sum = new Sum(scoreOutcomeValue);
scoreOutcomeValue.getExpressions().add(sum);
Variable scoreVar = new Variable(sum);
scoreVar.setIdentifier(QTI21Constants.SCORE_CLX_IDENTIFIER);
sum.getExpressions().add(scoreVar);
Variable maxScoreVar = new Variable(sum);
maxScoreVar.setIdentifier(QTI21Constants.MAXSCORE_CLX_IDENTIFIER);
sum.getExpressions().add(maxScoreVar);
}
{
// outcome feedback
SetOutcomeValue correctOutcomeValue = new SetOutcomeValue(responseElseIf);
correctOutcomeValue.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
responseElseIf.getResponseRules().add(correctOutcomeValue);
BaseValue correctValue = new BaseValue(correctOutcomeValue);
correctValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
correctValue.setSingleValue(QTI21Constants.CORRECT_IDENTIFIER_VALUE);
correctOutcomeValue.setExpression(correctValue);
}
}
{
// else feedback incorrect
ResponseElse responseElse = new ResponseElse(rule);
rule.setResponseElse(responseElse);
{
// outcome feedback
SetOutcomeValue correctOutcomeValue = new SetOutcomeValue(responseElse);
correctOutcomeValue.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
responseElse.getResponseRules().add(correctOutcomeValue);
BaseValue correctValue = new BaseValue(correctOutcomeValue);
correctValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
correctValue.setSingleValue(QTI21Constants.INCORRECT_IDENTIFIER_VALUE);
correctOutcomeValue.setExpression(correctValue);
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf in project OpenOLAT by OpenOLAT.
the class ModalFeedbackBuilder method findFeedbackRuleInSetOutcomeVariable.
private boolean findFeedbackRuleInSetOutcomeVariable(ResponseRule responseRule, Identifier feedbackIdentifier, Identifier outcomeValueIdentifier) {
if (responseRule instanceof ResponseCondition) {
ResponseCondition responseCondition = (ResponseCondition) responseRule;
ResponseIf responseIf = responseCondition.getResponseIf();
List<ResponseRule> ifResponseRules = responseIf.getResponseRules();
for (ResponseRule ifResponseRule : ifResponseRules) {
if (ifResponseRule instanceof SetOutcomeValue) {
SetOutcomeValue setOutcomeValue = (SetOutcomeValue) ifResponseRule;
if (outcomeValueIdentifier.equals(setOutcomeValue.getIdentifier()) && findBaseValueInExpression(setOutcomeValue.getExpression(), feedbackIdentifier)) {
return true;
}
}
}
}
return false;
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf in project OpenOLAT by OpenOLAT.
the class AssessmentItemBuilder method buildHint.
/**
* @param outcomeDeclarations
* @param responseRules
*/
protected void buildHint(List<OutcomeDeclaration> outcomeDeclarations, List<ResponseRule> responseRules) {
if (hint == null)
return;
// response declaration -> identifier=HINTREQUEST -> for the end attempt interaction
ResponseDeclaration hintResponseDeclaration = AssessmentItemFactory.createHintRequestResponseDeclaration(assessmentItem);
assessmentItem.getResponseDeclarations().add(hintResponseDeclaration);
// outcome declaration -> identifier=HINTFEEDBACKMODAL -> for processing and feedback
OutcomeDeclaration modalOutcomeDeclaration = AssessmentItemFactory.createOutcomeDeclarationForHint(assessmentItem);
outcomeDeclarations.add(modalOutcomeDeclaration);
// the body
P paragraph = new P(assessmentItem.getItemBody());
assessmentItem.getItemBody().getBlocks().add(paragraph);
EndAttemptInteraction endAttemptInteraction = new EndAttemptInteraction(paragraph);
endAttemptInteraction.setResponseIdentifier(QTI21Constants.HINT_REQUEST_IDENTIFIER);
endAttemptInteraction.setTitle(hint.getTitle());
paragraph.getInlines().add(endAttemptInteraction);
// the feedback
ModalFeedback emptyModalFeedback = AssessmentItemFactory.createModalFeedback(assessmentItem, QTI21Constants.HINT_FEEDBACKMODAL_IDENTIFIER, QTI21Constants.HINT_IDENTIFIER, hint.getTitle(), hint.getText());
assessmentItem.getModalFeedbacks().add(emptyModalFeedback);
// the response processing
ResponseCondition rule = new ResponseCondition(assessmentItem.getResponseProcessing());
responseRules.add(0, rule);
ResponseIf responseIf = new ResponseIf(rule);
rule.setResponseIf(responseIf);
/*
<responseIf>
<variable identifier="HINTREQUEST"/>
<setOutcomeValue identifier="FEEDBACK">
<baseValue baseType="identifier">HINT</baseValue>
</setOutcomeValue>
</responseIf>
*/
Variable variable = new Variable(responseIf);
variable.setIdentifier(QTI21Constants.HINT_REQUEST_CLX_IDENTIFIER);
responseIf.getExpressions().add(variable);
SetOutcomeValue hintVar = new SetOutcomeValue(responseIf);
hintVar.setIdentifier(QTI21Constants.HINT_FEEDBACKMODAL_IDENTIFIER);
BaseValue hintVal = new BaseValue(hintVar);
hintVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
hintVal.setSingleValue(new IdentifierValue(QTI21Constants.HINT));
hintVar.setExpression(hintVal);
responseIf.getResponseRules().add(hintVar);
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf 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);
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf in project openolat by klemens.
the class FIBAssessmentItemBuilder method buildMainScoreRulePerAnswer.
private void buildMainScoreRulePerAnswer(List<OutcomeDeclaration> outcomeDeclarations, List<ResponseRule> responseRules) {
/*
<setOutcomeValue identifier="SCORE_RESPONSE_1">
<mapResponse identifier="RESPONSE_1" />
</setOutcomeValue>
*/
/*
<responseCondition>
<responseIf>
<equal toleranceMode="absolute" tolerance="2.0 2.0" includeLowerBound="true" includeUpperBound="true">
<variable identifier="RESPONSE_3"/>
<correct identifier="RESPONSE_3"/>
</equal>
<setOutcomeValue identifier="SCORE_RESPONSE_3">
<baseValue baseType="float">3.0</baseValue>
</setOutcomeValue>
</responseIf>
</responseCondition>
*/
int count = 0;
for (Map.Entry<String, AbstractEntry> textEntryEntry : responseIdentifierToTextEntry.entrySet()) {
AbstractEntry entry = textEntryEntry.getValue();
String scoreIdentifier = "SCORE_" + entry.getResponseIdentifier().toString();
if (entry instanceof TextEntry) {
// outcome mapResonse
SetOutcomeValue mapOutcomeValue = new SetOutcomeValue(assessmentItem.getResponseProcessing());
responseRules.add(count++, mapOutcomeValue);
mapOutcomeValue.setIdentifier(Identifier.parseString(scoreIdentifier));
MapResponse mapResponse = new MapResponse(mapOutcomeValue);
mapResponse.setIdentifier(entry.getResponseIdentifier());
mapOutcomeValue.setExpression(mapResponse);
} else if (entry instanceof NumericalEntry) {
NumericalEntry numericalEntry = (NumericalEntry) entry;
ResponseCondition rule = new ResponseCondition(assessmentItem.getResponseProcessing());
responseRules.add(count++, rule);
ResponseIf responseIf = new ResponseIf(rule);
rule.setResponseIf(responseIf);
Equal equal = new Equal(responseIf);
equal.setToleranceMode(numericalEntry.getToleranceMode());
if (numericalEntry.getLowerTolerance() != null && numericalEntry.getUpperTolerance() != null) {
List<FloatOrVariableRef> tolerances = new ArrayList<>();
tolerances.add(new FloatOrVariableRef(numericalEntry.getLowerTolerance().doubleValue()));
tolerances.add(new FloatOrVariableRef(numericalEntry.getUpperTolerance().doubleValue()));
equal.setTolerances(tolerances);
}
equal.setIncludeLowerBound(Boolean.TRUE);
equal.setIncludeUpperBound(Boolean.TRUE);
responseIf.getExpressions().add(equal);
ComplexReferenceIdentifier responseIdentifier = ComplexReferenceIdentifier.assumedLegal(numericalEntry.getResponseIdentifier().toString());
Correct correct = new Correct(equal);
correct.setIdentifier(responseIdentifier);
equal.getExpressions().add(correct);
Variable variable = new Variable(equal);
variable.setIdentifier(responseIdentifier);
equal.getExpressions().add(variable);
SetOutcomeValue mapOutcomeValue = new SetOutcomeValue(responseIf);
responseIf.getResponseRules().add(mapOutcomeValue);
mapOutcomeValue.setIdentifier(Identifier.parseString(scoreIdentifier));
BaseValue correctValue = new BaseValue(mapOutcomeValue);
correctValue.setBaseTypeAttrValue(BaseType.FLOAT);
correctValue.setSingleValue(new FloatValue(entry.getScore()));
mapOutcomeValue.setExpression(correctValue);
}
}
/*
<setOutcomeValue identifier="SCORE">
<sum>
<variable identifier="SCORE_RESPONSE_1" />
<variable identifier="MINSCORE_RESPONSE_1" />
<variable identifier="SCORE_RESPONSE_2" />
<variable identifier="MINSCORE_RESPONSE_2" />
</sum>
</setOutcomeValue>
*/
{
SetOutcomeValue scoreOutcome = new SetOutcomeValue(assessmentItem.getResponseProcessing());
scoreOutcome.setIdentifier(QTI21Constants.SCORE_IDENTIFIER);
responseRules.add(count++, scoreOutcome);
Sum sum = new Sum(scoreOutcome);
scoreOutcome.setExpression(sum);
for (Map.Entry<String, AbstractEntry> textEntryEntry : responseIdentifierToTextEntry.entrySet()) {
AbstractEntry textEntry = textEntryEntry.getValue();
{
// variable score
Variable scoreVariable = new Variable(sum);
sum.getExpressions().add(scoreVariable);
String scoreIdentifier = "SCORE_" + textEntry.getResponseIdentifier().toString();
scoreVariable.setIdentifier(ComplexReferenceIdentifier.parseString(scoreIdentifier));
// create associated outcomeDeclaration
OutcomeDeclaration modalOutcomeDeclaration = AssessmentItemFactory.createOutcomeDeclarationForScoreResponse(assessmentItem, scoreIdentifier);
outcomeDeclarations.add(modalOutcomeDeclaration);
}
{
// variable minscore
Variable minScoreVariable = new Variable(sum);
sum.getExpressions().add(minScoreVariable);
String scoreIdentifier = "MINSCORE_" + textEntry.getResponseIdentifier().toString();
minScoreVariable.setIdentifier(ComplexReferenceIdentifier.parseString(scoreIdentifier));
// create associated outcomeDeclaration
OutcomeDeclaration modalOutcomeDeclaration = AssessmentItemFactory.createOutcomeDeclarationForScoreResponse(assessmentItem, scoreIdentifier);
outcomeDeclarations.add(modalOutcomeDeclaration);
}
}
}
if (correctFeedback != null || incorrectFeedback != null) {
SetOutcomeValue incorrectOutcomeValue = new SetOutcomeValue(assessmentItem.getResponseProcessing());
incorrectOutcomeValue.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
BaseValue correctValue = new BaseValue(incorrectOutcomeValue);
correctValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
correctValue.setSingleValue(QTI21Constants.INCORRECT_IDENTIFIER_VALUE);
incorrectOutcomeValue.setExpression(correctValue);
responseRules.add(count++, incorrectOutcomeValue);
}
}
Aggregations