#include<iostream>
#include<vector>
int ngram(const std::string sentence,int n,std::vector<std::string> &rev){
int len= sentence.length();
if(len==0){
return 0;
}
if(len<n){
rev.push_back(sentence);
return 1;
}
for(int i=0;i<len-n+1;i++){
std::string s1=sentence.substr(i,n);
rev.push_back(s1);
}
return len-n+1;
}
int main(){
std::string a="dsdfsdfae";
std::vector<std::string> rev;
int len=ngram(a,3,rev);
for(int i=0;i<len;i++){
std::cout<<rev[i]<<std::endl;
}
}
[c++] [vector] [ngram] ngram分词,vector使用
最新推荐文章于 2023-07-11 10:49:43 发布