Search in sources :

Example 6 with ResponseIf

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

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 7 with ResponseIf

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

the class AssessmentItemFactory method createMinScoreBoundLimitRule.

/**
 * Rule which ensure that the final score is not under the min. score value.
 */
public static ResponseRule createMinScoreBoundLimitRule(ResponseProcessing responseProcessing) {
    /*
		<responseCondition>
			<responseIf>
				<lt>
					<variable identifier="SCORE" /><variable identifier="MINSCORE" />
				</lt>
				<setOutcomeValue identifier="SCORE">
					<variable identifier="MINSCORE" />
				</setOutcomeValue>
			</responseIf>
		</responseCondition>
		*/
    ResponseCondition rule = new ResponseCondition(responseProcessing);
    ResponseIf responseIf = new ResponseIf(rule);
    rule.setResponseIf(responseIf);
    Lt lt = new Lt(responseIf);
    responseIf.setExpression(lt);
    Variable scoreVar = new Variable(lt);
    scoreVar.setIdentifier(SCORE_CLX_IDENTIFIER);
    lt.getExpressions().add(scoreVar);
    Variable minScoreVar = new Variable(lt);
    minScoreVar.setIdentifier(MINSCORE_CLX_IDENTIFIER);
    lt.getExpressions().add(minScoreVar);
    SetOutcomeValue setOutcomeValue = new SetOutcomeValue(responseIf);
    setOutcomeValue.setIdentifier(SCORE_IDENTIFIER);
    Variable minScoreOutcomeVar = new Variable(setOutcomeValue);
    minScoreOutcomeVar.setIdentifier(MINSCORE_CLX_IDENTIFIER);
    setOutcomeValue.setExpression(minScoreOutcomeVar);
    responseIf.getResponseRules().add(setOutcomeValue);
    return rule;
}
Also used : Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) Lt(uk.ac.ed.ph.jqtiplus.node.expression.operator.Lt) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Example 8 with ResponseIf

use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf 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;
}
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) Expression(uk.ac.ed.ph.jqtiplus.node.expression.Expression) And(uk.ac.ed.ph.jqtiplus.node.expression.operator.And) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) ResponseRule(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Example 9 with ResponseIf

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

the class FIBAssessmentItemBuilder method extractNumericalEntrySettings.

public static void extractNumericalEntrySettings(AssessmentItem item, NumericalEntry numericalEntry, ResponseDeclaration responseDeclaration, AtomicInteger countAlternatives, DoubleAdder mappedScore) {
    Double solution = null;
    CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
    if (correctResponse != null && correctResponse.getFieldValues().size() > 0) {
        List<FieldValue> fValues = correctResponse.getFieldValues();
        SingleValue sValue = fValues.get(0).getSingleValue();
        if (sValue instanceof FloatValue) {
            solution = ((FloatValue) sValue).doubleValue();
            numericalEntry.setSolution(solution);
        }
    }
    // search the equal
    List<ResponseRule> responseRules = item.getResponseProcessing().getResponseRules();
    a_a: for (ResponseRule responseRule : responseRules) {
        if (responseRule instanceof ResponseCondition) {
            ResponseCondition condition = (ResponseCondition) responseRule;
            ResponseIf responseIf = condition.getResponseIf();
            if (responseIf != null && responseIf.getExpressions().size() > 0) {
                // first is an and/equal/
                Expression potentialEqualOrAnd = responseIf.getExpressions().get(0);
                if (potentialEqualOrAnd instanceof And) {
                    And and = (And) potentialEqualOrAnd;
                    for (Expression potentialEqual : and.getExpressions()) {
                        if (potentialEqual instanceof Equal && potentialEqual.getExpressions().size() == 2 && extractNumericalEntrySettings(numericalEntry, (Equal) potentialEqual)) {
                            break a_a;
                        }
                    }
                } else if (potentialEqualOrAnd instanceof Equal) {
                    if (extractNumericalEntrySettings(numericalEntry, (Equal) potentialEqualOrAnd)) {
                        // find to score as outcome value
                        if (responseIf.getResponseRules() != null && responseIf.getResponseRules().size() == 1 && responseIf.getResponseRules().get(0) instanceof SetOutcomeValue) {
                            SetOutcomeValue outcomeValue = (SetOutcomeValue) responseIf.getResponseRules().get(0);
                            if (outcomeValue.getExpressions() != null && outcomeValue.getExpressions().size() == 1 && outcomeValue.getExpressions().get(0) instanceof BaseValue) {
                                BaseValue bValue = (BaseValue) outcomeValue.getExpressions().get(0);
                                SingleValue sValue = bValue.getSingleValue();
                                if (sValue instanceof FloatValue) {
                                    FloatValue fValue = (FloatValue) sValue;
                                    numericalEntry.setScore(fValue.doubleValue());
                                    mappedScore.add(fValue.doubleValue());
                                    countAlternatives.incrementAndGet();
                                }
                            }
                        }
                        break a_a;
                    }
                }
            }
        }
    }
    // toleranceMode cannot be empty
    if (numericalEntry.getToleranceMode() == null) {
        numericalEntry.setToleranceMode(ToleranceMode.EXACT);
    }
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) 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) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) ResponseRule(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule) Expression(uk.ac.ed.ph.jqtiplus.node.expression.Expression) Equal(uk.ac.ed.ph.jqtiplus.node.expression.operator.Equal) And(uk.ac.ed.ph.jqtiplus.node.expression.operator.And) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Example 10 with ResponseIf

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

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)

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