@@ -7,7 +7,7 @@ class Stats(Block):
77 def __init__ (self , m_len_max = 5 , e_len_max = 5 , report_mentions = True , report_entities = True ,
88 report_details = True , selected_upos = 'NOUN PRON PROPN DET ADJ VERB ADV NUM' ,
99 exclude_singletons = False , exclude_nonsingletons = False , style = 'human' ,
10- per_doc = False , ** kwargs ):
10+ per_doc = False , max_rows_per_page = 50 , ** kwargs ):
1111 super ().__init__ (** kwargs )
1212 self .m_len_max = m_len_max
1313 self .e_len_max = e_len_max
@@ -20,7 +20,9 @@ def __init__(self, m_len_max=5, e_len_max=5, report_mentions=True, report_entiti
2020 if style not in 'tex tex-table tex-doc human' .split ():
2121 raise ValueError (f'Unknown style { style } ' )
2222 self .per_doc = per_doc
23+ self .max_rows_per_page = max_rows_per_page
2324 self ._header_printed = False
25+ self ._lines_printed = None
2426
2527 self .counter = Counter ()
2628 self .mentions = 0
@@ -87,9 +89,9 @@ def after_process_document(self, doc):
8789 self .m_words = 0
8890
8991 def process_end (self , skip = True , doc = None ):
90- if not self ._header_printed :
91- self ._header_printed = True
92+ if not self ._lines_printed :
9293 self .print_header ()
94+ self ._lines_printed = 0
9395 if self .per_doc :
9496 if skip :
9597 self .print_footer ()
@@ -98,6 +100,7 @@ def process_end(self, skip=True, doc=None):
98100 print (f"{ doc [0 ].trees [0 ].newdoc :15} " , end = '&' if self .style .startswith ('tex' ) else '\n ' )
99101 elif self .style .startswith ('tex-' ):
100102 print (f"{ self .counter ['documents' ]:4} documents &" )
103+ self ._lines_printed += 1
101104
102105 mentions_nonzero = 1 if self .mentions == 0 else self .mentions
103106 entities_nonzero = 1 if self .entities == 0 else self .entities
@@ -139,17 +142,21 @@ def process_end(self, skip=True, doc=None):
139142 print (f"{ c [0 ]:>15} = { c [1 ].strip ():>10} " )
140143 if not self .per_doc :
141144 self .print_footer ()
145+ elif self ._lines_printed > self .max_rows_per_page :
146+ self .print_footer (False )
147+ self ._lines_printed = 0
142148
143149 def print_header (self ):
144150 if not self .style .startswith ('tex-' ):
145151 return
146152 if self .style == 'tex-doc' :
147- print (r'\documentclass{standalone}' )
148- print (r'\usepackage[utf8]{inputenc}\usepackage{booktabs}\usepackage{underscore}' )
149- print (r'\title{Udapi coreference statistics}' )
150- print (r'\begin{document}' )
153+ if self ._lines_printed is None :
154+ print (r'\documentclass[multi=mypage]{standalone}' )
155+ print (r'\usepackage[utf8]{inputenc}\usepackage{booktabs}\usepackage{underscore}' )
156+ print (r'\title{Udapi coreference statistics}' )
157+ print (r'\begin{document}' )
151158 print (r'\def\MC#1#2{\multicolumn{#1}{c}{#2}}' )
152- lines = [r'\begin{tabular}{@{}l ' , " " * 15 , ("document" if self .per_doc else "dataset " ) + " " * 7 , " " * 15 ]
159+ lines = [r'\begin{mypage}\begin{ tabular}{@{}l ' , " " * 15 , ("document" if self .per_doc else "dataset " ) + " " * 7 , " " * 15 ]
153160 if self .report_entities :
154161 lines [0 ] += "rrrr "
155162 lines [1 ] += r'& \MC{4}{entities} '
@@ -211,9 +218,9 @@ def print_header(self):
211218 lines [1 ] += r'}\cmidrule(l){' + f"{ last_col + 4 } -{ last_col + 3 + len (upos_list )} " + '}'
212219 print ("\n " .join (lines ))
213220
214- def print_footer (self ):
221+ def print_footer (self , end_doc = True ):
215222 if not self .style .startswith ('tex-' ):
216223 return
217- print (r'\bottomrule\end{tabular}' )
218- if self .style == 'tex-doc' :
224+ print (r'\bottomrule\end{tabular}\end{mypage} ' )
225+ if self .style == 'tex-doc' and end_doc :
219226 print (r'\end{document}' )
0 commit comments