Search in sources :

Example 36 with SingleValue

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

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)

Example 37 with SingleValue

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

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

the class TestFeedbackBuilder method findBaseValue.

private boolean findBaseValue(Expression expression, boolean value) {
    if (expression instanceof BaseValue) {
        BaseValue bValue = (BaseValue) expression;
        SingleValue sValue = bValue.getSingleValue();
        if (sValue instanceof BooleanValue) {
            BooleanValue booleanValue = (BooleanValue) sValue;
            return booleanValue.booleanValue() == value;
        }
    }
    return false;
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) BooleanValue(uk.ac.ed.ph.jqtiplus.value.BooleanValue)

Example 39 with SingleValue

use of uk.ac.ed.ph.jqtiplus.value.SingleValue 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)

Example 40 with SingleValue

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

the class QTI21ServiceImpl method stringifyQtiValue.

private String stringifyQtiValue(final Value value) {
    if (qtiModule.isMathAssessExtensionEnabled() && GlueValueBinder.isMathsContentRecord(value)) {
        /* This is a special MathAssess "Maths Content" variable. In this case, we'll record
             * just the ASCIIMath input form or the Maxima form, if either are available.
             */
        final RecordValue mathsValue = (RecordValue) value;
        final SingleValue asciiMathInput = mathsValue.get(MathAssessConstants.FIELD_CANDIDATE_INPUT_IDENTIFIER);
        if (asciiMathInput != null) {
            return "ASCIIMath[" + asciiMathInput.toQtiString() + "]";
        }
        final SingleValue maximaForm = mathsValue.get(MathAssessConstants.FIELD_MAXIMA_IDENTIFIER);
        if (maximaForm != null) {
            return "Maxima[" + maximaForm.toQtiString() + "]";
        }
    }
    /* Just convert to QTI string in the usual way */
    return value.toQtiString();
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) RecordValue(uk.ac.ed.ph.jqtiplus.value.RecordValue)

Aggregations

SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)52 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)30 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)20 FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)18 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)18 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)16 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)14 MapEntry (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry)14 RecordValue (uk.ac.ed.ph.jqtiplus.value.RecordValue)14 ArrayList (java.util.ArrayList)12 BaseValue (uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue)12 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)12 Mapping (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping)10 Value (uk.ac.ed.ph.jqtiplus.value.Value)10 MultipleValue (uk.ac.ed.ph.jqtiplus.value.MultipleValue)8 Map (java.util.Map)6 Expression (uk.ac.ed.ph.jqtiplus.node.expression.Expression)6 StringValue (uk.ac.ed.ph.jqtiplus.value.StringValue)6 AssessmentItemFactory.appendAssociationMatchResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendAssociationMatchResponseDeclaration)4 AssessmentItemFactory.createMatchResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createMatchResponseDeclaration)4