Search in sources :

Example 96 with ResponseDeclaration

use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration in project OpenOLAT by OpenOLAT.

the class SingleChoiceAssessmentItemBuilder method extract.

@Override
public void extract() {
    super.extract();
    if (choiceInteraction != null) {
        ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(choiceInteraction.getResponseIdentifier());
        if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
            CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
            List<FieldValue> values = correctResponse.getFieldValues();
            Value value = FieldValue.computeValue(Cardinality.SINGLE, values);
            if (value instanceof IdentifierValue) {
                IdentifierValue identifierValue = (IdentifierValue) value;
                correctAnswer = identifierValue.identifierValue();
            }
        }
    }
}
Also used : BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) AssessmentItemFactory.createSingleChoiceCorrectResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createSingleChoiceCorrectResponseDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 97 with ResponseDeclaration

use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration in project OpenOLAT by OpenOLAT.

the class DrawingAssessmentItemBuilder method buildResponseAndOutcomeDeclarations.

@Override
protected void buildResponseAndOutcomeDeclarations() {
    ResponseDeclaration responseDeclaration = createDrawingResponseDeclaration(assessmentItem, responseIdentifier);
    assessmentItem.getResponseDeclarations().add(responseDeclaration);
}
Also used : ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createDrawingResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createDrawingResponseDeclaration)

Example 98 with ResponseDeclaration

use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration in project OpenOLAT by OpenOLAT.

the class FIBAssessmentItemBuilder method extractEntriesSettingsFromResponseDeclaration.

/**
 * We loop around the textEntryInteraction, search the responseDeclaration. responseDeclaration
 * of type string are gap text, of type float are numerical.
 */
public void extractEntriesSettingsFromResponseDeclaration() {
    DoubleAdder mappedScore = new DoubleAdder();
    AtomicInteger countAlternatives = new AtomicInteger(0);
    responseIdentifierToTextEntry = new HashMap<>();
    List<Interaction> interactions = assessmentItem.getItemBody().findInteractions();
    for (Interaction interaction : interactions) {
        if (interaction instanceof TextEntryInteraction && interaction.getResponseIdentifier() != null) {
            AbstractEntry entry = null;
            TextEntryInteraction textInteraction = (TextEntryInteraction) interaction;
            ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
            if (responseDeclaration != null) {
                if (responseDeclaration.hasBaseType(BaseType.STRING) && responseDeclaration.hasCardinality(Cardinality.SINGLE)) {
                    TextEntry textEntry = new TextEntry(textInteraction);
                    extractTextEntrySettingsFromResponseDeclaration(textEntry, responseDeclaration, countAlternatives, mappedScore);
                    String marker = "responseIdentifier=\"" + interaction.getResponseIdentifier().toString() + "\"";
                    question = question.replace(marker, marker + " openolatType=\"string\"");
                    if (StringHelper.containsNonWhitespace(textEntry.getSolution())) {
                        question = question.replace(marker, marker + " data-qti-solution=\"" + escapeForDataQtiSolution(textEntry.getSolution()) + "\"");
                    }
                    entry = textEntry;
                } else if (responseDeclaration.hasBaseType(BaseType.FLOAT) && responseDeclaration.hasCardinality(Cardinality.SINGLE)) {
                    NumericalEntry numericalEntry = new NumericalEntry(textInteraction);
                    entry = numericalEntry;
                    extractNumericalEntrySettings(assessmentItem, numericalEntry, responseDeclaration, countAlternatives, mappedScore);
                    String marker = "responseIdentifier=\"" + interaction.getResponseIdentifier().toString() + "\"";
                    question = question.replace(marker, marker + " openolatType=\"float\"");
                    if (numericalEntry.getSolution() != null) {
                        question = question.replace(marker, marker + " data-qti-solution=\"" + Double.toString(numericalEntry.getSolution()) + "\"");
                    }
                }
            }
            if (entry != null) {
                responseIdentifierToTextEntry.put(interaction.getResponseIdentifier().toString(), entry);
            }
        }
    }
    boolean hasMapping = Math.abs(mappedScore.doubleValue() - (-1.0 * countAlternatives.get())) > 0.0001;
    scoreEvaluation = hasMapping ? ScoreEvaluation.perAnswer : ScoreEvaluation.allCorrectAnswers;
}
Also used : DoubleAdder(java.util.concurrent.atomic.DoubleAdder) AssessmentItemFactory.appendTextEntryInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendTextEntryInteraction) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssessmentItemFactory.appendTextEntryInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendTextEntryInteraction) TextEntryInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.TextEntryInteraction) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) AssessmentItemFactory.createNumericalEntryResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createNumericalEntryResponseDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createTextEntryResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createTextEntryResponseDeclaration)

Example 99 with ResponseDeclaration

use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration in project OpenOLAT by OpenOLAT.

the class AssessmentItemChecker method checkSetCorrectResponse.

/**
 * responseDeclaration -> float
 *
 * templateVraiable -> integer
 *
 * setCorrectResponse
 *   -> variable -> integer doesn't match float -> issue
 * @param item
 * @return
 */
