Search in sources :

Example 36 with ChoiceInteraction

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

the class AssessmentItemFactory method createMultipleChoiceInteraction.

public static ChoiceInteraction createMultipleChoiceInteraction(AssessmentItem assessmentItem, Identifier responseDeclarationId, Orientation orientation, List<String> classAtrr) {
    ChoiceInteraction choiceInteraction = new ChoiceInteraction(assessmentItem.getItemBody());
    choiceInteraction.setMaxChoices(0);
    choiceInteraction.setShuffle(true);
    if (orientation != null) {
        choiceInteraction.setOrientation(orientation);
    }
    if (classAtrr != null && classAtrr.size() > 0) {
        choiceInteraction.setClassAttr(classAtrr);
    }
    choiceInteraction.setResponseIdentifier(responseDeclarationId);
    PromptGroup prompts = new PromptGroup(choiceInteraction);
    choiceInteraction.getNodeGroups().add(prompts);
    SimpleChoiceGroup singleChoices = new SimpleChoiceGroup(choiceInteraction);
    choiceInteraction.getNodeGroups().add(singleChoices);
    return choiceInteraction;
}
Also used : ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) PromptGroup(uk.ac.ed.ph.jqtiplus.group.item.interaction.PromptGroup) SimpleChoiceGroup(uk.ac.ed.ph.jqtiplus.group.item.interaction.choice.SimpleChoiceGroup)

Example 37 with ChoiceInteraction

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

the class MultipleChoiceAssessmentItemBuilder method buildItemBody.

@Override
protected void buildItemBody() {
    // remove current blocks
    List<Block> blocks = assessmentItem.getItemBody().getBlocks();
    blocks.clear();
    // add question
    getHtmlHelper().appendHtml(assessmentItem.getItemBody(), question);
    // add interaction
    ChoiceInteraction singleChoiceInteraction = AssessmentItemFactory.createMultipleChoiceInteraction(assessmentItem, responseIdentifier, orientation, cssClass);
    singleChoiceInteraction.setShuffle(isShuffle());
    blocks.add(singleChoiceInteraction);
    List<SimpleChoice> choiceList = getChoices();
    singleChoiceInteraction.getSimpleChoices().addAll(choiceList);
    int finalMaxChoices = 0;
    if (maxChoices >= 0 && maxChoices <= choiceList.size()) {
        finalMaxChoices = maxChoices;
    }
    singleChoiceInteraction.setMaxChoices(finalMaxChoices);
    int finalMinChoices = 0;
    if (minChoices >= 0 && minChoices <= choiceList.size()) {
        finalMinChoices = minChoices;
    }
    singleChoiceInteraction.setMinChoices(finalMinChoices);
}
Also used : AssessmentItemFactory.appendSimpleChoice(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendSimpleChoice) SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) AssessmentItemFactory.appendChoiceInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendChoiceInteraction)

Example 38 with ChoiceInteraction

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

the class SingleChoiceAssessmentItemBuilder method buildItemBody.

@Override
protected void buildItemBody() {
    // remove current blocks
    List<Block> blocks = assessmentItem.getItemBody().getBlocks();
    blocks.clear();
    // add question
    getHtmlHelper().appendHtml(assessmentItem.getItemBody(), question);
    // add interaction
    ChoiceInteraction singleChoiceInteraction = AssessmentItemFactory.createSingleChoiceInteraction(assessmentItem, responseIdentifier, orientation, cssClass);
    singleChoiceInteraction.setShuffle(isShuffle());
    blocks.add(singleChoiceInteraction);
    List<SimpleChoice> choiceList = getChoices();
    singleChoiceInteraction.getSimpleChoices().addAll(choiceList);
}
Also used : AssessmentItemFactory.appendSimpleChoice(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendSimpleChoice) SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) AssessmentItemFactory.appendChoiceInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendChoiceInteraction)

Example 39 with ChoiceInteraction

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

the class AssessmentItemBuilderTest method buildAssessmentItem_singleChoice.

