How to Calculate Similarity Percentage with Levenshtein function

This is a discussion on How to Calculate Similarity Percentage with Levenshtein function within the PHP General forums, part of the PHP Programming Forums category; Hi, I'm trying to obtain the similarity percentage for 2 Strings when using the Levenshtein function but the percentages ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-10-2003
Gohaku
 
Posts: n/a
Default How to Calculate Similarity Percentage with Levenshtein function

Hi,
I'm trying to obtain the similarity percentage for 2 Strings when using
the Levenshtein function but the percentages doesn't seem to match the
percentage
returned by similar_text($str1,$str2,$match_percent);

Below is what I use to calculate the similarity percentage

$dist = levenshtein($str1,$str2);
$str1len = strlen($str1);
$str2len = strlen($str2);
if($str1len > $str2len)
{
$pct = ($str1len - $dist)/$str1len;
}
else
{
$pct = ($str2len - $dist)/$str2len;
}
$pct = $pct*100;

What am I missing from the calculation?

Thanks.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:12 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0