<s> """<STR_LIT>""" <EOL> def dispersion_plot ( text , words , ignore_case = False , title = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> from matplotlib import pylab <EOL> except ImportError : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> text = list ( text ) <EOL> words . reverse ( ) <EOL> if ignore_case : <EOL> words_to_comp = list ( map ( str . lower , words ) ) <EOL> text_to_comp = list ( map ( str . lower , text ) ) <EOL> else : <EOL> words_to_comp = words <EOL> text_to_comp = text <EOL> points = [ ( x , y ) for x in range ( len ( text_to_comp ) ) <EOL> for y in range ( len ( words_to_comp ) ) <EOL> if text_to_comp [ x ] == words_to_comp [ y ] ] <EOL> if points : <EOL> x , y = list ( zip ( * points ) ) <EOL> else : <EOL> x = y = ( ) <EOL> pylab . plot ( x , y , "<STR_LIT>" , scalex = <NUM_LIT> ) <EOL> pylab . yticks ( list ( range ( len ( words ) ) ) , words , color = "<STR_LIT:b>" ) <EOL> pylab . ylim ( - <NUM_LIT:1> , len ( words ) ) <EOL> pylab . title ( title ) <EOL> pylab . xlabel ( "<STR_LIT>" ) <EOL> pylab . show ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import nltk . compat <EOL> from nltk . corpus import gutenberg <EOL> words = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> dispersion_plot ( gutenberg . words ( '<STR_LIT>' ) , words ) </s>
