def _get_kwtuples_bai(pubs, person_id):
    '''
    Returns the list of keyword tuples for given personid.
    @param person_id: int person id
    '''
    tup = get_most_popular_field_values(pubs,
                            (CFG_WEBAUTHORPROFILE_KEYWORD_TAG), count_repetitive_values=True)
    return tup
def _get_collabtuples_fallback(pubs, person_id):
    '''
    Returns the list of keyword tuples for given personid.
    @param person_id: int person id
    '''
    tup = get_most_popular_field_values(pubs,
                            CFG_WEBAUTHORPROFILE_COLLABORATION_TAG, count_repetitive_values=True)
    return tup
def _get_collabtuples_fallback(pubs, person_id):
    '''
    Returns the keyword tuples for given personid.
    @param person_id: int person id
    '''
    tup = get_most_popular_field_values(pubs,
                            COLLABORATION_TAG, count_repetitive_values=False)
    return tup
def _get_kwtuples_fallback(pubs, person_id):
    '''
    Returns the keyword tuples for given personid.
    @param person_id: int person id
    '''
    tup = get_most_popular_field_values(pubs,
                            (KEYWORD_TAG, FKEYWORD_TAG), count_repetitive_values=False)
    return tup
def _get_kwtuples_fallback(pubs, person_id):
    '''
    Returns the list of keyword tuples for given personid.
    @param person_id: int person id
    '''
    tup = get_most_popular_field_values(pubs, (KEYWORD_TAG, FKEYWORD_TAG),
                                        count_repetitive_values=False)
    return tup
def _get_collabtuples_bai(pubs, person_id):
    '''
    Returns the list keyword tuples for given personid.
    @param person_id: int person id
    '''
    tup = get_most_popular_field_values(pubs, COLLABORATION_TAG,
                                        count_repetitive_values=False)
    return tup
def _get_collabtuples_fallback(pubs, person_id):
    '''
    Returns the list of keyword tuples for given personid.
    @param person_id: int person id
    '''
    tup = get_most_popular_field_values(pubs,
                                        CFG_WEBAUTHORPROFILE_COLLABORATION_TAG,
                                        count_repetitive_values=True)
    return tup
def _get_kwtuples_bai(pubs, person_id):
    '''
    Returns the list of keyword tuples for given personid.
    @param person_id: int person id
    '''
    tup = get_most_popular_field_values(pubs,
                                        (CFG_WEBAUTHORPROFILE_KEYWORD_TAG),
                                        count_repetitive_values=True)
    return tup
Esempio n. 9
0
def get_kbd_values(kbname, searchwith=""):
    """Return a list of values by searching a dynamic kb.

    @param kbname:     name of the knowledge base
    @param searchwith: a term to search with
    """
    from invenio import search_engine

    #first check that the kb in question is dynamic
    kbid = bibknowledge_dblayer.get_kb_id(kbname)
    if not kbid:
        return []
    kbtype = bibknowledge_dblayer.get_kb_type(kbid)
    if not kbtype:
        return []
    if kbtype != 'd':
        return []
    #get the configuration so that we see what the field is
    confdict = bibknowledge_dblayer.get_kb_dyn_config(kbid)
    if not confdict:
        return []
    if 'field' not in confdict:
        return []
    field = confdict['field']
    expression = confdict['expression']
    collection = ""
    if 'collection' in confdict:
        collection = confdict['collection']
    reclist = []  # return this
    if searchwith and expression:
        if (expression.count('%') > 0):
            expression = expression.replace("%", searchwith)
            reclist = search_engine.perform_request_search(p=expression,
                                                           cc=collection)
        else:
            #no %.. just make a combination
            expression = expression + " and " + searchwith
            reclist = search_engine.perform_request_search(p=expression,
                                                           cc=collection)
    else:  # either no expr or no searchwith.. but never mind about searchwith
        if expression:  # in this case: only expression
            reclist = search_engine.perform_request_search(p=expression,
                                                           cc=collection)
        else:
            #make a fake expression so that only records that have this field
            #will be returned
            fake_exp = "/.*/"
            if searchwith:
                fake_exp = searchwith
            reclist = search_engine.perform_request_search(f=field,
                                                           p=fake_exp,
                                                           cc=collection)
    if reclist:
        return [val for (val, dummy) in \
            search_engine.get_most_popular_field_values(reclist, field)]
    return []  # in case nothing worked
def _get_fieldtuples_bai_tup(pubs, person_id):
    '''
    Returns the fieldcode tuples for given personid.
    @param person_id: int person id
    '''
    tup = get_most_popular_field_values(pubs,
                            CFG_WEBAUTHORPROFILE_FIELDCODE_TAG, count_repetitive_values=True)
    if CFG_WEBAUTHORPROFILE_USE_ALLOWED_FIELDCODES and CFG_WEBAUTHORPROFILE_ALLOWED_FIELDCODES:
        return tuple([x for x in tup if x[0] in CFG_WEBAUTHORPROFILE_ALLOWED_FIELDCODES])
    return tup
