You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
loser
6a0c3abac1
Signed-off-by: loser <1711788888@qq.com> |
11 months ago | |
---|---|---|
.gitignore | 11 months ago | |
LICENSE | 11 months ago | |
README.md | 11 months ago | |
go.mod | 11 months ago | |
keywordprocessor.go | 11 months ago | |
trie.go | 11 months ago |
README.md
KeywordExtraction
KeywordExtraction是一个使用 Golang 实现的 AC 自动机库,用于在文本中查找和提取关键词。它使用高效的算法和数据结构,可以快速匹配大量的关键词,并返回匹配结果。
安装
使用以下命令将 KeywordExtraction 库添加到你的项目中:
go get git.echol.cn/loser/keyword-extraction
使用示例
下面是一个简单的示例,展示了如何使用 flashtext 进行关键词提取:
import (
"git.echol.cn/loser/keyword-extraction"
"fmt"
)
func main() {
// 创建一个关键词处理器,不区分大小写
kp := extractor.NewKeywordProcessor(false)
// 添加关键词
kp.AddKeyword("apple")
kp.AddKeyword("banana")
kp.AddKeyword("orange")
// 提取关键词
sentence := "I have an Apple and a Banana."
matches := kp.ExtractKeywords(sentence)
// 打印匹配结果
for _, match := range matches {
fmt.Println("Match:", match.Match)
fmt.Println("Start:", match.Start)
fmt.Println("End:", match.End)
fmt.Println("---")
}
}
输出:
Match: Apple
Start: 9
End: 13
---
Match: Banana
Start: 20
End: 25
---