Search in sources :

Example 6 with SingleChoiceAssessmentItemBuilder

use of org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder in project OpenOLAT by OpenOLAT.

the class CSVToAssessmentItemConverter method processType.

private void processType(String[] parts) {
    if (currentItem != null) {
        build();
        items.add(currentItem);
        currentItem = null;
    }
    if (parts.length > 1) {
        String type = parts[1].toLowerCase();
        AssessmentItemBuilder itemBuilder;
        switch(type) {
            case "fib":
                {
                    FIBAssessmentItemBuilder fibItemBuilder = new FIBAssessmentItemBuilder("Gap text", EntryType.text, qtiSerializer);
                    itemBuilder = initFIBAssessmentItemBuilder(fibItemBuilder);
                    break;
                }
            case "mc":
                {
                    MultipleChoiceAssessmentItemBuilder mcItemBuilder = new MultipleChoiceAssessmentItemBuilder("Multiple choice", "New answer", qtiSerializer);
                    itemBuilder = initMultipleChoiceAssessmentItemBuilder(mcItemBuilder);
                    break;
                }
            case "sc":
                {
                    SingleChoiceAssessmentItemBuilder scItemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "New answer", qtiSerializer);
                    itemBuilder = initSingleChoiceAssessmentItemBuilder(scItemBuilder);
                    break;
                }
            case "kprim":
                {
                    kprimPosition = 0;
                    itemBuilder = new KPrimAssessmentItemBuilder("Kprim", "New answer", qtiSerializer);
                    break;
                }
            case "essay":
                {
                    itemBuilder = new EssayAssessmentItemBuilder("Essay", qtiSerializer);
                    break;
                }
            case "matrix":
                {
                    MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_MATRIX, qtiSerializer);
                    itemBuilder = initMatchAssessmentItemBuilder(matchBuilder);
                    break;
                }
            case "drag&drop":
                {
                    MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_DRAG_AND_DROP, qtiSerializer);
                    itemBuilder = initMatchAssessmentItemBuilder(matchBuilder);
                    break;
                }
            case "truefalse":
                {
                    Translator trans = Util.createPackageTranslator(AssessmentItemEditorController.class, locale);
                    MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_TRUE_FALSE, trans.translate("match.unanswered"), trans.translate("match.true"), trans.translate("match.false"), qtiSerializer);
                    itemBuilder = initMatchAssessmentItemBuilderForTrueFalse(matchBuilder);
                    break;
                }
            default:
                {
                    itemBuilder = null;
                }
        }
        if (itemBuilder != null) {
            currentItem = new AssessmentItemAndMetadata(itemBuilder);
        } else {
            log.warn("Question type not supported: " + type);
            currentItem = null;
        }
    }
}
Also used : FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) Translator(org.olat.core.gui.translator.Translator) AssessmentItemEditorController(org.olat.ims.qti21.ui.editor.AssessmentItemEditorController) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) SimpleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SimpleChoiceAssessmentItemBuilder) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) MatchAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) AssessmentItemBuilder(org.olat.ims.qti21.model.xml.AssessmentItemBuilder) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) MatchAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder)

Example 7 with SingleChoiceAssessmentItemBuilder

use of org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder in project openolat by klemens.

the class CSVToAssessmentItemConverter method processType.

