use of org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder in project OpenOLAT by OpenOLAT.
the class HottextAssessmentItemBuilderTest method readHottextAssessmentItem.
@Test
public void readHottextAssessmentItem() throws URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
URL itemUrl = AssessmentItemBuilderTest.class.getResource("resources/openolat/hottext-per-answer-11-4-0.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
HottextAssessmentItemBuilder itemBuilder = new HottextAssessmentItemBuilder(assessmentItem, qtiSerializer);
// basic check ChoiceInteraction
AssessmentItem loadedItem = itemBuilder.getAssessmentItem();
List<Interaction> interactions = loadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(1, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof HottextInteraction);
// hot texts
Choice correct1 = itemBuilder.getChoice(Identifier.assumedLegal("htf9250a96f24bc8873c9cc54dfbaaaa"));
Assert.assertTrue(itemBuilder.isCorrect(correct1));
Choice correct2 = itemBuilder.getChoice(Identifier.assumedLegal("RESPONSE_3"));
Assert.assertTrue(itemBuilder.isCorrect(correct2));
Choice wrong1 = itemBuilder.getChoice(Identifier.assumedLegal("RESPONSE_2"));
Assert.assertFalse(itemBuilder.isCorrect(wrong1));
Choice wrong2 = itemBuilder.getChoice(Identifier.assumedLegal("RESPONSE_4"));
Assert.assertFalse(itemBuilder.isCorrect(wrong2));
// score
Double maxScore = itemBuilder.getMaxScoreBuilder().getScore();
Assert.assertEquals(3.0, maxScore.doubleValue(), 0.0001);
Double minScore = itemBuilder.getMinScoreBuilder().getScore();
Assert.assertEquals(0.0, minScore.doubleValue(), 0.0001);
// per answer
Assert.assertEquals(ScoreEvaluation.perAnswer, itemBuilder.getScoreEvaluationMode());
}
use of org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder in project OpenOLAT by OpenOLAT.
the class HottextAssessmentItemBuilderTest method readHottextAssessmentItem_allCorrectAnswers.
@Test
public void readHottextAssessmentItem_allCorrectAnswers() throws URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
URL itemUrl = AssessmentItemBuilderTest.class.getResource("resources/openolat/hottext-score-all-11-4-0.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
HottextAssessmentItemBuilder itemBuilder = new HottextAssessmentItemBuilder(assessmentItem, qtiSerializer);
// basic check ChoiceInteraction
AssessmentItem loadedItem = itemBuilder.getAssessmentItem();
List<Interaction> interactions = loadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(2, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof HottextInteraction);
Assert.assertTrue(interactions.get(1) instanceof EndAttemptInteraction);
// hot texts
Choice correct1 = itemBuilder.getChoice(Identifier.assumedLegal("htebdb40344641dba115e3c8c6ce3926"));
Assert.assertTrue(itemBuilder.isCorrect(correct1));
Choice correct2 = itemBuilder.getChoice(Identifier.assumedLegal("ht103ce53892dea97613005a5ce76be31e"));
Assert.assertTrue(itemBuilder.isCorrect(correct2));
Choice wrong1 = itemBuilder.getChoice(Identifier.assumedLegal("hte11a51c3e3d86a5f7293da19a1a8700e"));
Assert.assertFalse(itemBuilder.isCorrect(wrong1));
// score
Double maxScore = itemBuilder.getMaxScoreBuilder().getScore();
Assert.assertEquals(2.0, maxScore.doubleValue(), 0.0001);
Double minScore = itemBuilder.getMinScoreBuilder().getScore();
Assert.assertEquals(0.0, minScore.doubleValue(), 0.0001);
// per answer
Assert.assertEquals(ScoreEvaluation.allCorrectAnswers, itemBuilder.getScoreEvaluationMode());
// correct feedback
ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
Assert.assertNotNull(correctFeedback);
Assert.assertNotNull(correctFeedback.getText());
Assert.assertTrue(correctFeedback.getText().contains("You check the right answers"));
// incorrect
ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
Assert.assertNotNull(incorrectFeedback);
Assert.assertNotNull(incorrectFeedback.getText());
Assert.assertTrue(incorrectFeedback.getText().contains("Some of your anwsers are not the correct one."));
// correct solution feedback
ModalFeedbackBuilder correctSolutionFeedback = itemBuilder.getCorrectSolutionFeedback();
Assert.assertNotNull(correctSolutionFeedback);
Assert.assertNotNull(correctSolutionFeedback.getText());
Assert.assertTrue(correctSolutionFeedback.getText().contains("A little hint towards the correct solution"));
// hint
ModalFeedbackBuilder hint = itemBuilder.getHint();
Assert.assertNotNull(hint);
Assert.assertNotNull(hint.getText());
Assert.assertTrue(hint.getText().contains("This is an endAttemptInteraction"));
}
use of org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder in project OpenOLAT by OpenOLAT.
the class HottextAssessmentItemBuilderTest method createHottextAssessmentItem_perAnswer.
/**
* This is an hottextInteraction with 3 choices, one with 3.0 points and correct,
* one with 0.0 points but correct and one false with -1.0 points.
*
* @throws IOException
*/
@Test
public void createHottextAssessmentItem_perAnswer() throws IOException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
HottextAssessmentItemBuilder itemBuilder = new HottextAssessmentItemBuilder("Hot texts", "This is a hot ", "text", qtiSerializer);
itemBuilder.setQuestion("<p>This is <hottext identifier=\"RESPONSE_HOT_1\">hot</hottext>, <hottext identifier=\"RESPONSE_HOT_2\">cold</hottext> or <hottext identifier=\"RESPONSE_HOT_3\">freezing</hottext></p>");
itemBuilder.addCorrectAnswer(Identifier.parseString("RESPONSE_HOT_2"));
itemBuilder.addCorrectAnswer(Identifier.parseString("RESPONSE_HOT_3"));
itemBuilder.setMapping(Identifier.parseString("RESPONSE_HOT_1"), -1.0d);
itemBuilder.setMapping(Identifier.parseString("RESPONSE_HOT_2"), 0.0d);
itemBuilder.setMapping(Identifier.parseString("RESPONSE_HOT_3"), 3.0d);
itemBuilder.setMaxScore(3.0d);
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
itemBuilder.build();
File itemFile = new File(WebappHelper.getTmpDir(), "hottextAssessmentItem" + 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("RESPONSE_HOT_2", "RESPONSE_HOT_3"));
ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
Assert.assertEquals(new FloatValue(3.0d), score);
Value feedbackBasic = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
Assert.assertEquals(new IdentifierValue(QTI21Constants.CORRECT_IDENTIFIER), feedbackBasic);
}
{
// max score but not all correct
Map<Identifier, ResponseData> responseMap = new HashMap<>();
Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
responseMap.put(responseIdentifier, new StringResponseData("RESPONSE_HOT_3"));
ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
Assert.assertEquals(new FloatValue(3.0d), score);
Value feedbackBasic = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
Assert.assertEquals(new IdentifierValue(QTI21Constants.INCORRECT_IDENTIFIER), feedbackBasic);
}
{
// all wrong
Map<Identifier, ResponseData> responseMap = new HashMap<>();
Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
responseMap.put(responseIdentifier, new StringResponseData("RESPONSE_HOT_1"));
ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
Assert.assertEquals(new FloatValue(0.0d), score);
Value feedbackBasic = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
Assert.assertEquals(new IdentifierValue(QTI21Constants.INCORRECT_IDENTIFIER), feedbackBasic);
}
FileUtils.deleteDirsAndFiles(itemFile.toPath());
}
use of org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder in project OpenOLAT by OpenOLAT.
the class QTI21QPoolServiceProvider method createItem.
public QuestionItem createItem(Identity identity, QTI21QuestionType type, String title, Locale locale) {
AssessmentItemBuilder itemBuilder = null;
Translator translator = Util.createPackageTranslator(AssessmentTestComposerController.class, locale);
switch(type) {
case sc:
itemBuilder = new SingleChoiceAssessmentItemBuilder(translator.translate("new.sc"), translator.translate("new.answer"), qtiService.qtiSerializer());
break;
case mc:
itemBuilder = new MultipleChoiceAssessmentItemBuilder(translator.translate("new.mc"), translator.translate("new.answer"), qtiService.qtiSerializer());
break;
case kprim:
itemBuilder = new KPrimAssessmentItemBuilder(translator.translate("new.kprim"), translator.translate("new.answer"), qtiService.qtiSerializer());
break;
case match:
itemBuilder = new MatchAssessmentItemBuilder(translator.translate("new.match"), QTI21Constants.CSS_MATCH_MATRIX, qtiService.qtiSerializer());
break;
case matchdraganddrop:
itemBuilder = new MatchAssessmentItemBuilder(translator.translate("new.match"), QTI21Constants.CSS_MATCH_DRAG_AND_DROP, qtiService.qtiSerializer());
break;
case matchtruefalse:
itemBuilder = new MatchAssessmentItemBuilder(translator.translate("new.match"), QTI21Constants.CSS_MATCH_TRUE_FALSE, translator.translate("match.unanswered"), translator.translate("match.true"), translator.translate("match.false"), qtiService.qtiSerializer());
break;
case fib:
itemBuilder = new FIBAssessmentItemBuilder(translator.translate("new.fib"), EntryType.text, qtiService.qtiSerializer());
break;
case numerical:
itemBuilder = new FIBAssessmentItemBuilder(translator.translate("new.fib.numerical"), EntryType.numerical, qtiService.qtiSerializer());
break;
case essay:
itemBuilder = new EssayAssessmentItemBuilder(translator.translate("new.essay"), qtiService.qtiSerializer());
break;
case upload:
itemBuilder = new UploadAssessmentItemBuilder(translator.translate("new.upload"), qtiService.qtiSerializer());
break;
case drawing:
itemBuilder = new DrawingAssessmentItemBuilder(translator.translate("new.drawing"), qtiService.qtiSerializer());
break;
case hotspot:
itemBuilder = new HotspotAssessmentItemBuilder(translator.translate("new.hotspot"), qtiService.qtiSerializer());
break;
case hottext:
itemBuilder = new HottextAssessmentItemBuilder(translator.translate("new.hottext"), translator.translate("new.hottext.start"), translator.translate("new.hottext.text"), qtiService.qtiSerializer());
break;
default:
return null;
}
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
assessmentItem.setLabel(title);
assessmentItem.setTitle(title);
AssessmentItemMetadata itemMetadata = new AssessmentItemMetadata();
itemMetadata.setQuestionType(type);
QTI21ImportProcessor processor = new QTI21ImportProcessor(identity, locale);
QuestionItemImpl qitem = processor.processItem(assessmentItem, "", null, "OpenOLAT", Settings.getVersion(), itemMetadata);
VFSContainer baseDir = qpoolFileStorage.getContainer(qitem.getDirectory());
VFSLeaf leaf = baseDir.createChildLeaf(qitem.getRootFilename());
File itemFile = ((LocalImpl) leaf).getBasefile();
qtiService.persistAssessmentObject(itemFile, assessmentItem);
// create imsmanifest
ManifestBuilder manifest = ManifestBuilder.createAssessmentItemBuilder();
manifest.appendAssessmentItem(itemFile.getName());
manifest.write(new File(itemFile.getParentFile(), "imsmanifest.xml"));
return qitem;
}
use of org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder in project openolat by klemens.
the class HottextAssessmentItemBuilderTest method readHottextAssessmentItem_allCorrectAnswers.
@Test
public void readHottextAssessmentItem_allCorrectAnswers() throws URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
URL itemUrl = AssessmentItemBuilderTest.class.getResource("resources/openolat/hottext-score-all-11-4-0.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
HottextAssessmentItemBuilder itemBuilder = new HottextAssessmentItemBuilder(assessmentItem, qtiSerializer);
// basic check ChoiceInteraction
AssessmentItem loadedItem = itemBuilder.getAssessmentItem();
List<Interaction> interactions = loadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(2, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof HottextInteraction);
Assert.assertTrue(interactions.get(1) instanceof EndAttemptInteraction);
// hot texts
Choice correct1 = itemBuilder.getChoice(Identifier.assumedLegal("htebdb40344641dba115e3c8c6ce3926"));
Assert.assertTrue(itemBuilder.isCorrect(correct1));
Choice correct2 = itemBuilder.getChoice(Identifier.assumedLegal("ht103ce53892dea97613005a5ce76be31e"));
Assert.assertTrue(itemBuilder.isCorrect(correct2));
Choice wrong1 = itemBuilder.getChoice(Identifier.assumedLegal("hte11a51c3e3d86a5f7293da19a1a8700e"));
Assert.assertFalse(itemBuilder.isCorrect(wrong1));
// score
Double maxScore = itemBuilder.getMaxScoreBuilder().getScore();
Assert.assertEquals(2.0, maxScore.doubleValue(), 0.0001);
Double minScore = itemBuilder.getMinScoreBuilder().getScore();
Assert.assertEquals(0.0, minScore.doubleValue(), 0.0001);
// per answer
Assert.assertEquals(ScoreEvaluation.allCorrectAnswers, itemBuilder.getScoreEvaluationMode());
// correct feedback
ModalFeedbackBuilder correctFeedback = itemBuilder.getCorrectFeedback();
Assert.assertNotNull(correctFeedback);
Assert.assertNotNull(correctFeedback.getText());
Assert.assertTrue(correctFeedback.getText().contains("You check the right answers"));
// incorrect
ModalFeedbackBuilder incorrectFeedback = itemBuilder.getIncorrectFeedback();
Assert.assertNotNull(incorrectFeedback);
Assert.assertNotNull(incorrectFeedback.getText());
Assert.assertTrue(incorrectFeedback.getText().contains("Some of your anwsers are not the correct one."));
// correct solution feedback
ModalFeedbackBuilder correctSolutionFeedback = itemBuilder.getCorrectSolutionFeedback();
Assert.assertNotNull(correctSolutionFeedback);
Assert.assertNotNull(correctSolutionFeedback.getText());
Assert.assertTrue(correctSolutionFeedback.getText().contains("A little hint towards the correct solution"));
// hint
ModalFeedbackBuilder hint = itemBuilder.getHint();
Assert.assertNotNull(hint);
Assert.assertNotNull(hint.getText());
Assert.assertTrue(hint.getText().contains("This is an endAttemptInteraction"));
}
Aggregations