Skip to content

Commit

Permalink
Also apply fuzzy matching to answer option matching, but don't disreg…
Browse files Browse the repository at this point in the history
…ard characters that may change the nature of the answer option
  • Loading branch information
motin committed Mar 30, 2020
1 parent eefd150 commit b79faf0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/lib/answerOptionMatchesFactualAnswer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ const testAnswerOptionMatchesFactualAnswer: Macro<any> = (
factualAnswer: "1% ",
expectedOutput: true
},
{
answerOption: "1%",
factualAnswer: "1%,",
expectedOutput: true
},
{
answerOption: "1%,",
factualAnswer: "1%",
expectedOutput: true
},
{
answerOption: '1%"',
factualAnswer: "1%",
expectedOutput: true
},
{
answerOption: "1%",
factualAnswer: '1%"',
expectedOutput: true
},
{
answerOption: "30-40%",
factualAnswer: "24%",
Expand Down
5 changes: 3 additions & 2 deletions src/lib/answerOptionMatchesFactualAnswer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { extractNumericalPartsOfAnswerOption } from "./extractNumericalPartsOfAnswerOption";
import { keyNormalizerForSlightlyFuzzyLookups } from "./keyNormalizerForSlightlyFuzzyLookups";

/**
* @hidden
Expand All @@ -7,8 +8,8 @@ export function answerOptionMatchesFactualAnswer(
answerOption: string,
factualAnswer: string
): boolean {
answerOption = answerOption.trim().toLocaleLowerCase();
factualAnswer = factualAnswer.trim().toLocaleLowerCase();
answerOption = keyNormalizerForSlightlyFuzzyLookups(answerOption);
factualAnswer = keyNormalizerForSlightlyFuzzyLookups(factualAnswer);
if (answerOption === factualAnswer) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/keyNormalizerForSlightlyFuzzyLookups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export function keyNormalizerForSlightlyFuzzyLookups(
const trimmedLowerCasedWithoutDiacritics = removeDiacritics(
lookupKey.trim().toLowerCase()
);
return trimmedLowerCasedWithoutDiacritics.replace(/[^a-z0-9 ()]/g, "");
return trimmedLowerCasedWithoutDiacritics.replace(/[^a-z0-9%\-.,<> ()]/g, "");
}

0 comments on commit b79faf0

Please sign in to comment.