def processPassageAnnotation(pred, true, countDict, checkID): anns_pred = pred['annotations'] anns_true = Annotation.sortAnns(true['annotations'], TBDFilter= False) for ann_pred in anns_pred: if Annotation.gettype(ann_pred) == 'Gene': countDict['pred_gene_num'] += 1 else: continue flag = False for ann_true in anns_true: if Annotation.isSame(ann_pred, ann_true, checkID): countDict['tp'] += 1 flag = True break if not flag: countDict['fp'] += 1 # print(ann_pred) countDict['true_gene_num'] += len(anns_true) for ann_true in anns_true: flag = False for ann_pred in anns_pred: if Annotation.isSame(ann_pred, ann_true, checkID): flag = True break if not flag: countDict['fn'] += 1
def evalNormalization(documents_pred, documents_true): tp = 0 tbd = 0 fp = 1 for docu_pred, docu_true in zip(documents_pred, documents_true): for psg_pred, psg_true in zip(docu_pred['passages'], docu_true['passages']): for ann_pred, ann_true in zip(psg_pred['annotations'], psg_true['annotations']): if Annotation.isSame(ann_pred, ann_true, checkID=True): tp += 1 elif Annotation.getNCBIID(ann_pred) == 'TBD': tbd += 1 else: fp += 1 try: recall = tp / (tp + tbd + fp) except ZeroDivisionError: recall = 0 try: precision = tp / (tp + fp) except ZeroDivisionError: precision = 0 print(f"Recall {recall:.2f}\tPrecision {precision:.2f}") return tp, fp, tbd