#NEWLINE# def correct( self , word ) : #NEWLINE# #INDENT# if ( word in self . cache ) : #NEWLINE# #INDENT# return self . cache [ word ] #NEWLINE# #UNINDENT# suffix = '' #NEWLINE# for p in self . punctuation : #NEWLINE# #INDENT# if word . endswith ( p ) : #NEWLINE# #INDENT# suffix = p #NEWLINE# word = word [ : ( - 1 ) ] #NEWLINE# #UNINDENT# #UNINDENT# candidates = ( self . known ( [ word ] ) or self . known ( self . edits1 ( word ) ) or self . known_edits2 ( word ) or [ word ] ) #NEWLINE# newword = ( max ( candidates , key = self . NWORDS . get ) + suffix ) #NEWLINE# self . cache . update ( { #NEWLINE# #INDENT# word : newword , #NEWLINE# #UNINDENT# } ) #NEWLINE# return newword