Search in sources :

Example 41 with FieldValue

use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project openolat by klemens.

the class FIBAssessmentItemBuilder method extractTextEntrySettingsFromResponseDeclaration.

/**
 * All the needed informations are in the responseDeclaration, the list of alternatives
 * is in the mapping with case sensitivity options and score.
 *
 * @param textEntry
 * @param responseDeclaration
 * @param countAlternatives
 * @param mappedScore
 */
public static void extractTextEntrySettingsFromResponseDeclaration(TextEntry textEntry, ResponseDeclaration responseDeclaration, AtomicInteger countAlternatives, DoubleAdder mappedScore) {
    String 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 StringValue) {
            solution = ((StringValue) sValue).stringValue();
            textEntry.setSolution(solution);
        }
        if (correctResponse.getFieldValues().size() > 1) {
            List<TextEntryAlternative> alternatives = new ArrayList<>();
            for (int i = 1; i < correctResponse.getFieldValues().size(); i++) {
                SingleValue aValue = fValues.get(i).getSingleValue();
                if (aValue instanceof StringValue) {
                    TextEntryAlternative alternative = new TextEntryAlternative();
                    alternative.setAlternative(((StringValue) aValue).stringValue());
                    alternatives.add(alternative);
                }
            }
            textEntry.setAlternatives(alternatives);
        }
    }
    Mapping mapping = responseDeclaration.getMapping();
    if (mapping != null) {
        boolean caseSensitive = true;
        List<TextEntryAlternative> alternatives = new ArrayList<>();
        List<MapEntry> mapEntries = mapping.getMapEntries();
        for (MapEntry mapEntry : mapEntries) {
            TextEntryAlternative alternative = new TextEntryAlternative();
            SingleValue sValue = mapEntry.getMapKey();
            if (sValue instanceof StringValue) {
                String alt = ((StringValue) sValue).stringValue();
                if (solution == null || !solution.equals(alt)) {
                    alternative.setAlternative(alt);
                    alternative.setScore(mapEntry.getMappedValue());
                    alternatives.add(alternative);
                } else if (alt.equals(solution)) {
                    try {
                        textEntry.setScore(mapEntry.getMappedValue());
                    } catch (QtiAttributeException e) {
                        log.error("", e);
                    }
                }
                countAlternatives.incrementAndGet();
                mappedScore.add(mapEntry.getMappedValue());
            }
            caseSensitive &= mapEntry.getCaseSensitive();
        }
        textEntry.setCaseSensitive(caseSensitive);
        textEntry.setAlternatives(alternatives);
    }
}
Also used : QtiAttributeException(uk.ac.ed.ph.jqtiplus.exception.QtiAttributeException) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) ArrayList(java.util.ArrayList) Mapping(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) StringValue(uk.ac.ed.ph.jqtiplus.value.StringValue)

Example 42 with FieldValue

use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project openolat by klemens.

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);
    }
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) ResponseRule(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule) Expression(uk.ac.ed.ph.jqtiplus.node.expression.Expression) Equal(uk.ac.ed.ph.jqtiplus.node.expression.operator.Equal) And(uk.ac.ed.ph.jqtiplus.node.expression.operator.And) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Example 43 with FieldValue

use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project openolat by klemens.

the class MatchAssessmentItemBuilder method extractCorrectResponse.

private void extractCorrectResponse() {
    associations = new HashMap<>();
    if (matchInteraction != null) {
        ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(matchInteraction.getResponseIdentifier());
        if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
            CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
            List<FieldValue> values = correctResponse.getFieldValues();
            for (FieldValue value : values) {
                SingleValue sValue = value.getSingleValue();
                if (sValue instanceof DirectedPairValue) {
                    DirectedPairValue dpValue = (DirectedPairValue) sValue;
                    Identifier sourceId = dpValue.sourceValue();
                    Identifier targetId = dpValue.destValue();
                    List<Identifier> targetIds = associations.get(sourceId);
                    if (targetIds == null) {
                        targetIds = new ArrayList<>();
                        associations.put(sourceId, targetIds);
                    }
                    targetIds.add(targetId);
                }
            }
        }
    }
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) AssessmentItemFactory.appendAssociationMatchResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendAssociationMatchResponseDeclaration) AssessmentItemFactory.createMatchResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createMatchResponseDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 44 with FieldValue

