name: SearchLevel
synopsis:

>     g++ [flags ...] file ... -l /isip/tools/lib/$ISIP_BINARY/lib_search.a

>     #include <SearchLevel.h>

>     SearchLevel();
>     SearchLevel(const SearchLevel& copy_slev);

>     boolean loadSymbols(Sof& sof, long tag = DEF_TAG);
>     boolean loadSubGraphs(Sof& sof, long tag = DEF_TAG);

>     boolean setLevelIndex(long num);
>     boolean setNumSubGraphs(long num);
>     DiGraph<SearchNode>& getSubGraph(long index);

>     boolean setBeam(boolean use_beam_prune = DEF_BEAM_PRUNE, float beam_threshold = DEF_BEAM_THRESHOLD)
>     boolean useBeam() const;

>     boolean setSymbolTable(Vector<SearchSymbol>& symbol_list);
>     long getSymbolIndex(const SearchSymbol& input_symbol) const;
>     boolean getSymbol(SearchSymbol& output_symbol, long index) const;
>     boolean isValidSymbol(long index) const;

quick start:

>     SearchLevel search_level;

>     // configure SearchLevel
>     //
>     Sof model_sof;
>     model_sof.open(L"model.sof");
>     long num_levels = 3;
>     search_engine.setNumLevels(num_levels);

>     // read models
>     //
>     for (long curr_level = 0; curr_level < num_levels; curr_level++) {
>        SearchLevel& level = search_engine.getSearchLevel(curr_level);
>        level.load(model_sof);
>     }

description:
SearchLevel class represents a particular level in the search hierarchy for a hierarchical search engine. Each level has the following characteristics:

- beam pruning threshold
- instance pruning threshold
- ability to hold context-dependent models with arbitrary left and right contexts
- ability to hold N-symbol context probabilities with arbitrary left contexts + backoffs
- maintain or discard old search tokens. For instance, once a higher level symbol is completed, it may no longer necessary to maintain the lower level units that generated that symbol.

dependencies:

- SearchSymbol
- DiGraph
- NameMap
- HashTable
- String
- Boolean
- Float
- Long
- SearchNode
- Context

public constants:

- define class name:

      static const String CLASS_NAME;

- define i/o constants:

      static const String DEF_PARAM;

      static const String PARAM_DELIM1;

      static const String PARAM_DELIM2;

      static const String PARAM_DELIM3;

      static const String PARAM_LEVEL_TAG;

      static const String PARAM_SYMBOL;

      static const String PARAM_NONSPEECH_SYMBOL;

      static const String PARAM_DUMMY_SYMBOL;

      static const String PARAM_EXCLUDE_SYMBOL;

      static const String PARAM_CONTEXTLESS_SYMBOL;

      static const String PARAM_SKIP_SYMBOL;

      static const String PARAM_MODEL;

      static const String PARAM_STAT_HASH;

      static const String PARAM_STAT;

      static const String PARAM_STAT_OCCUPANCY;

      static const String PARAM_USE_NSYMBOL;

      static const String PARAM_NSYMBOL_ORDER;

      static const String PARAM_LM_SCALE;

      static const String PARAM_TR_SCALE;

      static const String PARAM_SYMBOL_PENALTY;

      static const String PARAM_NSYMBOL_MODEL;

      static const String PARAM_USE_CONTEXT;

      static const String PARAM_CONTEXT_MAPPING;

      static const String PARAM_USE_LEXICAL_TREE;

      static const String PARAM_LEFT_CONTEXT_LENGTH;

      static const String PARAM_RIGHT_CONTEXT_LENGTH;

      static const String PARAM_USE_BEAM;

      static const String PARAM_BEAM_THRESHOLD;

      static const String PARAM_USE_INSTANCE;

      static const String PARAM_INSTANCE_THRESHOLD;

      static const String PARAM_WRITE_SYMBOL_OCCUPANCY;

      static const String PARAM_SYMBOL_OCCUPANCY_FILE;

      static const String PARAM_NON_ADAPT_SYMBOL;

