def test_ascii_should_cache_cleaned_string(monkeypatch): s = ascii('mystring') assert s._cache def do_not_call_me(x): assert False monkeypatch.setattr('addok.helpers.text.alphanumerize', do_not_call_me) ascii(s) # Should not call alphanumerize.
def _score_by_ngram_distance(helper, result): for label in result.labels: label = ascii(label) score = compare_ngrams(label, helper.query) result.add_score('str_distance', score, ceiling=1.0) if score >= config.MATCH_THRESHOLD: break
def score_by_autocomplete_distance(helper, result): if not helper.autocomplete: return score = 0 query = ascii(helper.query) for idx, label in enumerate(result.labels): label = ascii(label) result.labels[idx] = label # Cache ascii folding. if equals(query, label): score = 1.0 elif startswith(query, label): score = 0.9 elif contains(query, label): score = 0.7 if score: result.add_score('str_distance', score, ceiling=1.0) if not score: _score_by_str_distance(helper, result, scale=0.9)
def score_by_autocomplete_distance(helper, result): if not helper._autocomplete: return score = 0 query = ascii(helper.query) for idx, label in enumerate(result.labels): label = ascii(label) result.labels[idx] = label # Cache ascii folding. if equals(query, label): score = 1.0 elif startswith(query, label): score = 0.9 elif contains(query, label): score = 0.7 if score: result.add_score('str_distance', score, ceiling=1.0) if score >= config.MATCH_THRESHOLD: break if not score: _score_by_ngram_distance(helper, result)
def test_ascii_should_clean_string(): s = ascii(u'Aystringé') assert s == 'aystringe'
def test_ascii_should_behave_like_a_string(): s = ascii('mystring') assert str(s) == 'mystring'
def test_ascii_should_cache_cleaned_string(monkeypatch): s = ascii('mystring') assert s._cache def do_not_call_me(x): assert False