Search in sources :

Example 81 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.

the class GapMatchInteractionArchive method writeInteractionData.

@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
    List<Gap> gaps = getGaps(interaction);
    if (gaps.size() > 0) {
        GapMatchInteraction gapMatchInteraction = (GapMatchInteraction) interaction;
        Set<String> correctAnswers = CorrectResponsesUtil.getCorrectDirectPairResponses(item, interaction, false);
        String stringuifiedResponse = response == null ? null : response.getStringuifiedResponse();
        List<String> responses = CorrectResponsesUtil.parseResponses(stringuifiedResponse);
        for (Gap gap : gaps) {
            String gapIdentifier = gap.getIdentifier().toString();
            String gapResponse = null;
            for (String r : responses) {
                if (r.endsWith(gapIdentifier)) {
                    gapResponse = r;
                }
            }
            if (gapResponse != null) {
                String[] gapResponsePair = gapResponse.split(" ");
                if (gapResponsePair.length > 1) {
                    String gapResponseAssociation = gapResponsePair[0];
                    Identifier gapResponseIdentifier = Identifier.assumedLegal(gapResponseAssociation);
                    GapChoice choice = gapMatchInteraction.getGapChoice(gapResponseIdentifier);
                    String value = null;
                    if (choice != null) {
                        value = getTextContent(choice);
                    }
                    boolean correct = correctAnswers.contains(gapResponse);
                    if (correct) {
                        dataRow.addCell(col++, value, workbook.getStyles().getCorrectStyle());
                    } else {
                        dataRow.addCell(col++, value);
                    }
                } else {
                    col++;
                }
            } else {
                col++;
            }
        }
    } else {
        col++;
    }
    return col;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) GapMatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GapMatchInteraction) Gap(uk.ac.ed.ph.jqtiplus.node.item.interaction.content.Gap) GapChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.GapChoice)

Example 82 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.

the class GraphicOrderInteractionArchive method writeInteractionData.

@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
    GraphicOrderInteraction orderInteraction = (GraphicOrderInteraction) interaction;
    List<HotspotChoice> choices = orderInteraction.getHotspotChoices();
    if (choices.size() > 0) {
        String stringuifiedResponse = response == null ? null : response.getStringuifiedResponse();
        List<String> responses = CorrectResponsesUtil.parseResponses(stringuifiedResponse);
        List<Identifier> correctAnswers = CorrectResponsesUtil.getCorrectOrderedIdentifierResponses(item, interaction);
        for (int i = 0; i < choices.size(); i++) {
            String currentResponse = null;
            if (responses.size() > i) {
                currentResponse = responses.get(i);
            }
            String correctAnswer = null;
            if (correctAnswers.size() > i) {
                correctAnswer = correctAnswers.get(i).toString();
            }
            if (correctAnswer != null && correctAnswer.equals(currentResponse)) {
                dataRow.addCell(col++, currentResponse, workbook.getStyles().getCorrectStyle());
            } else {
                dataRow.addCell(col++, currentResponse, null);
            }
        }
    } else {
        col++;
    }
    return col;
}
Also used : GraphicOrderInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.GraphicOrderInteraction) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) HotspotChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.graphic.HotspotChoice)

Example 83 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.

the class InlineChoiceInteractionArchive method writeInteractionData.

@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
    InlineChoiceInteraction choiceInteraction = (InlineChoiceInteraction) interaction;
    List<Identifier> correctAnswers = CorrectResponsesUtil.getCorrectIdentifierResponses(item, interaction);
    String stringuifiedResponse = response == null ? null : response.getStringuifiedResponse();
    if (StringHelper.containsNonWhitespace(stringuifiedResponse)) {
        String inlineResponse = CorrectResponsesUtil.stripResponse(stringuifiedResponse);
        Identifier responseIdentifier = Identifier.assumedLegal(inlineResponse);
        boolean correct = false;
        for (Identifier correctAnswer : correctAnswers) {
            if (responseIdentifier.equals(correctAnswer)) {
                correct = true;
                break;
            }
        }
        InlineChoice selectedChoice = choiceInteraction.getInlineChoice(responseIdentifier);
        if (selectedChoice != null) {
            String value = getTextContent(selectedChoice);
            if (correct) {
                dataRow.addCell(col++, value, workbook.getStyles().getCorrectStyle());
            } else {
                dataRow.addCell(col++, value);
            }
        } else {
            col++;
        }
    } else {
        col++;
    }
    return col;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) InlineChoiceInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.InlineChoiceInteraction) InlineChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.InlineChoice)

