String
extension String
-
Get distance between target. (alias of
distanceJaroWinkler(between:)
.)Declaration
Swift
public func distance(between target: String) -> Double
Parameters
target
The target
String
.Return Value
The Jaro-Winkler distance between the receiver and
target
. -
Get Damerau-Levenshtein distance.
Declaration
Swift
public func distanceDamerauLevenshtein(between target: String) -> Int
Parameters
target
The target
String
.Return Value
The Damerau-Levenshtein distance between the receiver and
target
. -
Get Hamming distance.
Note: Only applicable when string lengths are equal.
Declaration
Swift
public func distanceHamming(between target: String) -> Int
Parameters
target
The target
String
.Return Value
The Hamming distance between the receiver and
target
. -
Get Jaro-Winkler distance.
(Score is normalized such that 0 equates to no similarity and 1 is an exact match).
Reference https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance
Declaration
Swift
public func distanceJaroWinkler(between target: String) -> Double
Parameters
target
The target
String
.Return Value
The Jaro-Winkler distance between the receiver and
target
. -
Get the Levenshtein distance.
Reference https://en.wikipedia.org/wiki/Levenshtein_distance#Iterative_with_two_matrix_rows
Declaration
Swift
public func distanceLevenshtein(between target: String) -> Int
Parameters
target
The target
String
.Return Value
The Levenshtein distance between the receiver and
target
. -
Get most frequent K distance.
Reference https://web.archive.org/web/20191117082524/https://en.wikipedia.org/wiki/Most_frequent_k_characters
Declaration
Swift
public func distanceMostFreqK(between target: String, K: Int, maxDistance: Int = 10) -> Int
Parameters
target
The target
String
.K
The number of most frequently occuring characters to use for the similarity comparison.
maxDistance
The maximum distance limit (defaults to a value of 10 if not provided).
-
Get normalized most frequent K distance.
(Score is normalized such that 0 equates to no similarity and 1 is an exact match).
Declaration
Swift
public func distanceNormalizedMostFrequentK(between target: String, k: Int) -> Double
Parameters
target
The target
String
.k
The number of most frequently occuring characters to use for the similarity comparison.
Return Value
The normalized most frequent K distance between the receiver and
target
.