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

Allow valid permutations of molecules in api #639

Merged
merged 9 commits into from
Sep 25, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
public class IsaacSymbolicChemistryQuestion extends IsaacSymbolicQuestion {
@JsonProperty("isNuclear")
private boolean isNuclear;
private boolean allowPermutations;

/**
* @return whether the question is a nuclear question or not
Expand All @@ -45,4 +46,16 @@ public boolean isNuclear() {
public void setNuclear(boolean nuclear) {
isNuclear = nuclear;
}

/**
* @return whether the question allows compound permutations e.g. C10H22 == CH3(CH2)8CH3
*/
public boolean getAllowPermutations() { return allowPermutations; }

/**
* @param allowPermutations set whether the question allows compound permutations e.g. C10H22 == CH3(CH2)8CH3
*/
public void setAllowPermutations(boolean allowPermutations) {
this.allowPermutations = allowPermutations;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public class IsaacSymbolicChemistryQuestionDTO extends IsaacSymbolicQuestionDTO {
@JsonProperty("isNuclear")
private boolean isNuclear;
private boolean allowPermutations;

/**
* @return whether the question is a nuclear question or not
Expand All @@ -39,4 +40,16 @@ public boolean isNuclear() {
public void setNuclear(boolean nuclear) {
isNuclear = nuclear;
}

/**
* @return whether the question allows compound permutations e.g. C10H22 == CH3(CH2)8CH3
*/
public boolean getAllowPermutations() { return allowPermutations; }

/**
* @param allowPermutations set whether the question allows compound permutations e.g. C10H22 == CH3(CH2)8CH3
*/
public void setAllowPermutations(boolean allowPermutations) {
this.allowPermutations = allowPermutations;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ public QuestionValidationResponse validateQuestionResponse(final Question questi
req.put("target", formulaChoice.getMhchemExpression());
req.put("test", submittedFormula.getMhchemExpression());
req.put("description", chemistryQuestion.getId());
req.put("allowPermutations", String.valueOf(chemistryQuestion.getAllowPermutations()));
req.put("questionID", question.getId());

if (chemistryQuestion.isNuclear()) {
response = getResponseFromExternalValidator(nuclearValidatorUrl, req);
Expand Down Expand Up @@ -362,26 +364,36 @@ public QuestionValidationResponse validateQuestionResponse(final Question questi
// Input is nuclear, but atomic/mass numbers are invalid.
feedback = new Content("Check your atomic/mass numbers!");

} else if (closestMatch != null && closestMatch.isCorrect()) {
} else if (closestMatch != null && closestMatch.isCorrect() && closestResponse != null) {

// Weak match to a correct answer.
// closestResponse contains flags for generic mistakes from the Chemistry Checker.
// If any of these flags are false, provide feedback on the matched mistake.

if (!((String) closestResponse.get("expectedType")).contains("nuclear")
&& closestResponse.get("sameState").equals(false)) {
if (closestResponse.get("sameElements").equals(false)) {
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved

// Wrong state symbols
feedback = new Content("Check your state symbols!");
// Wrong element/compound
feedback = new Content("Check your elements!");

} else if (closestResponse.get("sameCoefficient").equals(false)) {

// Wrong coefficients
feedback = new Content("Check your coefficients!");

} else if (!isNuclear && closestResponse.get("sameState").equals(false)) {

// Wrong state symbols
feedback = new Content("Check your state symbols!");

} else if (!isNuclear && closestResponse.get("sameArrow").equals(false)) {

// Wrong arrow
feedback = new Content("What type of reaction is this?");

} else if (!isNuclear && closestResponse.get("sameBrackets").equals(false)) {

// Wrong brackets
feedback = new Content("Check your brackets!");
}
}
}
Expand Down
Loading