def nltk_tree(sentence):
from nltk import tree<EOL>def do_pnp(pnp):<EOL><INDENT>s = '<STR_LIT:U+0020>'.join([do_chunk(ch) for ch in pnp.chunks])<EOL>return '<STR_LIT>' % s<EOL><DEDENT>def do_chunk(ch):<EOL><INDENT>s = '<STR_LIT:U+0020>'.join(['<STR_LIT>' % (w.pos, w.string) for w in ch.words])<EOL>s+= '<STR_LIT:U+0020>'.join([do_pnp(pnp) for pnp in ch.attachments])<EOL>return '<STR_LIT>' % (ch.type, s)<EOL><DEDENT>T = ['<STR_LIT>']<EOL>v = [] <EOL>for ch in sentence.chunked():<EOL><INDENT>if not ch.pnp and isinstance(ch, Chink):<EOL><INDENT>T.append('<STR_LIT>' % (ch.words[<NUM_LIT:0>].pos, ch.words[<NUM_LIT:0>].string))<EOL><DEDENT>elif not ch.pnp:<EOL><INDENT>T.append(do_chunk(ch))<EOL><DEDENT>elif ch.pnp.anchor is None and ch.pnp not in v:<EOL><INDENT>T.append(do_pnp(ch.pnp))<EOL>v.append(ch.pnp)<EOL><DEDENT><DEDENT>T.append('<STR_LIT:)>')<EOL>return tree.bracket_parse('<STR_LIT:U+0020>'.join(T))<EOL>
Returns an NLTK nltk.tree.Tree object from the given Sentence.
        The NLTK module should be on the search path somewhere.