use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder in project openolat by klemens.
the class QTI12To21Converter method convertMultipleChoice.
private AssessmentItemBuilder convertMultipleChoice(Item item) {
MultipleChoiceAssessmentItemBuilder itemBuilder = new MultipleChoiceAssessmentItemBuilder("Multiple choice", "New answer", qtiSerializer);
convertItemBasics(item, itemBuilder);
itemBuilder.clearMapping();
itemBuilder.clearSimpleChoices();
ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
Question question = item.getQuestion();
itemBuilder.setShuffle(question.isShuffle());
convertOrientation(question, itemBuilder);
boolean hasNegative = false;
List<Response> responses = question.getResponses();
for (Response response : responses) {
if (response.getPoints() < 0.0f) {
hasNegative = true;
}
}
boolean singleCorrect = question.isSingleCorrect();
Map<String, Identifier> identToIdentifier = new HashMap<>();
for (Response response : responses) {
String responseText = response.getContent().renderAsHtmlForEditor();
responseText = blockedHtml(responseText);
SimpleChoice newChoice;
if (StringHelper.isHtml(responseText)) {
newChoice = AssessmentItemFactory.createSimpleChoice(interaction, "", itemBuilder.getQuestionType().getPrefix());
htmlBuilder.appendHtml(newChoice, responseText);
} else {
newChoice = AssessmentItemFactory.createSimpleChoice(interaction, responseText, itemBuilder.getQuestionType().getPrefix());
}
itemBuilder.addSimpleChoice(newChoice);
identToIdentifier.put(response.getIdent(), newChoice.getIdentifier());
double score = response.getPoints();
if (singleCorrect) {
if (response.isCorrect()) {
itemBuilder.addCorrectAnswer(newChoice.getIdentifier());
}
if (score > 0.0f) {
itemBuilder.setMaxScore(score);
}
} else {
if ((hasNegative && response.getPoints() >= 0.0f) || (!hasNegative && response.getPoints() > 0.0f)) {
itemBuilder.addCorrectAnswer(newChoice.getIdentifier());
}
itemBuilder.setMapping(newChoice.getIdentifier(), score);
}
}
convertFeedbackPerAnswers(item, itemBuilder, identToIdentifier);
if (singleCorrect) {
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
} else {
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
if (question instanceof ChoiceQuestion) {
ChoiceQuestion choice = (ChoiceQuestion) question;
itemBuilder.setMinScore(new Double(choice.getMinValue()));
itemBuilder.setMaxScore(new Double(choice.getMaxValue()));
}
}
return itemBuilder;
}
use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder in project openolat by klemens.
the class QTI12To21Converter method convertEssay.
private AssessmentItemBuilder convertEssay(Item item) {
EssayAssessmentItemBuilder itemBuilder = new EssayAssessmentItemBuilder("Essay", qtiSerializer);
convertItemBasics(item, itemBuilder);
EssayQuestion question = (EssayQuestion) item.getQuestion();
EssayResponse response = question.getEssayResponse();
int cols = response.getColumns();
int rows = response.getRows();
itemBuilder.setExpectedLength(cols * rows);
itemBuilder.setExpectedLines(rows);
double score = question.getMaxValue();
itemBuilder.setMinScore(0.0d);
itemBuilder.setMaxScore(score);
return itemBuilder;
}
use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder in project openolat by klemens.
the class QTI21QPoolServiceProvider method importExcelItem.
public QuestionItemImpl importExcelItem(Identity owner, AssessmentItemAndMetadata itemAndMetadata, Locale defaultLocale) {
QTI21ImportProcessor processor = new QTI21ImportProcessor(owner, defaultLocale);
String editor = itemAndMetadata.getEditor();
String editorVersion = itemAndMetadata.getEditorVersion();
AssessmentItemBuilder itemBuilder = itemAndMetadata.getItemBuilder();
itemBuilder.build();
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
QuestionItemImpl qitem = processor.processItem(assessmentItem, null, null, editor, editorVersion, itemAndMetadata);
String originalItemFilename = qitem.getRootFilename();
File itemStorage = qpoolFileStorage.getDirectory(qitem.getDirectory());
File itemFile = new File(itemStorage, originalItemFilename);
qtiService.persistAssessmentObject(itemFile, assessmentItem);
// create manifest
ManifestBuilder manifest = ManifestBuilder.createAssessmentItemBuilder();
ResourceType resource = manifest.appendAssessmentItem(UUID.randomUUID().toString(), originalItemFilename);
ManifestMetadataBuilder metadataBuilder = manifest.getMetadataBuilder(resource, true);
itemAndMetadata.toBuilder(metadataBuilder, defaultLocale);
manifest.write(new File(itemStorage, "imsmanifest.xml"));
return qitem;
}
use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder 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.AssessmentItemBuilder in project openolat by klemens.
the class CSVToAssessmentItemConverter method processCorrectSolution.
private void processCorrectSolution(String[] parts) {
if (currentItem == null || parts.length < 2)
return;
String feedback = parts[1];
if (StringHelper.containsNonWhitespace(feedback)) {
AssessmentItemBuilder itemBuilder = currentItem.getItemBuilder();
itemBuilder.createCorrectSolutionFeedback().setText(feedback);
}
}
Aggregations