Skip to content

Commit

Permalink
improve answerline parsing
Browse files Browse the repository at this point in the history
reject non-number, single letter answers for unformatted answerlines where the answerline is longer than 1 character
  • Loading branch information
geoffrey-wu committed Nov 15, 2022
1 parent edd5b04 commit 1c628ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion server/quizbowl.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function parseAnswerline(answerline) {
* @param {Number} strictness - the number of characters per error allowed for two tokens to match.
* @returns {Boolean}
*/
function stringMatchesReference(string, reference, strictness=4) {
function stringMatchesReference(string, reference, strictness = 4) {
if (string === null || string === undefined || reference === null || reference === undefined) {
return false;
}
Expand Down Expand Up @@ -244,6 +244,10 @@ function checkAnswer(answerline, givenAnswer) {
const isFormattedAnswerline = answerline.includes('<u>');
const parsedAnswerline = parseAnswerline(answerline);

if (!isFormattedAnswerline && answerline.length > 1 && givenAnswer.length === 1 && isNaN(givenAnswer)) {
return 'reject';
}

for (const answer of parsedAnswerline['reject']) {
if (stringMatchesReference(answer[2], givenAnswer, 11) && stringMatchesReference(givenAnswer, answer[2], 11)) {
return 'reject';
Expand Down
16 changes: 15 additions & 1 deletion tests/quizbowl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const formatted_answers = [
"The <b><u>Wasteland</u></b>",
"<b><u>W</u></b>orld <b><u>T</u></b>rade <b><u>O</u></b>rganization",
"The (Holy) <b><u>Grail</u></b>",

// or in the main answer,
// and commas instead of semicolons or "or" in alternate answer
"<b><u>Furies</u></b> or <b><u>Erinyes</u></b> [accept <b><u>Eumenides</u></b>, <b><u>Semnai</u></b>, or <b><u>Dirae</u></b>]",
];

const answers = [
Expand All @@ -42,14 +46,16 @@ const answers = [
"wave-particle duality [accept de Broglie wave until “de Broglie”; accept answers indicating that something is both a wave and a particle; prompt on duality or wave nature or complementarity; prompt on interference by asking “what property of matter causes the interference?”]",
"“September 1, 1939”",
"IR spectroscopy",
"adsorption [accept chemisorption or chemical adsorption or physisorption or physical adsorption; prompt on “sorption”; do not accept or prompt on “absorption”]"
"adsorption [accept chemisorption or chemical adsorption or physisorption or physical adsorption; prompt on “sorption”; do not accept or prompt on “absorption”]",
"fluorescence microscopy [prompt on super-resolved microscopy or confocal microscopy]",
];

const tests = [
// single answerline
['accept', formatted_answers[0], 'Jasper Johns'],
['accept', formatted_answers[0], 'Johns'],
['reject', formatted_answers[0], 'Jasper'],
['reject', formatted_answers[0], 'Jo'],

['accept', formatted_answers[1], 'manchester'],
['accept', formatted_answers[1], 'MANCHESTER'],
Expand Down Expand Up @@ -155,10 +161,16 @@ const tests = [
['accept', formatted_answers[25], 'grail'],
['accept', formatted_answers[25], 'holy grail'],

['accept', formatted_answers[26], 'Furies'],
['accept', formatted_answers[26], 'Erinyes'],
['accept', formatted_answers[26], 'Eumenides'],
['accept', formatted_answers[26], 'Semnai'],

['accept', answers[0], 'boll'],
['accept', answers[0], 'heinrich boll'],
['accept', answers[0], 'Böll'],
['accept', answers[0], 'Heinrich Böll'],
['reject', answers[0], 'H'],

// unformatted answerlines
['accept', answers[1], 'chimp'],
Expand Down Expand Up @@ -196,6 +208,8 @@ const tests = [

['accept', answers[12], 'adsorption'],
['reject', answers[12], 'absorption'],

['accept', answers[13], 'microscopy'],
];

let successful = 0, total = 0;
Expand Down

0 comments on commit 1c628ef

Please sign in to comment.