Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces accents and more into ascii equivalents for matching algorithm. #4716

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading