Skip to content

Commit

Permalink
Corona: try substring search before difflib
Browse files Browse the repository at this point in the history
If the name is sufficiently long, see if it's a substring of any of
the country names. This will allow, e.g.:

'United States' -> 'United States of America'

This changes may have to be reverted if it produces too many false
positives.
  • Loading branch information
kwzrd committed Oct 6, 2020
1 parent 60a9d7a commit 9bbd575
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ryan/exts/corona.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ def lookup(self, name: str) -> t.Optional[Country]:
log.debug("Named found directly in cache")
return country

if submatch := self.substring_match(normal_name, self.map):
log.debug("Found a substring match")
return submatch

log.debug("Name does not exist in cache, trying to find closest match")
try:
match = difflib.get_close_matches(normal_name, possibilities=self.map, n=1, cutoff=0.75)[0]
Expand Down

0 comments on commit 9bbd575

Please sign in to comment.