use of uk.ac.ed.ph.jqtiplus.types.Identifier 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());
}
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.
the class AssessmentObjectVelocityRenderDecorator method getVisibleOrderedChoices.
/*
<xsl:function name="qw:get-visible-ordered-choices" as="element()*">
<xsl:param name="interaction" as="element()"/>
<xsl:param name="choices" as="element()*"/>
<xsl:variable name="orderedChoices" as="element()*">
<xsl:choose>
<xsl:when test="$interaction/@shuffle='true'">
<xsl:for-each select="qw:get-shuffled-choice-order($interaction)">
<xsl:sequence select="$choices[@identifier=current()]"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="$choices"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:sequence select="qw:filter-visible($orderedChoices)"/>
</xsl:function>
*/
public List<InlineChoice> getVisibleOrderedChoices(InlineChoiceInteraction interaction) {
List<InlineChoice> choices;
if (interaction.getShuffle()) {
// <xsl:variable name="shuffledChoiceOrders" select="$itemSessionState/qw:shuffledInteractionChoiceOrder"
// as="element(qw:shuffledInteractionChoiceOrder)*"/>
// <xsl:variable name="choiceSequence" as="xs:string?"
// select="$shuffledChoiceOrders[@responseIdentifier=$interaction/@responseIdentifier]/@choiceSequence"/>
List<Identifier> choiceOrders = itemSessionState.getShuffledInteractionChoiceOrder(interaction.getResponseIdentifier());
choices = new ArrayList<>();
for (Identifier choiceOrder : choiceOrders) {
choices.add(interaction.getInlineChoice(choiceOrder));
}
} else {
choices = interaction.getInlineChoices();
}
return choices.stream().filter((choice) -> isVisible(choice, itemSessionState)).collect(Collectors.toList());
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier 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;
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.
the class MultipleChoiceAssessmentItemBuilder method extract.
@Override
public void extract() {
super.extract();
correctAnswers = new ArrayList<>(5);
if (choiceInteraction != null) {
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(choiceInteraction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
Value value = FieldValue.computeValue(Cardinality.MULTIPLE, correctResponse.getFieldValues());
if (value instanceof MultipleValue) {
MultipleValue multiValue = (MultipleValue) value;
for (SingleValue sValue : multiValue.getAll()) {
if (sValue instanceof IdentifierValue) {
IdentifierValue identifierValue = (IdentifierValue) sValue;
Identifier correctAnswer = identifierValue.identifierValue();
correctAnswers.add(correctAnswer);
}
}
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project OpenOLAT by OpenOLAT.
the class MultipleChoiceAssessmentItemBuilder method createAssessmentItem.
private static AssessmentItem createAssessmentItem(String title, String defaultAnswer) {
AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.mc, title);
NodeGroupList nodeGroups = assessmentItem.getNodeGroups();
Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
Identifier correctResponseId = IdentifierGenerator.newAsIdentifier("mc");
// define correct answer
ResponseDeclaration responseDeclaration = createMultipleChoiceCorrectResponseDeclaration(assessmentItem, responseDeclarationId, Collections.singletonList(correctResponseId));
nodeGroups.getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
// outcomes
appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
// the single choice interaction
ItemBody itemBody = appendDefaultItemBody(assessmentItem);
ChoiceInteraction choiceInteraction = appendChoiceInteraction(itemBody, responseDeclarationId, 0, true);
appendSimpleChoice(choiceInteraction, defaultAnswer, correctResponseId);
// response processing
ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
return assessmentItem;
}
Aggregations