Search in sources :

Example 41 with OutcomeDeclaration

use of uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration 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 42 with OutcomeDeclaration

use of uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration 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 43 with OutcomeDeclaration

use of uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration in project openolat by klemens.

the class AssessmentItemBuilder method extractMinScore.

private void extractMinScore() {
    OutcomeDeclaration outcomeDeclaration = assessmentItem.getOutcomeDeclaration(MINSCORE_IDENTIFIER);
    if (outcomeDeclaration != null) {
        DefaultValue defaultValue = outcomeDeclaration.getDefaultValue();
        if (defaultValue != null) {
            Value minScoreValue = defaultValue.evaluate();
            if (minScoreValue instanceof FloatValue) {
                Double minScore = new Double(((FloatValue) minScoreValue).doubleValue());
                minScoreBuilder = new ScoreBuilder(minScore, outcomeDeclaration);
            }
        }
    }
}
Also used : DefaultValue(uk.ac.ed.ph.jqtiplus.node.shared.declaration.DefaultValue) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) DefaultValue(uk.ac.ed.ph.jqtiplus.node.shared.declaration.DefaultValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) OutcomeDeclaration(uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration)

Example 44 with OutcomeDeclaration

use of uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration in project openolat by klemens.

the class AssessmentItemBuilder method buildHint.

/**
 * @param outcomeDeclarations
 * @param responseRules
 */
