Search in sources :

Example 31 with Match

use of uk.ac.ed.ph.jqtiplus.node.expression.operator.Match in project openolat by klemens.

the class AssessmentItemFactory method appendModalFeedbackCondition.

private static void appendModalFeedbackCondition(ModalFeedbackCondition condition, Identifier responseIdentifier, Cardinality cardinality, And and) {
    ModalFeedbackCondition.Variable var = condition.getVariable();
    ModalFeedbackCondition.Operator operator = condition.getOperator();
    String value = condition.getValue();
    if (var == ModalFeedbackCondition.Variable.response) {
        if (cardinality == Cardinality.MULTIPLE) {
            if (operator == ModalFeedbackCondition.Operator.equals) {
                Member member = new Member(and);
                and.getExpressions().add(member);
                appendVariableBaseValue(var, value, responseIdentifier, member, true);
            } else if (operator == ModalFeedbackCondition.Operator.notEquals) {
                Not not = new Not(and);
                and.getExpressions().add(not);
                Member member = new Member(not);
                not.getExpressions().add(member);
                appendVariableBaseValue(var, value, responseIdentifier, member, true);
            }
        } else {
            if (operator == ModalFeedbackCondition.Operator.equals) {
                Match match = new Match(and);
                and.getExpressions().add(match);
                appendVariableBaseValue(var, value, responseIdentifier, match, false);
            } else if (operator == ModalFeedbackCondition.Operator.notEquals) {
                Not not = new Not(and);
                and.getExpressions().add(not);
                Match match = new Match(not);
                not.getExpressions().add(match);
                appendVariableBaseValue(var, value, responseIdentifier, match, false);
            }
        }
    } else {
        switch(operator) {
            case bigger:
                {
                    Gt gt = new Gt(and);
                    and.getExpressions().add(gt);
                    appendVariableBaseValue(var, value, responseIdentifier, gt, false);
                    break;
                }
            case biggerEquals:
                {
                    Gte gte = new Gte(and);
                    and.getExpressions().add(gte);
                    appendVariableBaseValue(var, value, responseIdentifier, gte, false);
                    break;
                }
            case equals:
                {
                    Equal equal = new Equal(and);
                    equal.setToleranceMode(ToleranceMode.EXACT);
                    and.getExpressions().add(equal);
                    appendVariableBaseValue(var, value, responseIdentifier, equal, false);
                    break;
                }
            case notEquals:
                {
                    Not not = new Not(and);
                    and.getExpressions().add(not);
                    Equal equal = new Equal(not);
                    equal.setToleranceMode(ToleranceMode.EXACT);
                    not.getExpressions().add(equal);
                    appendVariableBaseValue(var, value, responseIdentifier, equal, false);
                    break;
                }
            case smaller:
                {
                    Lt lt = new Lt(and);
                    and.getExpressions().add(lt);
                    appendVariableBaseValue(var, value, responseIdentifier, lt, false);
                    break;
                }
            case smallerEquals:
                {
                    Lte lte = new Lte(and);
                    and.getExpressions().add(lte);
                    appendVariableBaseValue(var, value, responseIdentifier, lte, false);
                    break;
                }
        }
    }
}
Also used : Not(uk.ac.ed.ph.jqtiplus.node.expression.operator.Not) Equal(uk.ac.ed.ph.jqtiplus.node.expression.operator.Equal) Lt(uk.ac.ed.ph.jqtiplus.node.expression.operator.Lt) Gte(uk.ac.ed.ph.jqtiplus.node.expression.operator.Gte) Lte(uk.ac.ed.ph.jqtiplus.node.expression.operator.Lte) Member(uk.ac.ed.ph.jqtiplus.node.expression.operator.Member) Gt(uk.ac.ed.ph.jqtiplus.node.expression.operator.Gt) Match(uk.ac.ed.ph.jqtiplus.node.expression.operator.Match)

Example 32 with Match

use of uk.ac.ed.ph.jqtiplus.node.expression.operator.Match in project openolat by klemens.

