use of org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder in project OpenOLAT by OpenOLAT.
the class AssessmentItemBuilderTest method buildAssessmentItem_kprim.
@Test
public void buildAssessmentItem_kprim() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
KPrimAssessmentItemBuilder itemBuilder = new KPrimAssessmentItemBuilder("Kprim", "New answer", qtiSerializer);
if (build.booleanValue()) {
itemBuilder.build();
}
AssessmentItem singleChoiceItem = itemBuilder.getAssessmentItem();
ItemValidationResult itemResult = serializeAndReload(singleChoiceItem);
AssessmentItem reloadedItem = itemResult.getResolvedAssessmentItem().getItemLookup().extractIfSuccessful();
List<Interaction> interactions = reloadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(1, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof MatchInteraction);
MatchInteraction interaction = (MatchInteraction) interactions.get(0);
Assert.assertNotNull(interaction.getResponseIdentifier());
ResponseDeclaration responseDeclaration = reloadedItem.getResponseDeclaration(interaction.getResponseIdentifier());
Assert.assertNotNull(responseDeclaration);
Assert.assertEquals(2, interaction.getSimpleMatchSets().size());
SimpleMatchSet matchSet = interaction.getSimpleMatchSets().get(0);
Assert.assertEquals(4, matchSet.getSimpleAssociableChoices().size());
SimpleMatchSet correctWrongSet = interaction.getSimpleMatchSets().get(1);
Assert.assertEquals(2, correctWrongSet.getSimpleAssociableChoices().size());
}
use of org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder 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.KPrimAssessmentItemBuilder in project OpenOLAT by OpenOLAT.
the class CSVToAssessmentItemConverter method processPoints.
private void processPoints(String[] parts) {
if (currentItem == null)
return;
double points = parseFloat(parts[1], 1.0f);
AssessmentItemBuilder itemBuilder = currentItem.getItemBuilder();
if (itemBuilder instanceof SimpleChoiceAssessmentItemBuilder) {
itemBuilder.setMinScore(0.0d);
itemBuilder.setMaxScore(points);
} else if (itemBuilder instanceof FIBAssessmentItemBuilder) {
itemBuilder.setMinScore(0.0d);
itemBuilder.setMaxScore(points);
} else if (itemBuilder instanceof KPrimAssessmentItemBuilder) {
itemBuilder.setMinScore(0.0d);
itemBuilder.setMaxScore(points);
} else if (itemBuilder instanceof MatchAssessmentItemBuilder) {
itemBuilder.setMinScore(0.0d);
itemBuilder.setMaxScore(points);
}
}
use of org.olat.ims.qti21.model.xml.interactions.KPrimAssessmentItemBuilder 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.KPrimAssessmentItemBuilder 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;
}
Aggregations