示例#1
0
def _compare_citations_by(bib1, bib2):
    metadata_comparison_print("Comparing citations by.")

    cites1 = _find_citations_by(bib1)
    cites2 = _find_citations_by(bib2)

    return jaccard(cites1, cites2)
示例#2
0
def _compare_coauthors(bib1, bib2):
    metadata_comparison_print("Comparing authors.")

    aths1 = _find_coauthors(bib1)
    aths2 = _find_coauthors(bib2)

    return jaccard(aths1, aths2)
示例#3
0
def _compare_unified_affiliations(bib1, bib2):
    metadata_comparison_print("Comparing affiliations.")

    aff1 = _find_affiliation(bib1)
    aff2 = _find_affiliation(bib2)

    ret = jaccard(aff1, aff2)
    return ret
示例#4
0
def _compare_names(bib1, bib2):
    metadata_comparison_print("Comparing names.")

    name1 = get_name_by_bibrecref(bib1)
    name2 = get_name_by_bibrecref(bib2)

    if name1 and name2:
        return compare_names(name1, name2, False)
    return "?"
示例#5
0
def _compare_collaboration(bib1, bib2):
    metadata_comparison_print("Comparing collaboration.")

    colls1 = _find_collaboration(bib1)
    colls2 = _find_collaboration(bib2)

    metadata_comparison_print("Found %d, %d different collaborations for the two sets." % (len(colls1), len(colls2)))
    if len(colls1) != 1 or len(colls2) != 1:
        return "?"
    elif colls1 == colls2:
        return 1.0
    else:
        return 0.0
示例#6
0
def _compare_email(bib1, bib2):
    metadata_comparison_print("Comparing email addresses.")

    iids1 = _find_email(bib1)
    iids2 = _find_email(bib2)

    metadata_comparison_print("Found %d, %d different email addresses for the two sets." % (len(iids1), len(iids2)))
    if len(iids1) != 1 or len(iids2) != 1:
        return "?"
    elif iids1 == iids2:
        metadata_comparison_print("The addresses are the same.")
        return 1.0
    else:
        metadata_comparison_print("The addresses are there, but different.")
        return 0.3
示例#7
0
def _compare_inspireid(bib1, bib2):
    metadata_comparison_print("Comparing inspire ids.")

    iids1 = _find_inspireid(bib1)
    iids2 = _find_inspireid(bib2)

    metadata_comparison_print("Found %d, %d different inspire ids for the two sets." % (len(iids1), len(iids2)))
    if len(iids1) != 1 or len(iids2) != 1:
        return "?"
    elif iids1 == iids2:
        metadata_comparison_print("The ids are the same.")
        return "+"
    else:
        metadata_comparison_print("The ids are different.")
        return "-"
示例#8
0
def jaccard(set1, set2):
    """
    This is no longer jaccard distance.
    """
    metadata_comparison_print("Jaccard: Found %d items in the first set." % len(set1))
    metadata_comparison_print("Jaccard: Found %d items in the second set." % len(set2))

    if not set1 or not set2:
        return "?"

    match = len(set1 & set2)
    ret = float(match) / float(len(set1) + len(set2) - match)

    metadata_comparison_print("Jaccard: %d common items." % match)
    metadata_comparison_print("Jaccard: returning %f." % ret)
    return ret
示例#9
0
def _compare_key_words(bib1, bib2):
    metadata_comparison_print("Comparing key words.")
    words1 = _find_key_words(bib1)
    words2 = _find_key_words(bib2)

    return jaccard(words1, words2)
示例#10
0
def _compare_papers(bib1, bib2):
    metadata_comparison_print("Checking if the two bib refs are in the same paper.")
    if bib1[2] == bib2[2]:
        return "-"
    return "?"
示例#11
0
def compare_bibrefrecs(bibref1, bibref2):
    """
    This function compares two bibrefrecs (100:123,456) using all metadata
    and returns:
        * a pair with two numbers in [0, 1] - the probability that the two belong
            together and the ratio of the metadata functions used to the number of
            all metadata functions.
        * '+' - the metadata showed us that the two belong together for sure.
        * '-' - the metadata showed us that the two do not belong together for sure.

        Example:
            '(0.7, 0.4)' - 2 out of 5 functions managed to compare the bibrefrecs and
                using their computations the average value of 0.7 is returned.
            '-' - the two bibrefres are in the same paper, so they dont belong together
                for sure.
            '(1, 0)' There was insufficient metadata to compare the bibrefrecs. (The
                first values in ignored).
    """

    # try first the metrics, which might return + or -
    papers = _compare_papers(bibref1, bibref2)
    if papers != "?":
        return papers

    #    if bconfig.CFG_INSPIRE_SITE:
    #        insp_ids = _compare_inspireid(bibref1, bibref2)
    #        if insp_ids != '?':
    #            return insp_ids

    # unfortunately, we have to do all comparisons
    if bconfig.CFG_INSPIRE_SITE:
        func_weight = (
            (_compare_affiliations, 1.0),
            (_compare_names, 5.0),
            (_compare_citations, 0.5),
            (_compare_citations_by, 0.5),
            (_compare_key_words, 2.0),
        )
    elif bconfig.CFG_ADS_SITE:
        func_weight = (
            (_compare_email, 3.0),
            (_compare_unified_affiliations, 2.0),
            (_compare_names, 5.0),
            #        register(_compare_citations, .5)
            #        register(_compare_citations_by, .5)
            (_compare_key_words, 2.0),
        )

    else:
        func_weight = ((_compare_names, 5.0),)

    results = [(func(bibref1, bibref2), weight) for func, weight in func_weight]

    coll = _compare_collaboration(bibref1, bibref2)
    if coll == "?":
        coll = _compare_coauthors(bibref1, bibref2)

    results.append((coll, 3.0))
    total_weights = sum(res[1] for res in results)

    metadata_comparison_print("Final vector: %s." % str(results))
    results = filter(lambda x: x[0] != "?", results)

    if not results:
        return 0, 0

    cert = sum(starmap(mul, results))
    prob = sum(res[1] for res in results)
    return cert / prob, prob / total_weights