{"id":13880302,"url":"https://github.com/GlobalNamesArchitecture/damerau-levenshtein","last_synced_at":"2025-07-16T16:31:32.981Z","repository":{"id":45648541,"uuid":"2085407","full_name":"GlobalNamesArchitecture/damerau-levenshtein","owner":"GlobalNamesArchitecture","description":"Calculates edit distance using Damerau-Levenshtein algorithm","archived":false,"fork":false,"pushed_at":"2024-10-03T09:41:06.000Z","size":657,"stargazers_count":146,"open_issues_count":2,"forks_count":19,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-26T09:53:09.543Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GlobalNamesArchitecture.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-07-21T19:54:26.000Z","updated_at":"2025-05-22T16:07:15.000Z","dependencies_parsed_at":"2022-09-04T01:41:50.614Z","dependency_job_id":null,"html_url":"https://github.com/GlobalNamesArchitecture/damerau-levenshtein","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/GlobalNamesArchitecture/damerau-levenshtein","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlobalNamesArchitecture%2Fdamerau-levenshtein","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlobalNamesArchitecture%2Fdamerau-levenshtein/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlobalNamesArchitecture%2Fdamerau-levenshtein/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlobalNamesArchitecture%2Fdamerau-levenshtein/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GlobalNamesArchitecture","download_url":"https://codeload.github.com/GlobalNamesArchitecture/damerau-levenshtein/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlobalNamesArchitecture%2Fdamerau-levenshtein/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265524632,"owners_count":23782016,"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":[],"created_at":"2024-08-06T08:02:55.836Z","updated_at":"2025-07-16T16:31:32.531Z","avatar_url":"https://github.com/GlobalNamesArchitecture.png","language":"Ruby","funding_links":[],"categories":["Ruby","NLP Pipeline Subtasks"],"sub_categories":["Semantic Analysis"],"readme":"# damerau-levenshtein\n\n[![DOI](https://zenodo.org/badge/2085407.svg)](https://zenodo.org/badge/latestdoi/2085407)\n[![Gem Version][gem_svg]][gem]\n[![Continuous Integration Status][ci_svg]][ci]\n[![Coverage Status][cov_svg]][cov]\n\nThe damerau-levenshtein gem allows to find [edit distance][ed] between two\nUTF-8 or ASCII encoded strings with O(N\\*M) efficiency.\n\nThis gem implements pure Levenshtein algorithm, Damerau modification of it\n(where 2 character transposition counts as 1 edit distance). It also includes\nBoehmer \u0026 Rees 2008 modification of Damerau algorithm, where transposition\nof bigger than 1 character blocks is taken in account as well\n[(Rees 2014)][rees2014].\n\n```ruby\nrequire \"damerau-levenshtein\"\nDamerauLevenshtein.distance(\"Something\", \"Smoething\") #returns 1\n```\n\nIt also returns a diff between two strings according to Levenshtein alrorithm.\nThe diff is expressed by tags `\u003cins\u003e`, `\u003cdel\u003e`, and `\u003csubst\u003e`. Such tags make\nit possible to highlight differnce between strings in a flexible way.\n\n```ruby\nrequire \"damerau-levenshtein\"\ndiffer = DamerauLevenshtein::Differ.new\ndiffer.run(\"corn\", \"cron\")\n# output: [\"c\u003csubst\u003eor\u003c/subst\u003en\", \"c\u003csubst\u003ero\u003c/subst\u003en\"]\n```\n\n## Dependencies\n\n```bash\nsudo apt-get install build-essential libgmp3-dev\n```\n\n## Installation\n\n```bash\ngem install damerau-levenshtein\n```\n\n## Examples\n\n```ruby\nrequire \"damerau-levenshtein\"\ndl = DamerauLevenshtein\n```\n\n* compare using Damerau Levenshtein algorithm\n\n```ruby\ndl.distance(\"Something\", \"Smoething\") #returns 1\n```\n\n* compare using Levensthein algorithm\n\n```ruby\ndl.distance(\"Something\", \"Smoething\", 0) #returns 2\n```\n\n* compare using Boehmer \u0026 Rees modification\n\n```ruby\ndl.distance(\"Something\", \"meSothing\", 2) #returns 2 instead of 4\n```\n\n* comparison of words with UTF-8 characters should work fine:\n\n```ruby\ndl.distance(\"Sjöstedt\", \"Sjostedt\") #returns 1\n```\n\n* compare two arrays\n\n```ruby\ndl.array_distance([1,2,3,5], [1,2,3,4]) #returns 1\n```\n\n* return diff between two strings\n\n```ruby\ndiffer = DamerauLevenshtein::Differ.new\ndiffer.run(\"Something\", \"smthg\")\n```\n\n* return diff between two strings in raw format\n\n```ruby\ndiffer = DamerauLevenshtein::Differ.new\ndiffer.format = :raw\ndiffer.run(\"Something\", \"smthg\")\n```\n\n## API Description\n\n### Methods\n\n#### DamerauLevenshtein.version\n\n```ruby\nDamerauLevenshtein.version\n#returns version number of the gem\n```\n\n#### DamerauLevenshtein.distance\n\n```ruby\nDamerauLevenshtein.distance(string1, string2, block_size, max_distance)\n#returns edit distance between 2 strings\n\nDamerauLevenshtein.string_distance(string1, string2, block_size, max_distance)\n# an alias for .distance\n\nDamerauLevenshtein.array_distance(array1, array2, block_size, max_distance)\n# returns edit distance between 2 arrays of integers\n```\n\n`DamerauLevenshtein.distance` and `.array_distance` take 4 arguments:\n\n* `string1` (`array1` for `.array_distance`)\n* `string2` (`array2` for `.array_distance`)\n* `block_size` (default is 1)\n* `max_distance` (default is 10)\n\n`block_size` determines maximum number of characters in a transposition block:\n\n```bash\nblock_size = 0\n(transposition does not count -- it is a pure Levenshtein algorithm)\n\nblock_size = 1\n(transposition between 2 adjustent characters --\nit is pure Damerau-Levenshtein algorithm)\n\nblock_size = 2\n(transposition between blocks as big as 2 characters -- so abcd and cdab\ncounts as edit distance 2, not 4)\n\nblock_size = 3\n(transposition between blocks as big as 3 characters --\nso abcdef and defabc counts as edit distance 3, not 6)\n\netc.\n```\n\n`max_distance` -- is a threshold after which algorithm gives up and\nreturns `max_distance` instead of real edit distance.\n\nLevenshtein algorithm is expensive, so it makes sense to give up when edit\ndistance is becoming too big. The argument max_distance does just that.\n\n```ruby\n\nDamerauLevenshtein.distance(\"abcdefg\", \"1234567\", 0, 3)\n# output: 4 -- it gave up when edit distance exceeded 3\n\n```\n\n#### DamerauLevenshtein::Differ\n\n`differ = DamerauLevenshtein::Differ.new` creates an instance of new differ\nclass to return difference between two strings\n\n`differ.format` shows current format for diff. Default is `:tag` format\n\n`differ.format = :raw` changes current format for diffs. Possible values\nare `:tag` and `:raw`\n\n`differ.run(\"String1\", \"String2\")` returns difference between two strings.\n\nFor example:\n\n```ruby\ndiffer = DamerauLevenshtein::Differ.new\ndiffer.run(\"Something\", \"smthng\")\n# output: [\"\u003cins\u003eS\u003c/ins\u003e\u003csubst\u003eo\u003c/subst\u003em\u003cins\u003ee\u003c/ins\u003eth\u003cins\u003ei\u003c/ins\u003eng\",\n#          \"\u003cdel\u003eS\u003c/del\u003e\u003csubst\u003es\u003c/subst\u003em\u003cdel\u003ee\u003c/del\u003eth\u003cdel\u003ei\u003c/del\u003eng\"]\n\n```\n\nOr with parsing:\n\n```ruby\nrequire \"damerau-levenshtein\"\nrequire \"nokogiri\"\n\ndiffer = DamerauLevenshtein::Differ.new\nres = differ.run(\"Something\", \"Smothing!\")\nnodes = Nokogiri::XML(\"\u003croot\u003e#{res.first}\u003c/root\u003e\")\n\nmarkup = nodes.root.children.map do |n|\n  case n.name\n  when \"text\"\n    n.text\n  when \"del\"\n    \"~~#{n.children.first.text}~~\"\n  when \"ins\"\n    \"*#{n.children.first.text}*\"\n  when \"subst\"\n    \"**#{n.children.first.text}**\"\n  end\nend.join(\"\")\n\nputs markup\n```\n\nOutput\n\n```text\nS*o*m**e**thing~~!~~\n```\n\n## Contributing to damerau-levenshtein\n\n* Check out the latest master to make sure the feature hasn't been\n  implemented or the bug hasn't been fixed yet\n* Check out the issue tracker to make sure someone already hasn't requested\n  it and/or contributed it\n* Fork the project\n* Start a feature/bugfix branch\n* Commit and push until you are happy with your contribution\n* Make sure to add tests for it. This is important so I don't break it\n  in a future version unintentionally.\n* Please try not to mess with the Rakefile, version, or history. If you want\n  to have your own version, or is otherwise necessary, that is fine, but please\n  isolate to its own commit so I can cherry-pick around it.\n\n## Versioning\n\nThis gem is following practices of [Semantic Versioning][semver]\n\n## Authors\n\n[Dmitry Mozzherin][dimus]\n\n## Contributors\n\n[Alexey Zapparov][ixti],\n[azhi][azhi],\n[Fabian Winkler][wynksaiddestroy]\n[Josephine Wright][jozr],\n[lazylester][lazylester],\n[Ran Xie][skarlit],\n[Victor Maslov][Nakilon],\n[Masafumi Koba][ybiquitous]\n\n## Copyright\n\nCopyright (c) 2011-2019 Dmitry Mozzherin. See LICENSE.txt for\nfurther details.\n\n[gem_svg]: https://badge.fury.io/rb/damerau-levenshtein.svg\n[gem]: http://badge.fury.io/rb/damerau-levenshtein\n[ci_svg]: https://github.com/GlobalNamesArchitecture/damerau-levenshtein/actions/workflows/ci.yml/badge.svg\n[ci]: https://github.com/GlobalNamesArchitecture/damerau-levenshtein/actions/workflows/ci.yml\n[dep_svg]: https://gemnasium.com/GlobalNamesArchitecture/damerau-levenshtein.svg\n[cov_svg]: https://coveralls.io/repos/GlobalNamesArchitecture/damerau-levenshtein/badge.svg?branch=master\n[cov]: https://coveralls.io/r/GlobalNamesArchitecture/damerau-levenshtein?branch=master\n[ed]: http://en.wikipedia.org/wiki/Edit_distance\n[semver]: http://semver.org/\n[dimus]: https://github.com/dimus\n[lazylester]: https://github.com/lazylester\n[skarlit]: https://github.com/Skarlit\n[ixti]: https://github.com/ixti\n[azhi]: https://github.com/azhi\n[jozr]: https://github.com/jozr\n[rees2014]: https://dx.doi.org/10.1371/journal.pone.0107510\n[Nakilon]: https://github.com/Nakilon\n[wynksaiddestroy]: https://github.com/wynksaiddestroy\n[ybiquitous]: https://github.com/ybiquitous\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGlobalNamesArchitecture%2Fdamerau-levenshtein","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGlobalNamesArchitecture%2Fdamerau-levenshtein","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGlobalNamesArchitecture%2Fdamerau-levenshtein/lists"}