Install pyxDamerauLevenshtein via pip
masterInstall the package using pip. Note that this project requires Python 3.9+, a C compiler (such as GCC), and Cython to build the high-performance Cython implementation.
pip install pyxDamerauLevenshteinrepository·master·Indexed 42 days ago
https://github.com/lanl/pyxdameraulevenshteinA high-performance Python implementation of the Damerau-Levenshtein edit distance algorithm written in Cython. Version 1.10.1 provides raw and normalized distance metrics for single sequences or batches of sequences, supporting types such as str, list, tuple, and range.
Install the package using pip. Note that this project requires Python 3.9+, a C compiler (such as GCC), and Cython to build the high-performance Cython implementation.
pip install pyxDamerauLevenshteinUse damerau_levenshtein_distance(seq1, seq2, max_distance=None) to compute the minimum number of operations (insertion, deletion, substitution, or transposition) required to transform one sequence into another.
str, list, tuple, range, and more.max_distance integer, the function will short-circuit and return max_distance + 1 if the true distance exceeds the threshold, avoiding unnecessary computation.from pyxdameraulevenshtein import damerau_levenshtein_distance
# Basic usage
damerau_levenshtein_distance('smtih', 'smith') # returns 1
# Using a threshold for short-circuiting
damerau_levenshtein_distance('saturday', 'sunday', max_distance=2) # returns 3
# Works with non-string sequences
damerau_levenshtein_distance([1, 2, 3, 4, 5, 6], [7, 8, 9, 7, 10, 11, 4]) # returns 7Use normalized_damerau_levenshtein_distance(seq1, seq2) to compute the ratio of the edit distance to the length of the longer sequence.
difflib.SequenceMatcher.ratio().from pyxdameraulevenshtein import normalized_damerau_levenshtein_distance
normalized_damerau_levenshtein_distance('smtih', 'smith') # returns 0.2If you need to compare one sequence against multiple other sequences (e.g., a list of strings), use the _seqs variants of the API. These functions return a collection of distances corresponding to each element in the target sequence.
damerau_levenshtein_distance_seqs(seq, seqs, max_distance=None): Returns raw distances.normalized_damerau_levenshtein_distance_seqs(seq, seqs): Returns normalized distance ratios.from pyxdameraulevenshtein import damerau_levenshtein_distance_seqs, normalized_damerau_levenshtein_distance_seqs
array = ['test1', 'test12', 'test123']
# Raw distances
damerau_levenshtein_distance_seqs('test', array) # returns [1, 2, 3]
# Normalized distances
normalized_damerau_levenshtein_distance_seqs('test', array) # returns [0.2, 0.3333333333333333, 0.42857142857142855]