diff --git a/analyse/idf.go b/analyse/idf.go index c3b6f40..f597fec 100644 --- a/analyse/idf.go +++ b/analyse/idf.go @@ -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 } diff --git a/analyse/stopwords.go b/analyse/stopwords.go index 42a1591..112cece 100644 --- a/analyse/stopwords.go +++ b/analyse/stopwords.go @@ -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 { diff --git a/posseg/posseg.go b/posseg/posseg.go index 00b694a..60c89dc 100644 --- a/posseg/posseg.go +++ b/posseg/posseg.go @@ -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. diff --git a/util.go b/util.go index 66796b7..85d1acb 100644 --- a/util.go +++ b/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 }