Search in sources :

Example 26 with BaseValue

use of uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue in project OpenOLAT by OpenOLAT.

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 27 with BaseValue

use of uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue in project OpenOLAT by OpenOLAT.

the class AssessmentItemFactory method appendVariableBaseValue.

/*
		<variable identifier="SCORE" />
		<baseValue baseType="float">4</baseValue>
	 */
/**
 * @param var
 * @param value
 * @param responseIdentifier
 * @param parentExpression
 * @param reverse if true, reverse the order, first baseValue and then variable
 */
private static void appendVariableBaseValue(ModalFeedbackCondition.Variable var, String value, Identifier responseIdentifier, Expression parentExpression, boolean reverse) {
    Variable variable = new Variable(parentExpression);
    BaseValue bValue = new BaseValue(parentExpression);
    if (reverse) {
        parentExpression.getExpressions().add(bValue);
        parentExpression.getExpressions().add(variable);
    } else {
        parentExpression.getExpressions().add(variable);
        parentExpression.getExpressions().add(bValue);
    }
    switch(var) {
        case score:
            bValue.setBaseTypeAttrValue(BaseType.FLOAT);
            bValue.setSingleValue(new FloatValue(Double.parseDouble(value)));
            variable.setIdentifier(QTI21Constants.SCORE_CLX_IDENTIFIER);
            break;
        case attempts:
            bValue.setBaseTypeAttrValue(BaseType.INTEGER);
            bValue.setSingleValue(new IntegerValue(Integer.parseInt(value)));
            variable.setIdentifier(QTI21Constants.NUM_ATTEMPTS_CLX_IDENTIFIER);
            break;
        case response:
            bValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
            bValue.setSingleValue(new IdentifierValue(Identifier.parseString(value)));
            variable.setIdentifier(ComplexReferenceIdentifier.parseString(responseIdentifier.toString()));
            break;
    }
}
Also used : Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue)

Example 28 with BaseValue

use of uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue in project OpenOLAT by OpenOLAT.

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 29 with BaseValue

use of uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue in project OpenOLAT by OpenOLAT.

the class HottextAssessmentItemBuilder method buildMainScoreRuleAllCorrectAnswers.

private void buildMainScoreRuleAllCorrectAnswers(ResponseCondition rule) {
    /*
		<responseCondition>
			<responseIf>
				<match>
					<variable identifier="RESPONSE_1" />
					<correct identifier="RESPONSE_1" />
				</match>
				<setOutcomeValue identifier="SCORE">
					<sum>
						<variable identifier="SCORE" />
						<variable identifier="MAXSCORE" />
					</sum>
				</setOutcomeValue>
				<setOutcomeValue identifier="FEEDBACKBASIC">
					<baseValue baseType="identifier">correct</baseValue>
				</setOutcomeValue>
			</responseIf>
			<responseElse>
				<setOutcomeValue identifier="FEEDBACKBASIC">
					<baseValue baseType="identifier">incorrect</baseValue>
				</setOutcomeValue>
			</responseElse>
		</responseCondition>
		 */
    // simple as build with / without feedback
    ensureFeedbackBasicOutcomeDeclaration();
    ResponseIf responseIf = new ResponseIf(rule);
    rule.setResponseIf(responseIf);
    {
        // match the correct answers
        matchCorrectAnswers(responseIf);
    }
    {
        // outcome score
        SetOutcomeValue scoreOutcomeValue = new SetOutcomeValue(responseIf);
        scoreOutcomeValue.setIdentifier(QTI21Constants.SCORE_IDENTIFIER);
        responseIf.getResponseRules().add(scoreOutcomeValue);
        Sum sum = new Sum(scoreOutcomeValue);
        scoreOutcomeValue.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 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);
    }
    ResponseElse responseElse = new ResponseElse(rule);
    rule.setResponseElse(responseElse);
    {
        // outcome feedback
        SetOutcomeValue incorrectOutcomeValue = new SetOutcomeValue(responseElse);
        incorrectOutcomeValue.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
        responseElse.getResponseRules().add(incorrectOutcomeValue);
        BaseValue incorrectValue = new BaseValue(incorrectOutcomeValue);
        incorrectValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
        incorrectValue.setSingleValue(QTI21Constants.INCORRECT_IDENTIFIER_VALUE);
        incorrectOutcomeValue.setExpression(incorrectValue);
    }
}
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) ResponseElse(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseElse) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) Sum(uk.ac.ed.ph.jqtiplus.node.expression.operator.Sum)

