更新 'README.md'
Signed-off-by: loser <1711788888@qq.com>
This commit is contained in:
parent
9fe1154908
commit
6a0c3abac1
56
README.md
56
README.md
@ -1,3 +1,57 @@
|
||||
# KeywordExtraction
|
||||
|
||||
关键词提取器
|
||||
KeywordExtraction是一个使用 Golang 实现的 AC 自动机库,用于在文本中查找和提取关键词。它使用高效的算法和数据结构,可以快速匹配大量的关键词,并返回匹配结果。
|
||||
|
||||
## 安装
|
||||
|
||||
使用以下命令将 KeywordExtraction 库添加到你的项目中:
|
||||
|
||||
```bash
|
||||
go get git.echol.cn/loser/keyword-extraction
|
||||
```
|
||||
|
||||
## 使用示例
|
||||
|
||||
下面是一个简单的示例,展示了如何使用 flashtext 进行关键词提取:
|
||||
|
||||
```go
|
||||
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
|
||||
---
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user