Skip to content
/ strsim Public

Calculate string similarity library, integrate multiple algorithms on the back end。计算字符串相似度库,后端集成多种算法[从零实现]

License

Notifications You must be signed in to change notification settings

antlabs/strsim

Repository files navigation

strsim

strsim是golang实现的字符串相识度库,后端集成多种算法,主要解决现有相似度库不能很好的处理中文

Go codecov

构架

strsim.png

使用方式

go get -u github.com/antlabs/strsim

功能

  • 可以忽略空白字符
  • 可以大小写

    多种算法支持

    • 莱文斯坦-编辑距离(Levenshtein)
    • Hamming
    • Dice's coefficient
    • Jaro
    • JaroWinkler
    • Cosine
    • Simhash

内容

比较两个字符串相识度

strsim.Compare("中国人", "中")
// -> 0.333333

从数组里找到相似度最高的字符串

strsim.FindBestMatchOne("海刘", []string{"白日依山尽", "黄河入海流", "欲穷千里目", "更上一层楼"})

从数组里找到相似度最高的字符串-带下标

strsim.FindBestMatch("海刘", []string{"白日依山尽", "黄河入海流", "欲穷千里目", "更上一层楼"})

选择不同算法

莱文斯坦-编辑距离(Levenshtein)

strsim.Compare("abc", "ab")
// -> 0.6666666666666667

选择Dice's coefficient

strsim.Compare("abc", "ab", strsim.DiceCoefficient())
//-> 0.6666666666666666

选择jaro

strsim.Compare("abc", "ab", strsim.Jaro())

选择JaroWinkler

strsim.Compare("abc", "ab", strsim.JaroWinkler())

选择Hamming

strsim.Compare("abc", "ab", strsim.Hamming())

选择Cosine

strsim.Compare("abc", "ab", strsim.Cosine())

选择Simhash

strsim.Compare("abc", "ab", strsim.Simhash())

About

Calculate string similarity library, integrate multiple algorithms on the back end。计算字符串相似度库,后端集成多种算法[从零实现]

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages