# String comparison in ruby

**URL:** <https://www.ruby-forum.com/t/string-comparison-in-ruby/232445>\
**Category:** Ruby\
**Created:** [October 9, 2014, 6:45pm UTC](https://www.ruby-forum.com/t/string-comparison-in-ruby/232445 "2014-10-09T18:45:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [October 9, 2014, 6:45pm UTC](https://www.ruby-forum.com/t/string-comparison-in-ruby/232445/1 "2014-10-09T18:45:47Z")

</div>

Hi all,

Is there any good gem to do string comparison so that the following will  
be considered the same even there are one or two words or spaces  
differences?

Thanks in advance.

string1=“A boy comes to see me this morning.”  
string2="A male comes to see me this morning. "

What codes should be written so that string1 is considered the same as  
string2?

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [October 10, 2014, 3:46pm UTC](https://www.ruby-forum.com/t/string-comparison-in-ruby/232445/2 "2014-10-10T15:46:38Z")

</div>

I don’t know of a gem. In general, that is a very hard problem. It  
first requires a dictionary that says “boy” is the same as “male”. Once  
you have that, the rest is not mega hard but it is still non-trivial.

I don’t know of a gem that can do that. One thought is to read  
something like Chapter 12 of the PostgreSQL documentation “Full Text  
Search”. Pick up some terms that are used in that problem space, and  
then do Google searches with those terms.

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [October 10, 2014, 6:14pm UTC](https://www.ruby-forum.com/t/string-comparison-in-ruby/232445/3 "2014-10-10T18:14:14Z")

</div>

If you are seeking similarity between strings, I’d suggest to read about  
measuring of Levenshtein distance  
([Levenshtein distance - Wikipedia](http://en.wikipedia.org/wiki/Levenshtein_distance)), if not already did.
