use of uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction in project OpenOLAT by OpenOLAT.
the class KPrimAssessmentItemBuilder method createAssessmentItem.
private static AssessmentItem createAssessmentItem(String title, String defaultAnswer) {
AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.kprim, title);
NodeGroupList nodeGroups = assessmentItem.getNodeGroups();
double maxScore = 1.0d;
Identifier responseDeclarationId = Identifier.assumedLegal("KPRIM_RESPONSE_1");
// define correct answer
ResponseDeclaration responseDeclaration = createKPrimResponseDeclaration(assessmentItem, responseDeclarationId, new HashMap<>(), maxScore);
nodeGroups.getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
appendDefaultOutcomeDeclarations(assessmentItem, maxScore);
// the single choice interaction
ItemBody itemBody = appendDefaultItemBody(assessmentItem);
MatchInteraction matchInteraction = appendMatchInteractionForKPrim(itemBody, responseDeclarationId, defaultAnswer);
List<String> cssClasses = new ArrayList<>();
cssClasses.add(QTI21Constants.CSS_MATCH_KPRIM);
matchInteraction.setClassAttr(cssClasses);
SimpleMatchSet matchSet = matchInteraction.getSimpleMatchSets().get(0);
Map<Identifier, Identifier> associations = new HashMap<>();
for (SimpleAssociableChoice choice : matchSet.getSimpleAssociableChoices()) {
associations.put(choice.getIdentifier(), QTI21Constants.WRONG_IDENTIFIER);
}
appendAssociationKPrimResponseDeclaration(responseDeclaration, associations, 1.0);
// response processing
ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
return assessmentItem;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction in project OpenOLAT by OpenOLAT.
the class MatchAssessmentItemBuilder method createAssessmentItem.
private static AssessmentItem createAssessmentItem(String title, String matchCssClass, String unanswered, String right, String wrong) {
AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.match, title);
NodeGroupList nodeGroups = assessmentItem.getNodeGroups();
double maxScore = 1.0d;
Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
// define correct answer
ResponseDeclaration responseDeclaration = createMatchResponseDeclaration(assessmentItem, responseDeclarationId, new HashMap<>());
nodeGroups.getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
appendDefaultOutcomeDeclarations(assessmentItem, maxScore);
// the single choice interaction
ItemBody itemBody = appendDefaultItemBody(assessmentItem);
Map<Identifier, List<Identifier>> associations = new HashMap<>();
MatchInteraction interaction;
if (QTI21Constants.CSS_MATCH_TRUE_FALSE.equals(matchCssClass)) {
interaction = appendMatchInteractionTrueFalse(itemBody, unanswered, right, wrong, responseDeclarationId);
// default correct answers set to "right"
SimpleAssociableChoice rightChoice = interaction.getSimpleMatchSets().get(1).getSimpleAssociableChoices().get(1);
List<SimpleAssociableChoice> sourceChoices = interaction.getSimpleMatchSets().get(0).getSimpleAssociableChoices();
for (SimpleAssociableChoice sourceChoice : sourceChoices) {
List<Identifier> targetIdentifiers = new ArrayList<>();
targetIdentifiers.add(rightChoice.getIdentifier());
associations.put(sourceChoice.getIdentifier(), targetIdentifiers);
}
} else {
interaction = appendMatchInteraction(itemBody, responseDeclarationId);
}
List<String> cssClasses = new ArrayList<>();
cssClasses.add(matchCssClass);
interaction.setClassAttr(cssClasses);
appendAssociationMatchResponseDeclaration(responseDeclaration, associations);
// response processing
ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
return assessmentItem;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction in project OpenOLAT by OpenOLAT.
the class MatchAssessmentItemBuilder method extractMatchInteraction.
private void extractMatchInteraction() {
try (StringOutput sb = new StringOutput()) {
List<Block> blocks = assessmentItem.getItemBody().getBlocks();
for (Block block : blocks) {
if (block instanceof MatchInteraction) {
matchInteraction = (MatchInteraction) block;
responseIdentifier = matchInteraction.getResponseIdentifier();
shuffle = matchInteraction.getShuffle();
break;
} else {
serializeJqtiObject(block, sb);
}
}
question = sb.toString();
} catch (IOException e) {
log.error("", e);
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method appendMatchInteraction.
public static MatchInteraction appendMatchInteraction(ItemBody itemBody, Identifier responseDeclarationId) {
MatchInteraction matchInteraction = new MatchInteraction(itemBody);
matchInteraction.setResponseIdentifier(responseDeclarationId);
matchInteraction.setMaxAssociations(0);
matchInteraction.setShuffle(false);
itemBody.getBlocks().add(matchInteraction);
PromptGroup prompts = new PromptGroup(matchInteraction);
matchInteraction.getNodeGroups().add(prompts);
SimpleMatchSet sourceMatchSet = new SimpleMatchSet(matchInteraction);
matchInteraction.getSimpleMatchSets().add(sourceMatchSet);
String[] sources = new String[] { "A", "B" };
for (int i = 0; i < sources.length; i++) {
SimpleAssociableChoice sourceChoice = new SimpleAssociableChoice(sourceMatchSet);
sourceChoice.setMatchMax(0);
sourceChoice.setMatchMin(0);
sourceChoice.setIdentifier(IdentifierGenerator.newNumberAsIdentifier(sources[i]));
P question = getParagraph(sourceChoice, sources[i]);
sourceChoice.getFlowStatics().add(question);
sourceMatchSet.getSimpleAssociableChoices().add(sourceChoice);
}
SimpleMatchSet targetMatchSet = new SimpleMatchSet(matchInteraction);
matchInteraction.getSimpleMatchSets().add(targetMatchSet);
String[] targets = new String[] { "M", "N" };
for (int i = 0; i < targets.length; i++) {
SimpleAssociableChoice targetChoice = new SimpleAssociableChoice(sourceMatchSet);
targetChoice.setMatchMax(0);
targetChoice.setMatchMin(0);
targetChoice.setIdentifier(IdentifierGenerator.newNumberAsIdentifier(targets[i]));
P question = getParagraph(targetChoice, targets[i]);
targetChoice.getFlowStatics().add(question);
targetMatchSet.getSimpleAssociableChoices().add(targetChoice);
}
return matchInteraction;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction in project openolat by klemens.
the class KPrimAssessmentItemBuilder 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 MatchInteraction) {
break;
} else {
questionBlocks.add(block);
}
}
return questionBlocks;
}
Aggregations