Skip to content

Commit

Permalink
fix issue 8
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyiwu committed Sep 6, 2016
1 parent 6ae3b6b commit fcfc490
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
20 changes: 7 additions & 13 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package gojieba

import (
"os"
"path"
"strings"
"runtime"
)

var (
Expand All @@ -16,17 +15,7 @@ var (
)

func init() {
paths := os.Getenv("GOPATH")
path_list := strings.Split(paths, ":")
if len(path_list) == 1 {
path_list = strings.Split(paths, ";")
}
for _, p := range path_list {
DICT_DIR = path.Join(p, "src/github.com/yanyiwu/gojieba/dict")
if isDirExists(DICT_DIR) {
break
}
}
DICT_DIR = path.Join(path.Dir(getCurrentFilePath()), "dict")
DICT_PATH = path.Join(DICT_DIR, "jieba.dict.utf8")
HMM_PATH = path.Join(DICT_DIR, "hmm_model.utf8")
USER_DICT_PATH = path.Join(DICT_DIR, "user.dict.utf8")
Expand All @@ -49,3 +38,8 @@ func getDictPaths(args ...string) [TOTAL_DICT_PATH_NUMBER]string {
}
return dicts
}

func getCurrentFilePath() string {
_, filePath, _, _ := runtime.Caller(1)
return filePath
}
8 changes: 8 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package gojieba

import "testing"

func TestConfig(t *testing.T) {
file := getCurrentFilePath()
println(file)
}

0 comments on commit fcfc490

Please sign in to comment.