19 declare(strict_types=1);
84 protected function levenshtein(
string $secondary_string): float
89 $primary_string_length = count($primary_string_array);
90 $secondary_string_length = count($secondary_string_array);
94 if (abs($primary_string_length - $secondary_string_length) > $this->maximum_distance && $this->maximum_distance != 0) {
99 $current_row[0] = 0.0;
100 for ($j = 1; $j < $secondary_string_length + 1; $j++) {
104 $cost_matrix[0] = $current_row;
105 for (
$i = 0;
$i < $primary_string_length;
$i++) {
107 $current_row[0] = (
$i + 1) * $this->cost_deletion;
108 for ($j = 0; $j < $secondary_string_length; $j++) {
109 $current_row[$j + 1] = min(
110 $cost_matrix[
$i][$j + 1] + $this->cost_deletion,
111 $current_row[$j] + $this->cost_insertion,
112 $cost_matrix[
$i][$j] + ($primary_string_array[
$i] === $secondary_string_array[$j] ? 0.0 : $this->cost_replacement)
116 if (min($current_row) > $this->maximum_distance && $this->maximum_distance != 0) {
119 $cost_matrix[
$i + 1] = $current_row;
121 if ($cost_matrix[$primary_string_length][$secondary_string_length] > $this->maximum_distance && $this->maximum_distance != 0) {
124 return $cost_matrix[$primary_string_length][$secondary_string_length];
136 $character_array = [];
140 return $character_array;
155 if (!is_string($from)) {
static subStr($a_str, $a_start, $a_length=null)
trait DeriveApplyToFromTransform
trait DeriveInvokeFromTransform