Search in sources :

Example 11 with ResponseIf

use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf in project OpenOLAT by OpenOLAT.

the class ModalFeedbackBuilder method findBaseValueInExpressionsOfResponseIf.

private boolean findBaseValueInExpressionsOfResponseIf(ResponseCondition responseCondition, Identifier feedbackIdentifier) {
    if (responseCondition == null)
        return false;
    ResponseIf responseIf = responseCondition.getResponseIf();
    List<Expression> expressions = responseIf.getExpressions();
    for (Expression expression : expressions) {
        if (findBaseValueInExpression(expression, feedbackIdentifier)) {
            return true;
        }
    }
    return false;
}
Also used : AssessmentItemFactory.findBaseValueInExpression(org.olat.ims.qti21.model.xml.AssessmentItemFactory.findBaseValueInExpression) Expression(uk.ac.ed.ph.jqtiplus.node.expression.Expression) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf)

Example 12 with ResponseIf

use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf in project OpenOLAT by OpenOLAT.

the class HottextAssessmentItemBuilder method buildMainScoreRulePerAnswer.

private void buildMainScoreRulePerAnswer(ResponseCondition rule) {
    // simple as build with / without feedback
    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>
			<responseElse>
				<setOutcomeValue identifier="FEEDBACKBASIC">
					<baseValue baseType="identifier">incorrect</baseValue>
				</setOutcomeValue>
			</responseElse>
		</responseCondition>
		*/
    ResponseIf responseIf = new ResponseIf(rule);
    rule.setResponseIf(responseIf);
    {
        // match the correct answers
        matchCorrectAnswers(responseIf);
    }
    {
        // 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(hottextInteraction.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(hottextInteraction.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);
    }
}
Also used : MapResponse(uk.ac.ed.ph.jqtiplus.node.expression.general.MapResponse) Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) ResponseElse(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseElse) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) Sum(uk.ac.ed.ph.jqtiplus.node.expression.operator.Sum)

Example 13 with ResponseIf

use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf in project OpenOLAT by OpenOLAT.

the class LobAssessmentItemBuilder method buildMainEssayFeedbackRule.

private void buildMainEssayFeedbackRule(ResponseCondition rule) {
    /*
		 <responseCondition>
			<responseIf>
				<isNull>
					<variable identifier="RESPONSE_1" />
				</isNull>
				<setOutcomeValue identifier="FEEDBACKBASIC">
					<baseValue baseType="identifier">
						empty
					</baseValue>
				</setOutcomeValue>
			</responseIf>
		</responseCondition>
		 */
    ResponseIf responseIf = new ResponseIf(rule);
    rule.setResponseIf(responseIf);
    {
        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 feedbackOutcomeValue = new SetOutcomeValue(responseIf);
        feedbackOutcomeValue.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
        responseIf.getResponseRules().add(feedbackOutcomeValue);
        BaseValue incorrectValue = new BaseValue(feedbackOutcomeValue);
        incorrectValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
        incorrectValue.setSingleValue(QTI21Constants.EMPTY_IDENTIFIER_VALUE);
        feedbackOutcomeValue.setExpression(incorrectValue);
    }
    ResponseElseIf responseElseIf = new ResponseElseIf(rule);
    rule.getResponseElseIfs().add(responseElseIf);
    {
        Not not = new Not(responseElseIf);
        responseElseIf.getExpressions().add(not);
        IsNull isNull = new IsNull(responseIf);
        not.getExpressions().add(isNull);
        Variable variable = new Variable(isNull);
        variable.setIdentifier(ComplexReferenceIdentifier.parseString(responseIdentifier.toString()));
        isNull.getExpressions().add(variable);
        SetOutcomeValue feedbackOutcomeValue = new SetOutcomeValue(responseIf);
        feedbackOutcomeValue.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
        responseElseIf.getResponseRules().add(feedbackOutcomeValue);
        BaseValue answeredValue = new BaseValue(feedbackOutcomeValue);
        answeredValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
        answeredValue.setSingleValue(QTI21Constants.ANSWERED_IDENTIFIER_VALUE);
        feedbackOutcomeValue.setExpression(answeredValue);
    }
}
Also used : Not(uk.ac.ed.ph.jqtiplus.node.expression.operator.Not) Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) IsNull(uk.ac.ed.ph.jqtiplus.node.expression.operator.IsNull) ResponseElseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseElseIf)

Example 14 with ResponseIf

use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf 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);
    }
}
Also used : ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) MapResponse(uk.ac.ed.ph.jqtiplus.node.expression.general.MapResponse) Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) ResponseElse(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseElse) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) Sum(uk.ac.ed.ph.jqtiplus.node.expression.operator.Sum) Correct(uk.ac.ed.ph.jqtiplus.node.expression.general.Correct) Match(uk.ac.ed.ph.jqtiplus.node.expression.operator.Match)

Example 15 with ResponseIf

use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf in project openolat by klemens.

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);
        }
    }
}
Also used : MapResponse(uk.ac.ed.ph.jqtiplus.node.expression.general.MapResponse) Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) ArrayList(java.util.ArrayList) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) Sum(uk.ac.ed.ph.jqtiplus.node.expression.operator.Sum) Correct(uk.ac.ed.ph.jqtiplus.node.expression.general.Correct) Match(uk.ac.ed.ph.jqtiplus.node.expression.operator.Match) MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) Equal(uk.ac.ed.ph.jqtiplus.node.expression.operator.Equal) And(uk.ac.ed.ph.jqtiplus.node.expression.operator.And) FloatOrVariableRef(uk.ac.ed.ph.jqtiplus.types.FloatOrVariableRef) ResponseElse(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseElse) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Aggregations

ResponseIf (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf)56 Variable (uk.ac.ed.ph.jqtiplus.node.expression.general.Variable)48 SetOutcomeValue (uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue)48 BaseValue (uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue)38 ResponseCondition (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)28 Match (uk.ac.ed.ph.jqtiplus.node.expression.operator.Match)26 ResponseElse (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseElse)26 Sum (uk.ac.ed.ph.jqtiplus.node.expression.operator.Sum)24 Correct (uk.ac.ed.ph.jqtiplus.node.expression.general.Correct)22 IsNull (uk.ac.ed.ph.jqtiplus.node.expression.operator.IsNull)20 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)20 And (uk.ac.ed.ph.jqtiplus.node.expression.operator.And)16 MapResponse (uk.ac.ed.ph.jqtiplus.node.expression.general.MapResponse)14 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)12 ResponseElseIf (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseElseIf)10 Expression (uk.ac.ed.ph.jqtiplus.node.expression.Expression)8 ArrayList (java.util.ArrayList)6 Equal (uk.ac.ed.ph.jqtiplus.node.expression.operator.Equal)6 Multiple (uk.ac.ed.ph.jqtiplus.node.expression.operator.Multiple)6 Not (uk.ac.ed.ph.jqtiplus.node.expression.operator.Not)6