// file: $isip/util/speech/isip_lm_converter/isip_lm_converter.h
//

// make sure the file is included only once
//
#ifndef ISIP_LM_CONVERTER
#define ISIP_LM_CONVERTER

// isip include files
//
#include <CommandLine.h>
#include <Vector.h>
#include <String.h>
#include <File.h>

// local methods
//
boolean modelToModel(Filename& input_file_name, Filename& output_file_name,
		     LanguageModel::ALGORITHM out_format,
		     File::TYPE out_type,
		     Boolean minimize);

boolean nativeToModel(Filename& input_file_name, Filename& output_file_name,
		      Filename& output_sm_file,
		      LanguageModel::ALGORITHM out_format,
		      File::TYPE out_type);

boolean modelToNative(Filename& input_file_name, Filename& output_file_name);


boolean isOldDigraph(Filename& input_file_name);

boolean loadOldDigraph(Filename& input_file_name, HierarchicalDigraph& h_digraph);

boolean readHashTable(Filename& input_file_name,
		      HashTable<String, String>& hash_table);

boolean readSearchLevel(HierarchicalDigraph& search_level, long level,
			HashTable<String, String>& hash_table,
			String& prefix);

boolean readSMSymbols(Vector<SearchSymbol>& sm_symbols,
		      HashTable<String, String>& hash_table, String& prefix);

boolean readSubGraph(SearchLevel& search_level,
		     DiGraph<SearchNode>& sub_graph,
		       HashTable<String, String>& hash_table, String& prefix);

boolean readVertices(SearchLevel& search_level,
		     DiGraph<SearchNode>& sub_graph,
		     SingleLinkedList<GraphVertex<SearchNode> >&
		     vertices_list,
		     HashTable<String, String>& hash_table, String& prefix);

boolean detectSelfLoop(SearchLevel& search_level,
		       DiGraph<SearchNode>& sub_graph,
		 SingleLinkedList<SingleLinkedList<GraphVertex<SearchNode> > >&
		       vertices_list,
		       HashTable<String, String>& hash_table, String& prefix);

boolean readArcs(DiGraph<SearchNode>& sub_graph,
		 SingleLinkedList<SingleLinkedList<GraphVertex<SearchNode> > >&
		 vertices_list,
		 HashTable<String, String>& hash_table, String& prefix);

boolean readSymbols(Vector<SearchSymbol>& symbol_list,
		    HashTable<String, String>& hash_table,
		    String& size_prefix, String& prefix);

boolean storeSearchLevel(SearchLevel& search_level,
			HashTable<String, String>& hash_table,
			 Vector<SearchSymbol>& graph_name, String& prefix);

boolean storeSubGraph(SearchLevel& search_level,
		      DiGraph<SearchNode>& sub_graph,
		      HashTable<String, String>& hash_table, String& prefix);

boolean storeVertex(GraphVertex<SearchNode>& vertex,
		    DiGraph<SearchNode>& sub_graph,
		    HashTable<String, String>& hash_table, long& numrcs,
		    Vector<Long>& y_index, long x_index, String& prefix);

boolean storeArc(long& arc_index, long from_index, long to_index,
		 GraphArc<SearchNode>*& arc,
		 HashTable<String, String>& hash_table, String& prefix);

boolean storeSymbols(Vector<SearchSymbol>& symbol_list,
		     HashTable<String, String>& hash_table, String size_prefix,
		     String& prefix);

long indexOf(DiGraph<SearchNode>& sub_graph, GraphVertex<SearchNode>* vertex);

boolean writeHashTable(HashTable<String, String>& hash_table, String& output,
		       String description);

boolean writeHashTable(HashTable<String, String>& hash_table, File& output,
		       String description);

boolean convertContextMapping(Vector<ContextMap>& context_map,
			      Vector<SearchSymbol>& context_symbol);
boolean convertContextMapping(Vector<SearchSymbol>& context_symbol,
			      Vector<ContextMap>& context_map);

// constants
//
static const String PROG_NAME(L"isip_network_converter");
static const String LEVEL_TREE_TOP_GRAMMAR(L"sentence");

static const String START_VERTEX_NAME(L"Start");
static const String TERM_VERTEX_NAME(L"Stop");
static const String NODE_VERTEX_NAME(L"Node");

static const String OPTION_INPUT_FORMAT(L"input_format");
static const String OPTION_OUTPUT_FORMAT(L"output_format");
static const String OPTION_OUTPUT_TYPE(L"output_type");
static const String OPTION_DUMMY_SYMBOL(L"dummy_symbol");
static const String OPTION_DEBUG_LEVEL(L"debug_level");
static const String OPTION_MINIMIZE(L"minimize");

static const String PARAM_SEARCH_SYMBOL(L"search_symbols");

static const String EMPTY(String::NULL_STRING);
static const Integral::DEBUG DEBUG_LEVEL_DEFAULT=Integral::NONE;
static DebugLevel debug_level = Integral::NONE;

