texttheater / golang-levenshtein Goto Github PK
View Code? Open in Web Editor NEWAn implementation of the Levenshtein algorithm in Go. Provides edit distances and edit scripts.
License: MIT License
An implementation of the Levenshtein algorithm in Go. Provides edit distances and edit scripts.
License: MIT License
Hi,
That would be great if you could add a license to the code.
Thanks
Seems strange to insist on printing to os.Stderr:
https://github.com/texttheater/golang-levenshtein/blob/master/levenshtein/levenshtein.go#L119
Why not have an io.Writer as argument to the function.
The following program panics:
package main
import "github.com/texttheater/golang-levenshtein/levenshtein"
func main() {
m := levenshtein.MatrixForStrings(
[]rune("a"),
[]rune("aa"),
levenshtein.DefaultOptions,
)
levenshtein.EditScriptForMatrix(m, levenshtein.DefaultOptions)
}
Would it be possible to add some examples or documentation? I want to calculate the difference for a set of words but I don't know how to do this.
Thanks
I'm comparing a few different Levenshtein libraries and yours comes up with different values for my test cases:
I've checked with a few online checkers as well and they match my expected values. Is there a bug or are you calculating something different to the others?
The code I'm using is taken from your examples:
package main
import "fmt"
import "github.com/texttheater/golang-levenshtein/levenshtein"
func main() {
source := "kitten"
target := "sitting"
distance := levenshtein.DistanceForStrings([]rune(source), []rune(target), levenshtein.DefaultOptions)
fmt.Printf("The distance between '%s' and '%s' computed as %d.\n", source, target, distance)
}
Hello and thank you for your lib.
In your DistanceForStrings method, initialization costs should match insert/delete costs on lines 91, 94 and 102.
Currently it supposes costs are 1, but if you increase option costs you get wrong results.
Let's suppose insert and delete costs are 2, then if you compute distance between "meme" and "me", you'll get 2 instead of 4.
In the mentioned lines, I multiplied the value by the corresponding costs and now it works fine.
Try to run
DistanceForStrings([]rune("aa"), []rune("a"), DefaultOptions)
and get exception in
return matrix[len(target)][len(source)]
You have len(source)
== len(matrix[len(target)])
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.