From f5176d86b9fd08b3a53b2696e0352430be7f855e Mon Sep 17 00:00:00 2001 From: jezozwierzak <jezozwierzak@gmail.com> Date: Wed, 29 Aug 2012 13:15:41 +0200 Subject: [PATCH] repaired tabs in subheads --- utils/CSVColumn.py | 24 +++++++++++++++++++----- utils/chunk_eval.py | 6 ++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/utils/CSVColumn.py b/utils/CSVColumn.py index ad551de..59e315a 100755 --- a/utils/CSVColumn.py +++ b/utils/CSVColumn.py @@ -93,11 +93,12 @@ class CSVColumn: self.recountWidths() else: assert type(data).__name__ != 'dict', 'You added dict to column with no subcolumns' + if len(self.content) == 0: self.type = type(data).__name__ self.content.append(data) if len(str(data)) > self.width and self.isSubColumn(): - self.parent.recountWidths() + self.parent.recountWidths(self.parent.content.index(self)) elif len(str(data) + self.separator) > self.width: self.width = len(str(data)) @@ -113,7 +114,7 @@ class CSVColumn: result += row return result - def recountWidths(self): + def recountWidths(self, sub=''): subColsStr = '' for subColumn in self.content: subColsStr += subColumn.name + self.separator @@ -122,10 +123,23 @@ class CSVColumn: self.width = len(subColsStr) for subColumn in self.content: subColumn.width = len(subColumn.name + self.separator) - elif self.parent.rows > 0: + if len(self.content[0].content) > 0: widths = 0 - for i in range(0,len(self.content)): #Dla każdej podkolumny - for j in range(0, self.parent.rows): #Dla każdego wiersza + if sub == '': + for i in range(0,len(self.content)): #Dla każdej podkolumny + for j in range(0, len(self.content[0].content)): #Dla każdego wiersza + if i == len(self.content) - 1: + if self.width - widths > 0: + self.content[i].width = self.width - widths + else: + self.content[i].width = len(self.parent.ptr(self.content[i].content[j], 1)) + break + elif len(self.parent.ptr(self.content[i].content[j], 1)) > self.content[i].width: + self.content[i].width = len(self.parent.ptr(self.content[i].content[j], 1)) + widths += self.content[i].width + else: + i = sub + for j in range(0, len(self.content[0].content)): #Dla każdego wiersza if i == len(self.content) - 1: if self.width - widths > 0: self.content[i].width = self.width - widths diff --git a/utils/chunk_eval.py b/utils/chunk_eval.py index 284bd0a..32c29bf 100755 --- a/utils/chunk_eval.py +++ b/utils/chunk_eval.py @@ -159,6 +159,7 @@ def main(ch_path, ref_path, chan_names, input_format, out_path, tagset, verbose, # process each sentence separately for ch_sent, ref_sent in zip(ch_chunk.sentences(), ref_chunk.sentences()): + print ch_sent.size(), ref_sent.size() assert ch_sent.size() == ref_sent.size() ch_annots = get_annots(ch_sent, chan_name) ref_annots = get_annots(ref_sent, chan_name) @@ -166,14 +167,15 @@ def main(ch_path, ref_path, chan_names, input_format, out_path, tagset, verbose, results[chan_name] = stats.getStats() csvTable.addRow(results) -# csvTable.countAvg() + csvTable.countAvg() if out_path != '': out = codecs.open(out_path, "w", "utf-8") + out.write(csvTable.__str__()) out.close() else: print csvTable if __name__ == '__main__': - go() \ No newline at end of file + go() -- GitLab