/**
 * Check if a bare bone single choice created with our builder make a valid assessmentItem.
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void buildAssessmentItem_singleChoice() throws IOException, URISyntaxException {
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "New answer", qtiSerializer);
    if (build.booleanValue()) {
        itemBuilder.build();
    }
    AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
    ItemValidationResult itemResult = serializeAndReload(assessmentItem);
    AssessmentItem reloadedItem = itemResult.getResolvedAssessmentItem().getItemLookup().extractIfSuccessful();
    List<Interaction> interactions = reloadedItem.getItemBody().findInteractions();
    Assert.assertNotNull(interactions);
    Assert.assertEquals(1, interactions.size());
    Assert.assertTrue(interactions.get(0) instanceof ChoiceInteraction);
}
Also used : JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) ExtendedTextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ExtendedTextInteraction) HotspotInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ItemValidationResult(uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult) Test(org.junit.Test)

Example 40 with ChoiceInteraction

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

the class MultipleChoiceAssessmentItemBuilderTest method readMultipleChoice_perAnswer_1110.

/**
 * Check if a bare bone multiple choice created with our builder make a valid assessmentItem.
 * It has 2 correct choices, two wrong, correct and wrong feedbacks. The max score is 1.0
 * but the 2 choices has each a score of 1.0.
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void readMultipleChoice_perAnswer_1110() throws IOException, URISyntaxException {
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    URL itemUrl = AssessmentItemBuilderTest.class.getResource("resources/openolat/multiple-choice-per-answer-11-1-0.xml");
    AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
    MultipleChoiceAssessmentItemBuilder itemBuilder = new MultipleChoiceAssessmentItemBuilder(assessmentItem, qtiSerializer);
    // basic check ChoiceInteraction
    AssessmentItem loadedItem = itemBuilder.getAssessmentItem();
    List<Interaction> interactions = loadedItem.getItemBody().findInteractions();
    Assert.assertNotNull(interactions);
    Assert.assertEquals(1, interactions.size());
    Assert.assertTrue(interactions.get(0) instanceof ChoiceInteraction);
    // choices
    SimpleChoice correct1 = itemBuilder.getChoice(Identifier.assumedLegal("mc80677ac3f4449ebc689cf60c230a3d"));
    Assert.assertTrue(itemBuilder.isCorrect(correct1));
    SimpleChoice correct2 = itemBuilder.getChoice(Identifier.assumedLegal("mc7e5667abeb415fa05a8c7d8fd3d6bb"));
    Assert.assertTrue(itemBuilder.isCorrect(correct2));
    SimpleChoice wrong1 = itemBuilder.getChoice(Identifier.assumedLegal("mcaacc51e0ca4027b3adb3107cda4e30"));
    Assert.assertFalse(itemBuilder.isCorrect(wrong1));
    SimpleChoice wrong2 = itemBuilder.getChoice(Identifier.assumedLegal("mc1b7b8257e2419b880936ea11bff1f1"));
    Assert.assertFalse(itemBuilder.isCorrect(wrong2));
    // score
    Double maxScore = itemBuilder.getMaxScoreBuilder().getScore();
    Assert.assertEquals(1.0, maxScore.doubleValue(), 0.0001);
    Double minScore = itemBuilder.getMinScoreBuilder().getScore();
    Assert.assertEquals(0.0, minScore.doubleValue(), 0.0001);
    // correct feedback
    ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
    Assert.assertNotNull(correctFeedback);
    Assert.assertNotNull(correctFeedback.getText());
    Assert.assertTrue(correctFeedback.getText().contains("All answers correct"));
    // incorrect
    ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
    Assert.assertNotNull(incorrectFeedback);
    Assert.assertNotNull(incorrectFeedback.getText());
    Assert.assertTrue(incorrectFeedback.getText().contains("Some choices are wrong"));
    // per answer
    Assert.assertEquals(ScoreEvaluation.perAnswer, itemBuilder.getScoreEvaluationMode());
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) URL(java.net.URL) Test(org.junit.Test)

Aggregations

ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)54 SimpleChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice)30 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)20 Test (org.junit.Test)16 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)16 QtiSerializer (uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer)16 MultipleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder)14 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)14 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)14 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)12 URL (java.net.URL)10 SingleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder)10 AssessmentItemFactory.appendChoiceInteraction (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendChoiceInteraction)8 Block (uk.ac.ed.ph.jqtiplus.node.content.basic.Block)8 EndAttemptInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction)8 HotspotInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction)8 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)8 HashMap (java.util.HashMap)6 PromptGroup (uk.ac.ed.ph.jqtiplus.group.item.interaction.PromptGroup)6 SimpleChoiceGroup (uk.ac.ed.ph.jqtiplus.group.item.interaction.choice.SimpleChoiceGroup)6