Search in sources :

Example 11 with MatchInteraction

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

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

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 13 with MatchInteraction

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

the class AssessmentItemFactory method appendMatchInteractionTrueFalse.

public static MatchInteraction appendMatchInteractionTrueFalse(ItemBody itemBody, String unanswered, String right, String wrong, Identifier responseDeclarationId) {
    MatchInteraction matchInteraction = new MatchInteraction(itemBody);
    matchInteraction.setResponseIdentifier(responseDeclarationId);
    matchInteraction.setMaxAssociations(4);
    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++) {
        appendSimpleAssociableChoice(sourceMatchSet, sources[i], 1, 1);
    }
    SimpleMatchSet targetMatchSet = new SimpleMatchSet(matchInteraction);
    matchInteraction.getSimpleMatchSets().add(targetMatchSet);
    String[] targets = new String[] { unanswered, right, wrong };
    for (int i = 0; i < targets.length; i++) {
        appendSimpleAssociableChoice(targetMatchSet, targets[i], 0, 0);
    }
    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) PromptGroup(uk.ac.ed.ph.jqtiplus.group.item.interaction.PromptGroup)

Example 14 with MatchInteraction

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

the class MatchInteractionArchive method writeHeader2.

@Override
public int writeHeader2(AssessmentItem item, Interaction interaction, int itemNumber, int interactionNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
    MatchInteraction matchInteraction = (MatchInteraction) interaction;
    boolean kprim = matchInteraction.getResponseIdentifier().toString().startsWith("KPRIM_") || QTI21QuestionType.hasClass(matchInteraction, QTI21Constants.CSS_MATCH_KPRIM);
    String fix = kprim ? "_KP" : "_K";
    int numOfChoices = matchInteraction.getSimpleMatchSets().get(0).getSimpleAssociableChoices().size();
    if (numOfChoices > 0) {
        for (int i = 0; i < numOfChoices; i++) {
            String header = (itemNumber + 1) + fix + (i + 1);
            dataRow.addCell(col++, header, workbook.getStyles().getHeaderStyle());
        }
    } else {
        col++;
    }
    return col;
}
Also used : MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction)

Example 15 with MatchInteraction

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

the class MatchInteractionArchive method writeInteractionData.

@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
    MatchInteraction matchInteraction = (MatchInteraction) interaction;
    String stringuifiedResponse = response == null ? null : response.getStringuifiedResponse();
    if (!StringHelper.containsNonWhitespace(stringuifiedResponse)) {
        col += matchInteraction.getSimpleMatchSets().get(0).getSimpleAssociableChoices().size();
    } else {
        boolean kprim = matchInteraction.getResponseIdentifier().toString().startsWith("KPRIM_") || QTI21QuestionType.hasClass(matchInteraction, QTI21Constants.CSS_MATCH_KPRIM);
        Set<String> correctAnswers = CorrectResponsesUtil.getCorrectDirectPairResponses(item, matchInteraction, false);
        List<String> responses = CorrectResponsesUtil.parseResponses(stringuifiedResponse);
        SimpleMatchSet firstMatchSet = matchInteraction.getSimpleMatchSets().get(0);
        SimpleMatchSet secondMatchSet = matchInteraction.getSimpleMatchSets().get(1);
        for (SimpleAssociableChoice choice : firstMatchSet.getSimpleAssociableChoices()) {
            String choiceIdentifier = choice.getIdentifier().toString();
            if (kprim) {
                String markerCorrect = choiceIdentifier + " correct";
                String markerWrong = choiceIdentifier + " wrong";
                boolean isCorrectRight = correctAnswers.contains(markerCorrect);
                String rightFlag = isCorrectRight ? markerCorrect : markerWrong;
                String wrongFlag = isCorrectRight ? markerWrong : markerCorrect;
                String value = null;
                if (stringuifiedResponse.contains(markerCorrect)) {
                    value = "+";
                } else if (stringuifiedResponse.contains(markerWrong)) {
                    value = "-";
                }
                if (stringuifiedResponse.indexOf(rightFlag) >= 0) {
                    dataRow.addCell(col++, value, workbook.getStyles().getCorrectStyle());
                } else if (stringuifiedResponse.indexOf(wrongFlag) >= 0) {
                    dataRow.addCell(col++, value, null);
                } else {
                    col++;
                }
            } else {
                String aResponse = null;
                for (String r : responses) {
                    if (r.startsWith(choiceIdentifier)) {
                        aResponse = r;
                    }
                }
                if (StringHelper.containsNonWhitespace(aResponse)) {
                    boolean correct = correctAnswers.contains(aResponse);
                    String value = null;
                    for (SimpleAssociableChoice association : secondMatchSet.getSimpleAssociableChoices()) {
                        if (aResponse.endsWith(association.getIdentifier().toString())) {
                            value = getContent(association);
                            break;
                        }
                    }
                    if (correct) {
                        dataRow.addCell(col++, value, workbook.getStyles().getCorrectStyle());
                    } else {
                        dataRow.addCell(col++, value, null);
                    }
                } else {
                    col++;
                }
            }
        }
    }
    return col;
}
Also used : MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) SimpleMatchSet(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)

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