threedaymonk/text — pull request #8 by aramisbear (2012-05-09 14:12:16+00:00)
Title: Added a similarity function to Levenshtein

Since the distance is somewhat subjective, a percentage comparison seemed useful. The formula is very simple:

```ruby
def similarity(str1, str2)
dist = self.distance(str1,str2)
size = str1.length > str2.length ? str1.length : str2.length

return (size.to_f - dist.to_f) / size.to_f
end
```

The results were very comparable to White.similarity, with this variation showing what I believe to be more accurate results.

Here's a few for comparison (the numbers will vary slightly as I've swapped out the email and website addresses after the fact).

SAMPLE:
Am interested in your Item above,Please contact me at fake_email_address@example.com for more details and its present condition. Brian.
COMPARISON:
Am interested in your Item above,Please contact me at patricia.doe@example.com for more details and its present condition. Patricia.
Levenshtein: 19 / 135 : 0.8592592592592593
White: 0.8020304568527918

SAMPLE:
Am interested in your Item above,Please contact me at fake_email_address@example.com for more details and its present condition. Brian.
COMPARISON:
Goodday, Do you still have your item listed on www.example.com/ available?I hope it is in good condition like it stated because I have taken a close look at the advert and am completely satisfied,I would love to purchase it,I'll want you to remove the advert from web and consider this item is sold to me.My form of payment would be via Certified check,If this is Ok with you,I want you to get back to me with the following details: Your Full Name: Contact Physical Address not p.o box: City and State with Zip Code: Cell phone number: amount: And send your reply or any question directly to my email(EMAIL_REPLACED@yahoo.com)For quick response back cause i dont get on here much .
Levenshtein: 587 / 686 : 0.14431486880466474
White: 0.3071297989031079