Esempio n. 1
0
def test_no_labels(store, label_store):
    '''Make sure the learner can handle zero labels.'''
    # Overwrite the query so we get some hits.
    store.put([('q', counter_fc({'x': 5, 'y': 90}))])
    results = (mod_pairwise.similar(store, label_store)
                           .set_query_id('q')
                           .set_query_params({'limit': 1})
                           .recommendations())
    assert len(results['results']) == 0
Esempio n. 2
0
def test_no_labels(store, label_store):
    '''Make sure the learner can handle zero labels.'''
    # Overwrite the query so we get some hits.
    store.put([('q', counter_fc({'x': 5, 'y': 90}))])
    results = (mod_pairwise.similar(
        store, label_store).set_query_id('q').set_query_params({
            'limit': 1
        }).recommendations())
    assert len(results['results']) == 0
Esempio n. 3
0
def test_search_engine_limit(store, label_store):
    '''Pretty much the same as classify, but for the search engine.'''
    content_objs, labels = interesting_training_data()
    store.put(content_objs)
    for lab in labels:
        label_store.put(lab)

    # Overwrite the query so we get some hits.
    store.put([('q', counter_fc({'x': 5, 'y': 90}))])

    # And assign some labels to the query.
    # (label expansion should fill in the rest)
    label_store.put(neg_label('q', 'a'))
    label_store.put(pos_label('q', 'b'))

    results = (mod_pairwise.similar(store, label_store)
                           .set_query_id('q')
                           .set_query_params({'limit': 2})
                           .recommendations())
    assert len(results['results']) == 2
Esempio n. 4
0
def test_search_engine_limit(store, label_store):
    '''Pretty much the same as classify, but for the search engine.'''
    content_objs, labels = interesting_training_data()
    store.put(content_objs)
    for lab in labels:
        label_store.put(lab)

    # Overwrite the query so we get some hits.
    store.put([('q', counter_fc({'x': 5, 'y': 90}))])

    # And assign some labels to the query.
    # (label expansion should fill in the rest)
    label_store.put(neg_label('q', 'a'))
    label_store.put(pos_label('q', 'b'))

    results = (mod_pairwise.similar(
        store, label_store).set_query_id('q').set_query_params({
            'limit': 2
        }).recommendations())
    assert len(results['results']) == 2
Esempio n. 5
0
def test_only_negative_labels(store, label_store):
    '''Make sure the learner can handle one class of labels.'''
    content_objs, labels = interesting_training_data()
    store.put(content_objs)
    for lab in labels:
        if lab.value == CorefValue.Negative:
            label_store.put(lab)

    # Overwrite the query so we get some hits.
    store.put([('q', counter_fc({'x': 5, 'y': 90}))])

    # And assign a label to the query.
    label_store.put(neg_label('q', 'a'))

    results = (mod_pairwise.similar(store, label_store)
                           .set_query_id('q')
                           .set_query_params({'limit': 100})
                           .recommendations())
    # The search engine will fall back to a plain index scan if it has
    # insufficient training data.
    assert len(results['results']) >= 0
Esempio n. 6
0
def test_only_negative_labels(store, label_store):
    '''Make sure the learner can handle one class of labels.'''
    content_objs, labels = interesting_training_data()
    store.put(content_objs)
    for lab in labels:
        if lab.value == CorefValue.Negative:
            label_store.put(lab)

    # Overwrite the query so we get some hits.
    store.put([('q', counter_fc({'x': 5, 'y': 90}))])

    # And assign a label to the query.
    label_store.put(neg_label('q', 'a'))

    results = (mod_pairwise.similar(
        store, label_store).set_query_id('q').set_query_params({
            'limit': 100
        }).recommendations())
    # The search engine will fall back to a plain index scan if it has
    # insufficient training data.
    assert len(results['results']) >= 0