use of uk.ac.ed.ph.jqtiplus.value.StringValue in project OpenOLAT by OpenOLAT.
the class QTI21StatisticsManagerImpl method getTextEntryInteractionSettings.
private TextEntryInteractionStatistics getTextEntryInteractionSettings(Identifier responseIdentifier, ResponseDeclaration responseDeclaration) {
String correctResponse = null;
boolean caseSensitive = true;
double points = Double.NaN;
List<String> alternatives = new ArrayList<>();
List<MapEntry> mapEntries = responseDeclaration.getMapping().getMapEntries();
for (MapEntry mapEntry : mapEntries) {
SingleValue mapKey = mapEntry.getMapKey();
if (mapKey instanceof StringValue) {
String value = ((StringValue) mapKey).stringValue();
if (correctResponse == null) {
correctResponse = value;
points = mapEntry.getMappedValue();
} else {
alternatives.add(value);
}
}
caseSensitive &= mapEntry.getCaseSensitive();
}
if (points == -1.0d) {
// all score
points = 0.0d;
}
return new TextEntryInteractionStatistics(responseIdentifier, caseSensitive, correctResponse, alternatives, points);
}
use of uk.ac.ed.ph.jqtiplus.value.StringValue in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method appendStringValue.
private static void appendStringValue(CorrectResponse correctResponse, String response) {
FieldValue fieldValue = new FieldValue(correctResponse);
StringValue identifierValue = new StringValue(response);
fieldValue.setSingleValue(identifierValue);
correctResponse.getFieldValues().add(fieldValue);
}
use of uk.ac.ed.ph.jqtiplus.value.StringValue 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 "";
}
use of uk.ac.ed.ph.jqtiplus.value.StringValue in project OpenOLAT by OpenOLAT.
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 "";
}
use of uk.ac.ed.ph.jqtiplus.value.StringValue in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method createTextEntryResponseDeclaration.
public static ResponseDeclaration createTextEntryResponseDeclaration(AssessmentItem assessmentItem, Identifier declarationId, String response, Double score, boolean caseSensitive, List<TextEntryAlternative> alternatives) {
ResponseDeclaration responseDeclaration = new ResponseDeclaration(assessmentItem);
responseDeclaration.setIdentifier(declarationId);
responseDeclaration.setCardinality(Cardinality.SINGLE);
responseDeclaration.setBaseType(BaseType.STRING);
// correct response
CorrectResponse correctResponse = new CorrectResponse(responseDeclaration);
responseDeclaration.setCorrectResponse(correctResponse);
appendStringValue(correctResponse, response);
// mapping
Mapping mapping = new Mapping(responseDeclaration);
mapping.setDefaultValue(0.0d);
responseDeclaration.setMapping(mapping);
{
// map correct response
MapEntry mapEntry = new MapEntry(mapping);
mapEntry.setMapKey(new StringValue(response));
mapEntry.setMappedValue(score);
mapEntry.setCaseSensitive(new Boolean(caseSensitive));
mapping.getMapEntries().add(mapEntry);
}
// map alternatives
if (alternatives != null && alternatives.size() > 0) {
for (TextEntryAlternative alternative : alternatives) {
if (StringHelper.containsNonWhitespace(alternative.getAlternative())) {
MapEntry mapEntry = new MapEntry(mapping);
mapEntry.setMapKey(new StringValue(alternative.getAlternative()));
mapEntry.setMappedValue(score);
mapEntry.setCaseSensitive(new Boolean(caseSensitive));
mapping.getMapEntries().add(mapEntry);
}
}
}
return responseDeclaration;
}
Aggregations