def find_chunks(tagged, language="<STR_LIT>"):
chunked = [x for x in tagged]<EOL>tags = "<STR_LIT>".join("<STR_LIT>" % (tag, SEPARATOR) for token, tag in tagged)<EOL>for tag, rule in CHUNKS[int(language in ("<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"))]:<EOL><INDENT>for m in rule.finditer(tags):<EOL><INDENT>i = m.start()<EOL>j = tags[:i].count(SEPARATOR)<EOL>n = m.group(<NUM_LIT:0>).count(SEPARATOR)<EOL>for k in range(j, j+n):<EOL><INDENT>if len(chunked[k]) == <NUM_LIT:3>:<EOL><INDENT>continue<EOL><DEDENT>if len(chunked[k]) < <NUM_LIT:3>:<EOL><INDENT>if k == j and chunked[k][<NUM_LIT:1>] in ("<STR_LIT>", "<STR_LIT>", "<STR_LIT:U+002C>"):<EOL><INDENT>j += <NUM_LIT:1><EOL><DEDENT>elif k == j:<EOL><INDENT>chunked[k].append("<STR_LIT>" + tag)<EOL><DEDENT>else:<EOL><INDENT>chunked[k].append("<STR_LIT>" + tag)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>for chink in filter(lambda x: len(x) < <NUM_LIT:3>, chunked):<EOL><INDENT>chink.append("<STR_LIT:O>")<EOL><DEDENT>for i, (word, tag, chunk) in enumerate(chunked):<EOL><INDENT>if tag.startswith("<STR_LIT>") and chunk == "<STR_LIT>":<EOL><INDENT>if i < len(chunked)-<NUM_LIT:1> and not chunked[i+<NUM_LIT:1>][<NUM_LIT:1>].startswith("<STR_LIT>"):<EOL><INDENT>chunked[i+<NUM_LIT:0>][<NUM_LIT:2>] = "<STR_LIT>"<EOL>chunked[i+<NUM_LIT:1>][<NUM_LIT:2>] = "<STR_LIT>"<EOL><DEDENT>if i < len(chunked)-<NUM_LIT:1> and chunked[i+<NUM_LIT:1>][<NUM_LIT:1>] in ("<STR_LIT>", "<STR_LIT>", "<STR_LIT:U+002C>"):<EOL><INDENT>chunked[i+<NUM_LIT:1>][<NUM_LIT:2>] = "<STR_LIT:O>"<EOL><DEDENT>if i < len(chunked)-<NUM_LIT:2> and chunked[i+<NUM_LIT:1>][<NUM_LIT:2>] == "<STR_LIT:O>":<EOL><INDENT>chunked[i+<NUM_LIT:2>][<NUM_LIT:2>] = "<STR_LIT>"<EOL><DEDENT><DEDENT><DEDENT>return chunked<EOL>
The input is a list of [token, tag]-items.
        The output is a list of [token, tag, chunk]-items:
        The/DT nice/JJ fish/NN is/VBZ dead/JJ ./. =>
        The/DT/B-NP nice/JJ/I-NP fish/NN/I-NP is/VBZ/B-VP dead/JJ/B-ADJP ././O