You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.6 KiB

  1. // Copyright (c) 2022 Zhendong Peng (pzd17@tsinghua.org.cn)
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef PROCESSOR_WETEXT_PROCESSOR_H_
  15. #define PROCESSOR_WETEXT_PROCESSOR_H_
  16. #include <memory>
  17. #include <string>
  18. #include "fst/fstlib.h"
  19. #include "wetext_token_parser.h"
  20. using fst::StdArc;
  21. using fst::StdVectorFst;
  22. using fst::StringCompiler;
  23. using fst::StringPrinter;
  24. namespace wetext {
  25. class Processor {
  26. public:
  27. Processor(const std::string& tagger_path, const std::string& verbalizer_path);
  28. std::string Tag(const std::string& input);
  29. std::string Verbalize(const std::string& input);
  30. std::string Normalize(const std::string& input);
  31. private:
  32. std::string ShortestPath(const StdVectorFst& lattice);
  33. std::string Compose(const std::string& input, const StdVectorFst* fst);
  34. ParseType parse_type_;
  35. std::shared_ptr<StdVectorFst> tagger_ = nullptr;
  36. std::shared_ptr<StdVectorFst> verbalizer_ = nullptr;
  37. std::shared_ptr<StringCompiler<StdArc>> compiler_ = nullptr;
  38. std::shared_ptr<StringPrinter<StdArc>> printer_ = nullptr;
  39. };
  40. } // namespace wetext
  41. #endif // PROCESSOR_WETEXT_PROCESSOR_H_