edit-distance is a Python package that provides an implementation of the Optimal String Alignment (OSA) algorithm for calculating edit distances. The package leverages C++ extensions via Cython for improved performance.
- Calculate edit distances using the OSA algorithm.
- Enables custom weights for each edit operation.
- Find all edit paths resulting in the minimal OSA distance between strings.
- High-performance implementation using C++ and Cython.
- Easy integration into Python projects.
Ensure you have a C++ compiler installed. Then, clone the repository and install the package using:
pip install .
Alternatively, call setup.py
directly:
python setup.py build_ext --inplace
python setup.py install
For more details on the setup, see setup.py.
After installation, you can import and use the module in your Python code:
import editdistance.osa
# Example usage:
str1 = "kitten"
str2 = "sitting"
distance = editdistance.osa.calculate_distance(str1, str2, swap_weight=0.1)
print(f"The edit distance between '{{}}' and '{{}}' is {{}}".format(str1, str2, distance))
See examples located in examples directory.
The test suite is located in the tests directory. To run the tests, execute:
python -m unittest discover -v
This project is licensed under the MIT License. See the LICENSE file for details.