fix SplitByPunc

pull/3030/head
TianYuan 3 years ago
parent 153584d0f9
commit c5417c32bf

@ -51,7 +51,7 @@ int main(int argc, char** argv) {
// 根据标点进行分句 // 根据标点进行分句
LOG(INFO) << "Start to segment sentences by punctuation"; LOG(INFO) << "Start to segment sentences by punctuation";
front_inst->SplitByPunc(ws_sentence, sentence_part); front_inst->SplitByPunc(ws_sentence, &sentence_part);
LOG(INFO) << "Segment sentences through punctuation successfully"; LOG(INFO) << "Segment sentences through punctuation successfully";
// 分句后获取音素id // 分句后获取音素id

@ -51,19 +51,19 @@ int TextNormalizer::Replace(std::wstring *sentence,
// 根据标点符号切分句子 // 根据标点符号切分句子
int TextNormalizer::SplitByPunc(const std::wstring &sentence, int TextNormalizer::SplitByPunc(const std::wstring &sentence,
std::vector<std::wstring> &sentence_part) { std::vector<std::wstring> *sentence_part) {
std::wstring temp = sentence; std::wstring temp = sentence;
std::wregex reg(L"[:,;。?!,;?!]"); std::wregex reg(L"[:,;。?!,;?!]");
std::wsmatch match; std::wsmatch match;
while (std::regex_search(temp, match, reg)) { while (std::regex_search(temp, match, reg)) {
sentence_part.push_back( sentence_part->push_back(
temp.substr(0, match.position(0) + match.length(0))); temp.substr(0, match.position(0) + match.length(0)));
Replace(&temp, 0, match.position(0) + match.length(0), L""); Replace(&temp, 0, match.position(0) + match.length(0), L"");
} }
// 如果最后没有标点符号 // 如果最后没有标点符号
if (temp != L"") { if (temp != L"") {
sentence_part.push_back(temp); sentence_part->push_back(temp);
} }
return 0; return 0;
} }

@ -36,7 +36,7 @@ class TextNormalizer {
const int &len, const int &len,
const std::wstring &repstr); const std::wstring &repstr);
int SplitByPunc(const std::wstring &sentence, int SplitByPunc(const std::wstring &sentence,
std::vector<std::wstring> &sentence_part); std::vector<std::wstring> *sentence_part);
std::string CreateTextValue(const std::string &num, bool use_zero = true); std::string CreateTextValue(const std::string &num, bool use_zero = true);
std::string SingleDigit2Text(const std::string &num_str, std::string SingleDigit2Text(const std::string &num_str,

Loading…
Cancel
Save