- define default constants:

      static const long DEF_TAG = -1;

      static const long DEF_LEVEL_INDEX = 0;

      static const boolean DEF_BEAM_PRUNE = false;

      static const float DEF_BEAM_THRESHOLD = 300.0;

      static const boolean DEF_INSTANCE_PRUNE = false;

      static const long DEF_INSTANCE_THRESHOLD = 3000;

      static const boolean DEF_USE_CONTEXT = false;

      static const boolean DEF_USE_LEXICAL_TREE = false;

      static const long DEF_LEFT_CONTEXT = 0;

      static const long DEF_RIGHT_CONTEXT = 0;

      static const boolean DEF_USE_NSYMBOL = false;

      static const long DEF_NSYMBOL_ORDER = 1;

      static const float DEF_SYMBOL_PENALTY = 0.0;

      static const float DEF_LM_SCALE = 1.0;

      static const float DEF_TR_SCALE = 1.0;

      static const boolean DEF_WRITE_SYMBOL_OCCUPANCY = false;

error codes:

- error code indicating a general error:

      static const long ERR = 90800;

protected data:

- define the level number:

      Long level_index_d;

- define the level tag:

      String level_tag_d;

- symbols at this level, eg. if this is word level, symbols are all the words if phone level, symbols are all the phones:

      Vector<SearchSymbol> symbol_table_d;

- non-speech symbols at this level, symbols that are inserted between each symbol in the training process:

      Vector<SearchSymbol> nonspeech_symbol_table_d;

- dummy symbols at this level, symbols that act as mere place holders in the decoding process:

      Vector<SearchSymbol> dummy_symbol_table_d;

- exclude symbols at this level, symbols that act as mere place holders in the decoding process:

      Vector<SearchSymbol> exclude_symbol_table_d;

- context less symbols at this level, symbols that are context-independent throughout the decoding process:

      Vector<SearchSymbol> contextless_symbol_table_d;

- skip symbols at this level, symbols that are context-independent and cannot be a context for any other symbol:

      Vector<SearchSymbol> skip_symbol_table_d;

- non adapt symbols at this level, symbols that will not be adapted during the statistical model adaptation

      Vector<SearchSymbol> non_adapt_symbol_table_d;

- symbol to statistical model mapping at this level, hashtable of symbol and its index in the stat_models_d this is for finding the index of a statistical model (value) corresponding to a symbol (key):

      HashTable<SearchSymbol, Long> symbol_hash_d;

- statistical models at this level, statistical modesl have a unique index that can be cross referenced via the hashtable of symbol symbol_hash_d:

      Vector<StatisticalModel> stat_models_d;

- subgraph of the symbols at this level, if this is the word level, the sub_graphs will be the phone network(s), if this is the phone level, the sub_graphs will be the HMM(s):

      Vector<DiGraph<SearchNode> > sub_graphs_d;

- variables related to evaluation of n-symbol probabilities at this level, order 1 is equivalent to prob{Symbol(n)} order 2 is equivalent to prob{Symbol(n) | Symbol(n-1)} order 3 is equivalent to prob{Symbol(n) | Symbol(n-1), Symbol(n-2)} likewise for orders 4, 5, 6, ..., N:

      Boolean use_nsymbol_d;

      Long nsymbol_order_d;

- member variable that computes the n-symbol probability of a sequence:

      Filename nsymbol_file_d;

      NGramModel nsymbol_model_d;

- member variables related to the scale and symbol insertion penalty:

      Float tr_scale_d;

      Float lm_scale_d;

      Float symbol_penalty_d;

- variables related to context dependency at this level, member variables related to generation of context-dependent expansion of models for evaluation:

      Boolean use_context_d;

      Long left_context_d;

      Long right_context_d;

- member variable that associates a context with a subgraph index:

      Vector<ContextMap> context_map_d;

      HashTable<Context, Ulong> context_hash_d;

- member variables related to generation of lexical tree expansion of models for evaluation:

      Boolean use_lexical_tree_d;

- variables related to prunning at this level at this level, member variables related to beam pruning. if the flag is set to true, beam pruning will be employed at this level with the given beam threshold:

      Boolean use_beam_prune_d;

      Float beam_threshold_d;

- member variables related to instance pruning. if the flag is set to true, instance pruning will be employed at this level with only the given number of instances maintained.:

      Boolean use_instance_prune_d;

      Long instance_threshold_d;

- member variable related to symbol occupancies. the symbol occupancies will be written to the file only when the flag is true:

      Filename symbol_occupancy_file_d;

      Boolean write_symbol_occupancy_d;

