Java 树库风格的树解析器python

Java 树库风格的树解析器python,java,python,nlp,nltk,Java,Python,Nlp,Nltk,最近,我一直在尝试在python中解析由返回的语法树。我一直在尝试使用nltktree=tree.parse(result['句][0]['parsetree'])来实现这一点,解析成功了,但nltk的tree类提供的处理方法很少。我需要像tree.isPrePreTerminal()这样的方法,据我所知,这些方法不包括在内。我找到了替代方案,但它似乎不喜欢64位体系结构,它给了我这个错误ImportError:InputTree/\u InputTree.so:错误的ELF类:ELFCLASS

最近,我一直在尝试在python中解析由返回的语法树。我一直在尝试使用nltk
tree=tree.parse(result['句][0]['parsetree'])
来实现这一点,解析成功了,但nltk的tree类提供的处理方法很少。我需要像
tree.isPrePreTerminal()
这样的方法,据我所知,这些方法不包括在内。我找到了替代方案,但它似乎不喜欢64位体系结构,它给了我这个错误
ImportError:InputTree/\u InputTree.so:错误的ELF类:ELFCLASS32
,即使我使用
-m64
标志编译。
过去两天我一直在研究这个问题,如果您知道如何使上述模块与64位系统或备用库或至少一个好的nltk.tree文档一起工作,以便我自己实现这些方法,请告诉我。

不幸的是,
PyInputTree
不再维护。但是,来自
Charniak
解析器的
InputTree
类以包装形式作为。它没有实现
isPrePreTerminal()
,但有一种方法可以实现:

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)
有关更多信息,请参见PyPI