Search in sources :

Example 1 with SingleValue

use of uk.ac.ed.ph.jqtiplus.value.SingleValue 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 2 with SingleValue

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

the class QTI21StatisticsManagerImpl method getTextEntryInteractionSettings.

private TextEntryInteractionStatistics getTextEntryInteractionSettings(Identifier responseIdentifier, ResponseDeclaration responseDeclaration) {
    String correctResponse = null;
    boolean caseSensitive = true;
    double points = Double.NaN;
    List<String> alternatives = new ArrayList<>();
    List<MapEntry> mapEntries = responseDeclaration.getMapping().getMapEntries();
    for (MapEntry mapEntry : mapEntries) {
        SingleValue mapKey = mapEntry.getMapKey();
        if (mapKey instanceof StringValue) {
            String value = ((StringValue) mapKey).stringValue();
            if (correctResponse == null) {
                correctResponse = value;
                points = mapEntry.getMappedValue();
            } else {
                alternatives.add(value);
            }
        }
        caseSensitive &= mapEntry.getCaseSensitive();
    }
    if (points == -1.0d) {
        // all score
        points = 0.0d;
    }
    return new TextEntryInteractionStatistics(responseIdentifier, caseSensitive, correctResponse, alternatives, points);
}
Also used : MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) ArrayList(java.util.ArrayList) StringValue(uk.ac.ed.ph.jqtiplus.value.StringValue) TextEntryInteractionStatistics(org.olat.ims.qti21.model.statistics.TextEntryInteractionStatistics) AbstractTextEntryInteractionStatistics(org.olat.ims.qti21.model.statistics.AbstractTextEntryInteractionStatistics)

Example 3 with SingleValue

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

the class QTI21StatisticsManagerImpl method getKPrimStatistics.

// stringuifiedResponse: [a93247453265982 correct][b93247453265983 correct][c93247453265984 correct][d93247453265985 correct]
@Override
public List<KPrimStatistics> getKPrimStatistics(String itemRefIdent, AssessmentItem item, MatchInteraction interaction, QTI21StatisticSearchParams searchParams) {
    List<RawData> rawDatas = getRawDatas(itemRefIdent, interaction.getResponseIdentifier().toString(), searchParams);
    List<SimpleMatchSet> matchSets = interaction.getSimpleMatchSets();
    List<KPrimStatistics> kprimPoints = new ArrayList<>();
    SimpleMatchSet fourMatchSet = matchSets.get(0);
    ResponseDeclaration responseDeclaration = item.getResponseDeclaration(interaction.getResponseIdentifier());
    // readable responses
    Set<String> rightResponses = new HashSet<>();
    List<MapEntry> mapEntries = responseDeclaration.getMapping().getMapEntries();
    for (MapEntry mapEntry : mapEntries) {
        SingleValue mapKey = mapEntry.getMapKey();
        if (mapKey instanceof DirectedPairValue) {
            DirectedPairValue pairValue = (DirectedPairValue) mapKey;
            String source = pairValue.sourceValue().toString();
            String destination = pairValue.destValue().toString();
            rightResponses.add("[" + source + " " + destination + "]");
        }
    }
    for (SimpleAssociableChoice choice : fourMatchSet.getSimpleAssociableChoices()) {
        String choiceIdentifier = choice.getIdentifier().toString();
        String markerCorrect = "[" + choiceIdentifier + " correct]";
        String markerWrong = "[" + choiceIdentifier + " wrong]";
        boolean isCorrectRight = rightResponses.contains(markerCorrect);
        String rightFlag = isCorrectRight ? markerCorrect : markerWrong;
        String wrongFlag = isCorrectRight ? markerWrong : markerCorrect;
        long numCorrect = 0;
        long numIncorrect = 0;
        long numUnanswered = 0;
        for (RawData rawData : rawDatas) {
            String response = rawData.getStringuifiedResponse();
            if (response.indexOf(rightFlag) >= 0) {
                numCorrect += rawData.getCount();
            } else if (response.indexOf(wrongFlag) >= 0) {
                numIncorrect += rawData.getCount();
            } else {
                numUnanswered += rawData.getCount();
            }
        }
        kprimPoints.add(new KPrimStatistics(choice.getIdentifier(), isCorrectRight, numCorrect, numIncorrect, numUnanswered));
    }
    return kprimPoints;
}
Also used : SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) ArrayList(java.util.ArrayList) KPrimStatistics(org.olat.ims.qti21.model.statistics.KPrimStatistics) SimpleMatchSet(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleMatchSet) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) HashSet(java.util.HashSet)

Example 4 with SingleValue

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

the class AssessmentRenderFunctions method renderRecordCardinalityValue.

public static void renderRecordCardinalityValue(StringOutput sb, Value value, String delimiter, String mappingIndicator) {
    if (value != null && value.hasCardinality(Cardinality.RECORD)) {
        RecordValue oValue = (RecordValue) value;
        boolean hasDelimiter = StringHelper.containsNonWhitespace(delimiter);
        boolean hasMappingIndicator = StringHelper.containsNonWhitespace(mappingIndicator);
        int count = 0;
        for (Map.Entry<Identifier, SingleValue> entry : oValue.entrySet()) {
            if (hasDelimiter && count++ > 0)
                sb.append(delimiter);
            String identifierString = entry.getKey().toString();
            sb.append(identifierString);
            if (hasMappingIndicator) {
                sb.append(mappingIndicator);
            }
            renderSingleCardinalityValue(sb, entry.getValue());
        }
    }
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) RecordValue(uk.ac.ed.ph.jqtiplus.value.RecordValue) Map(java.util.Map)

Example 5 with SingleValue

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

the class AssessmentRenderFunctions method extractRecordFieldValue.

/*
  <xsl:function name="qw:extract-record-field-value" as="xs:string?">
    <xsl:param name="valueHolder" as="element()"/>
    <xsl:param name="fieldName" as="xs:string"/>
    <xsl:choose>
      <xsl:when test="qw:is-record-cardinality-value($valueHolder)">
        <xsl:value-of select="$valueHolder/qw:value[@fieldIdentifier=$fieldName]"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message terminate="yes">
          Expected value <xsl:copy-of select="$valueHolder"/> to have record
          cardinalty.
        </xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:function>
	 */
public static SingleValue extractRecordFieldValue(Value value, Identifier identifier) {
    SingleValue mappedValue = null;
    if (value != null && identifier != null && value.hasCardinality(Cardinality.RECORD)) {
        RecordValue recordValue = (RecordValue) value;
        mappedValue = recordValue.get(identifier);
    }
    return mappedValue;
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) RecordValue(uk.ac.ed.ph.jqtiplus.value.RecordValue)

Aggregations

SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)52 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)30 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)20 FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)18 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)18 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)16 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)14 MapEntry (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry)14 RecordValue (uk.ac.ed.ph.jqtiplus.value.RecordValue)14 ArrayList (java.util.ArrayList)12 BaseValue (uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue)12 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)12 Mapping (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping)10 Value (uk.ac.ed.ph.jqtiplus.value.Value)10 MultipleValue (uk.ac.ed.ph.jqtiplus.value.MultipleValue)8 Map (java.util.Map)6 Expression (uk.ac.ed.ph.jqtiplus.node.expression.Expression)6 StringValue (uk.ac.ed.ph.jqtiplus.value.StringValue)6 AssessmentItemFactory.appendAssociationMatchResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendAssociationMatchResponseDeclaration)4 AssessmentItemFactory.createMatchResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createMatchResponseDeclaration)4