Search in sources :

Example 1 with IdentifierValue

use of uk.ac.ed.ph.jqtiplus.value.IdentifierValue in project OpenOLAT by OpenOLAT.

the class CorrectResponsesUtil method getCorrectOrderedIdentifierResponses.

public static final List<Identifier> getCorrectOrderedIdentifierResponses(AssessmentItem assessmentItem, Interaction interaction) {
    List<Identifier> correctAnswers = new ArrayList<>(5);
    ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
    if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
        CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
        if (correctResponse.getCardinality().isOneOf(Cardinality.ORDERED)) {
            List<FieldValue> values = correctResponse.getFieldValues();
            Value value = FieldValue.computeValue(Cardinality.ORDERED, values);
            if (value instanceof OrderedValue) {
                OrderedValue multiValue = (OrderedValue) value;
                multiValue.forEach(oValue -> {
                    if (oValue instanceof IdentifierValue) {
                        IdentifierValue identifierValue = (IdentifierValue) oValue;
                        Identifier correctAnswer = identifierValue.identifierValue();
                        correctAnswers.add(correctAnswer);
                    }
                });
            }
        }
    }
    return correctAnswers;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) ArrayList(java.util.ArrayList) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) PointValue(uk.ac.ed.ph.jqtiplus.value.PointValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) PairValue(uk.ac.ed.ph.jqtiplus.value.PairValue) 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) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 2 with IdentifierValue

use of uk.ac.ed.ph.jqtiplus.value.IdentifierValue in project OpenOLAT by OpenOLAT.

the class CorrectResponsesUtil method getCorrectIdentifierResponses.

public static final List<Identifier> getCorrectIdentifierResponses(AssessmentItem assessmentItem, Identifier responseIdentifier) {
    List<Identifier> correctAnswers = new ArrayList<>(5);
    ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(responseIdentifier);
    if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
        CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
        if (correctResponse.getCardinality().isOneOf(Cardinality.SINGLE)) {
            List<FieldValue> values = correctResponse.getFieldValues();
            Value value = FieldValue.computeValue(Cardinality.SINGLE, values);
            if (value instanceof IdentifierValue) {
                IdentifierValue identifierValue = (IdentifierValue) value;
                Identifier correctAnswer = identifierValue.identifierValue();
                correctAnswers.add(correctAnswer);
            }
        } else if (correctResponse.getCardinality().isOneOf(Cardinality.MULTIPLE)) {
            Value value = FieldValue.computeValue(Cardinality.MULTIPLE, correctResponse.getFieldValues());
            if (value instanceof MultipleValue) {
                MultipleValue multiValue = (MultipleValue) value;
                for (SingleValue sValue : multiValue.getAll()) {
                    if (sValue instanceof IdentifierValue) {
                        IdentifierValue identifierValue = (IdentifierValue) sValue;
                        Identifier correctAnswer = identifierValue.identifierValue();
                        correctAnswers.add(correctAnswer);
                    }
                }
            }
        }
    }
    return correctAnswers;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) ArrayList(java.util.ArrayList) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) PointValue(uk.ac.ed.ph.jqtiplus.value.PointValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) PairValue(uk.ac.ed.ph.jqtiplus.value.PairValue) 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) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 3 with IdentifierValue

use of uk.ac.ed.ph.jqtiplus.value.IdentifierValue in project OpenOLAT by OpenOLAT.

the class HottextAssessmentItemBuilderTest method createHottextAssessmentItem_perAnswer.

/**
 * This is an hottextInteraction with 3 choices, one with 3.0 points and correct,
 * one with 0.0 points but correct and one false with -1.0 points.
 *
 * @throws IOException
 */
