Last active
January 3, 2018 20:15
-
-
Save alediaferia/df59e27501d9c55908752e7d64c5dadf to your computer and use it in GitHub Desktop.
A simple function to compute the similarity between 2 words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "math" | |
// similarity computes the similarity between | |
// 2 words. w1len and w2len are the lengths of the 2 | |
// words for which to compute the similarity. | |
// ld is the levenshtein distance between the 2 words. | |
// It returns a value between 0 and 1 that identifies the similarity | |
// between the 2 words. 2 equal words will have a similarity of 1. | |
func similarity(w1Len, w2Len, ld int) float64 { | |
maxLen := math.Max(float64(w1Len), float64(w2Len)) | |
return 1.0 - float64(ld)/float64(maxLen) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment