Search in sources :

Example 21 with ResponseIf

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

the class ModalFeedbackBuilder method extractConditions.

public void extractConditions() {
    ResponseCondition feedbackRule = findFeedbackResponseCondition(modalFeedback.getIdentifier(), QTI21Constants.FEEDBACKMODAL_IDENTIFIER);
    ResponseIf responseIf = feedbackRule.getResponseIf();
    if (responseIf != null && responseIf.getExpressions() != null && responseIf.getExpressions().size() == 1 && responseIf.getExpressions().get(0) instanceof And && responseIf.getResponseRules().size() == 1 && responseIf.getResponseRules().get(0) instanceof SetOutcomeValue) {
        And and = (And) responseIf.getExpression();
        List<Expression> conditionElements = and.getExpressions();
        List<ModalFeedbackCondition> extractedConditions = new ArrayList<>();
        for (Expression conditionElement : conditionElements) {
            ModalFeedbackCondition condition = extractCondition(conditionElement);
            if (condition != null) {
                extractedConditions.add(condition);
            }
        }
        if (extractedConditions != null) {
            conditions = extractedConditions;
        }
    }
}
Also used : SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) AssessmentItemFactory.findBaseValueInExpression(org.olat.ims.qti21.model.xml.AssessmentItemFactory.findBaseValueInExpression) Expression(uk.ac.ed.ph.jqtiplus.node.expression.Expression) And(uk.ac.ed.ph.jqtiplus.node.expression.operator.And) ArrayList(java.util.ArrayList) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Example 22 with ResponseIf

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

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;
}
Also used : SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition) ResponseRule(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule)

Example 23 with ResponseIf

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

the class AssessmentItemFactory method createModalFeedbackRuleWithConditions.

public static ResponseCondition createModalFeedbackRuleWithConditions(ResponseProcessing responseProcessing, Identifier feedbackIdentifier, Identifier responseIdentifier, Cardinality cardinality, List<ModalFeedbackCondition> conditions) {
    ResponseCondition rule = new ResponseCondition(responseProcessing);
    /*
		<responseCondition>
			<responseIf>
				<and>
					<equal toleranceMode="exact">
						<variable identifier="SCORE" />
						<baseValue baseType="float">
							4
						</baseValue>
					</equal>
				</and>
				<setOutcomeValue identifier="FEEDBACKMODAL">
					<multiple>
						<variable identifier="FEEDBACKMODAL" />
						<baseValue baseType="identifier">
							Feedback2074019497
						</baseValue>
					</multiple>
				</setOutcomeValue>
			</responseIf>
		</responseCondition>
		*/
    ResponseIf responseIf = new ResponseIf(rule);
    rule.setResponseIf(responseIf);
    {
        // rule
        And and = new And(responseIf);
        responseIf.getExpressions().add(and);
        for (ModalFeedbackCondition condition : conditions) {
            appendModalFeedbackCondition(condition, responseIdentifier, cardinality, and);
        }
    }
    {
        // outcome
        SetOutcomeValue feedbackVar = new SetOutcomeValue(responseIf);
        feedbackVar.setIdentifier(QTI21Constants.FEEDBACKMODAL_IDENTIFIER);
        Multiple multiple = new Multiple(feedbackVar);
        feedbackVar.setExpression(multiple);
        Variable variable = new Variable(multiple);
        variable.setIdentifier(ComplexReferenceIdentifier.parseString(QTI21Constants.FEEDBACKMODAL));
        multiple.getExpressions().add(variable);
        BaseValue feedbackVal = new BaseValue(feedbackVar);
        feedbackVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
        feedbackVal.setSingleValue(new IdentifierValue(feedbackIdentifier));
        multiple.getExpressions().add(feedbackVal);
        responseIf.getResponseRules().add(feedbackVar);
    }
    return rule;
}
Also used : Multiple(uk.ac.ed.ph.jqtiplus.node.expression.operator.Multiple) Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) And(uk.ac.ed.ph.jqtiplus.node.expression.operator.And) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Example 24 with ResponseIf

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

the class AssessmentItemFactory method createModalFeedbackBasicRule.

public static ResponseCondition createModalFeedbackBasicRule(ResponseProcessing responseProcessing, Identifier feedbackIdentifier, String inCorrect, boolean hint) {
    ResponseCondition rule = new ResponseCondition(responseProcessing);
    /*
		<responseIf>
			<and>
				<match>
					<baseValue baseType="identifier">correct</baseValue>
					<variable identifier="FEEDBACKBASIC" />
				</match>
			</and>
			<setOutcomeValue identifier="FEEDBACKMODAL">
				<multiple>
					<variable identifier="FEEDBACKMODAL" />
					<baseValue baseType="identifier">Feedback261171147</baseValue>
				</multiple>
			</setOutcomeValue>
		</responseIf>
		*/
    ResponseIf responseIf = new ResponseIf(rule);
    rule.setResponseIf(responseIf);
    {
        // rule
        And and = new And(responseIf);
        responseIf.getExpressions().add(and);
        Match match = new Match(and);
        and.getExpressions().add(match);
        BaseValue feedbackVal = new BaseValue(match);
        feedbackVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
        feedbackVal.setSingleValue(new IdentifierValue(inCorrect));
        match.getExpressions().add(feedbackVal);
        Variable variable = new Variable(match);
        variable.setIdentifier(ComplexReferenceIdentifier.parseString(QTI21Constants.FEEDBACKBASIC));
        match.getExpressions().add(variable);
        // not match the HINT
        if (hint) {
            IsNull isNull = new IsNull(and);
            and.getExpressions().add(isNull);
            Variable hintVar = new Variable(isNull);
            hintVar.setIdentifier(QTI21Constants.HINT_FEEDBACKMODAL_CLX_IDENTIFIER);
            isNull.getExpressions().add(hintVar);
        }
    }
    {
        // outcome
        SetOutcomeValue feedbackVar = new SetOutcomeValue(responseIf);
        feedbackVar.setIdentifier(QTI21Constants.FEEDBACKMODAL_IDENTIFIER);
        Multiple multiple = new Multiple(feedbackVar);
        feedbackVar.setExpression(multiple);
        Variable variable = new Variable(multiple);
        variable.setIdentifier(ComplexReferenceIdentifier.parseString(QTI21Constants.FEEDBACKMODAL));
        multiple.getExpressions().add(variable);
        BaseValue feedbackVal = new BaseValue(feedbackVar);
        feedbackVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
        feedbackVal.setSingleValue(new IdentifierValue(feedbackIdentifier));
        multiple.getExpressions().add(feedbackVal);
        responseIf.getResponseRules().add(feedbackVar);
    }
    return rule;
}
Also used : Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) Multiple(uk.ac.ed.ph.jqtiplus.node.expression.operator.Multiple) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) And(uk.ac.ed.ph.jqtiplus.node.expression.operator.And) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) IsNull(uk.ac.ed.ph.jqtiplus.node.expression.operator.IsNull) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition) Match(uk.ac.ed.ph.jqtiplus.node.expression.operator.Match)

Example 25 with ResponseIf

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

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

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