the class AssessmentItemFactory method createModalFeedbackResponseConditionByScore.

/**
 * This generate a response rule which compare the max score and the score
 * to set the feedback as "correct".
 *
 *	<responseCondition>
 *		<responseIf>
 *			<and>
 *				<not>
 *					<match>
 *						<variable identifier="FEEDBACKBASIC" />
 *						<baseValue baseType="identifier">empty</baseValue>
 *					</match>
 *				</not>
 *				<equal toleranceMode="exact">
 *					<variable identifier="SCORE" />
 *					<variable identifier="MAXSCORE" />
 *				</equal>
 *			</and>
 *			<setOutcomeValue identifier="FEEDBACKBASIC">
 *				<baseValue baseType="identifier">correct</baseValue>
 *			</setOutcomeValue>
 *		</responseIf>
 *	</responseCondition>
 */
public static ResponseCondition createModalFeedbackResponseConditionByScore(ResponseProcessing responseProcessing) {
    ResponseCondition responseCondition = new ResponseCondition(responseProcessing);
    ResponseIf responseIf = new ResponseIf(responseCondition);
    responseCondition.setResponseIf(responseIf);
    And and = new And(responseIf);
    responseIf.getExpressions().add(and);
    Not not = new Not(and);
    and.getExpressions().add(not);
    Match match = new Match(not);
    not.getExpressions().add(match);
    Variable feedbackbasicVar = new Variable(match);
    feedbackbasicVar.setIdentifier(QTI21Constants.FEEDBACKBASIC_CLX_IDENTIFIER);
    match.getExpressions().add(feedbackbasicVar);
    BaseValue emptyValue = new BaseValue(match);
    emptyValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
    emptyValue.setSingleValue(QTI21Constants.EMPTY_IDENTIFIER_VALUE);
    match.getExpressions().add(emptyValue);
    // SCORE >= MAXSCORE ( > is for security and special case where the max score is smalle than the sum of correct answers)
    Gte greaterOrEqual = new Gte(and);
    and.getExpressions().add(greaterOrEqual);
    Variable scoreVar = new Variable(greaterOrEqual);
    scoreVar.setIdentifier(QTI21Constants.SCORE_CLX_IDENTIFIER);
    greaterOrEqual.getExpressions().add(scoreVar);
    Variable maxScoreVar = new Variable(greaterOrEqual);
    maxScoreVar.setIdentifier(QTI21Constants.MAXSCORE_CLX_IDENTIFIER);
    greaterOrEqual.getExpressions().add(maxScoreVar);
    // outcome value
    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);
    return responseCondition;
}
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) And(uk.ac.ed.ph.jqtiplus.node.expression.operator.And) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) Gte(uk.ac.ed.ph.jqtiplus.node.expression.operator.Gte) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition) Match(uk.ac.ed.ph.jqtiplus.node.expression.operator.Match)

Example 33 with Match

use of uk.ac.ed.ph.jqtiplus.node.expression.operator.Match in project openolat by klemens.

the class AssessmentItemFactory method createCorrectSolutionModalFeedbackBasicRule.

/**
 * Generate the special case for "correct solution" feedback which is almost the same as
 * incorrect feedback.
 *
 * @param responseProcessing
 * @param feedbackIdentifier
 * @return
 */
