# How to make stopwords case insensitive

**URL:** <https://www.ruby-forum.com/t/how-to-make-stopwords-case-insensitive/184227>\
**Category:** Ruby\
**Created:** [February 26, 2010, 10:34pm UTC](https://www.ruby-forum.com/t/how-to-make-stopwords-case-insensitive/184227 "2010-02-26T22:34:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [February 26, 2010, 10:34pm UTC](https://www.ruby-forum.com/t/how-to-make-stopwords-case-insensitive/184227/1 "2010-02-26T22:34:43Z")

</div>

New at ruby…

I was trying to create a stoplist that is case insensitive. When I run  
the code below It includes “In” which I do not want. I was thinking I  
could use the .match(/[A-Z,a-z]/) I did use downcase on the string  
text, which did work, but I want to leave the string “text” in its  
orignal content.

Thanks,

John

text = %q{Los A. has some of the nicest weather In the country.}  
stopwords = %w{the a by on for of are with just but and to the my in I  
has some}

#stopwords = stopwords.match(/[A-Z,a-z]/)

words = text.scan(/\w+/)  
keywords = words.select { |word| !stopwords.include?(word) }

puts keywords.join(’ ')

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [February 28, 2010, 12:43am UTC](https://www.ruby-forum.com/t/how-to-make-stopwords-case-insensitive/184227/2 "2010-02-28T00:43:50Z")

</div>

JW DW wrote:

> New at ruby…
> 
> I was trying to create a stoplist that is case insensitive. When I run  
> the code below It includes “In” which I do not want. I was thinking I  
> could use the .match(/[A-Z,a-z]/) I did use downcase on the string  
> text, which did work, but I want to leave the string “text” in its  
> orignal content.
> 
> Thanks,
> 
> John
> 
> text = %q{Los A. has some of the nicest weather In the country.}  
> stopwords = %w{the a by on for of are with just but and to the my in I  
> has some}
> 
> #stopwords = stopwords.match(/[A-Z,a-z]/)
> 
> words = text.scan(/\w+/)  
> keywords = words.select { |word| !stopwords.include?(word) }
> 
> puts keywords.join(’ ')  
> You probably figured this out by yourself. Anyway, get the stopwords  
> array in lowercase, like this:

stopwords.map!{|el| el.downcase}

This gets rid of the disturbing “I” in your stopwords.

“keywords = words.select { |word| !stopwords.include?(word) }”

Almost works. Adjust like this:

keywords = words.select { |word| !stopwords.include?(word.downcase)}

hth,

Siep
