Search in sources :

Example 6 with TextEntry

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

the class QTI12To21Converter method convertFIB.

private AssessmentItemBuilder convertFIB(Item item) {
    FIBAssessmentItemBuilder itemBuilder = new FIBAssessmentItemBuilder("Gap text", EntryType.text, qtiSerializer);
    itemBuilder.setQuestion("");
    itemBuilder.clearTextEntries();
    convertItemBasics(item, itemBuilder);
    Question question = item.getQuestion();
    boolean singleCorrect = question.isSingleCorrect();
    if (singleCorrect) {
        itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
    } else {
        itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
    }
    itemBuilder.getMinScoreBuilder().setScore(new Double(question.getMinValue()));
    itemBuilder.getMaxScoreBuilder().setScore(new Double(question.getMaxValue()));
    List<Response> responses = question.getResponses();
    StringBuilder sb = new StringBuilder();
    for (Response response : responses) {
        if (response instanceof FIBResponse) {
            FIBResponse gap = (FIBResponse) response;
            if (FIBResponse.TYPE_BLANK.equals(gap.getType())) {
                String responseId = itemBuilder.generateResponseIdentifier();
                StringBuilder entryString = new StringBuilder();
                entryString.append(" <textentryinteraction responseidentifier=\"").append(responseId).append("\"");
                TextEntry entry = itemBuilder.createTextEntry(responseId);
                entry.setCaseSensitive("Yes".equals(gap.getCaseSensitive()));
                if (gap.getMaxLength() > 0) {
                    entry.setExpectedLength(gap.getMaxLength());
                    entryString.append(" expectedlength=\"").append(gap.getMaxLength()).append("\"");
                } else if (gap.getSize() > 0) {
                    entry.setExpectedLength(gap.getSize());
                    entryString.append(" expectedlength=\"").append(gap.getSize()).append("\"");
                }
                parseAlternatives(gap.getCorrectBlank(), gap.getPoints(), entry);
                entryString.append("></textentryinteraction>");
                sb.append(entryString);
            } else if (FIBResponse.TYPE_CONTENT.equals(gap.getType())) {
                Material text = gap.getContent();
                String htmltext = text.renderAsHtmlForEditor();
                htmltext = blockedHtml(htmltext);
                sb.append(htmltext);
            }
        }
    }
    String fib = "<div>" + sb.toString() + "</div>";
    itemBuilder.setQuestion(fib);
    return itemBuilder;
}
Also used : 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) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) 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) Material(org.olat.ims.qti.editor.beecom.objects.Material) TextEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry)

Example 7 with TextEntry

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

the class CSVToAssessmentItemConverter method processChoice_fib.

private void processChoice_fib(String[] parts, FIBAssessmentItemBuilder fibBuilder) {
    String firstPart = parts[0].toLowerCase();
    if ("text".equals(firstPart) || "texte".equals(firstPart)) {
        String text = parts[1];
        if (StringHelper.containsNonWhitespace(fibBuilder.getQuestion())) {
            fibBuilder.setQuestion(fibBuilder.getQuestion() + " " + text);
        } else {
            fibBuilder.setQuestion(text);
        }
    } else {
        double score = parseFloat(parts[0], 1.0f);
        String correctBlank = parts[1];
        String responseId = fibBuilder.generateResponseIdentifier();
        TextEntry textEntry = fibBuilder.createTextEntry(responseId);
        parseAlternatives(correctBlank, score, textEntry);
        if (parts.length > 2) {
            String sizes = parts[2];
            String[] sizeArr = sizes.split(",");
            if (sizeArr.length >= 2) {
                int size = Integer.parseInt(sizeArr[0]);
                textEntry.setExpectedLength(size);
            }
        }
        String entry = " <textEntryInteraction responseIdentifier=\"" + responseId + "\"/>";
        fibBuilder.setQuestion(fibBuilder.getQuestion() + " " + entry);
    }
}
Also used : TextEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry)

Example 8 with TextEntry

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

the class FIBEditorController method createEntry.

private AbstractEntry createEntry(String responseIdentifier, String selectedText, String type, boolean newEntry) {
    AbstractEntry interaction = null;
    if ("string".equalsIgnoreCase(type)) {
        TextEntry textInteraction = itemBuilder.createTextEntry(responseIdentifier);
        if (StringHelper.containsNonWhitespace(selectedText)) {
            String[] alternatives = selectedText.split(",");
            for (String alternative : alternatives) {
                if (StringHelper.containsNonWhitespace(alternative)) {
                    alternative = alternative.trim();
                    if (textInteraction.getSolution() == null) {
                        textInteraction.setSolution(alternative);
                    } else {
                        textInteraction.addAlternative(alternative, textInteraction.getScore());
                    }
                }
            }
            if (alternatives.length > 0) {
                String solution = alternatives[0];
                if (newEntry && "gap".equals(solution)) {
                    solution = "";
                }
                textInteraction.setSolution(solution);
            }
        }
        interaction = textInteraction;
    } else if ("float".equalsIgnoreCase(type)) {
        NumericalEntry numericalInteraction = itemBuilder.createNumericalEntry(responseIdentifier);
        if (newEntry && "gap".equals(selectedText)) {
        // skip it, it's a placeholder
        } else if (StringHelper.containsNonWhitespace(selectedText)) {
            try {
                Double val = Double.parseDouble(selectedText.trim());
                numericalInteraction.setSolution(val);
            } catch (NumberFormatException e) {
            // 
            }
        }
        interaction = numericalInteraction;
    }
    return interaction;
}
Also used : AbstractEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.AbstractEntry) TextEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry) NumericalEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry)

