LexicalDistance
in package
Computes the lexical distance between strings A and B.
The "distance" between two strings is given by counting the minimum number of edits needed to transform string A into string B. An edit can be an insertion, deletion, or substitution of a single character, or a swap of two adjacent characters.
Includes a custom alteration from Damerau-Levenshtein to treat case changes as a single edit which helps identify mis-cased values with an edit distance of 1.
This distance can be useful for detecting typos in input or sorting
Unlike the native levenshtein() function that always returns int, LexicalDistance::measure() returns int|null. It takes into account the threshold and returns null if the measured distance is bigger.
Table of Contents
- $input : string
- $inputArray : array<string|int, mixed>
- List of char codes in the input string.
- $inputLowerCase : string
- __construct() : mixed
- measure() : int|null
- stringToArray() : array<string|int, int>
- Returns a list of char codes in the given string.
Properties
$input
private
string
$input
$inputArray
List of char codes in the input string.
private
array<string|int, mixed>
$inputArray
$inputLowerCase
private
string
$inputLowerCase
Methods
__construct()
public
__construct(string $input) : mixed
Parameters
- $input : string
Return values
mixed —measure()
public
measure(string $option, float $threshold) : int|null
Parameters
- $option : string
- $threshold : float
Return values
int|null —stringToArray()
Returns a list of char codes in the given string.
private
static stringToArray(string $str) : array<string|int, int>
Parameters
- $str : string