Example 84 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.

the class OrderInteractionArchive method writeInteractionData.

@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
    OrderInteraction orderInteraction = (OrderInteraction) interaction;
    List<SimpleChoice> choices = orderInteraction.getSimpleChoices();
    if (choices.size() > 0) {
        String stringuifiedResponse = response == null ? null : response.getStringuifiedResponse();
        List<String> responses = CorrectResponsesUtil.parseResponses(stringuifiedResponse);
        List<Identifier> correctAnswers = CorrectResponsesUtil.getCorrectOrderedIdentifierResponses(item, interaction);
        for (int i = 0; i < choices.size(); i++) {
            String currentResponse = null;
            String currentResponseText = null;
            if (responses.size() > i) {
                currentResponse = currentResponseText = responses.get(i);
                SimpleChoice selectedChoice = orderInteraction.getSimpleChoice(Identifier.assumedLegal(currentResponse));
                if (selectedChoice != null) {
                    currentResponseText = getContent(selectedChoice);
                }
            }
            String correctAnswer = null;
            if (correctAnswers.size() > i) {
                correctAnswer = correctAnswers.get(i).toString();
            }
            if (correctAnswer != null && correctAnswer.equals(currentResponse)) {
                dataRow.addCell(col++, currentResponseText, workbook.getStyles().getCorrectStyle());
            } else {
                dataRow.addCell(col++, currentResponseText, null);
            }
        }
    } else {
        col++;
    }
    return col;
}
Also used : SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) OrderInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.OrderInteraction)

Example 85 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.

the class HottextAssessmentItemBuilderTest method createHottextAssessmentItem_allCorrectAnswers.

/**
 * A basic hottextInteraction with three choices. If all answers
 * are correct, the SCORE is 3.0.
 *
 * @throws IOException
 */
@Test
public void createHottextAssessmentItem_allCorrectAnswers() throws IOException {
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    HottextAssessmentItemBuilder itemBuilder = new HottextAssessmentItemBuilder("Hot texts", "This is a hot ", "text", qtiSerializer);
    itemBuilder.setQuestion("<p>This is <hottext identifier=\"RESPONSE_HOT_1\">hot</hottext>, <hottext identifier=\"RESPONSE_HOT_2\">cold</hottext> or <hottext identifier=\"RESPONSE_HOT_3\">freezing</hottext></p>");
    itemBuilder.addCorrectAnswer(Identifier.parseString("RESPONSE_HOT_2"));
    itemBuilder.addCorrectAnswer(Identifier.parseString("RESPONSE_HOT_3"));
    itemBuilder.setMaxScore(3.0d);
    itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
    itemBuilder.build();
    File itemFile = new File(WebappHelper.getTmpDir(), "hottextAssessmentItem" + 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("RESPONSE_HOT_2", "RESPONSE_HOT_3"));
        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("RESPONSE_HOT_1"));
        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 : HottextAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder) 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) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)208 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)62 ArrayList (java.util.ArrayList)53 HashMap (java.util.HashMap)52 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)46 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)42 Value (uk.ac.ed.ph.jqtiplus.value.Value)42 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)40 Map (java.util.Map)32 SimpleAssociableChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)24 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)24 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)24 ItemBody (uk.ac.ed.ph.jqtiplus.node.content.ItemBody)22 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)22 ResponseProcessing (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing)22 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)22 List (java.util.List)20 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)20 SimpleChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice)20 RecordValue (uk.ac.ed.ph.jqtiplus.value.RecordValue)20