mirror of
https://github.com/fumiama/jieba.git
synced 2026-06-13 05:31:02 +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) {
|
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)}
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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
|
// Set the stop words file path, could be absolute path of stop words file, or
|
||||||
// file name in current directory.
|
// file name in current directory.
|
||||||
func (s *StopWordLoader) SetStopWords(stopWordsFileName string) error {
|
func (s *StopWordLoader) SetStopWords(stopWordsFileName string) error {
|
||||||
stopWordsFilePath, err := jiebago.DictPath(stopWordsFileName)
|
return jiebago.LoadDict(s, stopWordsFileName, false)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return jiebago.LoadDict(s, stopWordsFilePath, false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s StopWordLoader) IsStopWord(word string) bool {
|
func (s StopWordLoader) IsStopWord(word string) bool {
|
||||||
|
|||||||
@@ -37,12 +37,11 @@ func (p *Posseg) AddEntry(entry *jiebago.Entry) {
|
|||||||
func NewPosseg(dictFileName string) (*Posseg, error) {
|
func NewPosseg(dictFileName string) (*Posseg, error) {
|
||||||
j := &jiebago.Jieba{Total: 0.0, Freq: make(map[string]float64)}
|
j := &jiebago.Jieba{Total: 0.0, Freq: make(map[string]float64)}
|
||||||
p := &Posseg{j, make(map[string]string)}
|
p := &Posseg{j, make(map[string]string)}
|
||||||
dictFilePath, err := jiebago.DictPath(dictFileName)
|
err := jiebago.LoadDict(p, dictFileName, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = jiebago.LoadDict(p, dictFilePath, true)
|
return p, nil
|
||||||
return p, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load user specified dictionary file.
|
// Load user specified dictionary file.
|
||||||
|
|||||||
11
util.go
11
util.go
@@ -13,7 +13,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DictPath(dictFileName string) (string, error) {
|
func dictPath(dictFileName string) (string, error) {
|
||||||
if filepath.IsAbs(dictFileName) {
|
if filepath.IsAbs(dictFileName) {
|
||||||
return dictFileName, nil
|
return dictFileName, nil
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,12 @@ func DictPath(dictFileName string) (string, error) {
|
|||||||
return dictFilePath, nil
|
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)
|
log.Printf("Building Trie..., from %s\n", dictFilePath)
|
||||||
|
|
||||||
dictFile, err := os.Open(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 {
|
func SetDict(l DictLoader, dictName string, pos bool) error {
|
||||||
dictPath, err := DictPath(dictName)
|
dictPath, err := dictPath(dictName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user