diff --git a/utils/CSVColumn.py b/utils/CSVColumn.py index ad551de9cf64d3d6bfe1ff68beef52879c500586..59e315ac45ec62b816b0677304ef1539d17e1160 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 284bd0a1b3cefc6f9caebd332c51bb20582de882..32c29bf5d52298a07f0c2189236ad32317e5e973 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()