def induce_pcfg(start, productions):
 pcount = {}
 lcount = {}
 for prod in productions:
  lcount[prod.lhs()] = (lcount.get(prod.lhs(), 0) + 1)
  pcount[prod] = (pcount.get(prod, 0) + 1)
 prods = [ProbabilisticProduction(p.lhs(), p.rhs(), prob=(pcount[p] / lcount[p.lhs()])) for p in pcount]
 return PCFG(start, prods)

def induce_pcfg ( start , productions ) : pcount = { } lcount = { } for prod in productions : lcount [ prod . lhs ( ) ] = ( lcount . get ( prod . lhs ( ) , 0 ) + 1 ) pcount [ prod ] = ( pcount . get ( prod , 0 ) + 1 ) prods = [ ProbabilisticProduction ( p . lhs ( ) , p . rhs ( ) , prob = ( pcount [ p ] / lcount [ p . lhs ( ) ] ) ) for p in pcount ] return PCFG ( start , prods )
induce a pcfg grammar from a list of productions .