Search in sources :

Example 11 with HottextInteraction

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

the class HottextAssessmentItemBuilder method createAssessmentItem.

private static AssessmentItem createAssessmentItem(String title, String text, String hottext) {
    AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.hottext, title);
    // define correct answer
    Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
    Identifier correctResponseId = IdentifierGenerator.newAsIdentifier("ht");
    List<Identifier> correctResponseIds = new ArrayList<>();
    correctResponseIds.add(correctResponseId);
    ResponseDeclaration responseDeclaration = createHottextCorrectResponseDeclaration(assessmentItem, responseDeclarationId, correctResponseIds);
    assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
    // outcomes
    appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
    // the single choice interaction
    ItemBody itemBody = appendDefaultItemBody(assessmentItem);
    HottextInteraction hottextInteraction = appendHottextInteraction(itemBody, responseDeclarationId, 0);
    P p = new P(itemBody);
    p.getInlines().add(new TextRun(p, text));
    appendHottext(p, correctResponseId, hottext);
    hottextInteraction.getBlockStatics().add(p);
    // response processing
    ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
    assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
    return assessmentItem;
}
Also used : P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) 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) ArrayList(java.util.ArrayList) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) AssessmentItemFactory.appendHottextInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendHottextInteraction) TextRun(uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun) AssessmentItemFactory.createResponseProcessing(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing) ResponseProcessing(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createHottextCorrectResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createHottextCorrectResponseDeclaration)

Example 12 with HottextInteraction

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

the class HottextAssessmentItemBuilder method extractHottextInteraction.

private void extractHottextInteraction() {
    try (StringOutput sb = new StringOutput()) {
        List<Block> blocks = assessmentItem.getItemBody().getBlocks();
        for (Block block : blocks) {
            if (block instanceof HottextInteraction) {
                hottextInteraction = (HottextInteraction) block;
                for (BlockStatic innerBlock : hottextInteraction.getBlockStatics()) {
                    serializeJqtiObject(innerBlock, sb);
                }
                responseIdentifier = hottextInteraction.getResponseIdentifier();
                break;
            }
        }
        question = sb.toString();
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : BlockStatic(uk.ac.ed.ph.jqtiplus.node.content.basic.BlockStatic) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) StringOutput(org.olat.core.gui.render.StringOutput) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) AssessmentItemFactory.appendHottextInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendHottextInteraction) IOException(java.io.IOException)

Example 13 with HottextInteraction

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

the class HottextAssessmentItemBuilderTest method readHottextAssessmentItem.

@Test
public void readHottextAssessmentItem() throws URISyntaxException {
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    URL itemUrl = AssessmentItemBuilderTest.class.getResource("resources/openolat/hottext-per-answer-11-4-0.xml");
    AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
    HottextAssessmentItemBuilder itemBuilder = new HottextAssessmentItemBuilder(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 HottextInteraction);
    // hot texts
    Choice correct1 = itemBuilder.getChoice(Identifier.assumedLegal("htf9250a96f24bc8873c9cc54dfbaaaa"));
    Assert.assertTrue(itemBuilder.isCorrect(correct1));
    Choice correct2 = itemBuilder.getChoice(Identifier.assumedLegal("RESPONSE_3"));
    Assert.assertTrue(itemBuilder.isCorrect(correct2));
    Choice wrong1 = itemBuilder.getChoice(Identifier.assumedLegal("RESPONSE_2"));
    Assert.assertFalse(itemBuilder.isCorrect(wrong1));
    Choice wrong2 = itemBuilder.getChoice(Identifier.assumedLegal("RESPONSE_4"));
    Assert.assertFalse(itemBuilder.isCorrect(wrong2));
    // score
    Double maxScore = itemBuilder.getMaxScoreBuilder().getScore();
    Assert.assertEquals(3.0, maxScore.doubleValue(), 0.0001);
    Double minScore = itemBuilder.getMinScoreBuilder().getScore();
    Assert.assertEquals(0.0, minScore.doubleValue(), 0.0001);
    // per answer
    Assert.assertEquals(ScoreEvaluation.perAnswer, itemBuilder.getScoreEvaluationMode());
}
Also used : HottextAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder) Choice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.Choice) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) URL(java.net.URL) Test(org.junit.Test)

Example 14 with HottextInteraction

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

the class HottextAssessmentItemBuilder method extractHottextInteraction.

private void extractHottextInteraction() {
    try (StringOutput sb = new StringOutput()) {
        List<Block> blocks = assessmentItem.getItemBody().getBlocks();
        for (Block block : blocks) {
            if (block instanceof HottextInteraction) {
                hottextInteraction = (HottextInteraction) block;
                for (BlockStatic innerBlock : hottextInteraction.getBlockStatics()) {
                    serializeJqtiObject(innerBlock, sb);
                }
                responseIdentifier = hottextInteraction.getResponseIdentifier();
                break;
            }
        }
        question = sb.toString();
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : BlockStatic(uk.ac.ed.ph.jqtiplus.node.content.basic.BlockStatic) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) StringOutput(org.olat.core.gui.render.StringOutput) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) AssessmentItemFactory.appendHottextInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendHottextInteraction) IOException(java.io.IOException)

Example 15 with HottextInteraction

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

the class AssessmentObjectVelocityRenderDecorator method isSingleChoice.

/**
 * Check the maxChoices and the cardinality
 * @param interaction
 * @return
 */
public boolean isSingleChoice(Interaction interaction) {
    if (interaction instanceof ChoiceInteraction) {
        ChoiceInteraction choiceInteraction = (ChoiceInteraction) interaction;
        boolean sc = choiceInteraction.getMaxChoices() == 1;
        ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(choiceInteraction.getResponseIdentifier());
        if (responseDeclaration != null && responseDeclaration.hasCardinality(Cardinality.MULTIPLE)) {
            return false;
        }
        return sc;
    } else if (interaction instanceof HottextInteraction) {
        HottextInteraction hottextInteraction = (HottextInteraction) interaction;
        boolean sc = hottextInteraction.getMaxChoices() == 1;
        ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(hottextInteraction.getResponseIdentifier());
        if (responseDeclaration != null && responseDeclaration.hasCardinality(Cardinality.MULTIPLE)) {
            return false;
        }
        return sc;
    } else if (interaction instanceof HotspotInteraction) {
        HotspotInteraction hotspotInteraction = (HotspotInteraction) interaction;
        ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(hotspotInteraction.getResponseIdentifier());
        if (responseDeclaration != null && responseDeclaration.hasCardinality(Cardinality.SINGLE)) {
            return true;
        }
        return false;
    }
    return false;
}
Also used : HotspotInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction) InlineChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.InlineChoiceInteraction) ChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Aggregations

HottextInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction)16 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)8 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)6 URL (java.net.URL)4 Test (org.junit.Test)4 AssessmentItemFactory.appendHottextInteraction (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendHottextInteraction)4 HottextAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder)4 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)4 EndAttemptInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction)4 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)4 Choice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.Choice)4 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)4 QtiSerializer (uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer)4 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)3 HotspotInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Controller (org.olat.core.gui.control.Controller)2 BasicController (org.olat.core.gui.control.controller.BasicController)2 StringOutput (org.olat.core.gui.render.StringOutput)2