Search in sources :

Example 11 with Question

use of org.olat.ims.qti.editor.beecom.objects.Question 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 12 with Question

use of org.olat.ims.qti.editor.beecom.objects.Question in project openolat by klemens.

the class QTI12To21Converter method convertKPrim.

private AssessmentItemBuilder convertKPrim(Item item) {
    KPrimAssessmentItemBuilder itemBuilder = new KPrimAssessmentItemBuilder("Kprim", "New answer", qtiSerializer);
    convertItemBasics(item, itemBuilder);
    Question question = item.getQuestion();
    itemBuilder.setShuffle(question.isShuffle());
    List<Response> responses = question.getResponses();
    List<SimpleAssociableChoice> choices = itemBuilder.getKprimChoices();
    for (int i = 0; i < 4; i++) {
        Response response = responses.get(i);
        SimpleAssociableChoice choice = choices.get(i);
        String answer = response.getContent().renderAsHtmlForEditor();
        answer = blockedHtml(answer);
        if (StringHelper.isHtml(answer)) {
            htmlBuilder.appendHtml(choice, answer);
        } else {
            P firstChoiceText = AssessmentItemFactory.getParagraph(choice, answer);
            choice.getFlowStatics().clear();
            choice.getFlowStatics().add(firstChoiceText);
        }
        if (response.isCorrect()) {
            itemBuilder.setAssociation(choice.getIdentifier(), QTI21Constants.CORRECT_IDENTIFIER);
        } else {
            itemBuilder.setAssociation(choice.getIdentifier(), QTI21Constants.WRONG_IDENTIFIER);
        }
    }
    double score = question.getMaxValue();
    itemBuilder.setMinScore(0.0d);
    itemBuilder.setMaxScore(score);
    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) P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) 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)

Example 13 with Question

use of org.olat.ims.qti.editor.beecom.objects.Question in project openolat by klemens.

the class QTI12To21Converter method convertItemBasics.

private void convertItemBasics(Item item, AssessmentItemBuilder itemBuilder) {
    AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
    if (StringHelper.containsNonWhitespace(item.getTitle())) {
        assessmentItem.setTitle(item.getTitle());
    }
    if (StringHelper.containsNonWhitespace(item.getLabel())) {
        assessmentItem.setLabel(item.getLabel());
    }
    Question question = item.getQuestion();
    String questionText = question.getQuestion().renderAsHtmlForEditor();
    questionText = blockedHtml(questionText);
    if (StringHelper.isHtml(questionText)) {
        itemBuilder.setQuestion(questionText);
    } else {
        itemBuilder.setQuestion("<p>" + questionText + "</p>");
    }
    String hintText = question.getHintText();
    if (StringHelper.containsNonWhitespace(hintText)) {
        ModalFeedbackBuilder hint = itemBuilder.createHint();
        Translator translator = Util.createPackageTranslator(QTIModule.class, locale);
        hint.setTitle(translator.translate("render.hint"));
        hint.setText(hintText);
    }
    String solutionText = question.getSolutionText();
    if (StringHelper.containsNonWhitespace(solutionText)) {
        ModalFeedbackBuilder solution = itemBuilder.createCorrectSolutionFeedback();
        solutionText = blockedHtml(solutionText);
        solution.setText(solutionText);
    }
    String feedbackMastery = QTIEditHelper.getFeedbackMasteryText(item);
    if (StringHelper.containsNonWhitespace(feedbackMastery)) {
        ModalFeedbackBuilder feedback = itemBuilder.createCorrectFeedback();
        feedbackMastery = blockedHtml(feedbackMastery);
        feedback.setText(feedbackMastery);
    }
    String feedbackFail = QTIEditHelper.getFeedbackFailText(item);
    if (StringHelper.containsNonWhitespace(feedbackFail)) {
        ModalFeedbackBuilder feedback = itemBuilder.createIncorrectFeedback();
        feedbackFail = blockedHtml(feedbackFail);
        feedback.setText(feedbackFail);
    }
}
Also used : ModalFeedbackBuilder(org.olat.ims.qti21.model.xml.ModalFeedbackBuilder) Translator(org.olat.core.gui.translator.Translator) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) 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)

Example 14 with Question

use of org.olat.ims.qti.editor.beecom.objects.Question in project openolat by klemens.

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 15 with Question

use of org.olat.ims.qti.editor.beecom.objects.Question in project openolat by klemens.

the class CSVToQuestionConverter method processQuestion.

private void processQuestion(String[] parts) {
    if (currentItem == null)
        return;
    Question question = currentItem.getItem().getQuestion();
    Material mat = question.getQuestion();
    String content = parts[1];
    Mattext matText = new Mattext(content);
    List<QTIObject> elements = new ArrayList<QTIObject>(1);
    elements.add(matText);
    mat.setElements(elements);
}
Also used : Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) ArrayList(java.util.ArrayList) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion) Material(org.olat.ims.qti.editor.beecom.objects.Material)

Aggregations

Question (org.olat.ims.qti.editor.beecom.objects.Question)36 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)32 Response (org.olat.ims.qti.editor.beecom.objects.Response)22 FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)18 EssayQuestion (org.olat.ims.qti.editor.beecom.objects.EssayQuestion)16 ChoiceResponse (org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)14 EssayResponse (org.olat.ims.qti.editor.beecom.objects.EssayResponse)14 ArrayList (java.util.ArrayList)12 Material (org.olat.ims.qti.editor.beecom.objects.Material)12 HashMap (java.util.HashMap)10 Control (org.olat.ims.qti.editor.beecom.objects.Control)10 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)10 WindowControl (org.olat.core.gui.control.WindowControl)8 Item (org.olat.ims.qti.editor.beecom.objects.Item)8 QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)8 List (java.util.List)4 Element (org.dom4j.Element)4 Duration (org.olat.ims.qti.editor.beecom.objects.Duration)4 ItemNode (org.olat.ims.qti.editor.tree.ItemNode)4 ModalFeedbackBuilder (org.olat.ims.qti21.model.xml.ModalFeedbackBuilder)4