Search in sources :

Example 16 with SimpleMatchSet

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

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 17 with SimpleMatchSet

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

the class AssessmentItemFactory method appendMatchInteractionForKPrim.

public static MatchInteraction appendMatchInteractionForKPrim(ItemBody itemBody, Identifier responseDeclarationId, String defaultAnswer) {
    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 questionMatchSet = new SimpleMatchSet(matchInteraction);
    matchInteraction.getSimpleMatchSets().add(questionMatchSet);
    String[] classic = new String[] { "a", "b", "c", "d" };
    for (int i = 0; i < 4; i++) {
        SimpleAssociableChoice correctChoice = new SimpleAssociableChoice(questionMatchSet);
        correctChoice.setMatchMax(1);
        correctChoice.setMatchMin(1);
        correctChoice.setIdentifier(IdentifierGenerator.newNumberAsIdentifier(classic[i]));
        P question = getParagraph(correctChoice, defaultAnswer + " " + classic[i]);
        correctChoice.getFlowStatics().add(question);
        questionMatchSet.getSimpleAssociableChoices().add(correctChoice);
    }
    SimpleMatchSet correctWrongMatchSet = new SimpleMatchSet(matchInteraction);
    matchInteraction.getSimpleMatchSets().add(correctWrongMatchSet);
    SimpleAssociableChoice correctChoice = new SimpleAssociableChoice(correctWrongMatchSet);
    correctChoice.setMatchMax(4);
    correctChoice.setFixed(Boolean.TRUE);
    correctChoice.setIdentifier(QTI21Constants.CORRECT_IDENTIFIER);
    correctChoice.getFlowStatics().add(new TextRun(correctChoice, "+"));
    correctWrongMatchSet.getSimpleAssociableChoices().add(correctChoice);
    SimpleAssociableChoice wrongChoice = new SimpleAssociableChoice(correctWrongMatchSet);
    wrongChoice.setMatchMax(4);
    wrongChoice.setFixed(Boolean.TRUE);
    wrongChoice.setIdentifier(QTI21Constants.WRONG_IDENTIFIER);
    wrongChoice.getFlowStatics().add(new TextRun(correctChoice, "-"));
    correctWrongMatchSet.getSimpleAssociableChoices().add(wrongChoice);
    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) TextRun(uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun)

Example 18 with SimpleMatchSet

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

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 19 with SimpleMatchSet

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

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 20 with SimpleMatchSet

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

the class AssessmentItemFactory method appendMatchInteractionForKPrim.

public static MatchInteraction appendMatchInteractionForKPrim(ItemBody itemBody, Identifier responseDeclarationId, String defaultAnswer) {
    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 questionMatchSet = new SimpleMatchSet(matchInteraction);
    matchInteraction.getSimpleMatchSets().add(questionMatchSet);
    String[] classic = new String[] { "a", "b", "c", "d" };
    for (int i = 0; i < 4; i++) {
        SimpleAssociableChoice correctChoice = new SimpleAssociableChoice(questionMatchSet);
        correctChoice.setMatchMax(1);
        correctChoice.setMatchMin(1);
        correctChoice.setIdentifier(IdentifierGenerator.newNumberAsIdentifier(classic[i]));
        P question = getParagraph(correctChoice, defaultAnswer + " " + classic[i]);
        correctChoice.getFlowStatics().add(question);
        questionMatchSet.getSimpleAssociableChoices().add(correctChoice);
    }
    SimpleMatchSet correctWrongMatchSet = new SimpleMatchSet(matchInteraction);
    matchInteraction.getSimpleMatchSets().add(correctWrongMatchSet);
    SimpleAssociableChoice correctChoice = new SimpleAssociableChoice(correctWrongMatchSet);
    correctChoice.setMatchMax(4);
    correctChoice.setFixed(Boolean.TRUE);
    correctChoice.setIdentifier(QTI21Constants.CORRECT_IDENTIFIER);
    correctChoice.getFlowStatics().add(new TextRun(correctChoice, "+"));
    correctWrongMatchSet.getSimpleAssociableChoices().add(correctChoice);
    SimpleAssociableChoice wrongChoice = new SimpleAssociableChoice(correctWrongMatchSet);
    wrongChoice.setMatchMax(4);
    wrongChoice.setFixed(Boolean.TRUE);
    wrongChoice.setIdentifier(QTI21Constants.WRONG_IDENTIFIER);
    wrongChoice.getFlowStatics().add(new TextRun(correctChoice, "-"));
    correctWrongMatchSet.getSimpleAssociableChoices().add(wrongChoice);
    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) TextRun(uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun)

Aggregations

SimpleMatchSet (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet)21 SimpleAssociableChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)16 MatchInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction)12 ArrayList (java.util.ArrayList)10 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)8 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)8 HashMap (java.util.HashMap)6 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)6 List (java.util.List)4 KPrimStatistics (org.olat.ims.qti21.model.statistics.KPrimStatistics)4 PromptGroup (uk.ac.ed.ph.jqtiplus.group.item.interaction.PromptGroup)4 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)4 P (uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P)3 File (java.io.File)2 URI (java.net.URI)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 UserRequest (org.olat.core.gui.UserRequest)2