Search in sources :

Example 1 with TextEntryInteraction

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

the class AssessmentHtmlBuilderTest method filter_alt.

@Test
public void filter_alt() {
    String content = "<p>Test <textEntryInteraction responseIdentifier=\"RESPONSE_1\"/> </p>";
    AssessmentItem item = new AssessmentItem();
    ItemBody helper = new ItemBody(item);
    new AssessmentHtmlBuilder().appendHtml(helper, content);
    List<Interaction> interactions = helper.findInteractions();
    Assert.assertNotNull(interactions);
    Assert.assertEquals(1, interactions.size());
    Interaction interaction = interactions.get(0);
    Assert.assertTrue(interaction instanceof TextEntryInteraction);
    Assert.assertNotNull(interaction.getResponseIdentifier());
    Assert.assertEquals("RESPONSE_1", interaction.getResponseIdentifier().toString());
}
Also used : ItemBody(uk.ac.ed.ph.jqtiplus.node.content.ItemBody) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) Test(org.junit.Test)

Example 2 with TextEntryInteraction

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

the class AssessmentItemBuilderTest method buildAssessmentItem_gap.

@Test
public void buildAssessmentItem_gap() throws IOException, URISyntaxException {
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    FIBAssessmentItemBuilder itemBuilder = new FIBAssessmentItemBuilder("Gap text", EntryType.text, 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 TextEntryInteraction);
    TextEntryInteraction interaction = (TextEntryInteraction) interactions.get(0);
    Assert.assertNotNull(interaction.getResponseIdentifier());
    ResponseDeclaration responseDeclaration = reloadedItem.getResponseDeclaration(interaction.getResponseIdentifier());
    Assert.assertNotNull(responseDeclaration);
}
Also used : FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) 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) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) ItemValidationResult(uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult) Test(org.junit.Test)

Example 3 with TextEntryInteraction

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

the class AssessmentItemFactory method appendTextEntryInteraction.

public static TextEntryInteraction appendTextEntryInteraction(ItemBody itemBody, Identifier responseDeclarationId) {
    P paragraph = new P(itemBody);
    TextRun text = new TextRun(paragraph, "New text");
    paragraph.getInlines().add(text);
    TextEntryInteraction textInteraction = new TextEntryInteraction(paragraph);
    textInteraction.setResponseIdentifier(responseDeclarationId);
    paragraph.getInlines().add(textInteraction);
    itemBody.getBlocks().add(paragraph);
    return textInteraction;
}
Also used : P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) TextRun(uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun)

Example 4 with TextEntryInteraction

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

the class TextEntryInteractionArchive method writeInteractionData.

@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
    String stringuifiedResponses = response == null ? null : response.getStringuifiedResponse();
    if (StringHelper.containsNonWhitespace(stringuifiedResponses)) {
        TextEntryInteraction textEntryInteraction = (TextEntryInteraction) interaction;
        AbstractEntry correctAnswers = CorrectResponsesUtil.getCorrectTextResponses(item, textEntryInteraction);
        stringuifiedResponses = CorrectResponsesUtil.stripResponse(stringuifiedResponses);
        boolean correct = correctAnswers.match(stringuifiedResponses);
        if (correct) {
            dataRow.addCell(col++, stringuifiedResponses, workbook.getStyles().getCorrectStyle());
        } else {
            dataRow.addCell(col++, stringuifiedResponses, null);
        }
    } else {
        col++;
    }
    return col;
}
Also used : AbstractEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.AbstractEntry) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction)

Example 5 with TextEntryInteraction

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

the class FIBAssessmentItemBuilder method extractEntriesSettingsFromResponseDeclaration.

/**
 * We loop around the textEntryInteraction, search the responseDeclaration. responseDeclaration
 * of type string are gap text, of type float are numerical.
 */
