// See www.openfst.org for extensive documentation on this weighted // finite-state transducer library. // // Utilities to convert strings into FSTs. #ifndef FST_STRING_H_ #define FST_STRING_H_ #include #include #include #include #include #include #include #include #include #include DECLARE_string(fst_field_separator); namespace fst { enum StringTokenType { SYMBOL = 1, BYTE = 2, UTF8 = 3 }; namespace internal { template bool ConvertSymbolToLabel(const char *str, const SymbolTable *syms, Label unknown_label, bool allow_negative, Label *output) { int64 n; if (syms) { n = syms->Find(str); if ((n == -1) && (unknown_label != kNoLabel)) n = unknown_label; if (n == -1 || (!allow_negative && n < 0)) { VLOG(1) << "ConvertSymbolToLabel: Symbol \"" << str << "\" is not mapped to any integer label, symbol table = " << syms->Name(); return false; } } else { char *p; n = strtoll(str, &p, 10); if (p < str + strlen(str) || (!allow_negative && n < 0)) { VLOG(1) << "ConvertSymbolToLabel: Bad label integer " << "= \"" << str << "\""; return false; } } *output = n; return true; } template bool ConvertStringToLabels(const string &str, StringTokenType token_type, const SymbolTable *syms, Label unknown_label, bool allow_negative, std::vector