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

small refactor

This commit is contained in:
Wang Bin
2015-02-26 14:42:16 +08:00
parent 60b2c9f763
commit 35094877da
3 changed files with 34 additions and 22 deletions

20
trie.go
View File

@@ -96,13 +96,7 @@ func newTrie(dictFileName string) (*Trie, error) {
if !isDictCached {
trie = &Trie{Total: 0.0, Freq: make(map[string]float64)}
dictFile, err := os.Open(dictFilePath)
if err != nil {
return nil, err
}
defer dictFile.Close()
wtfs, err := ParseDictFile(dictFile)
wtfs, err := ParseDictFile(dictFilePath)
if err != nil {
return nil, err
}
@@ -147,13 +141,7 @@ func addWord(wtf *WordTagFreq) {
}
func LoadUserDict(dictFilePath string) error {
dictFile, err := os.Open(dictFilePath)
if err != nil {
return err
}
defer dictFile.Close()
wtfs, err := ParseDictFile(dictFile)
wtfs, err := ParseDictFile(dictFilePath)
if err != nil {
return err
}
@@ -163,7 +151,7 @@ func LoadUserDict(dictFilePath string) error {
return nil
}
func SetDictionary(dict_path string) (err error) {
T, err = newTrie(dict_path)
func SetDictionary(dictFileName string) (err error) {
T, err = newTrie(dictFileName)
return
}