use of uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier in project OpenOLAT by OpenOLAT.
the class KPrimAssessmentItemBuilder method buildMainKPrimScoreRule.
/**
* The score is 100% if 4 correct responses, 50% if 3 correct
* responses and 0 otherwise.
*
* @param rule
*/
private void buildMainKPrimScoreRule(ResponseCondition rule) {
/*
<responseCondition>
<responseIf>
<isNull>
<variable identifier="RESPONSE"/>
</isNull>
<setOutcomeValue identifier="SCORE">
<baseValue baseType="float">0.0</baseValue>
</setOutcomeValue>
</responseIf>
<responseElse>
<setOutcomeValue identifier="SCORE">
<mapResponse identifier="RESPONSE"/>
</setOutcomeValue>
</responseElse>
</responseCondition>
*/
ResponseIf responseIf = new ResponseIf(rule);
rule.setResponseIf(responseIf);
{
// if no response
IsNull isNull = new IsNull(responseIf);
responseIf.getExpressions().add(isNull);
Variable variable = new Variable(isNull);
variable.setIdentifier(ComplexReferenceIdentifier.parseString(responseIdentifier.toString()));
isNull.getExpressions().add(variable);
SetOutcomeValue incorrectOutcomeValue = new SetOutcomeValue(responseIf);
incorrectOutcomeValue.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
responseIf.getResponseRules().add(incorrectOutcomeValue);
BaseValue incorrectValue = new BaseValue(incorrectOutcomeValue);
incorrectValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
incorrectValue.setSingleValue(QTI21Constants.EMPTY_IDENTIFIER_VALUE);
incorrectOutcomeValue.setExpression(incorrectValue);
}
ResponseElseIf responseElseIf = new ResponseElseIf(rule);
rule.getResponseElseIfs().add(responseElseIf);
{
// match the correct answers -> 100%
Match match = new Match(responseElseIf);
responseElseIf.getExpressions().add(match);
Variable scoreVar = new Variable(match);
ComplexReferenceIdentifier choiceResponseIdentifier = ComplexReferenceIdentifier.parseString(matchInteraction.getResponseIdentifier().toString());
scoreVar.setIdentifier(choiceResponseIdentifier);
match.getExpressions().add(scoreVar);
Correct correct = new Correct(match);
correct.setIdentifier(choiceResponseIdentifier);
match.getExpressions().add(correct);
}
{
// outcome score
SetOutcomeValue scoreOutcomeValue = new SetOutcomeValue(responseIf);
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);
}
{
// set outcome
SetOutcomeValue correctOutcomeValue = new SetOutcomeValue(responseIf);
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);
}
ResponseElse responseElse = new ResponseElse(rule);
rule.setResponseElse(responseElse);
/* Not perfect ->
<setOutcomeValue identifier="SCORE">
<sum>
<mapResponse identifier="KPRIM_RESPONSE_1"/>
</sum>
</setOutcomeValue>
*/
{
// outcome feedback
SetOutcomeValue halfScoreOutcomeValue = new SetOutcomeValue(responseIf);
halfScoreOutcomeValue.setIdentifier(QTI21Constants.SCORE_IDENTIFIER);
responseElse.getResponseRules().add(halfScoreOutcomeValue);
Sum sum = new Sum(halfScoreOutcomeValue);
halfScoreOutcomeValue.setExpression(sum);
MapResponse mapResponse = new MapResponse(sum);
mapResponse.setIdentifier(responseIdentifier);
sum.getExpressions().add(mapResponse);
SetOutcomeValue incorrectOutcomeValue = new SetOutcomeValue(responseIf);
incorrectOutcomeValue.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
responseElse.getResponseRules().add(incorrectOutcomeValue);
BaseValue incorrectValue = new BaseValue(incorrectOutcomeValue);
incorrectValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
incorrectValue.setSingleValue(QTI21Constants.INCORRECT_IDENTIFIER_VALUE);
incorrectOutcomeValue.setExpression(incorrectValue);
}
}
use of uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier in project OpenOLAT by OpenOLAT.
the class MatchAssessmentItemBuilder method buildMainScoreRulePerAnswer.
/**
* Case with some correct answers and scoring per answer:
* <ul>
* <li>All correct: calculate score + correct
* <li>Else: calculate score + incorrect
* </ul>
*
* @param rule
*/
private void buildMainScoreRulePerAnswer(ResponseCondition rule) {
/*
<responseCondition>
<responseIf>
<match>
<variable identifier="RESPONSE_1"/>
<correct identifier="RESPONSE_1"/>
</match>
<setOutcomeValue identifier="SCORE">
<sum>
<variable identifier="SCORE"/>
<mapResponse identifier="RESPONSE_1"/>
</sum>
</setOutcomeValue>
<setOutcomeValue identifier="FEEDBACKBASIC">
<baseValue baseType="identifier">correct</baseValue>
</setOutcomeValue>
</responseIf>
<responseElse>
<setOutcomeValue identifier="SCORE">
<sum>
<variable identifier="SCORE"/>
<mapResponse identifier="RESPONSE_1"/>
</sum>
</setOutcomeValue>
<setOutcomeValue identifier="FEEDBACKBASIC">
<baseValue baseType="identifier">incorrect</baseValue>
</setOutcomeValue>
</responseElse>
</responseCondition>
*/
// if no response
ResponseIf responseIf = new ResponseIf(rule);
rule.setResponseIf(responseIf);
Match match = new Match(responseIf);
responseIf.getExpressions().add(match);
Variable responseVar = new Variable(match);
ComplexReferenceIdentifier choiceResponseIdentifier = ComplexReferenceIdentifier.parseString(responseIdentifier.toString());
responseVar.setIdentifier(choiceResponseIdentifier);
match.getExpressions().add(responseVar);
Correct correct = new Correct(match);
correct.setIdentifier(choiceResponseIdentifier);
match.getExpressions().add(correct);
// outcome score
appendSetOutcomeScoreMapResponse(responseIf, responseIdentifier);
// outcome correct feedback
appendSetOutcomeFeedbackCorrect(responseIf);
ResponseElse responseElse = new ResponseElse(rule);
rule.setResponseElse(responseElse);
// outcome score
appendSetOutcomeScoreMapResponse(responseElse, responseIdentifier);
// outcome incorrect feedback
appendSetOutcomeFeedbackIncorrect(responseElse);
}
use of uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method matchAdditionalFeedback.
/**
* the additional feedback have only responseIf
*
* @param item
* @param feedback
* @return
*/
public static boolean matchAdditionalFeedback(AssessmentItem item, ModalFeedback feedback) {
List<ResponseRule> responseRules = item.getResponseProcessing().getResponseRules();
for (ResponseRule responseRule : responseRules) {
if (responseRule instanceof ResponseCondition) {
ResponseCondition responseCondition = (ResponseCondition) responseRule;
if (responseCondition.getResponseIf() == null || responseCondition.getResponseElse() != null || (responseCondition.getResponseElseIfs() != null && responseCondition.getResponseElseIfs().size() > 0)) {
continue;
}
ResponseIf responseIf = responseCondition.getResponseIf();
List<ResponseRule> ifResponseRules = responseIf.getResponseRules();
if (ifResponseRules == null || ifResponseRules.size() != 1 || !(ifResponseRules.get(0) instanceof SetOutcomeValue)) {
continue;
}
SetOutcomeValue setOutcomeValue = (SetOutcomeValue) responseIf.getResponseRules().get(0);
if (!findBaseValueInExpression(setOutcomeValue.getExpression(), feedback.getIdentifier())) {
continue;
}
List<Expression> expressions = responseIf.getExpressions();
if (expressions == null || expressions.size() != 1 || !(expressions.get(0) instanceof And)) {
continue;
}
List<Variable> variables = QueryUtils.search(Variable.class, expressions.get(0));
if (variables != null && variables.size() == 1) {
Variable bValue = variables.get(0);
ComplexReferenceIdentifier identifier = bValue.getIdentifier();
if (identifier.equals(QTI21Constants.SCORE_CLX_IDENTIFIER) || identifier.equals(QTI21Constants.NUM_ATTEMPTS_CLX_IDENTIFIER)) {
return true;
}
if (identifier.equals(QTI21Constants.CORRECT_CLX_IDENTIFIER) || identifier.equals(QTI21Constants.INCORRECT_CLX_IDENTIFIER) || identifier.equals(QTI21Constants.EMPTY_CLX_IDENTIFIER)) {
return false;
}
String identifierToString = identifier.toString();
if (identifierToString.contains("RESPONSE_")) {
return true;
}
}
}
}
return false;
}
use of uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier in project OpenOLAT by OpenOLAT.
the class FIBAssessmentItemBuilder method extractNumericalEntrySettings.
private static boolean extractNumericalEntrySettings(NumericalEntry numericalEntry, Equal equal) {
Expression variableOrCorrect = equal.getExpressions().get(0);
Expression correctOrVariable = equal.getExpressions().get(1);
Correct correct = null;
if (variableOrCorrect instanceof Correct) {
correct = (Correct) variableOrCorrect;
} else if (correctOrVariable instanceof Correct) {
correct = (Correct) correctOrVariable;
}
ComplexReferenceIdentifier reponseIdentifer = ComplexReferenceIdentifier.assumedLegal(numericalEntry.getResponseIdentifier().toString());
if (correct != null && correct.getIdentifier().equals(reponseIdentifer)) {
numericalEntry.setToleranceMode(equal.getToleranceMode());
List<FloatOrVariableRef> tolerances = equal.getTolerances();
if (tolerances != null && tolerances.size() == 2) {
double lowerTolerance = tolerances.get(0).getConstantFloatValue().doubleValue();
numericalEntry.setLowerTolerance(lowerTolerance);
double upperTolerance = tolerances.get(1).getConstantFloatValue().doubleValue();
numericalEntry.setUpperTolerance(upperTolerance);
}
return true;
}
return false;
}
use of uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier in project OpenOLAT by OpenOLAT.
the class SingleChoiceAssessmentItemBuilder method buildMainScoreRulePerAnswer.
private void buildMainScoreRulePerAnswer(ResponseCondition rule) {
ensureFeedbackBasicOutcomeDeclaration();
/*
<responseCondition>
<responseIf>
<match>
<variable identifier="RESPONSE_1" />
<correct identifier="RESPONSE_1" />
</match>
<setOutcomeValue identifier="SCORE">
<sum>
<variable identifier="SCORE" />
<mapResponse identifier="RESPONSE_1" />
</sum>
</setOutcomeValue>
<setOutcomeValue identifier="FEEDBACKBASIC">
<baseValue baseType="identifier">
correct
</baseValue>
</setOutcomeValue>
</responseIf>
</responseCondition>
*/
ResponseIf responseIf = new ResponseIf(rule);
rule.setResponseIf(responseIf);
{
// match the correct answer
Match match = new Match(responseIf);
responseIf.getExpressions().add(match);
Variable responseVar = new Variable(match);
ComplexReferenceIdentifier choiceResponseIdentifier = ComplexReferenceIdentifier.parseString(choiceInteraction.getResponseIdentifier().toString());
responseVar.setIdentifier(choiceResponseIdentifier);
match.getExpressions().add(responseVar);
Correct correct = new Correct(match);
correct.setIdentifier(choiceResponseIdentifier);
match.getExpressions().add(correct);
}
{
// outcome score
SetOutcomeValue scoreOutcome = new SetOutcomeValue(responseIf);
scoreOutcome.setIdentifier(QTI21Constants.SCORE_IDENTIFIER);
responseIf.getResponseRules().add(scoreOutcome);
Sum sum = new Sum(scoreOutcome);
scoreOutcome.getExpressions().add(sum);
Variable scoreVar = new Variable(sum);
scoreVar.setIdentifier(QTI21Constants.SCORE_CLX_IDENTIFIER);
sum.getExpressions().add(scoreVar);
MapResponse mapResponse = new MapResponse(sum);
mapResponse.setIdentifier(choiceInteraction.getResponseIdentifier());
sum.getExpressions().add(mapResponse);
}
{
// outcome feedback
SetOutcomeValue correctOutcomeValue = new SetOutcomeValue(responseIf);
correctOutcomeValue.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
responseIf.getResponseRules().add(correctOutcomeValue);
BaseValue correctValue = new BaseValue(correctOutcomeValue);
correctValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
correctValue.setSingleValue(QTI21Constants.CORRECT_IDENTIFIER_VALUE);
correctOutcomeValue.setExpression(correctValue);
}
ResponseElse responseElse = new ResponseElse(rule);
rule.setResponseElse(responseElse);
{
// outcome score
SetOutcomeValue scoreOutcome = new SetOutcomeValue(responseElse);
scoreOutcome.setIdentifier(QTI21Constants.SCORE_IDENTIFIER);
responseElse.getResponseRules().add(scoreOutcome);
Sum sum = new Sum(scoreOutcome);
scoreOutcome.getExpressions().add(sum);
Variable scoreVar = new Variable(sum);
scoreVar.setIdentifier(QTI21Constants.SCORE_CLX_IDENTIFIER);
sum.getExpressions().add(scoreVar);
MapResponse mapResponse = new MapResponse(sum);
mapResponse.setIdentifier(choiceInteraction.getResponseIdentifier());
sum.getExpressions().add(mapResponse);
}
{
// outcome feedback
SetOutcomeValue incorrectOutcomeValue = new SetOutcomeValue(responseElse);
incorrectOutcomeValue.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
responseElse.getResponseRules().add(incorrectOutcomeValue);
BaseValue incorrectValue = new BaseValue(incorrectOutcomeValue);
incorrectValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
incorrectValue.setSingleValue(QTI21Constants.INCORRECT_IDENTIFIER_VALUE);
incorrectOutcomeValue.setExpression(incorrectValue);
}
}
Aggregations