use of uk.ac.ed.ph.jqtiplus.node.expression.operator.And in project openolat by klemens.
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 createModalFeedbackResponseConditionByScore.
/**
* This generate a response rule which compare the max score and the score
* to set the feedback as "correct".
*
* <responseCondition>
* <responseIf>
* <and>
* <not>
* <match>
* <variable identifier="FEEDBACKBASIC" />
* <baseValue baseType="identifier">empty</baseValue>
* </match>
* </not>
* <equal toleranceMode="exact">
* <variable identifier="SCORE" />
* <variable identifier="MAXSCORE" />
* </equal>
* </and>
* <setOutcomeValue identifier="FEEDBACKBASIC">
* <baseValue baseType="identifier">correct</baseValue>
* </setOutcomeValue>
* </responseIf>
* </responseCondition>
*/
public static ResponseCondition createModalFeedbackResponseConditionByScore(ResponseProcessing responseProcessing) {
ResponseCondition responseCondition = new ResponseCondition(responseProcessing);
ResponseIf responseIf = new ResponseIf(responseCondition);
responseCondition.setResponseIf(responseIf);
And and = new And(responseIf);
responseIf.getExpressions().add(and);
Not not = new Not(and);
and.getExpressions().add(not);
Match match = new Match(not);
not.getExpressions().add(match);
Variable feedbackbasicVar = new Variable(match);
feedbackbasicVar.setIdentifier(QTI21Constants.FEEDBACKBASIC_CLX_IDENTIFIER);
match.getExpressions().add(feedbackbasicVar);
BaseValue emptyValue = new BaseValue(match);
emptyValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
emptyValue.setSingleValue(QTI21Constants.EMPTY_IDENTIFIER_VALUE);
match.getExpressions().add(emptyValue);
// SCORE >= MAXSCORE ( > is for security and special case where the max score is smalle than the sum of correct answers)
Gte greaterOrEqual = new Gte(and);
and.getExpressions().add(greaterOrEqual);
Variable scoreVar = new Variable(greaterOrEqual);
scoreVar.setIdentifier(QTI21Constants.SCORE_CLX_IDENTIFIER);
greaterOrEqual.getExpressions().add(scoreVar);
Variable maxScoreVar = new Variable(greaterOrEqual);
maxScoreVar.setIdentifier(QTI21Constants.MAXSCORE_CLX_IDENTIFIER);
greaterOrEqual.getExpressions().add(maxScoreVar);
// outcome value
SetOutcomeValue correctOutcomeValue = new SetOutcomeValue(responseIf);
correctOutcomeValue.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
responseIf.getResponseRules().add(correctOutcomeValue);
BaseValue correctValue = new BaseValue(correctOutcomeValue);
correctValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
correctValue.setSingleValue(QTI21Constants.CORRECT_IDENTIFIER_VALUE);
correctOutcomeValue.setExpression(correctValue);
return responseCondition;
}
use of uk.ac.ed.ph.jqtiplus.node.expression.operator.And in project OpenOLAT by OpenOLAT.
the class TestFeedbackBuilder method findFeedbackMatch.
private boolean findFeedbackMatch(OutcomeRule outcomeRule, boolean pass, ComplexReferenceIdentifier id) {
if (outcomeRule instanceof OutcomeCondition) {
OutcomeCondition outcomeCondition = (OutcomeCondition) outcomeRule;
OutcomeIf outcomeIf = outcomeCondition.getOutcomeIf();
if (outcomeIf != null && outcomeIf.getExpressions().size() == 1) {
Expression mustBeAnd = outcomeIf.getExpressions().get(0);
if (mustBeAnd instanceof And && mustBeAnd.getExpressions().size() == 1) {
Expression mustBeMatch = mustBeAnd.getExpressions().get(0);
if (mustBeMatch instanceof Match && mustBeMatch.getExpressions().size() == 2) {
return findFeedbackMatch((Match) mustBeMatch, pass, id);
}
}
}
}
return false;
}
use of uk.ac.ed.ph.jqtiplus.node.expression.operator.And in project OpenOLAT by OpenOLAT.
the class FIBAssessmentItemBuilder method buildMainScoreRuleAllCorrectAnswers.
private void buildMainScoreRuleAllCorrectAnswers(List<ResponseRule> responseRules) {
/*
<responseCondition>
<responseIf>
<and>
<match>
<value>-1.0</value>
<correct identifier="RESPONSE_1" />
</match>
<equal toleranceMode="relative" tolerance="0.1 0.1" includeLowerBound="true" includeUpperBound="true">
<correct identifier="RESPONSE_2" />
<variable identifier="RESPONSE_2" />
</equal>
</and>
<setOutcomeValue identifier="SCORE">
<sum>
<variable identifier="SCORE" />
<variable identifier="MAXSCORE" />
</sum>
</setOutcomeValue>
<setOutcomeValue identifier="FEEDBACKBASIC">
<baseValue baseType="identifier">
incorrect
</baseValue>
</setOutcomeValue>
</responseIf>
</responseCondition>
*/
// add condition
ResponseCondition rule = new ResponseCondition(assessmentItem.getResponseProcessing());
responseRules.add(0, rule);
{
// match all
ResponseIf responseElseIf = new ResponseIf(rule);
rule.setResponseIf(responseElseIf);
// rule.getResponseElseIfs().add(responseElseIf);
And and = new And(responseElseIf);
responseElseIf.setExpression(and);
for (Map.Entry<String, AbstractEntry> textEntryEntry : responseIdentifierToTextEntry.entrySet()) {
AbstractEntry abstractEntry = textEntryEntry.getValue();
if (abstractEntry instanceof TextEntry) {
Match match = new Match(and);
and.getExpressions().add(match);
TextEntry textEntry = (TextEntry) abstractEntry;
BaseValue variable = new BaseValue(match);
variable.setBaseTypeAttrValue(BaseType.FLOAT);
variable.setSingleValue(new FloatValue(-1.0d));
match.getExpressions().add(variable);
MapResponse correct = new MapResponse(match);
correct.setIdentifier(textEntry.getResponseIdentifier());
match.getExpressions().add(correct);
} else if (abstractEntry instanceof NumericalEntry) {
NumericalEntry numericalEntry = (NumericalEntry) abstractEntry;
Equal equal = new Equal(and);
equal.setToleranceMode(numericalEntry.getToleranceMode());
if (numericalEntry.getLowerTolerance() != null && numericalEntry.getUpperTolerance() != null) {
List<FloatOrVariableRef> tolerances = new ArrayList<>();
tolerances.add(new FloatOrVariableRef(numericalEntry.getLowerTolerance().doubleValue()));
tolerances.add(new FloatOrVariableRef(numericalEntry.getUpperTolerance().doubleValue()));
equal.setTolerances(tolerances);
}
equal.setIncludeLowerBound(Boolean.TRUE);
equal.setIncludeUpperBound(Boolean.TRUE);
and.getExpressions().add(equal);
ComplexReferenceIdentifier responseIdentifier = ComplexReferenceIdentifier.assumedLegal(numericalEntry.getResponseIdentifier().toString());
Correct correct = new Correct(equal);
correct.setIdentifier(responseIdentifier);
equal.getExpressions().add(correct);
Variable variable = new Variable(equal);
variable.setIdentifier(responseIdentifier);
equal.getExpressions().add(variable);
}
}
{
// outcome max score -> score
SetOutcomeValue scoreOutcomeValue = new SetOutcomeValue(responseElseIf);
scoreOutcomeValue.setIdentifier(QTI21Constants.SCORE_IDENTIFIER);
responseElseIf.getResponseRules().add(scoreOutcomeValue);
Sum sum = new Sum(scoreOutcomeValue);
scoreOutcomeValue.getExpressions().add(sum);
Variable scoreVar = new Variable(sum);
scoreVar.setIdentifier(QTI21Constants.SCORE_CLX_IDENTIFIER);
sum.getExpressions().add(scoreVar);
Variable maxScoreVar = new Variable(sum);
maxScoreVar.setIdentifier(QTI21Constants.MAXSCORE_CLX_IDENTIFIER);
sum.getExpressions().add(maxScoreVar);
}
{
// outcome feedback
SetOutcomeValue correctOutcomeValue = new SetOutcomeValue(responseElseIf);
correctOutcomeValue.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
responseElseIf.getResponseRules().add(correctOutcomeValue);
BaseValue correctValue = new BaseValue(correctOutcomeValue);
correctValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
correctValue.setSingleValue(QTI21Constants.CORRECT_IDENTIFIER_VALUE);
correctOutcomeValue.setExpression(correctValue);
}
}
{
// else feedback incorrect
ResponseElse responseElse = new ResponseElse(rule);
rule.setResponseElse(responseElse);
{
// outcome feedback
SetOutcomeValue correctOutcomeValue = new SetOutcomeValue(responseElse);
correctOutcomeValue.setIdentifier(QTI21Constants.FEEDBACKBASIC_IDENTIFIER);
responseElse.getResponseRules().add(correctOutcomeValue);
BaseValue correctValue = new BaseValue(correctOutcomeValue);
correctValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
correctValue.setSingleValue(QTI21Constants.INCORRECT_IDENTIFIER_VALUE);
correctOutcomeValue.setExpression(correctValue);
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.expression.operator.And in project OpenOLAT by OpenOLAT.
the class AssessmentTestFactory method createTestFeedbackModalCondition.
/*
<outcomeCondition>
<outcomeIf>
<and>
<match>
<baseValue baseType="boolean">
false
</baseValue>
<variable identifier="PASS" />
</match>
</and>
<setOutcomeValue identifier="FEEDBACKMODAL">
<multiple>
<variable identifier="FEEDBACKMODAL" />
<baseValue baseType="identifier">
Feedback1757237693
</baseValue>
</multiple>
</setOutcomeValue>
</outcomeIf>
</outcomeCondition>
*/
public static final OutcomeCondition createTestFeedbackModalCondition(AssessmentTest assessmentTest, boolean condition, Identifier feedbackIdentifier) {
OutcomeCondition outcomeCondition = new OutcomeCondition(assessmentTest);
OutcomeIf outcomeIf = new OutcomeIf(outcomeCondition);
outcomeCondition.setOutcomeIf(outcomeIf);
{
// condition
And and = new And(outcomeIf);
outcomeIf.getExpressions().add(and);
Match match = new Match(and);
and.getExpressions().add(match);
BaseValue feedbackVal = new BaseValue(match);
feedbackVal.setBaseTypeAttrValue(BaseType.BOOLEAN);
feedbackVal.setSingleValue(condition ? BooleanValue.TRUE : BooleanValue.FALSE);
match.getExpressions().add(feedbackVal);
Variable variable = new Variable(match);
variable.setIdentifier(ComplexReferenceIdentifier.parseString(QTI21Constants.PASS));
match.getExpressions().add(variable);
}
{
// outcome
SetOutcomeValue setOutcomeValue = new SetOutcomeValue(outcomeIf);
setOutcomeValue.setIdentifier(QTI21Constants.FEEDBACKMODAL_IDENTIFIER);
outcomeIf.getOutcomeRules().add(setOutcomeValue);
Multiple multiple = new Multiple(setOutcomeValue);
setOutcomeValue.getExpressions().add(multiple);
Variable variable = new Variable(multiple);
variable.setIdentifier(ComplexReferenceIdentifier.parseString(QTI21Constants.FEEDBACKMODAL));
multiple.getExpressions().add(variable);
BaseValue feedbackVal = new BaseValue(multiple);
feedbackVal.setBaseTypeAttrValue(BaseType.IDENTIFIER);
feedbackVal.setSingleValue(new IdentifierValue(feedbackIdentifier));
multiple.getExpressions().add(feedbackVal);
}
return outcomeCondition;
}
Aggregations