From 1c628ef7e302a9c458e737042ddacd4b7ab5208f Mon Sep 17 00:00:00 2001 From: Geoffrey Wu Date: Tue, 15 Nov 2022 02:35:05 -0500 Subject: [PATCH] improve answerline parsing reject non-number, single letter answers for unformatted answerlines where the answerline is longer than 1 character --- server/quizbowl.js | 6 +++++- tests/quizbowl.test.js | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/server/quizbowl.js b/server/quizbowl.js index 1c35fed11..caf304576 100644 --- a/server/quizbowl.js +++ b/server/quizbowl.js @@ -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; } @@ -244,6 +244,10 @@ function checkAnswer(answerline, givenAnswer) { const isFormattedAnswerline = answerline.includes(''); 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'; diff --git a/tests/quizbowl.test.js b/tests/quizbowl.test.js index be4def3ea..96322a306 100644 --- a/tests/quizbowl.test.js +++ b/tests/quizbowl.test.js @@ -27,6 +27,10 @@ const formatted_answers = [ "The Wasteland", "World Trade Organization", "The (Holy) Grail", + + // or in the main answer, + // and commas instead of semicolons or "or" in alternate answer + "Furies or Erinyes [accept Eumenides, Semnai, or Dirae]", ]; const answers = [ @@ -42,7 +46,8 @@ 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 = [ @@ -50,6 +55,7 @@ const tests = [ ['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'], @@ -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'], @@ -196,6 +208,8 @@ const tests = [ ['accept', answers[12], 'adsorption'], ['reject', answers[12], 'absorption'], + + ['accept', answers[13], 'microscopy'], ]; let successful = 0, total = 0;