Revision: 34071
Updated Code
at October 17, 2010 21:09 by voodoochilo
Updated Code
<?php
/*----------------------------------------------------------------------------
PhpDiceCoeff - An Implementation of the Dice-Coefficient in PHP
Version 0.0.01a
(C)2010 by Emil Endgut
==============================================================
This is Friendware, which means that you may use it as if you
wrote it, after you became a friend of mine on Facebook.
Please Visit:
http://www.facebook.com/profile.php?id=100001062124472
==============================================================
Usage:
php dice.php "stringA" "stringB"
----------------------------------------------------------------------------*/
$str_a =$argv[1];
$str_b =$argv[2];
echo "dice(\"".$str_a . "\", \"". $str_b. "\") = " . dice($str_a, $str_b) . "\n";
function dice($a, $b)
{
$az=zerleg($a);
$ac=count($az);
$bz=zerleg($b);
$bc=count($bz);
$is=array_intersect($az, $bz);
$ic=count($is);
return 2 * $ic / ($ac + $bc);
}
function zerleg($str)
{
$a=strtolower($str);
$len=strlen($a);
for($n=2;$n<$len;$n++)
for($i=0 ; $i+$n<=$len ; $i++)
$arr[]=substr($a,$i,$n);
return $arr;
}
?>
Revision: 34070
Updated Code
at October 17, 2010 21:06 by voodoochilo
Updated Code
<?php
/*----------------------------------------------------------------------------
PhpDiceCoeff - An Implementation of the Dice-Coefficient in PHP
Version 0.0.01a
(C)2010 by Emil Endgut
==============================================================
This is Friendware, which means that you may use it as if you
wrote it, after you became a friend of mine on Facebook.
Please Visit:
http://www.facebook.com/profile.php?id=100001062124472
==============================================================
Usage:
php dice.php "stringA" "stringB"
----------------------------------------------------------------------------*/
$str_a =$argv[1];
$str_b =$argv[2];
echo "dice(\"".$str_a . "\", \"". $str_b. "\") = " . dice($str_a, $str_b) . "\n";
function dice($a, $b)
{
$az=zerleg($a);
$ac=count($az);
$bz=zerleg($b);
$bc=count($bz);
$is=array_intersect($az, $bz);
$ic=count($is);
return 2 * $ic / ($ac + $bc);
}
function zerleg($str)
{
$a=strtolower($str);
$len=strlen($a);
for($n=2;$n<$len;$n++)
for($i=0 ; $i+$n<=$len ; $i++){
$arr[]=substr($a,$i,$n);
return $arr;
}
?>
Revision: 34069
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 16, 2010 12:17 by voodoochilo
Initial Code
<?php
/*----------------------------------------------------------------------------
PhpDiceCoeff - An Implementation of the Dice-Coefficient in PHP
Version 0.0.01a
(C)2010 by Emil Endgut
==============================================================
This is Friendware, which means that you may use it as if you
wrote it, after you became a friend of mine on Facebook.
Please Visit:
http://www.facebook.com/profile.php?id=100001062124472
==============================================================
Usage:
php dice.php "stringA" "stringB"
----------------------------------------------------------------------------*/
$str_a =$argv[1];
$str_b =$argv[2];
echo "dice(\"".$str_a . "\", \"". $str_b. "\") = " . dice($str_a, $str_b) . "\n";
function dice($a, $b)
{
$az=zerleg($a);
$ac=count($az);
$bz=zerleg($b);
$bc=count($bz);
$is=array_intersect($az, $bz);
$ic=count($is);
return 2 * $ic / ($ac + $bc);
}
function zerleg($str)
{
$len=strlen($str);
$str=strtolower($str);
for($n=2 ; $n<$len ; $n++)
for($a=0,$l=$n ; $a+$l<=$len ; $a++)
$arr[]=substr($str,$a,$l);
return $arr;
}
?>
Initial URL
Initial Description
Initial Title
Dice Coefficient in PHP
Initial Tags
Initial Language
PHP