private static boolean checkSetCorrectResponse(AssessmentItem item) {
    boolean allOk = true;
    List<SetCorrectResponse> setCorrectResponses = QueryUtils.search(SetCorrectResponse.class, item);
    for (SetCorrectResponse setCorrectResponse : setCorrectResponses) {
        Identifier responseIdentifier = setCorrectResponse.getIdentifier();
        ResponseDeclaration responseDeclaration = item.getResponseDeclaration(responseIdentifier);
        BaseType baseType = responseDeclaration.getBaseType();
        Expression expression = setCorrectResponse.getExpression();
        if (expression instanceof Variable) {
            Variable variable = (Variable) expression;
            ComplexReferenceIdentifier cpxVariableIdentifier = variable.getIdentifier();
            Identifier variableIdentifier = Identifier.assumedLegal(cpxVariableIdentifier.toString());
            TemplateDeclaration templateDeclaration = item.getTemplateDeclaration(variableIdentifier);
            if (templateDeclaration != null && !templateDeclaration.hasBaseType(baseType)) {
                templateDeclaration.setBaseType(baseType);
                allOk &= false;
            }
        }
    }
    return allOk;
}
Also used : ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) SetCorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.template.processing.SetCorrectResponse) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) BaseType(uk.ac.ed.ph.jqtiplus.value.BaseType) Expression(uk.ac.ed.ph.jqtiplus.node.expression.Expression) TemplateDeclaration(uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 100 with ResponseDeclaration

use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration in project OpenOLAT by OpenOLAT.

the class AssessmentItemBuilder method buildHint.

/**
 * @param outcomeDeclarations
 * @param responseRules
 */
protected void buildHint(List<OutcomeDeclaration> outcomeDeclarations, List<ResponseRule> responseRules) {
    if (hint == null)
        return;
    // response declaration -> identifier=HINTREQUEST -> for the end attempt interaction
    ResponseDeclaration hintResponseDeclaration = AssessmentItemFactory.createHintRequestResponseDeclaration(assessmentItem);
    assessmentItem.getResponseDeclarations().add(hintResponseDeclaration);
    // outcome declaration -> identifier=HINTFEEDBACKMODAL -> for processing and feedback
    OutcomeDeclaration modalOutcomeDeclaration = AssessmentItemFactory.createOutcomeDeclarationForHint(assessmentItem);
    outcomeDeclarations.add(modalOutcomeDeclaration);
    // the body
    P paragraph = new P(assessmentItem.getItemBody());
    assessmentItem.getItemBody().getBlocks().add(paragraph);
    EndAttemptInteraction endAttemptInteraction = new EndAttemptInteraction(paragraph);
    endAttemptInteraction.setResponseIdentifier(QTI21Constants.HINT_REQUEST_IDENTIFIER);
    endAttemptInteraction.setTitle(hint.getTitle());
    paragraph.getInlines().add(endAttemptInteraction);
    // the feedback
    ModalFeedback emptyModalFeedback = AssessmentItemFactory.createModalFeedback(assessmentItem, QTI21Constants.HINT_FEEDBACKMODAL_IDENTIFIER, QTI21Constants.HINT_IDENTIFIER, hint.getTitle(), hint.getText());
    assessmentItem.getModalFeedbacks().add(emptyModalFeedback);
    // the response processing
    ResponseCondition rule = new ResponseCondition(assessmentItem.getResponseProcessing());
    responseRules.add(0, rule);
    ResponseIf responseIf = new ResponseIf(rule);
    rule.setResponseIf(responseIf);
    /*
		<responseIf>
			<variable identifier="HINTREQUEST"/>
			<setOutcomeValue identifier="FEEDBACK">
				<baseValue baseType="identifier">HINT</baseValue>
			</setOutcomeValue>
  		</responseIf>
		*/
    Variable variable = new Variable(responseIf);
    variable.setIdentifier(QTI21Constants.HINT_REQUEST_CLX_IDENTIFIER);
    responseIf.getExpressions().add(variable);
    SetOutcomeValue hintVar = new SetOutcomeValue(responseIf);
    hintVar.setIdentifier(QTI21Constants.HINT_FEEDBACKMODAL_IDENTIFIER);
    BaseValue hintVal = new BaseValue(hintVar);
    hintVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
    hintVal.setSingleValue(new IdentifierValue(QTI21Constants.HINT));
    hintVar.setExpression(hintVal);
    responseIf.getResponseRules().add(hintVar);
}
Also used : P(uk.ac.ed.ph.jqtiplus.node.content.xhtml.text.P) Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) SetOutcomeValue(uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) ModalFeedback(uk.ac.ed.ph.jqtiplus.node.item.ModalFeedback) ResponseIf(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) OutcomeDeclaration(uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration) ResponseCondition(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)

Aggregations

ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)132 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)54 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)40 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)36 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)28 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)28 ResponseProcessing (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing)24 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)24 ArrayList (java.util.ArrayList)22 ItemBody (uk.ac.ed.ph.jqtiplus.node.content.ItemBody)22 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)22 AssessmentItemFactory.appendDefaultItemBody (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendDefaultItemBody)20 AssessmentItemFactory.createResponseProcessing (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing)20 FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)18 Value (uk.ac.ed.ph.jqtiplus.value.Value)16 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)14 HashMap (java.util.HashMap)12 MapEntry (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry)12 MultipleValue (uk.ac.ed.ph.jqtiplus.value.MultipleValue)12 IntegerValue (uk.ac.ed.ph.jqtiplus.value.IntegerValue)10