Search in sources :

Example 16 with ComplexReferenceIdentifier

use of uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier in project OpenOLAT by OpenOLAT.

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);
    }
}
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) 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) OutcomeDeclaration(uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) Equal(uk.ac.ed.ph.jqtiplus.node.expression.operator.Equal) FloatOrVariableRef(uk.ac.ed.ph.jqtiplus.types.FloatOrVariableRef) List(java.util.List) ArrayList(java.util.ArrayList) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) Map(java.util.Map) HashMap(java.util.HashMap) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Example 17 with ComplexReferenceIdentifier

use of uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier 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);
        }
    }
}
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)

Example 18 with ComplexReferenceIdentifier

use of uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier in project OpenOLAT by OpenOLAT.

the class AssessmentItemChecker method checkSetCorrectResponse.

/**
 * responseDeclaration -> float
 *
 * templateVraiable -> integer
 *
 * setCorrectResponse
 *   -> variable -> integer doesn't match float -> issue
 * @param item
 * @return
 */
private static boolean checkSetCorrectResponse(AssessmentItem item) {
    boolean allOk = true;
    List<SetCorrectResponse> setCorrectResponses = QueryUtils.search(SetCorrectResponse.class, item);
    for (SetCorrectResponse setCorrectResponse : setCorrectResponses) {
        Identifier responseIdentifier = setCorrectResponse.getIdentifier();
        ResponseDeclaration responseDeclaration = item.getResponseDeclaration(responseIdentifier);
        BaseType baseType = responseDeclaration.getBaseType();
        Expression expression = setCorrectResponse.getExpression();
        if (expression instanceof Variable) {
            Variable variable = (Variable) expression;
            ComplexReferenceIdentifier cpxVariableIdentifier = variable.getIdentifier();
            Identifier variableIdentifier = Identifier.assumedLegal(cpxVariableIdentifier.toString());
            TemplateDeclaration templateDeclaration = item.getTemplateDeclaration(variableIdentifier);
            if (templateDeclaration != null && !templateDeclaration.hasBaseType(baseType)) {
                templateDeclaration.setBaseType(baseType);
                allOk &= false;
            }
        }
    }
    return allOk;
}
Also used : ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) SetCorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.template.processing.SetCorrectResponse) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) BaseType(uk.ac.ed.ph.jqtiplus.value.BaseType) Expression(uk.ac.ed.ph.jqtiplus.node.expression.Expression) TemplateDeclaration(uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 19 with ComplexReferenceIdentifier

use of uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier 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);
    }
}
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) 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) OutcomeDeclaration(uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) Equal(uk.ac.ed.ph.jqtiplus.node.expression.operator.Equal) FloatOrVariableRef(uk.ac.ed.ph.jqtiplus.types.FloatOrVariableRef) List(java.util.List) ArrayList(java.util.ArrayList) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) Map(java.util.Map) HashMap(java.util.HashMap) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Example 20 with ComplexReferenceIdentifier

use of uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier in project openolat by klemens.

the class HotspotAssessmentItemBuilder method buildMainScoreRuleAllCorrectAnswers.

private void buildMainScoreRuleAllCorrectAnswers(ResponseCondition rule) {
    /*
		<responseCondition>
			<responseIf>
				<isNull>
					<variable identifier="RESPONSE_1" />
				</isNull>
				<setOutcomeValue identifier="FEEDBACKBASIC">
					<baseValue baseType="identifier">empty</baseValue>
				</setOutcomeValue>
			</responseIf>
			<responseElseIf>
				<match>
					<variable identifier="RESPONSE_1" />
					<correct identifier="RESPONSE_1" />
				</match>
				<setOutcomeValue identifier="SCORE">
					<sum>
						<variable identifier="SCORE" />
						<variable identifier="MAXSCORE" />
					</sum>
				</setOutcomeValue>
				<setOutcomeValue identifier="FEEDBACKBASIC">
					<baseValue baseType="identifier">correct</baseValue>
				</setOutcomeValue>
			</responseElseIf>
			<responseElse>
				<setOutcomeValue identifier="FEEDBACKBASIC">
					<baseValue baseType="identifier">incorrect</baseValue>
				</setOutcomeValue>
			</responseElse>
		</responseCondition>
		 */
    // simple as build with / without feedback
    ensureFeedbackBasicOutcomeDeclaration();
    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
        Match match = new Match(responseElseIf);
        responseElseIf.getExpressions().add(match);
        Variable scoreVar = new Variable(match);
        ComplexReferenceIdentifier choiceResponseIdentifier = ComplexReferenceIdentifier.parseString(hotspotInteraction.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(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);
    }
    ResponseElse responseElse = new ResponseElse(rule);
    rule.setResponseElse(responseElse);
    {
        // 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) 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) IsNull(uk.ac.ed.ph.jqtiplus.node.expression.operator.IsNull) Sum(uk.ac.ed.ph.jqtiplus.node.expression.operator.Sum) ResponseElseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseElseIf) Correct(uk.ac.ed.ph.jqtiplus.node.expression.general.Correct) Match(uk.ac.ed.ph.jqtiplus.node.expression.operator.Match)

Aggregations

ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)26 Variable (uk.ac.ed.ph.jqtiplus.node.expression.general.Variable)24 Correct (uk.ac.ed.ph.jqtiplus.node.expression.general.Correct)22 ResponseIf (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf)20 Match (uk.ac.ed.ph.jqtiplus.node.expression.operator.Match)18 ResponseElse (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseElse)16 SetOutcomeValue (uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue)16 BaseValue (uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue)14 Sum (uk.ac.ed.ph.jqtiplus.node.expression.operator.Sum)14 MapResponse (uk.ac.ed.ph.jqtiplus.node.expression.general.MapResponse)10 IsNull (uk.ac.ed.ph.jqtiplus.node.expression.operator.IsNull)8 Expression (uk.ac.ed.ph.jqtiplus.node.expression.Expression)6 ResponseCondition (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)6 FloatOrVariableRef (uk.ac.ed.ph.jqtiplus.types.FloatOrVariableRef)6 ArrayList (java.util.ArrayList)4 AssessmentItemFactory.appendSetOutcomeFeedbackCorrect (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendSetOutcomeFeedbackCorrect)4 And (uk.ac.ed.ph.jqtiplus.node.expression.operator.And)4 Equal (uk.ac.ed.ph.jqtiplus.node.expression.operator.Equal)4 MapEntry (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry)4 ResponseElseIf (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseElseIf)4