<s> from . signature import Signature <EOL> class Statement ( object ) : <EOL> def __init__ ( self , text , ** kwargs ) : <EOL> self . text = text <EOL> self . in_response_to = kwargs . get ( "<STR_LIT>" , [ ] ) <EOL> self . extra_data = { } <EOL> if "<STR_LIT>" in kwargs : <EOL> del ( kwargs [ "<STR_LIT>" ] ) <EOL> self . extra_data . update ( kwargs ) <EOL> def __str__ ( self ) : <EOL> return self . text <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . text ) <EOL> def __eq__ ( self , other ) : <EOL> if not other : <EOL> return False <EOL> if isinstance ( other , Statement ) : <EOL> return self . text == other . text <EOL> return self . text == other <EOL> def add_extra_data ( self , key , value ) : <EOL> self . extra_data [ key ] = value <EOL> def add_response ( self , response ) : <EOL> """<STR_LIT>""" <EOL> updated = False <EOL> for index in range ( <NUM_LIT:0> , len ( self . in_response_to ) ) : <EOL> if response . text == self . in_response_to [ index ] . text : <EOL> self . in_response_to [ index ] . occurrence += <NUM_LIT:1> <EOL> updated = True <EOL> if not updated : <EOL> self . in_response_to . append ( response ) <EOL> def remove_response ( self , response_text ) : <EOL> """<STR_LIT>""" <EOL> for response in self . in_response_to : <EOL> if response_text == response . text : <EOL> self . in_response_to . remove ( response ) <EOL> return True <EOL> return False <EOL> def get_response_count ( self , statement ) : <EOL> """<STR_LIT>""" <EOL> for response in self . in_response_to : <EOL> if statement . text == response . text : <EOL> return response . occurrence <EOL> return <NUM_LIT:0> <EOL> def serialize ( self ) : <EOL> """<STR_LIT>""" <EOL> data = { } <EOL> data [ "<STR_LIT:text>" ] = self . text <EOL> data [ "<STR_LIT>" ] = [ ] <EOL> data . update ( self . extra_data ) <EOL> for response in self . in_response_to : <EOL> data [ "<STR_LIT>" ] . append ( response . serialize ( ) ) <EOL> return data <EOL> class Response ( object ) : <EOL> def __init__ ( self , text , ** kwargs ) : <EOL> self . text = text <EOL> self . occurrence = kwargs . get ( "<STR_LIT>" , <NUM_LIT:1> ) <EOL> self . signatures = kwargs . get ( "<STR_LIT>" , [ ] ) <EOL> def __str__ ( self ) : <EOL> return self . text <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . text ) <EOL> def __eq__ ( self , other ) : <EOL> if not other : <EOL> return False <EOL> if isinstance ( other , Response ) : <EOL> return self . text == other . text <EOL> return self . text == other <EOL> def add_signature ( self , signature ) : <EOL> self . signatures . append ( signature ) <EOL> def serialize ( self ) : <EOL> data = { } <EOL> data [ "<STR_LIT:text>" ] = self . text <EOL> data [ "<STR_LIT>" ] = self . occurrence <EOL> data [ "<STR_LIT>" ] = [ ] <EOL> for signature in self . signatures : <EOL> data [ "<STR_LIT>" ] . append ( signature . serialize ( ) ) <EOL> return data </s>
