From 3cd3473bf7a3b41484baa86d9092248d78e7af39 Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期五, 21 四月 2023 17:17:37 +0800
Subject: [PATCH] docs
---
funasr/runtime/onnxruntime/src/Vocab.cpp | 32 +++++++++++++++++---------------
1 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/funasr/runtime/onnxruntime/src/Vocab.cpp b/funasr/runtime/onnxruntime/src/Vocab.cpp
index d2d0341..b54a6c6 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,25 @@
Vocab::Vocab(const char *filename)
{
ifstream in(filename);
- string line;
-
- if (in) // 鏈夎鏂囦欢
- {
- while (getline(in, line)) // line涓笉鍖呮嫭姣忚鐨勬崲琛岀
- {
- vocab.push_back(line);
- }
- // cout << vocab[1719] << endl;
- }
- // else // 娌℃湁璇ユ枃浠�
- //{
- // cout << "no such file" << endl;
- // }
+ loadVocabFromYaml(filename);
}
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 +69,6 @@
return false;
}
-
string Vocab::vector2stringV2(vector<int> in)
{
--
Gitblit v1.9.1