- declare the debugging parameters:

      static Integral::DEBUG debug_level_d;

- declare the memory manager:

      static MemoryManager mgr_d;

required public methods:

- static methods:

      static const String& name();

- debug methods:

      static boolean diagnose(Integral::DEBUG debug_level);

      boolean debug(const unichar* message) const;

      static boolean setDebug(Integral::DEBUG debug_level);

- destructor/constructor(s):

      ~SearchLevel();

      SearchLevel();

      SearchLevel(const SearchLevel& copy_level);

- assign methods:

      boolean assign(const SearchLevel& copy_level);

- operator= method:

      not present.

- i/o methods:

      long sofSize() const;

      boolean read(Sof& sof, long tag, const String& cname = CLASS_NAME);

      boolean write(Sof& sof, long tag, const String& cname = CLASS_NAME) const;

      boolean readData(Sof& sof, const String& pname = DEF_PARAM, long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false);

      boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const;

- equality methods:

      boolean eq(const SearchLevel& compare_level) const;

- memory management methods:

      static void* operator new(size_t size);

      static void* operator new[](size_t size);

      static void operator delete(void* ptr);

      static void operator delete[](void* ptr);

      static boolean setGrowSize(long grow_size);

      boolean clear(Integral::CMODE ctype = Integral::DEF_CMODE);

class-specific public methods:

- declare search level load methods:

      boolean load(Sof& sof, long tag = DEF_TAG);

      boolean loadLevelTag(Sof& sof, long tag = DEF_TAG);

      boolean loadSymbols(Sof& sof, long tag = DEF_TAG);

      boolean loadNonSpeechSymbols(Sof& sof, long tag = DEF_TAG);

      boolean loadContextLessSymbols(Sof& sof, long tag = DEF_TAG);

      boolean loadSkipSymbols(Sof& sof, long tag = DEF_TAG);

      boolean loadDummySymbols(Sof& sof, long tag = DEF_TAG);

      boolean loadExcludeSymbols(Sof& sof, long tag = DEF_TAG);

      boolean loadSubGraphs(Sof& sof, long tag = DEF_TAG);

      boolean loadStatisticalModels(Sof& sof, long tag = DEF_TAG);

      boolean loadAccumulators(Sof& sof, long tag = DEF_TAG);

      boolean loadContextMapping(Sof& sof, long tag = DEF_TAG);

      boolean loadNSymbolModel(Sof& sof, long tag = DEF_TAG);

      boolean loadOccupancies();

- declare search level store methods:

      boolean store(Sof& sof, long tag = DEF_TAG);

      boolean storeLevelTag(Sof& sof, long tag = DEF_TAG);

      boolean storeSymbols(Sof& sof, long tag = DEF_TAG);

      boolean storeNonSpeechSymbols(Sof& sof, long tag = DEF_TAG);

      boolean storeContextLessSymbols(Sof& sof, long tag = DEF_TAG);

      boolean storeSkipSymbols(Sof& sof, long tag = DEF_TAG);

      boolean storeDummySymbols(Sof& sof, long tag = DEF_TAG);

      boolean storeExcludeSymbols(Sof& sof, long tag = DEF_TAG);

      boolean storeNonAdaptSymbols(Sof& sof, long tag = DEF_TAG);

      boolean storeSubGraphs(Sof& sof, long tag = DEF_TAG);

      boolean storeStatisticalModels(Sof& sof, long tag = DEF_TAG);

      boolean storeAccumulators(Sof& sof, long tag = DEF_TAG);

      boolean storeContextMapping(Sof& sof, long tag = DEF_TAG);

      boolean storeOccupancies();

- declare search level get/set methods:

      String& getLevelTag() const;

      boolean setLevelTag(String& tag);

- declare search level penalty and scale methods:

      float getLmScale() const;

      boolean setLmScale(float scale);

      float getTrScale() const;

      boolean setTrScale(float scale);

      float getSymbolPenalty() const;

      boolean setSymbolPenalty(float penalty);

