Skip to content

Commit

Permalink
get dict path by env var GOPATH
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyiwu committed Apr 4, 2016
1 parent d273532 commit 94b0293
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ go get github.com/yanyiwu/gojieba
See Details in [example/demo.go](example/demo.go)

```
cd example
go run demo.go
go run example/demo.go
```

之所以需要先 cd 到 example 目录下,是因为 demo.go 里面有写死的字典相对路径。

输出结果:

```
Expand All @@ -54,8 +51,7 @@ DemoExtract
## Bleve 中文分词插件用法

```
cd example/bleve
go run bleve_gojieba_demo.go
go run example/bleve/bleve_gojieba_demo.go
```

See Details in [example/bleve/bleve_gojieba_demo.go](example/bleve/bleve_gojieba_demo.go)
Expand Down
3 changes: 1 addition & 2 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ go get github.com/yanyiwu/gojieba
See example in [example/demo.go](example/demo.go)

```
cd example
go run demo.go
go run example/demo.go
```

Output Result:
Expand Down
14 changes: 11 additions & 3 deletions example/bleve/bleve_gojieba_demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ import (
"encoding/json"
"fmt"
"os"
"path"

"github.com/blevesearch/bleve"
_ "github.com/yanyiwu/gojieba/bleve"
)

var (
DICT_DIR = path.Join(os.Getenv("GOPATH"), "src/github.com/yanyiwu/gojieba/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")
)

func main() {
messages := []struct {
Id string
Expand Down Expand Up @@ -38,9 +46,9 @@ func main() {

err := indexMapping.AddCustomTokenizer("gojieba",
map[string]interface{}{
"dictpath": "../../dict/jieba.dict.utf8",
"hmmpath": "../../dict/hmm_model.utf8",
"userdictpath": "../../dict/user.dict.utf8",
"dictpath": DICT_PATH,
"hmmpath": HMM_PATH,
"userdictpath": USER_DICT_PATH,
"type": "gojieba",
},
)
Expand Down
16 changes: 10 additions & 6 deletions example/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ package main

import (
"fmt"
"os"
"path"
"strings"

"github.com/yanyiwu/gojieba"
)

const (
DICT_PATH = "../dict/jieba.dict.utf8"
HMM_PATH = "../dict/hmm_model.utf8"
USER_DICT_PATH = "../dict/user.dict.utf8"
IDF_PATH = "../dict/idf.utf8"
STOP_WORDS_PATH = "../dict/stop_words.utf8"
var (
DICT_DIR = path.Join(os.Getenv("GOPATH"), "src/github.com/yanyiwu/gojieba/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")
IDF_PATH = path.Join(DICT_DIR, "idf.utf8")
STOP_WORDS_PATH = path.Join(DICT_DIR, "stop_words.utf8")
)

func DemoJieba() {
println(DICT_DIR)
fmt.Println("DemoJieba")
var words []string
use_hmm := true
Expand Down

0 comments on commit 94b0293

Please sign in to comment.