Search in sources :

Example 1 with PairValue

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

the class CorrectResponsesUtil method getCorrectDirectPairResponses.

/**
 * The list of correct associations
 * @param assessmentItem
 * @param interaction
 * @return A list of string with [ and ] before and after!
 */
public static final Set<String> getCorrectDirectPairResponses(AssessmentItem assessmentItem, Interaction interaction, boolean withDelimiter) {
    ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
    Set<String> correctAnswers = new HashSet<>();
    // readable responses
    if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
        CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
        if (correctResponse.getCardinality().isOneOf(Cardinality.MULTIPLE)) {
            List<FieldValue> values = correctResponse.getFieldValues();
            Value value = FieldValue.computeValue(Cardinality.MULTIPLE, values);
            if (value instanceof MultipleValue) {
                MultipleValue multiValue = (MultipleValue) value;
                multiValue.forEach(oValue -> {
                    if (oValue instanceof DirectedPairValue) {
                        DirectedPairValue pairValue = (DirectedPairValue) oValue;
                        String source = pairValue.sourceValue().toString();
                        String destination = pairValue.destValue().toString();
                        if (withDelimiter) {
                            correctAnswers.add("[" + source + " " + destination + "]");
                        } else {
                            correctAnswers.add(source + " " + destination);
                        }
                    }
                });
            }
        }
    }
    return correctAnswers;
}
Also used : MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) 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) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) HashSet(java.util.HashSet)

Example 2 with PairValue

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

the class CorrectResponsesUtil method getCorrectMultiplePairResponses.

public static final List<String> getCorrectMultiplePairResponses(AssessmentItem assessmentItem, Interaction interaction, boolean withDelimiter) {
    final List<String> 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.MULTIPLE)) {
            List<FieldValue> values = correctResponse.getFieldValues();
            Value value = FieldValue.computeValue(Cardinality.MULTIPLE, values);
            if (value instanceof MultipleValue) {
                MultipleValue multiValue = (MultipleValue) value;
                multiValue.forEach(oValue -> {
                    if (oValue instanceof PairValue) {
                        PairValue pairValue = (PairValue) oValue;
                        String source = pairValue.sourceValue().toString();
                        String destination = pairValue.destValue().toString();
                        if (withDelimiter) {
                            correctAnswers.add("[" + source + " " + destination + "]");
                        } else {
                            correctAnswers.add(source + " " + destination);
                        }
                    }
                });
            }
        }
    }
    return correctAnswers;
}
Also used : DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) PairValue(uk.ac.ed.ph.jqtiplus.value.PairValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) 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 3 with PairValue

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

the class CorrectResponsesUtil method getCorrectMultiplePairResponses.

public static final List<String> getCorrectMultiplePairResponses(AssessmentItem assessmentItem, Interaction interaction, boolean withDelimiter) {
    final List<String> 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.MULTIPLE)) {
            List<FieldValue> values = correctResponse.getFieldValues();
            Value value = FieldValue.computeValue(Cardinality.MULTIPLE, values);
            if (value instanceof MultipleValue) {
                MultipleValue multiValue = (MultipleValue) value;
                multiValue.forEach(oValue -> {
                    if (oValue instanceof PairValue) {
                        PairValue pairValue = (PairValue) oValue;
                        String source = pairValue.sourceValue().toString();
                        String destination = pairValue.destValue().toString();
                        if (withDelimiter) {
                            correctAnswers.add("[" + source + " " + destination + "]");
                        } else {
                            correctAnswers.add(source + " " + destination);
                        }
                    }
                });
            }
        }
    }
    return correctAnswers;
}
Also used : DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) PairValue(uk.ac.ed.ph.jqtiplus.value.PairValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) 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 4 with PairValue

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

the class CorrectResponsesUtil method getCorrectDirectPairResponses.

/**
 * The list of correct associations
 * @param assessmentItem
 * @param interaction
 * @return A list of string with [ and ] before and after!
 */
public static final Set<String> getCorrectDirectPairResponses(AssessmentItem assessmentItem, Interaction interaction, boolean withDelimiter) {
    ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
    Set<String> correctAnswers = new HashSet<>();
    // readable responses
    if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
        CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
        if (correctResponse.getCardinality().isOneOf(Cardinality.MULTIPLE)) {
            List<FieldValue> values = correctResponse.getFieldValues();
            Value value = FieldValue.computeValue(Cardinality.MULTIPLE, values);
            if (value instanceof MultipleValue) {
                MultipleValue multiValue = (MultipleValue) value;
                multiValue.forEach(oValue -> {
                    if (oValue instanceof DirectedPairValue) {
                        DirectedPairValue pairValue = (DirectedPairValue) oValue;
                        String source = pairValue.sourceValue().toString();
                        String destination = pairValue.destValue().toString();
                        if (withDelimiter) {
                            correctAnswers.add("[" + source + " " + destination + "]");
                        } else {
                            correctAnswers.add(source + " " + destination);
                        }
                    }
                });
            }
        }
    }
    return correctAnswers;
}
Also used : MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) 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) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) HashSet(java.util.HashSet)

Aggregations

CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)4 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)4 FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)4 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)4 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)4 IntegerValue (uk.ac.ed.ph.jqtiplus.value.IntegerValue)4 MultipleValue (uk.ac.ed.ph.jqtiplus.value.MultipleValue)4 OrderedValue (uk.ac.ed.ph.jqtiplus.value.OrderedValue)4 PairValue (uk.ac.ed.ph.jqtiplus.value.PairValue)4 PointValue (uk.ac.ed.ph.jqtiplus.value.PointValue)4 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)4 Value (uk.ac.ed.ph.jqtiplus.value.Value)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2