Search in sources :

Example 66 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.

the class AssessmentItemChecker method checkSetCorrectResponse.

/**
 * responseDeclaration -> float
 *
 * templateVraiable -> integer
 *
 * setCorrectResponse
 *   -> variable -> integer doesn't match float -> issue
 * @param item
 * @return
 */
private static boolean checkSetCorrectResponse(AssessmentItem item) {
    boolean allOk = true;
    List<SetCorrectResponse> setCorrectResponses = QueryUtils.search(SetCorrectResponse.class, item);
    for (SetCorrectResponse setCorrectResponse : setCorrectResponses) {
        Identifier responseIdentifier = setCorrectResponse.getIdentifier();
        ResponseDeclaration responseDeclaration = item.getResponseDeclaration(responseIdentifier);
        BaseType baseType = responseDeclaration.getBaseType();
        Expression expression = setCorrectResponse.getExpression();
        if (expression instanceof Variable) {
            Variable variable = (Variable) expression;
            ComplexReferenceIdentifier cpxVariableIdentifier = variable.getIdentifier();
            Identifier variableIdentifier = Identifier.assumedLegal(cpxVariableIdentifier.toString());
            TemplateDeclaration templateDeclaration = item.getTemplateDeclaration(variableIdentifier);
            if (templateDeclaration != null && !templateDeclaration.hasBaseType(baseType)) {
                templateDeclaration.setBaseType(baseType);
                allOk &= false;
            }
        }
    }
    return allOk;
}
Also used : ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) SetCorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.template.processing.SetCorrectResponse) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) BaseType(uk.ac.ed.ph.jqtiplus.value.BaseType) Expression(uk.ac.ed.ph.jqtiplus.node.expression.Expression) TemplateDeclaration(uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 67 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.

the class AssessmentItemFactory method appendAssociationKPrimResponseDeclaration.

public static ResponseDeclaration appendAssociationKPrimResponseDeclaration(ResponseDeclaration responseDeclaration, Map<Identifier, Identifier> associations, double maxScore) {
    responseDeclaration.setCardinality(Cardinality.MULTIPLE);
    responseDeclaration.setBaseType(BaseType.DIRECTED_PAIR);
    // correct response
    CorrectResponse correctResponse = new CorrectResponse(responseDeclaration);
    responseDeclaration.setCorrectResponse(correctResponse);
    for (Map.Entry<Identifier, Identifier> association : associations.entrySet()) {
        Identifier choiceId = association.getKey();
        Identifier correctwrongId = association.getValue();
        DirectedPairValue dpValue = new DirectedPairValue(choiceId, correctwrongId);
        FieldValue fValue = new FieldValue(correctResponse, dpValue);
        correctResponse.getFieldValues().add(fValue);
    }
    double mappedValue = maxScore;
    if (associations.size() > 0) {
        mappedValue = maxScore / associations.size();
    }
    // mapping
    Mapping mapping = new Mapping(responseDeclaration);
    mapping.setDefaultValue(-mappedValue);
    responseDeclaration.setMapping(mapping);
    for (Map.Entry<Identifier, Identifier> association : associations.entrySet()) {
        Identifier choiceId = association.getKey();
        Identifier correctwrongId = association.getValue();
        MapEntry mapEntry = new MapEntry(mapping);
        mapEntry.setMapKey(new DirectedPairValue(choiceId, correctwrongId));
        mapEntry.setMappedValue(mappedValue);
        mapping.getMapEntries().add(mapEntry);
    }
    return responseDeclaration;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) 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) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) Map(java.util.Map)

Example 68 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.

the class AssessmentItemFactory method createHottextCorrectResponseDeclaration.

public static ResponseDeclaration createHottextCorrectResponseDeclaration(AssessmentItem assessmentItem, Identifier declarationId, List<Identifier> correctResponseIds) {
    ResponseDeclaration responseDeclaration = new ResponseDeclaration(assessmentItem);
    responseDeclaration.setIdentifier(declarationId);
    responseDeclaration.setCardinality(Cardinality.MULTIPLE);
    responseDeclaration.setBaseType(BaseType.IDENTIFIER);
    CorrectResponse correctResponse = new CorrectResponse(responseDeclaration);
    responseDeclaration.setCorrectResponse(correctResponse);
    for (Identifier correctResponseId : correctResponseIds) {
        appendIdentifierValue(correctResponse, correctResponseId);
    }
    return responseDeclaration;
}
Also used : 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) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 69 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.

the class QtiNodesExtractor method extractIdentifiersFromCorrectResponse.

public static void extractIdentifiersFromCorrectResponse(CorrectResponse correctResponse, Map<Identifier, List<Identifier>> correctAnswers) {
    if (correctResponse != null) {
        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 = correctAnswers.get(sourceId);
                if (targetIds == null) {
                    targetIds = new ArrayList<>();
                    correctAnswers.put(sourceId, targetIds);
                }
                targetIds.add(targetId);
            }
        }
    }
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)

Example 70 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.

the class DrawingAssessmentItemBuilder method createAssessmentItem.

private static AssessmentItem createAssessmentItem(String title) {
    AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.drawing, title);
    // define the response
    Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
    ResponseDeclaration responseDeclaration = createDrawingResponseDeclaration(assessmentItem, responseDeclarationId);
    assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
    // outcomes
    appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
    ItemBody itemBody = appendDefaultItemBody(assessmentItem);
    appendDrawingInteraction(itemBody, responseDeclarationId);
    // response processing
    ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
    assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
    return assessmentItem;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ItemBody(uk.ac.ed.ph.jqtiplus.node.content.ItemBody) AssessmentItemFactory.appendDefaultItemBody(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendDefaultItemBody) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ResponseProcessing(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing) AssessmentItemFactory.createResponseProcessing(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createDrawingResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createDrawingResponseDeclaration)

Aggregations

Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)208 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)62 ArrayList (java.util.ArrayList)53 HashMap (java.util.HashMap)52 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)46 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)42 Value (uk.ac.ed.ph.jqtiplus.value.Value)42 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)40 Map (java.util.Map)32 SimpleAssociableChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)24 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)24 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)24 ItemBody (uk.ac.ed.ph.jqtiplus.node.content.ItemBody)22 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)22 ResponseProcessing (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing)22 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)22 List (java.util.List)20 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)20 SimpleChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice)20 RecordValue (uk.ac.ed.ph.jqtiplus.value.RecordValue)20