Id like to compare two strings in Ruby and find their similarity
I’ve had a look at the Levenshtein gem but it seems this was last updated in 2008 and I can’t find documentation how to use it. With some blogs suggesting its broken
I tried the text gem with Levenshtein but it gives an integer (smaller is better)
Obviously if the two strings are of variable length I run into problems with the Levenshtein Algorithm (Say comparing two names, where one has a middle name and one doesnt).
What would you suggest I do to get a percentage comparison?
Edit: Im looking for something similar to PHP’s similar text
I think your question could do with some clarifications, but here’s something quick and dirty (calculating as percentage of the longer string as per your clarification above):
I’m still not sure how much sense this percent difference you are looking for makes, but this should get you started at least.
It’s a bit like Levensthein distance, in that it compares the strings character by character. So if two names differ only by the middle name, they’ll actually be very different.