Example 9 with TextEntry

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

the class FIBEditorController method doGapEntry.

private void doGapEntry(UserRequest ureq, String responseIdentifier, String selectedText, String emptySolution, String type, boolean newEntry) {
    if (textEntrySettingsCtrl != null || numericalEntrySettingsCtrl != null)
        return;
    AbstractEntry interaction = itemBuilder.getEntry(responseIdentifier);
    if (interaction == null) {
        interaction = createEntry(responseIdentifier, selectedText, type, newEntry);
    } else if (StringHelper.containsNonWhitespace(selectedText)) {
        updateSolution(interaction, selectedText, emptySolution);
    }
    if (interaction instanceof TextEntry) {
        textEntrySettingsCtrl = new FIBTextEntrySettingsController(ureq, getWindowControl(), (TextEntry) interaction, restrictedEdit, readOnly);
        listenTo(textEntrySettingsCtrl);
        cmc = new CloseableModalController(getWindowControl(), translate("close"), textEntrySettingsCtrl.getInitialComponent(), true, translate("title.add"));
        cmc.activate();
        listenTo(cmc);
    } else if (interaction instanceof NumericalEntry) {
        numericalEntrySettingsCtrl = new FIBNumericalEntrySettingsController(ureq, getWindowControl(), (NumericalEntry) interaction, restrictedEdit, readOnly);
        listenTo(numericalEntrySettingsCtrl);
        cmc = new CloseableModalController(getWindowControl(), translate("close"), numericalEntrySettingsCtrl.getInitialComponent(), true, translate("title.add"));
        cmc.activate();
        listenTo(cmc);
    }
}
Also used : AbstractEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.AbstractEntry) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) TextEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry) NumericalEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry)

Example 10 with TextEntry

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

the class FIBEditorController method createEntry.

private AbstractEntry createEntry(String responseIdentifier, String selectedText, String type, boolean newEntry) {
    AbstractEntry interaction = null;
    if ("string".equalsIgnoreCase(type)) {
        TextEntry textInteraction = itemBuilder.createTextEntry(responseIdentifier);
        if (StringHelper.containsNonWhitespace(selectedText)) {
            String[] alternatives = selectedText.split(",");
            for (String alternative : alternatives) {
                if (StringHelper.containsNonWhitespace(alternative)) {
                    alternative = alternative.trim();
                    if (textInteraction.getSolution() == null) {
                        textInteraction.setSolution(alternative);
                    } else {
                        textInteraction.addAlternative(alternative, textInteraction.getScore());
                    }
                }
            }
            if (alternatives.length > 0) {
                String solution = alternatives[0];
                if (newEntry && "gap".equals(solution)) {
                    solution = "";
                }
                textInteraction.setSolution(solution);
            }
        }
        interaction = textInteraction;
    } else if ("float".equalsIgnoreCase(type)) {
        NumericalEntry numericalInteraction = itemBuilder.createNumericalEntry(responseIdentifier);
        if (newEntry && "gap".equals(selectedText)) {
        // skip it, it's a placeholder
        } else if (StringHelper.containsNonWhitespace(selectedText)) {
            try {
                Double val = Double.parseDouble(selectedText.trim());
                numericalInteraction.setSolution(val);
            } catch (NumberFormatException e) {
            // 
            }
        }
        interaction = numericalInteraction;
    }
    return interaction;
}
Also used : AbstractEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.AbstractEntry) TextEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry) NumericalEntry(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry)

Aggregations

TextEntry (org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry)10 NumericalEntry (org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.NumericalEntry)6 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 DoubleAdder (java.util.concurrent.atomic.DoubleAdder)4 AssessmentItemFactory.createNumericalEntryResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createNumericalEntryResponseDeclaration)4 AssessmentItemFactory.createTextEntryResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createTextEntryResponseDeclaration)4 AbstractEntry (org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.AbstractEntry)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BarSeries (org.olat.core.gui.components.chart.BarSeries)2 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)2 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)2 ChoiceResponse (org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)2 EssayQuestion (org.olat.ims.qti.editor.beecom.objects.EssayQuestion)2 EssayResponse (org.olat.ims.qti.editor.beecom.objects.EssayResponse)2 FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)2 Material (org.olat.ims.qti.editor.beecom.objects.Material)2 Question (org.olat.ims.qti.editor.beecom.objects.Question)2