Search in sources :

Example 51 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.

the class HottextAssessmentItemBuilder method extractScoreEvaluationMode.

private void extractScoreEvaluationMode() {
    boolean hasMapping = false;
    if (hottextInteraction != null) {
        ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(hottextInteraction.getResponseIdentifier());
        if (responseDeclaration != null) {
            Mapping mapping = responseDeclaration.getMapping();
            hasMapping = (mapping != null && mapping.getMapEntries() != null && mapping.getMapEntries().size() > 0);
            if (hasMapping) {
                scoreMapping = new HashMap<>();
                for (MapEntry entry : mapping.getMapEntries()) {
                    SingleValue sValue = entry.getMapKey();
                    if (sValue instanceof IdentifierValue) {
                        Identifier identifier = ((IdentifierValue) sValue).identifierValue();
                        scoreMapping.put(identifier, entry.getMappedValue());
                    }
                }
            }
        }
    }
    scoreEvaluation = hasMapping ? ScoreEvaluation.perAnswer : ScoreEvaluation.allCorrectAnswers;
}
Also used : MapEntry(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) Mapping(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createHottextCorrectResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createHottextCorrectResponseDeclaration)

Example 52 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.

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 53 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.

the class KPrimAssessmentItemBuilder method extractCorrectResponse.

private void extractCorrectResponse() {
    associations = new HashMap<>();
    if (matchInteraction != null) {
        ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(matchInteraction.getResponseIdentifier());
        if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
            CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
            List<FieldValue> values = correctResponse.getFieldValues();
            for (FieldValue value : values) {
                SingleValue sValue = value.getSingleValue();
                if (sValue instanceof DirectedPairValue) {
                    DirectedPairValue dpValue = (DirectedPairValue) sValue;
                    Identifier sourceId = dpValue.sourceValue();
                    Identifier destinationId = dpValue.destValue();
                    associations.put(sourceId, destinationId);
                }
            }
        }
    }
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createKPrimResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createKPrimResponseDeclaration) AssessmentItemFactory.appendAssociationKPrimResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendAssociationKPrimResponseDeclaration)

Example 54 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.

the class MatchAssessmentItemBuilder method createAssessmentItem.

private static AssessmentItem createAssessmentItem(String title, String matchCssClass, String unanswered, String right, String wrong) {
    AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.match, title);
    NodeGroupList nodeGroups = assessmentItem.getNodeGroups();
    double maxScore = 1.0d;
    Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
    // define correct answer
    ResponseDeclaration responseDeclaration = createMatchResponseDeclaration(assessmentItem, responseDeclarationId, new HashMap<>());
    nodeGroups.getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
    appendDefaultOutcomeDeclarations(assessmentItem, maxScore);
    // the single choice interaction
    ItemBody itemBody = appendDefaultItemBody(assessmentItem);
    Map<Identifier, List<Identifier>> associations = new HashMap<>();
    MatchInteraction interaction;
    if (QTI21Constants.CSS_MATCH_TRUE_FALSE.equals(matchCssClass)) {
        interaction = appendMatchInteractionTrueFalse(itemBody, unanswered, right, wrong, responseDeclarationId);
        // default correct answers set to "right"
        SimpleAssociableChoice rightChoice = interaction.getSimpleMatchSets().get(1).getSimpleAssociableChoices().get(1);
        List<SimpleAssociableChoice> sourceChoices = interaction.getSimpleMatchSets().get(0).getSimpleAssociableChoices();
        for (SimpleAssociableChoice sourceChoice : sourceChoices) {
            List<Identifier> targetIdentifiers = new ArrayList<>();
            targetIdentifiers.add(rightChoice.getIdentifier());
            associations.put(sourceChoice.getIdentifier(), targetIdentifiers);
        }
    } else {
        interaction = appendMatchInteraction(itemBody, responseDeclarationId);
    }
    List<String> cssClasses = new ArrayList<>();
    cssClasses.add(matchCssClass);
    interaction.setClassAttr(cssClasses);
    appendAssociationMatchResponseDeclaration(responseDeclaration, associations);
    // response processing
    ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
    assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
    return assessmentItem;
}
Also used : AssessmentItemFactory.appendMatchInteraction(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendMatchInteraction) MatchInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction) SimpleAssociableChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) AssessmentItemFactory.createResponseProcessing(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createResponseProcessing) ResponseProcessing(uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing) 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) NodeGroupList(uk.ac.ed.ph.jqtiplus.group.NodeGroupList) List(java.util.List) ArrayList(java.util.ArrayList) NodeGroupList(uk.ac.ed.ph.jqtiplus.group.NodeGroupList) AssessmentItemFactory.appendAssociationMatchResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendAssociationMatchResponseDeclaration) AssessmentItemFactory.createMatchResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createMatchResponseDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 55 with Identifier

use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.

the class MultipleChoiceAssessmentItemBuilder method extract.

@Override
public void extract() {
    super.extract();
    correctAnswers = new ArrayList<>(5);
    if (choiceInteraction != null) {
        ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(choiceInteraction.getResponseIdentifier());
        if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
            CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
            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);
                    }
                }
            }
        }
    }
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) 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) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentItemFactory.createMultipleChoiceCorrectResponseDeclaration(org.olat.ims.qti21.model.xml.AssessmentItemFactory.createMultipleChoiceCorrectResponseDeclaration)

Aggregations

Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)208 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)62 ArrayList (java.util.ArrayList)53 HashMap (java.util.HashMap)52 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)46 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)42 Value (uk.ac.ed.ph.jqtiplus.value.Value)42 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)40 Map (java.util.Map)32 SimpleAssociableChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice)24 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)24 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)24 ItemBody (uk.ac.ed.ph.jqtiplus.node.content.ItemBody)22 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)22 ResponseProcessing (uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseProcessing)22 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)22 List (java.util.List)20 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)20 SimpleChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice)20 RecordValue (uk.ac.ed.ph.jqtiplus.value.RecordValue)20