Strsimpy is a Python library that provides implementations for various string similarity and distance measures, including popular algorithms like Levenshtein, Jaro-Winkler, N-Gram, Cosine Similarity, and Jaccard Index. It's designed to be straightforward to use for text analysis and data matching tasks. The current version is 0.2.1. Releases are infrequent, typically addressing bug fixes or adding new algorithms.
pip install strsimpyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates calculating Levenshtein distance and Jaro-Winkler similarity between strings. Most algorithms follow a pattern of instantiating a class and then calling a `distance()` or `similarity()` method.
Update all `import similarity...` statements to `import strsimpy...` and reinstall the package.
Review the documentation for `WeightedLevenshtein` and update your weight calculation logic to use direct functions as arguments, rather than class instances.
If your project requires `numpy`, ensure it is explicitly listed in your project's dependencies.
Upgrade to version 0.1.2 or later to ensure correct calculations and avoid potential runtime errors with ShingleBased algorithms.
from strsimpy.similarity.jarowinkler import JaroWinkler
from strsimpy.similarity.jarowinkler import JaroWinkler jarowinkler_sim = JaroWinkler()
s1 = str(s1) if s1 is not None else '' s2 = str(s2) if s2 is not None else '' similarity_score = your_similarity_object.similarity(s1, s2)
from strsimpy.similarity.ngram import NGram ngram_sim = NGram(n=2) # Specify 'n' for bigrams, trigrams, etc.
No dependency data recorded yet.