擅长:python、mysql、java
<p>你可以使用<strong>树.生产()</strong>从树中获取CFG规则的方法。在</p>
<p><strong>示例:</strong></p>
<pre><code>from nltk import Tree
t = Tree.fromstring("(S (VP (VB open) (NP (DT the) (NN door))) (. .))")
print t.productions()
</code></pre>
<p><strong>输出:</strong></p>
^{pr2}$
<p>有关详细信息,请查看-<a href="http://www.nltk.org/api/nltk.html#nltk.tree.Tree.productions" rel="noreferrer">NLTK Tree Productions</a></p>