Search in sources :

Example 16 with FIBResponse

use of org.olat.ims.qti.editor.beecom.objects.FIBResponse in project OpenOLAT by OpenOLAT.

the class ItemNode method createMemento.

public Memento createMemento() {
    Question question = item.getQuestion();
    // special case switches as question types are encoded into integers!!
    boolean isFIB = question.getType() == Question.TYPE_FIB;
    boolean isESSAY = question.getType() == Question.TYPE_ESSAY;
    // Item metadata
    QtiNodeMemento qnm = new QtiNodeMemento();
    Map<String, Object> qtiState = new HashMap<>();
    qtiState.put("ID", item.getIdent());
    qtiState.put("TITLE", item.getTitle());
    qtiState.put("OBJECTIVES", item.getObjectives());
    // question and responses
    qtiState.put("QUESTION.ID", question.getIdent());
    qtiState.put("QUESTION.HINTTEXT", question.getHintText());
    Material questMaterial = question.getQuestion();
    qtiState.put("QUESTION.MATERIAL.ASTEXT", questMaterial.renderAsText());
    List<String> ids = new ArrayList<String>();
    List<String> asTexts = new ArrayList<String>();
    List<String> feedbacks = new ArrayList<String>();
    List<Response> responses = question.getResponses();
    for (Iterator<Response> iter = responses.iterator(); iter.hasNext(); ) {
        Response resp = iter.next();
        if (isFIB) {
            if (FIBResponse.TYPE_BLANK.equals(((FIBResponse) resp).getType())) {
                asTexts.add(formatFIBResponseAsText((FIBResponse) resp));
                ids.add(resp.getIdent());
                feedbacks.add(QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent()));
            }
        } else if (isESSAY) {
            asTexts.add(formatESSAYResponseAsText((EssayResponse) resp));
            ids.add(resp.getIdent());
            feedbacks.add(QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent()));
        } else {
            // not a FIB or ESSAY response
            asTexts.add(resp.getContent().renderAsText());
            ids.add(resp.getIdent());
            feedbacks.add(QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent()));
        }
    }
    qtiState.put("QUESTION.RESPONSES.IDS", ids);
    qtiState.put("QUESTION.RESPONSES.ASTEXT", asTexts);
    qtiState.put("QUESTION.RESPONSES.FEEDBACK", feedbacks);
    // feedback
    qtiState.put("FEEDBACK.MASTERY", QTIEditHelper.getFeedbackMasteryText(item));
    qtiState.put("FEEDBACK.FAIL", QTIEditHelper.getFeedbackFailText(item));
    Control control = QTIEditHelper.getControl(item);
    qtiState.put("FEEDBACK.ENABLED", control.getFeedback() == 1 ? Boolean.TRUE : Boolean.FALSE);
    // 
    qnm.setQtiState(qtiState);
    // 
    return qnm;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Material(org.olat.ims.qti.editor.beecom.objects.Material) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) 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) Control(org.olat.ims.qti.editor.beecom.objects.Control) WindowControl(org.olat.core.gui.control.WindowControl) Question(org.olat.ims.qti.editor.beecom.objects.Question) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject)

Example 17 with FIBResponse

use of org.olat.ims.qti.editor.beecom.objects.FIBResponse in project OpenOLAT by OpenOLAT.

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 18 with FIBResponse

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

the class CSVToQuestionConverterTest method importFillInBlanck.

@Test
public void importFillInBlanck() throws IOException, URISyntaxException {
    URL importTxtUrl = CSVToQuestionConverterTest.class.getResource("question_import_fib.txt");
    Assert.assertNotNull(importTxtUrl);
    File importTxt = new File(importTxtUrl.toURI());
    String input = FileUtils.readFileToString(importTxt, "UTF-8");
    Translator translator = new KeyTranslator(Locale.ENGLISH);
    ImportOptions options = new ImportOptions();
    options.setShuffle(true);
    CSVToQuestionConverter converter = new CSVToQuestionConverter(translator, options);
    converter.parse(input);
    List<ItemAndMetadata> items = converter.getItems();
    Assert.assertNotNull(items);
    Assert.assertEquals(1, items.size());
    ItemAndMetadata importedItem = items.get(0);
    Item item = importedItem.getItem();
    Assert.assertNotNull(item);
    Assert.assertEquals(Question.TYPE_FIB, item.getQuestion().getType());
    Assert.assertTrue(item.getQuestion() instanceof FIBQuestion);
    FIBQuestion question = (FIBQuestion) item.getQuestion();
    List<Response> responses = question.getResponses();
    Assert.assertNotNull(responses);
    Assert.assertEquals(7, responses.size());
    // check java type
    for (Response response : responses) {
        Assert.assertTrue(response instanceof FIBResponse);
    }
    // check type
    Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(0)).getType());
    Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(1)).getType());
    Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(2)).getType());
    Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(3)).getType());
    Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(4)).getType());
    Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(5)).getType());
    Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(6)).getType());
    // check size
    Assert.assertEquals(2, ((FIBResponse) responses.get(1)).getSize());
    Assert.assertEquals(2, ((FIBResponse) responses.get(3)).getSize());
    Assert.assertEquals(2, ((FIBResponse) responses.get(5)).getSize());
    // check max length
    Assert.assertEquals(2, ((FIBResponse) responses.get(1)).getMaxLength());
    Assert.assertEquals(2, ((FIBResponse) responses.get(3)).getMaxLength());
    Assert.assertEquals(2, ((FIBResponse) responses.get(5)).getMaxLength());
}
Also used : URL(java.net.URL) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Item(org.olat.ims.qti.editor.beecom.objects.Item) Translator(org.olat.core.gui.translator.Translator) KeyTranslator(org.olat.test.KeyTranslator) KeyTranslator(org.olat.test.KeyTranslator) File(java.io.File) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion) Test(org.junit.Test)

