vector<string>Preprocess:: mySplit(string s,set<string> stopwords)
{
vector<string> wordCollection;
trim(s," ");
int nPosBegin=0;
int nPosEnd=s.find(',',nPosBegin);
while(nPosEnd!=string::npos)
{
string temp=s.substr(nPosBegin,nPosEnd-nPosBegin);
trim(temp," ");
if(temp!="")
{
wordCollection.push_back(temp);
}
nPosBegin=s.find_first_not_of(',',nPosEnd);
if(nPosBegin==string::npos)
{
nPosEnd=string::npos;
}
else
{
nPosEnd=s.find(',',nPosBegin);
}
}
if(nPosBegin!=string::npos&&nPosEnd==string::npos)//结尾缺少分割号,添加该词
{
string temp=s.substr(nPosBegin,s.size()-nPosBegin);
trim(temp," ");
if(temp!="")
{
wordCollection.push_back(temp);
}
}
return wordCollection;
}
{
vector<string> wordCollection;
trim(s," ");
int nPosBegin=0;
int nPosEnd=s.find(',',nPosBegin);
while(nPosEnd!=string::npos)
{
string temp=s.substr(nPosBegin,nPosEnd-nPosBegin);
trim(temp," ");
if(temp!="")
{
wordCollection.push_back(temp);
}
nPosBegin=s.find_first_not_of(',',nPosEnd);
if(nPosBegin==string::npos)
{
nPosEnd=string::npos;
}
else
{
nPosEnd=s.find(',',nPosBegin);
}
}
if(nPosBegin!=string::npos&&nPosEnd==string::npos)//结尾缺少分割号,添加该词
{
string temp=s.substr(nPosBegin,s.size()-nPosBegin);
trim(temp," ");
if(temp!="")
{
wordCollection.push_back(temp);
}
}
return wordCollection;
}