37 #include <unordered_map> 40 "Single non-white-space character delimiter inside sequences of " 41 "feature symbols and output symbols");
43 "Special symbol that designates an empty sequence");
45 DEFINE_string(start_symbol,
"<s>",
"Start of sentence symbol");
49 "Treat input model as a classifier instead of a tagger");
55 return FST_FLAGS_delimiter.size() == 1 &&
56 !std::isspace(FST_FLAGS_delimiter[0]);
60 bool okay = !FST_FLAGS_empty_symbol.empty();
61 for (
size_t i = 0; i < FST_FLAGS_empty_symbol.size(); ++i) {
62 char c = FST_FLAGS_empty_symbol[i];
63 if (std::isspace(c)) okay =
false;
69 const std::string &epsilon_symbol,
70 const std::string &unknown_symbol,
const std::string &vocab,
71 char **models,
int models_len,
const std::string &out,
72 const std::string &save_isymbols,
73 const std::string &save_fsymbols,
74 const std::string &save_osymbols) {
76 models_len, out, save_isymbols, save_fsymbols,
78 Apply<Operation<LinearCompileArgs>>(
"LinearCompileTpl", arc_type, &args);
85 std::istringstream strm(str);
87 while (strm >> buf) out->push_back(buf);
91 std::set<std::string, std::less<>> preds;
92 for (
int i = 0; i < models_len; ++i) {
93 std::ifstream in(models[i]);
94 if (!in)
LOG(FATAL) <<
"Failed to open " << models[i];
96 std::getline(in, line);
98 while (std::getline(in, line)) {
100 std::vector<std::string> fields;
102 if (fields.size() != 3)
103 LOG(FATAL) <<
"Wrong number of fields in source " << models[i]
104 <<
", line " << num_line;
105 preds.insert(fields[1]);
void SplitByWhitespace(const std::string &str, std::vector< std::string > *out)
REGISTER_FST_OPERATION_3ARCS(Compress, CompressArgs)
std::tuple< const std::string &, const std::string &, const std::string &, char **, int, const std::string &, const std::string &, const std::string &, const std::string & > LinearCompileArgs
DEFINE_string(delimiter,"|","Single non-white-space character delimiter inside sequences of ""feature symbols and output symbols")
bool ValidateEmptySymbol()
int ScanNumClasses(char **models, int models_len)
void LinearCompile(const std::string &arc_type, const std::string &epsilon_symbol, const std::string &unknown_symbol, const std::string &vocab, char **models, int models_len, const std::string &out, const std::string &save_isymbols, const std::string &save_fsymbols, const std::string &save_osymbols)
DEFINE_bool(classifier, false,"Treat input model as a classifier instead of a tagger")
void LinearCompileTpl(LinearCompileArgs *args)