Search in sources :

Example 6 with MatchInteraction

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

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

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

the class MatchAssessmentItemBuilder method extractMatchInteraction.

private void extractMatchInteraction() {
    try (StringOutput sb = new StringOutput()) {
        List<Block> blocks = assessmentItem.getItemBody().getBlocks();
        for (Block block : blocks) {
            if (block instanceof MatchInteraction) {
                matchInteraction = (MatchInteraction) block;
                responseIdentifier = matchInteraction.getResponseIdentifier();
                shuffle = matchInteraction.getShuffle();
                break;
            } else {
                serializeJqtiObject(block, sb);
            }
        }
        question = sb.toString();
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : AssessmentItemFactory.appendMatchInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendMatchInteraction) MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) StringOutput(org.olat.core.gui.render.StringOutput) IOException(java.io.IOException)

Example 9 with MatchInteraction

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

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

the class KPrimAssessmentItemBuilder method getQuestionBlocks.

/**
 * @return A copy of the list of blocks which make the question.
 * 		The list is a copy and modification will not be persisted.
 */
public List<Block> getQuestionBlocks() {
    List<Block> blocks = assessmentItem.getItemBody().getBlocks();
    List<Block> questionBlocks = new ArrayList<>(blocks.size());
    for (Block block : blocks) {
        if (block instanceof MatchInteraction) {
            break;
        } else {
            questionBlocks.add(block);
        }
    }
    return questionBlocks;
}
Also used : MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) ArrayList(java.util.ArrayList) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block)

Aggregations

MatchInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction)40 SimpleAssociableChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)18 ArrayList (java.util.ArrayList)12 SimpleMatchSet (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet)12 Block (uk.ac.ed.ph.jqtiplus.node.content.basic.Block)10 HashMap (java.util.HashMap)8 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)8 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)8 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)8 IOException (java.io.IOException)6 List (java.util.List)6 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)6 StringOutput (org.olat.core.gui.render.StringOutput)6 AssessmentItemFactory.appendMatchInteraction (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendMatchInteraction)6 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)6 HotspotInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction)6 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)6 FlowFormItem (org.olat.ims.qti21.ui.components.FlowFormItem)5 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4