// file: $isip/class/search/LexialTree/lex_02.cc
// version: $Id: lex_02.cc 8865 2002-12-05 21:42:54Z alphonso $
//

//isip include files
//
#include "LexicalTree.h"
#include <SearchLevel.h>

// method: diagnose
//
// arguments:
//  Integral::DEBUG level: (input) debug level for diagnostics
//
// return: logical error status
//
// this is the diagnostics method
//
boolean LexicalTree::diagnose(Integral::DEBUG level_a) {

  //----------------------------------------------------------------------
  //
  // 0. preliminaries
  //
  //----------------------------------------------------------------------

  // output the class name
  //
  if (level_a > Integral::NONE) {
    SysString output(L"diagnosing class ");
    output.concat(CLASS_NAME);
    output.concat(L": ");
    Console::put(output);
    Console::increaseIndention();
  }

  //---------------------------------------------------------------------
  //
  // 1. required public methods
  //
  //---------------------------------------------------------------------


  // set indentation
  //
  if (level_a > Integral::NONE) {
    Console::put(L"testing required public methods...\n");
    Console::increaseIndention();
  }

  // declare variables
  //
  LexicalTree lex_00;

  lex_00.setAlgorithm(LexicalTree::UNFACTORED);

  if (lex_00.getAlgorithm() != LexicalTree::UNFACTORED) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }
  
  lex_00.setAlgorithm(LexicalTree::DI_GRAPH);

  if (lex_00.getAlgorithm() != LexicalTree::DI_GRAPH) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }
      
  // reset indentation
  //
  if (level_a > Integral::NONE) {
    Console::decreaseIndention();
  }

  //---------------------------------------------------------------------
  //
  // 2. class-specific public methods
  //
  //---------------------------------------------------------------------

  // set indentation
  //
  if (level_a > Integral::NONE) {
    Console::put(L"testing class-specific public methods...\n");
    Console::increaseIndention(); 
  }

  // first test file
  //
  String model_fn;

  Sof model_sof;

  // testing expand lexical tree
  //
  SearchLevel word_level_3;
  SearchLevel phone_level_3;

  model_fn.assign(L"$ISIP_DEVEL/doc/examples/data/models/lex_02_lm_model.sof");
  model_sof.open(model_fn, File::READ_ONLY, File::TEXT);

  // load word level -- level 0
  //
  word_level_3.loadSymbols(model_sof,0);
  word_level_3.loadSubGraphs(model_sof,0);
  word_level_3.setLevelIndex(0);

  // print the search space
  //
  if (level_a > Integral::BRIEF) {
    word_level_3.debug(L"word_level_3");
  }

  // load the phone level -- level 1
  //
  phone_level_3.loadSymbols(model_sof,1);
  phone_level_3.loadSubGraphs(model_sof,1);
  phone_level_3.setLevelIndex(1);
  
  // print the search space
  //
  if (level_a > Integral::BRIEF) {
    phone_level_3.debug(L"phone_level_3");
  }

  model_sof.close();

  // expand the top level graph to a lexical tree
  //
  LexicalTree::expandLexicalTree(word_level_3.getSubGraph((long)0),
				 phone_level_3.getSubGraphs(),
				 0);
  // print the output
  //
  if (level_a > Integral::BRIEF) {
    word_level_3.getSubGraph((long)0).debug(L"word_level");
  }
  
  // reset indentation
  //
  if (level_a > Integral::NONE) {
    Console::decreaseIndention();
  }
  
  //---------------------------------------------------------------------
  //
  // 4. print completion message
  //
  //---------------------------------------------------------------------

  // reset indentation
  //
  if (level_a > Integral::NONE) {
    Console::decreaseIndention();
  }
  
  if (level_a > Integral::NONE) {
    SysString output(L"diagnostics passed for class");
    output.concat(name());
    output.concat(L"\n");
    Console::put(output);
  }  
  
  // exit gracefully
  //
  return true;
}


