def perform_request_knowledge_base_show(kb_id, ln=CFG_SITE_LANG, sortby="to",
                                        startat=0, search_term=""):
    """
    Show the content of a knowledge base

    @param ln language
    @param kb a knowledge base id
    @param sortby the sorting criteria ('from' or 'to')
    @param startat start showing mapping rules at what number
    @param search_term search for this string in kb
    @return the content of the given knowledge base
    """
    name = bibknowledge_dblayer.get_kb_name(kb_id)
    mappings = bibknowledge_dblayer.get_kb_mappings(name, sortby)

    kb_type = bibknowledge_dblayer.get_kb_type(kb_id)
    #filter in only the requested rules if the user is searching..
    if search_term:
        newmappings = []
        for mapping in mappings:
            key =  mapping['key']
            value = mapping['value']
            if key.count(search_term)> 0 or value.count(search_term)> 0:
                newmappings.append(mapping)
        #we were searching, so replace
        mappings = newmappings
    #if this bk is dynamic, get the configuration from the DB
    dyn_config = None
    if kb_type == 'd':
        dyn_config = bibknowledge_dblayer.get_kb_dyn_config(kb_id)
    return bibknowledge_templates.tmpl_admin_kb_show(ln, kb_id, name,
                                                     mappings, sortby, startat,
                                                     kb_type, search_term,
                                                     dyn_config)
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
    """
    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 not confdict.has_key('field'):
        return []
    field = confdict['field']
    expression = confdict['expression']
    collection = ""
    if confdict.has_key('collection'):
        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:
        fieldvaluelist = search_engine.get_most_popular_field_values(reclist,
                                                                     field)
        val_list = []
        for f in fieldvaluelist:
            (val, dummy) = f
            val_list.append(val)
        return val_list
    return [] #in case nothing worked
Esempio n. 3
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
    """
    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 not confdict.has_key('field'):
        return []
    field = confdict['field']
    expression = confdict['expression']
    collection = ""
    if confdict.has_key('collection'):
        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:
        fieldvaluelist = search_engine.get_most_popular_field_values(reclist,
                                                                     field)
        val_list = []
        for f in fieldvaluelist:
            (val, dummy) = f
            val_list.append(val)
        return val_list
    return [] #in case nothing worked
def perform_request_knowledge_base_show_attributes(kb_id, ln=CFG_SITE_LANG, sortby="to"):
    """
    Show the attributes of a knowledge base

    @param ln language
    @param kb a knowledge base id
    @param sortby the sorting criteria ('from' or 'to')
    @return the content of the given knowledge base
    """
    name = bibknowledge_dblayer.get_kb_name(kb_id)
    description = bibknowledge_dblayer.get_kb_description(name)
    kb_type = bibknowledge_dblayer.get_kb_type(name)
    return bibknowledge_templates.tmpl_admin_kb_show_attributes(ln, kb_id, name, description, sortby, kb_type)
Esempio n. 5
0
def perform_request_knowledge_base_show_attributes(kb_id,
                                                   ln=CFG_SITE_LANG,
                                                   sortby="to"):
    """
    Show the attributes of a knowledge base

    @param ln language
    @param kb a knowledge base id
    @param sortby the sorting criteria ('from' or 'to')
    @return the content of the given knowledge base
    """
    name = bibknowledge_dblayer.get_kb_name(kb_id)
    description = bibknowledge_dblayer.get_kb_description(name)
    kb_type = bibknowledge_dblayer.get_kb_type(name)
    return bibknowledge_templates.tmpl_admin_kb_show_attributes(
        ln, kb_id, name, description, sortby, kb_type)
