def cook_test(test, args, n=4):
    '''Takes a test sentence and returns an object that
    encapsulates everything that BLEU needs to know about it.'''
    
    reflens, refmaxcounts = args
    test = normalize(test)
    result = {}
    result["testlen"] = len(test)

    # Calculate effective reference sentence length.
    
    if eff_ref_len == "shortest":
        result["reflen"] = min(reflens)
    elif eff_ref_len == "average":
        result["reflen"] = float(sum(reflens))/len(reflens)
    elif eff_ref_len == "closest":
        min_diff = None
        for reflen in reflens:
            if min_diff is None or abs(reflen-len(test)) < min_diff:
                min_diff = abs(reflen-len(test))
                result['reflen'] = reflen

    result["guess"] = [max(len(test)-k+1,0) for k in range(1,n+1)]

    result['correct'] = [0]*n
    counts = count_ngrams(test, n)
    for (ngram, count) in list(counts.items()):
        result["correct"][len(ngram)-1] += min(refmaxcounts.get(ngram,0), count)

    return result
def cook_test ( test , args , n = 4 ) : reflens , refmaxcounts = args test = normalize ( test ) result = { } result [ "testlen" ] = len ( test ) if eff_ref_len == "shortest" : result [ "reflen" ] = min ( reflens ) elif eff_ref_len == "average" : result [ "reflen" ] = float ( sum ( reflens ) ) / len ( reflens ) elif eff_ref_len == "closest" : min_diff = None for reflen in reflens : if min_diff is None or abs ( reflen - len ( test ) ) < min_diff : min_diff = abs ( reflen - len ( test ) ) result [ 'reflen' ] = reflen result [ "guess" ] = [ max ( len ( test ) - k + 1 , 0 ) for k in range ( 1 , n + 1 ) ] result [ 'correct' ] = [ 0 ] * n counts = count_ngrams ( test , n ) for ( ngram , count ) in list ( counts . items ( ) ) : result [ "correct" ] [ len ( ngram ) - 1 ] += min ( refmaxcounts . get ( ngram , 0 ) , count ) return result
Takes a test sentence and returns an object that
    encapsulates everything that BLEU needs to know about it.