def _compute_precision(references, translation, n):
matches = <NUM_LIT:0><EOL>candidates = <NUM_LIT:0><EOL>ref_ngram_counts = Counter()<EOL>for reference in references:<EOL><INDENT>ref_ngram_counts |= _ngrams(reference, n)<EOL><DEDENT>trans_ngram_counts = _ngrams(translation, n)<EOL>overlap_ngram_counts = trans_ngram_counts & ref_ngram_counts<EOL>matches += sum(overlap_ngram_counts.values())<EOL>possible_matches = len(translation) - n + <NUM_LIT:1><EOL>if possible_matches > <NUM_LIT:0>:<EOL><INDENT>candidates += possible_matches<EOL><DEDENT>return matches, candidates<EOL>
Compute ngram precision.

    Parameters
    ----------
    references: list(list(str))
        A list of references.
    translation: list(str)
        A translation.
    n: int
        Order of n-gram.

    Returns
    -------
    matches: int
        Number of matched nth order n-grams
    candidates
        Number of possible nth order n-grams