jmwang66
2023-05-09 8dab6d184a034ca86eafa644ea0d2100aadfe27d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
 * Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights Reserved.
 * MIT License  (https://opensource.org/licenses/MIT)
*/
 
#pragma once
#include <yaml-cpp/yaml.h>
 
namespace funasr {
class CTokenizer {
private:
 
    bool  m_ready = false;
    vector<string>   m_id2token,m_id2punc;
    map<string, int>  m_token2id,m_punc2id;
 
public:
 
    CTokenizer(const char* sz_yamlfile);
    CTokenizer();
    ~CTokenizer();
    bool OpenYaml(const char* sz_yamlfile);
    void ReadYaml(const YAML::Node& node);
    vector<string> Id2String(vector<int> input);
    vector<int> String2Ids(vector<string> input);
    int String2Id(string input);
    vector<string> Id2Punc(vector<int> input);
    string Id2Punc(int n_punc_id);
    vector<int> Punc2Ids(vector<string> input);
    vector<string> SplitChineseString(const string& str_info);
    void StrSplit(const string& str, const char split, vector<string>& res);
    void Tokenize(const char* str_info, vector<string>& str_out, vector<int>& id_out);
 
};
 
} // namespace funasr