#NEWLINE# def generate_stanford_gazettes_file( self ) : #NEWLINE# #INDENT# "\n        Generates the gazettes file if there's any. Returns\n        the filepath in case gazette items where found, else None.\n\n        Note: the Stanford Coreference annotator, only handles Entities of their\n        native classes. That's why there's some special management of Gazette items\n        of such classes/kinds.\n        As a side effect, populates the internal cache with the gazette-items\n        that will be passed to Stanford with any of their Native classes (Entity Kinds)\n        " #NEWLINE# if ( not filepath . gazette_items ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# overridable_classes = ',' . join ( self . NATIVE_CLASSES ) #NEWLINE# self . _cache_per_kind = defaultdict ( list ) #NEWLINE# gazette_format = '{}\t{}\t{}\n' #NEWLINE# ( _ , filepath ) = tempfile . mkstemp ( ) #NEWLINE# with open ( filepath , 'w' ) as gazette_file : #NEWLINE# #INDENT# for gazette in self . gazette_items : #NEWLINE# #INDENT# kname = gazette . kind . name #NEWLINE# if ( kname in self . NATIVE_CLASSES ) : #NEWLINE# #INDENT# self . _cache_per_kind [ kname ] . append ( gazette . text ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# kname = '{}{}' . format ( self . _PREFIX , kname ) #NEWLINE# #UNINDENT# text = self . escape_text ( gazette . text ) #NEWLINE# line = gazette_format . format ( text , kname , overridable_classes ) #NEWLINE# gazette_file . write ( line ) #NEWLINE# #UNINDENT# #UNINDENT# return filepath