Example 30 with BaseValue

use of uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue in project OpenOLAT by OpenOLAT.

the class MultipleChoiceAssessmentItemBuilder method buildMainScoreRuleAllCorrectAnswers.

private void buildMainScoreRuleAllCorrectAnswers(ResponseCondition rule) {
    /*
		<responseCondition>
			<responseIf>
				<match>
					<variable identifier="RESPONSE_1" />
					<correct identifier="RESPONSE_1" />
				</match>
				<setOutcomeValue identifier="SCORE">
					<sum>
						<variable identifier="SCORE" />
						<variable identifier="MAXSCORE" />
					</sum>
				</setOutcomeValue>
				<setOutcomeValue identifier="FEEDBACKBASIC">
					<baseValue baseType="identifier">correct</baseValue>
				</setOutcomeValue>
			</responseIf>
			<responseElse>
				<setOutcomeValue identifier="FEEDBACKBASIC">
					<baseValue baseType="identifier">incorrect</baseValue>
				</setOutcomeValue>
			</responseElse>
		</responseCondition>
		 */
    // simple as build with / without feedback
    ensureFeedbackBasicOutcomeDeclaration();
    ResponseIf responseIf = new ResponseIf(rule);
    rule.setResponseIf(responseIf);
    {
        // match the correct answers
        Match match = new Match(responseIf);
        responseIf.getExpressions().add(match);
        Variable scoreVar = new Variable(match);
        ComplexReferenceIdentifier choiceResponseIdentifier = ComplexReferenceIdentifier.parseString(choiceInteraction.getResponseIdentifier().toString());
        scoreVar.setIdentifier(choiceResponseIdentifier);
        match.getExpressions().add(scoreVar);
        Correct correct = new Correct(match);
        correct.setIdentifier(choiceResponseIdentifier);
        match.getExpressions().add(correct);
    }
    {
        // outcome score
        SetOutcomeValue scoreOutcomeValue = new SetOutcomeValue(responseIf);
        scoreOutcomeValue.setIdentifier(QTI21Constants.SCORE_IDENTIFIER);
        responseIf.getResponseRules().add(scoreOutcomeValue);
        Sum sum = new Sum(scoreOutcomeValue);
        scoreOutcomeValue.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 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);
    }
    ResponseElse responseElse = new ResponseElse(rule);
    rule.setResponseElse(responseElse);
    {
        // outcome feedback
        SetOutcomeValue incorrectOutcomeValue = new SetOutcomeValue(responseElse);
        incorrectOutcomeValue.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
        responseElse.getResponseRules().add(incorrectOutcomeValue);
        BaseValue incorrectValue = new BaseValue(incorrectOutcomeValue);
        incorrectValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
        incorrectValue.setSingleValue(QTI21Constants.INCORRECT_IDENTIFIER_VALUE);
        incorrectOutcomeValue.setExpression(incorrectValue);
    }
}
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) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) ResponseElse(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseElse) 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) Match(uk.ac.ed.ph.jqtiplus.node.expression.operator.Match)

Aggregations

BaseValue (uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue)56 SetOutcomeValue (uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue)42 Variable (uk.ac.ed.ph.jqtiplus.node.expression.general.Variable)40 ResponseIf (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf)38 Match (uk.ac.ed.ph.jqtiplus.node.expression.operator.Match)24 Sum (uk.ac.ed.ph.jqtiplus.node.expression.operator.Sum)24 ResponseElse (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseElse)20 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)20 Correct (uk.ac.ed.ph.jqtiplus.node.expression.general.Correct)18 ResponseCondition (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)18 IsNull (uk.ac.ed.ph.jqtiplus.node.expression.operator.IsNull)16 MapResponse (uk.ac.ed.ph.jqtiplus.node.expression.general.MapResponse)14 And (uk.ac.ed.ph.jqtiplus.node.expression.operator.And)14 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)14 FloatValue (uk.ac.ed.ph.jqtiplus.value.FloatValue)12 ResponseElseIf (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseElseIf)10 Expression (uk.ac.ed.ph.jqtiplus.node.expression.Expression)8 Multiple (uk.ac.ed.ph.jqtiplus.node.expression.operator.Multiple)8 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)8 Equal (uk.ac.ed.ph.jqtiplus.node.expression.operator.Equal)6