use of uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction in project OpenOLAT by OpenOLAT.
the class AssessmentHtmlBuilderTest method filter_alt.
@Test
public void filter_alt() {
String content = "<p>Test <textEntryInteraction responseIdentifier=\"RESPONSE_1\"/> </p>";
AssessmentItem item = new AssessmentItem();
ItemBody helper = new ItemBody(item);
new AssessmentHtmlBuilder().appendHtml(helper, content);
List<Interaction> interactions = helper.findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(1, interactions.size());
Interaction interaction = interactions.get(0);
Assert.assertTrue(interaction instanceof TextEntryInteraction);
Assert.assertNotNull(interaction.getResponseIdentifier());
Assert.assertEquals("RESPONSE_1", interaction.getResponseIdentifier().toString());
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction in project OpenOLAT by OpenOLAT.
the class AssessmentItemBuilderTest method buildAssessmentItem_gap.
@Test
public void buildAssessmentItem_gap() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
FIBAssessmentItemBuilder itemBuilder = new FIBAssessmentItemBuilder("Gap text", EntryType.text, qtiSerializer);
if (build.booleanValue()) {
itemBuilder.build();
}
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
ItemValidationResult itemResult = serializeAndReload(assessmentItem);
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 TextEntryInteraction);
TextEntryInteraction interaction = (TextEntryInteraction) interactions.get(0);
Assert.assertNotNull(interaction.getResponseIdentifier());
ResponseDeclaration responseDeclaration = reloadedItem.getResponseDeclaration(interaction.getResponseIdentifier());
Assert.assertNotNull(responseDeclaration);
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method appendTextEntryInteraction.
public static TextEntryInteraction appendTextEntryInteraction(ItemBody itemBody, Identifier responseDeclarationId) {
P paragraph = new P(itemBody);
TextRun text = new TextRun(paragraph, "New text");
paragraph.getInlines().add(text);
TextEntryInteraction textInteraction = new TextEntryInteraction(paragraph);
textInteraction.setResponseIdentifier(responseDeclarationId);
paragraph.getInlines().add(textInteraction);
itemBody.getBlocks().add(paragraph);
return textInteraction;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction in project OpenOLAT by OpenOLAT.
the class TextEntryInteractionArchive method writeInteractionData.
@Override
public int writeInteractionData(AssessmentItem item, AssessmentResponse response, Interaction interaction, int itemNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
String stringuifiedResponses = response == null ? null : response.getStringuifiedResponse();
if (StringHelper.containsNonWhitespace(stringuifiedResponses)) {
TextEntryInteraction textEntryInteraction = (TextEntryInteraction) interaction;
AbstractEntry correctAnswers = CorrectResponsesUtil.getCorrectTextResponses(item, textEntryInteraction);
stringuifiedResponses = CorrectResponsesUtil.stripResponse(stringuifiedResponses);
boolean correct = correctAnswers.match(stringuifiedResponses);
if (correct) {
dataRow.addCell(col++, stringuifiedResponses, workbook.getStyles().getCorrectStyle());
} else {
dataRow.addCell(col++, stringuifiedResponses, null);
}
} else {
col++;
}
return col;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction in project openolat by klemens.
the class FIBAssessmentItemBuilder method extractEntriesSettingsFromResponseDeclaration.
/**
* We loop around the textEntryInteraction, search the responseDeclaration. responseDeclaration
* of type string are gap text, of type float are numerical.
*/
public void extractEntriesSettingsFromResponseDeclaration() {
DoubleAdder mappedScore = new DoubleAdder();
AtomicInteger countAlternatives = new AtomicInteger(0);
responseIdentifierToTextEntry = new HashMap<>();
List<Interaction> interactions = assessmentItem.getItemBody().findInteractions();
for (Interaction interaction : interactions) {
if (interaction instanceof TextEntryInteraction && interaction.getResponseIdentifier() != null) {
AbstractEntry entry = null;
TextEntryInteraction textInteraction = (TextEntryInteraction) interaction;
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
if (responseDeclaration != null) {
if (responseDeclaration.hasBaseType(BaseType.STRING) && responseDeclaration.hasCardinality(Cardinality.SINGLE)) {
TextEntry textEntry = new TextEntry(textInteraction);
extractTextEntrySettingsFromResponseDeclaration(textEntry, responseDeclaration, countAlternatives, mappedScore);
String marker = "responseIdentifier=\"" + interaction.getResponseIdentifier().toString() + "\"";
question = question.replace(marker, marker + " openolatType=\"string\"");
if (StringHelper.containsNonWhitespace(textEntry.getSolution())) {
question = question.replace(marker, marker + " data-qti-solution=\"" + escapeForDataQtiSolution(textEntry.getSolution()) + "\"");
}
entry = textEntry;
} else if (responseDeclaration.hasBaseType(BaseType.FLOAT) && responseDeclaration.hasCardinality(Cardinality.SINGLE)) {
NumericalEntry numericalEntry = new NumericalEntry(textInteraction);
entry = numericalEntry;
extractNumericalEntrySettings(assessmentItem, numericalEntry, responseDeclaration, countAlternatives, mappedScore);
String marker = "responseIdentifier=\"" + interaction.getResponseIdentifier().toString() + "\"";
question = question.replace(marker, marker + " openolatType=\"float\"");
if (numericalEntry.getSolution() != null) {
question = question.replace(marker, marker + " data-qti-solution=\"" + Double.toString(numericalEntry.getSolution()) + "\"");
}
}
}
if (entry != null) {
responseIdentifierToTextEntry.put(interaction.getResponseIdentifier().toString(), entry);
}
}
}
boolean hasMapping = Math.abs(mappedScore.doubleValue() - (-1.0 * countAlternatives.get())) > 0.0001;
scoreEvaluation = hasMapping ? ScoreEvaluation.perAnswer : ScoreEvaluation.allCorrectAnswers;
}
Aggregations