use of uk.ac.ed.ph.jqtiplus.value.SingleValue in project openolat by klemens.
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);
}
use of uk.ac.ed.ph.jqtiplus.value.SingleValue 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.SingleValue in project openolat by klemens.
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());
}
}
}
use of uk.ac.ed.ph.jqtiplus.value.SingleValue in project openolat by klemens.
the class AssessmentRenderFunctions method isMathsContentValue.
// <xsl:sequence select="boolean($valueHolder[@cardinality='record'
// and qw:value[@baseType='string' and @fieldIdentifier='MathsContentClass'
// and string(qw:value)='org.qtitools.mathassess']])"/>
public static boolean isMathsContentValue(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) && MATHS_CONTENT_RECORD_VARIABLE_IDENTIFIER.equals(itemIdentifier)) {
return true;
}
}
}
return false;
}
use of uk.ac.ed.ph.jqtiplus.value.SingleValue in project OpenOLAT by OpenOLAT.
the class CorrectResponsesUtil method getCorrectIntegerResponses.
public static final List<Integer> getCorrectIntegerResponses(AssessmentItem assessmentItem, Interaction interaction) {
List<Integer> correctAnswers = new ArrayList<>(5);
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
if (correctResponse.getCardinality().isOneOf(Cardinality.SINGLE)) {
List<FieldValue> values = correctResponse.getFieldValues();
Value value = FieldValue.computeValue(Cardinality.SINGLE, values);
if (value instanceof IntegerValue) {
IntegerValue identifierValue = (IntegerValue) value;
correctAnswers.add(identifierValue.intValue());
}
} else if (correctResponse.getCardinality().isOneOf(Cardinality.MULTIPLE)) {
Value value = FieldValue.computeValue(Cardinality.MULTIPLE, correctResponse.getFieldValues());
if (value instanceof MultipleValue) {
MultipleValue multiValue = (MultipleValue) value;
for (SingleValue sValue : multiValue.getAll()) {
if (sValue instanceof IntegerValue) {
IntegerValue identifierValue = (IntegerValue) value;
correctAnswers.add(identifierValue.intValue());
}
}
}
}
}
return correctAnswers;
}
Aggregations