Skip to content

Commit

Permalink
fix cpplint
Browse files Browse the repository at this point in the history
  • Loading branch information
duj12 committed Sep 8, 2023
1 parent e0b10a3 commit 019499f
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 39 deletions.
16 changes: 10 additions & 6 deletions runtime/core/api/wenet_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,18 @@ class Recognizer {
post_process_opts_->language_type = wenet::kIndoEuropean;
}
resource_->post_processor =
std::make_shared<wenet::PostProcessor>(*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<wenet::PostProcessor>(*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<wenet::PostProcessor>(*post_process_opts_);
auto postprocessor =
std::make_shared<wenet::PostProcessor>(*post_process_opts_);
postprocessor->InitITNResource(itn_tagger_path, itn_verbalizer_path);
resource_->post_processor = postprocessor;
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/core/decoder/asr_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ enum DecodeState {
struct DecodeResource {
std::shared_ptr<AsrModel> model = nullptr;
std::shared_ptr<fst::SymbolTable> symbol_table = nullptr;
//std::shared_ptr<fst::Fst<fst::StdArc>> fst = nullptr;
// std::shared_ptr<fst::Fst<fst::StdArc>> fst = nullptr;
std::shared_ptr<fst::VectorFst<fst::StdArc>> fst = nullptr;
std::shared_ptr<fst::SymbolTable> unit_table = nullptr;
std::shared_ptr<ContextGraph> context_graph = nullptr;
Expand Down Expand Up @@ -141,7 +141,7 @@ class AsrDecoder {
std::shared_ptr<PostProcessor> post_processor_;
std::shared_ptr<ContextGraph> context_graph_;

//std::shared_ptr<fst::Fst<fst::StdArc>> fst_ = nullptr;
// std::shared_ptr<fst::Fst<fst::StdArc>> fst_ = nullptr;
std::shared_ptr<fst::VectorFst<fst::StdArc>> fst_ = nullptr;
// output symbol table
std::shared_ptr<fst::SymbolTable> symbol_table_;
Expand Down
13 changes: 8 additions & 5 deletions runtime/core/decoder/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,17 @@ std::shared_ptr<DecodeResource> 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<wenet::PostProcessor>(post_process_opts);
auto postprocessor =
std::make_shared<wenet::PostProcessor>(post_process_opts);
postprocessor->InitITNResource(itn_tagger_path, itn_verbalizer_path);
resource->post_processor = postprocessor;
}
}

return resource;
}

Expand Down
34 changes: 19 additions & 15 deletions runtime/core/post_processor/post_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<wenet::Processor>(tagger_path, verbalizer_path);
void PostProcessor::InitITNResource(
const std::string& tagger_path, const std::string& verbalizer_path) {
auto itn_processor =
std::make_shared<wenet::Processor>(tagger_path, verbalizer_path);
itn_resource = itn_processor;
};
}

std::string PostProcessor::ProcessSpace(const std::string& str) {
std::string result = str;
Expand Down Expand Up @@ -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, "<unk>");
del_substr(result, "<context>");
del_substr(result, "</context>");
result = del_substr(result, "<unk>");
result = del_substr(result, "<context>");
result = del_substr(result, "</context>");
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);
}
}
Expand Down
3 changes: 2 additions & 1 deletion runtime/core/post_processor/post_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<wenet::Processor> itn_resource = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion runtime/core/post_processor/processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ std::string Processor::normalize(const std::string& input) {
return verbalize(tag(input));
}

} // namespace wetext
} // namespace wenet
8 changes: 4 additions & 4 deletions runtime/core/post_processor/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -43,6 +43,6 @@ class Processor {
std::shared_ptr<StringPrinter<StdArc>> printer_ = nullptr;
};

} // namespace wetext
} // namespace wenet

#endif // PROCESSOR_PROCESSOR_H_
#endif // POST_PROCESSOR_PROCESSOR_H_
2 changes: 1 addition & 1 deletion runtime/core/post_processor/token_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,4 @@ std::string TokenParser::reorder(const std::string& input) {
return Trim(output);
}

} // namespace wetext
} // namespace wenet
8 changes: 4 additions & 4 deletions runtime/core/post_processor/token_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <set>
#include <string>
Expand Down Expand Up @@ -86,6 +86,6 @@ class TokenParser {
std::unordered_map<std::string, std::vector<std::string>> orders;
};

} // wetext
} // namespace wenet

#endif // PROCESSOR_TOKEN_PARSER_H_
#endif // POST_PROCESSOR_TOKEN_PARSER_H_
1 change: 1 addition & 0 deletions runtime/resource

0 comments on commit 019499f

Please sign in to comment.