15 #ifndef NLP_GRM2_BAUMWELCH_A_STAR_H_ 16 #define NLP_GRM2_BAUMWELCH_A_STAR_H_ 20 #include <fst/arc-map.h> 21 #include <fst/arcfilter.h> 22 #include <fst/determinize.h> 23 #include <fst/fst-decl.h> 24 #include <fst/queue.h> 25 #include <fst/shortest-distance.h> 26 #include <fst/shortest-path.h> 27 #include <fst/weight.h> 43 float delta = kShortestDelta) {
44 static_assert(!IsPath<typename Arc::Weight>::value,
45 "This procedure is only valid for non-path semirings");
46 using StateId =
typename Arc::StateId;
47 using Weight =
typename Arc::Weight;
48 using PathWeight = TropicalWeightTpl<typename Weight::ValueType>;
49 using PathArc = ArcTpl<PathWeight>;
50 std::vector<Weight> nfa_beta;
51 ShortestDistance(ifst, &nfa_beta,
true);
52 std::vector<Weight> dfa_beta;
53 static const DeterminizeFstOptions<Arc> dopts;
54 const DeterminizeFst<Arc> dfa(ifst, &nfa_beta, &dfa_beta, dopts);
55 VectorFst<PathArc> path_shortest;
57 using MyEstimate = NaturalAStarEstimate<StateId, PathWeight>;
58 using MyQueue = NaturalAStarQueue<StateId, PathWeight, MyEstimate>;
59 using MyArcFilter = AnyArcFilter<PathArc>;
60 using MyShortestPathOptions =
61 ShortestPathOptions<PathArc, MyQueue, MyArcFilter>;
62 using ToPathMapper = WeightConvertMapper<Arc, PathArc>;
63 static constexpr ToPathMapper to_mapper;
64 const ArcMapFst path_dfa(dfa, to_mapper);
65 const MyEstimate estimate(
66 reinterpret_cast<const std::vector<PathWeight> &
>(dfa_beta));
67 std::vector<PathWeight> dfa_alpha;
68 MyQueue queue(dfa_alpha, estimate);
69 static constexpr MyArcFilter arc_filter;
70 const MyShortestPathOptions sopts(
77 ShortestPath(path_dfa, &path_shortest, &dfa_alpha, sopts);
80 using FromPathMapper = WeightConvertMapper<PathArc, Arc>;
81 static constexpr FromPathMapper from_mapper;
82 ArcMap(path_shortest, ofst, from_mapper);
87 #endif // NLP_GRM2_BAUMWELCH_A_STAR_H_
void AStarSingleShortestString(const Fst< Arc > &ifst, MutableFst< Arc > *ofst, float delta=kShortestDelta)
size_t ExploredStates(const std::vector< Weight > &distance)