Example 19 with FIBResponse

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

the class QTIEditHelper method createFIBItem.

/**
 * Creates a new FIB item
 * @param trans
 * @return New fib item.
 */
public static Item createFIBItem(Translator trans) {
    // create item
    Item newItem = new Item();
    newItem.setIdent(EDITOR_IDENT + ":" + ITEM_TYPE_FIB + ":" + String.valueOf(CodeHelper.getRAMUniqueID()));
    newItem.setTitle(trans.translate("editor.newquestion"));
    newItem.setLabel("");
    // conrols
    Control control = new Control();
    List<Control> controls = new ArrayList<Control>();
    controls.add(control);
    newItem.setItemcontrols(controls);
    QTIEditHelper.setFeedbackMastery(newItem, "");
    QTIEditHelper.setFeedbackFail(newItem, "");
    FIBQuestion fibquestion = new FIBQuestion();
    fibquestion.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
    fibquestion.setSingleCorrect(true);
    fibquestion.setSingleCorrectScore(1);
    FIBResponse response = new FIBResponse();
    response.setType(FIBResponse.TYPE_CONTENT);
    Material mat = new Material();
    mat.add(new Mattext(trans.translate("editor.newtextelement")));
    response.setContent(mat);
    fibquestion.getResponses().add(response);
    newItem.setQuestion(fibquestion);
    return newItem;
}
Also used : FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) Control(org.olat.ims.qti.editor.beecom.objects.Control) Mattext(org.olat.ims.qti.editor.beecom.objects.Mattext) ArrayList(java.util.ArrayList) Material(org.olat.ims.qti.editor.beecom.objects.Material) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion)

Example 20 with FIBResponse

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

the class CSVToQuestionConverter method processChoice.

private void processChoice(String[] parts) {
    if (currentItem == null || parts.length < 2) {
        return;
    }
    try {
        Question question = currentItem.getItem().getQuestion();
        int type = question.getType();
        if (type == Question.TYPE_MC || type == Question.TYPE_SC) {
            float point = parseFloat(parts[0], 1.0f);
            String content = parts[1];
            ChoiceQuestion choice = (ChoiceQuestion) question;
            List<Response> choices = choice.getResponses();
            ChoiceResponse newChoice = new ChoiceResponse();
            newChoice.getContent().add(createMattext(content));
            newChoice.setCorrect(point > 0.0f);
            newChoice.setPoints(point);
            choices.add(newChoice);
        } else if (type == Question.TYPE_FIB) {
            String firstPart = parts[0].toLowerCase();
            FIBQuestion fib = (FIBQuestion) question;
            if ("text".equals(firstPart) || "texte".equals(firstPart)) {
                String text = parts[1];
                FIBResponse response = new FIBResponse();
                response.setType(FIBResponse.TYPE_CONTENT);
                Material mat = createMaterialWithText(text);
                response.setContent(mat);
                fib.getResponses().add(response);
            } else {
                float point = parseFloat(parts[0], 1.0f);
                String correctBlank = parts[1];
                FIBResponse response = new FIBResponse();
                response.setType(FIBResponse.TYPE_BLANK);
                response.setCorrectBlank(correctBlank);
                response.setPoints(point);
                if (parts.length > 2) {
                    String sizes = parts[2];
                    String[] sizeArr = sizes.split(",");
                    if (sizeArr.length >= 2) {
                        int size = Integer.parseInt(sizeArr[0]);
                        int maxLength = Integer.parseInt(sizeArr[1]);
                        response.setSize(size);
                        response.setMaxLength(maxLength);
                    }
                }
                fib.getResponses().add(response);
            }
        }
    } catch (NumberFormatException e) {
        log.warn("Cannot parse point for: " + parts[0] + " / " + parts[1], e);
    }
}
Also used : ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) Response(org.olat.ims.qti.editor.beecom.objects.Response) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse) FIBResponse(org.olat.ims.qti.editor.beecom.objects.FIBResponse) 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) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Material(org.olat.ims.qti.editor.beecom.objects.Material) FIBQuestion(org.olat.ims.qti.editor.beecom.objects.FIBQuestion)

Aggregations

FIBResponse (org.olat.ims.qti.editor.beecom.objects.FIBResponse)22 Response (org.olat.ims.qti.editor.beecom.objects.Response)20 FIBQuestion (org.olat.ims.qti.editor.beecom.objects.FIBQuestion)12 Material (org.olat.ims.qti.editor.beecom.objects.Material)10 Question (org.olat.ims.qti.editor.beecom.objects.Question)10 ArrayList (java.util.ArrayList)8 Item (org.olat.ims.qti.editor.beecom.objects.Item)8 HashMap (java.util.HashMap)6 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)6 Control (org.olat.ims.qti.editor.beecom.objects.Control)6 EssayResponse (org.olat.ims.qti.editor.beecom.objects.EssayResponse)6 File (java.io.File)4 URL (java.net.URL)4 List (java.util.List)4 Test (org.junit.Test)4 WindowControl (org.olat.core.gui.control.WindowControl)4 Translator (org.olat.core.gui.translator.Translator)4 ChoiceResponse (org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)4 EssayQuestion (org.olat.ims.qti.editor.beecom.objects.EssayQuestion)4 Mattext (org.olat.ims.qti.editor.beecom.objects.Mattext)4