{"id":13856978,"url":"https://github.com/lanl/pyxDamerauLevenshtein","last_synced_at":"2025-07-13T19:33:34.359Z","repository":{"id":45041965,"uuid":"9456338","full_name":"lanl/pyxDamerauLevenshtein","owner":"lanl","description":"pyxDamerauLevenshtein implements the Damerau-Levenshtein (DL) edit distance algorithm for Python in Cython for high performance.","archived":false,"fork":false,"pushed_at":"2023-04-17T17:39:05.000Z","size":565,"stargazers_count":237,"open_issues_count":4,"forks_count":31,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-04-10T06:10:58.654Z","etag":null,"topics":["cython","damerau-levenshtein","edit-distance-algorithm"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lanl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2013-04-15T19:21:04.000Z","updated_at":"2024-03-19T12:13:36.000Z","dependencies_parsed_at":"2023-09-26T03:39:52.521Z","dependency_job_id":null,"html_url":"https://github.com/lanl/pyxDamerauLevenshtein","commit_stats":{"total_commits":132,"total_committers":13,"mean_commits":"10.153846153846153","dds":"0.18939393939393945","last_synced_commit":"84575c5ae726575cfa55072092628c949c903a04"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lanl%2FpyxDamerauLevenshtein","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lanl%2FpyxDamerauLevenshtein/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lanl%2FpyxDamerauLevenshtein/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lanl%2FpyxDamerauLevenshtein/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lanl","download_url":"https://codeload.github.com/lanl/pyxDamerauLevenshtein/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225912438,"owners_count":17544176,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cython","damerau-levenshtein","edit-distance-algorithm"],"created_at":"2024-08-05T03:01:21.099Z","updated_at":"2024-11-22T14:31:33.941Z","avatar_url":"https://github.com/lanl.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# pyxDamerauLevenshtein\n\n[![Build Status](https://app.travis-ci.com/lanl/pyxDamerauLevenshtein.svg?branch=master)](https://app.travis-ci.com/lanl/pyxDamerauLevenshtein)\n\n## LICENSE\nThis software is licensed under the [BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause). Please refer to the separate [LICENSE](LICENSE) file for the exact text of the license. You are obligated to give attribution if you use this code.\n\n## ABOUT\npyxDamerauLevenshtein implements the Damerau-Levenshtein (DL) edit distance algorithm for Python in Cython for high performance. Courtesy [Wikipedia](http://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance):\n\n\u003e In information theory and computer science, the Damerau-Levenshtein distance (named after Frederick J. Damerau and Vladimir I. Levenshtein) is a \"distance\" (string metric) between two strings, i.e., finite sequence of symbols, given by counting the minimum number of operations needed to transform one string into the other, where an operation is defined as an insertion, deletion, or substitution of a single character, or a transposition of two adjacent characters.\n\nThis implementation is based on [Michael Homer's pure Python implementation](https://web.archive.org/web/20150909134357/http://mwh.geek.nz:80/2009/04/26/python-damerau-levenshtein-distance/), which implements the [optimal string alignment distance algorithm](https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance#Optimal_string_alignment_distance). It runs in `O(N*M)` time using `O(M)` space. It supports unicode characters.\n\n## REQUIREMENTS\nThis code requires Python 3.8+, C compiler such as GCC, and Cython.\n\n## INSTALL\npyxDamerauLevenshtein is available on PyPI at https://pypi.org/project/pyxDamerauLevenshtein/.\n\nInstall using [pip](https://pypi.org/project/pip/):\n\n    pip install pyxDamerauLevenshtein\n\nInstall from source:\n\n    pip install .\n\n## USING THIS CODE\nThe following methods are available:\n\n* **Edit distance** (`damerau_levenshtein_distance`)\n    * Compute the raw distance between two strings (i.e., the minumum number of operations necessary to transform one string into the other).\n    * Additionally, the distance between lists and tuples can also be computed.\n\n* **Normalized edit distance** (`normalized_damerau_levenshtein_distance`)\n    * Compute the ratio of the edit distance to the length of `max(string1, string2)`. 0.0 means that the sequences are identical, while 1.0 means that they have nothing in common. Note that this definition is the exact opposite of [`difflib.SequenceMatcher.ratio()`](https://docs.python.org/3/library/difflib.html#difflib.SequenceMatcher.ratio).\n\n* **Edit distance against a sequence of sequences** (`damerau_levenshtein_distance_seqs`)\n    * Compute the raw distances between a sequence and each sequence within another sequence (e.g., `list`, `tuple`).\n\n* **Normalized edit distance against a sequence of sequences** (`normalized_damerau_levenshtein_distance_seqs`)\n    * Compute the normalized distances between a sequence and each sequence within another sequence (e.g., `list`, `tuple`).\n\nBasic use:\n\n```python\nfrom pyxdameraulevenshtein import damerau_levenshtein_distance, normalized_damerau_levenshtein_distance\ndamerau_levenshtein_distance('smtih', 'smith')  # expected result: 1\nnormalized_damerau_levenshtein_distance('smtih', 'smith')  # expected result: 0.2\ndamerau_levenshtein_distance([1, 2, 3, 4, 5, 6], [7, 8, 9, 7, 10, 11, 4])  # expected result: 7\n\nfrom pyxdameraulevenshtein import damerau_levenshtein_distance_seqs, normalized_damerau_levenshtein_distance_seqs\narray = ['test1', 'test12', 'test123']\ndamerau_levenshtein_distance_seqs('test', array)  # expected result: [1, 2, 3]\nnormalized_damerau_levenshtein_distance_seqs('test', array)  # expected result: [0.2, 0.33333334, 0.42857143]\n```\n\n## DIFFERENCES\nOther Python DL implementations:\n\n* [Michael Homer's native Python code](https://web.archive.org/web/20150909134357/http://mwh.geek.nz:80/2009/04/26/python-damerau-levenshtein-distance/)\n* [jellyfish](https://github.com/sunlightlabs/jellyfish)\n\npyxDamerauLevenshtein differs from other Python implementations in that it is both fast via Cython *and* supports unicode. Michael Homer's implementation is fast for Python, but it is *two orders of magnitude* slower than this Cython implementation. jellyfish provides C implementations for a variety of string comparison metrics and is sometimes faster than pyxDamerauLevenshtein.\n\nPython's built-in [`difflib.SequenceMatcher.ratio()`](https://docs.python.org/3/library/difflib.html#difflib.SequenceMatcher.ratio) performs about an order of magnitude faster than Michael Homer's implementation but is still one order of magnitude slower than this DL implementation. difflib, however, uses a different algorithm (difflib uses the [Ratcliff/Obershelp algorithm](http://www.drdobbs.com/database/pattern-matching-the-gestalt-approach/184407970)).\n\nPerformance differences (on Intel i7-2600 running at 3.4Ghz):\n\n    \u003e\u003e\u003e import timeit\n    \u003e\u003e\u003e #this implementation:\n    ... timeit.timeit(\"damerau_levenshtein_distance('e0zdvfb840174ut74j2v7gabx1 5bs', 'qpk5vei 4tzo0bglx8rl7e 2h4uei7')\", 'from pyxdameraulevenshtein import damerau_levenshtein_distance', number=500000)\n    7.417556047439575\n    \u003e\u003e\u003e #Michael Homer's native Python implementation:\n    ... timeit.timeit(\"dameraulevenshtein('e0zdvfb840174ut74j2v7gabx1 5bs', 'qpk5vei 4tzo0bglx8rl7e 2h4uei7')\", 'from dameraulevenshtein import dameraulevenshtein', number=500000)\n    667.0276439189911\n    \u003e\u003e\u003e #difflib\n    ... timeit.timeit(\"difflib.SequenceMatcher(None, 'e0zdvfb840174ut74j2v7gabx1 5bs', 'qpk5vei 4tzo0bglx8rl7e 2h4uei7').ratio()\", 'import difflib', number=500000)\n    135.41051697731018\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flanl%2FpyxDamerauLevenshtein","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flanl%2FpyxDamerauLevenshtein","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flanl%2FpyxDamerauLevenshtein/lists"}