From 580b11b57ac4b62f7e2acda73813a4e10e8e4cd3 Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期二, 10 十月 2023 17:17:29 +0800
Subject: [PATCH] v0.8.0

---
 funasr/runtime/onnxruntime/src/ct-transformer.cpp |   30 +++++++++++++++++++++++++-----
 1 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/funasr/runtime/onnxruntime/src/ct-transformer.cpp b/funasr/runtime/onnxruntime/src/ct-transformer.cpp
index 2f7c0cd..64a70da 100644
--- a/funasr/runtime/onnxruntime/src/ct-transformer.cpp
+++ b/funasr/runtime/onnxruntime/src/ct-transformer.cpp
@@ -18,10 +18,11 @@
 
     try{
         m_session = std::make_unique<Ort::Session>(env_, punc_model.c_str(), session_options);
+        LOG(INFO) << "Successfully load model from " << punc_model;
     }
     catch (std::exception const &e) {
         LOG(ERROR) << "Error when load punc onnx model: " << e.what();
-        exit(0);
+        exit(-1);
     }
     // read inputnames outputnames
     string strName;
@@ -45,7 +46,7 @@
 {
 }
 
-string CTTransformer::AddPunc(const char* sz_input)
+string CTTransformer::AddPunc(const char* sz_input, std::string language)
 {
     string strResult;
     vector<string> strOut;
@@ -103,7 +104,7 @@
         vector<string> WordWithPunc;
         for (int i = 0; i < InputStr.size(); i++)
         {
-            #if (i > 0 && !(InputStr[i][0] & 0x80) && (i + 1) <InputStr.size() && !(InputStr[i+1][0] & 0x80))// 锟叫硷拷锟接拷模锟�
+            // if (i > 0 && !(InputStr[i][0] & 0x80) && (i + 1) <InputStr.size() && !(InputStr[i+1][0] & 0x80))// 锟叫硷拷锟接拷模锟�
             if (i > 0 && !(InputStr[i-1][0] & 0x80) && !(InputStr[i][0] & 0x80))
             {
                 InputStr[i] = " " + InputStr[i];
@@ -138,8 +139,28 @@
             }
         }
     }
-    for (auto& item : NewSentenceOut)
+
+    for (auto& item : NewSentenceOut){
         strResult += item;
+    }
+    
+    if(language == "en-bpe"){
+        std::vector<std::string> chineseSymbols;
+        chineseSymbols.push_back("锛�");
+        chineseSymbols.push_back("銆�");
+        chineseSymbols.push_back("銆�");
+        chineseSymbols.push_back("锛�");
+
+        std::string englishSymbols = ",.,?";
+        for (size_t i = 0; i < chineseSymbols.size(); i++) {
+            size_t pos = 0;
+            while ((pos = strResult.find(chineseSymbols[i], pos)) != std::string::npos) {
+                strResult.replace(pos, 3, 1, englishSymbols[i]);
+                pos++;
+            }
+        }
+    }
+
     return strResult;
 }
 
@@ -183,7 +204,6 @@
     catch (std::exception const &e)
     {
         LOG(ERROR) << "Error when run punc onnx forword: " << (e.what());
-        exit(0);
     }
     return punction;
 }

--
Gitblit v1.9.1