Search in sources :

Example 26 with DirectedPairValue

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

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 27 with DirectedPairValue

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

the class AssessmentItemFactory method appendAssociationMatchResponseDeclaration.

public static ResponseDeclaration appendAssociationMatchResponseDeclaration(ResponseDeclaration responseDeclaration, Map<Identifier, List<Identifier>> associations) {
    responseDeclaration.setCardinality(Cardinality.MULTIPLE);
    responseDeclaration.setBaseType(BaseType.DIRECTED_PAIR);
    // correct response
    CorrectResponse correctResponse = new CorrectResponse(responseDeclaration);
    responseDeclaration.setCorrectResponse(correctResponse);
    for (Map.Entry<Identifier, List<Identifier>> association : associations.entrySet()) {
        Identifier sourceChoiceId = association.getKey();
        List<Identifier> targetChoiceIds = association.getValue();
        for (Identifier targetChoiceId : targetChoiceIds) {
            DirectedPairValue dpValue = new DirectedPairValue(sourceChoiceId, targetChoiceId);
            FieldValue fValue = new FieldValue(correctResponse, dpValue);
            correctResponse.getFieldValues().add(fValue);
        }
    }
    return responseDeclaration;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) List(java.util.List) ArrayList(java.util.ArrayList) NodeGroupList(uk.ac.ed.ph.jqtiplus.group.NodeGroupList) 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 28 with DirectedPairValue

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

the class CSVToAssessmentItemConverter method processChoice_match.

private void processChoice_match(String[] parts, MatchAssessmentItemBuilder matchBuilder) {
    List<SimpleAssociableChoice> targetChoices = matchBuilder.getTargetChoices();
    if (targetChoices == null || targetChoices.isEmpty()) {
        for (int i = 1; i < parts.length; i++) {
            String answer = parts[i];
            SimpleAssociableChoice choice = AssessmentItemFactory.createSimpleAssociableChoice(answer, matchBuilder.getTargetMatchSet());
            targetChoices.add(choice);
        }
    } else {
        String answer = parts[0];
        if (StringHelper.containsNonWhitespace(answer)) {
            SimpleAssociableChoice sourceChoice = AssessmentItemFactory.createSimpleAssociableChoice(answer, matchBuilder.getSourceMatchSet());
            matchBuilder.getSourceChoices().add(sourceChoice);
            // correct answer and points
            for (int i = 1; i < parts.length && i < (targetChoices.size() + 1); i++) {
                double point = parseFloat(parts[i], 0.0f);
                SimpleAssociableChoice targetChoice = targetChoices.get(i - 1);
                DirectedPairValue directedPair = new DirectedPairValue(sourceChoice.getIdentifier(), targetChoice.getIdentifier());
                matchBuilder.addScore(directedPair, Double.valueOf(point));
                if (point > 0.0) {
                    matchBuilder.addAssociation(sourceChoice.getIdentifier(), targetChoice.getIdentifier());
                }
            }
        }
    }
}
Also used : SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)

Example 29 with DirectedPairValue

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

the class MatchScoreController method forgeScoreElement.

private void forgeScoreElement(MatchWrapper sourceWrapper, MatchWrapper targetWrapper) {
    Identifier sourceIdentifier = sourceWrapper.getChoiceIdentifier();
    Identifier targetIdentifier = targetWrapper.getChoiceIdentifier();
    DirectedPairValue dKey = new DirectedPairValue(sourceIdentifier, targetIdentifier);
    if (!scoreWrappers.containsKey(dKey)) {
        String key = sourceIdentifier.toString() + "-" + targetIdentifier.toString();
        TextElement textEl = uifactory.addTextElement(key, null, 8, "", scoreCont);
        MatchScoreWrapper scoreWrapper = new MatchScoreWrapper(sourceIdentifier, targetIdentifier, textEl);
        textEl.setDomReplacementWrapperRequired(false);
        textEl.setDisplaySize(5);
        textEl.setUserObject(scoreWrapper);
        textEl.setEnabled(!restrictedEdit && !readOnly);
        Double score = itemBuilder.getScore(sourceIdentifier, targetIdentifier);
        if (score == null) {
            textEl.setValue("0.0");
        } else {
            textEl.setValue(AssessmentHelper.getRoundedScore(score));
        }
        scoreWrappers.put(dKey, scoreWrapper);
        scoreCont.contextPut(key, scoreWrapper);
    }
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)

Example 30 with DirectedPairValue

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

the class MatchScoreController method validateFormLogic.

@Override
protected boolean validateFormLogic(UserRequest ureq) {
    boolean allOk = true;
    allOk &= validateMinMaxScores(minScoreEl, maxScoreEl);
    if (assessmentModeEl.isOneSelected() && assessmentModeEl.isSelected(1)) {
        for (Map.Entry<DirectedPairValue, MatchScoreWrapper> entry : scoreWrappers.entrySet()) {
            MatchScoreWrapper scoreWrapper = entry.getValue();
            TextElement scoreEl = scoreWrapper.getScoreEl();
            String val = scoreEl.getValue();
            scoreEl.clearError();
            if (StringHelper.containsNonWhitespace(val)) {
                try {
                    Double.parseDouble(val);
                } catch (NumberFormatException e) {
                    scoreEl.setErrorKey("error.double", null);
                    allOk &= false;
                }
            } else {
                scoreEl.setErrorKey("form.legende.mandatory", null);
                allOk &= false;
            }
        }
    }
    return allOk & super.validateFormLogic(ureq);
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) HashMap(java.util.HashMap) Map(java.util.Map)

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