nlpword

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EMO_VAL_DEFAULT = 0    //词情感值,默认值
	EMO_VAL_ONE     = 2    //词情感值,积极词的前一词为程度副词,
	EMO_VAL_TWO     = 1    //词情感值,积极词的前后词什么都不是,消极词的前一词为否定词
	EMO_VAL_THREE   = -0.5 //词情感值,否定词
	EMO_VAL_FOUR    = -1   //词情感值,积极词的前一词为否定词、消极词,后一词为消极词,消极词的前一次什么都不是
	EMO_VAL_FIVE    = -2   //词情感值,消极词的前一词为程度副词
)
View Source
const (
	TAG_VAL_ZERO  = 0 //不显示词其他信息
	TAG_VAL_ONE   = 1 //显示词典中的词性
	TAG_VAL_TWO   = 2 //显示词的词频,distance
	TAG_VAL_THREE = 3 //显示词的情感词性,积极词(po),否定词(ga),消极词(ne),程度副词(de),主张词(cl),无词性(x)。
)
View Source
const (
	PART_MODE_ONE   = 1 //普通分词
	PART_MODE_TWO   = 2 //mmseg分词
	PART_MODE_THREE = 3 //隐马尔可夫模型分词
)
View Source
const MIN_FLOAT = -3.14e100
View Source
const MIN_WORD_FREQUENCY = 2
View Source
const SPACE = 32

Variables

This section is empty.

Functions

func GetKeysId

func GetKeysId(keywords ...string) (id uint64)

func LoadEmitProb

func LoadEmitProb()

func PartToStrings

func PartToStrings(part []*Part, tag int) (output string)

字符串显示分词 (老方法保留) tag 0 不显示词其他信息 tag 1 显示词的词性 tag 2 显示词的词频,distance

func PartToTexts

func PartToTexts(part []*Part) (output []string)

字符数组显示分词 (老方法保留)

func Reverse

func Reverse(s string) string

func ToLower

func ToLower(text []byte) []byte

将英文词转化为小写

func Viterbi

func Viterbi(obs []rune, states []byte) (float64, []byte)

Types

type Dictionary

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

分词字典

func NewDictionary

func NewDictionary() *Dictionary

func (*Dictionary) AddWord

func (dict *Dictionary) AddWord(word *Word)

func (*Dictionary) FindWord

func (dict *Dictionary) FindWord(chars []rune) ([]*Word, int)

func (*Dictionary) MaxCharLen

func (dict *Dictionary) MaxCharLen() int

func (*Dictionary) TotalRate

func (dict *Dictionary) TotalRate() int64

func (*Dictionary) Trie

func (dict *Dictionary) Trie() *Trie

func (*Dictionary) WordsNum

func (dict *Dictionary) WordsNum() int

type EmoDictionary

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

情感词典

func NewEmoDictionary

func NewEmoDictionary() *EmoDictionary

type EmoWord

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

func (*EmoWord) Less

func (records *EmoWord) Less(item btree.Item) bool

type Emotion

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

func NewEmotion

func NewEmotion(sentence string) *Emotion

func (*Emotion) DoScore

func (e *Emotion) DoScore() *Emotion

func (*Emotion) GetScore

func (e *Emotion) GetScore() float64

type Hmm

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

func NewHmm

func NewHmm() *Hmm

func (*Hmm) GetViterbiResult

func (hmm *Hmm) GetViterbiResult(text string) []string

func (*Hmm) HmmPart

func (hmm *Hmm) HmmPart(text string) []string

type MMseg

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

func NewMMsge

func NewMMsge(chars []rune, dict *Dictionary) *MMseg

func (*MMseg) FilterByMMsegRules

func (mm *MMseg) FilterByMMsegRules() []*Word

func (*MMseg) GetChunks

func (mm *MMseg) GetChunks() (chunks [][]*Word)

type Node

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

func (*Node) Children

func (n *Node) Children() map[rune]*Node

func (*Node) Depth

func (n *Node) Depth() int

