Skip to content

Commit

Permalink
Merge branch 'master' into links
Browse files Browse the repository at this point in the history
  • Loading branch information
hqpho authored Nov 7, 2024
2 parents 69ee3cf + 82d3c9c commit f9905b5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions server/routes/shared_api/autocomplete/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import re
from typing import Dict, List
import unicodedata
from urllib.parse import urlencode

from flask import current_app
Expand Down Expand Up @@ -135,11 +136,21 @@ def off_by_one_letter(str1_word: str, name_word: str) -> bool:
return offby <= 1


def sanitize_and_replace_non_ascii(string: str) -> str:
"""Sanitize and replace non ascii.
Returns:
String sanitized and without accents, cedillas, or enye."""
nfkd_form = unicodedata.normalize('NFKD', string)
return "".join([c for c in nfkd_form if not unicodedata.combining(c)])


def get_match_score(match_string: str, name: str) -> float:
"""Computes a 'score' based on the matching words in two strings. Lowest
score is best match.
Returns:
Float score."""
name = sanitize_and_replace_non_ascii(name)
match_string = sanitize_and_replace_non_ascii(match_string)

rgx = re.compile(r'[\s|,]+')
words_in_name = re.split(rgx, name)
Expand Down

0 comments on commit f9905b5

Please sign in to comment.