segment

package
v0.0.0-...-67d0eb9 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: AGPL-3.0 Imports: 11 Imported by: 1

README

README

注册驱动

import (
	_ "github.com/coscms/webfront/library/search/segment/gojieba"
	_ "github.com/coscms/webfront/library/search/segment/jiebago"
    _ "github.com/coscms/webfront/library/search/segment/sego"
)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultEngine = atomic.NewString(`sego`) // gojieba / sego / jiebago

	Filters []Filter
)
View Source
var (

	// DictFile 分词词典文件
	DictFile string
)

Functions

func AddFilter

func AddFilter(filter Filter)

func ApplySegmentConfig

func ApplySegmentConfig(c *config.Config)

func CleanStopWords

func CleanStopWords(v string) string

func CleanStopWordsFromSlice

func CleanStopWordsFromSlice(v []string) (r []string)

func DoFilter

func DoFilter(v string) bool

func Has

func Has(name string) bool

func IsInitialized

func IsInitialized() bool

func IsNop

func IsNop(segment Segment) bool

func LoadStopWordsDict

func LoadStopWordsDict(stopWordsFile string, args ...bool)

func NewAPI

func NewAPI(apiURL string, apiKey string) *apiSegment

func Register

func Register(name string, c func() Segment)

func ReloadDict

func ReloadDict(dictFiles ...string) error

ReloadDict 重新加载词典

func ResetSegment

func ResetSegment()

func ResetStopwords

func ResetStopwords()

func SplitWords

func SplitWords(b []byte, args ...string) []string

SplitWords 分词

func SplitWordsAsString

func SplitWordsAsString(b []byte, args ...string) string

SplitWordsAsString 将分词结果作为字串返回

func SplitWordsBy

func SplitWordsBy(b []byte, mode string, args ...string) []string

SplitWordsBy 按模式分词

func StopWords

func StopWords() []string

func Unregister

func Unregister(name string)

Types

type Filter

type Filter func(string) bool

type Segment

type Segment interface {
	//载入词典(词典路径,词典类型)
	LoadDict(string, ...string) error

	//分词(文本,词性)
	Segment(string, ...string) []string

	//分词(文本,分词模式,词性)
	SegmentBy(string, string, ...string) []string

	//关闭或释放资源
	Close() error
}

Segment interface

func Default

func Default() Segment

func Get

func Get(name string) Segment

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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