{"id":16950624,"url":"https://github.com/vcaesar/leven","last_synced_at":"2025-08-01T04:17:04.496Z","repository":{"id":47275018,"uuid":"287050040","full_name":"vcaesar/leven","owner":"vcaesar","description":"Go calculate Levenshtein Distance.","archived":false,"fork":false,"pushed_at":"2021-09-05T15:47:39.000Z","size":73,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-26T07:11:22.681Z","etag":null,"topics":["go","golang","levenshtein","levenshtein-distance"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vcaesar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-12T15:29:15.000Z","updated_at":"2021-09-05T15:47:41.000Z","dependencies_parsed_at":"2022-09-03T23:12:02.312Z","dependency_job_id":null,"html_url":"https://github.com/vcaesar/leven","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vcaesar%2Fleven","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vcaesar%2Fleven/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vcaesar%2Fleven/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vcaesar%2Fleven/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vcaesar","download_url":"https://codeload.github.com/vcaesar/leven/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244780335,"owners_count":20509346,"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":["go","golang","levenshtein","levenshtein-distance"],"created_at":"2024-10-13T21:58:09.393Z","updated_at":"2025-03-21T10:41:27.384Z","avatar_url":"https://github.com/vcaesar.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Go package for calculating the Levenshtein distance between two strings\n\n[![Build Status](https://github.com/vcaesar/leven/workflows/Go/badge.svg)](https://github.com/vcaesar/leven/commits/master)\n[![CircleCI Status](https://circleci.com/gh/vcaesar/leven.svg?style=shield)](https://circleci.com/gh/vcaesar/leven)\n[![codecov](https://codecov.io/gh/vcaesar/leven/branch/master/graph/badge.svg)](https://codecov.io/gh/vcaesar/leven)\n[![Build Status](https://travis-ci.org/vcaesar/leven.svg?branch=master\u0026style=flat)](https://travis-ci.org/vcaesar/leven)\n\u003c!-- [![Coverage Status](https://coveralls.io/repos/github/vcaesar/leven/badge.svg?style=flat)](https://coveralls.io/github/vcaesar/leven) --\u003e\n[![Go Report Card](https://goreportcard.com/badge/github.com/vcaesar/leven?style=flat)](https://goreportcard.com/report/github.com/vcaesar/leven)\n[![Release](https://img.shields.io/github/release/vcaesar/leven.svg?style=flat)](https://github.com/vcaesar/leven/releases/latest)\n[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/vcaesar/leven) \n\nThis package implements distance and similarity metrics for strings, based on the Levenshtein measure, in [Go](http://golang.org).\n\n## Use\n```Go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/go-ego/gse\"\n\t\"github.com/vcaesar/leven\"\n)\n\nvar seg gse.Segmenter\n\nfunc init() {\n\tseg.LoadDict()\n}\n\nfunc main() {\n\tp := *leven.NewParams().FilterScore(0.6)\n\n\ts1 := \"City of Seattle, 西雅图都会区\"\n\ts2 := \"The Space Nedle, 西雅图太空针, 都会区\"\n\n\tr := leven.Ratio(s1, s2, p)\n\tfmt.Println(r)\n\n\tm := leven.MatchNew(s1, s2)\n\tfmt.Println(m)\n\n\td := leven.DistanceNew(s1, s2)\n\tfmt.Println(d)\n\n\tseq1 := seg.Cut(s1)\n\tseq2 := seg.Cut(s2)\n\n\ts := leven.SeqRatio(seq1, seq2, p)\n\tfmt.Println(\"cut with ratio: \", s)\n}\n```\n\n## Overview\n\nThe Levenshtein `Distance` between two strings is the minimum total cost of edits that would convert the first string into the second. The allowed edit operations are insertions, deletions, and substitutions, all at character (one UTF-8 code point) level. Each operation has a default cost of 1, but each can be assigned its own cost equal to or greater than 0.\n\nA `Distance` of 0 means the two strings are identical, and the higher the value the more different the strings. Since in practice we are interested in finding if the two strings are \"close enough\", it often does not make sense to continue the calculation once the result is mathematically guaranteed to exceed a desired threshold. Providing this value to the `Distance` function allows it to take a shortcut and return a lower bound instead of an exact cost when the threshold is exceeded.\n\nThe `Similarity` function calculates the distance, then converts it into a normalized metric within the range 0..1, with 1 meaning the strings are identical, and 0 that they have nothing in common. A minimum similarity threshold can be provided to speed up the calculation of the metric for strings that are far too dissimilar for the purpose at hand. All values under this threshold are rounded down to 0.\n\nThe `Match` function provides a similarity metric, with the same range and meaning as `Similarity`, but with a bonus for string pairs that share a common prefix and have a similarity above a \"bonus threshold\". It uses the same method as proposed by Winkler for the Jaro distance, and the reasoning behind it is that these string pairs are very likely spelling variations or errors, and they are more closely linked than the edit distance alone would suggest.\n\nThe underlying `Calculate` function is also exported, to allow the building of other derivative metrics, if needed.\n\n## Installation\n\n```\ngo get github.com/vcaesar/leven\n```\n\n## License\n\nPackage levenshtein is released under the Apache 2.0 license. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvcaesar%2Fleven","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvcaesar%2Fleven","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvcaesar%2Fleven/lists"}