Jump to content
  • Advertisement
Sign in to follow this  
Prozak

Function that returns how similar two strings are

This topic is 4730 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there an algorithm that returns a number, more or less specifying how similar two strings are? I'm writing a PHP page on my website that detects when you've hit a page that no longer exists (404), and suggests a few possible pages that might take you to where you originally would have wanted to go. But in order to do that I have to go beyond a simple string compare function, I need some sort of hash function that returns to me a number that defines the level of similarity between two strings, like: user fell on: "art.php" suggest page: "articles.php" Does anyone know such an algorithm?

Share this post


Link to post
Share on other sites
Advertisement
Calculating the Levenshtein distance might do the trick.
Quote:

In information theory, the Levenshtein distance or edit distance between two strings is given by the minimum number of operations needed to transform one string into the other, where an operation is an insertion, deletion, or substitution.

The Wikipedia page contains some pseudo-code, and you can find implementations in several languages here.

[Edited by - Peregrin on October 10, 2005 10:42:48 AM]

Share this post


Link to post
Share on other sites
I googled this page and this page for you(query other query). They may not be what you want. It sounds a bit like dna-pattern matching so there will be plenty more info on it. The trick is to come up with the proper queries :)

Tom

EDIT: or just use the Wikipedia one :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!