Removing stop words from single string

前端 未结 3 495
花落未央
花落未央 2020-12-11 08:30

My query is string = \'Alligator in water\' where in is a stop word. How can I remove it so that I get stop_remove = \'Alligator water\'

3条回答
  •  独厮守ぢ
    2020-12-11 09:09

    A slightly more elegant way than Luis Mendo's solution is to use regexprep that does exactly what you want

    >> result = regexprep( 'Alligator in water', 'in\s*', '' ); % replace with an empty string 
    result =    
       Alligator water
    

    If you have several stop words you can simply add them to the pattern (in this example I consider 'in' and 'near' as stop words):

    >> result = regexprep( 'Alligator in water near land', {'in\s*','near\s*'}, '' )
    result =
       Alligator water land
    

提交回复
热议问题