Search in sources :

Example 11 with SingleValue

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

the class FIBAssessmentItemBuilder method extractNumericalEntrySettings.

public static void extractNumericalEntrySettings(AssessmentItem item, NumericalEntry numericalEntry, ResponseDeclaration responseDeclaration, AtomicInteger countAlternatives, DoubleAdder mappedScore) {
    Double 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 FloatValue) {
            solution = ((FloatValue) sValue).doubleValue();
            numericalEntry.setSolution(solution);
        }
    }
    // search the equal
    List<ResponseRule> responseRules = item.getResponseProcessing().getResponseRules();
    a_a: for (ResponseRule responseRule : responseRules) {
        if (responseRule instanceof ResponseCondition) {
            ResponseCondition condition = (ResponseCondition) responseRule;
            ResponseIf responseIf = condition.getResponseIf();
            if (responseIf != null && responseIf.getExpressions().size() > 0) {
                // first is an and/equal/
                Expression potentialEqualOrAnd = responseIf.getExpressions().get(0);
                if (potentialEqualOrAnd instanceof And) {
                    And and = (And) potentialEqualOrAnd;
                    for (Expression potentialEqual : and.getExpressions()) {
                        if (potentialEqual instanceof Equal && potentialEqual.getExpressions().size() == 2 && extractNumericalEntrySettings(numericalEntry, (Equal) potentialEqual)) {
                            break a_a;
                        }
                    }
                } else if (potentialEqualOrAnd instanceof Equal) {
                    if (extractNumericalEntrySettings(numericalEntry, (Equal) potentialEqualOrAnd)) {
                        // find to score as outcome value
                        if (responseIf.getResponseRules() != null && responseIf.getResponseRules().size() == 1 && responseIf.getResponseRules().get(0) instanceof SetOutcomeValue) {
                            SetOutcomeValue outcomeValue = (SetOutcomeValue) responseIf.getResponseRules().get(0);
                            if (outcomeValue.getExpressions() != null && outcomeValue.getExpressions().size() == 1 && outcomeValue.getExpressions().get(0) instanceof BaseValue) {
                                BaseValue bValue = (BaseValue) outcomeValue.getExpressions().get(0);
                                SingleValue sValue = bValue.getSingleValue();
                                if (sValue instanceof FloatValue) {
                                    FloatValue fValue = (FloatValue) sValue;
                                    numericalEntry.setScore(fValue.doubleValue());
                                    mappedScore.add(fValue.doubleValue());
                                    countAlternatives.incrementAndGet();
                                }
                            }
                        }
                        break a_a;
                    }
                }
            }
        }
    }
    // toleranceMode cannot be empty
    if (numericalEntry.getToleranceMode() == null) {
        numericalEntry.setToleranceMode(ToleranceMode.EXACT);
    }
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) ResponseRule(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule) Expression(uk.ac.ed.ph.jqtiplus.node.expression.Expression) Equal(uk.ac.ed.ph.jqtiplus.node.expression.operator.Equal) And(uk.ac.ed.ph.jqtiplus.node.expression.operator.And) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Example 12 with SingleValue

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

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)

Example 13 with SingleValue

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

the class AssessmentObjectComponentRenderer method renderPrintedVariable.

/**
 * The QTI spec says that this variable must have single cardinality.
 *
 * For convenience, we also accept multiple, ordered and record cardinality variables here,
 * printing them out in a hard-coded form that probably won't make sense to test
 * candidates but might be useful for debugging.
 *
 * Our implementation additionally adds support for "printing" MathsContent variables
 * used in MathAssess, outputting an inline Presentation MathML element, as documented
 * in the MathAssses spec.
 */
