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);
}
}
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();
}
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());
}
}
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);
}
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;
}
Aggregations