#NEWLINE# def get_features( self , context_obj ) : #NEWLINE# #INDENT# if ( ( len ( self . content_src ) == 0 ) or ( len ( self . content_tg ) == 0 ) ) : #NEWLINE# #INDENT# logger . warn ( 'One or more POS lists are empty' ) #NEWLINE# #UNINDENT# ( content_src , content_tg , verbs_src , verbs_tg , nouns_src , nouns_tg , pronouns_src , pronouns_tg ) = ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) #NEWLINE# source_idx = context_obj [ 'source_index' ] #NEWLINE# target_idx = context_obj [ 'index' ] #NEWLINE# if ( len ( source_idx ) > 0 ) : #NEWLINE# #INDENT# for word in context_obj [ 'source_pos' ] [ source_idx [ 0 ] : source_idx [ 1 ] ] : #NEWLINE# #INDENT# content = False #NEWLINE# if self . belongs_to ( word , self . pronouns_src ) : #NEWLINE# #INDENT# pronouns_src += 1 #NEWLINE# #UNINDENT# if self . belongs_to ( word , self . nouns_src ) : #NEWLINE# #INDENT# nouns_src += 1 #NEWLINE# if ( not content ) : #NEWLINE# #INDENT# content_src += 1 #NEWLINE# content = True #NEWLINE# #UNINDENT# #UNINDENT# if self . belongs_to ( word , self . verbs_src ) : #NEWLINE# #INDENT# verbs_src += 1 #NEWLINE# if ( not content ) : #NEWLINE# #INDENT# content_src += 1 #NEWLINE# content = True #NEWLINE# #UNINDENT# #UNINDENT# if ( not content ) : #NEWLINE# #INDENT# if self . belongs_to ( word , self . content_src ) : #NEWLINE# #INDENT# content_src += 1 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# for word in context_obj [ 'target_pos' ] [ target_idx [ 0 ] : target_idx [ 1 ] ] : #NEWLINE# #INDENT# content = False #NEWLINE# if self . belongs_to ( word , self . pronouns_tg ) : #NEWLINE# #INDENT# pronouns_tg += 1 #NEWLINE# #UNINDENT# if self . belongs_to ( word , self . nouns_tg ) : #NEWLINE# #INDENT# nouns_tg += 1 #NEWLINE# if ( not content ) : #NEWLINE# #INDENT# content_tg += 1 #NEWLINE# content = True #NEWLINE# #UNINDENT# #UNINDENT# if self . belongs_to ( word , self . verbs_tg ) : #NEWLINE# #INDENT# verbs_tg += 1 #NEWLINE# if ( not content ) : #NEWLINE# #INDENT# content_tg += 1 #NEWLINE# content = True #NEWLINE# #UNINDENT# #UNINDENT# if ( not content ) : #NEWLINE# #INDENT# if self . belongs_to ( word , self . content_tg ) : #NEWLINE# #INDENT# content_tg += 1 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# content_tg_percent = ( content_tg / len ( context_obj [ 'token' ] ) ) #NEWLINE# verbs_tg_percent = ( verbs_tg / len ( context_obj [ 'token' ] ) ) #NEWLINE# nouns_tg_percent = ( nouns_tg / len ( context_obj [ 'token' ] ) ) #NEWLINE# pronouns_tg_percent = ( pronouns_tg / len ( context_obj [ 'token' ] ) ) #NEWLINE# content_src_percent = 0 #NEWLINE# verbs_src_percent = 0 #NEWLINE# nouns_src_percent = 0 #NEWLINE# pronouns_src_percent = 0 #NEWLINE# if ( len ( context_obj [ 'source_token' ] ) > 0 ) : #NEWLINE# #INDENT# content_src_percent = ( content_src / len ( context_obj [ 'source_token' ] ) ) #NEWLINE# verbs_src_percent = ( verbs_src / len ( context_obj [ 'source_token' ] ) ) #NEWLINE# nouns_src_percent = ( nouns_src / len ( context_obj [ 'source_token' ] ) ) #NEWLINE# pronouns_src_percent = ( pronouns_src / len ( context_obj [ 'source_token' ] ) ) #NEWLINE# #UNINDENT# ratio_content = ( ( content_src_percent / content_tg_percent ) if ( content_tg_percent > 0 ) else ( 1 if ( content_src_percent == 0 ) else 0 ) ) #NEWLINE# ratio_verbs = ( ( verbs_src_percent / verbs_tg_percent ) if ( verbs_tg_percent > 0 ) else ( 1 if ( verbs_src_percent == 0 ) else 0 ) ) #NEWLINE# ratio_nouns = ( ( nouns_src_percent / nouns_tg_percent ) if ( nouns_tg_percent > 0 ) else ( 1 if ( nouns_src_percent == 0 ) else 0 ) ) #NEWLINE# ratio_pronouns = ( ( pronouns_src_percent / pronouns_tg_percent ) if ( pronouns_tg_percent > 0 ) else ( 1 if ( pronouns_src_percent == 0 ) else 0 ) ) #NEWLINE# return [ content_src_percent , content_tg_percent , verbs_src_percent , verbs_tg_percent , nouns_src_percent , nouns_tg_percent , pronouns_src_percent , pronouns_tg_percent , ratio_content , ratio_verbs , ratio_nouns , ratio_pronouns ]