Exemplo n.º 1
0
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.
Exemplo n.º 2
0
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.
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
def test_ascii_should_clean_string():
    s = ascii(u'Aystringé')
    assert s == 'aystringe'
Exemplo n.º 7
0
def test_ascii_should_behave_like_a_string():
    s = ascii('mystring')
    assert str(s) == 'mystring'
Exemplo n.º 8
0
def test_ascii_should_cache_cleaned_string(monkeypatch):
    s = ascii('mystring')
    assert s._cache

    def do_not_call_me(x):
        assert False
Exemplo n.º 9
0
def test_ascii_should_clean_string():
    s = ascii(u'Aystringé')
    assert s == 'aystringe'
Exemplo n.º 10
0
def test_ascii_should_behave_like_a_string():
    s = ascii('mystring')
    assert str(s) == 'mystring'