public static ResponseCondition createCorrectSolutionModalFeedbackBasicRule(ResponseProcessing responseProcessing, Identifier correctSolutionFeedbackIdentifier, Identifier incorrectFeedbackIdentifier, boolean hint) {
    ResponseCondition rule = new ResponseCondition(responseProcessing);
    /*
		<responseIf>
			<and>
				<match>
					<baseValue baseType="identifier">incorrect</baseValue>
					<variable identifier="FEEDBACKBASIC" />
				</match>
			</and>
			<setOutcomeValue identifier="FEEDBACKMODAL">
				<multiple>
					<variable identifier="FEEDBACKMODAL" />
					<baseValue baseType="identifier">Feedback261171147</baseValue>
				</multiple>
			</setOutcomeValue>
			<setOutcomeValue identifier="SOLUTIONMODAL">
				<baseValue baseType="identifier">Feedback261171147</baseValue>
			</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(QTI21Constants.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);
        }
    }
    if (incorrectFeedbackIdentifier != null) {
        // outcome incorrect
        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(incorrectFeedbackIdentifier));
        multiple.getExpressions().add(feedbackVal);
        responseIf.getResponseRules().add(feedbackVar);
    }
    if (correctSolutionFeedbackIdentifier != null) {
        // outcome correct solution
        SetOutcomeValue feedbackVar = new SetOutcomeValue(responseIf);
        feedbackVar.setIdentifier(QTI21Constants.CORRECT_SOLUTION_IDENTIFIER);
        BaseValue feedbackVal = new BaseValue(feedbackVar);
        feedbackVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
        feedbackVal.setSingleValue(new IdentifierValue(correctSolutionFeedbackIdentifier));
        feedbackVar.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 34 with Match

use of uk.ac.ed.ph.jqtiplus.node.expression.operator.Match in project openolat by klemens.

the class TestFeedbackBuilder method findFeedbackMatch.

private boolean findFeedbackMatch(OutcomeRule outcomeRule, boolean pass, ComplexReferenceIdentifier id) {
    if (outcomeRule instanceof OutcomeCondition) {
        OutcomeCondition outcomeCondition = (OutcomeCondition) outcomeRule;
        OutcomeIf outcomeIf = outcomeCondition.getOutcomeIf();
        if (outcomeIf != null && outcomeIf.getExpressions().size() == 1) {
            Expression mustBeAnd = outcomeIf.getExpressions().get(0);
            if (mustBeAnd instanceof And && mustBeAnd.getExpressions().size() == 1) {
                Expression mustBeMatch = mustBeAnd.getExpressions().get(0);
                if (mustBeMatch instanceof Match && mustBeMatch.getExpressions().size() == 2) {
                    return findFeedbackMatch((Match) mustBeMatch, pass, id);
                }
            }
        }
    }
    return false;
}
Also used : Expression(uk.ac.ed.ph.jqtiplus.node.expression.Expression) OutcomeIf(uk.ac.ed.ph.jqtiplus.node.test.outcome.processing.OutcomeIf) And(uk.ac.ed.ph.jqtiplus.node.expression.operator.And) OutcomeCondition(uk.ac.ed.ph.jqtiplus.node.test.outcome.processing.OutcomeCondition) Match(uk.ac.ed.ph.jqtiplus.node.expression.operator.Match)

Aggregations

Match (uk.ac.ed.ph.jqtiplus.node.expression.operator.Match)34 Variable (uk.ac.ed.ph.jqtiplus.node.expression.general.Variable)30 ResponseIf (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf)26 BaseValue (uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue)24 Correct (uk.ac.ed.ph.jqtiplus.node.expression.general.Correct)22 SetOutcomeValue (uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue)22 ResponseElse (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseElse)20 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)18 IsNull (uk.ac.ed.ph.jqtiplus.node.expression.operator.IsNull)16 Sum (uk.ac.ed.ph.jqtiplus.node.expression.operator.Sum)16 And (uk.ac.ed.ph.jqtiplus.node.expression.operator.And)12 ResponseCondition (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)10 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)10 MapResponse (uk.ac.ed.ph.jqtiplus.node.expression.general.MapResponse)8 ResponseElseIf (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseElseIf)8 Multiple (uk.ac.ed.ph.jqtiplus.node.expression.operator.Multiple)6 AssessmentItemFactory.appendSetOutcomeFeedbackCorrect (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendSetOutcomeFeedbackCorrect)4 Equal (uk.ac.ed.ph.jqtiplus.node.expression.operator.Equal)4 Gte (uk.ac.ed.ph.jqtiplus.node.expression.operator.Gte)4 Not (uk.ac.ed.ph.jqtiplus.node.expression.operator.Not)4