/* ngram.h
 *
 * $Id: ngram.h,v 1.2 2011/10/17 13:17:08 gildea Exp $
 */

#ifndef NGRAM_H
#define NGRAM_H

#include <string>
#include "globals.h"

/* #include <google/sparse_hash_map> */
/* using GOOGLE_NAMESPACE::sparse_hash_map; */

class NGram {
public:
  NGram(int _N0 = 2) : N(_N0) { loaded = false; }
  void load(string);
  double prob(WORDTYPE*);
  
  double trigram(WORDTYPE, WORDTYPE, WORDTYPE);
  double bigram(WORDTYPE, WORDTYPE);
  double unigram(WORDTYPE);

  int uninonz(int n);
  int binnonz(int m, int n);        // true if bigram(m,n) exists
  int biwnonz(int m, int n);
  int trinonz(int l, int m, int n); // true if trigram(l,m,n) exists

  int N;
  string lmfile;

  bool loaded;

//   struct unigram_table : sparse_hash_map<WORDTYPE, double, hash<int>, eqint> {};
  typedef hash_map <WORDTYPE, double> unigram_table;
  typedef hash_map <WORDTYPE, unigram_table> bigram_table;
  typedef hash_map <WORDTYPE, bigram_table> trigram_table;

  unigram_table unigram_tbl, unigram_w_tbl;
  bigram_table bigram_tbl, bigram_w_tbl;
  trigram_table trigram_tbl;
};

#endif
