Changeset View
Changeset View
Standalone View
Standalone View
src/utils/PhutilEditDistanceMatrix.php
<?php | <?php | ||||
/** | /** | ||||
* Compute edit distance between two scalar sequences. This class uses | * Compute edit distance between two scalar sequences. This class uses | ||||
* Levenshtein (or Damerau-Levenshtein) to compute the edit distance between | * Levenshtein (or Damerau-Levenshtein) to compute the edit distance between | ||||
* two inputs. The inputs are arrays containing any scalars (not just strings) | * two inputs. The inputs are arrays containing any scalars (not just strings) | ||||
* so it can be used with, e.g., utf8 sequences. | * so it can be used with, e.g., utf8 sequences. | ||||
* | * | ||||
* $matrix = id(new PhutilEditDistanceMatrix()) | * $matrix = (new PhutilEditDistanceMatrix()) | ||||
* ->setSequences(str_split('ran'), str_split('rat')); | * ->setSequences(str_split('ran'), str_split('rat')); | ||||
* | * | ||||
* $cost = $matrix->getEditDistance(); | * $cost = $matrix->getEditDistance(); | ||||
* | * | ||||
* Edit distance computation is slow and requires a large amount of memory; | * Edit distance computation is slow and requires a large amount of memory; | ||||
* both are roughly O(N * M) in the length of the strings. | * both are roughly O(N * M) in the length of the strings. | ||||
* | * | ||||
* You can customize the cost of insertions, deletions and replacements. By | * You can customize the cost of insertions, deletions and replacements. By | ||||
▲ Show 20 Lines • Show All 545 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0