def _get_pubs_per_year_fallback(person_id):
    '''
    Returns a dict consisting of: year -> number of publications in that year (given a personID).
    @param person_id: int personid
    @return [{'year':no_of_publications}, bool]
    '''
    recids = perform_request_search(rg=0, p='exactauthor:"%s"' % str(person_id))
    a = format_records(recids, 'WAPDAT')
    a = [deserialize(p) for p in a.strip().split('!---THEDELIMITER---!') if p]
    return _get_pubs_per_year_dictionary(a)
def _get_pubs_per_year_fallback(person_id):
    '''
    Returns a dict consisting of: year -> number of publications in that year (given a personID).
    @param person_id: int personid
    @return [{'year':no_of_publications}, bool]
    '''
    recids = perform_request_search(rg=0,
                                    p='exactauthor:"%s"' % str(person_id))
    a = format_records(recids, 'WAPDAT')
    a = [deserialize(p) for p in a.strip().split('!---THEDELIMITER---!') if p]
    return _get_pubs_per_year_dictionary(a)
def _get_institute_pubs_dict(recids, names_list):
    a = format_records(recids, 'WAPAFF')
    a = [deserialize(p) for p in a.strip().split('!---THEDELIMITER---!') if p]
    affdict = {}
    for rec, affs in a:
        keys = affs.keys()
        for name in names_list:
            if name in keys and affs[name][0]:
                for aff in affs[name]:
                    try:
                        affdict[aff].add(rec)
                    except KeyError:
                        affdict[aff] = set([rec])
    # the serialization function (msgpack.packb) cannot serialize a python set
    for key in affdict.keys():
        affdict[key] = list(affdict[key])
    return affdict
def _get_institute_pubs_dict(recids, names_list):
    a = format_records(recids, 'WAPAFF')
    a = [deserialize(p) for p in a.strip().split('!---THEDELIMITER---!') if p]
    affdict = {}
    for rec, affs in a:
        keys = affs.keys()
        for name in names_list:
            if name in keys and affs[name][0]:
                for aff in affs[name]:
                    try:
                        affdict[aff].add(rec)
                    except KeyError:
                        affdict[aff] = set([rec])
    # the serialization function (msgpack.packb) cannot serialize a python set
    for key in affdict.keys():
        affdict[key] = list(affdict[key])
    return affdict
def retrieve_update_cache(name, key, target, *args):
    '''
    Retrieves the result of target(args)(= value) from (name, key) cached element.
    If element present and UpToDate it returns [value, True]. If element present and Precached it returns [None, False]
    because it is currently computed. If element is not present it computes its value, updates the cache and returns [value, True].
    '''
    #print '--Getting ', name, ' ', key
    cached = get_cached_element(name, str(key))
    if cached['present']:
        if cached['upToDate'] and not FORCE_CACHE_IS_EXPIRED:
            delay = datetime.now() - cached['last_updated']
            if delay < CACHE_IS_OUTDATED_DELAY:
                return [deserialize(cached['value']), True]
    val = update_cache(cached, name, str(key), target, *args)
    if val[0]:
        return [val[1], True]
    else:
        return [None, False]
def retrieve_update_cache(name, key, target, *args):
    '''
    Retrieves the result of target(args)(= value) from (name, key) cached element.
    If element present and UpToDate it returns [value, True]. If element present and Precached it returns [None, False]
    because it is currently computed. If element is not present it computes its value, updates the cache and returns [value, True].
    '''
    #print '--Getting ', name, ' ', key
    cached = get_cached_element(name, str(key))
    if cached['present']:
        if cached['upToDate'] and not FORCE_CACHE_IS_EXPIRED:
            delay = datetime.now() - cached['last_updated']
            if delay < CACHE_IS_OUTDATED_DELAY:
                return [deserialize(cached['value']), True]
    val = update_cache(cached, name, str(key), target, *args)
    if val[0]:
        return [val[1], True]
    else:
        return [None, False]
def _get_coauthors_fallback(collabs, person_id):
    exclude_recs = []
    if collabs:
        query = 'exactauthor:"%s" and (%s)' % (person_id, ' or '.join([('collaboration:"%s"' % x) for x in zip(*collabs)[0]]))
        exclude_recs = perform_request_search(rg=0, p=query)
    recids = perform_request_search(rg=0, p='exactauthor:"%s"' % str(person_id))
    recids = list(set(recids) - set(exclude_recs))
    a = format_records(recids, 'WAPAFF')
    a = [deserialize(p) for p in a.strip().split('!---THEDELIMITER---!') if p]
    coauthors = {}
    for rec, affs in a:
        keys = affs.keys()
        for n in keys:
            try:
                coauthors[n].add(rec)
            except KeyError:
                coauthors[n] = set([rec])

    coauthors = [(x, x, len(coauthors[x])) for x in coauthors if x.lower() != person_id.lower()]
    return coauthors
def _get_coauthors_fallback(collabs, person_id):
    exclude_recs = []
    if collabs:
        query = 'exactauthor:"%s" and (%s)' % (person_id, ' or '.join(
            [('collaboration:"%s"' % x) for x in zip(*collabs)[0]]))
        exclude_recs = perform_request_search(rg=0, p=query)
    recids = perform_request_search(rg=0,
                                    p='exactauthor:"%s"' % str(person_id))
    recids = list(set(recids) - set(exclude_recs))
    a = format_records(recids, 'WAPAFF')
    a = [deserialize(p) for p in a.strip().split('!---THEDELIMITER---!') if p]
    coauthors = {}
    for rec, affs in a:
        keys = affs.keys()
        for n in keys:
            try:
                coauthors[n].add(rec)
            except KeyError:
                coauthors[n] = set([rec])

    coauthors = [(x, x, len(coauthors[x])) for x in coauthors
                 if x.lower() != person_id.lower()]
    return coauthors
示例#9
0
def get_affiliation_for_paper(rec, name):
    """ Returns guessed affiliations for a given record id and name

    @param rec: record id to guess affiliations from
    @type: string

    @param name: string with the name of the author
    @type: string
    """
    try:
        affs = run_sql("""SELECT affiliations
                          FROM bibEDITAFFILIATIONS
                          WHERE bibrec=%s
                          AND name=%s""", (rec, name))
    except ProgrammingError:
        # Table bibEDITAFFILIATIONS does not exist. As it is not mandatory,
        # return None
        return None

    if not affs:
        return None

    return list(deserialize(affs[0][0]))
示例#10
0
def get_affiliation_for_paper(rec, name):
    """ Returns guessed affiliations for a given record id and name

    @param rec: record id to guess affiliations from
    @type: string

    @param name: string with the name of the author
    @type: string
    """
    try:
        affs = run_sql(
            """SELECT affiliations
                          FROM bibEDITAFFILIATIONS
                          WHERE bibrec=%s
                          AND name=%s""", (rec, name))
    except ProgrammingError:
        # Table bibEDITAFFILIATIONS does not exist. As it is not mandatory,
        # return None
        return None

    if not affs:
        return None

    return list(deserialize(affs[0][0]))