Search in sources :

Example 6 with ResponseRule

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

the class AssessmentItemBuilder method build.

public final void build() {
    List<OutcomeDeclaration> outcomeDeclarations = assessmentItem.getOutcomeDeclarations();
    outcomeDeclarations.clear();
    ResponseProcessing responseProcessing = assessmentItem.getResponseProcessing();
    List<ResponseRule> responseRules = responseProcessing.getResponseRules();
    responseRules.clear();
    List<ResponseDeclaration> responseDeclarations = assessmentItem.getResponseDeclarations();
    responseDeclarations.clear();
    List<ModalFeedback> modalFeedbacks = assessmentItem.getModalFeedbacks();
    modalFeedbacks.clear();
    buildItemBody();
    buildResponseAndOutcomeDeclarations();
    buildModalFeedbacksAndHints(outcomeDeclarations, responseRules);
    buildMinMaxScores(outcomeDeclarations, responseRules);
    buildMainScoreRule(outcomeDeclarations, responseRules);
    buildHint(outcomeDeclarations, responseRules);
}
Also used : ModalFeedback(uk.ac.ed.ph.jqtiplus.node.item.ModalFeedback) ResponseProcessing(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing) OutcomeDeclaration(uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) ResponseRule(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule)

Example 7 with ResponseRule

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

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 8 with ResponseRule

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

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 9 with ResponseRule

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

the class AssessmentItemBuilder method buildMinMaxScores.

/**
 * Add outcome declaration for score, min. score and mx. score.
 * and the response rules which ensure that the score is between
 * the max. score and min. score.
 *
 * @param outcomeDeclarations
 * @param responseRules
 */
protected final void buildMinMaxScores(List<OutcomeDeclaration> outcomeDeclarations, List<ResponseRule> responseRules) {
    if ((getMinScoreBuilder() != null && getMinScoreBuilder().getScore() != null) || (getMaxScoreBuilder() != null && getMaxScoreBuilder().getScore() != null)) {
        OutcomeDeclaration outcomeDeclaration = AssessmentItemFactory.createOutcomeDeclarationForScore(assessmentItem);
        outcomeDeclarations.add(outcomeDeclaration);
    }
    if (getMinScoreBuilder() != null && getMinScoreBuilder().getScore() != null) {
        OutcomeDeclaration outcomeDeclaration = AssessmentItemFactory.createOutcomeDeclarationForMinScore(assessmentItem, getMinScoreBuilder().getScore().doubleValue());
        outcomeDeclarations.add(outcomeDeclaration);
        // ensure that the score is not smaller than min. score value
        ResponseRule minScoreBoundResponseRule = AssessmentItemFactory.createMinScoreBoundLimitRule(assessmentItem.getResponseProcessing());
        responseRules.add(minScoreBoundResponseRule);
    }
    if (getMaxScoreBuilder() != null && getMaxScoreBuilder().getScore() != null) {
        OutcomeDeclaration outcomeDeclaration = AssessmentItemFactory.createOutcomeDeclarationForMaxScore(assessmentItem, getMaxScoreBuilder().getScore().doubleValue());
        outcomeDeclarations.add(outcomeDeclaration);
        // ensure that the score is not bigger than the max. score value
        ResponseRule maxScoreBoundResponseRule = AssessmentItemFactory.createMaxScoreBoundLimitRule(assessmentItem.getResponseProcessing());
        responseRules.add(maxScoreBoundResponseRule);
    }
}
Also used : OutcomeDeclaration(uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration) ResponseRule(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule)

Example 10 with ResponseRule

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

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)

Aggregations

ResponseRule (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule)10 ResponseCondition (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)6 ResponseIf (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf)6 SetOutcomeValue (uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue)6 Expression (uk.ac.ed.ph.jqtiplus.node.expression.Expression)4 And (uk.ac.ed.ph.jqtiplus.node.expression.operator.And)4 OutcomeDeclaration (uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration)4 BaseValue (uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue)2 Variable (uk.ac.ed.ph.jqtiplus.node.expression.general.Variable)2 Equal (uk.ac.ed.ph.jqtiplus.node.expression.operator.Equal)2 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)2 ModalFeedback (uk.ac.ed.ph.jqtiplus.node.item.ModalFeedback)2 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)2 ResponseProcessing (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing)2 FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)2 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)2 FloatValue (uk.ac.ed.ph.jqtiplus.value.FloatValue)2 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)2