Search in sources :

Example 16 with Identifier

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

the class KPrimAssessmentItemBuilder method createAssessmentItem.

private static AssessmentItem createAssessmentItem(String title, String defaultAnswer) {
    AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.kprim, title);
    NodeGroupList nodeGroups = assessmentItem.getNodeGroups();
    double maxScore = 1.0d;
    Identifier responseDeclarationId = Identifier.assumedLegal("KPRIM_RESPONSE_1");
    // define correct answer
    ResponseDeclaration responseDeclaration = createKPrimResponseDeclaration(assessmentItem, responseDeclarationId, new HashMap<>(), maxScore);
    nodeGroups.getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
    appendDefaultOutcomeDeclarations(assessmentItem, maxScore);
    // the single choice interaction
    ItemBody itemBody = appendDefaultItemBody(assessmentItem);
    MatchInteraction matchInteraction = appendMatchInteractionForKPrim(itemBody, responseDeclarationId, defaultAnswer);
    List<String> cssClasses = new ArrayList<>();
    cssClasses.add(QTI21Constants.CSS_MATCH_KPRIM);
    matchInteraction.setClassAttr(cssClasses);
    SimpleMatchSet matchSet = matchInteraction.getSimpleMatchSets().get(0);
    Map<Identifier, Identifier> associations = new HashMap<>();
    for (SimpleAssociableChoice choice : matchSet.getSimpleAssociableChoices()) {
        associations.put(choice.getIdentifier(), QTI21Constants.WRONG_IDENTIFIER);
    }
    appendAssociationKPrimResponseDeclaration(responseDeclaration, associations, 1.0);
    // response processing
    ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
    assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
    return assessmentItem;
}
Also used : MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) AssessmentItemFactory.createResponseProcessing(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing) ResponseProcessing(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing) SimpleMatchSet(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) AssessmentItemFactory.appendDefaultItemBody(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendDefaultItemBody) ItemBody(uk.ac.ed.ph.jqtiplus.node.content.ItemBody) NodeGroupList(uk.ac.ed.ph.jqtiplus.group.NodeGroupList) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createKPrimResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createKPrimResponseDeclaration) AssessmentItemFactory.appendAssociationKPrimResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendAssociationKPrimResponseDeclaration)

Example 17 with Identifier

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

the class KPrimAssessmentItemBuilder 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 destinationId = dpValue.destValue();
                    associations.put(sourceId, destinationId);
                }
            }
        }
    }
}
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) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createKPrimResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createKPrimResponseDeclaration) AssessmentItemFactory.appendAssociationKPrimResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendAssociationKPrimResponseDeclaration)

Example 18 with Identifier

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

the class MatchAssessmentItemBuilder method createAssessmentItem.

private static AssessmentItem createAssessmentItem(String title, String matchCssClass, String unanswered, String right, String wrong) {
    AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.match, title);
    NodeGroupList nodeGroups = assessmentItem.getNodeGroups();
    double maxScore = 1.0d;
    Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
    // define correct answer
    ResponseDeclaration responseDeclaration = createMatchResponseDeclaration(assessmentItem, responseDeclarationId, new HashMap<>());
    nodeGroups.getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
    appendDefaultOutcomeDeclarations(assessmentItem, maxScore);
    // the single choice interaction
    ItemBody itemBody = appendDefaultItemBody(assessmentItem);
    Map<Identifier, List<Identifier>> associations = new HashMap<>();
    MatchInteraction interaction;
    if (QTI21Constants.CSS_MATCH_TRUE_FALSE.equals(matchCssClass)) {
        interaction = appendMatchInteractionTrueFalse(itemBody, unanswered, right, wrong, responseDeclarationId);
        // default correct answers set to "right"
        SimpleAssociableChoice rightChoice = interaction.getSimpleMatchSets().get(1).getSimpleAssociableChoices().get(1);
        List<SimpleAssociableChoice> sourceChoices = interaction.getSimpleMatchSets().get(0).getSimpleAssociableChoices();
        for (SimpleAssociableChoice sourceChoice : sourceChoices) {
            List<Identifier> targetIdentifiers = new ArrayList<>();
            targetIdentifiers.add(rightChoice.getIdentifier());
            associations.put(sourceChoice.getIdentifier(), targetIdentifiers);
        }
    } else {
        interaction = appendMatchInteraction(itemBody, responseDeclarationId);
    }
    List<String> cssClasses = new ArrayList<>();
    cssClasses.add(matchCssClass);
    interaction.setClassAttr(cssClasses);
    appendAssociationMatchResponseDeclaration(responseDeclaration, associations);
    // response processing
    ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
    assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
    return assessmentItem;
}
Also used : AssessmentItemFactory.appendMatchInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendMatchInteraction) MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) AssessmentItemFactory.createResponseProcessing(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing) ResponseProcessing(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) AssessmentItemFactory.appendDefaultItemBody(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendDefaultItemBody) ItemBody(uk.ac.ed.ph.jqtiplus.node.content.ItemBody) NodeGroupList(uk.ac.ed.ph.jqtiplus.group.NodeGroupList) List(java.util.List) ArrayList(java.util.ArrayList) NodeGroupList(uk.ac.ed.ph.jqtiplus.group.NodeGroupList) 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 19 with Identifier

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

the class SimpleChoiceAssessmentItemBuilder method extractScoreEvaluationMode.

private void extractScoreEvaluationMode() {
    boolean hasMapping = false;
    if (choiceInteraction != null) {
        ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(choiceInteraction.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;
}
Also used : MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) Mapping(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 20 with Identifier

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

the class UploadAssessmentItemBuilder method createAssessmentItem.

private static AssessmentItem createAssessmentItem(String title) {
    AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.upload, title);
    // define the response
    Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
    ResponseDeclaration responseDeclaration = createUploadResponseDeclaration(assessmentItem, responseDeclarationId);
    assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
    // outcomes
    appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
    ItemBody itemBody = appendDefaultItemBody(assessmentItem);
    appendUploadInteraction(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.createUploadResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createUploadResponseDeclaration)

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