Search in sources :

Example 6 with StringValue

use of uk.ac.ed.ph.jqtiplus.value.StringValue in project OpenOLAT by OpenOLAT.

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 7 with StringValue

use of uk.ac.ed.ph.jqtiplus.value.StringValue in project openolat by klemens.

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);
}
Also used : MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) ArrayList(java.util.ArrayList) StringValue(uk.ac.ed.ph.jqtiplus.value.StringValue) TextEntryInteractionStatistics(org.olat.ims.qti21.model.statistics.TextEntryInteractionStatistics) AbstractTextEntryInteractionStatistics(org.olat.ims.qti21.model.statistics.AbstractTextEntryInteractionStatistics)

Example 8 with StringValue

use of uk.ac.ed.ph.jqtiplus.value.StringValue 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 9 with StringValue

use of uk.ac.ed.ph.jqtiplus.value.StringValue in project openolat by klemens.

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;
}
Also used : MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) Mapping(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) StringValue(uk.ac.ed.ph.jqtiplus.value.StringValue) TextEntryAlternative(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntryAlternative) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 10 with StringValue

use of uk.ac.ed.ph.jqtiplus.value.StringValue in project openolat by klemens.

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);
}
Also used : FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) StringValue(uk.ac.ed.ph.jqtiplus.value.StringValue)

Aggregations

StringValue (uk.ac.ed.ph.jqtiplus.value.StringValue)10 MapEntry (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry)6 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)6 ArrayList (java.util.ArrayList)4 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)4 Mapping (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping)4 FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)4 Map (java.util.Map)2 AbstractTextEntryInteractionStatistics (org.olat.ims.qti21.model.statistics.AbstractTextEntryInteractionStatistics)2 TextEntryInteractionStatistics (org.olat.ims.qti21.model.statistics.TextEntryInteractionStatistics)2 TextEntryAlternative (org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntryAlternative)2 QtiAttributeException (uk.ac.ed.ph.jqtiplus.exception.QtiAttributeException)2 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)2 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)2 RecordValue (uk.ac.ed.ph.jqtiplus.value.RecordValue)2