Search in sources :

Example 11 with SimpleAssociableChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice 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 12 with SimpleAssociableChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project OpenOLAT by OpenOLAT.

the class AssessmentItemFactory method appendMatchInteraction.

public static MatchInteraction appendMatchInteraction(ItemBody itemBody, Identifier responseDeclarationId) {
    MatchInteraction matchInteraction = new MatchInteraction(itemBody);
    matchInteraction.setResponseIdentifier(responseDeclarationId);
    matchInteraction.setMaxAssociations(0);
    matchInteraction.setShuffle(false);
    itemBody.getBlocks().add(matchInteraction);
    PromptGroup prompts = new PromptGroup(matchInteraction);
    matchInteraction.getNodeGroups().add(prompts);
    SimpleMatchSet sourceMatchSet = new SimpleMatchSet(matchInteraction);
    matchInteraction.getSimpleMatchSets().add(sourceMatchSet);
    String[] sources = new String[] { "A", "B" };
    for (int i = 0; i < sources.length; i++) {
        SimpleAssociableChoice sourceChoice = new SimpleAssociableChoice(sourceMatchSet);
        sourceChoice.setMatchMax(0);
        sourceChoice.setMatchMin(0);
        sourceChoice.setIdentifier(IdentifierGenerator.newNumberAsIdentifier(sources[i]));
        P question = getParagraph(sourceChoice, sources[i]);
        sourceChoice.getFlowStatics().add(question);
        sourceMatchSet.getSimpleAssociableChoices().add(sourceChoice);
    }
    SimpleMatchSet targetMatchSet = new SimpleMatchSet(matchInteraction);
    matchInteraction.getSimpleMatchSets().add(targetMatchSet);
    String[] targets = new String[] { "M", "N" };
    for (int i = 0; i < targets.length; i++) {
        SimpleAssociableChoice targetChoice = new SimpleAssociableChoice(sourceMatchSet);
        targetChoice.setMatchMax(0);
        targetChoice.setMatchMin(0);
        targetChoice.setIdentifier(IdentifierGenerator.newNumberAsIdentifier(targets[i]));
        P question = getParagraph(targetChoice, targets[i]);
        targetChoice.getFlowStatics().add(question);
        targetMatchSet.getSimpleAssociableChoices().add(targetChoice);
    }
    return matchInteraction;
}
Also used : MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) SimpleMatchSet(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet) P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) PromptGroup(uk.ac.ed.ph.jqtiplus.group.item.interaction.PromptGroup)

Example 13 with SimpleAssociableChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project OpenOLAT by OpenOLAT.

the class CSVToAssessmentItemConverter method processChoice_match.

private void processChoice_match(String[] parts, MatchAssessmentItemBuilder matchBuilder) {
    List<SimpleAssociableChoice> targetChoices = matchBuilder.getTargetChoices();
    if (targetChoices == null || targetChoices.isEmpty()) {
        for (int i = 1; i < parts.length; i++) {
            String answer = parts[i];
            SimpleAssociableChoice choice = AssessmentItemFactory.createSimpleAssociableChoice(answer, matchBuilder.getTargetMatchSet());
            targetChoices.add(choice);
        }
    } else {
        String answer = parts[0];
        if (StringHelper.containsNonWhitespace(answer)) {
            SimpleAssociableChoice sourceChoice = AssessmentItemFactory.createSimpleAssociableChoice(answer, matchBuilder.getSourceMatchSet());
            matchBuilder.getSourceChoices().add(sourceChoice);
            // correct answer and points
            for (int i = 1; i < parts.length && i < (targetChoices.size() + 1); i++) {
                double point = parseFloat(parts[i], 0.0f);
                SimpleAssociableChoice targetChoice = targetChoices.get(i - 1);
                DirectedPairValue directedPair = new DirectedPairValue(sourceChoice.getIdentifier(), targetChoice.getIdentifier());
                matchBuilder.addScore(directedPair, Double.valueOf(point));
                if (point > 0.0) {
                    matchBuilder.addAssociation(sourceChoice.getIdentifier(), targetChoice.getIdentifier());
                }
            }
        }
    }
}
Also used : SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)

Example 14 with SimpleAssociableChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project openolat by klemens.

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 15 with SimpleAssociableChoice

use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project openolat by klemens.

the class MatchAssessmentItemBuilder method extractSingleChoice.

/**
 * Single choice is a special edge case where
 * all source choices have matchMax=1 and all
 * target choices have matchMax=0
 */
private void extractSingleChoice() {
    List<SimpleAssociableChoice> sourceChoices = matchInteraction.getSimpleMatchSets().get(0).getSimpleAssociableChoices();
    List<SimpleAssociableChoice> targetChoices = matchInteraction.getSimpleMatchSets().get(1).getSimpleAssociableChoices();
    boolean singleChoice = true;
    for (SimpleAssociableChoice sourceChoice : sourceChoices) {
        if (sourceChoice.getMatchMax() != 1) {
            singleChoice &= false;
        }
    }
    for (SimpleAssociableChoice targetChoice : targetChoices) {
        if (targetChoice.getMatchMax() != 0) {
            singleChoice &= false;
        }
    }
    multipleChoice = !singleChoice;
}
Also used : SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)

Aggregations

SimpleAssociableChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)54 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)20 MatchInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction)18 ArrayList (java.util.ArrayList)17 SimpleMatchSet (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet)16 AssessmentItemFactory.createSimpleAssociableChoice (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createSimpleAssociableChoice)14 HashMap (java.util.HashMap)12 List (java.util.List)10 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)10 AssessmentItemEvent (org.olat.ims.qti21.ui.editor.events.AssessmentItemEvent)10 P (uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P)10 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)10 FlowFormItem (org.olat.ims.qti21.ui.components.FlowFormItem)7 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)7 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)6 File (java.io.File)4 UserRequest (org.olat.core.gui.UserRequest)4 FormItem (org.olat.core.gui.components.form.flexible.FormItem)4