(test, (reflen, refmaxcounts), eff=None, n=4)
return result
Takes a test sentence and returns an object that
    encapsulates everything that BLEU needs to know about it.
Takes a test sentence and returns an object that
    encapsulates everything that BLEU needs to know about it.
Takes a test sentence and returns an object that encapsulates everything that BLEU needs to know about it .
def cook_test(test, (reflen, refmaxcounts), eff=None, n=4):
    '''Takes a test sentence and returns an object that
    encapsulates everything that BLEU needs to know about it.'''

    testlen, counts = precook(test, n, True)

    result = {}

    # Calculate effective reference sentence length.
    
    if eff == "closest":
        result["reflen"] = min((abs(l-testlen), l) for l in reflen)[1]
    else: ## i.e., "average" or "shortest" or None
        result["reflen"] = reflen

    result["testlen"] = testlen

    result["guess"] = [max(0,testlen-k+1) for k in xrange(1,n+1)]

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

    return result
def cook_test ( test , ( reflen , refmaxcounts ) , eff = None , n = 4 ) : testlen , counts = precook ( test , n , True ) result = { } # Calculate effective reference sentence length. if eff == "closest" : result [ "reflen" ] = min ( ( abs ( l - testlen ) , l ) for l in reflen ) [ 1 ] else : ## i.e., "average" or "shortest" or None result [ "reflen" ] = reflen result [ "testlen" ] = testlen result [ "guess" ] = [ max ( 0 , testlen - k + 1 ) for k in xrange ( 1 , n + 1 ) ] result [ 'correct' ] = [ 0 ] * n for ( ngram , count ) in counts . iteritems ( ) : result [ "correct" ] [ len ( ngram ) - 1 ] += min ( refmaxcounts . get ( ngram , 0 ) , count ) return result