extractor

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2023 License: GPL-3.0 Imports: 2 Imported by: 0

README

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
---

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeywordProcessor

type KeywordProcessor struct {
	// contains filtered or unexported fields
}

func NewKeywordProcessor

func NewKeywordProcessor(caseSensitive bool) *KeywordProcessor

func (*KeywordProcessor) AddKeyWord

func (kp *KeywordProcessor) AddKeyWord(keyword string) *KeywordProcessor

func (*KeywordProcessor) AddKeywordsFromList

func (kp *KeywordProcessor) AddKeywordsFromList(keywords []string) *KeywordProcessor

func (*KeywordProcessor) Build

func (kp *KeywordProcessor) Build()

func (*KeywordProcessor) ExtractKeywords

func (kp *KeywordProcessor) ExtractKeywords(sentence string) []Match

ExtractKeywords 匹配关键词

func (*KeywordProcessor) ExtractKeywordsFromBytes

func (kp *KeywordProcessor) ExtractKeywordsFromBytes(sentence []byte) []Match

type Match

type Match struct {
	// contains filtered or unexported fields
}

func (*Match) End

func (m *Match) End() int

func (*Match) MatchString

func (m *Match) MatchString() string

func (*Match) Start

func (m *Match) Start() int

type Node

type Node struct {
	// contains filtered or unexported fields
}

type WalkFn

type WalkFn func(start, end int) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL