use of uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction in project OpenOLAT by OpenOLAT.
the class AssessmentItemBuilderTest method buildAssessmentItem_multipleChoice.
/**
* Check if a bare bone multiple choice created with our builder make a valid assessmentItem.
*
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void buildAssessmentItem_multipleChoice() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
MultipleChoiceAssessmentItemBuilder itemBuilder = new MultipleChoiceAssessmentItemBuilder("Multiple choice", "New answer", 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 ChoiceInteraction);
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction in project OpenOLAT by OpenOLAT.
the class SimpleChoiceAssessmentItemBuilder method getQuestionBlocks.
/**
* @return A copy of the list of blocks which make the question.
* The list is a copy and modification will not be persisted.
*/
public List<Block> getQuestionBlocks() {
List<Block> blocks = assessmentItem.getItemBody().getBlocks();
List<Block> questionBlocks = new ArrayList<>(blocks.size());
for (Block block : blocks) {
if (block instanceof ChoiceInteraction) {
break;
} else if (block != null) {
questionBlocks.add(block);
}
}
return questionBlocks;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction in project OpenOLAT by OpenOLAT.
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 uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method createSingleChoiceInteraction.
public static ChoiceInteraction createSingleChoiceInteraction(AssessmentItem assessmentItem, Identifier responseDeclarationId, Orientation orientation, List<String> classAtrr) {
ChoiceInteraction choiceInteraction = new ChoiceInteraction(assessmentItem.getItemBody());
choiceInteraction.setMaxChoices(1);
choiceInteraction.setShuffle(true);
if (orientation != null) {
choiceInteraction.setOrientation(orientation);
}
choiceInteraction.setResponseIdentifier(responseDeclarationId);
if (classAtrr != null && classAtrr.size() > 0) {
choiceInteraction.setClassAttr(classAtrr);
}
PromptGroup prompts = new PromptGroup(choiceInteraction);
choiceInteraction.getNodeGroups().add(prompts);
SimpleChoiceGroup singleChoices = new SimpleChoiceGroup(choiceInteraction);
choiceInteraction.getNodeGroups().add(singleChoices);
return choiceInteraction;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method appendChoiceInteraction.
public static ChoiceInteraction appendChoiceInteraction(ItemBody itemBody, Identifier responseDeclarationId, int maxChoices, boolean shuffle) {
ChoiceInteraction choiceInteraction = new ChoiceInteraction(itemBody);
choiceInteraction.setMaxChoices(maxChoices);
choiceInteraction.setShuffle(shuffle);
choiceInteraction.setResponseIdentifier(responseDeclarationId);
itemBody.getBlocks().add(choiceInteraction);
PromptGroup prompts = new PromptGroup(choiceInteraction);
choiceInteraction.getNodeGroups().add(prompts);
SimpleChoiceGroup singleChoices = new SimpleChoiceGroup(choiceInteraction);
choiceInteraction.getNodeGroups().add(singleChoices);
return choiceInteraction;
}
Aggregations