46 std::string usage =
"Finds shortest path(s) in an FST.\n\n Usage: ";
48 usage +=
" [in.fst [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 const auto weight_threshold =
65 FST_FLAGS_weight.empty()
66 ? WeightClass::Zero(ifst->WeightType())
67 : WeightClass(ifst->WeightType(), FST_FLAGS_weight);
69 VectorFstClass ofst(ifst->ArcType());
73 LOG(ERROR) <<
"Unknown or unsupported queue type: " 74 << FST_FLAGS_queue_type;
78 const s::ShortestPathOptions opts(
79 queue_type, FST_FLAGS_nshortest, FST_FLAGS_unique,
80 FST_FLAGS_delta, weight_threshold,
85 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)
DECLARE_string(queue_type)
bool GetQueueType(std::string_view str, QueueType *queue_type)
int fstshortestpath_main(int argc, char **argv)