1 Star 2 Fork 0

weidongkl/similarity

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT
# Similarity This project provides a Go package for calculating the similarity between strings using various algorithms. It supports different similarity measures through the `Calculator` interface and includes functions to compute and sort similarities. ## Features - **Modular Design**: Use different similarity measures by implementing the `Calculator` interface. - **Efficient Calculation**: Concurrent processing for calculating similarities in arrays. - **Priority Queue**: Sort and retrieve strings based on their similarity to a given string. ## Installation To install the package, use the following command: ```sh go get gitee.com/weidongkl/similarity ``` ## Usage ### Implementing a Similarity Measure To create a custom similarity measure, implement the `Calculator` interface: ```go type Calculator interface { Calculate(s1, s2 string) (float64, error) } ``` ### Example: Cosine Here's an example of how to use the Cosine as a similarity measure: ```go package main import ( "fmt" "gitee.com/weidongkl/similarity" "gitee.com/weidongkl/similarity/cosine" ) func main() { calc := cosine.New() s1 := "string1" s2 := "string2" similarity, err := calc.Calculate(s1, s2) if err != nil { fmt.Println("Error calculating similarity:", err) } else { fmt.Printf("Similarity between %s and %s: %f\n", s1, s2, similarity) } } ``` ### Sorting Strings by Similarity To sort an array of strings by their similarity to a given string, use the `CalculateArray` function: ```go package main import ( "fmt" "gitee.com/weidongkl/similarity" "gitee.com/weidongkl/similarity/jaccard" ) func main() { calc := jaccard.New() s1 := "base" sArr := []string{"test1", "test2", "test3"} sortedItems, err := similarity.CalculateArray(calc, s1, sArr) if err != nil { fmt.Println("Error calculating similarities:", err) } else { fmt.Println("Sorted items by similarity:") for _, item := range sortedItems { fmt.Printf("%s: %f\n", item.Value, item.Priority) } } } ``` ## Directory Structure ``` similarity/ ├── hamming/ │ └── hamming.go ├── jaccard/ │ └── jaccard.go ├── cosine/ │ └── cosine.go ├── levenshtein/ │ └── levenshtein.go ├── similarity.go ├── errors.go ├── heap.go ├── heap_test.go ├── similarity_test.go ├── go.mod ├── README.md └── .gitignore ``` ## Contributing 1. Fork the repository. 2. Create a new branch for your feature. 3. Commit your changes. 4. Push the branch. 5. Create a pull request. ## License This project is licensed under the MIT License. ## Contact For any questions or issues, please contact [email protected].

简介

calculating the similarity between strings using various algorithms 计算字符串的相似度 展开 收起
Go
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/weidongkl/similarity.git
[email protected]:weidongkl/similarity.git
weidongkl
similarity
similarity
master

搜索帮助