Search in sources :

Example 16 with AssessmentItemBuilder

use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder 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 17 with AssessmentItemBuilder

use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder in project openolat by klemens.

the class QTI12To21Converter method convert.

private void convert(Section section, TestPart testPart) throws URISyntaxException {
    AssessmentSection assessmentSection = AssessmentTestFactory.appendAssessmentSection("Section", testPart);
    assessmentSection.setTitle(section.getTitle());
    convertDuration(section.getDuration(), assessmentSection);
    RubricBlock rubricBlock = assessmentSection.getRubricBlocks().get(0);
    rubricBlock.getBlocks().clear();
    String objectives = section.getObjectives();
    htmlBuilder.appendHtml(rubricBlock, blockedHtml(objectives));
    boolean shuffle = SelectionOrdering.RANDOM.equals(section.getSelection_ordering().getOrderType());
    assessmentSection.getOrdering().setShuffle(shuffle);
    int selectionNum = section.getSelection_ordering().getSelectionNumber();
    if (selectionNum > 0) {
        Selection selection = new Selection(assessmentSection);
        selection.setSelect(selectionNum);
        assessmentSection.setSelection(selection);
    }
    List<Item> items = section.getItems();
    for (Item item : items) {
        AssessmentItemBuilder itemBuilder = null;
        if (item != null && item.getQuestion() != null) {
            int questionType = item.getQuestion().getType();
            switch(questionType) {
                case Question.TYPE_SC:
                    itemBuilder = convertSingleChoice(item);
                    break;
                case Question.TYPE_MC:
                    itemBuilder = convertMultipleChoice(item);
                    break;
                case Question.TYPE_KPRIM:
                    itemBuilder = convertKPrim(item);
                    break;
                case Question.TYPE_FIB:
                    itemBuilder = convertFIB(item);
                    break;
                case Question.TYPE_ESSAY:
                    itemBuilder = convertEssay(item);
                    break;
            }
        } else {
            errors.add(item.getTitle());
            log.error("Item without question: " + item);
        }
        if (itemBuilder != null) {
            itemBuilder.build();
            AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
            AssessmentItemRef itemRef = new AssessmentItemRef(assessmentSection);
            String itemId = IdentifierGenerator.newAsString(itemBuilder.getQuestionType().getPrefix());
            itemRef.setIdentifier(Identifier.parseString(itemId));
            convertItemBasics(item, itemRef);
            File itemFile = new File(unzippedDirRoot, itemId + ".xml");
            itemRef.setHref(new URI(itemFile.getName()));
            assessmentSection.getSectionParts().add(itemRef);
            persistAssessmentObject(itemFile, assessmentItem);
            appendResourceAndMetadata(item, itemBuilder, itemFile);
            // collect max score
            Double maxScore = QtiNodesExtractor.extractMaxScore(assessmentItem);
            if (maxScore != null && maxScore.doubleValue() > 0.0d) {
                atomicMaxScore.add(maxScore.doubleValue());
            }
        }
    }
}
Also used : Selection(uk.ac.ed.ph.jqtiplus.node.test.Selection) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) AssessmentItemBuilder(org.olat.ims.qti21.model.xml.AssessmentItemBuilder) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) SimpleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SimpleChoiceAssessmentItemBuilder) FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) URI(java.net.URI) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) RubricBlock(uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock) File(java.io.File)

Example 18 with AssessmentItemBuilder

use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder 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 19 with AssessmentItemBuilder

use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder 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 20 with AssessmentItemBuilder

use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder in project openolat by klemens.

the class QTI12To21Converter method convertItem.

/**
 * @param item
 * @return The name of the assesssmentItem file
 */
private boolean convertItem(QuestionItemImpl convertedQuestion, Item item) {
    QItemTypeDAO qItemTypeDao = CoreSpringFactory.getImpl(QItemTypeDAO.class);
    AssessmentItemBuilder itemBuilder = null;
    int questionType = item.getQuestion().getType();
    switch(questionType) {
        case Question.TYPE_SC:
            itemBuilder = convertSingleChoice(item);
            convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.SC.name()));
            break;
        case Question.TYPE_MC:
            itemBuilder = convertMultipleChoice(item);
            convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.MC.name()));
            break;
        case Question.TYPE_KPRIM:
            itemBuilder = convertKPrim(item);
            convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.KPRIM.name()));
            break;
        case Question.TYPE_FIB:
            itemBuilder = convertFIB(item);
            convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.FIB.name()));
            break;
        case Question.TYPE_ESSAY:
            itemBuilder = convertEssay(item);
            convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.ESSAY.name()));
            break;
    }
    if (itemBuilder != null) {
        itemBuilder.build();
        AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
        String itemId = IdentifierGenerator.newAsString(itemBuilder.getQuestionType().getPrefix());
        File itemFile = new File(unzippedDirRoot, itemId + ".xml");
        persistAssessmentObject(itemFile, assessmentItem);
        appendResourceAndMetadata(item, itemBuilder, itemFile);
        convertedQuestion.setRootFilename(itemFile.getName());
        return true;
    }
    return false;
}
Also used : QItemTypeDAO(org.olat.modules.qpool.manager.QItemTypeDAO) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) EssayAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder) AssessmentItemBuilder(org.olat.ims.qti21.model.xml.AssessmentItemBuilder) KPrimAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder) MultipleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder) SimpleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SimpleChoiceAssessmentItemBuilder) FIBAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder) SingleChoiceAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder) File(java.io.File)

Aggregations

EssayAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.EssayAssessmentItemBuilder)28 FIBAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder)28 KPrimAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder)28 MultipleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.MultipleChoiceAssessmentItemBuilder)28 SingleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder)28 MatchAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.MatchAssessmentItemBuilder)26 AssessmentItemBuilder (org.olat.ims.qti21.model.xml.AssessmentItemBuilder)24 SimpleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.SimpleChoiceAssessmentItemBuilder)18 EssayQuestion (org.olat.ims.qti.editor.beecom.objects.EssayQuestion)14 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)12 EssayResponse (org.olat.ims.qti.editor.beecom.objects.EssayResponse)12 Question (org.olat.ims.qti.editor.beecom.objects.Question)12 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)12 ChoiceResponse (org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)10 FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)10 Response (org.olat.ims.qti.editor.beecom.objects.Response)10 File (java.io.File)8 HashMap (java.util.HashMap)8 DrawingAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.DrawingAssessmentItemBuilder)8 HotspotAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.HotspotAssessmentItemBuilder)8