"""Lexical comparisons only: faithful evidence and embedding inputs stay unchanged.""" import re import unicodedata TRANSLATE_FROM = "۰۱۲۳۴۵۶۷۸۹٠١٢٣٤٥٦٧٨٩كيى" TRANSLATE_TO = "01234567890123456789کیی" TRANSLATION = str.maketrans(TRANSLATE_FROM, TRANSLATE_TO) LEXICAL_POLICY = "nfc-digits-kaf-yeh-lower-whitespace-terminal-period-v2" # Python split() and PostgreSQL locale whitespace classes differ for NBSP. # Bind the complete Unicode whitespace set used by Python str.split(). WHITESPACE = "\t\n\v\f\r\x1c\x1d\x1e\x1f\u0085\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000" SQL_LEXICAL_PARAMS = dict(lexical_from=TRANSLATE_FROM + WHITESPACE, lexical_to=TRANSLATE_TO + " " * len(WHITESPACE)) SQL_LEXICAL_TEXT = ( "regexp_replace(lower(translate(normalize(c.text, NFC), " ":lexical_from, :lexical_to)), ' +', ' ', 'g')" ) _TOKEN = re.compile(r"(?