title: Grouping of CFG grammar rules sentencewise
body: <p>Below specified rules are generated for each sentence. We have to group them for each sentence. The input is in file. Output also should be in file</p>
  
  <pre><code>sentenceid=2
  
  NP---&gt;N_NNP
  NP---&gt;N_NN_S_NU
  NP---&gt;N_NNP
  NP---&gt;N_NNP
  NP---&gt;N_NN_O_NU
  VGF---&gt;V_VM_VF
  
  sentenceid=3
  
  NP---&gt;N_NN
  VGNF---&gt;V_VM_VNF
  JJP---&gt;JJ
  NP---&gt;N_NN_S_NU
  NP---&gt;N_NN
  VGF---&gt;V_VM_VF
  
  sentenceid=4
  
  NP---&gt;N_NNP
  NP---&gt;N_NN_S_NU
  NP---&gt;N_NNP_O_M
  VGF---&gt;V_VM_VF
  </code></pre>
  
  <p>The above section containing input ,that is actually grammar for each sentence. I want to group adjacent rules sentence wise. Output should be like below.</p>
  
  <pre><code>sentenceid=2
  
  NP---&gt;N_NNP N_NN_S_NU N_NNP N_NNP N_NN_O_NU
  VGF---&gt;V_VM_VF
  
  sentenceid=3
  
  NP---&gt;N_NN
  VGNF---&gt;V_VM_VNF
  JJP---&gt;JJ
  NP---&gt;N_NN_S_NU N_NN
  VGF---&gt;V_VM_VF
  
  senetnceid=4
  
  NP---&gt;N_NNP N_NN_S_NU N_NNP_O_M
  VGF---&gt;V_VM_VF
  </code></pre>
  
  <p>How can I implement this? I need almost 1000 sentences rules for probability calculation. This is the CFG grammar for each sentence, I want to group adjacent rules sentence-wise.</p>