Search in sources :

Example 21 with DirectedPairValue

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

the class MatchAssessmentItemBuilder method buildResponseAndOutcomeDeclarations.

@Override
protected void buildResponseAndOutcomeDeclarations() {
    // refresh correct response
    ResponseDeclaration responseDeclaration;
    if (assessmentItem.getResponseDeclaration(responseIdentifier) != null) {
        responseDeclaration = assessmentItem.getResponseDeclaration(responseIdentifier);
        appendAssociationMatchResponseDeclaration(responseDeclaration, associations);
    } else {
        responseDeclaration = createMatchResponseDeclaration(assessmentItem, responseIdentifier, associations);
        assessmentItem.getResponseDeclarations().add(responseDeclaration);
    }
    if (scoreEvaluation == ScoreEvaluation.perAnswer) {
        Map<DirectedPairValue, Double> pairMapping = new HashMap<>();
        if (scoreMapping != null && scoreMapping.size() > 0) {
            for (Map.Entry<DirectedPairValue, Double> entry : scoreMapping.entrySet()) {
                DirectedPairValue sdKey = entry.getKey();
                pairMapping.put(new DirectedPairValue(sdKey.sourceValue(), sdKey.destValue()), entry.getValue());
            }
        }
        AssessmentItemFactory.appendPairMapping(responseDeclaration, pairMapping);
    } else {
        // make sure there isn't any mapping
        responseDeclaration.setMapping(null);
    }
}
Also used : HashMap(java.util.HashMap) 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) Map(java.util.Map) HashMap(java.util.HashMap)

Example 22 with DirectedPairValue

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

the class AssessmentItemFactory method appendPairMapping.

public static Mapping appendPairMapping(ResponseDeclaration responseDeclaration, Map<DirectedPairValue, Double> map) {
    Mapping mapping = new Mapping(responseDeclaration);
    mapping.setDefaultValue(0d);
    responseDeclaration.setMapping(mapping);
    for (Map.Entry<DirectedPairValue, Double> entry : map.entrySet()) {
        MapEntry mapEntry = new MapEntry(mapping);
        mapEntry.setMapKey(entry.getKey());
        mapEntry.setMappedValue(entry.getValue());
        mapping.getMapEntries().add(mapEntry);
    }
    return mapping;
}
Also used : MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) Mapping(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) Map(java.util.Map)

Example 23 with DirectedPairValue

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

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

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

the class MatchAssessmentItemBuilder method extractScoreEvaluationMode.

private void extractScoreEvaluationMode() {
    boolean hasMapping = false;
    if (matchInteraction != null) {
        ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(matchInteraction.getResponseIdentifier());
        if (responseDeclaration != null) {
            Mapping mapping = responseDeclaration.getMapping();
            hasMapping = (mapping != null && mapping.getMapEntries() != null && mapping.getMapEntries().size() > 0);
            if (hasMapping) {
                scoreMapping = new HashMap<>();
                for (MapEntry entry : mapping.getMapEntries()) {
                    SingleValue sValue = entry.getMapKey();
                    if (sValue instanceof DirectedPairValue) {
                        Identifier sourceIdentifier = ((DirectedPairValue) sValue).sourceValue();
                        Identifier destIdentifier = ((DirectedPairValue) sValue).destValue();
                        scoreMapping.put(new DirectedPairValue(sourceIdentifier, destIdentifier), entry.getMappedValue());
                    }
                }
            }
        }
    }
    scoreEvaluation = hasMapping ? ScoreEvaluation.perAnswer : ScoreEvaluation.allCorrectAnswers;
}
Also used : MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) Mapping(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping) 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)

Aggregations

DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)30 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)16 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)14 Map (java.util.Map)12 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)12 FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)12 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)12 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)10 HashMap (java.util.HashMap)8 MapEntry (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry)8 ArrayList (java.util.ArrayList)6 AssessmentItemFactory.appendAssociationMatchResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendAssociationMatchResponseDeclaration)6 AssessmentItemFactory.createMatchResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createMatchResponseDeclaration)6 SimpleAssociableChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)6 Mapping (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping)6 HashSet (java.util.HashSet)4 List (java.util.List)4 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)4 SimpleMatchSet (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet)4 KPrimStatistics (org.olat.ims.qti21.model.statistics.KPrimStatistics)2