ณ๒
4าวIc           @   s   d  d  Z  d   Z d S(   t   1c      	   C   s   t  |   t  |  j o t d  n d } xb t t  |   |  D]J } | t |  | | | d !i |  | | | | d !i |   7} qC W| S(   s๕  
    Compute the windowdiff score for a pair of segmentations.  A segmentation is any sequence
    over a vocabulary of two items (e.g. "0", "1"), where the specified boundary value is used
    to mark the edge of a segmentation.
    
    >>> s1 = "00000010000000001000000"
    >>> s2 = "00000001000000010000000"
    >>> s3 = "00010000000000000001000"
    >>> windowdiff(s1, s1, 3)
    0
    >>> windowdiff(s1, s2, 3)
    4
    >>> windowdiff(s2, s3, 3)
    16

    @param seg1: a segmentation
    @type seg1: C{string} or C{list}
    @param seg2: a segmentation
    @type seg2: C{string} or C{list}
    @param k: window width
    @type k: C{int}
    @param boundary: boundary value
    @type boundary: C{string} or C{int} or C{bool}
    @rtype: C{int}
    s!   Segmentations have unequal lengthi    i   (   t   lent
   ValueErrort   ranget   abst   count(   t   seg1t   seg2t   kt   boundaryt   wdt   i(    (    s-   /p/zhu/06/nlp/nltk/nltk/metrics/windowdiff.pyt
   windowdiff   s     Hc          C   sp   d }  d } d } d G|  GHd G| GHd G| GHd Gt  |  |  d  GHd	 Gt  |  | d  GHd
 Gt  | | d  GHd  S(   Nt   00000010000000001000000t   00000001000000010000000t   00010000000000000001000s   s1:s   s2:s   s3:s   windowdiff(s1, s1, 3) = i   s   windowdiff(s1, s2, 3) = s   windowdiff(s2, s3, 3) = (   R   (   t   s1t   s2t   s3(    (    s-   /p/zhu/06/nlp/nltk/nltk/metrics/windowdiff.pyt   demo2   s    			N(   R   R   (    (    (    s-   /p/zhu/06/nlp/nltk/nltk/metrics/windowdiff.pys   <module>   s   "