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.

54 lines
1.8 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. #include <fstream>
  15. #include <iostream>
  16. #include <string>
  17. #include "wetext_processor.h"
  18. #include "../utils/wetext_flags.h"
  19. DEFINE_string(text, "", "input string");
  20. DEFINE_string(file, "", "input file");
  21. DEFINE_string(tagger, "", "tagger fst path");
  22. DEFINE_string(verbalizer, "", "verbalizer fst path");
  23. int main(int argc, char* argv[]) {
  24. gflags::ParseCommandLineFlags(&argc, &argv, false);
  25. google::InitGoogleLogging(argv[0]);
  26. if (FLAGS_tagger.empty() || FLAGS_verbalizer.empty()) {
  27. LOG(FATAL) << "Please provide the tagger and verbalizer fst files.";
  28. }
  29. wetext::Processor processor(FLAGS_tagger, FLAGS_verbalizer);
  30. if (!FLAGS_text.empty()) {
  31. std::string tagged_text = processor.Tag(FLAGS_text);
  32. std::cout << tagged_text << std::endl;
  33. std::string normalized_text = processor.Verbalize(tagged_text);
  34. std::cout << normalized_text << std::endl;
  35. }
  36. if (!FLAGS_file.empty()) {
  37. std::ifstream file(FLAGS_file);
  38. std::string line;
  39. while (getline(file, line)) {
  40. std::string tagged_text = processor.Tag(line);
  41. std::cout << tagged_text << std::endl;
  42. std::string normalized_text = processor.Verbalize(tagged_text);
  43. std::cout << normalized_text << std::endl;
  44. }
  45. }
  46. return 0;
  47. }