/* itg.h
 *
 * $Id: itg.h,v 1.18 2008/05/08 15:12:52 post Exp $
 */

#ifndef ITG_H
#define ITG_H

#include "itgcorp.h"
#include "itggrmr.h"
#include "itgchart.h"
#include "ngram.h"

#include <queue>
#include <functional>
#include <stack>
#include <list>
#include <unistd.h>

using namespace std;

// default maximum sentence length
#define DEFAULTMAXT 25
#define DEFAULTMAXV 25

class ITG {
 public:
  WORDTYPE *en, *cn;      // the sentences (only one used for decoding)
  int T, V;               // lengths of en and cn sentences being considered

  double loglike;
  char mode;              // [t]raining, [v]iterbi parsing, [d]ecoding
  int MAXT, MAXV;         // max permissible sentence lengths

  double pi;              // sentence probability (for parsing and training);

  int _sentno;            // current sentence number

  string runid;
  char runmode;

  timeval start, finish;

  ITGGrammar* grammar;
  ITGCorp* corpus;

  int _verb;  // verbosity

  Cell* topcell_; // the top cell after decoding, parsing, training

/*   FeatureList weights_; // for discriminative parsing */

  //rules: the file name of the grammar
  //probs: the file name of the probabilities table
  //langmodel: the file of the language model
  //runid: the id of this run
  //mt: maximum length of lang 1
  //mv: maximum length of lang 2
  //vt: viterbi output trigger
  ITG(ITGGrammar* igrammar, ITGCorp* _corpus) {
    corpus = _corpus;

    grammar = igrammar;

    runid = Globals::Get<string>("runid");

    _verb = Globals::Get<int>("verbosity");

    //vtrue=vt;
    mode = runmode;

    MAXT = DEFAULTMAXT;
    MAXV = DEFAULTMAXV;

    _sentno = 0;

    loglike = 0;
    pi = 0.0;
  }

  virtual ~ITG() { }

  int readin(ITGCorp *corp);  // default impl used by parsing and training
  virtual void run() = 0;
};

#endif

