// file: $isip/class/stat/NGramModel/ngrm_06.cc
// version: $Id: ngrm_06.cc 8546 2002-08-08 21:53:44Z zheng $
//

// isip include files
//
#include "NGramModel.h"

// method: getScore
//
// arguments:
//  const VectorLong& index: (input) SearchSymbol index sequence
//  
// return: a status 
//
// this method returns the score represented by the ngram give a
// SearchSymbol index sequence
//
boolean NGramModel::getScore(const VectorLong& index_a, float& score_a) {
  
  // define temporary variables used in function
  //
  NGramNode* ngnode = NULL;
  long num = index_a.length();
  VectorLong final_index;
  long i = 0;
  
  // get the correct ngram node
  //
  for (i = 0; i < num; i++) {

    // find the successive nodes
    //
    ngnode = gram_hash_d.get(index_a(i));
    
    // if the ngram word sequences exist
    //
    if (ngnode != NULL) {
      final_index.setLength(final_index.length()+1);
      final_index(final_index.length()-1).assign(index_a(i));
    }
    // if any of these ngram word sequences do not exist
    //
    else{
      // don't allow forms like AXB or AXX
      //
      if ( final_index.length() > 0 ){
	return false;
      }
    }
  } // end for loop

  if ( final_index.length() == 0 ){
    return false;
  }
  
  score_a = getScore(final_index);

  // exit gracefully
  //
  return true;
}
