Exemple #1
0
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