Search in sources :

Example 6 with ChoiceInteraction

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

the class AssessmentItemBuilderTest method buildAssessmentItem_multipleChoice.

/**
 * Check if a bare bone multiple choice created with our builder make a valid assessmentItem.
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void buildAssessmentItem_multipleChoice() throws IOException, URISyntaxException {
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    MultipleChoiceAssessmentItemBuilder itemBuilder = new MultipleChoiceAssessmentItemBuilder("Multiple 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) 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) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) ItemValidationResult(uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult) Test(org.junit.Test)

Example 7 with ChoiceInteraction

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

the class SimpleChoiceAssessmentItemBuilder 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 ChoiceInteraction) {
            break;
        } else if (block != null) {
            questionBlocks.add(block);
        }
    }
    return questionBlocks;
}
Also used : ArrayList(java.util.ArrayList) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)

Example 8 with ChoiceInteraction

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

the class QTI12To21Converter method convertMultipleChoice.

private AssessmentItemBuilder convertMultipleChoice(Item item) {
    MultipleChoiceAssessmentItemBuilder itemBuilder = new MultipleChoiceAssessmentItemBuilder("Multiple choice", "New answer", qtiSerializer);
    convertItemBasics(item, itemBuilder);
    itemBuilder.clearMapping();
    itemBuilder.clearSimpleChoices();
    ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
    Question question = item.getQuestion();
    itemBuilder.setShuffle(question.isShuffle());
    convertOrientation(question, itemBuilder);
    boolean hasNegative = false;
    List<Response> responses = question.getResponses();
    for (Response response : responses) {
        if (response.getPoints() < 0.0f) {
            hasNegative = true;
        }
    }
    boolean singleCorrect = question.isSingleCorrect();
    Map<String, Identifier> identToIdentifier = new HashMap<>();
    for (Response response : responses) {
        String responseText = response.getContent().renderAsHtmlForEditor();
        responseText = blockedHtml(responseText);
        SimpleChoice newChoice;
        if (StringHelper.isHtml(responseText)) {
            newChoice = AssessmentItemFactory.createSimpleChoice(interaction, "", itemBuilder.getQuestionType().getPrefix());
            htmlBuilder.appendHtml(newChoice, responseText);
        } else {
            newChoice = AssessmentItemFactory.createSimpleChoice(interaction, responseText, itemBuilder.getQuestionType().getPrefix());
        }
        itemBuilder.addSimpleChoice(newChoice);
        identToIdentifier.put(response.getIdent(), newChoice.getIdentifier());
        double score = response.getPoints();
        if (singleCorrect) {
            if (response.isCorrect()) {
                itemBuilder.addCorrectAnswer(newChoice.getIdentifier());
            }
            if (score > 0.0f) {
                itemBuilder.setMaxScore(score);
            }
        } else {
            if ((hasNegative && response.getPoints() >= 0.0f) || (!hasNegative && response.getPoints() > 0.0f)) {
                itemBuilder.addCorrectAnswer(newChoice.getIdentifier());
            }
            itemBuilder.setMapping(newChoice.getIdentifier(), score);
        }
    }
    convertFeedbackPerAnswers(item, itemBuilder, identToIdentifier);
    if (singleCorrect) {
        itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
    } else {
        itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
        if (question instanceof ChoiceQuestion) {
            ChoiceQuestion choice = (ChoiceQuestion) question;
            itemBuilder.setMinScore(new Double(choice.getMinValue()));
            itemBuilder.setMaxScore(new Double(choice.getMaxValue()));
        }
    }
    return itemBuilder;
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) HashMap(java.util.HashMap) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) EssayResponse(org.olat.ims.qti.editor.beecom.objects.EssayResponse) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) EssayQuestion(org.olat.ims.qti.editor.beecom.objects.EssayQuestion) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)

Example 9 with ChoiceInteraction

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

the class AssessmentItemFactory method createSingleChoiceInteraction.

public static ChoiceInteraction createSingleChoiceInteraction(AssessmentItem assessmentItem, Identifier responseDeclarationId, Orientation orientation, List<String> classAtrr) {
    ChoiceInteraction choiceInteraction = new ChoiceInteraction(assessmentItem.getItemBody());
    choiceInteraction.setMaxChoices(1);
    choiceInteraction.setShuffle(true);
    if (orientation != null) {
        choiceInteraction.setOrientation(orientation);
    }
    choiceInteraction.setResponseIdentifier(responseDeclarationId);
    if (classAtrr != null && classAtrr.size() > 0) {
        choiceInteraction.setClassAttr(classAtrr);
    }
    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 10 with ChoiceInteraction

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

the class AssessmentItemFactory method appendChoiceInteraction.

public static ChoiceInteraction appendChoiceInteraction(ItemBody itemBody, Identifier responseDeclarationId, int maxChoices, boolean shuffle) {
    ChoiceInteraction choiceInteraction = new ChoiceInteraction(itemBody);
    choiceInteraction.setMaxChoices(maxChoices);
    choiceInteraction.setShuffle(shuffle);
    choiceInteraction.setResponseIdentifier(responseDeclarationId);
    itemBody.getBlocks().add(choiceInteraction);
    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)

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