Function that returns how similar two strings are

Started by
2 comments, last by Prozak 18 years, 6 months ago
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?
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]
Jooleem. Get addicted.
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 :)
Thanks, Rate++!

I found this, tailored for PHP and everything [wink]

This topic is closed to new replies.

Advertisement