示例#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.
示例#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.
示例#3
0
文件: results.py 项目: xlqian/addok
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
示例#4
0
文件: results.py 项目: mkc188/addok
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)
示例#5
0
文件: results.py 项目: xlqian/addok
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)
示例#6
0
def test_ascii_should_clean_string():
    s = ascii(u'Aystringé')
    assert s == 'aystringe'
示例#7
0
def test_ascii_should_behave_like_a_string():
    s = ascii('mystring')
    assert str(s) == 'mystring'
示例#8
0
def test_ascii_should_cache_cleaned_string(monkeypatch):
    s = ascii('mystring')
    assert s._cache

    def do_not_call_me(x):
        assert False
示例#9
0
def test_ascii_should_clean_string():
    s = ascii(u'Aystringé')
    assert s == 'aystringe'
示例#10
0
def test_ascii_should_behave_like_a_string():
    s = ascii('mystring')
    assert str(s) == 'mystring'