def type_token_ratio(string, n=100, punctuation=PUNCTUATION):
 def window(a, n=100):
  if (n > 0):
   for i in xrange(max(((len(a) - n) + 1), 1)):
    (yield a[i:(i + n)])
 s = string.lower().split()
 s = [w.strip(punctuation) for w in s]
 return mean((((1.0 * len(set(x))) / max(len(x), 1)) for x in window(s, n)))

def type_token_ratio ( string , n = 100 , punctuation = PUNCTUATION ) : def window ( a , n = 100 ) : if ( n > 0 ) : for i in xrange ( max ( ( ( len ( a ) - n ) + 1 ) , 1 ) ) : ( yield a [ i : ( i + n ) ] ) s = string . lower ( ) . split ( ) s = [ w . strip ( punctuation ) for w in s ] return mean ( ( ( ( 1.0 * len ( set ( x ) ) ) / max ( len ( x ) , 1 ) ) for x in window ( s , n ) ) )
returns the percentage of unique words in the given string as a number between 0 .