def get_author_keywords(skw_db, ckw_db, fulltext):
    """Find out human defined keywords in a text string.

    Searches for the string "Keywords:" and its declinations and matches the
    following words.
    """
    timer_start = time.clock()
    out = {}

    split_string = current_app.config[
        "CLASSIFIER_AUTHOR_KW_START"
    ].split(fulltext, 1)
    if len(split_string) == 1:
        current_app.logger.info(
            "No keyword marker found when matching authors.")
        return out

    kw_string = split_string[1]

    for regex in current_app.config["CLASSIFIER_AUTHOR_KW_END"]:
        parts = regex.split(kw_string, 1)
        kw_string = parts[0]

    # We separate the keywords.
    author_keywords = current_app.config[
        "CLASSIFIER_AUTHOR_KW_SEPARATION"
    ].split(kw_string)

    current_app.logger.info(
        "Matching author keywords... %d keywords found in "
        "%.1f sec." % (len(author_keywords), time.clock() - timer_start)
    )

    for kw in author_keywords:
        # If the author keyword is an acronym with capital letters
        # separated by points, remove the points.
        if re.match('([A-Z].)+$', kw):
            kw = kw.replace('.', '')

        # Drop trailing dots such as those in the last keyword.
        if kw.endswith('.'):
            kw = kw[:-1]

        # First try with the keyword as such, then lower it.
        kw_with_spaces = ' %s ' % kw
        matching_skw = get_single_keywords(skw_db, kw_with_spaces)
        matching_ckw = get_composite_keywords(ckw_db, kw_with_spaces,
                                              matching_skw)

        if matching_skw or matching_ckw:
            out[kw] = (matching_skw, matching_ckw)
            continue

        lowkw = kw.lower()

        matching_skw = get_single_keywords(skw_db, ' %s ' % lowkw)
        matching_ckw = get_composite_keywords(ckw_db, ' %s ' % lowkw,
                                              matching_skw)

        out[kw] = (matching_skw, matching_ckw)

    return out
def get_author_keywords ( skw_db , ckw_db , fulltext ) : timer_start = time . clock ( ) out = { } split_string = current_app . config [ "CLASSIFIER_AUTHOR_KW_START" ] . split ( fulltext , 1 ) if len ( split_string ) == 1 : current_app . logger . info ( "No keyword marker found when matching authors." ) return out kw_string = split_string [ 1 ] for regex in current_app . config [ "CLASSIFIER_AUTHOR_KW_END" ] : parts = regex . split ( kw_string , 1 ) kw_string = parts [ 0 ] author_keywords = current_app . config [ "CLASSIFIER_AUTHOR_KW_SEPARATION" ] . split ( kw_string ) current_app . logger . info ( "Matching author keywords... %d keywords found in " "%.1f sec." % ( len ( author_keywords ) , time . clock ( ) - timer_start ) ) for kw in author_keywords : if re . match ( '([A-Z].)+$' , kw ) : kw = kw . replace ( '.' , '' ) if kw . endswith ( '.' ) : kw = kw [ : - 1 ] kw_with_spaces = ' %s ' % kw matching_skw = get_single_keywords ( skw_db , kw_with_spaces ) matching_ckw = get_composite_keywords ( ckw_db , kw_with_spaces , matching_skw ) if matching_skw or matching_ckw : out [ kw ] = ( matching_skw , matching_ckw ) continue lowkw = kw . lower ( ) matching_skw = get_single_keywords ( skw_db , ' %s ' % lowkw ) matching_ckw = get_composite_keywords ( ckw_db , ' %s ' % lowkw , matching_skw ) out [ kw ] = ( matching_skw , matching_ckw ) return out
Find out human defined keywords in a text string.

    Searches for the string "Keywords:" and its declinations and matches the
    following words.