private void processType(String[] parts) {
    if (currentItem != null) {
        build();
        items.add(currentItem);
        currentItem = null;
    }
    if (parts.length > 1) {
        String type = parts[1].toLowerCase();
        AssessmentItemBuilder itemBuilder;
        switch(type) {
            case "fib":
                {
                    FIBAssessmentItemBuilder fibItemBuilder = new FIBAssessmentItemBuilder("Gap text", EntryType.text, qtiSerializer);
                    itemBuilder = initFIBAssessmentItemBuilder(fibItemBuilder);
                    break;
                }
            case "mc":
                {
                    MultipleChoiceAssessmentItemBuilder mcItemBuilder = new MultipleChoiceAssessmentItemBuilder("Multiple choice", "New answer", qtiSerializer);
                    itemBuilder = initMultipleChoiceAssessmentItemBuilder(mcItemBuilder);
                    break;
                }
            case "sc":
                {
                    SingleChoiceAssessmentItemBuilder scItemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "New answer", qtiSerializer);
                    itemBuilder = initSingleChoiceAssessmentItemBuilder(scItemBuilder);
                    break;
                }
            case "kprim":
                {
                    kprimPosition = 0;
                    itemBuilder = new KPrimAssessmentItemBuilder("Kprim", "New answer", qtiSerializer);
                    break;
                }
            case "essay":
                {
                    itemBuilder = new EssayAssessmentItemBuilder("Essay", qtiSerializer);
                    break;
                }
            case "matrix":
                {
                    MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_MATRIX, qtiSerializer);
                    itemBuilder = initMatchAssessmentItemBuilder(matchBuilder);
                    break;
                }
            case "drag&drop":
                {
                    MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_DRAG_AND_DROP, qtiSerializer);
                    itemBuilder = initMatchAssessmentItemBuilder(matchBuilder);
                    break;
                }
            case "truefalse":
                {
                    Translator trans = Util.createPackageTranslator(AssessmentItemEditorController.class, locale);
                    MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_TRUE_FALSE, trans.translate("match.unanswered"), trans.translate("match.true"), trans.translate("match.false"), qtiSerializer);
                    itemBuilder = initMatchAssessmentItemBuilderForTrueFalse(matchBuilder);
                    break;
                }
            default:
                {
                    itemBuilder = null;
                }
        }
        if (itemBuilder != null) {
            currentItem = new AssessmentItemAndMetadata(itemBuilder);
        } else {
            log.warn("Question type not supported: " + type);
            currentItem = null;
        }
    }
}
Also used : FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) Translator(org.olat.core.gui.translator.Translator) AssessmentItemEditorController(org.olat.ims.qti21.ui.editor.AssessmentItemEditorController) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) SimpleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SimpleChoiceAssessmentItemBuilder) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) MatchAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) AssessmentItemBuilder(org.olat.ims.qti21.model.xml.AssessmentItemBuilder) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) MatchAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder)

Example 8 with SingleChoiceAssessmentItemBuilder

use of org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder in project openolat by klemens.

the class SingleChoiceAssessmentItemBuilderTest method createSingleAssessmentItem_allCorrectAnswers.

@Test
public void createSingleAssessmentItem_allCorrectAnswers() throws IOException {
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "Single choice", qtiSerializer);
    itemBuilder.setQuestion("<p>Hello</p>");
    ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
    SimpleChoice choice1 = AssessmentItemFactory.createSimpleChoice(interaction, "One", "sc");
    SimpleChoice choice2 = AssessmentItemFactory.createSimpleChoice(interaction, "Two", "sc");
    SimpleChoice choice3 = AssessmentItemFactory.createSimpleChoice(interaction, "Three", "sc");
    List<SimpleChoice> choiceList = new ArrayList<>();
    choiceList.add(choice1);
    choiceList.add(choice2);
    choiceList.add(choice3);
    itemBuilder.setSimpleChoices(choiceList);
    itemBuilder.setCorrectAnswer(choice2.getIdentifier());
    itemBuilder.setMaxScore(3.0d);
    itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
    itemBuilder.build();
    File itemFile = new File(WebappHelper.getTmpDir(), "scAssessmentItem" + UUID.randomUUID() + ".xml");
    try (FileOutputStream out = new FileOutputStream(itemFile)) {
        qtiSerializer.serializeJqtiObject(itemBuilder.getAssessmentItem(), out);
    } catch (Exception e) {
        log.error("", e);
    }
    {
        // correct answers
        Map<Identifier, ResponseData> responseMap = new HashMap<>();
        Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
        responseMap.put(responseIdentifier, new StringResponseData(choice2.getIdentifier().toString()));
        ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
        Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
        Assert.assertEquals(new FloatValue(3.0d), score);
    }
    {
        // wrong answer
        Map<Identifier, ResponseData> responseMap = new HashMap<>();
        Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
        responseMap.put(responseIdentifier, new StringResponseData(choice3.getIdentifier().toString()));
        ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
        Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
        Assert.assertEquals(new FloatValue(0.0d), score);
    }
    FileUtils.deleteDirsAndFiles(itemFile.toPath());
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) ArrayList(java.util.ArrayList) ItemSessionController(uk.ac.ed.ph.jqtiplus.running.ItemSessionController) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) StringResponseData(uk.ac.ed.ph.jqtiplus.types.StringResponseData) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) FileOutputStream(java.io.FileOutputStream) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 9 with SingleChoiceAssessmentItemBuilder

