Treebank-style tree parser python
Question: Recently i have been trying to parse syntactic trees returned by the [stanford
parser](http://nlp.stanford.edu/software/lex-parser.shtml) in python. I have
been trying to do that with nltk `tree =
Tree.parse(result['sentences'][0]['parsetree'])` and the parsing succeeds but
the tree class of nltk offers very few processing methods. I will need methods
like `tree.isPrePreTerminal()` which are not included from what i understand.
I found [this](http://nlp.stanford.edu/~mcclosky/software/PyInputTree/)
alternative but it seems that it doesnt like 64bit architectures and it gives
me this error `ImportError: InputTree/_InputTree.so: wrong ELF class:
ELFCLASS32` even though i compiled with the `-m64` flag. I have been looking
into this the last 2 days, if you know a way to make the above module to work
with 64bit systems or an alternate library or at least a good nltk.tree
documentation so that i implement the methods myself please let me know.


Answer: Unfortunately, `PyInputTree` is no longer maintained. However, the `InputTree`
class from the `Charniak` parser lives on in wrapped form as the [`Tree` class
in BLLIP Parser](https://github.com/BLLIP/bllip-parser/blob/master/README-
python.rst#the-tree-class). It doesn't implement `isPrePreTerminal()` but
here's one way to do it:

    
    
    import bllipparser
    
    def is_prepreterminal(node):
        """Returns True iff all children of this node are preterminals."""
        subtrees = node.subtrees()
        return len(subtrees) > 0 and \
            all(subtree.is_preterminal() for subtree in subtrees)
    
    # testing code
    tree = bllipparser.Tree('(S1 (S (NP (DT This)) (VP (VBZ is) (NP (DT a) (ADJP (RB fairly) (JJ simple)) (NN parse) (NN tree))) (. .)))')
    for subtree in tree.all_subtrees():
        print subtree, is_prepreterminal(subtree)
    

See [`bllipparser`](https://pypi.python.org/pypi/bllipparser) on PyPI for more
information.

