/* itgtrain.h
 *
 * Contains class declaration used for training ITG model.
 *
 * $Id: itgtrain.h,v 1.5 2008/05/18 15:12:02 zhanghao Exp $
 */

#include "itg.h"
#include "itgchart.h"

using namespace std;

#ifndef TRAINER_H
#define TRAINER_H

class Trainer : public ITG
{
 public:
  Trainer(ITGGrammar*,ITGCorp*);
  virtual ~Trainer();

  void tinit(); // initialize alpha, beta, before parsing
  void parse(); // pack up all the parse trees, get alpha, beta
  void count(); //get the expected counts, update grammar

  void update() { 
    if (Globals::Get<bool>("mixture_DP")) 
      grammar->mdpnormalize();
    else
      grammar->normalize(); 

    loglike = 0; 
  }
  void dumpbefore() { grammar->dumpcnt(counts_file); }
  void dumpafter() { grammar->dumpprb(rule_probs_file, t_probs_file); }

  void run();

 protected:
  ITGChart *chart;
  string counts_file; // name of the file of expected counts 
  string rule_probs_file;  // name of the file of probabilities
  string t_probs_file;  // name of the file of probabilities
  bool CLONING;
  int MAXITER;
};

#endif
