Skip to content

Commit

Permalink
close #63
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffrey-wu committed Sep 8, 2022
1 parent b47e1e0 commit d663e6c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
13 changes: 13 additions & 0 deletions server/quizbowl.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ function parseAnswerline(answerline) {
}
}

/**
* Get all words which are partially or wholly underlined.
*/
const extractKeyWords = (string) => {
const tokens = string.split(' ');
return tokens.filter(token => token.length > 0 && token.match(/<[^>]*>/))
Expand Down Expand Up @@ -216,6 +219,16 @@ function checkAnswer(answerline, givenAnswer) {
}
}

if (answerline.includes('[accept either') || answerline.includes('(accept either')) {
const [answer1, answer2] = parsedAnswerline.accept[0][0].split(' ');
if (answerWorks(answer1, givenAnswer, isFormattedAnswerline)) {
return 'accept';
}
if (answerWorks(answer2, givenAnswer, isFormattedAnswerline)) {
return 'accept';
}
}

for (const type of ['accept', 'prompt']) {
for (const answer of parsedAnswerline[type]) {
if (answerWorks(answer[0], givenAnswer, isFormattedAnswerline)) return type;
Expand Down
20 changes: 20 additions & 0 deletions tests/quizbowl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const formatted_answers = [
"<b><u>primatology</u></b> [or word forms; accept any answers about the study of great <b><u>ape</u></b>s, nonhuman <b><u>primate</u></b>s, <b><u>gorilla</u></b>s, <b><u>bonobo</u></b>s, or <b><u>chimp</u></b>anzees; prompt on the study of <u>monkey</u>s or <u>simian</u>s; prompt on word forms of <u>ethology</u>, <u>biology</u>, <u>anthropology</u>, or evolutionary or social <u>psychology</u>; prompt on the study of <u>animal</u>s with “what type of animals?”]",
"Heinrich <b><u>Böll</u></b> [or Heinrich Theodor <b><u>Böll</u></b>]",
"<b><u>Louis-Philippe</u></b> [or <b><u>Duke d’Orleans</u></b>; prompt on “Citizen King” before mentioned]",
"Johann <b><u>Tserclaes</u></b>, Graf von <b><u>Tilly</u></b> (accept either underlined answer as well as Count of <b><u>Tilly</u></b>)",
"<b><u>Paul</u></b> <b><u>Bäumer</u></b> [accept either name]",
"<b><u>Matsuo</u></b> <b><u>Bashō</u></b> [accept either underlined part; accept <b><u>Matsuo</u></b> Kinsaku or <b><u>Matsuo</u></b> Chūemon Munefusa]"
];

const answers = [
Expand Down Expand Up @@ -59,6 +62,23 @@ const tests = [
['reject', formatted_answers[8], 'Louis'],
['reject', formatted_answers[8], 'Philippe'],

// accept either clauses
['accept', formatted_answers[9], 'Tserclaes'],
['accept', formatted_answers[9], 'Tilly'],
['accept', formatted_answers[9], 'Count of Tilly'],

// accept either clauses with special characters
['accept', formatted_answers[10], 'Baumer'],
['accept', formatted_answers[10], 'Bäumer'],
['accept', formatted_answers[10], 'Paul'],
['accept', formatted_answers[10], 'Paul Bäumer'],

['accept', formatted_answers[11], 'Basho'],
['accept', formatted_answers[11], 'Bashō'],
['accept', formatted_answers[11], 'Matsuo'],
['accept', formatted_answers[11], 'Matsuo Basho'],
['accept', formatted_answers[11], 'Matsuo Bashō'],

['accept', answers[0], 'boll'],
['accept', answers[0], 'heinrich boll'],
['accept', answers[0], 'Böll'],
Expand Down

0 comments on commit d663e6c

Please sign in to comment.