def write_megam_file(train_toks, encoding, stream, bernoulli=True, explicit=True):
 labels = encoding.labels()
 labelnum = dict(((label, i) for (i, label) in enumerate(labels)))
 for (featureset, label) in train_toks:
  if hasattr(encoding, 'cost'):
   stream.write(':'.join((str(encoding.cost(featureset, label, l)) for l in labels)))
  else:
   stream.write(('%d' % labelnum[label]))
  if (not explicit):
   _write_megam_features(encoding.encode(featureset, label), stream, bernoulli)
  else:
   for l in labels:
    stream.write(' #')
    _write_megam_features(encoding.encode(featureset, l), stream, bernoulli)
  stream.write('\n')

def write_megam_file ( train_toks , encoding , stream , bernoulli = True , explicit = True ) : labels = encoding . labels ( ) labelnum = dict ( ( ( label , i ) for ( i , label ) in enumerate ( labels ) ) ) for ( featureset , label ) in train_toks : if hasattr ( encoding , 'cost' ) : stream . write ( ':' . join ( ( str ( encoding . cost ( featureset , label , l ) ) for l in labels ) ) ) else : stream . write ( ( '%d' % labelnum [ label ] ) ) if ( not explicit ) : _write_megam_features ( encoding . encode ( featureset , label ) , stream , bernoulli ) else : for l in labels : stream . write ( ' #' ) _write_megam_features ( encoding . encode ( featureset , l ) , stream , bernoulli ) stream . write ( '\n' )
generate an input file for megam based on the given corpus of classified tokens .