From 0eacba96a12d5c0dea89c4533ca68b40decd8e9f Mon Sep 17 00:00:00 2001
From: Yabin Li <wucong.lyb@alibaba-inc.com>
Date: 星期四, 06 四月 2023 10:53:13 +0800
Subject: [PATCH] Merge branch 'main' into main

---
 funasr/runtime/onnxruntime/src/Vocab.cpp |   31 ++++++++++++++++++++++++-------
 1 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/funasr/runtime/onnxruntime/src/Vocab.cpp b/funasr/runtime/onnxruntime/src/Vocab.cpp
index d2d0341..af6312b 100644
--- a/funasr/runtime/onnxruntime/src/Vocab.cpp
+++ b/funasr/runtime/onnxruntime/src/Vocab.cpp
@@ -1,4 +1,5 @@
 #include "Vocab.h"
+#include "yaml-cpp/yaml.h"
 
 #include <fstream>
 #include <iostream>
@@ -11,23 +12,40 @@
 Vocab::Vocab(const char *filename)
 {
     ifstream in(filename);
-    string line;
+    loadVocabFromYaml(filename);
 
+    /*
+    string line;
     if (in) // 鏈夎鏂囦欢
     {
         while (getline(in, line)) // line涓笉鍖呮嫭姣忚鐨勬崲琛岀
         {
             vocab.push_back(line);
         }
-        // cout << vocab[1719] << endl;
     }
-    // else // 娌℃湁璇ユ枃浠�
-    //{
-    //     cout << "no such file" << endl;
-    // }
+    else{
+        printf("Cannot load vocab from: %s, there must be file vocab.txt", filename);
+        exit(-1);
+    }
+    */
 }
 Vocab::~Vocab()
 {
+}
+
+void Vocab::loadVocabFromYaml(const char* filename){
+    YAML::Node config;
+    try{
+        config = YAML::LoadFile(filename);
+    }catch(...){
+        printf("error loading file, yaml file error or not exist.\n");
+        exit(-1);
+    }
+
+    YAML::Node myList = config["token_list"];
+    for (YAML::const_iterator it = myList.begin(); it != myList.end(); ++it) {
+        vocab.push_back(it->as<string>());
+    }
 }
 
 string Vocab::vector2string(vector<int> in)
@@ -66,7 +84,6 @@
 
     return false;
 }
-
 
 string Vocab::vector2stringV2(vector<int> in)
 {

--
Gitblit v1.9.1