Skip to main content

A little package with string comparison tools

Project description

Curly Comparer

A lightweight Python package for advanced string comparison and distance calculation.

Overview

curly_comparer provides flexible string comparison algorithms, primarily focusing on Levenshtein distance calculations with customizable cost functions.

Features

  • Basic Levenshtein Distance: Quick string comparison
  • Weighted Levenshtein Distance: Customizable cost functions for:
    • Character insertions
    • Character deletions
    • Character substitutions

Installation

Install curly_comparer using pip:

pip install curly_comparer

Requirements

  • Python 3.10+
  • NumPy 2.1+

Usage

Basic Levenshtein Distance

from curly_comparer.algorithms.levenshtein import distace

# Calculate distance between two strings
distance = distace("hello", "hallo")
print(distance)  # Outputs: 1

Weighted Levenshtein Distance

from curly_comparer.algorithms.levenshtein import weighted_distance

# Custom cost functions
def custom_insertion_cost(char):
    return 1.5  # Different cost for inserting characters

def custom_substitution_cost(char1, char2):
    return 2.0  # Custom substitution cost

distance = weighted_distance(
    "hello", 
    "hallo", 
    insertion_fn=custom_insertion_cost,
    deletion_fn=lambda x: 1.0,
    subs_fn=custom_substitution_cost
)

Advanced Customization

The weighted_distance function allows complete flexibility in defining costs for string transformations:

  • insertion_fn: Cost of inserting a character
  • deletion_fn: Cost of deleting a character
  • subs_fn: Cost of substituting one character for another

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

Licensed under the Apache License 2.0

Author

Pedro Lopez (pdihax@gmail.com)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

curly_comparer-0.1.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

curly_comparer-0.1.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file curly_comparer-0.1.1.tar.gz.

File metadata

  • Download URL: curly_comparer-0.1.1.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for curly_comparer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ec2794377ef42596eb27528e009b9f32c03a4c02b6c950be01c188b2b3909083
MD5 c58b9acc3ca2093459f5102c2f9a3794
BLAKE2b-256 f7e487bfe21496527023697725f5aa02ca523708ffe28ca8ed800b2d14f9f5a2

See more details on using hashes here.

File details

Details for the file curly_comparer-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: curly_comparer-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for curly_comparer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6deef92160c7770d0e298ad96ad9038c8cfc572ad59ece2698bcfc0d61f6fed8
MD5 85e6fcab8bca35cf6c59c6e666dd080d
BLAKE2b-256 0053cdb0aea473786c08eec3513ec9aed7736f6532f5a0bab91d5bb3d70ffc05

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page