use of org.olat.ims.qti.editor.beecom.objects.Mattext in project openolat by klemens.
the class CSVToQuestionConverterTest method importMultipleChoice.
@Test
public void importMultipleChoice() throws IOException, URISyntaxException {
URL importTxtUrl = CSVToQuestionConverterTest.class.getResource("question_import_mc.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("Fussball: Austragungsort", item.getTitle());
Assert.assertEquals("Die Fussball WM wird alle vier Jahre von einem anderen Land ausgerichtet.", item.getObjectives());
Assert.assertEquals(Question.TYPE_MC, item.getQuestion().getType());
Assert.assertTrue(item.getQuestion() instanceof ChoiceQuestion);
Material questionMat = item.getQuestion().getQuestion();
Assert.assertNotNull(questionMat);
Assert.assertNotNull(questionMat.getElements());
Assert.assertEquals(1, questionMat.getElements().size());
QTIObject questionMatEl = questionMat.getElements().get(0);
Assert.assertTrue(questionMatEl instanceof Mattext);
String text = ((Mattext) questionMatEl).getContent();
Assert.assertEquals("In welchen L\u00E4ndern wurde zwischen dem Jahr 2000 und 2015 eine Fussball Weltmeisterschaft ausgetragen?", text);
ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
Assert.assertNotNull(question.getResponses());
Assert.assertEquals(7, question.getResponses().size());
List<Response> responses = question.getResponses();
Assert.assertEquals(1.0f, responses.get(0).getPoints(), 0.0001);
Assert.assertEquals(1.0f, responses.get(1).getPoints(), 0.0001);
Assert.assertEquals(1.0f, responses.get(2).getPoints(), 0.0001);
Assert.assertEquals(-1.0f, responses.get(3).getPoints(), 0.0001);
Assert.assertEquals(-1.0f, responses.get(4).getPoints(), 0.0001);
Assert.assertEquals(-1.0f, responses.get(5).getPoints(), 0.0001);
Assert.assertEquals(-1.0f, responses.get(6).getPoints(), 0.0001);
// after it will be set to true for all of them
Assert.assertTrue(responses.get(0).isCorrect());
Assert.assertTrue(responses.get(1).isCorrect());
Assert.assertTrue(responses.get(2).isCorrect());
Assert.assertFalse(responses.get(3).isCorrect());
Assert.assertFalse(responses.get(4).isCorrect());
Assert.assertFalse(responses.get(5).isCorrect());
Assert.assertFalse(responses.get(6).isCorrect());
String feedbackMastery = QTIEditHelper.getFeedbackMasteryText(item);
Assert.assertEquals("Bravo! Die Antwort ich absolut korrekt.", feedbackMastery);
String feedbackFail = QTIEditHelper.getFeedbackFailText(item);
Assert.assertEquals("Leider falsch. Probieren Sie es noch einmal.", feedbackFail);
}
use of org.olat.ims.qti.editor.beecom.objects.Mattext 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);
}
use of org.olat.ims.qti.editor.beecom.objects.Mattext in project openolat by klemens.
the class QTIEditHelper method setFeedback.
/**
* Set feedback
* @param object
* @param feedbackString
* @param sIdent
*/
public static void setFeedback(QTIObject object, String feedbackString, String sIdent) {
List<Feedback> feedbacks = getFeedbacks(object);
Feedback feedback = getFeedback(sIdent, feedbacks);
if (feedbackString == null || feedbackString.trim().length() == 0) {
feedbacks.remove(feedback);
return;
}
if (feedback != null) {
feedbackString = feedbackString.trim();
List matList = feedback.getMaterials();
if (matList.size() > 0) {
Material mat = (Material) feedback.getMaterials().get(0);
if (mat == null) {
mat = new Material();
mat.getElements().add(new Mattext(feedbackString));
feedback.getMaterials().add(mat);
} else if (mat.getElements().size() > 0) {
mat.getElements().set(0, new Mattext(feedbackString));
} else {
mat.getElements().add(new Mattext(feedbackString));
}
} else {
Material mat = new Material();
mat.getElements().add(new Mattext(feedbackString));
feedback.getMaterials().add(mat);
}
} else {
Feedback newFeedback = new Feedback();
newFeedback.setIdent(sIdent);
newFeedback.setView("All");
Mattext newMattext = new Mattext(feedbackString);
List<QTIObject> newMattextL = new ArrayList<>();
newMattextL.add(newMattext);
Material material = new Material();
material.setElements(newMattextL);
List<Material> newMaterialL = new ArrayList<>();
newMaterialL.add(material);
newFeedback.setMaterials(newMaterialL);
feedbacks.add(newFeedback);
}
}
use of org.olat.ims.qti.editor.beecom.objects.Mattext in project openolat by klemens.
the class QTIEditHelper method createMCItem.
/**
* Creates a new Multiple Choice item.
* @param trans
* @return New Multiple Choice item.
*/
public static Item createMCItem(Translator trans) {
// create item
Item newItem = new Item();
newItem.setIdent(EDITOR_IDENT + ":" + ITEM_TYPE_MC + ":" + 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);
// pepare question
ChoiceQuestion question = new ChoiceQuestion();
question.setLable(trans.translate("editor.newquestion"));
question.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
question.setType(Question.TYPE_MC);
question.setSingleCorrect(true);
question.setSingleCorrectScore(1);
ChoiceResponse newChoice = new ChoiceResponse();
newChoice.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
newChoice.setCorrect(true);
newChoice.setPoints(1);
question.getResponses().add(newChoice);
newItem.setQuestion(question);
QTIEditHelper.setFeedbackMastery(newItem, "");
QTIEditHelper.setFeedbackFail(newItem, "");
return newItem;
}
use of org.olat.ims.qti.editor.beecom.objects.Mattext in project openolat by klemens.
the class QTIEditHelper method fetchChoices.
/**
* Fetch choices.
* @param response_labels
* @return Map of choices.
*/
public static List<Response> fetchChoices(List response_labels) {
List<Response> choices = new ArrayList<Response>();
for (Iterator i = response_labels.iterator(); i.hasNext(); ) {
ChoiceResponse choice = new ChoiceResponse();
Element response_label = (Element) i.next();
choice.setIdent(response_label.attributeValue("ident"));
List materials = response_label.selectNodes(".//material");
Material content = new Material();
for (Iterator iter = materials.iterator(); iter.hasNext(); ) {
Element el_material = (Element) iter.next();
Material mat = (Material) parserManager.parse(el_material);
content.getElements().addAll(mat.getElements());
}
// assure material always has some content
if (content.getElements().size() == 0) {
content.getElements().add(new Mattext(""));
}
choice.setContent(content);
choices.add(choice);
}
return choices;
}
Aggregations