Search in sources :

Example 36 with IdentifierValue

use of uk.ac.ed.ph.jqtiplus.value.IdentifierValue 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 37 with IdentifierValue

use of uk.ac.ed.ph.jqtiplus.value.IdentifierValue in project OpenOLAT by OpenOLAT.

the class AssessmentItemFactory method appendIdentifierValue.

private static void appendIdentifierValue(CorrectResponse correctResponse, Identifier correctResponseId) {
    FieldValue fieldValue = new FieldValue(correctResponse);
    IdentifierValue identifierValue = new IdentifierValue(correctResponseId);
    fieldValue.setSingleValue(identifierValue);
    correctResponse.getFieldValues().add(fieldValue);
}
Also used : IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)

Example 38 with IdentifierValue

use of uk.ac.ed.ph.jqtiplus.value.IdentifierValue 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 39 with IdentifierValue

use of uk.ac.ed.ph.jqtiplus.value.IdentifierValue in project OpenOLAT by OpenOLAT.

the class SingleChoiceAssessmentItemBuilder method extract.

@Override
public void extract() {
    super.extract();
    if (choiceInteraction != null) {
        ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(choiceInteraction.getResponseIdentifier());
        if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
            CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
            List<FieldValue> values = correctResponse.getFieldValues();
            Value value = FieldValue.computeValue(Cardinality.SINGLE, values);
            if (value instanceof IdentifierValue) {
                IdentifierValue identifierValue = (IdentifierValue) value;
                correctAnswer = identifierValue.identifierValue();
            }
        }
    }
}
Also used : BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) AssessmentItemFactory.createSingleChoiceCorrectResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createSingleChoiceCorrectResponseDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 40 with IdentifierValue

use of uk.ac.ed.ph.jqtiplus.value.IdentifierValue in project OpenOLAT by OpenOLAT.

the class SingleChoiceAssessmentItemBuilder method buildMainScoreRuleAllCorrectAnswers.

private void buildMainScoreRuleAllCorrectAnswers(ResponseCondition rule) {
    ensureFeedbackBasicOutcomeDeclaration();
    /*
			<responseIf>
				<isNull>
					<variable identifier="RESPONSE_1" />
				</isNull>
				<setOutcomeValue identifier="FEEDBACKBASIC">
					<baseValue baseType="identifier">
						empty
					</baseValue>
				</setOutcomeValue>
			</responseIf>
		*/
    // 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(responseIdentifier.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);
    }
    /*
			<responseElseIf>
				<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>
			</responseElseIf>
		*/
    // 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(responseIdentifier.toString()));
        match.getExpressions().add(responseVar);
        Correct correct = new Correct(match);
        correct.setIdentifier(ComplexReferenceIdentifier.parseString(responseIdentifier.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);
    }
    /*
			<responseElse>
				<setOutcomeValue identifier="FEEDBACKBASIC">
					<baseValue baseType="identifier">
						incorrect
					</baseValue>
				</setOutcomeValue>
			</responseElse>
		</responseCondition>
		*/
    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);
    }
}
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) IsNull(uk.ac.ed.ph.jqtiplus.node.expression.operator.IsNull) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) Sum(uk.ac.ed.ph.jqtiplus.node.expression.operator.Sum) 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)

Aggregations

IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)56 BaseValue (uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue)26 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)24 Value (uk.ac.ed.ph.jqtiplus.value.Value)22 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)18 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)18 Variable (uk.ac.ed.ph.jqtiplus.node.expression.general.Variable)16 SetOutcomeValue (uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue)16 FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)16 MultipleValue (uk.ac.ed.ph.jqtiplus.value.MultipleValue)16 IntegerValue (uk.ac.ed.ph.jqtiplus.value.IntegerValue)14 ResponseIf (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf)12 OrderedValue (uk.ac.ed.ph.jqtiplus.value.OrderedValue)12 Match (uk.ac.ed.ph.jqtiplus.node.expression.operator.Match)10 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)10 ResponseCondition (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)10 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 IsNull (uk.ac.ed.ph.jqtiplus.node.expression.operator.IsNull)8 MapEntry (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry)8