def find_relations(chunked):
tag = lambda token: token[<NUM_LIT:2>].split("<STR_LIT:->")[-<NUM_LIT:1>] <EOL>chunks = []<EOL>for token in chunked:<EOL><INDENT>if len(chunks) == <NUM_LIT:0>or token[<NUM_LIT:2>].startswith("<STR_LIT>")or tag(token) != tag(chunks[-<NUM_LIT:1>][-<NUM_LIT:1>]):<EOL><INDENT>chunks.append([])<EOL><DEDENT>chunks[-<NUM_LIT:1>].append(token+["<STR_LIT:O>"])<EOL><DEDENT>id = <NUM_LIT:0><EOL>for i, chunk in enumerate(chunks):<EOL><INDENT>if tag(chunk[-<NUM_LIT:1>]) == "<STR_LIT>" and i > <NUM_LIT:0> and tag(chunks[i-<NUM_LIT:1>][-<NUM_LIT:1>]) == "<STR_LIT>":<EOL><INDENT>if chunk[-<NUM_LIT:1>][-<NUM_LIT:1>] == "<STR_LIT:O>":<EOL><INDENT>id += <NUM_LIT:1><EOL><DEDENT>for token in chunk:<EOL><INDENT>token[-<NUM_LIT:1>] = "<STR_LIT>" + str(id)<EOL><DEDENT>for token in chunks[i-<NUM_LIT:1>]:<EOL><INDENT>token[-<NUM_LIT:1>] += "<STR_LIT>" + str(id)<EOL>token[-<NUM_LIT:1>] = token[-<NUM_LIT:1>].lstrip("<STR_LIT>")<EOL><DEDENT><DEDENT>if tag(chunk[-<NUM_LIT:1>]) == "<STR_LIT>" and i < len(chunks)-<NUM_LIT:1> and tag(chunks[i+<NUM_LIT:1>][-<NUM_LIT:1>]) == "<STR_LIT>":<EOL><INDENT>if chunk[-<NUM_LIT:1>][-<NUM_LIT:1>] == "<STR_LIT:O>":<EOL><INDENT>id += <NUM_LIT:1><EOL><DEDENT>for token in chunk:<EOL><INDENT>token[-<NUM_LIT:1>] = "<STR_LIT>" + str(id)<EOL><DEDENT>for token in chunks[i+<NUM_LIT:1>]:<EOL><INDENT>token[-<NUM_LIT:1>] = "<STR_LIT>" + str(id)<EOL>token[-<NUM_LIT:1>] = token[-<NUM_LIT:1>].lstrip("<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT>for i, chunk in enumerate(chunks):<EOL><INDENT>if <NUM_LIT:0> < i < len(chunks)-<NUM_LIT:1> and len(chunk) == <NUM_LIT:1> and chunk[-<NUM_LIT:1>][-<NUM_LIT:1>] == "<STR_LIT:O>":<EOL><INDENT>t0, t1, t2 = chunks[i-<NUM_LIT:1>][-<NUM_LIT:1>], chunks[i][<NUM_LIT:0>], chunks[i+<NUM_LIT:1>][<NUM_LIT:0>] <EOL>if tag(t1) == "<STR_LIT>" and t2[<NUM_LIT:1>] in ("<STR_LIT>", "<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>if t0[<NUM_LIT:0>] in BE and t1[<NUM_LIT:0>] in ("<STR_LIT>", "<STR_LIT>")      : t1[-<NUM_LIT:1>] = "<STR_LIT>"<EOL>if t0[<NUM_LIT:0>] in GO and t1[<NUM_LIT:0>] in ("<STR_LIT:to>", "<STR_LIT>") : t1[-<NUM_LIT:1>] = "<STR_LIT>"<EOL><DEDENT><DEDENT><DEDENT>related = []; [related.extend(chunk) for chunk in chunks]<EOL>return related<EOL>
The input is a list of [token, tag, chunk]-items.
        The output is a list of [token, tag, chunk, relation]-items.
        A noun phrase preceding a verb phrase is perceived as sentence subject.
        A noun phrase following a verb phrase is perceived as sentence object.