use of uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun in project openolat by klemens.
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.content.basic.TextRun in project OpenOLAT by OpenOLAT.
the class AssessmentObjectComponentRenderer method renderMath.
protected void renderMath(AssessmentRenderer renderer, StringOutput out, AssessmentObjectComponent component, ResolvedAssessmentItem resolvedAssessmentItem, ItemSessionState itemSessionState, QtiNode mathElement) {
if (mathElement instanceof ForeignElement) {
ForeignElement fElement = (ForeignElement) mathElement;
boolean mi = fElement.getQtiClassName().equals("mi");
boolean ci = fElement.getQtiClassName().equals("ci");
if (ci || mi) {
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
String text = contentAsString(fElement);
Identifier identifier = Identifier.assumedLegal(text);
Value templateValue = getTemplateValue(itemSessionState, text);
Value outcomeValue = getOutcomeValue(itemSessionState, text);
Value responseValue = getResponseValue(assessmentItem, itemSessionState, identifier, renderer.isSolutionMode());
if (templateValue != null && isTemplateDeclarationAMathVariable(assessmentItem, text)) {
if (ci) {
substituteCi(out, templateValue);
} else if (mi) {
substituteMi(out, templateValue);
}
} else if (outcomeValue != null) {
if (ci) {
substituteCi(out, outcomeValue);
} else if (mi) {
substituteMi(out, outcomeValue);
}
} else if (responseValue != null) {
if (ci) {
substituteCi(out, responseValue);
} else if (mi) {
substituteMi(out, responseValue);
}
} else {
renderStartHtmlTag(out, component, resolvedAssessmentItem, fElement, null);
fElement.getChildren().forEach((child) -> renderMath(renderer, out, component, resolvedAssessmentItem, itemSessionState, child));
renderEndTag(out, fElement);
}
} else {
renderStartHtmlTag(out, component, resolvedAssessmentItem, fElement, null);
fElement.getChildren().forEach((child) -> renderMath(renderer, out, component, resolvedAssessmentItem, itemSessionState, child));
renderEndTag(out, fElement);
}
} else if (mathElement instanceof TextRun) {
out.append(((TextRun) mathElement).getTextContent());
}
}
use of uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method appendMatchInteractionForKPrim.
public static MatchInteraction appendMatchInteractionForKPrim(ItemBody itemBody, Identifier responseDeclarationId, String defaultAnswer) {
MatchInteraction matchInteraction = new MatchInteraction(itemBody);
matchInteraction.setResponseIdentifier(responseDeclarationId);
matchInteraction.setMaxAssociations(4);
matchInteraction.setShuffle(false);
itemBody.getBlocks().add(matchInteraction);
PromptGroup prompts = new PromptGroup(matchInteraction);
matchInteraction.getNodeGroups().add(prompts);
SimpleMatchSet questionMatchSet = new SimpleMatchSet(matchInteraction);
matchInteraction.getSimpleMatchSets().add(questionMatchSet);
String[] classic = new String[] { "a", "b", "c", "d" };
for (int i = 0; i < 4; i++) {
SimpleAssociableChoice correctChoice = new SimpleAssociableChoice(questionMatchSet);
correctChoice.setMatchMax(1);
correctChoice.setMatchMin(1);
correctChoice.setIdentifier(IdentifierGenerator.newNumberAsIdentifier(classic[i]));
P question = getParagraph(correctChoice, defaultAnswer + " " + classic[i]);
correctChoice.getFlowStatics().add(question);
questionMatchSet.getSimpleAssociableChoices().add(correctChoice);
}
SimpleMatchSet correctWrongMatchSet = new SimpleMatchSet(matchInteraction);
matchInteraction.getSimpleMatchSets().add(correctWrongMatchSet);
SimpleAssociableChoice correctChoice = new SimpleAssociableChoice(correctWrongMatchSet);
correctChoice.setMatchMax(4);
correctChoice.setFixed(Boolean.TRUE);
correctChoice.setIdentifier(QTI21Constants.CORRECT_IDENTIFIER);
correctChoice.getFlowStatics().add(new TextRun(correctChoice, "+"));
correctWrongMatchSet.getSimpleAssociableChoices().add(correctChoice);
SimpleAssociableChoice wrongChoice = new SimpleAssociableChoice(correctWrongMatchSet);
wrongChoice.setMatchMax(4);
wrongChoice.setFixed(Boolean.TRUE);
wrongChoice.setIdentifier(QTI21Constants.WRONG_IDENTIFIER);
wrongChoice.getFlowStatics().add(new TextRun(correctChoice, "-"));
correctWrongMatchSet.getSimpleAssociableChoices().add(wrongChoice);
return matchInteraction;
}
use of uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun 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.content.basic.TextRun in project openolat by klemens.
the class AssessmentHtmlBuilderTest method serializer.
@Test
public void serializer() {
AssessmentItem item = new AssessmentItem();
SimpleChoice helper = new SimpleChoice(item);
P p = new P(helper);
TextRun text = new TextRun(p, "Hello world");
p.getInlines().add(text);
helper.getFlowStatics().add(p);
String content = new AssessmentHtmlBuilder().flowStaticString(helper.getFlowStatics());
Assert.assertTrue(content.contains(">Hello world<"));
}
Aggregations