Esempio n. 11
0
def get_kbd_values(kbname, searchwith=""):
    """Return a list of values by searching a dynamic kb.

    @param kbname:     name of the knowledge base
    @param searchwith: a term to search with
    """
    from invenio import search_engine

    #first check that the kb in question is dynamic
    kbid = bibknowledge_dblayer.get_kb_id(kbname)
    if not kbid:
        return []
    kbtype = bibknowledge_dblayer.get_kb_type(kbid)
    if not kbtype:
        return []
    if kbtype != 'd':
        return []
    #get the configuration so that we see what the field is
    confdict = bibknowledge_dblayer.get_kb_dyn_config(kbid)
    if not confdict:
        return []
    if 'field' not in confdict:
        return []
    field = confdict['field']
    expression = confdict['expression']
    collection = ""
    if 'collection' in confdict:
        collection = confdict['collection']
    reclist = []  # return this
    if searchwith and expression:
        if (expression.count('%') > 0):
            expression = expression.replace("%", searchwith)
            reclist = search_engine.perform_request_search(p=expression,
                                                           cc=collection)
        else:
            #no %.. just make a combination
            expression = expression + " and " + searchwith
            reclist = search_engine.perform_request_search(p=expression,
                                                           cc=collection)
    else:  # either no expr or no searchwith.. but never mind about searchwith
        if expression:  # in this case: only expression
            reclist = search_engine.perform_request_search(p=expression,
                                                           cc=collection)
        else:
            #make a fake expression so that only records that have this field
            #will be returned
            fake_exp = "/.*/"
            if searchwith:
                fake_exp = searchwith
            reclist = search_engine.perform_request_search(f=field, p=fake_exp,
                                                           cc=collection)
    if reclist:
        return [val for (val, dummy) in \
            search_engine.get_most_popular_field_values(reclist, field)]
    return []  # in case nothing worked
Esempio n. 12
0
 def get_facets_for_query(self, qid, limit=20, parent=None):
     from invenio.search_engine_config import CFG_LANGUAGE_DICT as language_dict
     facet = get_most_popular_field_values(self.get_recids(qid),
                                           get_field_tags(self.name)
                                           )[0:limit]
     nicer_facet = []
     for i in facet:
         if i[0] in language_dict.keys():
             nicer_facet.append((i[0], i[1], language_dict[i[0]]))
         elif i[0] not in ('N/A',):
             nicer_facet.append((i[0], i[1], i[0]))
     return nicer_facet
def _get_fieldtuples_bai_tup(pubs, person_id):
    '''
    Returns the fieldcode tuples for given personid.
    @param person_id: int person id
    '''
    tup = get_most_popular_field_values(pubs,
                                        CFG_WEBAUTHORPROFILE_FIELDCODE_TAG,
                                        count_repetitive_values=True)
    if CFG_WEBAUTHORPROFILE_USE_ALLOWED_FIELDCODES and CFG_WEBAUTHORPROFILE_ALLOWED_FIELDCODES:
        return tuple([
            x for x in tup if x[0] in CFG_WEBAUTHORPROFILE_ALLOWED_FIELDCODES
        ])
    return tup
Esempio n. 14
0
def bst_autocompletion_cache(collection_list=None):
    """
    Bibtasklet responsible of the generation of the subjects and authors list for the
    autocompletion suggestions.
    @param collection_list: list of collection ids to cache.
                            If None, all the collections will be calculated.

    """

    task_update_progress("Started updating autocomplete cache")

    tag_dicc = {'en': '9051_a', 'fr': '9061_a', 'es': '9071_a'}

    if collection_list == None:
        res = run_sql("SELECT id FROM collection")
        collection_list = [i[0] for i in res]

    i = 0
    task_update_progress("Done %s of %s" % (i, len(collection_list)))
    for collection in collection_list:
        i += 1
        recids = list(get_collection_reclist(get_collection_name_by_id(collection)))
        authors = get_most_popular_field_values(recids, get_field_tags('exactauthor'))[0:200]
        authors = [a[0] for a in authors]

        subjects = {}
        for ln in ['en', 'fr', 'es']:
            subject_tag = tag_dicc[ln]
            subjects[ln] = [s[0] for s in get_most_popular_field_values(recids, subject_tag)]

        ins = AutocompletionCache(id_collection=collection, authors=authors, subjects=subjects)
        db.session.merge(ins)
        db.session.flush()
        task_update_progress("Done %s of %s" % (i, len(collection_list)))


    db.session.close_all()
    task_update_progress("Finished updating autocomplete cache")
Esempio n. 15
0
    def get_facets_for_query(self, qid, limit=20, parent=None):
        facet = get_most_popular_field_values(self.get_recids(qid),
                                             get_field_tags(self.name))
        nicer_facet = [i for i in facet if is_correct_year(i[0])]

        return sorted(nicer_facet, key=lambda x: x[0], reverse=True)[0:limit]
 def get_facets_for_query(self, qid, limit=20, parent=None):
     return get_most_popular_field_values(self.get_recids(qid),
                                          get_field_tags(
                                              self.name))[0:limit]
def _get_venuetuples(pubs, person_id):
    tup = get_most_popular_field_values(pubs, (VENUE_TAG))
    return tup
def _get_venuetuples(pubs, person_id):
    tup = get_most_popular_field_values(pubs, (VENUE_TAG))
    return tup