Function that returns how similar two strings are
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?
Calculating the Levenshtein distance might do the trick.
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]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement