// file: create_mixtures.h
//
// definitions file for the utility that initializes triphones using a
// clustered phone list and context-independent phones related material
//

// make sure definitions are made only once
//
#ifndef __ISIP_TIE_STATE
#define __ISIP_TIE_STATE

// isip include files
//
#ifndef __ISIP_INTEGRAL
#include <integral.h>
#endif

// forward declaration of classes
//
#ifndef __ISIP_STATE
#include <state.h>
#endif

#ifndef __ISIP_HASH_CELL
#include <hash_cell.h>
#endif

#ifndef __ISIP_HASH_TABLE
#include <hash_table.h>
#endif

#ifndef __ISIP_MEMORY_MANAGER
#include <memory_manager.h>
#endif

#ifndef __ISIP_LINK_LIST
#include <link_list.h>
#endif

#ifndef __ISIP_QUESTION
#include <question.h>
#endif

#ifndef __ISIP_DECISION_TREE
#include <decision_tree.h>
#endif

#ifndef __ISIP_DT_NODE
#include <dt_node.h>
#endif

#ifndef __ISIP_CD_MODEL
#include <cd_model.h>
#endif

// functions to decipher commandline
//
logical_1 read_cmdline_cc(int_4 argc, char_1** argv, char_1* in_file);

// i/o methods
//
// function to read parameter file
//
logical_1 read_params_cc(char_1* params_file, char_1*& in_models_file,
			 char_1*& out_models_file, char_1*& in_states_file,
			 char_1*& out_states_file, char_1*& monophone_file,
			 char_1*& membership_file, char_1*& occupancy_file,
			 char_1*& out_tree_file, char_1*& in_tree_file,
			 char_1*& in_phlist_file, char_1*& out_clist_file,
			 char_1*& special_models_file_a,
			 float_4& split_threshld, float_4& merge_threshld,
			 float_4& num_occ_threshld, int_4& num_context,
			 logical_1& mode, logical_1& output_mode,
			 int_4& debug_level);


// function to read monophone file, question file etc.
//
char_1** read_monophones_cc(int_4& num_mono, char_1* monophone_file);

// read membership file, set answers and questions
//
logical_1 read_answers_cc(FILE* fpq, Hash_table*& answers,
                          char_1** mono, int_4 num_mono);

logical_1 read_questions_cc(int_4& num_questions, Question**& questions,
			    FILE* fpq);

// functions to read states file and occupancy 
//
State** read_states_cc(int_4& num_st, int_4& num_feat, char_1* state_file);
logical_1 read_occupancy_cc(float_4*& occupancy, int_4 num_states,
			    int_4 num_mixture, char_1* occupancy_file);

// function to read models file and set states and context to the root nodes
//
logical_1 pool_states_cc(FILE* fpm, State** old_states, char_1** mono,
			 int_4 num_mono, int_4& num_cd_models,
			 Cd_model**& cd_models, Decision_tree**& trees,
			 int_4& num_trees, State**& new_states, 
			 int_4* trans_map, int_4& num_special_st,
			 int_4 num_special_model, char_1** special_models,
			 int_4 ph_size, logical_1 mode, int_4 state_num);

logical_1 pool_context_cc(FILE* fpm_in, int_4 num_states,
			  int_4 num_context, char_1** mono,
                          int_4 num_mono, int_4**& l_context,
			  int_4**& r_context);


// split and merge tree methods
//
logical_1 split_tree_cc(Decision_tree* decision_tree,
			Question** questions, Hash_table* answers,
			State** states, float_4* occupancy, 
			int_4** l_context, int_4** r_context,
			float_4 split_threshd, float_4 num_st_threshd,
			int_4 num_questions, int_4 num_featurs,
			int_4 num_mixtures, int_4 debug_level);

logical_1 merge_tree_cc(Decision_tree* decision_tree, 
			Question** questions, Hash_table* answers,
			State** states, float_4* occupancy, 
			int_4** l_context, int_4** r_context,
			float_4 merge_threshd, 
			int_4 num_featurs, int_4 num_mixtures,
			int_4 debug_level);

logical_1 index_tree_cc(Link_list* leaf_list, int_4& label,
			State** new_states, State** states,
			float_4* occupancy, int_4 num_features,
			int_4 num_mixtures);


// read / write decision_tree method
//
logical_1 read_trees_cc(Decision_tree**& decision_trees, int_4& num_trees,
			Question***& questions, int_4*& num_questions,
			FILE* fp_in);

logical_1 write_trees_cc(Decision_tree** trees, int_4 num_trees,
			FILE* fp_dt);


// write model method
//
logical_1 write_models_cc(FILE* fp_out_model, int_4 num_mono,
			  char_1** monophones, int_4 num_models,
			  int_4* trans_map, Decision_tree** trees,
			  int_4** l_context, int_4** r_context,
			  int_4* ph_map, int_4* num_states);


logical_1 write_cd_models_cc(FILE* fp_out_model, int_4 num_mono,
			     char_1** mono, int_4 num_models,
			     Cd_model** cd_models, int_4 num_cd_models,
			     int_4* trans_map, Hash_table* table);

logical_1 write_clist_cc(FILE* fp_out_clist, Hash_table*& phy_models,
			 int_4& num_phy_model, Cd_model** cd_models,
			 int_4 num_cd_models, int_4 phone_size);

// print methods
//
logical_1 print_model_cc(FILE* fp_state, State* state);

logical_1 print_state_cc(char_1* file, State** states, int_4 num_st,
                         int_4 num_feat, logical_1 output_mode);

logical_1 print_bin_state_cc(char_1* file, State** states, int_4 num_st,
                             int_4 num_feat);

logical_1 print_ascii_state_cc(char_1* file, State** states, int_4 num_st,
                               int_4 num_feat);

// map the central phone index and state position to the decision tree
// index
//
int_4 map_tr_index_cc(int_4 cph_index, int_4 num_special_model, int_4 st_pos);

// set the Cd_model list given the phone list and decision trees 
//
logical_1 pool_phones_cc(FILE* fp_phlist, char_1** mono, int_4 num_mono,
			 int_4& num_cd_models, Cd_model**& cd_models,
			 Decision_tree** trees, char_1** special_ph,
			 int_4 ph_size, int_4 num_states,
			 int_4 num_special_model, char_1** special_models,
			 Hash_table* answers);

// update the state index by asking questions with decision trees
//
logical_1 update_models_cc( char_1** mono, int_4 num_mono, 
			    int_4 num_cd_models, Cd_model**& cd_models,
			    int_4 num_spe_models, char_1** special_models,
			    Decision_tree** trees, int_4 ph_size,
			    Hash_table* answers);
  
// miscellaneous methods
//
logical_1 expand_filename_cc(char_1*& fname);

// read special models method
//
char_1** read_spm_cc(int_4& num_spm, FILE* fp_spm);

// method to get number of trees
//
int_4 get_num_trees_cc(int_4 num_mono, int_4 num_spe_mono, int_4 num_state);

// end of file
//
#endif








