Search in sources :

Example 31 with FieldValue

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

the class AssessmentItemFactory method createOutcomeDeclarationForMaxScore.

public static OutcomeDeclaration createOutcomeDeclarationForMaxScore(AssessmentItem assessmentItem, double maxScore) {
    OutcomeDeclaration maxScoreOutcomeDeclaration = new OutcomeDeclaration(assessmentItem);
    maxScoreOutcomeDeclaration.setIdentifier(QTI21Constants.MAXSCORE_IDENTIFIER);
    maxScoreOutcomeDeclaration.setCardinality(Cardinality.SINGLE);
    maxScoreOutcomeDeclaration.setBaseType(BaseType.FLOAT);
    DefaultValue maxScoreDefaultVal = new DefaultValue(maxScoreOutcomeDeclaration);
    maxScoreOutcomeDeclaration.setDefaultValue(maxScoreDefaultVal);
    FieldValue maxScoreDefaultFieldVal = new FieldValue(maxScoreDefaultVal, new FloatValue(maxScore));
    maxScoreDefaultVal.getFieldValues().add(maxScoreDefaultFieldVal);
    return maxScoreOutcomeDeclaration;
}
Also used : DefaultValue(uk.ac.ed.ph.jqtiplus.node.shared.declaration.DefaultValue) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) OutcomeDeclaration(uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration)

Example 32 with FieldValue

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

the class AssessmentItemFactory method appendAssociationKPrimResponseDeclaration.

public static ResponseDeclaration appendAssociationKPrimResponseDeclaration(ResponseDeclaration responseDeclaration, Map<Identifier, Identifier> associations, double maxScore) {
    responseDeclaration.setCardinality(Cardinality.MULTIPLE);
    responseDeclaration.setBaseType(BaseType.DIRECTED_PAIR);
    // correct response
    CorrectResponse correctResponse = new CorrectResponse(responseDeclaration);
    responseDeclaration.setCorrectResponse(correctResponse);
    for (Map.Entry<Identifier, Identifier> association : associations.entrySet()) {
        Identifier choiceId = association.getKey();
        Identifier correctwrongId = association.getValue();
        DirectedPairValue dpValue = new DirectedPairValue(choiceId, correctwrongId);
        FieldValue fValue = new FieldValue(correctResponse, dpValue);
        correctResponse.getFieldValues().add(fValue);
    }
    double mappedValue = maxScore;
    if (associations.size() > 0) {
        mappedValue = maxScore / associations.size();
    }
    // mapping
    Mapping mapping = new Mapping(responseDeclaration);
    mapping.setDefaultValue(-mappedValue);
    responseDeclaration.setMapping(mapping);
    for (Map.Entry<Identifier, Identifier> association : associations.entrySet()) {
        Identifier choiceId = association.getKey();
        Identifier correctwrongId = association.getValue();
        MapEntry mapEntry = new MapEntry(mapping);
        mapEntry.setMapKey(new DirectedPairValue(choiceId, correctwrongId));
        mapEntry.setMappedValue(mappedValue);
        mapping.getMapEntries().add(mapEntry);
    }
    return responseDeclaration;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) Mapping(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping) 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) Map(java.util.Map)

Example 33 with FieldValue

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

the class QtiNodesExtractor method extractIdentifiersFromCorrectResponse.

public static void extractIdentifiersFromCorrectResponse(CorrectResponse correctResponse, Map<Identifier, List<Identifier>> correctAnswers) {
    if (correctResponse != null) {
        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 = correctAnswers.get(sourceId);
                if (targetIds == null) {
                    targetIds = new ArrayList<>();
                    correctAnswers.put(sourceId, targetIds);
                }
                targetIds.add(targetId);
            }
        }
    }
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)

Example 34 with FieldValue

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

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

the class FIBAssessmentItemBuilder method extractTextEntrySettingsFromResponseDeclaration.

/**
 * All the needed informations are in the responseDeclaration, the list of alternatives
 * is in the mapping with case sensitivity options and score.
 *
 * @param textEntry
 * @param responseDeclaration
 * @param countAlternatives
 * @param mappedScore
 */
public static void extractTextEntrySettingsFromResponseDeclaration(TextEntry textEntry, ResponseDeclaration responseDeclaration, AtomicInteger countAlternatives, DoubleAdder mappedScore) {
    String solution = null;
    CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
    if (correctResponse != null && correctResponse.getFieldValues().size() > 0) {
        List<FieldValue> fValues = correctResponse.getFieldValues();
        SingleValue sValue = fValues.get(0).getSingleValue();
        if (sValue instanceof StringValue) {
            solution = ((StringValue) sValue).stringValue();
            textEntry.setSolution(solution);
        }
        if (correctResponse.getFieldValues().size() > 1) {
            List<TextEntryAlternative> alternatives = new ArrayList<>();
            for (int i = 1; i < correctResponse.getFieldValues().size(); i++) {
                SingleValue aValue = fValues.get(i).getSingleValue();
                if (aValue instanceof StringValue) {
                    TextEntryAlternative alternative = new TextEntryAlternative();
                    alternative.setAlternative(((StringValue) aValue).stringValue());
                    alternatives.add(alternative);
                }
            }
            textEntry.setAlternatives(alternatives);
        }
    }
    Mapping mapping = responseDeclaration.getMapping();
    if (mapping != null) {
        boolean caseSensitive = true;
        List<TextEntryAlternative> alternatives = new ArrayList<>();
        List<MapEntry> mapEntries = mapping.getMapEntries();
        for (MapEntry mapEntry : mapEntries) {
            TextEntryAlternative alternative = new TextEntryAlternative();
            SingleValue sValue = mapEntry.getMapKey();
            if (sValue instanceof StringValue) {
                String alt = ((StringValue) sValue).stringValue();
                if (solution == null || !solution.equals(alt)) {
                    alternative.setAlternative(alt);
                    alternative.setScore(mapEntry.getMappedValue());
                    alternatives.add(alternative);
                } else if (alt.equals(solution)) {
                    try {
                        textEntry.setScore(mapEntry.getMappedValue());
                    } catch (QtiAttributeException e) {
                        log.error("", e);
                    }
                }
                countAlternatives.incrementAndGet();
                mappedScore.add(mapEntry.getMappedValue());
            }
            caseSensitive &= mapEntry.getCaseSensitive();
        }
        textEntry.setCaseSensitive(caseSensitive);
        textEntry.setAlternatives(alternatives);
    }
}
Also used : QtiAttributeException(uk.ac.ed.ph.jqtiplus.exception.QtiAttributeException) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) ArrayList(java.util.ArrayList) Mapping(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) StringValue(uk.ac.ed.ph.jqtiplus.value.StringValue)

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