Пример #1
0
def get_possible_matches(review_requests, summary, description, limit=5):
    """Returns a sorted list of tuples of score and review request.

    Each review request is given a score based on the summary and
    description provided. The result is a sorted list of tuples containing
    the score and the corresponding review request, sorted by the highest
    scoring review request first.
    """
    candidates = []

    # Get all potential matches.
    for review_request in review_requests.all_items:
        summary_pair = (get_draft_or_current_value('summary', review_request),
                        summary)
        description_pair = (get_draft_or_current_value('description',
                                                       review_request),
                            description)
        score = Score.get_match(summary_pair, description_pair)
        candidates.append((score, review_request))

    # Sort by summary and description on descending rank.
    sorted_candidates = sorted(
        candidates,
        key=lambda m: (m[0].summary_score, m[0].description_score),
        reverse=True
    )

    return sorted_candidates[:limit]
Пример #2
0
def get_possible_matches(review_requests, summary, description, limit=5):
    """Returns a sorted list of tuples of score and review request.

    Each review request is given a score based on the summary and
    description provided. The result is a sorted list of tuples containing
    the score and the corresponding review request, sorted by the highest
    scoring review request first.
    """
    candidates = []

    # Get all potential matches.
    for review_request in review_requests.all_items:
        summary_pair = (get_draft_or_current_value('summary',
                                                   review_request), summary)
        description_pair = (get_draft_or_current_value('description',
                                                       review_request),
                            description)
        score = Score.get_match(summary_pair, description_pair)
        candidates.append((score, review_request))

    # Sort by summary and description on descending rank.
    sorted_candidates = sorted(candidates,
                               key=lambda m:
                               (m[0].summary_score, m[0].description_score),
                               reverse=True)

    return sorted_candidates[:limit]