def perform_request_knowledge_base_show(kb_id,
                                        ln=CFG_SITE_LANG,
                                        sortby="to",
                                        startat=0,
                                        search_term=""):
    """
    Show the content of a knowledge base

    @param ln language
    @param kb a knowledge base id
    @param sortby the sorting criteria ('from' or 'to')
    @param startat start showing mapping rules at what number
    @param search_term search for this string in kb
    @return the content of the given knowledge base
    """
    name = bibknowledge_dblayer.get_kb_name(kb_id)
    mappings = bibknowledge_dblayer.get_kb_mappings(name, sortby)

    kb_type = bibknowledge_dblayer.get_kb_type(kb_id)
    #filter in only the requested rules if the user is searching..
    if search_term:
        newmappings = []
        for mapping in mappings:
            key = mapping['key']
            value = mapping['value']
            if key.count(search_term) > 0 or value.count(search_term) > 0:
                newmappings.append(mapping)
        #we were searching, so replace
        mappings = newmappings
    #if this bk is dynamic, get the configuration from the DB, and a list of
    #collections as a bonus
    dyn_config = None
    collections = None
    if kb_type == 'd':
        from invenio.search_engine import get_alphabetically_ordered_collection_list
        dyn_config = bibknowledge_dblayer.get_kb_dyn_config(kb_id)
        collections = []
        collitems = get_alphabetically_ordered_collection_list()
        for collitem in collitems:
            collections.append(collitem[0])
    return bibknowledge_templates.tmpl_admin_kb_show(ln, kb_id, name, mappings,
                                                     sortby, startat, kb_type,
                                                     search_term, dyn_config,
                                                     collections)
Esempio n. 7
0
def get_kbd_values(kbname, searchwith=""):
    """
    To be used by bibedit. Returns a list of values based on a dynamic kb.
    @param kbname: name of the knowledge base
    @param searchwith: a term to search with
    """
    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 not confdict.has_key('field'):
        return []
    field = confdict['field']
    expression = confdict['expression']
    collection = ""
    if confdict.has_key('collection'):
        collection = confdict['collection']
    reclist = [] #return this
    #see if searchwith is a quoted expression
    if searchwith:
        if not searchwith.startswith("'"):
            searchwith = "'"+searchwith
        if not searchwith.endswith("'"):
            searchwith = searchwith+"'"
    if searchwith and expression:
        if (expression.count('%') > 0) or (expression.endswith(":*")):
            expression = expression.replace("%", searchwith)
            expression = expression.replace(":*", ':'+searchwith)
        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:
            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:
        fieldvaluelist = search_engine.get_most_popular_field_values(reclist,
                                                                     field)
        val_list = []
        for f in fieldvaluelist:
            (val, dummy) = f
            #support "starts with",
            #indicated by the * at the end of the searchstring
            if searchwith and (len(searchwith) > 2) and (searchwith[-2] == '*'):
                if (val.startswith(searchwith[1:-3])):
                    val_list.append(val)
            else:
                val_list.append(val)
        return val_list
    return [] #in case nothing worked
Esempio n. 8
0
def get_kbd_values(kbname, searchwith=""):
    """
    To be used by bibedit. Returns a list of values based on a dynamic kb.
    @param kbname: name of the knowledge base
    @param searchwith: a term to search with
    """
    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 not confdict.has_key('field'):
        return []
    field = confdict['field']
    expression = confdict['expression']
    collection = ""
    if confdict.has_key('collection'):
        collection = confdict['collection']
    reclist = []  #return this
    #see if searchwith is a quoted expression
    if searchwith:
        if not searchwith.startswith("'"):
            searchwith = "'" + searchwith
        if not searchwith.endswith("'"):
            searchwith = searchwith + "'"
    if searchwith and expression:
        if (expression.count('%') > 0) or (expression.endswith(":*")):
            expression = expression.replace("%", searchwith)
            expression = expression.replace(":*", ':' + searchwith)
        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:
            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:
        fieldvaluelist = search_engine.get_most_popular_field_values(
            reclist, field)
        val_list = []
        for f in fieldvaluelist:
            (val, dummy) = f
            #support "starts with",
            #indicated by the * at the end of the searchstring
            if searchwith and (len(searchwith) > 2) and (searchwith[-2]
                                                         == '*'):
                if (val.startswith(searchwith[1:-3])):
                    val_list.append(val)
            else:
                val_list.append(val)
        return val_list
    return []  #in case nothing worked