// Copyright 2005-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the 'License'); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an 'AS IS' BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // See www.openfst.org for extensive documentation on this weighted // finite-state transducer library. // // Expands an MPDT to an FST. #ifndef FST_EXTENSIONS_MPDT_EXPAND_H_ #define FST_EXTENSIONS_MPDT_EXPAND_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace fst { template struct MPdtExpandFstOptions : public CacheOptions { bool keep_parentheses; internal::MPdtStack *stack; PdtStateTable *state_table; explicit MPdtExpandFstOptions( const CacheOptions &opts = CacheOptions(), bool kp = false, internal::MPdtStack *s = nullptr, PdtStateTable *st = nullptr) : CacheOptions(opts), keep_parentheses(kp), stack(s), state_table(st) {} }; // Properties for an expanded PDT. inline uint64_t MPdtExpandProperties(uint64_t inprops) { return inprops & (kAcceptor | kAcyclic | kInitialAcyclic | kUnweighted); } namespace internal { // Implementation class for ExpandFst template class MPdtExpandFstImpl : public CacheImpl { public: using Label = typename Arc::Label; using StateId = typename Arc::StateId; using Weight = typename Arc::Weight; using StackId = StateId; using StateTuple = PdtStateTuple; using ParenStack = internal::MPdtStack; using FstImpl::SetType; using FstImpl::SetProperties; using FstImpl::Properties; using FstImpl::SetInputSymbols; using FstImpl::SetOutputSymbols; using CacheBaseImpl>::PushArc; using CacheBaseImpl>::HasArcs; using CacheBaseImpl>::HasFinal; using CacheBaseImpl>::HasStart; using CacheBaseImpl>::SetArcs; using CacheBaseImpl>::SetFinal; using CacheBaseImpl>::SetStart; MPdtExpandFstImpl(const Fst &fst, const std::vector> &parens, const std::vector