20 #ifndef FST_TEST_PROPERTIES_H_ 21 #define FST_TEST_PROPERTIES_H_ 30 #include <unordered_set> 50 using Label =
typename Arc::Label;
51 using StateId =
typename Arc::StateId;
52 using Weight =
typename Arc::Weight;
60 constexpr uint64_t kDfsProps =
63 std::vector<StateId> scc;
69 if (mask & ~(kBinaryProperties | kDfsProps)) {
82 std::unique_ptr<std::unordered_set<Label>> ilabels;
83 std::unique_ptr<std::unordered_set<Label>> olabels;
86 StateId s = siter.Value();
90 ilabels = std::make_unique<std::unordered_set<Label>>();
93 olabels = std::make_unique<std::unordered_set<Label>>();
95 bool first_arc =
true;
97 const auto &arc = aiter.Value();
98 if (ilabels && ilabels->find(arc.ilabel) != ilabels->end()) {
102 if (olabels && olabels->find(arc.olabel) != olabels->end()) {
106 if (arc.ilabel != arc.olabel) {
110 if (arc.ilabel == 0 && arc.olabel == 0) {
114 if (arc.ilabel == 0) {
118 if (arc.olabel == 0) {
123 if (arc.ilabel < prev_arc.ilabel) {
127 if (arc.olabel < prev_arc.olabel) {
132 if (arc.weight != Weight::One() && arc.weight != Weight::Zero()) {
136 scc[s] == scc[arc.nextstate]) {
138 comp_props &= ~kUnweightedCycles;
141 if (arc.nextstate <= s) {
145 if (arc.nextstate != s + 1) {
151 if (ilabels) ilabels->insert(arc.ilabel);
152 if (olabels) olabels->insert(arc.olabel);
159 const auto final_weight = fst.
Final(s);
160 if (final_weight != Weight::Zero()) {
161 if (final_weight != Weight::One()) {
191 if ((known_props & mask) == mask) {
192 if (known) *known = known_props;
205 if (FST_FLAGS_fst_verify_properties) {
209 FSTERROR() <<
"TestProperties: stored FST properties incorrect" 210 <<
" (stored: props1, computed: props2)";
212 return computed_props;
224 uint64_t test_mask) {
226 if (FST_FLAGS_fst_verify_properties) {
231 return props & (check_mask | test_mask);
237 #endif // FST_TEST_PROPERTIES_H_ constexpr uint64_t kCyclic
constexpr uint64_t kNotString
uint64_t TestProperties(const Fst< Arc > &fst, uint64_t mask, uint64_t *known)
uint64_t ComputeProperties(const Fst< Arc > &fst, uint64_t mask, uint64_t *known)
constexpr uint64_t kWeightedCycles
virtual uint64_t Properties(uint64_t mask, bool test) const =0
constexpr uint64_t kOEpsilons
constexpr uint64_t kInitialCyclic
virtual size_t NumArcs(StateId) const =0
constexpr uint64_t kCoAccessible
bool CompatProperties(uint64_t props1, uint64_t props2)
constexpr uint64_t kBinaryProperties
constexpr uint64_t kNotAccessible
constexpr uint64_t kNotTopSorted
void DfsVisit(const FST &fst, Visitor *visitor, ArcFilter filter, bool access_only=false)
constexpr uint64_t kInitialAcyclic
virtual Weight Final(StateId) const =0
constexpr uint64_t kUnweightedCycles
constexpr uint64_t kEpsilons
constexpr uint64_t kNotOLabelSorted
constexpr uint64_t kTopSorted
DECLARE_bool(fst_verify_properties)
constexpr uint64_t kODeterministic
constexpr uint64_t kNonIDeterministic
constexpr uint64_t kNotILabelSorted
constexpr uint64_t kNoOEpsilons
constexpr uint64_t kOLabelSorted
constexpr uint64_t kNotAcceptor
constexpr uint64_t kAcyclic
constexpr uint64_t kNoEpsilons
uint64_t CheckProperties(const Fst< Arc > &fst, uint64_t check_mask, uint64_t test_mask)
uint64_t KnownProperties(uint64_t props)
constexpr uint64_t kAccessible
virtual StateId Start() const =0
constexpr uint64_t kIDeterministic
constexpr uint64_t kIEpsilons
uint64_t ComputeOrUseStoredProperties(const Fst< Arc > &fst, uint64_t mask, uint64_t *known)
constexpr uint64_t kILabelSorted
constexpr uint64_t kFstProperties
constexpr uint64_t kUnweighted
constexpr uint64_t kNonODeterministic
constexpr uint64_t kString
constexpr uint64_t kNotCoAccessible
constexpr uint64_t kWeighted
constexpr uint64_t kNoIEpsilons
constexpr uint64_t kAcceptor