use of org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder in project OpenOLAT by OpenOLAT.
the class CSVToAssessmentItemConverter method processType.
private void processType(String[] parts) {
if (currentItem != null) {
build();
items.add(currentItem);
currentItem = null;
}
if (parts.length > 1) {
String type = parts[1].toLowerCase();
AssessmentItemBuilder itemBuilder;
switch(type) {
case "fib":
{
FIBAssessmentItemBuilder fibItemBuilder = new FIBAssessmentItemBuilder("Gap text", EntryType.text, qtiSerializer);
itemBuilder = initFIBAssessmentItemBuilder(fibItemBuilder);
break;
}
case "mc":
{
MultipleChoiceAssessmentItemBuilder mcItemBuilder = new MultipleChoiceAssessmentItemBuilder("Multiple choice", "New answer", qtiSerializer);
itemBuilder = initMultipleChoiceAssessmentItemBuilder(mcItemBuilder);
break;
}
case "sc":
{
SingleChoiceAssessmentItemBuilder scItemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "New answer", qtiSerializer);
itemBuilder = initSingleChoiceAssessmentItemBuilder(scItemBuilder);
break;
}
case "kprim":
{
kprimPosition = 0;
itemBuilder = new KPrimAssessmentItemBuilder("Kprim", "New answer", qtiSerializer);
break;
}
case "essay":
{
itemBuilder = new EssayAssessmentItemBuilder("Essay", qtiSerializer);
break;
}
case "matrix":
{
MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_MATRIX, qtiSerializer);
itemBuilder = initMatchAssessmentItemBuilder(matchBuilder);
break;
}
case "drag&drop":
{
MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_DRAG_AND_DROP, qtiSerializer);
itemBuilder = initMatchAssessmentItemBuilder(matchBuilder);
break;
}
case "truefalse":
{
Translator trans = Util.createPackageTranslator(AssessmentItemEditorController.class, locale);
MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_TRUE_FALSE, trans.translate("match.unanswered"), trans.translate("match.true"), trans.translate("match.false"), qtiSerializer);
itemBuilder = initMatchAssessmentItemBuilderForTrueFalse(matchBuilder);
break;
}
default:
{
itemBuilder = null;
}
}
if (itemBuilder != null) {
currentItem = new AssessmentItemAndMetadata(itemBuilder);
} else {
log.warn("Question type not supported: " + type);
currentItem = null;
}
}
}
use of org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder in project openolat by klemens.
the class CSVToAssessmentItemConverter method processType.
private void processType(String[] parts) {
if (currentItem != null) {
build();
items.add(currentItem);
currentItem = null;
}
if (parts.length > 1) {
String type = parts[1].toLowerCase();
AssessmentItemBuilder itemBuilder;
switch(type) {
case "fib":
{
FIBAssessmentItemBuilder fibItemBuilder = new FIBAssessmentItemBuilder("Gap text", EntryType.text, qtiSerializer);
itemBuilder = initFIBAssessmentItemBuilder(fibItemBuilder);
break;
}
case "mc":
{
MultipleChoiceAssessmentItemBuilder mcItemBuilder = new MultipleChoiceAssessmentItemBuilder("Multiple choice", "New answer", qtiSerializer);
itemBuilder = initMultipleChoiceAssessmentItemBuilder(mcItemBuilder);
break;
}
case "sc":
{
SingleChoiceAssessmentItemBuilder scItemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "New answer", qtiSerializer);
itemBuilder = initSingleChoiceAssessmentItemBuilder(scItemBuilder);
break;
}
case "kprim":
{
kprimPosition = 0;
itemBuilder = new KPrimAssessmentItemBuilder("Kprim", "New answer", qtiSerializer);
break;
}
case "essay":
{
itemBuilder = new EssayAssessmentItemBuilder("Essay", qtiSerializer);
break;
}
case "matrix":
{
MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_MATRIX, qtiSerializer);
itemBuilder = initMatchAssessmentItemBuilder(matchBuilder);
break;
}
case "drag&drop":
{
MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_DRAG_AND_DROP, qtiSerializer);
itemBuilder = initMatchAssessmentItemBuilder(matchBuilder);
break;
}
case "truefalse":
{
Translator trans = Util.createPackageTranslator(AssessmentItemEditorController.class, locale);
MatchAssessmentItemBuilder matchBuilder = new MatchAssessmentItemBuilder("Matrix", QTI21Constants.CSS_MATCH_TRUE_FALSE, trans.translate("match.unanswered"), trans.translate("match.true"), trans.translate("match.false"), qtiSerializer);
itemBuilder = initMatchAssessmentItemBuilderForTrueFalse(matchBuilder);
break;
}
default:
{
itemBuilder = null;
}
}
if (itemBuilder != null) {
currentItem = new AssessmentItemAndMetadata(itemBuilder);
} else {
log.warn("Question type not supported: " + type);
currentItem = null;
}
}
}
use of org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder in project openolat by klemens.
the class SingleChoiceAssessmentItemBuilderTest method createSingleAssessmentItem_allCorrectAnswers.
@Test
public void createSingleAssessmentItem_allCorrectAnswers() throws IOException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "Single choice", qtiSerializer);
itemBuilder.setQuestion("<p>Hello</p>");
ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
SimpleChoice choice1 = AssessmentItemFactory.createSimpleChoice(interaction, "One", "sc");
SimpleChoice choice2 = AssessmentItemFactory.createSimpleChoice(interaction, "Two", "sc");
SimpleChoice choice3 = AssessmentItemFactory.createSimpleChoice(interaction, "Three", "sc");
List<SimpleChoice> choiceList = new ArrayList<>();
choiceList.add(choice1);
choiceList.add(choice2);
choiceList.add(choice3);
itemBuilder.setSimpleChoices(choiceList);
itemBuilder.setCorrectAnswer(choice2.getIdentifier());
itemBuilder.setMaxScore(3.0d);
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
itemBuilder.build();
File itemFile = new File(WebappHelper.getTmpDir(), "scAssessmentItem" + UUID.randomUUID() + ".xml");
try (FileOutputStream out = new FileOutputStream(itemFile)) {
qtiSerializer.serializeJqtiObject(itemBuilder.getAssessmentItem(), out);
} catch (Exception e) {
log.error("", e);
}
{
// correct answers
Map<Identifier, ResponseData> responseMap = new HashMap<>();
Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
responseMap.put(responseIdentifier, new StringResponseData(choice2.getIdentifier().toString()));
ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
Assert.assertEquals(new FloatValue(3.0d), score);
}
{
// wrong answer
Map<Identifier, ResponseData> responseMap = new HashMap<>();
Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
responseMap.put(responseIdentifier, new StringResponseData(choice3.getIdentifier().toString()));
ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
Assert.assertEquals(new FloatValue(0.0d), score);
}
FileUtils.deleteDirsAndFiles(itemFile.toPath());
}
use of org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder in project openolat by klemens.
the class AssessmentItemBuilderTest method findFeedbacks.
@Test
public void findFeedbacks() throws URISyntaxException {
URL itemUrl = AssessmentItemBuilderTest.class.getResource("assessment-item-single-choice-feedbacks.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder(assessmentItem, qtiSerializer);
if (build.booleanValue()) {
itemBuilder.build();
}
ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
Assert.assertNotNull(correctFeedback);
Assert.assertTrue(correctFeedback.isCorrectRule());
ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
Assert.assertNotNull(incorrectFeedback);
Assert.assertTrue(incorrectFeedback.isIncorrectRule());
}
use of org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder in project openolat by klemens.
the class OnyxToAssessmentItemBuilderTest method extractsingleChoiceWithFeedbacks.
@Test
public void extractsingleChoiceWithFeedbacks() throws URISyntaxException {
URL itemUrl = OnyxToAssessmentItemBuilderTest.class.getResource("resources/onyx/single-choice-1-with-feedbacks_5-11.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder(assessmentItem, qtiSerializer);
// correct answer
List<SimpleChoice> choices = itemBuilder.getChoices();
Assert.assertNotNull(choices);
SimpleChoice choice = choices.get(3);
Assert.assertTrue(itemBuilder.isCorrect(choice));
// scoring
Assert.assertEquals(ScoreEvaluation.allCorrectAnswers, itemBuilder.getScoreEvaluationMode());
ScoreBuilder maxScoreBuilder = itemBuilder.getMaxScoreBuilder();
Assert.assertEquals(4.0d, maxScoreBuilder.getScore(), 0.00001d);
// check standard feedback
ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
Assert.assertNotNull(correctFeedback);
Assert.assertTrue(correctFeedback.isCorrectRule());
Assert.assertEquals("<p>Richtig Text</p>", correctFeedback.getText());
ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
Assert.assertNotNull(incorrectFeedback);
Assert.assertTrue(incorrectFeedback.isIncorrectRule());
Assert.assertEquals("<p>Falsch Text</p>", incorrectFeedback.getText());
}
Aggregations