1
0
mirror of https://github.com/fumiama/jieba.git synced 2026-06-26 23:20:31 +08:00

removed dict.go, functions move to util.go, also use interface to simplify code

This commit is contained in:
Wang Bin
2015-03-25 18:28:37 +08:00
parent 7fe5e7d4c4
commit 59da5b5e3a
7 changed files with 57 additions and 115 deletions

15
trie.go
View File

@@ -60,14 +60,10 @@ func (j *Jieba) load(dictFileName string) error {
}
if !isDictCached {
entries, err := ParseDictFile(dictFilePath)
err = LoadDict(j, dictFilePath, false)
if err != nil {
return err
}
for _, entry := range entries {
j.AddEntry(entry)
}
// dump trie
cacheFile, err = os.OpenFile(cacheFilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
@@ -103,14 +99,7 @@ func (j *Jieba) Add(word string, freq float64) {
// Load user specified dictionary file.
func (j *Jieba) LoadUserDict(dictFilePath string) error {
entries, err := ParseDictFile(dictFilePath)
if err != nil {
return err
}
for _, entry := range entries {
j.Add(entry.Word, entry.Freq)
}
return nil
return LoadDict(j, dictFilePath, false)
}
// Set the dictionary, could be absolute path of dictionary file, or dictionary