use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project openolat by klemens.

the class AssessmentItemFactory method createOutcomeDeclarationForScoreResponse.

/*
	<outcomeDeclaration identifier="SCORE_RESPONSE_2" cardinality="single" baseType="float" view="testConstructor">
		<defaultValue>
			<value>0</value>
		</defaultValue>
	</outcomeDeclaration>
	*/
public static OutcomeDeclaration createOutcomeDeclarationForScoreResponse(AssessmentItem assessmentItem, String scoreIdentifier) {
    OutcomeDeclaration scoreOutcomeDeclaration = new OutcomeDeclaration(assessmentItem);
    scoreOutcomeDeclaration.setIdentifier(Identifier.parseString(scoreIdentifier));
    scoreOutcomeDeclaration.setCardinality(Cardinality.SINGLE);
    scoreOutcomeDeclaration.setBaseType(BaseType.FLOAT);
    DefaultValue scoreDefaultVal = new DefaultValue(scoreOutcomeDeclaration);
    scoreOutcomeDeclaration.setDefaultValue(scoreDefaultVal);
    FieldValue scoreDefaultFieldVal = new FieldValue(scoreDefaultVal, FloatValue.ZERO);
    scoreDefaultVal.getFieldValues().add(scoreDefaultFieldVal);
    return scoreOutcomeDeclaration;
}
Also used : DefaultValue(uk.ac.ed.ph.jqtiplus.node.shared.declaration.DefaultValue) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) OutcomeDeclaration(uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration)

Example 45 with FieldValue

use of uk.ac.ed.ph.jqtiplus.node.shared.FieldValue in project openolat by klemens.

the class AssessmentItemFactory method appendAssociationMatchResponseDeclaration.

public static ResponseDeclaration appendAssociationMatchResponseDeclaration(ResponseDeclaration responseDeclaration, Map<Identifier, List<Identifier>> associations) {
    responseDeclaration.setCardinality(Cardinality.MULTIPLE);
    responseDeclaration.setBaseType(BaseType.DIRECTED_PAIR);
    // correct response
    CorrectResponse correctResponse = new CorrectResponse(responseDeclaration);
    responseDeclaration.setCorrectResponse(correctResponse);
    for (Map.Entry<Identifier, List<Identifier>> association : associations.entrySet()) {
        Identifier sourceChoiceId = association.getKey();
        List<Identifier> targetChoiceIds = association.getValue();
        for (Identifier targetChoiceId : targetChoiceIds) {
            DirectedPairValue dpValue = new DirectedPairValue(sourceChoiceId, targetChoiceId);
            FieldValue fValue = new FieldValue(correctResponse, dpValue);
            correctResponse.getFieldValues().add(fValue);
        }
    }
    return responseDeclaration;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) List(java.util.List) ArrayList(java.util.ArrayList) NodeGroupList(uk.ac.ed.ph.jqtiplus.group.NodeGroupList) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) Map(java.util.Map)

Aggregations

FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)48 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)24 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)20 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)20 ArrayList (java.util.ArrayList)16 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)16 DefaultValue (uk.ac.ed.ph.jqtiplus.node.shared.declaration.DefaultValue)16 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)16 OutcomeDeclaration (uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration)14 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)14 FloatValue (uk.ac.ed.ph.jqtiplus.value.FloatValue)12 Value (uk.ac.ed.ph.jqtiplus.value.Value)12 IntegerValue (uk.ac.ed.ph.jqtiplus.value.IntegerValue)10 MultipleValue (uk.ac.ed.ph.jqtiplus.value.MultipleValue)10 OrderedValue (uk.ac.ed.ph.jqtiplus.value.OrderedValue)10 PairValue (uk.ac.ed.ph.jqtiplus.value.PairValue)10 PointValue (uk.ac.ed.ph.jqtiplus.value.PointValue)10 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)8 Map (java.util.Map)4 BaseValue (uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue)4