19 declare(strict_types=1);
53 string $primary_string =
'',
54 int $maximum_distance = 0,
55 float $cost_insertion = 1.0,
56 float $cost_replacement = 1.0,
57 float $cost_deletion = 1.0
79 protected function levenshtein(
string $secondary_string): float
84 $primary_string_length = count($primary_string_array);
85 $secondary_string_length = count($secondary_string_array);
89 if ($this->maximum_distance !== 0 && abs($primary_string_length - $secondary_string_length) > $this->maximum_distance) {
94 $current_row[0] = 0.0;
95 for ($j = 1; $j < $secondary_string_length + 1; $j++) {
99 $cost_matrix[0] = $current_row;
100 for ($i = 0; $i < $primary_string_length; $i++) {
102 $current_row[0] = ($i + 1) * $this->cost_deletion;
103 for ($j = 0; $j < $secondary_string_length; $j++) {
104 $current_row[$j + 1] = min(
105 $cost_matrix[$i][$j + 1] + $this->cost_deletion,
106 $current_row[$j] + $this->cost_insertion,
107 $cost_matrix[$i][$j] + ($primary_string_array[$i] === $secondary_string_array[$j] ? 0.0 : $this->cost_replacement)
111 if ($this->maximum_distance !== 0 && min($current_row) > $this->maximum_distance) {
114 $cost_matrix[$i + 1] = $current_row;
116 if ($cost_matrix[$primary_string_length][$secondary_string_length] > $this->maximum_distance && $this->maximum_distance != 0) {
119 return $cost_matrix[$primary_string_length][$secondary_string_length];
131 $character_array = [];
132 for ($index = 0; $index < $length; $index++) {
133 $character_array[$index] =
ilStr::subStr($string_to_convert, $index, 1);
135 return $character_array;
149 if (!is_string($from)) {
trait DeriveInvokeFromTransform
trait DeriveApplyToFromTransform
static subStr(string $a_str, int $a_start, ?int $a_length=null)
static strLen(string $a_string)