<?php // Calcul du coefficient de Dice // Inspiration: http://en.wikibooks.org/wiki... // Licence: Libre de droit function dice($str1='', $str2='') { $str1_length = strlen($str1); $str2_length = strlen($str2); // Length of the string must not be equal to zero if ( ($str1_length==0) OR ($str2_length==0) ) return 0; $ar1 = array(); $ar2 = array(); $intersection = 0; // find the pair of characters for ($i=0 ; $i<($str1_length-1) ; $i++) $ar1[] = substr($str1, $i, 2); for ($i=0 ; $i<($str2_length-1) ; $i++) $ar2[] = substr($str2, $i, 2); // find the intersection between the two sets foreach ($ar1 as $pair1) { foreach ($ar2 as $pair2) { if ($pair1 == $pair2) $intersection++; } } $count_set = count($ar1) + count($ar2); $dice = (2 * $intersection) / $count_set; return $dice; }
- guillaume chave
<?php // Calcul du coefficient de Dice // Inspiration: http://en.wikibooks.org/wiki... // Licence: Libre de droit function dice($str1='', $str2='') { $str1_length = strlen($str1); $str2_length = strlen($str2); // Length of the string must not be equal to zero if ( ($str1_length==0) OR ($str2_length==0) ) return 0; $ar1 = array(); $ar2 = array(); $intersection = 0; // find the pair of characters for ($i=0 ; $i<($str1_length-1) ; $i++) $ar1[] = substr($str1, $i, 2); for ($i=0 ; $i<($str2_length-1) ; $i++) $ar2[] = substr($str2, $i, 2); // find the intersection between the two sets foreach ($ar1 as $pair1) { foreach ($ar2 as $pair2) { if ($pair1 == $pair2) $intersection++; } } $count_set = count($ar1) + count($ar2); $dice = (2 * $intersection) / $count_set; return $dice; }
- guillaume chave