use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method matchAdditionalFeedback.
/**
* the additional feedback have only responseIf
*
* @param item
* @param feedback
* @return
*/
public static boolean matchAdditionalFeedback(AssessmentItem item, ModalFeedback feedback) {
List<ResponseRule> responseRules = item.getResponseProcessing().getResponseRules();
for (ResponseRule responseRule : responseRules) {
if (responseRule instanceof ResponseCondition) {
ResponseCondition responseCondition = (ResponseCondition) responseRule;
if (responseCondition.getResponseIf() == null || responseCondition.getResponseElse() != null || (responseCondition.getResponseElseIfs() != null && responseCondition.getResponseElseIfs().size() > 0)) {
continue;
}
ResponseIf responseIf = responseCondition.getResponseIf();
List<ResponseRule> ifResponseRules = responseIf.getResponseRules();
if (ifResponseRules == null || ifResponseRules.size() != 1 || !(ifResponseRules.get(0) instanceof SetOutcomeValue)) {
continue;
}
SetOutcomeValue setOutcomeValue = (SetOutcomeValue) responseIf.getResponseRules().get(0);
if (!findBaseValueInExpression(setOutcomeValue.getExpression(), feedback.getIdentifier())) {
continue;
}
List<Expression> expressions = responseIf.getExpressions();
if (expressions == null || expressions.size() != 1 || !(expressions.get(0) instanceof And)) {
continue;
}
List<Variable> variables = QueryUtils.search(Variable.class, expressions.get(0));
if (variables != null && variables.size() == 1) {
Variable bValue = variables.get(0);
ComplexReferenceIdentifier identifier = bValue.getIdentifier();
if (identifier.equals(QTI21Constants.SCORE_CLX_IDENTIFIER) || identifier.equals(QTI21Constants.NUM_ATTEMPTS_CLX_IDENTIFIER)) {
return true;
}
if (identifier.equals(QTI21Constants.CORRECT_CLX_IDENTIFIER) || identifier.equals(QTI21Constants.INCORRECT_CLX_IDENTIFIER) || identifier.equals(QTI21Constants.EMPTY_CLX_IDENTIFIER)) {
return false;
}
String identifierToString = identifier.toString();
if (identifierToString.contains("RESPONSE_")) {
return true;
}
}
}
}
return false;
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule in project OpenOLAT by OpenOLAT.
the class FIBAssessmentItemBuilder method extractNumericalEntrySettings.
public static void extractNumericalEntrySettings(AssessmentItem item, NumericalEntry numericalEntry, ResponseDeclaration responseDeclaration, AtomicInteger countAlternatives, DoubleAdder mappedScore) {
Double solution = null;
CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
if (correctResponse != null && correctResponse.getFieldValues().size() > 0) {
List<FieldValue> fValues = correctResponse.getFieldValues();
SingleValue sValue = fValues.get(0).getSingleValue();
if (sValue instanceof FloatValue) {
solution = ((FloatValue) sValue).doubleValue();
numericalEntry.setSolution(solution);
}
}
// search the equal
List<ResponseRule> responseRules = item.getResponseProcessing().getResponseRules();
a_a: for (ResponseRule responseRule : responseRules) {
if (responseRule instanceof ResponseCondition) {
ResponseCondition condition = (ResponseCondition) responseRule;
ResponseIf responseIf = condition.getResponseIf();
if (responseIf != null && responseIf.getExpressions().size() > 0) {
// first is an and/equal/
Expression potentialEqualOrAnd = responseIf.getExpressions().get(0);
if (potentialEqualOrAnd instanceof And) {
And and = (And) potentialEqualOrAnd;
for (Expression potentialEqual : and.getExpressions()) {
if (potentialEqual instanceof Equal && potentialEqual.getExpressions().size() == 2 && extractNumericalEntrySettings(numericalEntry, (Equal) potentialEqual)) {
break a_a;
}
}
} else if (potentialEqualOrAnd instanceof Equal) {
if (extractNumericalEntrySettings(numericalEntry, (Equal) potentialEqualOrAnd)) {
// find to score as outcome value
if (responseIf.getResponseRules() != null && responseIf.getResponseRules().size() == 1 && responseIf.getResponseRules().get(0) instanceof SetOutcomeValue) {
SetOutcomeValue outcomeValue = (SetOutcomeValue) responseIf.getResponseRules().get(0);
if (outcomeValue.getExpressions() != null && outcomeValue.getExpressions().size() == 1 && outcomeValue.getExpressions().get(0) instanceof BaseValue) {
BaseValue bValue = (BaseValue) outcomeValue.getExpressions().get(0);
SingleValue sValue = bValue.getSingleValue();
if (sValue instanceof FloatValue) {
FloatValue fValue = (FloatValue) sValue;
numericalEntry.setScore(fValue.doubleValue());
mappedScore.add(fValue.doubleValue());
countAlternatives.incrementAndGet();
}
}
}
break a_a;
}
}
}
}
}
// toleranceMode cannot be empty
if (numericalEntry.getToleranceMode() == null) {
numericalEntry.setToleranceMode(ToleranceMode.EXACT);
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule in project OpenOLAT by OpenOLAT.
the class AssessmentItemBuilder method build.
public final void build() {
List<OutcomeDeclaration> outcomeDeclarations = assessmentItem.getOutcomeDeclarations();
outcomeDeclarations.clear();
ResponseProcessing responseProcessing = assessmentItem.getResponseProcessing();
List<ResponseRule> responseRules = responseProcessing.getResponseRules();
responseRules.clear();
List<ResponseDeclaration> responseDeclarations = assessmentItem.getResponseDeclarations();
responseDeclarations.clear();
List<ModalFeedback> modalFeedbacks = assessmentItem.getModalFeedbacks();
modalFeedbacks.clear();
buildItemBody();
buildResponseAndOutcomeDeclarations();
buildModalFeedbacksAndHints(outcomeDeclarations, responseRules);
buildMinMaxScores(outcomeDeclarations, responseRules);
buildMainScoreRule(outcomeDeclarations, responseRules);
buildHint(outcomeDeclarations, responseRules);
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule in project OpenOLAT by OpenOLAT.
the class AssessmentItemBuilder method buildMinMaxScores.
/**
* Add outcome declaration for score, min. score and mx. score.
* and the response rules which ensure that the score is between
* the max. score and min. score.
*
* @param outcomeDeclarations
* @param responseRules
*/
protected final void buildMinMaxScores(List<OutcomeDeclaration> outcomeDeclarations, List<ResponseRule> responseRules) {
if ((getMinScoreBuilder() != null && getMinScoreBuilder().getScore() != null) || (getMaxScoreBuilder() != null && getMaxScoreBuilder().getScore() != null)) {
OutcomeDeclaration outcomeDeclaration = AssessmentItemFactory.createOutcomeDeclarationForScore(assessmentItem);
outcomeDeclarations.add(outcomeDeclaration);
}
if (getMinScoreBuilder() != null && getMinScoreBuilder().getScore() != null) {
OutcomeDeclaration outcomeDeclaration = AssessmentItemFactory.createOutcomeDeclarationForMinScore(assessmentItem, getMinScoreBuilder().getScore().doubleValue());
outcomeDeclarations.add(outcomeDeclaration);
// ensure that the score is not smaller than min. score value
ResponseRule minScoreBoundResponseRule = AssessmentItemFactory.createMinScoreBoundLimitRule(assessmentItem.getResponseProcessing());
responseRules.add(minScoreBoundResponseRule);
}
if (getMaxScoreBuilder() != null && getMaxScoreBuilder().getScore() != null) {
OutcomeDeclaration outcomeDeclaration = AssessmentItemFactory.createOutcomeDeclarationForMaxScore(assessmentItem, getMaxScoreBuilder().getScore().doubleValue());
outcomeDeclarations.add(outcomeDeclaration);
// ensure that the score is not bigger than the max. score value
ResponseRule maxScoreBoundResponseRule = AssessmentItemFactory.createMaxScoreBoundLimitRule(assessmentItem.getResponseProcessing());
responseRules.add(maxScoreBoundResponseRule);
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.processing.ResponseRule in project openolat by klemens.
the class ModalFeedbackBuilder method findFeedbackRuleInSetOutcomeVariable.
private boolean findFeedbackRuleInSetOutcomeVariable(ResponseRule responseRule, Identifier feedbackIdentifier, Identifier outcomeValueIdentifier) {
if (responseRule instanceof ResponseCondition) {
ResponseCondition responseCondition = (ResponseCondition) responseRule;
ResponseIf responseIf = responseCondition.getResponseIf();
List<ResponseRule> ifResponseRules = responseIf.getResponseRules();
for (ResponseRule ifResponseRule : ifResponseRules) {
if (ifResponseRule instanceof SetOutcomeValue) {
SetOutcomeValue setOutcomeValue = (SetOutcomeValue) ifResponseRule;
if (outcomeValueIdentifier.equals(setOutcomeValue.getIdentifier()) && findBaseValueInExpression(setOutcomeValue.getExpression(), feedbackIdentifier)) {
return true;
}
}
}
}
return false;
}
Aggregations