mirror of
https://github.com/fumiama/jieba.git
synced 2026-06-05 00:32:51 +08:00
move dictPath function private
This commit is contained in:
@@ -17,12 +17,8 @@ func (l *IDFLoader) AddEntry(entry *jiebago.Entry) {
|
||||
}
|
||||
|
||||
func NewIDFLoader(IDFFileName string) (*IDFLoader, error) {
|
||||
IDFFilePath, err := jiebago.DictPath(IDFFileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
loader := &IDFLoader{make(map[string]float64), 0.0, make([]float64, 0)}
|
||||
err = jiebago.LoadDict(loader, IDFFilePath, false)
|
||||
err = jiebago.LoadDict(loader, IDFFileName, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -53,11 +53,7 @@ func NewStopWordLoader() *StopWordLoader {
|
||||
// Set the stop words file path, could be absolute path of stop words file, or
|
||||
// file name in current directory.
|
||||
func (s *StopWordLoader) SetStopWords(stopWordsFileName string) error {
|
||||
stopWordsFilePath, err := jiebago.DictPath(stopWordsFileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return jiebago.LoadDict(s, stopWordsFilePath, false)
|
||||
return jiebago.LoadDict(s, stopWordsFileName, false)
|
||||
}
|
||||
|
||||
func (s StopWordLoader) IsStopWord(word string) bool {
|
||||
|
||||
@@ -37,12 +37,11 @@ func (p *Posseg) AddEntry(entry *jiebago.Entry) {
|
||||
func NewPosseg(dictFileName string) (*Posseg, error) {
|
||||
j := &jiebago.Jieba{Total: 0.0, Freq: make(map[string]float64)}
|
||||
p := &Posseg{j, make(map[string]string)}
|
||||
dictFilePath, err := jiebago.DictPath(dictFileName)
|
||||
err := jiebago.LoadDict(p, dictFileName, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = jiebago.LoadDict(p, dictFilePath, true)
|
||||
return p, err
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// Load user specified dictionary file.
|
||||
|
||||
11
util.go
11
util.go
@@ -13,7 +13,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func DictPath(dictFileName string) (string, error) {
|
||||
func dictPath(dictFileName string) (string, error) {
|
||||
if filepath.IsAbs(dictFileName) {
|
||||
return dictFileName, nil
|
||||
}
|
||||
@@ -26,7 +26,12 @@ func DictPath(dictFileName string) (string, error) {
|
||||
return dictFilePath, nil
|
||||
}
|
||||
|
||||
func LoadDict(l DictLoader, dictFilePath string, usingFlag bool) error {
|
||||
func LoadDict(l DictLoader, dictFileName string, usingFlag bool) error {
|
||||
dictFilePath, err := dictPath(dictFileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("Building Trie..., from %s\n", dictFilePath)
|
||||
|
||||
dictFile, err := os.Open(dictFilePath)
|
||||
@@ -96,7 +101,7 @@ func dump(c Cacher, cachePath string) error {
|
||||
}
|
||||
|
||||
func SetDict(l DictLoader, dictName string, pos bool) error {
|
||||
dictPath, err := DictPath(dictName)
|
||||
dictPath, err := dictPath(dictName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user