diff --git a/runtime/engine/common/utils/text_process.cc b/runtime/engine/common/utils/text_process.cc index bcaffd7ae..f9ade2804 100644 --- a/runtime/engine/common/utils/text_process.cc +++ b/runtime/engine/common/utils/text_process.cc @@ -2,7 +2,7 @@ namespace ppspeech { -std::string RemoveBlk(const std::string& str) { +std::string DelBlank(const std::string& str) { std::string out = ""; int ptr_in = 0; // the pointer of input string (for traversal) int end = str.size(); @@ -23,7 +23,7 @@ std::string RemoveBlk(const std::string& str) { return out; } -std::string AddBlk(const std::string& str) { +std::string AddBlank(const std::string& str) { std::string out = ""; int ptr = 0; // the pointer of the input string int end = str.size(); @@ -44,32 +44,29 @@ std::string AddBlk(const std::string& str) { return out; } -std::string ReverseFrac(const std::string& str, - const std::string& left_tag, - const std::string& right_tag) { +std::string ReverseFraction(const std::string& str) { std::string out = ""; int ptr = 0; // the pointer of the input string int end = str.size(); int left, right, frac; // the start index of the left tag, right tag and '/'. left = right = frac = 0; - int len_left_tag = left_tag.size(); - int len_right_tag = right_tag.size(); + int len_tag = 5; // length of "" while (ptr != end) { // find the position of left tag, right tag and '/'. (xxxnum1/num2) - left = str.find(left_tag, ptr); + left = str.find("", ptr); if (left == -1) break; out += str.substr(ptr, left - ptr); // content before left tag (xxx) frac = str.find("/", left); - right = str.find(right_tag, frac); + right = str.find("", frac); out += str.substr(frac + 1, right - frac - 1) + '/' + - str.substr(left + len_left_tag, frac - left - len_left_tag); // num2/num1 - ptr = right + len_right_tag; + str.substr(left + len_tag, frac - left - len_tag); // num2/num1 + ptr = right + len_tag; } if (ptr != end) { - out += str.substr(ptr, end - right - len_right_tag); + out += str.substr(ptr, end - ptr); } return out; } diff --git a/runtime/engine/common/utils/text_process.h b/runtime/engine/common/utils/text_process.h index e084794a5..9dbc53223 100644 --- a/runtime/engine/common/utils/text_process.h +++ b/runtime/engine/common/utils/text_process.h @@ -4,12 +4,10 @@ namespace ppspeech { -std::string RemoveBlk(const std::string& str); +std::string DelBlank(const std::string& str); -std::string AddBlk(const std::string& str); +std::string AddBlank(const std::string& str); -std::string ReverseFrac(const std::string& str, - const std::string& left_tag = "", - const std::string& right_tag = ""); +std::string ReverseFraction(const std::string& str); } // namespace ppspeech \ No newline at end of file diff --git a/runtime/engine/common/utils/text_process_test.cc b/runtime/engine/common/utils/text_process_test.cc index 3e36ca0d1..e6da82593 100644 --- a/runtime/engine/common/utils/text_process_test.cc +++ b/runtime/engine/common/utils/text_process_test.cc @@ -3,43 +3,45 @@ #include #include -TEST(TextProcess, RemoveBlkTest) { +TEST(TextProcess, DelBlankTest) { std::string test_str = "我 今天 去 了 超市 花了 120 元。"; - std::string out_str = ppspeech::RemoveBlk(test_str); + std::string out_str = ppspeech::DelBlank(test_str); int ret = out_str.compare("我今天去了超市花了120元。"); EXPECT_EQ(ret, 0); test_str = "how are you today"; - out_str = ppspeech::RemoveBlk(test_str); + out_str = ppspeech::DelBlank(test_str); ret = out_str.compare("how are you today"); EXPECT_EQ(ret, 0); test_str = "我 的 paper 在 哪里?"; - out_str = ppspeech::RemoveBlk(test_str); + out_str = ppspeech::DelBlank(test_str); ret = out_str.compare("我的paper在哪里?"); EXPECT_EQ(ret, 0); } -TEST(TextProcess, AddBlkTest) { +TEST(TextProcess, AddBlankTest) { std::string test_str = "how are you"; - std::string out_str = ppspeech::AddBlk(test_str); + std::string out_str = ppspeech::AddBlank(test_str); int ret = out_str.compare(" how are you "); EXPECT_EQ(ret, 0); test_str = "欢迎来到China。"; - out_str = ppspeech::AddBlk(test_str); + out_str = ppspeech::AddBlank(test_str); ret = out_str.compare("欢迎来到 China 。"); EXPECT_EQ(ret, 0); } -TEST(TextProcess, ReverseFracTest) { - std::string test_str = "3/1"; - std::string out_str = ppspeech::ReverseFrac(test_str); +TEST(TextProcess, ReverseFractionTest) { + std::string test_str = "3/1"; + std::string out_str = ppspeech::ReverseFraction(test_str); int ret = out_str.compare("1/3"); + std::cout<