Search in sources :

Example 26 with FieldValue

use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project OpenOLAT by OpenOLAT.

the class CorrectResponsesUtil method getCorrectIntegerResponses.

public static final List<Integer> getCorrectIntegerResponses(AssessmentItem assessmentItem, Interaction interaction) {
    List<Integer> correctAnswers = new ArrayList<>(5);
    ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
    if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
        CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
        if (correctResponse.getCardinality().isOneOf(Cardinality.SINGLE)) {
            List<FieldValue> values = correctResponse.getFieldValues();
            Value value = FieldValue.computeValue(Cardinality.SINGLE, values);
            if (value instanceof IntegerValue) {
                IntegerValue identifierValue = (IntegerValue) value;
                correctAnswers.add(identifierValue.intValue());
            }
        } else if (correctResponse.getCardinality().isOneOf(Cardinality.MULTIPLE)) {
            Value value = FieldValue.computeValue(Cardinality.MULTIPLE, correctResponse.getFieldValues());
            if (value instanceof MultipleValue) {
                MultipleValue multiValue = (MultipleValue) value;
                for (SingleValue sValue : multiValue.getAll()) {
                    if (sValue instanceof IntegerValue) {
                        IntegerValue identifierValue = (IntegerValue) value;
                        correctAnswers.add(identifierValue.intValue());
                    }
                }
            }
        }
    }
    return correctAnswers;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) ArrayList(java.util.ArrayList) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) PointValue(uk.ac.ed.ph.jqtiplus.value.PointValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) PairValue(uk.ac.ed.ph.jqtiplus.value.PairValue) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 27 with FieldValue

use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project OpenOLAT by OpenOLAT.

the class MatchAssessmentItemBuilder method extractCorrectResponse.

private void extractCorrectResponse() {
    associations = new HashMap<>();
    if (matchInteraction != null) {
        ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(matchInteraction.getResponseIdentifier());
        if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
            CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
            List<FieldValue> values = correctResponse.getFieldValues();
            for (FieldValue value : values) {
                SingleValue sValue = value.getSingleValue();
                if (sValue instanceof DirectedPairValue) {
                    DirectedPairValue dpValue = (DirectedPairValue) sValue;
                    Identifier sourceId = dpValue.sourceValue();
                    Identifier targetId = dpValue.destValue();
                    List<Identifier> targetIds = associations.get(sourceId);
                    if (targetIds == null) {
                        targetIds = new ArrayList<>();
                        associations.put(sourceId, targetIds);
                    }
                    targetIds.add(targetId);
                }
            }
        }
    }
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) AssessmentItemFactory.appendAssociationMatchResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendAssociationMatchResponseDeclaration) AssessmentItemFactory.createMatchResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createMatchResponseDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 28 with FieldValue

use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project OpenOLAT by OpenOLAT.

the class AssessmentItemFactory method createOutcomeDeclarationForScoreResponse.

/*
	<outcomeDeclaration identifier="SCORE_RESPONSE_2" cardinality="single" baseType="float" view="testConstructor">
		<defaultValue>
			<value>0</value>
		</defaultValue>
	</outcomeDeclaration>
	*/
public static OutcomeDeclaration createOutcomeDeclarationForScoreResponse(AssessmentItem assessmentItem, String scoreIdentifier) {
    OutcomeDeclaration scoreOutcomeDeclaration = new OutcomeDeclaration(assessmentItem);
    scoreOutcomeDeclaration.setIdentifier(Identifier.parseString(scoreIdentifier));
    scoreOutcomeDeclaration.setCardinality(Cardinality.SINGLE);
    scoreOutcomeDeclaration.setBaseType(BaseType.FLOAT);
    DefaultValue scoreDefaultVal = new DefaultValue(scoreOutcomeDeclaration);
    scoreOutcomeDeclaration.setDefaultValue(scoreDefaultVal);
    FieldValue scoreDefaultFieldVal = new FieldValue(scoreDefaultVal, FloatValue.ZERO);
    scoreDefaultVal.getFieldValues().add(scoreDefaultFieldVal);
    return scoreOutcomeDeclaration;
}
Also used : DefaultValue(uk.ac.ed.ph.jqtiplus.node.shared.declaration.DefaultValue) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) OutcomeDeclaration(uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration)

Example 29 with FieldValue

use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project OpenOLAT by OpenOLAT.

the class AssessmentItemFactory method appendFloatValue.

private static void appendFloatValue(CorrectResponse correctResponse, double response) {
    FieldValue fieldValue = new FieldValue(correctResponse);
    FloatValue identifierValue = new FloatValue(response);
    fieldValue.setSingleValue(identifierValue);
    correctResponse.getFieldValues().add(fieldValue);
}
Also used : FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue)

Example 30 with FieldValue

use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue 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)

Aggregations

FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)48 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)24 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)20 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)20 ArrayList (java.util.ArrayList)16 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)16 DefaultValue (uk.ac.ed.ph.jqtiplus.node.shared.declaration.DefaultValue)16 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)16 OutcomeDeclaration (uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration)14 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)14 FloatValue (uk.ac.ed.ph.jqtiplus.value.FloatValue)12 Value (uk.ac.ed.ph.jqtiplus.value.Value)12 IntegerValue (uk.ac.ed.ph.jqtiplus.value.IntegerValue)10 MultipleValue (uk.ac.ed.ph.jqtiplus.value.MultipleValue)10 OrderedValue (uk.ac.ed.ph.jqtiplus.value.OrderedValue)10 PairValue (uk.ac.ed.ph.jqtiplus.value.PairValue)10 PointValue (uk.ac.ed.ph.jqtiplus.value.PointValue)10 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)8 Map (java.util.Map)4 BaseValue (uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue)4