diff --git a/readTrace.py b/readTrace.py index a9e917782fd2fdd9322da582552173b834f1cf2e..4d1354ce2b13c99219f1fa82c04017cad0f06e77 100755 --- a/readTrace.py +++ b/readTrace.py @@ -292,6 +292,9 @@ class History() : globalStats["backPrecision"] = 100.0*globalStats["backOnErr"] / globalStats["nbBack"] if globalStats["backPrecision"] + globalStats["backRecall"] > 0.0 : globalStats["backFScore"] = 2*(globalStats["backPrecision"] * globalStats["backRecall"])/(globalStats["backPrecision"] + globalStats["backRecall"]) + if globalStats["nbRedoneErrErr"] : + globalStats["redoneErrErrAvgDistChange"] /= globalStats["nbRedoneErrErr"] + globalStats["redoneErrErrAvgIndexChange"] /= globalStats["nbRedoneErrErr"] if globalStats["nbRedone"] : globalStats["redoneAvgErrChange"] /= globalStats["nbRedone"] globalStats["nbRedoneDiminishErr"] /= globalStats["nbRedone"] * (1/100) @@ -300,9 +303,7 @@ class History() : globalStats["nbRedoneErrErr"] /= globalStats["nbRedone"] * (1/100) globalStats["nbRedoneCorrectErr"] /= globalStats["nbRedone"] * (1/100) globalStats["nbRedoneErrCorrect"] /= globalStats["nbRedone"] * (1/100) - if globalStats["nbRedoneErrErr"] : - globalStats["redoneErrErrAvgDistChange"] /= globalStats["nbRedoneErrErr"] - globalStats["redoneErrErrAvgIndexChange"] /= globalStats["nbRedoneErrErr"] + return globalStats #------------------------------------------------------------------------------- @@ -324,10 +325,11 @@ class History() : #------------------------------------------------------------------------------- def readFromTrace(self, traceFile) : curStep = Step() + started = False for line in open(traceFile, "r") : - line = line.strip() - + line = line.rstrip() + # End of sentence : if len(line) == 0 : if len(self.sentences) == 0 or len(self.sentences[-1]) > 0 : @@ -336,6 +338,11 @@ class History() : self.sentences[-1].append([]) continue + if "-----" in line : + started = True + if not started : + continue + if "state :" in line : curStep.state = int(line.split(':')[-1].strip()) elif "=>" in line : @@ -360,8 +367,10 @@ class History() : curStep.scores = [a.replace("*","").split(':') for a in curStep.scores if not len(a.split(':')) == 1] curStep.scores = [(float(a[0]), a[1]) for a in curStep.scores] elif " " in line : - curId = int(annotLine.split()[0]) - self.sentences[-1][0][curId] = annotLine + annotLine = " ".join(line.split(" ")[1:]) + if "-" not in annotLine.split()[0] : + curId = int(annotLine.split()[0]) + self.sentences[-1][0][curId] = annotLine elif "Chosen action :" in line : curStep.action = line.split(':')[-1].strip() elif "Oracle costs :" in line : @@ -381,7 +390,12 @@ class History() : ################################################################################ def prettyNumber(num) : - return ("%.2f"%num).rstrip(".0") + base = "%.2f"%num + splited = base.split('.') + striped = splited[1].rstrip('.0') + if len(striped) > 0 : + striped = "."+striped + return splited[0] + striped ################################################################################ ################################################################################