protected void buildHint(List<OutcomeDeclaration> outcomeDeclarations, List<ResponseRule> responseRules) {
    if (hint == null)
        return;
    // response declaration -> identifier=HINTREQUEST -> for the end attempt interaction
    ResponseDeclaration hintResponseDeclaration = AssessmentItemFactory.createHintRequestResponseDeclaration(assessmentItem);
    assessmentItem.getResponseDeclarations().add(hintResponseDeclaration);
    // outcome declaration -> identifier=HINTFEEDBACKMODAL -> for processing and feedback
    OutcomeDeclaration modalOutcomeDeclaration = AssessmentItemFactory.createOutcomeDeclarationForHint(assessmentItem);
    outcomeDeclarations.add(modalOutcomeDeclaration);
    // the body
    P paragraph = new P(assessmentItem.getItemBody());
    assessmentItem.getItemBody().getBlocks().add(paragraph);
    EndAttemptInteraction endAttemptInteraction = new EndAttemptInteraction(paragraph);
    endAttemptInteraction.setResponseIdentifier(QTI21Constants.HINT_REQUEST_IDENTIFIER);
    endAttemptInteraction.setTitle(hint.getTitle());
    paragraph.getInlines().add(endAttemptInteraction);
    // the feedback
    ModalFeedback emptyModalFeedback = AssessmentItemFactory.createModalFeedback(assessmentItem, QTI21Constants.HINT_FEEDBACKMODAL_IDENTIFIER, QTI21Constants.HINT_IDENTIFIER, hint.getTitle(), hint.getText());
    assessmentItem.getModalFeedbacks().add(emptyModalFeedback);
    // the response processing
    ResponseCondition rule = new ResponseCondition(assessmentItem.getResponseProcessing());
    responseRules.add(0, rule);
    ResponseIf responseIf = new ResponseIf(rule);
    rule.setResponseIf(responseIf);
    /*
		<responseIf>
			<variable identifier="HINTREQUEST"/>
			<setOutcomeValue identifier="FEEDBACK">
				<baseValue baseType="identifier">HINT</baseValue>
			</setOutcomeValue>
  		</responseIf>
		*/
    Variable variable = new Variable(responseIf);
    variable.setIdentifier(QTI21Constants.HINT_REQUEST_CLX_IDENTIFIER);
    responseIf.getExpressions().add(variable);
    SetOutcomeValue hintVar = new SetOutcomeValue(responseIf);
    hintVar.setIdentifier(QTI21Constants.HINT_FEEDBACKMODAL_IDENTIFIER);
    BaseValue hintVal = new BaseValue(hintVar);
    hintVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
    hintVal.setSingleValue(new IdentifierValue(QTI21Constants.HINT));
    hintVar.setExpression(hintVal);
    responseIf.getResponseRules().add(hintVar);
}
Also used : P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) ModalFeedback(uk.ac.ed.ph.jqtiplus.node.item.ModalFeedback) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) OutcomeDeclaration(uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Example 45 with OutcomeDeclaration

use of uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration in project openolat by klemens.

the class AssessmentItemBuilder method buildModalFeedbacksAndHints.

/**
 * Add feedbackbasic and feedbackmodal outcomes
 * @param outcomeDeclarations
 * @param responseRules
 */
protected void buildModalFeedbacksAndHints(List<OutcomeDeclaration> outcomeDeclarations, List<ResponseRule> responseRules) {
    if (correctFeedback != null || incorrectFeedback != null || emptyFeedback != null || answeredFeedback != null || correctSolutionFeedback != null || additionalFeedbacks.size() > 0) {
        ensureFeedbackBasicOutcomeDeclaration();
        OutcomeDeclaration modalOutcomeDeclaration = AssessmentItemFactory.createOutcomeDeclarationForFeedbackModal(assessmentItem);
        outcomeDeclarations.add(modalOutcomeDeclaration);
        List<ModalFeedback> modalFeedbacks = assessmentItem.getModalFeedbacks();
        if (correctFeedback != null) {
            appendModalFeedback(correctFeedback, QTI21Constants.CORRECT, modalFeedbacks, responseRules);
        }
        // correct solution must be set before the "incorrect" feedback
        if (correctSolutionFeedback != null) {
            OutcomeDeclaration correctSolutionOutcomeDeclaration = AssessmentItemFactory.createOutcomeDeclarationForCorrectSolutionFeedbackModal(assessmentItem);
            outcomeDeclarations.add(correctSolutionOutcomeDeclaration);
        }
        if (incorrectFeedback != null || correctSolutionFeedback != null) {
            appendCorrectSolutionAndIncorrectModalFeedback(modalFeedbacks, responseRules);
        }
        if (emptyFeedback != null) {
            appendModalFeedback(emptyFeedback, QTI21Constants.EMPTY, modalFeedbacks, responseRules);
        }
        if (answeredFeedback != null) {
            appendModalFeedback(answeredFeedback, QTI21Constants.ANSWERED, modalFeedbacks, responseRules);
        }
        if (additionalFeedbacks.size() > 0) {
            for (ModalFeedbackBuilder feedback : additionalFeedbacks) {
                appendAdditionalFeedback(feedback, modalFeedbacks, responseRules);
            }
        }
    }
}
Also used : ModalFeedback(uk.ac.ed.ph.jqtiplus.node.item.ModalFeedback) OutcomeDeclaration(uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration)

Aggregations

OutcomeDeclaration (uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration)52 DefaultValue (uk.ac.ed.ph.jqtiplus.node.shared.declaration.DefaultValue)18 FloatValue (uk.ac.ed.ph.jqtiplus.value.FloatValue)16 FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)14 ArrayList (java.util.ArrayList)12 BaseValue (uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue)10 View (uk.ac.ed.ph.jqtiplus.node.test.View)10 SetOutcomeValue (uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue)8 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)8 Value (uk.ac.ed.ph.jqtiplus.value.Value)8 ModalFeedback (uk.ac.ed.ph.jqtiplus.node.item.ModalFeedback)6 Variable (uk.ac.ed.ph.jqtiplus.node.expression.general.Variable)4 Sum (uk.ac.ed.ph.jqtiplus.node.expression.operator.Sum)4 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)4 ResponseCondition (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)4 ResponseIf (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf)4 ResponseRule (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule)4 TemplateDeclaration (uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration)4 SetOutcomeValue (uk.ac.ed.ph.jqtiplus.node.test.outcome.processing.SetOutcomeValue)4 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)4