float formatting for stats

This commit is contained in:
Ozbolt Menegatti 2019-06-10 11:05:46 +02:00
parent bf0ed35e00
commit c0a22a4ef3

14
wani.py
View File

@ -1109,6 +1109,10 @@ class StatsFormatter(Formatter):
self.jppb = None self.jppb = None
self.corew = 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): def set_structure(self, structure):
jppb = [] jppb = []
corew = [] corew = []
@ -1162,7 +1166,7 @@ class StatsFormatter(Formatter):
word = words[idx] word = words[idx]
key = (sidx, idx, word.lemma) key = (sidx, idx, word.lemma)
distribution = self.colocation_ids.dispersions[key] distribution = self.colocation_ids.dispersions[key]
return [str(distribution)] return [self.stat_str(distribution)]
def content_right(self, freq): def content_right(self, freq):
fx = self.stats['freq'][self.jppb[0]] 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) sum_fi = sum(self.stats['freq'][idx] for idx in self.corew)
logdice_all = 14 + log2(len(self.corew) * freq / sum_fi) logdice_all = 14 + log2(len(self.corew) * freq / sum_fi)
dp12 = str(self.stats["delta_12"]) dp12 = self.stats["delta_12"]
dp21 = str(self.stats["delta_21"]) dp21 = self.stats["delta_21"]
return [dp12, dp21, str(logdice_core), str(logdice_all), str(self.stats['df'])] return [self.stat_str(x) for x in (
dp12, dp21, logdice_core, logdice_all, self.stats['df']
)]
def group(self): def group(self):
return True return True