or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/python-levenshtein@0.27.x
tile.json

tessl/pypi-python-levenshtein

tessl install tessl/pypi-python-levenshtein@0.27.0

Python compatibility wrapper for computing string edit distances and similarities using fast Levenshtein algorithms.

Agent Success

Agent success rate when using this tile

88%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.38x

Baseline

Agent success rate without this tile

64%

task.mdevals/scenario-10/

Weighted String Comparator

A utility for computing edit distances between strings with custom operation costs.

Context

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.

Capabilities

Computes distance with uniform costs

  • Given strings "kitten" and "sitting", with all costs set to 1, returns distance 3 @test
  • Given identical strings "hello" and "hello", returns distance 0 @test

Applies custom substitution costs

  • Given strings "abc" and "adc", with substitution cost 5 and other costs 1, returns distance 5 @test
  • Given strings "abc" and "adc", with substitution cost 1 and insertion/deletion costs 10, returns distance 1 @test

Applies custom insertion costs

  • Given strings "abc" and "abcd", with insertion cost 3 and other costs 1, returns distance 3 @test

Applies custom deletion costs

  • Given strings "abcd" and "abc", with deletion cost 5 and other costs 1, returns distance 5 @test

Handles combined custom costs

  • Given strings "fast" and "cats", with insertion cost 2, deletion cost 3, and substitution cost 1, computes the minimum weighted distance @test

Implementation

@generates

API

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
    """
    pass

Dependencies { .dependencies }

python-Levenshtein { .dependency }

Provides fast string distance computation with support for custom edit costs.

@satisfied-by