Class with algorithm-specific params for customizing.
Class instance with default params for quick and simple usage.
All algorithms have some common methods:
.distance(*sequences) -- calculate distance between sequences.
.similarity(*sequences) -- calculate similarity for sequences.
.maximum(*sequences) -- maximum possible value for distance and similarity. For any sequence: distance + similarity == maximum.
.normalized_distance(*sequences) -- normalized distance between sequences. The return value is a float between 0 and 1, where 0 means equal, and 1 totally different.
.normalized_similarity(*sequences) -- normalized similarity for sequences. The return value is a float between 0 and 1, where 0 means totally different, and 1 equal.
Most common init arguments:
qval -- q-value for split sequences into q-grams. Possible values:
For main algorithms textdistance try to call known external libraries (fastest first) if available (installed in your system) and possible (this implementation can compare this type of sequences). Install textdistance with extras for this feature.
You can disable this by passing external=False argument on init:
TextDistance show benchmarks results table for your system and save libraries priorities into libraries.json file in TextDistance's folder. This file will be used by textdistance for calling fastest algorithm implementation. Default libraries.json already included in package.
Running tests
All you need is task. See Taskfile.yml for the list of available commands. For example, to run tests including third-party libraries usage, execute task pytest-external:run.
Contributing
PRs are welcome!
Found a bug? Fix it!
Want to add more algorithms? Sure! Just make it with the same interface as other algorithms in the lib and add some tests.
Can make something faster? Great! Just avoid external dependencies and remember that everything should work not only with strings.
Something else that do you think is good? Do it! Just make sure that CI passes and everything from the README is still applicable (interface, features, and so on).
Have no time to code? Tell your friends and subscribers about textdistance. More users, more contributions, more amazing features.
Thank you :heart:
Alternatives
Use instead of textdistance: tools that do the same job, closest first.