def measures(self, i): g = self.Gold[i].brackets if self.Parse[i] is None: p, n = set(), 0 else: p = self.Parse[i].brackets n = float(bracketing.coincidences(self.Gold[i], self.Parse[i])) if len(p) > 0: if self.count_fullspan_bracket: prec = (n + 1) / float(len(p) + 1) else: prec = n / float(len(p)) elif len(g) == 0: prec = 1.0 else: # XXX: no deberia ser 1? prec = 0.0 if len(g) > 0: if self.count_fullspan_bracket: rec = (n + 1) / float(len(g) + 1) else: rec = n / float(len(g)) else: rec = 1.0 return (prec, rec)
def eval_label(label, goldtb, parse): Rec = 0.0 brackets_ok = 0 brackets_gold = 0 bad = [] for gt, pb in izip(goldtb.trees, parse): g = set(x[1] for x in gt.labelled_spannings( leaves=False, root=False, unary=False) if x[0] == label) gb = bracketing.Bracketing(pb.length, g, start_index=0) n = bracketing.coincidences(gb, pb) if len(g) > 0: rec = float(n) / float(len(g)) bad += [difference(gb, pb)] else: rec = 1.0 bad += [set()] Rec += rec brackets_ok += n brackets_gold += len(g) m = len(parse) Rec = Rec / float(m) print "Recall:", Rec print "Brackets gold:", brackets_gold print "Brackets ok:", brackets_ok return (Rec, bad)
def measures(gb, pb): g, p = gb.brackets, pb.brackets n = bracketing.coincidences(gb, pb) if count_fullspan_bracket: return (n + 1, len(p) + 1, len(g) + 1) else: return (n, len(p), len(g))
def eval_label(label, goldtb, parse): Rec = 0.0 brackets_ok = 0 brackets_gold = 0 bad = [] for gt, pb in izip(goldtb.trees, parse): g = set(x[1] for x in gt.labelled_spannings(leaves=False, root=False, unary=False) if x[0] == label) gb = bracketing.Bracketing(pb.length, g, start_index=0) n = bracketing.coincidences(gb, pb) if len(g) > 0: rec = float(n) / float(len(g)) bad += [difference(gb, pb)] else: rec = 1.0 bad += [set()] Rec += rec brackets_ok += n brackets_gold += len(g) m = len(parse) Rec = Rec / float(m) print "Recall:", Rec print "Brackets gold:", brackets_gold print "Brackets ok:", brackets_ok return (Rec, bad)
def measures(gb, pb): g, p = gb.brackets, pb.brackets n = bracketing.coincidences(gb, pb) if count_fullspan_bracket: return (n+1, len(p)+1, len(g)+1) else: return (n, len(p), len(g))
def measures2(self, i): g = self.Gold[i].brackets if self.Parse[i] is None: p, n = set(), 0 else: p = self.Parse[i].brackets n = float(bracketing.coincidences(self.Gold[i], self.Parse[i])) if self.count_fullspan_bracket: return (n + 1, len(p) + 1, len(g) + 1) else: return (n, len(p), len(g))