Skip to content

Commit

Permalink
export dictionary addToken function
Browse files Browse the repository at this point in the history
  • Loading branch information
vcaesar committed Sep 21, 2021
1 parent be4ddfd commit ad61431
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dict_1.16.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (seg *Segmenter) LoadDictStr(dict string) error {
// 将分词添加到字典中
words := seg.SplitTextToWords([]byte(text))
token := Token{text: words, frequency: frequency, pos: pos}
seg.Dict.addToken(token)
seg.Dict.AddToken(token)
}

seg.CalcToken()
Expand Down
6 changes: 3 additions & 3 deletions dict_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (seg *Segmenter) AddToken(text string, frequency float64, pos ...string) er
words := seg.SplitTextToWords([]byte(text))
token := Token{text: words, frequency: frequency, pos: po}

return seg.Dict.addToken(token)
return seg.Dict.AddToken(token)
}

// AddTokenForce add new text to token and force
Expand Down Expand Up @@ -99,7 +99,7 @@ func (seg *Segmenter) LoadDictMap(dict []map[string]string) error {

words := seg.SplitTextToWords([]byte(d["text"]))
token := Token{text: words, frequency: frequency, pos: d["pos"]}
seg.Dict.addToken(token)
seg.Dict.AddToken(token)
}

seg.CalcToken()
Expand Down Expand Up @@ -311,7 +311,7 @@ func (seg *Segmenter) Reader(reader io.Reader, files ...string) error {
// 将分词添加到字典中
words := seg.SplitTextToWords([]byte(text))
token := Token{text: words, frequency: frequency, pos: pos}
seg.Dict.addToken(token)
seg.Dict.AddToken(token)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions dictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (dict *Dictionary) TotalFreq() float64 {
return dict.totalFrequency
}

// addToken 向词典中加入一个分词
func (dict *Dictionary) addToken(token Token) error {
// AddToken 向词典中加入一个分词
func (dict *Dictionary) AddToken(token Token) error {
bytes := textSliceToBytes(token.text)
val, err := dict.trie.Get(bytes)
if err == nil || val > 0 {
Expand Down

0 comments on commit ad61431

Please sign in to comment.