def find_keywords(string, parser, top=<NUM_LIT:10>, frequency={}, **kwargs):
lemmata = kwargs.pop("<STR_LIT>", kwargs.pop("<STR_LIT>", True))<EOL>chunks = []<EOL>wordcount = <NUM_LIT:0><EOL>for sentence in parser.parse(string, chunks=True, lemmata=lemmata).split():<EOL><INDENT>for w in sentence: <EOL><INDENT>if w[<NUM_LIT:2>] == "<STR_LIT>":<EOL><INDENT>chunks.append([w])<EOL>wordcount += <NUM_LIT:1><EOL><DEDENT>elif w[<NUM_LIT:2>] == "<STR_LIT>" and w[<NUM_LIT:1>][:<NUM_LIT:3>] == chunks[-<NUM_LIT:1>][-<NUM_LIT:1>][<NUM_LIT:1>][:<NUM_LIT:3>] == "<STR_LIT>":<EOL><INDENT>chunks[-<NUM_LIT:1>][-<NUM_LIT:1>][+<NUM_LIT:0>] += "<STR_LIT:U+0020>" + w[+<NUM_LIT:0>] <EOL>chunks[-<NUM_LIT:1>][-<NUM_LIT:1>][-<NUM_LIT:1>] += "<STR_LIT:U+0020>" + w[-<NUM_LIT:1>]<EOL><DEDENT>elif w[<NUM_LIT:2>] == "<STR_LIT>":<EOL><INDENT>chunks[-<NUM_LIT:1>].append(w)<EOL>wordcount += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>m = {}<EOL>for i, chunk in enumerate(chunks):<EOL><INDENT>head = True<EOL>if parser.language not in ("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>chunk = list(reversed(chunk))<EOL><DEDENT>for w in chunk:<EOL><INDENT>if w[<NUM_LIT:1>].startswith("<STR_LIT>"):<EOL><INDENT>if lemmata:<EOL><INDENT>k = w[-<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>k = w[<NUM_LIT:0>].lower()<EOL><DEDENT>if not k in m:<EOL><INDENT>m[k] = [<NUM_LIT:0.0>, set(), <NUM_LIT:1.0>, <NUM_LIT:1.0>, <NUM_LIT:1.0>]<EOL><DEDENT>m[k][<NUM_LIT:0>] += <NUM_LIT:1> / float(wordcount)<EOL>m[k][<NUM_LIT:1>].add("<STR_LIT:U+0020>".join(map(lambda x: x[<NUM_LIT:0>], chunk)).lower())<EOL>m[k][<NUM_LIT:2>] += <NUM_LIT:1> if float(i) / len(chunks) <= <NUM_LIT> else <NUM_LIT:0><EOL>m[k][<NUM_LIT:3>] += <NUM_LIT:1> if w[<NUM_LIT:3>] == "<STR_LIT:O>" else <NUM_LIT:0><EOL>m[k][<NUM_LIT:4>] += <NUM_LIT:1> if head else <NUM_LIT:0><EOL>head = False<EOL><DEDENT><DEDENT><DEDENT>for k in m:<EOL><INDENT>if frequency:<EOL><INDENT>df = frequency.get(k, <NUM_LIT:0.0>)<EOL>df = max(df, <NUM_LIT>)<EOL>df = log(<NUM_LIT:1.0> / df, <NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>df = <NUM_LIT:1.0><EOL><DEDENT>m[k][<NUM_LIT:0>] = max(<NUM_LIT>, m[k][<NUM_LIT:0>] * df)<EOL>m[k][<NUM_LIT:1>] = <NUM_LIT:1> + float(len(m[k][<NUM_LIT:1>]))<EOL><DEDENT>hmean = lambda a: len(a) / sum(<NUM_LIT:1.0> / x for x in a)<EOL>m = [(hmean(m[k]), k) for k in m]<EOL>m = sorted(m, key=lambda x: x[<NUM_LIT:1>])<EOL>m = sorted(m, key=lambda x: x[<NUM_LIT:0>], reverse=True)<EOL>m = [k for score, k in m]<EOL>return m[:top]<EOL>
Returns a sorted list of keywords in the given string.
        The given parser (e.g., pattern.en.parser) is used to identify noun phrases.
        The given frequency dictionary can be a reference corpus,
        with relative document frequency (df, 0.0-1.0) for each lemma, 
        e.g., {"the": 0.8, "cat": 0.1, ...}