title: How to extract the grammar productions rules given bracketed parses?
body: <p>I have a sample sentence. "Open the door." that I parsed a sentence to get the bracketed parse output as below.</p>
  
  <blockquote>
    <p>(S (VP (VB open) (NP (DT the) (NN door))) (. .))</p>
  </blockquote>
  
  <p>I need to extract the CFG grammar rules that produce the parsed output.
  I can manually write them out as such:</p>
  
  <pre><code>grammar = CFG.fromstring("""   
  S -&gt; VP NP   
  NP -&gt; Det N   
  VP -&gt; V   
  Det -&gt;'the '   
  N -&gt; 'door'   
  V -&gt; 'Open'   
  """)  
  </code></pre>
  
  <p>But it's time consuming, how do I produce the grammar rules given the bracketed parsed automatically?</p>