use of org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder in project openolat by klemens.

the class AssessmentItemBuilderTest method findFeedbacks.

@Test
public void findFeedbacks() throws URISyntaxException {
    URL itemUrl = AssessmentItemBuilderTest.class.getResource("assessment-item-single-choice-feedbacks.xml");
    AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder(assessmentItem, qtiSerializer);
    if (build.booleanValue()) {
        itemBuilder.build();
    }
    ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
    Assert.assertNotNull(correctFeedback);
    Assert.assertTrue(correctFeedback.isCorrectRule());
    ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
    Assert.assertNotNull(incorrectFeedback);
    Assert.assertTrue(incorrectFeedback.isIncorrectRule());
}
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) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) URL(java.net.URL) Test(org.junit.Test)

Example 10 with SingleChoiceAssessmentItemBuilder

use of org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder in project openolat by klemens.

the class OnyxToAssessmentItemBuilderTest method extractsingleChoiceWithFeedbacks.

@Test
public void extractsingleChoiceWithFeedbacks() throws URISyntaxException {
    URL itemUrl = OnyxToAssessmentItemBuilderTest.class.getResource("resources/onyx/single-choice-1-with-feedbacks_5-11.xml");
    AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder(assessmentItem, qtiSerializer);
    // correct answer
    List<SimpleChoice> choices = itemBuilder.getChoices();
    Assert.assertNotNull(choices);
    SimpleChoice choice = choices.get(3);
    Assert.assertTrue(itemBuilder.isCorrect(choice));
    // scoring
    Assert.assertEquals(ScoreEvaluation.allCorrectAnswers, itemBuilder.getScoreEvaluationMode());
    ScoreBuilder maxScoreBuilder = itemBuilder.getMaxScoreBuilder();
    Assert.assertEquals(4.0d, maxScoreBuilder.getScore(), 0.00001d);
    // check standard feedback
    ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
    Assert.assertNotNull(correctFeedback);
    Assert.assertTrue(correctFeedback.isCorrectRule());
    Assert.assertEquals("<p>Richtig Text</p>", correctFeedback.getText());
    ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
    Assert.assertNotNull(incorrectFeedback);
    Assert.assertTrue(incorrectFeedback.isIncorrectRule());
    Assert.assertEquals("<p>Falsch Text</p>", incorrectFeedback.getText());
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) URL(java.net.URL) Test(org.junit.Test)

Aggregations

SingleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder)24 Test (org.junit.Test)12 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)12 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)12 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)12 QtiSerializer (uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer)12 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)10 SimpleChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice)10 URL (java.net.URL)8 MultipleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder)8 EssayAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder)6 FIBAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder)6 KPrimAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder)6 MatchAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder)6 File (java.io.File)4 HashMap (java.util.HashMap)4 DrawingAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.DrawingAssessmentItemBuilder)4 HotspotAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.HotspotAssessmentItemBuilder)4 HottextAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder)4 UploadAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.UploadAssessmentItemBuilder)4