#NEWLINE# def __init__( self , image ) : #NEWLINE# #INDENT# self . _word_models = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# self . _words = [ ] #NEWLINE# self . key = image . template . key #NEWLINE# for line in image . text . lines : #NEWLINE# #INDENT# self . _words += line . lower ( ) . split ( ' ' ) #NEWLINE# #UNINDENT# for word in self . _words : #NEWLINE# #INDENT# if ( not self . _word_models . get ( word ) ) : #NEWLINE# #INDENT# model = db . session . query ( WordModel ) . filter ( ( WordModel . id == word ) ) . first ( ) #NEWLINE# if ( not model ) : #NEWLINE# #INDENT# model = WordModel ( id = word , meme_id = self . key , occurances = 0 ) #NEWLINE# #UNINDENT# model . occurances += 1 #NEWLINE# self . _word_models [ word ] = model #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _word_models [ word ] . occurances += 1 #NEWLINE# #UNINDENT# #UNINDENT# for key in self . _word_models : #NEWLINE# #INDENT# if self . _word_models [ model ] : #NEWLINE# #INDENT# db . session . add ( self . _word_models [ key ] ) #NEWLINE# #UNINDENT# #UNINDENT# db . session . commit ( )