Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allowScalingCoefficents option to Chemistry checker #646

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class IsaacSymbolicChemistryQuestion extends IsaacSymbolicQuestion {
@JsonProperty("isNuclear")
private boolean isNuclear;
private boolean allowPermutations;
private boolean allowScalingCoefficients;

/**
* @return whether the question is a nuclear question or not
Expand All @@ -58,4 +59,16 @@ public void setNuclear(boolean nuclear) {
public void setAllowPermutations(boolean allowPermutations) {
this.allowPermutations = allowPermutations;
}

/**
* @return whether the question allows coefficients to be multiplied e.g. 10 H2 + 5 O2 -> 10 H2O
*/
public boolean getAllowScalingCoefficients() { return allowScalingCoefficients; }

/**
* @param allowScalingCoefficients set whether the question allows coefficients to be multiplied e.g. 10 H2 + 5 O2 -> 10 H2O
*/
public void setAllowScalingCoefficients(boolean allowScalingCoefficients) {
this.allowScalingCoefficients = allowScalingCoefficients;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class IsaacSymbolicChemistryQuestionDTO extends IsaacSymbolicQuestionDTO
@JsonProperty("isNuclear")
private boolean isNuclear;
private boolean allowPermutations;
private boolean allowScalingCoefficients;

/**
* @return whether the question is a nuclear question or not
Expand All @@ -52,4 +53,16 @@ public void setNuclear(boolean nuclear) {
public void setAllowPermutations(boolean allowPermutations) {
this.allowPermutations = allowPermutations;
}

/**
* @return whether the question allows coefficients to be multiplied e.g. 10 H2 + 5 O2 -> 10 H2O
*/
public boolean getAllowScalingCoefficients() { return allowScalingCoefficients; }

/**
* @param allowScalingCoefficients set whether the question allows coefficients to be multiplied e.g. 10 H2 + 5 O2 -> 10 H2O
*/
public void setAllowScalingCoefficients(boolean allowScalingCoefficients) {
this.allowScalingCoefficients = allowScalingCoefficients;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import static uk.ac.cam.cl.dtg.isaac.api.Constants.*;

Expand All @@ -55,6 +56,11 @@ private enum MatchType {
private final String chemistryValidatorUrl;
private final String nuclearValidatorUrl;

private final Set<String> VALID_ERROR_FEEDBACK = Set.of(
"Division by zero is undefined!",
"Your answer contains invalid syntax!"
);

public IsaacSymbolicChemistryValidator(final String hostname, final String port) {
this.nuclearValidatorUrl = "http://" + hostname + ":" + port + "/nuclear/check";
this.chemistryValidatorUrl = "http://" + hostname + ":" + port + "/chemistry/check";
Expand Down Expand Up @@ -192,6 +198,7 @@ public QuestionValidationResponse validateQuestionResponse(final Question questi
req.put("test", submittedFormula.getMhchemExpression());
req.put("description", chemistryQuestion.getId());
req.put("allowPermutations", String.valueOf(chemistryQuestion.getAllowPermutations()));
req.put("allowScalingCoefficients", String.valueOf(chemistryQuestion.getAllowScalingCoefficients()));
req.put("questionID", question.getId());

if (chemistryQuestion.isNuclear()) {
Expand All @@ -212,9 +219,9 @@ public QuestionValidationResponse validateQuestionResponse(final Question questi
+ "\" with symbolic chemistry checker: " + response.get("error"));
}

closestMatch = formulaChoice;
closestResponse = response;
containsError = true;
// If parsing was unsuccessful the student provided the wrong type
isNuclear = !chemistryQuestion.isNuclear();
break;
}

Expand Down Expand Up @@ -324,9 +331,12 @@ public QuestionValidationResponse validateQuestionResponse(final Question questi
if (containsError) {

// User input contains error terms.
// FIXME: This currently clashes with determining whether the submitted answer was the wrong type
// Inequality should be changed to not allow Nuclear syntax in Chemistry questions and vice versa
feedback = new Content("Your answer contains invalid syntax!");
if (closestResponse != null && VALID_ERROR_FEEDBACK.contains((String) closestResponse.get("error"))) {
feedback = new Content((String) closestResponse.get("error"));
} else {
// Default error message
feedback = new Content("Your answer contains invalid syntax!");
}

} else if (closestMatch != null && closestMatchType == MatchType.EXACT) {

Expand Down
Loading