Search in sources :

Example 21 with IdentifierValue

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

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 22 with IdentifierValue

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

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)

Example 23 with IdentifierValue

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

the class AssessmentTestFactory method createTestFeedbackModalCondition.

/*
	<outcomeCondition>
		<outcomeIf>
			<and>
				<match>
					<baseValue baseType="boolean">
						false
					</baseValue>
					<variable identifier="PASS" />
				</match>
			</and>
			<setOutcomeValue identifier="FEEDBACKMODAL">
				<multiple>
					<variable identifier="FEEDBACKMODAL" />
					<baseValue baseType="identifier">
						Feedback1757237693
					</baseValue>
				</multiple>
			</setOutcomeValue>
		</outcomeIf>
	</outcomeCondition>
	 */
public static final OutcomeCondition createTestFeedbackModalCondition(AssessmentTest assessmentTest, boolean condition, Identifier feedbackIdentifier) {
    OutcomeCondition outcomeCondition = new OutcomeCondition(assessmentTest);
    OutcomeIf outcomeIf = new OutcomeIf(outcomeCondition);
    outcomeCondition.setOutcomeIf(outcomeIf);
    {
        // condition
        And and = new And(outcomeIf);
        outcomeIf.getExpressions().add(and);
        Match match = new Match(and);
        and.getExpressions().add(match);
        BaseValue feedbackVal = new BaseValue(match);
        feedbackVal.setBaseTypeAttrValue(BaseType.BOOLEAN);
        feedbackVal.setSingleValue(condition ? BooleanValue.TRUE : BooleanValue.FALSE);
        match.getExpressions().add(feedbackVal);
        Variable variable = new Variable(match);
        variable.setIdentifier(ComplexReferenceIdentifier.parseString(QTI21Constants.PASS));
        match.getExpressions().add(variable);
    }
    {
        // outcome
        SetOutcomeValue setOutcomeValue = new SetOutcomeValue(outcomeIf);
        setOutcomeValue.setIdentifier(QTI21Constants.FEEDBACKMODAL_IDENTIFIER);
        outcomeIf.getOutcomeRules().add(setOutcomeValue);
        Multiple multiple = new Multiple(setOutcomeValue);
        setOutcomeValue.getExpressions().add(multiple);
        Variable variable = new Variable(multiple);
        variable.setIdentifier(ComplexReferenceIdentifier.parseString(QTI21Constants.FEEDBACKMODAL));
        multiple.getExpressions().add(variable);
        BaseValue feedbackVal = new BaseValue(multiple);
        feedbackVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
        feedbackVal.setSingleValue(new IdentifierValue(feedbackIdentifier));
        multiple.getExpressions().add(feedbackVal);
    }
    return outcomeCondition;
}
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.test.outcome.processing.SetOutcomeValue) OutcomeIf(uk.ac.ed.ph.jqtiplus.node.test.outcome.processing.OutcomeIf) And(uk.ac.ed.ph.jqtiplus.node.expression.operator.And) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) OutcomeCondition(uk.ac.ed.ph.jqtiplus.node.test.outcome.processing.OutcomeCondition) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) Match(uk.ac.ed.ph.jqtiplus.node.expression.operator.Match)

Example 24 with IdentifierValue

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

the class AssessmentItemFactory method createOutcomeDeclarationForFeedbackBasic.

public static OutcomeDeclaration createOutcomeDeclarationForFeedbackBasic(AssessmentItem assessmentItem) {
    OutcomeDeclaration feedbackOutcomeDeclaration = new OutcomeDeclaration(assessmentItem);
    feedbackOutcomeDeclaration.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
    feedbackOutcomeDeclaration.setCardinality(Cardinality.SINGLE);
    feedbackOutcomeDeclaration.setBaseType(BaseType.IDENTIFIER);
    DefaultValue feedbackDefaultVal = new DefaultValue(feedbackOutcomeDeclaration);
    feedbackOutcomeDeclaration.setDefaultValue(feedbackDefaultVal);
    FieldValue feedbackDefaultFieldVal = new FieldValue(feedbackDefaultVal, new IdentifierValue("none"));
    feedbackDefaultVal.getFieldValues().add(feedbackDefaultFieldVal);
    List<View> views = new ArrayList<>();
    views.add(View.TEST_CONSTRUCTOR);
    feedbackOutcomeDeclaration.setViews(views);
    return feedbackOutcomeDeclaration;
}
Also used : DefaultValue(uk.ac.ed.ph.jqtiplus.node.shared.declaration.DefaultValue) ArrayList(java.util.ArrayList) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) OutcomeDeclaration(uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration) View(uk.ac.ed.ph.jqtiplus.node.test.View)

Example 25 with IdentifierValue

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

the class AssessmentItemFactory method findBaseValueInExpression.

public static boolean findBaseValueInExpression(Expression expression, Identifier feedbackIdentifier) {
    if (expression instanceof BaseValue) {
        BaseValue bValue = (BaseValue) expression;
        SingleValue sValue = bValue.getSingleValue();
        if (sValue instanceof IdentifierValue) {
            IdentifierValue iValue = (IdentifierValue) sValue;
            if (feedbackIdentifier.equals(iValue.identifierValue())) {
                return true;
            }
        }
    } else {
        List<Expression> childExpressions = expression.getExpressions();
        for (Expression childExpression : childExpressions) {
            if (findBaseValueInExpression(childExpression, feedbackIdentifier)) {
                return true;
            }
        }
    }
    return false;
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) Expression(uk.ac.ed.ph.jqtiplus.node.expression.Expression) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue)

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