use of uk.ac.ed.ph.jqtiplus.node.expression.operator.And in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method createCorrectSolutionModalFeedbackBasicRule.
/**
* Generate the special case for "correct solution" feedback which is almost the same as
* incorrect feedback.
*
* @param responseProcessing
* @param feedbackIdentifier
* @return
*/
public static ResponseCondition createCorrectSolutionModalFeedbackBasicRule(ResponseProcessing responseProcessing, Identifier correctSolutionFeedbackIdentifier, Identifier incorrectFeedbackIdentifier, boolean hint) {
ResponseCondition rule = new ResponseCondition(responseProcessing);
/*
<responseIf>
<and>
<match>
<baseValue baseType="identifier">incorrect</baseValue>
<variable identifier="FEEDBACKBASIC" />
</match>
</and>
<setOutcomeValue identifier="FEEDBACKMODAL">
<multiple>
<variable identifier="FEEDBACKMODAL" />
<baseValue baseType="identifier">Feedback261171147</baseValue>
</multiple>
</setOutcomeValue>
<setOutcomeValue identifier="SOLUTIONMODAL">
<baseValue baseType="identifier">Feedback261171147</baseValue>
</setOutcomeValue>
</responseIf>
*/
ResponseIf responseIf = new ResponseIf(rule);
rule.setResponseIf(responseIf);
{
// rule
And and = new And(responseIf);
responseIf.getExpressions().add(and);
Match match = new Match(and);
and.getExpressions().add(match);
BaseValue feedbackVal = new BaseValue(match);
feedbackVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
feedbackVal.setSingleValue(new IdentifierValue(QTI21Constants.INCORRECT));
match.getExpressions().add(feedbackVal);
Variable variable = new Variable(match);
variable.setIdentifier(ComplexReferenceIdentifier.parseString(QTI21Constants.FEEDBACKBASIC));
match.getExpressions().add(variable);
// not match the HINT
if (hint) {
IsNull isNull = new IsNull(and);
and.getExpressions().add(isNull);
Variable hintVar = new Variable(isNull);
hintVar.setIdentifier(QTI21Constants.HINT_FEEDBACKMODAL_CLX_IDENTIFIER);
isNull.getExpressions().add(hintVar);
}
}
if (incorrectFeedbackIdentifier != null) {
// outcome incorrect
SetOutcomeValue feedbackVar = new SetOutcomeValue(responseIf);
feedbackVar.setIdentifier(QTI21Constants.FEEDBACKMODAL_IDENTIFIER);
Multiple multiple = new Multiple(feedbackVar);
feedbackVar.setExpression(multiple);
Variable variable = new Variable(multiple);
variable.setIdentifier(ComplexReferenceIdentifier.parseString(QTI21Constants.FEEDBACKMODAL));
multiple.getExpressions().add(variable);
BaseValue feedbackVal = new BaseValue(feedbackVar);
feedbackVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
feedbackVal.setSingleValue(new IdentifierValue(incorrectFeedbackIdentifier));
multiple.getExpressions().add(feedbackVal);
responseIf.getResponseRules().add(feedbackVar);
}
if (correctSolutionFeedbackIdentifier != null) {
// outcome correct solution
SetOutcomeValue feedbackVar = new SetOutcomeValue(responseIf);
feedbackVar.setIdentifier(QTI21Constants.CORRECT_SOLUTION_IDENTIFIER);
BaseValue feedbackVal = new BaseValue(feedbackVar);
feedbackVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
feedbackVal.setSingleValue(new IdentifierValue(correctSolutionFeedbackIdentifier));
feedbackVar.getExpressions().add(feedbackVal);
responseIf.getResponseRules().add(feedbackVar);
}
return rule;
}
use of uk.ac.ed.ph.jqtiplus.node.expression.operator.And in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method createModalFeedbackRuleWithConditions.
public static ResponseCondition createModalFeedbackRuleWithConditions(ResponseProcessing responseProcessing, Identifier feedbackIdentifier, Identifier responseIdentifier, Cardinality cardinality, List<ModalFeedbackCondition> conditions) {
ResponseCondition rule = new ResponseCondition(responseProcessing);
/*
<responseCondition>
<responseIf>
<and>
<equal toleranceMode="exact">
<variable identifier="SCORE" />
<baseValue baseType="float">
4
</baseValue>
</equal>
</and>
<setOutcomeValue identifier="FEEDBACKMODAL">
<multiple>
<variable identifier="FEEDBACKMODAL" />
<baseValue baseType="identifier">
Feedback2074019497
</baseValue>
</multiple>
</setOutcomeValue>
</responseIf>
</responseCondition>
*/
ResponseIf responseIf = new ResponseIf(rule);
rule.setResponseIf(responseIf);
{
// rule
And and = new And(responseIf);
responseIf.getExpressions().add(and);
for (ModalFeedbackCondition condition : conditions) {
appendModalFeedbackCondition(condition, responseIdentifier, cardinality, and);
}
}
{
// outcome
SetOutcomeValue feedbackVar = new SetOutcomeValue(responseIf);
feedbackVar.setIdentifier(QTI21Constants.FEEDBACKMODAL_IDENTIFIER);
Multiple multiple = new Multiple(feedbackVar);
feedbackVar.setExpression(multiple);
Variable variable = new Variable(multiple);
variable.setIdentifier(ComplexReferenceIdentifier.parseString(QTI21Constants.FEEDBACKMODAL));
multiple.getExpressions().add(variable);
BaseValue feedbackVal = new BaseValue(feedbackVar);
feedbackVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
feedbackVal.setSingleValue(new IdentifierValue(feedbackIdentifier));
multiple.getExpressions().add(feedbackVal);
responseIf.getResponseRules().add(feedbackVar);
}
return rule;
}
use of uk.ac.ed.ph.jqtiplus.node.expression.operator.And in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method createModalFeedbackBasicRule.
public static ResponseCondition createModalFeedbackBasicRule(ResponseProcessing responseProcessing, Identifier feedbackIdentifier, String inCorrect, boolean hint) {
ResponseCondition rule = new ResponseCondition(responseProcessing);
/*
<responseIf>
<and>
<match>
<baseValue baseType="identifier">correct</baseValue>
<variable identifier="FEEDBACKBASIC" />
</match>
</and>
<setOutcomeValue identifier="FEEDBACKMODAL">
<multiple>
<variable identifier="FEEDBACKMODAL" />
<baseValue baseType="identifier">Feedback261171147</baseValue>
</multiple>
</setOutcomeValue>
</responseIf>
*/
ResponseIf responseIf = new ResponseIf(rule);
rule.setResponseIf(responseIf);
{
// rule
And and = new And(responseIf);
responseIf.getExpressions().add(and);
Match match = new Match(and);
and.getExpressions().add(match);
BaseValue feedbackVal = new BaseValue(match);
feedbackVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
feedbackVal.setSingleValue(new IdentifierValue(inCorrect));
match.getExpressions().add(feedbackVal);
Variable variable = new Variable(match);
variable.setIdentifier(ComplexReferenceIdentifier.parseString(QTI21Constants.FEEDBACKBASIC));
match.getExpressions().add(variable);
// not match the HINT
if (hint) {
IsNull isNull = new IsNull(and);
and.getExpressions().add(isNull);
Variable hintVar = new Variable(isNull);
hintVar.setIdentifier(QTI21Constants.HINT_FEEDBACKMODAL_CLX_IDENTIFIER);
isNull.getExpressions().add(hintVar);
}
}
{
// outcome
SetOutcomeValue feedbackVar = new SetOutcomeValue(responseIf);
feedbackVar.setIdentifier(QTI21Constants.FEEDBACKMODAL_IDENTIFIER);
Multiple multiple = new Multiple(feedbackVar);
feedbackVar.setExpression(multiple);
Variable variable = new Variable(multiple);
variable.setIdentifier(ComplexReferenceIdentifier.parseString(QTI21Constants.FEEDBACKMODAL));
multiple.getExpressions().add(variable);
BaseValue feedbackVal = new BaseValue(feedbackVar);
feedbackVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
feedbackVal.setSingleValue(new IdentifierValue(feedbackIdentifier));
multiple.getExpressions().add(feedbackVal);
responseIf.getResponseRules().add(feedbackVar);
}
return rule;
}
use of uk.ac.ed.ph.jqtiplus.node.expression.operator.And 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.expression.operator.And 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);
}
}
Aggregations