Search in sources :

Example 46 with ResponseCondition

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

the class AssessmentItemBuilder method appendAdditionalFeedback.

protected void appendAdditionalFeedback(ModalFeedbackBuilder feedback, List<ModalFeedback> modalFeedbacks, List<ResponseRule> responseRules) {
    Identifier feedbackIdentifier = feedback.getIdentifier();
    ModalFeedback modalFeedback = AssessmentItemFactory.createModalFeedback(assessmentItem, feedbackIdentifier, feedback.getTitle(), feedback.getText());
    modalFeedbacks.add(modalFeedback);
    Cardinality cardinality = null;
    Identifier responseIdentifier = null;
    if (this instanceof ResponseIdentifierForFeedback) {
        responseIdentifier = ((ResponseIdentifierForFeedback) this).getResponseIdentifier();
        cardinality = assessmentItem.getResponseDeclaration(responseIdentifier).getCardinality();
    }
    ResponseCondition feedbackCondition = AssessmentItemFactory.createModalFeedbackRuleWithConditions(assessmentItem.getResponseProcessing(), feedbackIdentifier, responseIdentifier, cardinality, feedback.getFeedbackConditons());
    responseRules.add(feedbackCondition);
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) Cardinality(uk.ac.ed.ph.jqtiplus.value.Cardinality) ModalFeedback(uk.ac.ed.ph.jqtiplus.node.item.ModalFeedback) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Example 47 with ResponseCondition

use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition 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 48 with ResponseCondition

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

the class AssessmentItemFactory method createResponseProcessing.

public static ResponseProcessing createResponseProcessing(AssessmentItem assessmentItem, Identifier responseId) {
    ResponseProcessing responseProcessing = new ResponseProcessing(assessmentItem);
    ResponseCondition rule = new ResponseCondition(responseProcessing);
    // if no response
    ResponseIf responseIf = new ResponseIf(rule);
    rule.setResponseIf(responseIf);
    IsNull isNull = new IsNull(responseIf);
    responseIf.getExpressions().add(isNull);
    Variable variable = new Variable(isNull);
    variable.setIdentifier(ComplexReferenceIdentifier.parseString(responseId.toString()));
    isNull.getExpressions().add(variable);
    {
        SetOutcomeValue feedbackVar = new SetOutcomeValue(responseIf);
        feedbackVar.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
        BaseValue feedbackVal = new BaseValue(feedbackVar);
        feedbackVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
        feedbackVal.setSingleValue(new IdentifierValue("empty"));
        feedbackVar.setExpression(feedbackVal);
        responseIf.getResponseRules().add(feedbackVar);
    }
    // else if correct response
    ResponseElseIf responseElseIf = new ResponseElseIf(rule);
    rule.getResponseElseIfs().add(responseElseIf);
    // match
    {
        Match match = new Match(responseElseIf);
        responseElseIf.getExpressions().add(match);
        Variable responseVar = new Variable(match);
        responseVar.setIdentifier(ComplexReferenceIdentifier.parseString(responseId.toString()));
        match.getExpressions().add(responseVar);
        Correct correct = new Correct(match);
        correct.setIdentifier(ComplexReferenceIdentifier.parseString(responseId.toString()));
        match.getExpressions().add(correct);
    }
    // outcome score
    {
        SetOutcomeValue scoreOutcomeVar = new SetOutcomeValue(responseIf);
        scoreOutcomeVar.setIdentifier(QTI21Constants.SCORE_IDENTIFIER);
        responseElseIf.getResponseRules().add(scoreOutcomeVar);
        Sum sum = new Sum(scoreOutcomeVar);
        scoreOutcomeVar.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 correctFeedbackVar = new SetOutcomeValue(responseIf);
        correctFeedbackVar.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
        BaseValue correctFeedbackVal = new BaseValue(correctFeedbackVar);
        correctFeedbackVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
        correctFeedbackVal.setSingleValue(QTI21Constants.CORRECT_IDENTIFIER_VALUE);
        correctFeedbackVar.setExpression(correctFeedbackVal);
        responseElseIf.getResponseRules().add(correctFeedbackVar);
    }
    // else failed
    ResponseElse responseElse = new ResponseElse(rule);
    rule.setResponseElse(responseElse);
    {
        // feedback incorrect
        SetOutcomeValue incorrectFeedbackVar = new SetOutcomeValue(responseIf);
        incorrectFeedbackVar.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
        BaseValue incorrectFeedbackVal = new BaseValue(incorrectFeedbackVar);
        incorrectFeedbackVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
        incorrectFeedbackVal.setSingleValue(QTI21Constants.INCORRECT_IDENTIFIER_VALUE);
        incorrectFeedbackVar.setExpression(incorrectFeedbackVal);
        responseElse.getResponseRules().add(incorrectFeedbackVar);
    }
    responseProcessing.getResponseRules().add(rule);
    return responseProcessing;
}
Also used : 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) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) Sum(uk.ac.ed.ph.jqtiplus.node.expression.operator.Sum) ResponseProcessing(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing) 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) ResponseElse(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseElse) IsNull(uk.ac.ed.ph.jqtiplus.node.expression.operator.IsNull) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Example 49 with ResponseCondition

use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition 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 50 with ResponseCondition

use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition 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)

Aggregations

ResponseCondition (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)54 ResponseIf (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf)28 SetOutcomeValue (uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue)28 Variable (uk.ac.ed.ph.jqtiplus.node.expression.general.Variable)22 BaseValue (uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue)18 And (uk.ac.ed.ph.jqtiplus.node.expression.operator.And)16 Match (uk.ac.ed.ph.jqtiplus.node.expression.operator.Match)10 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)10 ModalFeedback (uk.ac.ed.ph.jqtiplus.node.item.ModalFeedback)8 ArrayList (java.util.ArrayList)6 Expression (uk.ac.ed.ph.jqtiplus.node.expression.Expression)6 Correct (uk.ac.ed.ph.jqtiplus.node.expression.general.Correct)6 Equal (uk.ac.ed.ph.jqtiplus.node.expression.operator.Equal)6 IsNull (uk.ac.ed.ph.jqtiplus.node.expression.operator.IsNull)6 Multiple (uk.ac.ed.ph.jqtiplus.node.expression.operator.Multiple)6 Sum (uk.ac.ed.ph.jqtiplus.node.expression.operator.Sum)6 ResponseRule (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule)6 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)6 FloatValue (uk.ac.ed.ph.jqtiplus.value.FloatValue)6 MapResponse (uk.ac.ed.ph.jqtiplus.node.expression.general.MapResponse)4