title: NLTK context-free grammars
body: <p>I am just wondering how would you add an optional grammer in the rule</p>
  
  <pre><code>&gt;&gt;&gt; import nltk
  &gt;&gt;&gt; nltk.app.rdparser()
  </code></pre>
  
  <p>For example, the normal way to add a optional grammer is by putting it in parentheses: NP -> NP (PP) </p>
  
  <p>But in the program how would you do it? parentheses doesnt  work.</p>
  
  <pre><code>S   Þ NP VP
  NP  Þ NP PP | Det N
  VP  Þ V NP PP
  PP  Þ P NP
  
  Det Þ 'the' | 'a'
  N   Þ 'man' | 'park' | 'dog' | 'boy' | 'girl'
  V   Þ 'was' | 'saw' 
  P   Þ 'in' | 'under' | 'with'
  </code></pre>
  
  <p>Thanks,</p>
  
  <p>Ray</p>