mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
* add hotword for deploy_tools * Support wfst decoder and contextual biasing (#1039) * Support wfst decoder and contextual biasing * Turn on fstbin compilation --------- Co-authored-by: gongbo.gb <gongbo.gb@alibaba-inc.com> * mv funasr/runtime runtime * Fix crash caused by OOV in hotwords list * funasr infer * funasr infer * funasr infer * funasr infer * funasr infer * fix some bugs about fst hotword; support wfst for websocket server and clients; mv runtime out of funasr; modify relative docs * del onnxruntime/include/gflags * update tensor.h * update run_server.sh * update deploy tools * update deploy tools * update websocket-server * update funasr-wss-server * Remove self loop propagation * Update websocket_protocol_zh.md * Update websocket_protocol_zh.md * update hotword protocol * author zhaomingwork: change hotwords for h5 and java * update hotword protocol * catch exception for json_fst_hws * update hotword on message * update onnx benchmark for ngram&hotword * update docs * update funasr-wss-serve * add NONE for LM_DIR * update docs * update run_server.sh * add whats-new * modify whats-new * update whats-new * update whats-new * Support decoder option for beam searching * update benchmark_onnx_cpp * Support decoder option for websocket * fix bug of CompileHotwordEmbedding * update html client * update docs --------- Co-authored-by: gongbo.gb <35997837+aibulamusi@users.noreply.github.com> Co-authored-by: gongbo.gb <gongbo.gb@alibaba-inc.com> Co-authored-by: 游雁 <zhifu.gzf@alibaba-inc.com>
96 lines
2.7 KiB
C++
96 lines
2.7 KiB
C++
#ifndef CPPJIEBA_QUERYSEGMENT_H
|
|
#define CPPJIEBA_QUERYSEGMENT_H
|
|
|
|
#include <algorithm>
|
|
#include <set>
|
|
#include <cassert>
|
|
#include "limonp/Logging.hpp"
|
|
#include "DictTrie.hpp"
|
|
#include "SegmentBase.hpp"
|
|
#include "FullSegment.hpp"
|
|
#include "MixSegment.hpp"
|
|
#include "Unicode.hpp"
|
|
|
|
namespace cppjieba {
|
|
class QuerySegment: public SegmentBase {
|
|
public:
|
|
QuerySegment(const string& dict, const string& model, const string& userDict = "")
|
|
: mixSeg_(dict, model, userDict),
|
|
trie_(mixSeg_.GetDictTrie()) {
|
|
}
|
|
QuerySegment(const DictTrie* dictTrie, const HMMModel* model)
|
|
: mixSeg_(dictTrie, model), trie_(dictTrie) {
|
|
}
|
|
QuerySegment() {
|
|
trie_ = NULL;
|
|
}
|
|
~QuerySegment() {
|
|
}
|
|
void setRes(DictTrie *&dictTrie, HMMModel *&model) {
|
|
mixSeg_.setRes(dictTrie, model);
|
|
trie_ = dictTrie;
|
|
}
|
|
void Cut(const string& sentence, vector<string>& words) const {
|
|
Cut(sentence, words, true);
|
|
}
|
|
void Cut(const string& sentence, vector<string>& words, bool hmm) const {
|
|
vector<Word> tmp;
|
|
Cut(sentence, tmp, hmm);
|
|
GetStringsFromWords(tmp, words);
|
|
}
|
|
void Cut(const string& sentence, vector<Word>& words, bool hmm = true) const {
|
|
PreFilter pre_filter(symbols_, sentence);
|
|
PreFilter::Range range;
|
|
vector<WordRange> wrs;
|
|
wrs.reserve(sentence.size()/2);
|
|
while (pre_filter.HasNext()) {
|
|
range = pre_filter.Next();
|
|
Cut(range.begin, range.end, wrs, hmm);
|
|
}
|
|
words.clear();
|
|
words.reserve(wrs.size());
|
|
GetWordsFromWordRanges(sentence, wrs, words);
|
|
}
|
|
void Cut(RuneStrArray::const_iterator begin, RuneStrArray::const_iterator end, vector<WordRange>& res, bool hmm) const {
|
|
//use mix Cut first
|
|
vector<WordRange> mixRes;
|
|
mixSeg_.Cut(begin, end, mixRes, hmm);
|
|
|
|
vector<WordRange> fullRes;
|
|
for (vector<WordRange>::const_iterator mixResItr = mixRes.begin(); mixResItr != mixRes.end(); mixResItr++) {
|
|
if (mixResItr->Length() > 2) {
|
|
for (size_t i = 0; i + 1 < mixResItr->Length(); i++) {
|
|
WordRange wr(mixResItr->left + i, mixResItr->left + i + 1);
|
|
if (trie_->Find(wr.left, wr.right + 1) != NULL) {
|
|
res.push_back(wr);
|
|
}
|
|
}
|
|
}
|
|
if (mixResItr->Length() > 3) {
|
|
for (size_t i = 0; i + 2 < mixResItr->Length(); i++) {
|
|
WordRange wr(mixResItr->left + i, mixResItr->left + i + 2);
|
|
if (trie_->Find(wr.left, wr.right + 1) != NULL) {
|
|
res.push_back(wr);
|
|
}
|
|
}
|
|
}
|
|
res.push_back(*mixResItr);
|
|
}
|
|
}
|
|
private:
|
|
bool IsAllAscii(const Unicode& s) const {
|
|
for(size_t i = 0; i < s.size(); i++) {
|
|
if (s[i] >= 0x80) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
MixSegment mixSeg_;
|
|
const DictTrie* trie_;
|
|
}; // QuerySegment
|
|
|
|
} // namespace cppjieba
|
|
|
|
#endif
|