use of uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction in project OpenOLAT by OpenOLAT.
the class HottextAssessmentItemBuilder method createAssessmentItem.
private static AssessmentItem createAssessmentItem(String title, String text, String hottext) {
AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.hottext, title);
// define correct answer
Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
Identifier correctResponseId = IdentifierGenerator.newAsIdentifier("ht");
List<Identifier> correctResponseIds = new ArrayList<>();
correctResponseIds.add(correctResponseId);
ResponseDeclaration responseDeclaration = createHottextCorrectResponseDeclaration(assessmentItem, responseDeclarationId, correctResponseIds);
assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
// outcomes
appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
// the single choice interaction
ItemBody itemBody = appendDefaultItemBody(assessmentItem);
HottextInteraction hottextInteraction = appendHottextInteraction(itemBody, responseDeclarationId, 0);
P p = new P(itemBody);
p.getInlines().add(new TextRun(p, text));
appendHottext(p, correctResponseId, hottext);
hottextInteraction.getBlockStatics().add(p);
// response processing
ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
return assessmentItem;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction in project OpenOLAT by OpenOLAT.
the class HottextAssessmentItemBuilder method extractHottextInteraction.
private void extractHottextInteraction() {
try (StringOutput sb = new StringOutput()) {
List<Block> blocks = assessmentItem.getItemBody().getBlocks();
for (Block block : blocks) {
if (block instanceof HottextInteraction) {
hottextInteraction = (HottextInteraction) block;
for (BlockStatic innerBlock : hottextInteraction.getBlockStatics()) {
serializeJqtiObject(innerBlock, sb);
}
responseIdentifier = hottextInteraction.getResponseIdentifier();
break;
}
}
question = sb.toString();
} catch (IOException e) {
log.error("", e);
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction in project openolat by klemens.
the class HottextAssessmentItemBuilderTest method readHottextAssessmentItem.
@Test
public void readHottextAssessmentItem() throws URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
URL itemUrl = AssessmentItemBuilderTest.class.getResource("resources/openolat/hottext-per-answer-11-4-0.xml");
AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
HottextAssessmentItemBuilder itemBuilder = new HottextAssessmentItemBuilder(assessmentItem, qtiSerializer);
// basic check ChoiceInteraction
AssessmentItem loadedItem = itemBuilder.getAssessmentItem();
List<Interaction> interactions = loadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(1, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof HottextInteraction);
// hot texts
Choice correct1 = itemBuilder.getChoice(Identifier.assumedLegal("htf9250a96f24bc8873c9cc54dfbaaaa"));
Assert.assertTrue(itemBuilder.isCorrect(correct1));
Choice correct2 = itemBuilder.getChoice(Identifier.assumedLegal("RESPONSE_3"));
Assert.assertTrue(itemBuilder.isCorrect(correct2));
Choice wrong1 = itemBuilder.getChoice(Identifier.assumedLegal("RESPONSE_2"));
Assert.assertFalse(itemBuilder.isCorrect(wrong1));
Choice wrong2 = itemBuilder.getChoice(Identifier.assumedLegal("RESPONSE_4"));
Assert.assertFalse(itemBuilder.isCorrect(wrong2));
// score
Double maxScore = itemBuilder.getMaxScoreBuilder().getScore();
Assert.assertEquals(3.0, maxScore.doubleValue(), 0.0001);
Double minScore = itemBuilder.getMinScoreBuilder().getScore();
Assert.assertEquals(0.0, minScore.doubleValue(), 0.0001);
// per answer
Assert.assertEquals(ScoreEvaluation.perAnswer, itemBuilder.getScoreEvaluationMode());
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction in project openolat by klemens.
the class HottextAssessmentItemBuilder method extractHottextInteraction.
private void extractHottextInteraction() {
try (StringOutput sb = new StringOutput()) {
List<Block> blocks = assessmentItem.getItemBody().getBlocks();
for (Block block : blocks) {
if (block instanceof HottextInteraction) {
hottextInteraction = (HottextInteraction) block;
for (BlockStatic innerBlock : hottextInteraction.getBlockStatics()) {
serializeJqtiObject(innerBlock, sb);
}
responseIdentifier = hottextInteraction.getResponseIdentifier();
break;
}
}
question = sb.toString();
} catch (IOException e) {
log.error("", e);
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction in project openolat by klemens.
the class AssessmentObjectVelocityRenderDecorator method isSingleChoice.
/**
* Check the maxChoices and the cardinality
* @param interaction
* @return
*/
public boolean isSingleChoice(Interaction interaction) {
if (interaction instanceof ChoiceInteraction) {
ChoiceInteraction choiceInteraction = (ChoiceInteraction) interaction;
boolean sc = choiceInteraction.getMaxChoices() == 1;
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(choiceInteraction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.hasCardinality(Cardinality.MULTIPLE)) {
return false;
}
return sc;
} else if (interaction instanceof HottextInteraction) {
HottextInteraction hottextInteraction = (HottextInteraction) interaction;
boolean sc = hottextInteraction.getMaxChoices() == 1;
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(hottextInteraction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.hasCardinality(Cardinality.MULTIPLE)) {
return false;
}
return sc;
} else if (interaction instanceof HotspotInteraction) {
HotspotInteraction hotspotInteraction = (HotspotInteraction) interaction;
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(hotspotInteraction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.hasCardinality(Cardinality.SINGLE)) {
return true;
}
return false;
}
return false;
}
Aggregations