- declare search level sub-graph methods:

      long getNumSubGraphs();

      boolean setNumSubGraphs(long num);

      Vector<DiGraph<SearchNode> >& getSubGraphs();

      boolean setSubGraphs(Vector<DiGraph<SearchNode> >& sub_graphs);

      DiGraph<SearchNode>& getSubGraph(long index);

      boolean setSubGraph(long index, DiGraph<SearchNode>& arg);

      boolean convertDigraphs(Vector< DiGraph<Ulong> > digraphs);

      Vector< DiGraph<Ulong> > convertSubgraphs();

- declare search level symbol hash methods:

      HashTable<SearchSymbol, Long>& getSymbolHashTable();

      boolean setSymbolHashTable(HashTable<SearchSymbol, Long>& arg);

- declare search level index methods:

      long getSymbolIndex(const SearchSymbol& input_symbol) const;

      long getLevelIndex() const;

      boolean setLevelIndex(long num);

- declare search level beam pruning methods:

      boolean setBeam(float beam_threshold);

      boolean setBeam(boolean use_beam_prune = DEF_BEAM_PRUNE, float beam_threshold = DEF_BEAM_THRESHOLD);

      boolean useBeam() const;

      float getBeamThreshold() const;

- declare search level instance methods:

      boolean setInstance(boolean use_instance_prune = DEF_INSTANCE_PRUNE, long instance_threshold = DEF_INSTANCE_THRESHOLD);

      boolean setInstance(long instance_threshold);

      boolean useInstance() const;

      long getInstanceThreshold() const;

- declare search level context related methods:

      boolean generateContextMapping(long left_order, long right_order, Filename& context_list, Vector<SearchLevel>& search_levels);

      boolean createCopy(SearchSymbol& central_symbol, ContextMap& context_map, Vector<SearchLevel>& search_levels);

      boolean parseSymbols(String& symbols_string, Vector<SearchSymbol>& symbols_vec);

      Vector<ContextMap>& getContextMap();

      boolean setContextMap(Vector<ContextMap>& arg);

      boolean setContext(long left_context, long right_context);

      boolean useContext() const;

      long getLeftContext() const;

      long getRightContext() const;

- declare search level lexical tree methods:

      boolean useLexicalTree() const;

- declare search level n-symbol methods:

      boolean setNSymbol(boolean use_nsymbol = DEF_USE_NSYMBOL, long nsymbol_order = DEF_NSYMBOL_ORDER);

      boolean setNSymbol(long nsymbol_order);

      boolean useNSymbol() const;

      long getNSymbolOrder() const;

      NGramModel& getNSymbolModel();

- declare search level symbol table methods:

      boolean setSymbolTable(Vector<SearchSymbol>& symbol_list);

      Vector<SearchSymbol>& getSymbolTable();

      boolean getSymbol(SearchSymbol& output_symbol, long index) const;

      boolean isValidSymbol(long index) const;

- declare search level non-speech symbol methods:

      boolean setNonSpeechSymbolTable(Vector<SearchSymbol>& symbol_list);

      Vector<SearchSymbol>& getNonSpeechSymbolTable();

      boolean isNonSpeechSymbol(long index) const;

- declare search level dummy symbol methods:

      boolean setDummySymbolTable(Vector<SearchSymbol>& symbol_list);

      Vector<SearchSymbol>& getDummySymbolTable();

      boolean isDummySymbol(long index) const;

- declare search level exclude symbol methods:

      boolean setExcludeSymbolTable(Vector<SearchSymbol>& symbol_list);

      Vector<SearchSymbol>& getExcludeSymbolTable();

      boolean isExcludeSymbol(long index) const;

- declare search level no-context symbol methods:

      boolean setContextLessSymbolTable(Vector<SearchSymbol>& symbol_list);

      Vector<SearchSymbol>& getContextLessSymbolTable();

      boolean isContextLessSymbol(long index) const;

- declare search level skip symbol methods:

      boolean setSkipSymbolTable(Vector<SearchSymbol>& symbol_list);

      Vector<SearchSymbol>& getSkipSymbolTable();

      boolean isSkipSymbol(long index) const;

- declare search level statistical model methods:

      Vector<StatisticalModel>& getStatisticalModels();

      boolean setStatisticalModels(long index, StatisticalModel& arg);

      boolean connectStatisticalModels();

- declare search level misc methods:

      boolean writeSymbolOccupancy() const;

      Ulong* getSubGraphIndex(const Context& context);

private methods:

- none.

examples:

- none.

notes:

- none.