Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions segmenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"fmt"
"log"
"math"
"os"
"strconv"
"strings"
"unicode"
"unicode/utf8"

"github.com/wangkuiyi/fs"
)

const (
Expand Down Expand Up @@ -41,14 +42,14 @@ func (seg *Segmenter) Dictionary() *Dictionary {
//
// 词典的格式为(每个分词一行):
// 分词文本 频率 词性
func (seg *Segmenter) LoadDictionary(files string) {
func (seg *Segmenter) LoadDictionary(files string) error {
seg.dict = NewDictionary()
for _, file := range strings.Split(files, ",") {
log.Printf("载入sego词典 %s", file)
dictFile, err := os.Open(file)
dictFile, err := fs.Open(file)
defer dictFile.Close()
if err != nil {
log.Fatalf("无法载入字典文件 \"%s\" \n", file)
return fmt.Errorf("Cannot load segmenter dictionary \"%s\": %v", file, err)
}

reader := bufio.NewReader(dictFile)
Expand Down Expand Up @@ -125,6 +126,7 @@ func (seg *Segmenter) LoadDictionary(files string) {
}

log.Println("sego词典载入完毕")
return nil
}

// 对文本分词
Expand Down