@Test
public void createHottextAssessmentItem_perAnswer() throws IOException {
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    HottextAssessmentItemBuilder itemBuilder = new HottextAssessmentItemBuilder("Hot texts", "This is a hot ", "text", qtiSerializer);
    itemBuilder.setQuestion("<p>This is <hottext identifier=\"RESPONSE_HOT_1\">hot</hottext>, <hottext identifier=\"RESPONSE_HOT_2\">cold</hottext> or <hottext identifier=\"RESPONSE_HOT_3\">freezing</hottext></p>");
    itemBuilder.addCorrectAnswer(Identifier.parseString("RESPONSE_HOT_2"));
    itemBuilder.addCorrectAnswer(Identifier.parseString("RESPONSE_HOT_3"));
    itemBuilder.setMapping(Identifier.parseString("RESPONSE_HOT_1"), -1.0d);
    itemBuilder.setMapping(Identifier.parseString("RESPONSE_HOT_2"), 0.0d);
    itemBuilder.setMapping(Identifier.parseString("RESPONSE_HOT_3"), 3.0d);
    itemBuilder.setMaxScore(3.0d);
    itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
    itemBuilder.build();
    File itemFile = new File(WebappHelper.getTmpDir(), "hottextAssessmentItem" + UUID.randomUUID() + ".xml");
    try (FileOutputStream out = new FileOutputStream(itemFile)) {
        qtiSerializer.serializeJqtiObject(itemBuilder.getAssessmentItem(), out);
    } catch (Exception e) {
        log.error("", e);
    }
    {
        // correct answers
        Map<Identifier, ResponseData> responseMap = new HashMap<>();
        Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
        responseMap.put(responseIdentifier, new StringResponseData("RESPONSE_HOT_2", "RESPONSE_HOT_3"));
        ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
        Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
        Assert.assertEquals(new FloatValue(3.0d), score);
        Value feedbackBasic = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
        Assert.assertEquals(new IdentifierValue(QTI21Constants.CORRECT_IDENTIFIER), feedbackBasic);
    }
    {
        // max score but not all correct
        Map<Identifier, ResponseData> responseMap = new HashMap<>();
        Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
        responseMap.put(responseIdentifier, new StringResponseData("RESPONSE_HOT_3"));
        ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
        Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
        Assert.assertEquals(new FloatValue(3.0d), score);
        Value feedbackBasic = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
        Assert.assertEquals(new IdentifierValue(QTI21Constants.INCORRECT_IDENTIFIER), feedbackBasic);
    }
    {
        // all wrong
        Map<Identifier, ResponseData> responseMap = new HashMap<>();
        Identifier responseIdentifier = itemBuilder.getInteraction().getResponseIdentifier();
        responseMap.put(responseIdentifier, new StringResponseData("RESPONSE_HOT_1"));
        ItemSessionController itemSessionController = RunningItemHelper.run(itemFile, responseMap);
        Value score = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.SCORE_IDENTIFIER);
        Assert.assertEquals(new FloatValue(0.0d), score);
        Value feedbackBasic = itemSessionController.getItemSessionState().getOutcomeValue(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
        Assert.assertEquals(new IdentifierValue(QTI21Constants.INCORRECT_IDENTIFIER), feedbackBasic);
    }
    FileUtils.deleteDirsAndFiles(itemFile.toPath());
}
Also used : HottextAssessmentItemBuilder(org.olat.ims.qti21.model.xml.interactions.HottextAssessmentItemBuilder) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) ItemSessionController(uk.ac.ed.ph.jqtiplus.running.ItemSessionController) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) StringResponseData(uk.ac.ed.ph.jqtiplus.types.StringResponseData) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) FileOutputStream(java.io.FileOutputStream) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with IdentifierValue

use of uk.ac.ed.ph.jqtiplus.value.IdentifierValue in project OpenOLAT by OpenOLAT.

the class AssessmentRenderFunctions method isVisible.

// <xsl:sequence select="boolean($element[$overrideTemplate
// or not(@templateIdentifier)
// or (qw:value-contains(qw:get-template-value(@templateIdentifier), @identifier) and not(@showHide='hide'))])"/>
public static boolean isVisible(Choice choice, ItemSessionState iSessionState) {
    if (choice.getTemplateIdentifier() == null)
        return true;
    Value templateValue = iSessionState.getTemplateValue(choice.getTemplateIdentifier());
    boolean visible = templateValue instanceof IdentifierValue && ((IdentifierValue) templateValue).identifierValue().equals(choice.getIdentifier()) && choice.getVisibilityMode() != VisibilityMode.HIDE_IF_MATCH;
    return visible;
}
Also used : DurationValue(uk.ac.ed.ph.jqtiplus.value.DurationValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) ListValue(uk.ac.ed.ph.jqtiplus.value.ListValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) RecordValue(uk.ac.ed.ph.jqtiplus.value.RecordValue) OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) BooleanValue(uk.ac.ed.ph.jqtiplus.value.BooleanValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) StringValue(uk.ac.ed.ph.jqtiplus.value.StringValue) NullValue(uk.ac.ed.ph.jqtiplus.value.NullValue) FileValue(uk.ac.ed.ph.jqtiplus.value.FileValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue)

Example 5 with IdentifierValue

use of uk.ac.ed.ph.jqtiplus.value.IdentifierValue in project OpenOLAT by OpenOLAT.

the class AssessmentRenderFunctionsTest method valueContains_multipleValues.

@Test
public void valueContains_multipleValues() {
    Value identifierValues = MultipleValue.createMultipleValue(new IdentifierValue(Identifier.parseString("reference-id")), new IdentifierValue(Identifier.parseString("reference-id")));
    Assert.assertTrue(AssessmentRenderFunctions.valueContains(identifierValues, Identifier.parseString("reference-id")));
    Assert.assertFalse(AssessmentRenderFunctions.valueContains(identifierValues, Identifier.parseString("noid")));
}
Also used : OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) NullValue(uk.ac.ed.ph.jqtiplus.value.NullValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) Test(org.junit.Test)

Aggregations

IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)56 BaseValue (uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue)26 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)24 Value (uk.ac.ed.ph.jqtiplus.value.Value)22 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)18 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)18 Variable (uk.ac.ed.ph.jqtiplus.node.expression.general.Variable)16 SetOutcomeValue (uk.ac.ed.ph.jqtiplus.node.item.response.processing.SetOutcomeValue)16 FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)16 MultipleValue (uk.ac.ed.ph.jqtiplus.value.MultipleValue)16 IntegerValue (uk.ac.ed.ph.jqtiplus.value.IntegerValue)14 ResponseIf (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseIf)12 OrderedValue (uk.ac.ed.ph.jqtiplus.value.OrderedValue)12 Match (uk.ac.ed.ph.jqtiplus.node.expression.operator.Match)10 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)10 ResponseCondition (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseCondition)10 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 IsNull (uk.ac.ed.ph.jqtiplus.node.expression.operator.IsNull)8 MapEntry (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry)8