use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class QTI12To21Converter method convertItem.
/**
* @param item
* @return The name of the assesssmentItem file
*/
private boolean convertItem(QuestionItemImpl convertedQuestion, Item item) {
QItemTypeDAO qItemTypeDao = CoreSpringFactory.getImpl(QItemTypeDAO.class);
AssessmentItemBuilder itemBuilder = null;
int questionType = item.getQuestion().getType();
switch(questionType) {
case Question.TYPE_SC:
itemBuilder = convertSingleChoice(item);
convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.SC.name()));
break;
case Question.TYPE_MC:
itemBuilder = convertMultipleChoice(item);
convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.MC.name()));
break;
case Question.TYPE_KPRIM:
itemBuilder = convertKPrim(item);
convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.KPRIM.name()));
break;
case Question.TYPE_FIB:
itemBuilder = convertFIB(item);
convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.FIB.name()));
break;
case Question.TYPE_ESSAY:
itemBuilder = convertEssay(item);
convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.ESSAY.name()));
break;
}
if (itemBuilder != null) {
itemBuilder.build();
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
String itemId = IdentifierGenerator.newAsString(itemBuilder.getQuestionType().getPrefix());
File itemFile = new File(unzippedDirRoot, itemId + ".xml");
persistAssessmentObject(itemFile, assessmentItem);
appendResourceAndMetadata(item, itemBuilder, itemFile);
convertedQuestion.setRootFilename(itemFile.getName());
return true;
}
return false;
}
use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder in project OpenOLAT by OpenOLAT.
the class QTI12To21Converter method convertSingleChoice.
private AssessmentItemBuilder convertSingleChoice(Item item) {
SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "New answer", qtiSerializer);
convertItemBasics(item, itemBuilder);
itemBuilder.clearMapping();
itemBuilder.clearSimpleChoices();
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
Question question = item.getQuestion();
itemBuilder.setShuffle(question.isShuffle());
convertOrientation(question, itemBuilder);
List<Response> responses = question.getResponses();
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());
if (response.isCorrect()) {
itemBuilder.setCorrectAnswer(newChoice.getIdentifier());
}
}
convertFeedbackPerAnswers(item, itemBuilder, identToIdentifier);
double correctScore = question.getSingleCorrectScore();
if (correctScore >= 0.0d) {
itemBuilder.setMinScore(0.0d);
itemBuilder.setMaxScore(correctScore);
}
return itemBuilder;
}
use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder in project OpenOLAT by OpenOLAT.
the class QTI12To21Converter method convertFIB.
private AssessmentItemBuilder convertFIB(Item item) {
FIBAssessmentItemBuilder itemBuilder = new FIBAssessmentItemBuilder("Gap text", EntryType.text, qtiSerializer);
itemBuilder.setQuestion("");
itemBuilder.clearTextEntries();
convertItemBasics(item, itemBuilder);
Question question = item.getQuestion();
boolean singleCorrect = question.isSingleCorrect();
if (singleCorrect) {
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
} else {
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
}
itemBuilder.getMinScoreBuilder().setScore(new Double(question.getMinValue()));
itemBuilder.getMaxScoreBuilder().setScore(new Double(question.getMaxValue()));
List<Response> responses = question.getResponses();
StringBuilder sb = new StringBuilder();
for (Response response : responses) {
if (response instanceof FIBResponse) {
FIBResponse gap = (FIBResponse) response;
if (FIBResponse.TYPE_BLANK.equals(gap.getType())) {
String responseId = itemBuilder.generateResponseIdentifier();
StringBuilder entryString = new StringBuilder();
entryString.append(" <textentryinteraction responseidentifier=\"").append(responseId).append("\"");
TextEntry entry = itemBuilder.createTextEntry(responseId);
entry.setCaseSensitive("Yes".equals(gap.getCaseSensitive()));
if (gap.getMaxLength() > 0) {
entry.setExpectedLength(gap.getMaxLength());
entryString.append(" expectedlength=\"").append(gap.getMaxLength()).append("\"");
} else if (gap.getSize() > 0) {
entry.setExpectedLength(gap.getSize());
entryString.append(" expectedlength=\"").append(gap.getSize()).append("\"");
}
parseAlternatives(gap.getCorrectBlank(), gap.getPoints(), entry);
entryString.append("></textentryinteraction>");
sb.append(entryString);
} else if (FIBResponse.TYPE_CONTENT.equals(gap.getType())) {
Material text = gap.getContent();
String htmltext = text.renderAsHtmlForEditor();
htmltext = blockedHtml(htmltext);
sb.append(htmltext);
}
}
}
String fib = "<div>" + sb.toString() + "</div>";
itemBuilder.setQuestion(fib);
return itemBuilder;
}
Aggregations