46 std::string usage =
"Shortest path in a (bounded-stack) PDT.\n\n Usage: ";
48 usage +=
" in.pdt [out.fst]\n";
50 SET_FLAGS(usage.c_str(), &argc, &argv,
true);
56 const std::string in_name =
57 (argc > 1 && (strcmp(argv[1],
"-") != 0)) ? argv[1] :
"";
58 const std::string out_name =
59 (argc > 2 && (strcmp(argv[2],
"-") != 0)) ? argv[2] :
"";
61 std::unique_ptr<FstClass> ifst(FstClass::Read(in_name));
64 if (FST_FLAGS_pdt_parentheses.empty()) {
65 LOG(ERROR) << argv[0] <<
": No PDT parenthesis label pairs provided";
69 std::vector<std::pair<int64_t, int64_t>> parens;
72 VectorFstClass ofst(ifst->ArcType());
75 if (FST_FLAGS_queue_type ==
"fifo") {
77 }
else if (FST_FLAGS_queue_type ==
"lifo") {
79 }
else if (FST_FLAGS_queue_type ==
"state") {
82 LOG(ERROR) <<
"Unknown queue type: " << FST_FLAGS_queue_type;
86 const s::PdtShortestPathOptions opts(
87 qt, FST_FLAGS_keep_parentheses, FST_FLAGS_path_gc);
91 return !ofst.Write(out_name);
void ShowUsage(bool long_usage=true)
void ShortestPath(const FstClass &ifst, const std::vector< std::pair< int64_t, int64_t >> &parens, MutableFstClass *ofst, const PdtShortestPathOptions &opts)
#define SET_FLAGS(usage, argc, argv, rmflags)
int pdtshortestpath_main(int argc, char **argv)
DECLARE_string(queue_type)
DECLARE_bool(keep_parentheses)
bool ReadLabelPairs(std::string_view source, std::vector< std::pair< Label, Label >> *pairs)