func (*Node) Mask

func (n *Node) Mask() uint64

func (*Node) NewChild

func (parent *Node) NewChild(val rune, path string, mask uint64, meta interface{}, term bool) *Node

func (*Node) Parent

func (n *Node) Parent() *Node

func (*Node) RemoveChild

func (n *Node) RemoveChild(r rune)

func (*Node) Val

func (n *Node) Val() rune

type OpRet

type OpRet string

得到分词整句的情感值

func (OpRet) GetEmoScore

func (r OpRet) GetEmoScore() (output string)

type OptionalVal

type OptionalVal func(*Word) //可参数值

func Pos

func Pos(pos string) OptionalVal

func Rate

func Rate(rate int) OptionalVal

type OutPut

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

func (*OutPut) EmotionLabel

func (op *OutPut) EmotionLabel(xtext string) (output string)

给分词加情感词性标注

func (*OutPut) GetOutPut

func (op *OutPut) GetOutPut() *OutPut

func (*OutPut) ToStrings

func (op *OutPut) ToStrings() (output string)

字符串显示分词

func (*OutPut) ToTexts

func (op *OutPut) ToTexts() (output []string)

字符数组显示分词

type Part

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

func FilterPartNil

func FilterPartNil(part []*Part) []*Part

func NewPart

func NewPart(start, end int, word []*Word) *Part

func (*Part) End

func (p *Part) End() int

func (*Part) Start

func (p *Part) Start() int

func (*Part) Word

func (p *Part) Word() []*Word

type Parter

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

npartword分词器

func NewParter

func NewParter() *Parter

func (*Parter) Dictionary

func (pr *Parter) Dictionary() *Dictionary

func (*Parter) DoPartWords

func (pr *Parter) DoPartWords(text string, partModel int) []*Part

执行分词

func (*Parter) LoadDictionary

func (pr *Parter) LoadDictionary(dictfiles string)

*

  • 加载分词词典数据,dictfiles为字典文件路径,可以多个以,分隔 *

func (*Parter) LoadEmoDictionary

func (pr *Parter) LoadEmoDictionary(dictfiles string)

*

  • 加载情感词典数据,dictfiles为字典文件路径,可以多个以,分隔 *

func (*Parter) Part

func (pr *Parter) Part(text string, partModel int, tag int) *OutPut

分词

func (*Parter) PartWords

func (pr *Parter) PartWords(text string, partModel int, tag int) string

分词返回字符串,老方法暂时保留

func (*Parter) PartWordsTexts

func (pr *Parter) PartWordsTexts(text string, partModel int) []string

分词返回字符串数组,老方法暂时保留

type Text

type Text []byte

type Trie

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

func NewTrie

func NewTrie() *Trie

func (*Trie) AddKey

func (t *Trie) AddKey(key string, meta interface{}) *Node

*

  • 前缀树添加数据 *
  • @return 返回当前数据的尾节点

func (*Trie) FindKey

func (t *Trie) FindKey(key string) (*Node, bool)

func (*Trie) HasKey

func (t *Trie) HasKey(key string) bool

func (*Trie) RemoveKey

func (t *Trie) RemoveKey(key string)

func (*Trie) Root

func (t *Trie) Root() *Node

func (*Trie) SearchKeyByPre

func (t *Trie) SearchKeyByPre(pre string) []string

*

  • 通过数据的前缀搜索所有匹配的数据key *

func (*Trie) SearchKeyByPre2Next

func (t *Trie) SearchKeyByPre2Next(pre, next string) (string, bool)

*

  • 通过数据的前缀和后缀找到确定的一个key *

func (*Trie) SearchKeyNodeByPre2Next

func (t *Trie) SearchKeyNodeByPre2Next(pre, next string) (string, bool)

*

  • 通过数据的前缀和一个后缀查找节点,如果存在节点则返回前缀+后缀的字符串 *

type Word

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

func NewWord

func NewWord(chars []byte, optvals ...OptionalVal) *Word

Jump to

Keyboard shortcuts

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