public void extractEntriesSettingsFromResponseDeclaration() {
    DoubleAdder mappedScore = new DoubleAdder();
    AtomicInteger countAlternatives = new AtomicInteger(0);
    responseIdentifierToTextEntry = new HashMap<>();
    List<Interaction> interactions = assessmentItem.getItemBody().findInteractions();
    for (Interaction interaction : interactions) {
        if (interaction instanceof TextEntryInteraction && interaction.getResponseIdentifier() != null) {
            AbstractEntry entry = null;
            TextEntryInteraction textInteraction = (TextEntryInteraction) interaction;
            ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
            if (responseDeclaration != null) {
                if (responseDeclaration.hasBaseType(BaseType.STRING) && responseDeclaration.hasCardinality(Cardinality.SINGLE)) {
                    TextEntry textEntry = new TextEntry(textInteraction);
                    extractTextEntrySettingsFromResponseDeclaration(textEntry, responseDeclaration, countAlternatives, mappedScore);
                    String marker = "responseIdentifier=\"" + interaction.getResponseIdentifier().toString() + "\"";
                    question = question.replace(marker, marker + " openolatType=\"string\"");
                    if (StringHelper.containsNonWhitespace(textEntry.getSolution())) {
                        question = question.replace(marker, marker + " data-qti-solution=\"" + escapeForDataQtiSolution(textEntry.getSolution()) + "\"");
                    }
                    entry = textEntry;
                } else if (responseDeclaration.hasBaseType(BaseType.FLOAT) && responseDeclaration.hasCardinality(Cardinality.SINGLE)) {
                    NumericalEntry numericalEntry = new NumericalEntry(textInteraction);
                    entry = numericalEntry;
                    extractNumericalEntrySettings(assessmentItem, numericalEntry, responseDeclaration, countAlternatives, mappedScore);
                    String marker = "responseIdentifier=\"" + interaction.getResponseIdentifier().toString() + "\"";
                    question = question.replace(marker, marker + " openolatType=\"float\"");
                    if (numericalEntry.getSolution() != null) {
                        question = question.replace(marker, marker + " data-qti-solution=\"" + Double.toString(numericalEntry.getSolution()) + "\"");
                    }
                }
            }
            if (entry != null) {
                responseIdentifierToTextEntry.put(interaction.getResponseIdentifier().toString(), entry);
            }
        }
    }
    boolean hasMapping = Math.abs(mappedScore.doubleValue() - (-1.0 * countAlternatives.get())) > 0.0001;
    scoreEvaluation = hasMapping ? ScoreEvaluation.perAnswer : ScoreEvaluation.allCorrectAnswers;
}
Also used : DoubleAdder(java.util.concurrent.atomic.DoubleAdder) AssessmentItemFactory.appendTextEntryInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendTextEntryInteraction) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssessmentItemFactory.appendTextEntryInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendTextEntryInteraction) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) AssessmentItemFactory.createNumericalEntryResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createNumericalEntryResponseDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createTextEntryResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createTextEntryResponseDeclaration)

Aggregations

TextEntryInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction)16 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)10 ArrayList (java.util.ArrayList)6 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)6 Test (org.junit.Test)4 AssessmentItemFactory.appendTextEntryInteraction (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendTextEntryInteraction)4 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)4 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)4 HotspotInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction)4 MatchInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction)4 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DoubleAdder (java.util.concurrent.atomic.DoubleAdder)2 Component (org.olat.core.gui.components.Component)2 StatisticsComponent (org.olat.core.gui.components.chart.StatisticsComponent)2 Controller (org.olat.core.gui.control.Controller)2 BasicController (org.olat.core.gui.control.controller.BasicController)2 AbstractTextEntryInteractionStatistics (org.olat.ims.qti21.model.statistics.AbstractTextEntryInteractionStatistics)2 NumericalInputInteractionStatistics (org.olat.ims.qti21.model.statistics.NumericalInputInteractionStatistics)2 TextEntryInteractionStatistics (org.olat.ims.qti21.model.statistics.TextEntryInteractionStatistics)2