protected void renderPrintedVariable(AssessmentRenderer renderer, StringOutput sb, PrintedVariable source, VariableDeclaration valueDeclaration, Value valueHolder) {
    if (isNullValue(valueHolder)) {
    // (Spec says to output nothing in this case)
    } else if (isSingleCardinalityValue(valueHolder)) {
        if (valueDeclaration.hasBaseType(BaseType.INTEGER) || valueDeclaration.hasBaseType(BaseType.FLOAT)) {
            renderSingleCardinalityValue(sb, valueHolder);
        } else {
            renderSingleCardinalityValue(sb, valueHolder);
        }
    // math content is a record with special markers
    } else if (isMathsContentValue(valueHolder)) {
        // <xsl:copy-of select="qw:extract-maths-content-pmathml($valueHolder)"/>
        String mathMlContent = extractMathsContentPmathml(valueHolder);
        if (renderer.isMathXsltDisabled()) {
            sb.append(mathMlContent);
        } else {
            transformMathmlAsString(sb, mathMlContent);
        }
    } else if (isMultipleCardinalityValue(valueHolder)) {
        String delimiter = source.getDelimiter();
        if (!StringHelper.containsNonWhitespace(delimiter)) {
            delimiter = ";";
        }
        renderMultipleCardinalityValue(sb, valueHolder, delimiter);
    } else if (isOrderedCardinalityValue(valueHolder)) {
        if (source.getIndex() != null) {
            int index = -1;
            if (source.getIndex().isConstantInteger()) {
                index = source.getIndex().getConstantIntegerValue().intValue();
            } else if (source.getIndex().isVariableRef()) {
            // TODO qti what to do???
            }
            SingleValue indexedValue = extractIterableElement(valueHolder, index);
            renderSingleCardinalityValue(sb, indexedValue);
        } else {
            String delimiter = source.getDelimiter();
            if (!StringHelper.containsNonWhitespace(delimiter)) {
                delimiter = ";";
            }
            renderOrderedCardinalityValue(sb, valueHolder, delimiter);
        }
    } else if (isRecordCardinalityValue(valueHolder)) {
        String field = source.getField();
        if (StringHelper.containsNonWhitespace(field)) {
            Identifier fieldIdentifier = Identifier.assumedLegal(field);
            SingleValue mappedValue = extractRecordFieldValue(valueHolder, fieldIdentifier);
            renderSingleCardinalityValue(sb, mappedValue);
        } else {
            String delimiter = source.getDelimiter();
            String mappingIndicator = source.getMappingIndicator();
            if (!StringHelper.containsNonWhitespace(delimiter)) {
                delimiter = ";";
            }
            if (!StringHelper.containsNonWhitespace(mappingIndicator)) {
                mappingIndicator = "=";
            }
            renderRecordCardinalityValue(sb, valueHolder, delimiter, mappingIndicator);
        }
    } else {
        sb.append("printedVariable may not be applied to value ").append(valueHolder.toString());
    }
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString)

Example 14 with SingleValue

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

the class AssessmentObjectVelocityRenderDecorator method getRespondedVisibleChoices.

/*
		<xsl:variable name="respondedChoiceIdentifiers" select="qw:extract-iterable-elements(qw:get-response-value(/, @responseIdentifier))" as="xs:string*"/>
        <xsl:variable name="unselectedVisibleChoices" select="$visibleOrderedChoices[not(@identifier = $respondedChoiceIdentifiers)]" as="element(qti:simpleChoice)*"/>
        
        <xsl:variable name="respondedVisibleChoices" as="element(qti:simpleChoice)*">
          <xsl:for-each select="$respondedChoiceIdentifiers">
            <xsl:sequence select="$thisInteraction/qti:simpleChoice[@identifier=current() and qw:is-visible(.)]"/>
          </xsl:for-each>
        </xsl:variable>
	 */
public OrderChoices getRespondedVisibleChoices(OrderInteraction interaction) {
    List<SimpleChoice> visibleChoices = getVisibleOrderedSimpleChoices(interaction);
    Value responseValue = getResponseValue(interaction.getResponseIdentifier());
    List<String> responseIdentifiers = new ArrayList<>();
    if (responseValue instanceof ListValue) {
        for (SingleValue singleValue : (ListValue) responseValue) {
            responseIdentifiers.add(singleValue.toQtiString());
        }
    }
    List<SimpleChoice> unselectedVisibleChoices = new ArrayList<>(visibleChoices);
    for (Iterator<SimpleChoice> it = unselectedVisibleChoices.iterator(); it.hasNext(); ) {
        SimpleChoice choice = it.next();
        if (responseIdentifiers.contains(choice.getIdentifier().toString())) {
            it.remove();
        }
    }
    List<SimpleChoice> respondedVisibleChoices = new ArrayList<>();
    for (String responseIdentifier : responseIdentifiers) {
        for (SimpleChoice visibleChoice : visibleChoices) {
            if (responseIdentifier.equals(visibleChoice.getIdentifier().toString())) {
                respondedVisibleChoices.add(visibleChoice);
            }
        }
    }
    return new OrderChoices(respondedVisibleChoices, unselectedVisibleChoices);
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) ListValue(uk.ac.ed.ph.jqtiplus.value.ListValue) ListValue(uk.ac.ed.ph.jqtiplus.value.ListValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) AssessmentRenderFunctions.renderValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderValue) RecordValue(uk.ac.ed.ph.jqtiplus.value.RecordValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) NullValue(uk.ac.ed.ph.jqtiplus.value.NullValue) FileValue(uk.ac.ed.ph.jqtiplus.value.FileValue) ArrayList(java.util.ArrayList)

Example 15 with SingleValue

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

the class HottextAssessmentItemBuilder method extractScoreEvaluationMode.

private void extractScoreEvaluationMode() {
    boolean hasMapping = false;
    if (hottextInteraction != null) {
        ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(hottextInteraction.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 IdentifierValue) {
                        Identifier identifier = ((IdentifierValue) sValue).identifierValue();
                        scoreMapping.put(identifier, 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) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createHottextCorrectResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createHottextCorrectResponseDeclaration)

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