#ifndef DECODER_UTILS_H_ #define DECODER_UTILS_H_ #include #include "path_trie.h" template bool pair_comp_first_rev(const std::pair &a, const std::pair &b) { return a.first > b.first; } template bool pair_comp_second_rev(const std::pair &a, const std::pair &b) { return a.second > b.second; } template T log_sum_exp(const T &x, const T &y) { static T num_min = -std::numeric_limits::max(); if (x <= num_min) return y; if (y <= num_min) return x; T xmax = std::max(x, y); return std::log(std::exp(x-xmax) + std::exp(y-xmax)) + xmax; } //------------------------------------------------------- // Overriding less than operator for sorting //------------------------------------------------------- bool prefix_compare(const PathTrie* x, const PathTrie* y); // Get length of utf8 encoding string // See: http://stackoverflow.com/a/4063229 size_t get_utf8_str_len(const std::string& str); std::vector UTF8_split(const std::string &str); void add_word_to_fst(const std::vector& word, fst::StdVectorFst* dictionary); bool add_word_to_dictionary(const std::string& word, const std::unordered_map& char_map, bool add_space, int SPACE, fst::StdVectorFst* dictionary); #endif // DECODER_UTILS_H