#NEWLINE# def windowdiff( seg1 , seg2 , k , boundary = '1' , weighted = False ) : #NEWLINE# #INDENT# '\n    Compute the windowdiff score for a pair of segmentations.  A\n    segmentation is any sequence over a vocabulary of two items\n    (e.g. "0", "1"), where the specified boundary value is used to\n    mark the edge of a segmentation.\n\n        >>> s1 = "000100000010"\n        >>> s2 = "000010000100"\n        >>> s3 = "100000010000"\n        >>> \'%.2f\' % windowdiff(s1, s1, 3)\n        \'0.00\'\n        >>> \'%.2f\' % windowdiff(s1, s2, 3)\n        \'0.30\'\n        >>> \'%.2f\' % windowdiff(s2, s3, 3)\n        \'0.80\'\n\n    :param seg1: a segmentation\n    :type seg1: str or list\n    :param seg2: a segmentation\n    :type seg2: str or list\n    :param k: window width\n    :type k: int\n    :param boundary: boundary value\n    :type boundary: str or int or bool\n    :param weighted: use the weighted variant of windowdiff\n    :type weighted: boolean\n    :rtype: float\n    ' #NEWLINE# if ( len ( seg1 ) != len ( seg2 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Segmentations have unequal length' ) #NEWLINE# #UNINDENT# if ( k > len ( seg1 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Window width k should be smaller or equal than segmentation lengths' ) #NEWLINE# #UNINDENT# wd = 0 #NEWLINE# for i in range ( ( ( len ( i ) - k ) + 1 ) ) : #NEWLINE# #INDENT# ndiff = abs ( ( seg1 [ i : ( i + k ) ] . count ( boundary ) - seg2 [ i : ( i + k ) ] . count ( boundary ) ) ) #NEWLINE# if weighted : #NEWLINE# #INDENT# wd += ndiff #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# wd += min ( 1 , ndiff ) #NEWLINE# #UNINDENT# #UNINDENT# return ( wd / ( ( len ( seg1 ) - k ) + 1.0 ) )