def pk(ref, hyp, k=None, boundary='1'):
 if (k is None):
  k = int(round((len(ref) / (ref.count(boundary) * 2.0))))
 err = 0
 for i in xrange(((len(ref) - k) + 1)):
  r = (ref[i:(i + k)].count(boundary) > 0)
  h = (hyp[i:(i + k)].count(boundary) > 0)
  if (r != h):
   err += 1
 return (err / ((len(ref) - k) + 1.0))

def pk ( ref , hyp , k = None , boundary = '1' ) : if ( k is None ) : k = int ( round ( ( len ( ref ) / ( ref . count ( boundary ) * 2.0 ) ) ) ) err = 0 for i in xrange ( ( ( len ( ref ) - k ) + 1 ) ) : r = ( ref [ i : ( i + k ) ] . count ( boundary ) > 0 ) h = ( hyp [ i : ( i + k ) ] . count ( boundary ) > 0 ) if ( r != h ) : err += 1 return ( err / ( ( len ( ref ) - k ) + 1.0 ) )
compute the pk metric for a pair of segmentations a segmentation is any sequence over a vocabulary of two items .