Skip to content

Commit

Permalink
Merge pull request #26 from ai-cfia/24-flaw-in-calculate-accuracy
Browse files Browse the repository at this point in the history
issue #24: fix regex pattern
  • Loading branch information
k-allagbe authored May 7, 2024
2 parents aee846b + f8619e5 commit 4517a7c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion finesse/accuracy_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def calculate_accuracy(responses_url: list[str], expected_url: list | str) -> Ac
score: float = 0.0
expected_url_ids = []

PATTERN = r'/[a-z]{3}/[0-9]+/[0-9]+$'
PATTERN = r'/[a-z]{3}/\d+/\d+'
if isinstance(expected_url, list):
for url in expected_url:
if url.startswith("https://inspection.canada.ca"):
Expand Down
28 changes: 28 additions & 0 deletions tests/test_accuracy_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,33 @@ def test_calculate_accuracy_multiple_expected_urls(self):
self.assertEqual(result.total_pages, 4)
self.assertEqual(result.score, 0.5)

def test_calculate_accuracy_no_match(self):
responses_url = [
"https://inspection.canada.ca/exporting-food-plants-or-animals/food-exports/food-specific-export-requirements/meat/crfpcp/eng/1434119937443/1434120400252",
"https://inspection.canada.ca/protection-des-vegetaux/especes-envahissantes/directives/date/d-08-04/fra/1323752901318/1323753612811",
"https://inspection.canada.ca/varietes-vegetales/vegetaux-a-caracteres-nouveaux/demandeurs/directive-94-08/documents-sur-la-biologie/lens-culinaris-medikus-lentille-/fra/1330978380871/1330978449837",
"https://inspection.canada.ca/protection-des-vegetaux/especes-envahissantes/directives/date/d-96-15/fra/1323854808025/1323854941807"
]
expected_url = "https://inspection.canada.ca/animal-health/terrestrial-animals/exports/pets/brunei-darussalam/eng/1475849543824/1475849672294"
result = calculate_accuracy(responses_url, expected_url)
self.assertEqual(result.position, 0)
self.assertEqual(result.total_pages, 4)
self.assertEqual(result.score, 0.0)

def test_calculate_accuracy_with_query_params(self):
responses_url = [
"https://inspection.canada.ca/exporting-food-plants-or-animals/food-exports/food-specific-export-requirements/meat/crfpcp/eng/1434119937443/1434120400252?param1=value1&param2=value2",
"https://inspection.canada.ca/protection-des-vegetaux/especes-envahissantes/directives/date/d-08-04/fra/1323752901318/1323753612811?param3=value3",
"https://inspection.canada.ca/varietes-vegetales/vegetaux-a-caracteres-nouveaux/demandeurs/directive-94-08/documents-sur-la-biologie/lens-culinaris-medikus-lentille-/fra/1330978380871/1330978449837?param4=value4",
"https://inspection.canada.ca/protection-des-vegetaux/especes-envahissantes/directives/date/d-96-15/fra/1323854808025/1323854941807?param5=value5"
]
expected_url = "https://inspection.canada.ca/protection-des-vegetaux/especes-envahissantes/directives/date/d-08-04/fra/1323752901318/1323753612811?param3=value3"
result = calculate_accuracy(responses_url, expected_url)
self.assertEqual(result.position, 1)
self.assertEqual(result.total_pages, 4)
self.assertEqual(result.score, 0.75)



if __name__ == "__main__":
unittest.main()

0 comments on commit 4517a7c

Please sign in to comment.