Exemplo n.º 1
0
def recommend(source, target, search, seed, count, include_pageviews, max_candidates=500):
    """
    1. Use finder to select a set of candidate articles
    2. Filter out candidates that are not missing, are disambiguation pages, etc
    3. get pageview info for each passing candidate if desired
    """

    recs = []

    if seed:
        finder = finder_map[search]
        for seed in seed.split('|'):
            recs.extend(finder.get_candidates(source, seed, max_candidates))
    else:
        recs.extend(finder_map['mostpopular'].get_candidates(source, seed, max_candidates))

    recs = sorted(recs, key=lambda x: x.rank)

    recs = filters.apply_filters(source, target, recs, count)

    if recs and include_pageviews:
        recs = pageviews.set_pageview_data(source, recs)

    recs = sorted(recs, key=lambda x: x.rank)
    return [{'title': r.title, 'pageviews': r.pageviews, 'wikidata_id': r.wikidata_id} for r in recs]
Exemplo n.º 2
0
def recommend(source,
              target,
              search,
              seed,
              count,
              include_pageviews,
              max_candidates=500):
    """
    1. Use finder to select a set of candidate articles
    2. Filter out candidates that are not missing, are disambiguation pages, etc
    3. get pageview info for each passing candidate if desired
    """

    recs = []

    if seed:
        finder = finder_map[search]
        for seed in seed.split('|'):
            recs.extend(finder.get_candidates(source, seed, max_candidates))
    else:
        recs.extend(finder_map['mostpopular'].get_candidates(
            source, seed, max_candidates))

    recs = sorted(recs, key=lambda x: x.rank)

    recs = filters.apply_filters(source, target, recs, count)

    if recs and include_pageviews:
        recs = pageviews.set_pageview_data(source, recs)

    recs = sorted(recs, key=lambda x: x.rank)
    return [{
        'title': r.title,
        'pageviews': r.pageviews,
        'wikidata_id': r.wikidata_id
    } for r in recs]
Exemplo n.º 3
0
def run_getter():
    articles = [utils.Article(TITLE)]
    result = pageviews.set_pageview_data(SOURCE, articles)
    assert result == articles
    return result
def run_getter():
    articles = [utils.Article(TITLE)]
    result = pageviews.set_pageview_data(SOURCE, articles)
    assert result == articles
    return result