From c0a22a4ef3b54378b80a467d2174219aba8b43d1 Mon Sep 17 00:00:00 2001 From: Ozbolt Menegatti Date: Mon, 10 Jun 2019 11:05:46 +0200 Subject: [PATCH] float formatting for stats --- wani.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/wani.py b/wani.py index 993efff..b4fb3fb 100644 --- a/wani.py +++ b/wani.py @@ -1109,6 +1109,10 @@ class StatsFormatter(Formatter): self.jppb = None self.corew = None + @staticmethod + def stat_str(num): + return "{:.5f}".format(num) if isinstance(num, float) else str(num) + def set_structure(self, structure): jppb = [] corew = [] @@ -1162,7 +1166,7 @@ class StatsFormatter(Formatter): word = words[idx] key = (sidx, idx, word.lemma) distribution = self.colocation_ids.dispersions[key] - return [str(distribution)] + return [self.stat_str(distribution)] def content_right(self, freq): fx = self.stats['freq'][self.jppb[0]] @@ -1173,9 +1177,11 @@ class StatsFormatter(Formatter): sum_fi = sum(self.stats['freq'][idx] for idx in self.corew) logdice_all = 14 + log2(len(self.corew) * freq / sum_fi) - dp12 = str(self.stats["delta_12"]) - dp21 = str(self.stats["delta_21"]) - return [dp12, dp21, str(logdice_core), str(logdice_all), str(self.stats['df'])] + dp12 = self.stats["delta_12"] + dp21 = self.stats["delta_21"] + return [self.stat_str(x) for x in ( + dp12, dp21, logdice_core, logdice_all, self.stats['df'] + )] def group(self): return True