use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry in project openolat by klemens.
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;
}
use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry in project openolat by klemens.
the class CSVToAssessmentItemConverter method processChoice_fib.
private void processChoice_fib(String[] parts, FIBAssessmentItemBuilder fibBuilder) {
String firstPart = parts[0].toLowerCase();
if ("text".equals(firstPart) || "texte".equals(firstPart)) {
String text = parts[1];
if (StringHelper.containsNonWhitespace(fibBuilder.getQuestion())) {
fibBuilder.setQuestion(fibBuilder.getQuestion() + " " + text);
} else {
fibBuilder.setQuestion(text);
}
} else {
double score = parseFloat(parts[0], 1.0f);
String correctBlank = parts[1];
String responseId = fibBuilder.generateResponseIdentifier();
TextEntry textEntry = fibBuilder.createTextEntry(responseId);
parseAlternatives(correctBlank, score, textEntry);
if (parts.length > 2) {
String sizes = parts[2];
String[] sizeArr = sizes.split(",");
if (sizeArr.length >= 2) {
int size = Integer.parseInt(sizeArr[0]);
textEntry.setExpectedLength(size);
}
}
String entry = " <textEntryInteraction responseIdentifier=\"" + responseId + "\"/>";
fibBuilder.setQuestion(fibBuilder.getQuestion() + " " + entry);
}
}
use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry in project openolat by klemens.
the class FIBEditorController method createEntry.
private AbstractEntry createEntry(String responseIdentifier, String selectedText, String type, boolean newEntry) {
AbstractEntry interaction = null;
if ("string".equalsIgnoreCase(type)) {
TextEntry textInteraction = itemBuilder.createTextEntry(responseIdentifier);
if (StringHelper.containsNonWhitespace(selectedText)) {
String[] alternatives = selectedText.split(",");
for (String alternative : alternatives) {
if (StringHelper.containsNonWhitespace(alternative)) {
alternative = alternative.trim();
if (textInteraction.getSolution() == null) {
textInteraction.setSolution(alternative);
} else {
textInteraction.addAlternative(alternative, textInteraction.getScore());
}
}
}
if (alternatives.length > 0) {
String solution = alternatives[0];
if (newEntry && "gap".equals(solution)) {
solution = "";
}
textInteraction.setSolution(solution);
}
}
interaction = textInteraction;
} else if ("float".equalsIgnoreCase(type)) {
NumericalEntry numericalInteraction = itemBuilder.createNumericalEntry(responseIdentifier);
if (newEntry && "gap".equals(selectedText)) {
// skip it, it's a placeholder
} else if (StringHelper.containsNonWhitespace(selectedText)) {
try {
Double val = Double.parseDouble(selectedText.trim());
numericalInteraction.setSolution(val);
} catch (NumberFormatException e) {
//
}
}
interaction = numericalInteraction;
}
return interaction;
}
use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry in project openolat by klemens.
the class FIBEditorController method doGapEntry.
private void doGapEntry(UserRequest ureq, String responseIdentifier, String selectedText, String emptySolution, String type, boolean newEntry) {
if (textEntrySettingsCtrl != null || numericalEntrySettingsCtrl != null)
return;
AbstractEntry interaction = itemBuilder.getEntry(responseIdentifier);
if (interaction == null) {
interaction = createEntry(responseIdentifier, selectedText, type, newEntry);
} else if (StringHelper.containsNonWhitespace(selectedText)) {
updateSolution(interaction, selectedText, emptySolution);
}
if (interaction instanceof TextEntry) {
textEntrySettingsCtrl = new FIBTextEntrySettingsController(ureq, getWindowControl(), (TextEntry) interaction, restrictedEdit, readOnly);
listenTo(textEntrySettingsCtrl);
cmc = new CloseableModalController(getWindowControl(), translate("close"), textEntrySettingsCtrl.getInitialComponent(), true, translate("title.add"));
cmc.activate();
listenTo(cmc);
} else if (interaction instanceof NumericalEntry) {
numericalEntrySettingsCtrl = new FIBNumericalEntrySettingsController(ureq, getWindowControl(), (NumericalEntry) interaction, restrictedEdit, readOnly);
listenTo(numericalEntrySettingsCtrl);
cmc = new CloseableModalController(getWindowControl(), translate("close"), numericalEntrySettingsCtrl.getInitialComponent(), true, translate("title.add"));
cmc.activate();
listenTo(cmc);
}
}
use of org.olat.ims.qti21.model.xml.interactions.FIBAssessmentItemBuilder.TextEntry in project OpenOLAT by OpenOLAT.
the class FIBEditorController method createEntry.
private AbstractEntry createEntry(String responseIdentifier, String selectedText, String type, boolean newEntry) {
AbstractEntry interaction = null;
if ("string".equalsIgnoreCase(type)) {
TextEntry textInteraction = itemBuilder.createTextEntry(responseIdentifier);
if (StringHelper.containsNonWhitespace(selectedText)) {
String[] alternatives = selectedText.split(",");
for (String alternative : alternatives) {
if (StringHelper.containsNonWhitespace(alternative)) {
alternative = alternative.trim();
if (textInteraction.getSolution() == null) {
textInteraction.setSolution(alternative);
} else {
textInteraction.addAlternative(alternative, textInteraction.getScore());
}
}
}
if (alternatives.length > 0) {
String solution = alternatives[0];
if (newEntry && "gap".equals(solution)) {
solution = "";
}
textInteraction.setSolution(solution);
}
}
interaction = textInteraction;
} else if ("float".equalsIgnoreCase(type)) {
NumericalEntry numericalInteraction = itemBuilder.createNumericalEntry(responseIdentifier);
if (newEntry && "gap".equals(selectedText)) {
// skip it, it's a placeholder
} else if (StringHelper.containsNonWhitespace(selectedText)) {
try {
Double val = Double.parseDouble(selectedText.trim());
numericalInteraction.setSolution(val);
} catch (NumberFormatException e) {
//
}
}
interaction = numericalInteraction;
}
return interaction;
}
Aggregations