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;

}
posted on 2011-03-01 09:47  finallyly  阅读(393)  评论(0编辑  收藏  举报