Ruby gem for comparing text

I am looking for a gem that can compare two lines (in this case, paragraphs of text) and be able to assess the likelihood that they are similar in content (maybe only a few words are rearranged, changed). I find that SO uses something like this when users ask questions.

+7
source share
1 answer

I would use, for example, Diff :: LCS:

>> require "diff/lcs" >> seq1 = "lorem ipsum dolor sit amet consequtor".split(" ") >> seq2 = "lorem ipsum dolor amet sit consequtor".split(" ") 1.9.3-p194 :010 > Diff::LCS.diff(seq1, seq2).length => 2 

It uses the longest general subsequence algorithm (the method of using LCS to get diff is described on the wiki page ).

+7
source

All Articles