use of uk.ac.ed.ph.jqtiplus.node.expression.operator.Match in project openolat by klemens.
the class AssessmentItemFactory method appendModalFeedbackCondition.
private static void appendModalFeedbackCondition(ModalFeedbackCondition condition, Identifier responseIdentifier, Cardinality cardinality, And and) {
ModalFeedbackCondition.Variable var = condition.getVariable();
ModalFeedbackCondition.Operator operator = condition.getOperator();
String value = condition.getValue();
if (var == ModalFeedbackCondition.Variable.response) {
if (cardinality == Cardinality.MULTIPLE) {
if (operator == ModalFeedbackCondition.Operator.equals) {
Member member = new Member(and);
and.getExpressions().add(member);
appendVariableBaseValue(var, value, responseIdentifier, member, true);
} else if (operator == ModalFeedbackCondition.Operator.notEquals) {
Not not = new Not(and);
and.getExpressions().add(not);
Member member = new Member(not);
not.getExpressions().add(member);
appendVariableBaseValue(var, value, responseIdentifier, member, true);
}
} else {
if (operator == ModalFeedbackCondition.Operator.equals) {
Match match = new Match(and);
and.getExpressions().add(match);
appendVariableBaseValue(var, value, responseIdentifier, match, false);
} else if (operator == ModalFeedbackCondition.Operator.notEquals) {
Not not = new Not(and);
and.getExpressions().add(not);
Match match = new Match(not);
not.getExpressions().add(match);
appendVariableBaseValue(var, value, responseIdentifier, match, false);
}
}
} else {
switch(operator) {
case bigger:
{
Gt gt = new Gt(and);
and.getExpressions().add(gt);
appendVariableBaseValue(var, value, responseIdentifier, gt, false);
break;
}
case biggerEquals:
{
Gte gte = new Gte(and);
and.getExpressions().add(gte);
appendVariableBaseValue(var, value, responseIdentifier, gte, false);
break;
}
case equals:
{
Equal equal = new Equal(and);
equal.setToleranceMode(ToleranceMode.EXACT);
and.getExpressions().add(equal);
appendVariableBaseValue(var, value, responseIdentifier, equal, false);
break;
}
case notEquals:
{
Not not = new Not(and);
and.getExpressions().add(not);
Equal equal = new Equal(not);
equal.setToleranceMode(ToleranceMode.EXACT);
not.getExpressions().add(equal);
appendVariableBaseValue(var, value, responseIdentifier, equal, false);
break;
}
case smaller:
{
Lt lt = new Lt(and);
and.getExpressions().add(lt);
appendVariableBaseValue(var, value, responseIdentifier, lt, false);
break;
}
case smallerEquals:
{
Lte lte = new Lte(and);
and.getExpressions().add(lte);
appendVariableBaseValue(var, value, responseIdentifier, lte, false);
break;
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.expression.operator.Match in project openolat by klemens.
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.Match in project openolat by klemens.
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.Match in project openolat by klemens.
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;
}
Aggregations