44 std::string usage =
"Finds shortest path(s) in an FST.\n\n Usage: ";
46 usage +=
" [in.fst [out.fst]]\n";
49 SET_FLAGS(usage.c_str(), &argc, &argv,
true);
55 const std::string in_name =
56 (argc > 1 && strcmp(argv[1],
"-") != 0) ? argv[1] :
"";
57 const std::string out_name =
58 (argc > 2 && strcmp(argv[2],
"-") != 0) ? argv[2] :
"";
60 std::unique_ptr<FstClass> ifst(FstClass::Read(in_name));
63 const auto weight_threshold =
64 FST_FLAGS_weight.empty()
65 ? WeightClass::Zero(ifst->WeightType())
66 : WeightClass(ifst->WeightType(), FST_FLAGS_weight);
68 VectorFstClass ofst(ifst->ArcType());
72 LOG(ERROR) <<
"Unknown or unsupported queue type: " 73 << FST_FLAGS_queue_type;
77 const s::ShortestPathOptions opts(
78 queue_type, FST_FLAGS_nshortest, FST_FLAGS_unique,
79 FST_FLAGS_delta, weight_threshold,
84 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)