Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do advanced string comparison in Ruby?

I am trying to compare 2 paragraphs of strings the output of which has to be the percentage of similarity.

I have tried doing this using the diff method and some Natural Language Processing tools

Is there a better way of doing this in ruby?

like image 937
Avinasha Shastry Avatar asked Dec 17 '22 18:12

Avinasha Shastry


2 Answers

You may want to try the Levenshtein string distance algorithm for this. http://rubygems.org/gems/text has an implementation of this along with other helpful string comparison utils.

like image 99
Michael Papile Avatar answered Jan 06 '23 09:01

Michael Papile


See my similar Question here what I needed but did not know what it was called was a Levenshtein distance algorithm

like image 44
Paul Whelan Avatar answered Jan 06 '23 10:01

Paul Whelan