Search in sources :

Example 6 with TextRun

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;
}
Also used : P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) TextRun(uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun)

Example 7 with TextRun

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());
    }
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ForeignElement(uk.ac.ed.ph.jqtiplus.node.ForeignElement) AssessmentRenderFunctions.getOutcomeValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getOutcomeValue) AssessmentRenderFunctions.extractRecordFieldValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.extractRecordFieldValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) AssessmentRenderFunctions.getHtmlAttributeValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getHtmlAttributeValue) AssessmentRenderFunctions.renderOrderedCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderOrderedCardinalityValue) AssessmentRenderFunctions.isMultipleCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isMultipleCardinalityValue) AssessmentRenderFunctions.renderSingleCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderSingleCardinalityValue) AssessmentRenderFunctions.renderMultipleCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderMultipleCardinalityValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) AssessmentRenderFunctions.getTemplateValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getTemplateValue) AssessmentRenderFunctions.renderRecordCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.renderRecordCardinalityValue) AssessmentRenderFunctions.getResponseValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getResponseValue) AssessmentRenderFunctions.isNullValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isNullValue) AssessmentRenderFunctions.isSingleCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isSingleCardinalityValue) AssessmentRenderFunctions.isRecordCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isRecordCardinalityValue) AssessmentRenderFunctions.isOrderedCardinalityValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isOrderedCardinalityValue) AssessmentRenderFunctions.isMathsContentValue(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isMathsContentValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString) TextRun(uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun)

Example 8 with TextRun

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;
}
Also used : MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) SimpleMatchSet(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet) P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) PromptGroup(uk.ac.ed.ph.jqtiplus.group.item.interaction.PromptGroup) TextRun(uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun)

Example 9 with TextRun

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;
}
Also used : P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) AssessmentItemFactory.appendDefaultItemBody(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendDefaultItemBody) ItemBody(uk.ac.ed.ph.jqtiplus.node.content.ItemBody) ArrayList(java.util.ArrayList) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) HottextInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.HottextInteraction) AssessmentItemFactory.appendHottextInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendHottextInteraction) TextRun(uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun) AssessmentItemFactory.createResponseProcessing(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing) ResponseProcessing(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createHottextCorrectResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createHottextCorrectResponseDeclaration)

Example 10 with TextRun

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<"));
}
Also used : P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) SimpleChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) TextRun(uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun) Test(org.junit.Test)

Aggregations

TextRun (uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun)14 P (uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P)10 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)6 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)4 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 AssessmentItemFactory.appendDefaultItemBody (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendDefaultItemBody)2 AssessmentItemFactory.appendHottextInteraction (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendHottextInteraction)2 AssessmentItemFactory.createHottextCorrectResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createHottextCorrectResponseDeclaration)2 AssessmentItemFactory.createResponseProcessing (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing)2 AssessmentRenderFunctions.contentAsString (org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString)2 AssessmentRenderFunctions.extractRecordFieldValue (org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.extractRecordFieldValue)2 AssessmentRenderFunctions.getHtmlAttributeValue (org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getHtmlAttributeValue)2 AssessmentRenderFunctions.getOutcomeValue (org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getOutcomeValue)2 AssessmentRenderFunctions.getResponseValue (org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getResponseValue)2 AssessmentRenderFunctions.getTemplateValue (org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getTemplateValue)2 AssessmentRenderFunctions.isMathsContentValue (org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isMathsContentValue)2 AssessmentRenderFunctions.isMultipleCardinalityValue (org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isMultipleCardinalityValue)2 AssessmentRenderFunctions.isNullValue (org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isNullValue)2 AssessmentRenderFunctions.isOrderedCardinalityValue (org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.isOrderedCardinalityValue)2