1
0
mirror of https://github.com/fumiama/jieba.git synced 2026-07-01 09:30:29 +08:00

uniform the api

This commit is contained in:
Wang Bin
2015-03-30 17:52:09 +08:00
parent 7a7f8af517
commit c397cafe8a
4 changed files with 50 additions and 28 deletions

View File

@@ -2,17 +2,19 @@
package jiebago
import (
"errors"
"github.com/wangbin/jiebago/finalseg"
"regexp"
"sort"
)
var (
reEng = regexp.MustCompile(`[[:alnum:]]`)
reHanCutAll = regexp.MustCompile(`\p{Han}+`)
reSkipCutAll = regexp.MustCompile(`[^[:alnum:]+#\n]`)
reHanDefault = regexp.MustCompile(`([\p{Han}+[:alnum:]+#&\._]+)`)
reSkipDefault = regexp.MustCompile(`(\r\n|\s)`)
ErrInitialized = errors.New("already initialized")
reEng = regexp.MustCompile(`[[:alnum:]]`)
reHanCutAll = regexp.MustCompile(`\p{Han}+`)
reSkipCutAll = regexp.MustCompile(`[^[:alnum:]+#\n]`)
reHanDefault = regexp.MustCompile(`([\p{Han}+[:alnum:]+#&\._]+)`)
reSkipDefault = regexp.MustCompile(`(\r\n|\s)`)
)
type Segmenter interface {
@@ -51,8 +53,15 @@ func (j *Jieba) Add(word string, freq float64) {
}
// Load user specified dictionary file.
func (j *Jieba) LoadUserDict(dictFilePath string) error {
return LoadDict(j, dictFilePath, false)
func (j *Jieba) LoadUserDict(dictFileName string) error {
return LoadDict(j, dictFileName, false)
}
func (j *Jieba) SetDict(dictFileName string) error {
if len(j.freqMap) > 0 || j.total > 0.0 {
return ErrInitialized
}
return LoadDict(j, dictFileName, false)
}
func New() *Jieba {