From 019499fbb029d7dfbda63c8acc69f6d8ac52da57 Mon Sep 17 00:00:00 2001 From: dujing Date: Fri, 8 Sep 2023 11:54:01 +0800 Subject: [PATCH] fix cpplint --- runtime/core/api/wenet_api.cc | 16 +++++---- runtime/core/decoder/asr_decoder.h | 4 +-- runtime/core/decoder/params.h | 13 ++++--- runtime/core/post_processor/post_processor.cc | 34 +++++++++++-------- runtime/core/post_processor/post_processor.h | 3 +- runtime/core/post_processor/processor.cc | 2 +- runtime/core/post_processor/processor.h | 8 ++--- runtime/core/post_processor/token_parser.cc | 2 +- runtime/core/post_processor/token_parser.h | 8 ++--- runtime/resource | 1 + 10 files changed, 52 insertions(+), 39 deletions(-) create mode 120000 runtime/resource diff --git a/runtime/core/api/wenet_api.cc b/runtime/core/api/wenet_api.cc index f0de85913..aa5861f72 100644 --- a/runtime/core/api/wenet_api.cc +++ b/runtime/core/api/wenet_api.cc @@ -90,14 +90,18 @@ class Recognizer { post_process_opts_->language_type = wenet::kIndoEuropean; } resource_->post_processor = - std::make_shared(*post_process_opts_); - //Optional: ITN - std::string itn_tagger_path = wenet::JoinPath(model_dir, "zh_itn_tagger.fst"); - std::string itn_verbalizer_path = wenet::JoinPath(model_dir, "zh_itn_verbalizer.fst"); - if (wenet::FileExists(itn_tagger_path) && wenet::FileExists(itn_verbalizer_path)){ + std::make_shared(*post_process_opts_); + // Optional: ITN + std::string itn_tagger_path = + wenet::JoinPath(model_dir, "zh_itn_tagger.fst"); + std::string itn_verbalizer_path = + wenet::JoinPath(model_dir, "zh_itn_verbalizer.fst"); + if (wenet::FileExists(itn_tagger_path) + && wenet::FileExists(itn_verbalizer_path)) { LOG(INFO) << "Reading ITN fst"; post_process_opts_->itn = true; - auto postprocessor = std::make_shared(*post_process_opts_); + auto postprocessor = + std::make_shared(*post_process_opts_); postprocessor->InitITNResource(itn_tagger_path, itn_verbalizer_path); resource_->post_processor = postprocessor; } diff --git a/runtime/core/decoder/asr_decoder.h b/runtime/core/decoder/asr_decoder.h index 0a2addfbb..e40d46c61 100644 --- a/runtime/core/decoder/asr_decoder.h +++ b/runtime/core/decoder/asr_decoder.h @@ -92,7 +92,7 @@ enum DecodeState { struct DecodeResource { std::shared_ptr model = nullptr; std::shared_ptr symbol_table = nullptr; - //std::shared_ptr> fst = nullptr; + // std::shared_ptr> fst = nullptr; std::shared_ptr> fst = nullptr; std::shared_ptr unit_table = nullptr; std::shared_ptr context_graph = nullptr; @@ -141,7 +141,7 @@ class AsrDecoder { std::shared_ptr post_processor_; std::shared_ptr context_graph_; - //std::shared_ptr> fst_ = nullptr; + // std::shared_ptr> fst_ = nullptr; std::shared_ptr> fst_ = nullptr; // output symbol table std::shared_ptr symbol_table_; diff --git a/runtime/core/decoder/params.h b/runtime/core/decoder/params.h index 18118046f..32b100d9a 100644 --- a/runtime/core/decoder/params.h +++ b/runtime/core/decoder/params.h @@ -245,14 +245,17 @@ std::shared_ptr InitDecodeResourceFromFlags() { if (!FLAGS_itn_model_path.empty()) { // With ITN LOG(INFO) << "Reading ITN fst " << FLAGS_itn_model_path; - std::string itn_tagger_path = wenet::JoinPath(FLAGS_itn_model_path, "zh_itn_tagger.fst"); - std::string itn_verbalizer_path = wenet::JoinPath(FLAGS_itn_model_path, "zh_itn_verbalizer.fst"); + std::string itn_tagger_path = + wenet::JoinPath(FLAGS_itn_model_path, "zh_itn_tagger.fst"); + std::string itn_verbalizer_path = + wenet::JoinPath(FLAGS_itn_model_path, "zh_itn_verbalizer.fst"); post_process_opts.itn = true; - auto postprocessor = std::make_shared(post_process_opts); + auto postprocessor = + std::make_shared(post_process_opts); postprocessor->InitITNResource(itn_tagger_path, itn_verbalizer_path); resource->post_processor = postprocessor; - } - + } + return resource; } diff --git a/runtime/core/post_processor/post_processor.cc b/runtime/core/post_processor/post_processor.cc index e964b5c21..bfab194d8 100644 --- a/runtime/core/post_processor/post_processor.cc +++ b/runtime/core/post_processor/post_processor.cc @@ -20,10 +20,12 @@ #include "utils/string.h" namespace wenet { -void PostProcessor::InitITNResource(const std::string& tagger_path, const std::string& verbalizer_path){ - auto itn_processor = std::make_shared(tagger_path, verbalizer_path); +void PostProcessor::InitITNResource( + const std::string& tagger_path, const std::string& verbalizer_path) { + auto itn_processor = + std::make_shared(tagger_path, verbalizer_path); itn_resource = itn_processor; -}; +} std::string PostProcessor::ProcessSpace(const std::string& str) { std::string result = str; @@ -60,29 +62,31 @@ std::string PostProcessor::ProcessSpace(const std::string& str) { return result; } -void del_substr(std::string& str, const std::string& sub){ - int pos = 0; - while (string::npos != (pos = str.find(sub)) ) - { - str.erase(pos, sub.size()); - } +std::string del_substr(const std::string& str, const std::string& sub) { + std::string result = str; + int pos = 0; + while (string::npos != (pos = result.find(sub))) { + result.erase(pos, sub.size()); + } + return result; } std::string PostProcessor::ProcessSymbols(const std::string& str) { std::string result = str; - del_substr(result, ""); - del_substr(result, ""); - del_substr(result, ""); + result = del_substr(result, ""); + result = del_substr(result, ""); + result = del_substr(result, ""); return result; } std::string PostProcessor::Process(const std::string& str, bool finish) { std::string result; - result = ProcessSymbols(str); //remove symbols with "<>" first + // remove symbols with "<>" first + result = ProcessSymbols(str); result = ProcessSpace(result); // TODO(xcsong): do itn/punctuation if finish == true - if (finish == true and opts_.itn){ - if (nullptr != itn_resource){ + if (finish == true && opts_.itn) { + if (nullptr != itn_resource) { result = itn_resource->normalize(result); } } diff --git a/runtime/core/post_processor/post_processor.h b/runtime/core/post_processor/post_processor.h index 70059fb0e..b6ca61204 100644 --- a/runtime/core/post_processor/post_processor.h +++ b/runtime/core/post_processor/post_processor.h @@ -63,7 +63,8 @@ class PostProcessor { // TODO(xcsong): add punctuation // void Punctuate(const std::string& str); - void InitITNResource(const std::string& tagger_path, const std::string& verbalizer_path); + void InitITNResource(const std::string& tagger_path, + const std::string& verbalizer_path); private: std::shared_ptr itn_resource = nullptr; diff --git a/runtime/core/post_processor/processor.cc b/runtime/core/post_processor/processor.cc index ea7e7afa7..5762d7be1 100644 --- a/runtime/core/post_processor/processor.cc +++ b/runtime/core/post_processor/processor.cc @@ -70,4 +70,4 @@ std::string Processor::normalize(const std::string& input) { return verbalize(tag(input)); } -} // namespace wetext +} // namespace wenet diff --git a/runtime/core/post_processor/processor.h b/runtime/core/post_processor/processor.h index 2f5ddadb0..3b3e4cbbd 100644 --- a/runtime/core/post_processor/processor.h +++ b/runtime/core/post_processor/processor.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef PROCESSOR_PROCESSOR_H_ -#define PROCESSOR_PROCESSOR_H_ +#ifndef POST_PROCESSOR_PROCESSOR_H_ +#define POST_PROCESSOR_PROCESSOR_H_ #include "fst/fstlib.h" @@ -43,6 +43,6 @@ class Processor { std::shared_ptr> printer_ = nullptr; }; -} // namespace wetext +} // namespace wenet -#endif // PROCESSOR_PROCESSOR_H_ +#endif // POST_PROCESSOR_PROCESSOR_H_ diff --git a/runtime/core/post_processor/token_parser.cc b/runtime/core/post_processor/token_parser.cc index 858b864cf..7ed0becc5 100644 --- a/runtime/core/post_processor/token_parser.cc +++ b/runtime/core/post_processor/token_parser.cc @@ -151,4 +151,4 @@ std::string TokenParser::reorder(const std::string& input) { return Trim(output); } -} // namespace wetext +} // namespace wenet diff --git a/runtime/core/post_processor/token_parser.h b/runtime/core/post_processor/token_parser.h index fd2875550..134934b65 100644 --- a/runtime/core/post_processor/token_parser.h +++ b/runtime/core/post_processor/token_parser.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef PROCESSOR_TOKEN_PARSER_H_ -#define PROCESSOR_TOKEN_PARSER_H_ +#ifndef POST_PROCESSOR_TOKEN_PARSER_H_ +#define POST_PROCESSOR_TOKEN_PARSER_H_ #include #include @@ -86,6 +86,6 @@ class TokenParser { std::unordered_map> orders; }; -} // wetext +} // namespace wenet -#endif // PROCESSOR_TOKEN_PARSER_H_ +#endif // POST_PROCESSOR_TOKEN_PARSER_H_ diff --git a/runtime/resource b/runtime/resource new file mode 120000 index 000000000..67a624052 --- /dev/null +++ b/runtime/resource @@ -0,0 +1 @@ +../../wenet/runtime/resource \ No newline at end of file