Search in sources :

Example 1 with RecordValue

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

the class AssessmentRenderFunctions method renderRecordCardinalityValue.

public static void renderRecordCardinalityValue(StringOutput sb, Value value, String delimiter, String mappingIndicator) {
    if (value != null && value.hasCardinality(Cardinality.RECORD)) {
        RecordValue oValue = (RecordValue) value;
        boolean hasDelimiter = StringHelper.containsNonWhitespace(delimiter);
        boolean hasMappingIndicator = StringHelper.containsNonWhitespace(mappingIndicator);
        int count = 0;
        for (Map.Entry<Identifier, SingleValue> entry : oValue.entrySet()) {
            if (hasDelimiter && count++ > 0)
                sb.append(delimiter);
            String identifierString = entry.getKey().toString();
            sb.append(identifierString);
            if (hasMappingIndicator) {
                sb.append(mappingIndicator);
            }
            renderSingleCardinalityValue(sb, entry.getValue());
        }
    }
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) RecordValue(uk.ac.ed.ph.jqtiplus.value.RecordValue) Map(java.util.Map)

Example 2 with RecordValue

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

the class AssessmentRenderFunctions method extractRecordFieldValue.

/*
  <xsl:function name="qw:extract-record-field-value" as="xs:string?">
    <xsl:param name="valueHolder" as="element()"/>
    <xsl:param name="fieldName" as="xs:string"/>
    <xsl:choose>
      <xsl:when test="qw:is-record-cardinality-value($valueHolder)">
        <xsl:value-of select="$valueHolder/qw:value[@fieldIdentifier=$fieldName]"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message terminate="yes">
          Expected value <xsl:copy-of select="$valueHolder"/> to have record
          cardinalty.
        </xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:function>
	 */
public static SingleValue extractRecordFieldValue(Value value, Identifier identifier) {
    SingleValue mappedValue = null;
    if (value != null && identifier != null && value.hasCardinality(Cardinality.RECORD)) {
        RecordValue recordValue = (RecordValue) value;
        mappedValue = recordValue.get(identifier);
    }
    return mappedValue;
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) RecordValue(uk.ac.ed.ph.jqtiplus.value.RecordValue)

Example 3 with RecordValue

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

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

the class AssessmentObjectVelocityRenderDecorator method getResponseValueForField.

public String getResponseValueForField(Value value, String field) {
    String responseValue;
    // for math entry interaction
    if (value instanceof RecordValue) {
        Identifier fieldIdentifier = Identifier.assumedLegal(field);
        RecordValue recordValue = (RecordValue) value;
        SingleValue sValue = recordValue.get(fieldIdentifier);
        responseValue = sValue == null ? null : sValue.toQtiString();
    } else {
        responseValue = null;
    }
    return responseValue;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) RecordValue(uk.ac.ed.ph.jqtiplus.value.RecordValue)

Example 5 with RecordValue

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

the class AssessmentRenderFunctions method extractMathsContentPmathml.

/*
	  <xsl:function name="qw:extract-maths-content-pmathml" as="element(m:math)">
	    <xsl:param name="valueHolder" as="element()"/>
	    <xsl:choose>
	      <xsl:when test="qw:is-maths-content-value($valueHolder)">
	        <xsl:variable name="pmathmlString" select="$valueHolder/qw:value[@fieldIdentifier='PMathML']" as="xs:string"/>
	        <xsl:variable name="pmathmlDocNode" select="saxon:parse($pmathmlString)" as="document-node()"/>
	        <xsl:copy-of select="$pmathmlDocNode/*"/>
	      </xsl:when>
	      <xsl:otherwise>
	        <xsl:message terminate="yes">
	          Expected value <xsl:copy-of select="$valueHolder"/> to be a MathsContent value
	        </xsl:message>
	      </xsl:otherwise>
	    </xsl:choose>
	  </xsl:function>
	*/
public static String extractMathsContentPmathml(Value value) {
    if (value.hasCardinality(Cardinality.RECORD)) {
        RecordValue recordValue = (RecordValue) value;
        for (Map.Entry<Identifier, SingleValue> entry : recordValue.entrySet()) {
            final Identifier itemIdentifier = entry.getKey();
            final SingleValue itemValue = entry.getValue();
            if (itemValue.hasBaseType(BaseType.STRING) && FIELD_PMATHML_IDENTIFIER.equals(itemIdentifier)) {
                return ((StringValue) itemValue).stringValue();
            }
        }
    }
    return "";
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) RecordValue(uk.ac.ed.ph.jqtiplus.value.RecordValue) StringValue(uk.ac.ed.ph.jqtiplus.value.StringValue) Map(java.util.Map)

Aggregations

RecordValue (uk.ac.ed.ph.jqtiplus.value.RecordValue)12 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)12 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)8 Map (java.util.Map)6 StringValue (uk.ac.ed.ph.jqtiplus.value.StringValue)2