#NEWLINE# def run_ner( self , doc ) : #NEWLINE# #INDENT# entities = [ ] #NEWLINE# ner_sentences = self . ner ( doc . get_sentences ( ) ) #NEWLINE# ner_kinds = ( k for s in ner_sentences for ( _ , k ) in s ) #NEWLINE# z = itertools . chain ( enumerate ( zip ( doc . tokens , ner_kinds ) ) , [ ( len ( doc . tokens ) , ( None , 'INVALID' ) ) ] ) #NEWLINE# last_kind = 'O' #NEWLINE# offset = 0 #NEWLINE# for ( i , ( token , kind ) ) in z : #NEWLINE# #INDENT# if ( kind != name ) : #NEWLINE# #INDENT# if ( last_kind != 'O' ) : #NEWLINE# #INDENT# name = ' ' . join ( doc . tokens [ offset : i ] ) #NEWLINE# entities . append ( self . build_occurrence ( name , last_kind . lower ( ) , name , offset , i ) ) #NEWLINE# #UNINDENT# offset = i #NEWLINE# #UNINDENT# last_kind = kind #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# next ( ner_kinds ) #NEWLINE# assert False , 'ner_kinds should have been completely consumed' #NEWLINE# #UNINDENT# except StopIteration : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# return entities