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)
Exemple #2
0
def get_kb_mappings(kb_name="", key="", value="", match_type="s"):
    """Get mappings from kb kb_name. If key given, give only those with
       left side (mapFrom) = key. If value given, give only those with
       right side (mapTo) = value.
       @param kb_name: the name of the kb
       @param key: include only lines matching this on left side in the results
       @param value: include only lines matching this on right side in the results
       @param match_type: s = substring match, e = exact match
       @return a list of mappings
    """
    return bibknowledge_dblayer.get_kb_mappings(kb_name,
                                         keylike=key, valuelike=value,
                                         match_type=match_type)
def get_kb_mapping(kb_name="", key="", value="", match_type="e", default=""):
    """Get one unique mapping. If not found, return default
       @param kb_name: the name of the kb
       @param key: include only lines matching this on left side in the results
       @param value: include only lines matching this on right side in the results
       @param match_type: s = substring match, e = exact match
       @return a mapping
    """
    mappings = bibknowledge_dblayer.get_kb_mappings(kb_name, keylike=key, valuelike=value, match_type=match_type)
    if len(mappings) == 0:
        return default
    else:
        return mappings[0]
def get_kb_mappings(kb_name="", key="", value="", match_type="s"):
    """Get mappings from kb kb_name. If key given, give only those with
       left side (mapFrom) = key. If value given, give only those with
       right side (mapTo) = value.
       @param kb_name: the name of the kb
       @param key: include only lines matching this on left side in the results
       @param value: include only lines matching this on right side in the results
       @param match_type: s = substring match, e = exact match
       @return a list of mappings
    """
    return bibknowledge_dblayer.get_kb_mappings(kb_name,
                                         keylike=key, valuelike=value,
                                         match_type=match_type)
Exemple #5
0
def get_kb_mapping(kb_name="", key="", value="", match_type="e", default=""):
    """Get one unique mapping. If not found, return default
       @param kb_name: the name of the kb
       @param key: include only lines matching this on left side in the results
       @param value: include only lines matching this on right side in the results
       @param match_type: s = substring match, e = exact match
       @return a mapping
    """
    mappings = bibknowledge_dblayer.get_kb_mappings(kb_name,
                                         keylike=key, valuelike=value,
                                         match_type=match_type)
    if len(mappings) == 0:
        return default
    else:
        return mappings[0]
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)
Exemple #7
0
def perform_request_knowledge_bases_management(ln=CFG_SITE_LANG,
                                               search="",
                                               descriptiontoo=""):
    """
    Returns the main page for knowledge bases management.

    @param ln language
    @param search search for this string in kb's
    @param descriptiontoo search in descriptions too
    @return the main page for knowledge bases management
    """
    kbs = bibknowledge.get_kbs_info()
    #if search is nonempty, filter out kb's that do not have the
    #the string that we search
    newkbs = []
    if search:
        for kb in kbs:
            skip = 0  #do-we-need-to-scan-more control
            kbname = kb['name']
            #get description if needed
            if descriptiontoo and kb['description'].count(search) > 0:
                #add and skip
                newkbs.append(kb)
                skip = 1
            #likewise: check if name matches
            if descriptiontoo and kbname.count(search) > 0:
                #add and skip
                newkbs.append(kb)
                skip = 1
            #get mappings
            mappings = bibknowledge_dblayer.get_kb_mappings(kbname)
            for mapping in mappings:
                if skip == 0:
                    key = mapping['key']
                    value = mapping['value']
                    if key.count(search) > 0 or value.count(search) > 0:
                        #add this in newkbs
                        newkbs.append(kb)
                        #skip the rest, we know there's ok stuff in this kb
                        skip = 1
        kbs = newkbs

    return bibknowledge_templates.tmpl_admin_kbs_management(ln, kbs, search)
def perform_request_knowledge_bases_management(ln=CFG_SITE_LANG, search="",
                                               descriptiontoo=""):
    """
    Returns the main page for knowledge bases management.

    @param ln language
    @param search search for this string in kb's
    @param descriptiontoo search in descriptions too
    @return the main page for knowledge bases management
    """
    kbs = bibknowledge.get_kbs_info()
    #if search is nonempty, filter out kb's that do not have the
    #the string that we search
    newkbs = []
    if search:
        for kb in kbs:
            skip = 0 #do-we-need-to-scan-more control
            kbname = kb['name']
            #get description if needed
            if descriptiontoo and kb['description'].count(search) > 0:
                #add and skip
                newkbs.append(kb)
                skip = 1
            #likewise: check if name matches
            if descriptiontoo and kbname.count(search) > 0:
                #add and skip
                newkbs.append(kb)
                skip = 1
            #get mappings
            mappings = bibknowledge_dblayer.get_kb_mappings(kbname)
            for mapping in mappings:
                if skip == 0:
                    key =  mapping['key']
                    value = mapping['value']
                    if key.count(search)> 0 or value.count(search)> 0:
                        #add this in newkbs
                        newkbs.append(kb)
                        #skip the rest, we know there's ok stuff in this kb
                        skip = 1
        kbs = newkbs

    return bibknowledge_templates.tmpl_admin_kbs_management(ln, kbs, search)