Python compatibility wrapper for computing string edit distances and similarities using fast Levenshtein algorithms.
88
A utility for computing edit distances between strings with custom operation costs.
Different text correction scenarios require different cost models. For example, in spell-checking, character substitutions might be cheaper than insertions or deletions. In data entry validation, deleting characters might be costlier than adding them. This tool allows configuring custom costs for each edit operation.
@generates
def weighted_distance(str1: str, str2: str, insertion_cost: int = 1, deletion_cost: int = 1, substitution_cost: int = 1) -> int:
"""
Calculate the edit distance between two strings using custom operation costs.
Args:
str1: First string to compare
str2: Second string to compare
insertion_cost: Cost for inserting a character (default 1)
deletion_cost: Cost for deleting a character (default 1)
substitution_cost: Cost for substituting a character (default 1)
Returns:
Integer representing the minimum weighted cost to transform str1 into str2
"""
passProvides fast string distance computation with support for custom edit costs.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/pypi-python-levenshteindocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10