static const String COMMENT_CHAR(L"#");
static const String DELIMITER_CHAR(L"=");

// all io constants
//
static const long START_VERTEX = 0;
static const long TERM_VERTEX = 1;
static const long NODE_VERTEX = 2;

static const int VERTEX_WIDTH = 70;    
static const int VERTEX_HEIGHT = 48;

static const int VERTEX_INITIAL_X = 100;    
static const int VERTEX_INITIAL_Y = 100;

static const int VERTEX_OFFSET_X = 140;    
static const int VERTEX_OFFSET_Y = 140;


// search level tags
//
static const String DEF_DUMMY_SYMBOL(L"!null");
static const String IO_CDATA_LEVEL_SIZE(L"level_size");

static const String IO_LEVEL_NAME(L"_name");
static const String IO_LEVEL_GRAPH_SIZE(L"_graph_size");
static const String IO_LEVEL_GRAPH_NAME(L"_graph_name");
static const String IO_LEVEL_SYMBOL_SIZE(L"_symbol_size");
static const String IO_LEVEL_SYMBOL(L"_symbol_");
static const String IO_LEVEL_CONTEXT_SIZE(L"_context_size");
static const String IO_LEVEL_CONTEXT(L"_context_");
static const String IO_LEVEL_NON_SPEECH_SYMBOL_SIZE(L"_non_speech_symbol_size");
static const String IO_LEVEL_NON_SPEECH_SYMBOL(L"_non_speech_symbol_");
static const String IO_LEVEL_CONTEXTLESS_SYMBOL_SIZE(L"_contextless_symbol_size");

static const String IO_LEVEL_NON_SPEECH_BOUNDARY_SYMBOL_SIZE(L"_non_speech_boundary_symbol_size");
static const String IO_LEVEL_NON_SPEECH_BOUNDARY_SYMBOL(L"_non_speech_boundary_symbol_");

static const String IO_LEVEL_NON_SPEECH_INTERNAL_SYMBOL_SIZE(L"_non_speech_internal_symbol_size");
static const String IO_LEVEL_NON_SPEECH_INTERNAL_SYMBOL(L"_non_speech_internal_symbol_");

static const String IO_LEVEL_SPENALTY_EXCLUDE_SYMBOL_SIZE(L"_spenalty_exclude_symbol_size");
static const String IO_LEVEL_SPENALTY_EXCLUDE_SYMBOL(L"_spenalty_exclude_symbol_");
static const String IO_LEVEL_CONTEXTLESS_SYMBOL(L"_contextless_symbol_");
static const String IO_LEVEL_DUMMY_SYMBOL(L"_dummy_symbol_");
static const String IO_LEVEL_DUMMY_SYMBOL_SIZE(L"_dummy_symbol_size");
static const String IO_LEVEL_SKIP_SYMBOL(L"_skip_symbol_");
static const String IO_LEVEL_SKIP_SYMBOL_SIZE(L"_skip_symbol_size");
static const String IO_LEVEL_EXCLUDE_SYMBOL(L"_exclude_symbol_");
static const String IO_LEVEL_EXCLUDE_SYMBOL_SIZE(L"_exclude_symbol_size");
static const String IO_LEVEL_SM_SYMBOL(L"_ST_symbol_");
static const String IO_LEVEL_SM_SYMBOL_SIZE(L"_ST_symbol_size");

// graph tags
//
static const String IO_DIGRAPH_VERTEX_SIZE(L"_vertex_size");
static const String IO_DIGRAPH_ARC_SIZE(L"_arc_size");

// vertex tags
//
static const String IO_VERTEX_SYMBOL_SIZE(L"_symbol_size");
static const String IO_VERTEX_NAME(L"_name");
static const String IO_VERTEX_TYPE(L"_type");
static const String IO_VERTEX_WIDTH(L"_width");
static const String IO_VERTEX_HEIGHT(L"_height");
static const String IO_VERTEX_LOC_X(L"_loc_x");
static const String IO_VERTEX_LOC_Y(L"_loc_y");
static const String IO_VERTEX_SYMBOL(L"_S");
    
// arc tags
//
static const String IO_ARC_FROM_ID(L"_from");
static const String IO_ARC_TO_ID(L"_to");
static const String IO_ARC_WEIGHTS(L"_weight");
static const String IO_ARC_EPSILON(L"_epsilon");
static const String IO_ARC_WIDTH(L"_width");
static const String IO_ARC_HEIGHT(L"_height");
static const String IO_ARC_LOC_X(L"_loc_x");
static const String IO_ARC_LOC_Y(L"_loc_y");

// prefix tags
//
static const String IO_SEARCHLEVEL_PREFIX(L"L");
static const String IO_DIGRAPH_PREFIX(L"G");
static const String IO_VERTEX_PREFIX(L"V");
static const String IO_ARC_PREFIX(L"A");

// global variables
//
static String dummy_symbol_g = DEF_DUMMY_SYMBOL;
boolean dummy_check;

// end of file
//
#endif
