20 #ifndef FST_EXPANDED_FST_H_ 21 #define FST_EXPANDED_FST_H_ 23 #include <sys/types.h> 67 if (!hdr.
Read(strm, opts.
source))
return nullptr;
71 LOG(ERROR) <<
"ExpandedFst::Read: Not an ExpandedFst: " << ropts.
source;
77 LOG(ERROR) <<
"ExpandedFst::Read: Unknown FST type \"" << hdr.
FstType()
78 <<
"\" (arc type = \"" << A::Type() <<
"\"): " << ropts.
source;
81 auto *
fst = reader(strm, ropts);
82 if (!
fst)
return nullptr;
89 if (!source.empty()) {
90 std::ifstream strm(std::string(source),
91 std::ios_base::in | std::ios_base::binary);
93 LOG(ERROR) <<
"ExpandedFst::Read: Can't open file: " << source;
108 typename Arc::StateId s) {
119 typename Arc::StateId s) {
125 typename Arc::StateId s) {
137 template <
class Impl,
class FST = ExpandedFst<
typename Impl::Arc>>
140 using Arc =
typename FST::Arc;
156 return Impl::Read(strm, opts);
161 static Impl *
Read(std::string_view source) {
162 if (!source.empty()) {
163 std::ifstream strm(std::string(source),
164 std::ios_base::in | std::ios_base::binary);
166 LOG(ERROR) <<
"ExpandedFst::Read: Can't open file: " << source;
180 if (std::optional<typename Arc::StateId> num_states =
184 typename Arc::StateId nstates = 0;
196 typename Arc::StateId nstates = 0;
206 narcs += fst.NumArcs(siter.Value());
213 #endif // FST_EXPANDED_FST_H_ static Impl * Read(std::istream &strm, const FstReadOptions &opts)
virtual size_t NumArcs(StateId) const =0
static ExpandedFst * Read(std::string_view source)
typename Arc::Weight Weight
virtual Weight Final(StateId) const =0
size_t CountArcs(const F &fst)
static FstRegister< Arc > * GetRegister()
virtual size_t NumInputEpsilons(StateId) const =0
std::optional< StateId > NumStatesIfKnown() const override
ImplToExpandedFst(std::shared_ptr< Impl > impl)
StateId NumStates() const override
ExpandedFst * Copy(bool safe=false) const override=0
ImplToExpandedFst(const ImplToExpandedFst &fst, bool safe)
virtual std::optional< StateId > NumStatesIfKnown() const
Arc::StateId CountStates(const Fst< Arc > &fst)
static ExpandedFst * Read(std::istream &strm, const FstReadOptions &opts)
typename Arc::StateId StateId
static Impl * Read(std::string_view source)
virtual StateId NumStates() const =0
constexpr uint64_t kExpanded
virtual size_t NumOutputEpsilons(StateId) const =0