def __init__(self, dataset, target_dois):
        self.metrics = \
            [dfk.EVAL_MEAN_PREC, dfk.EVAL_MEAN_REC, dfk.EVAL_MEAN_F1,
             dfk.EVAL_CI_PREC, dfk.EVAL_CI_REC, dfk.EVAL_CI_F1,
             dfk.EVAL_DOC_METRICS]

        self.metrics_groups = \
            [(dfk.EVAL_MEAN_PREC, dfk.EVAL_CI_PREC, dfk.EVAL_PREC),
             (dfk.EVAL_MEAN_REC, dfk.EVAL_CI_REC, dfk.EVAL_REC),
             (dfk.EVAL_MEAN_F1, dfk.EVAL_CI_F1, dfk.EVAL_F1)]

        target_dois_norm = [doi_normalize(doi) for doi in target_dois]
        dataset_split = {doi: [] for doi in target_dois_norm}
        for d in dataset:
            doi_gt = get_target_gt_doi(d)
            if isinstance(doi_gt, list):
                doi_gt = doi_gt[0]
            doi_gt = doi_normalize(doi_gt)
            if doi_gt in target_dois_norm:
                dataset_split[doi_gt].append(d)
            doi_test = doi_normalize(get_target_test_doi(d))
            if doi_test != doi_gt and doi_test in target_dois_norm:
                dataset_split[doi_test].append(d)

        results_by_doc = \
            [(doi,
              TargetDocLinkMetricsResults(dataset_split[doi_normalize(doi)],
                                          doi))
             for doi in target_dois]

        self.results = {}

        for av, ci, m in self.metrics_groups:
            if results_by_doc:
                self.results[av] = mean([r.get(m) for _, r in results_by_doc])
                self.results[ci] = \
                    confidence_interval([r.get(m) for _, r in results_by_doc],
                                        .95)
            else:
                self.results[ci] = None
                self.results[av] = None

        doc_metrics = {'doc': [d for d, _ in results_by_doc]}
        for metric in [dfk.EVAL_PREC, dfk.EVAL_REC, dfk.EVAL_F1]:
            doc_metrics[metric] = [r.get(metric) for _, r in results_by_doc]
        self.results[dfk.EVAL_DOC_METRICS] = pd.DataFrame(doc_metrics)
def doi_test_same(item, doi):
    return doi_same(doi, get_target_test_doi(item))
def doi_equals(item):
    return doi_same(get_target_test_doi(item), get_target_gt_doi(item))
def doi_test_null(item):
    return get_target_test_doi(item) is None
 def test_target_test_doi(self):
     assert get_target_test_doi({}) is None
     assert get_target_test_doi(ITEM) == '10.14195/2182-708'