yanyiwu / gojieba

"结巴"中文分词的Golang版本
MIT License
2.43k stars 302 forks source link

Example panic #8

Closed douglarek closed 8 years ago

douglarek commented 8 years ago
package main

import (
    "fmt"
    "strings"

    "github.com/yanyiwu/gojieba"
)

func main() {
    var s string
    var words []string
    use_hmm := true
    x := gojieba.NewJieba()
    defer x.Free()

    s = "我来到北京清华大学"
    words = x.CutAll(s)
    fmt.Println(s)
    fmt.Println("全模式:", strings.Join(words, "/"))

    words = x.Cut(s, use_hmm)
    fmt.Println(s)
    fmt.Println("精确模式:", strings.Join(words, "/"))
    s = "比特币"
    words = x.Cut(s, use_hmm)
    fmt.Println(s)
    fmt.Println("精确模式:", strings.Join(words, "/"))

    x.AddWord("比特币")
    s = "比特币"
    words = x.Cut(s, use_hmm)
    fmt.Println(s)
    fmt.Println("添加词典后,精确模式:", strings.Join(words, "/"))

    s = "他来到了网易杭研大厦"
    words = x.Cut(s, use_hmm)
    fmt.Println(s)
    fmt.Println("新词识别:", strings.Join(words, "/"))

    s = "小明硕士毕业于中国科学院计算所,后在日本京都大学深造"
    words = x.CutForSearch(s, use_hmm)
    fmt.Println(s)
    fmt.Println("搜索引擎模式:", strings.Join(words, "/"))

    s = "长春市长春药店"
    words = x.Tag(s)
    fmt.Println(s)
    fmt.Println("词性标注:", strings.Join(words, ","))

    s = "区块链"
    words = x.Tag(s)
    fmt.Println(s)
    fmt.Println("词性标注:", strings.Join(words, ","))

    s = "长江大桥"
    words = x.CutForSearch(s, !use_hmm)
    fmt.Println(s)
    fmt.Println("搜索引擎模式:", strings.Join(words, "/"))

    wordinfos := x.Tokenize(s, gojieba.SearchMode, !use_hmm)
    fmt.Println(s)
    fmt.Println("Tokenize:(搜索引擎模式)", wordinfos)

    wordinfos = x.Tokenize(s, gojieba.DefaultMode, !use_hmm)
    fmt.Println(s)
    fmt.Println("Tokenize:(默认模式)", wordinfos)

    ex := gojieba.NewExtractor()
    defer ex.Free()
    keywords := ex.ExtractWithWeight(s, 5)
    fmt.Println("Extract:", keywords)
}
2016-09-06 16:10:10 ./deps/cppjieba/DictTrie.hpp:153 FATAL exp: [ifs.is_open()] false. open /Users/lingchax/.go/src/github.com/yanyiwu/gojieba/dict/jieba.dict.utf8 failed.
SIGABRT: abort
PC=0x7fff9080cf06 m=0
signal arrived during cgo execution

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x40925b0, 0xc42004f9a0, 0xc400000000)
        /usr/local/Cellar/go/1.7/libexec/src/runtime/cgocall.go:131 +0x110 fp=0xc42004f970 sp=0xc42004f930
hello/vendor/github.com/yanyiwu/gojieba._Cfunc_NewJieba(0x4503290, 0x45032e0, 0x4503370, 0x0)
        ??:0 +0x4e fp=0xc42004f9a0 sp=0xc42004f970
hello/vendor/github.com/yanyiwu/gojieba.NewJieba(0x0, 0x0, 0x0, 0x0)
        /Users/lingchax/.go/src/hello/vendor/github.com/yanyiwu/gojieba/jieba.go:37 +0x1b3 fp=0xc42004fa90 sp=0xc42004f9a0
main.main()
        /Users/lingchax/.go/src/hello/main.go:14 +0x51 fp=0xc42004ff48 sp=0xc42004fa90
runtime.main()
        /usr/local/Cellar/go/1.7/libexec/src/runtime/proc.go:183 +0x1f4 fp=0xc42004ffa0 sp=0xc42004ff48
runtime.goexit()
        /usr/local/Cellar/go/1.7/libexec/src/runtime/asm_amd64.s:2086 +0x1 fp=0xc42004ffa8 sp=0xc42004ffa0

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
        /usr/local/Cellar/go/1.7/libexec/src/runtime/asm_amd64.s:2086 +0x1

rax    0x0
rbx    0x6
rcx    0x7fff5fbff0f8
rdx    0x0
rdi    0x307
rsi    0x6
rbp    0x7fff5fbff120
rsp    0x7fff5fbff0f8
r8     0x8
r9     0x0
r10    0x8000000
r11    0x206
r12    0x7fff5fbff40a
r13    0x4802000
r14    0x7fff78114000
r15    0x7fff759af398
rip    0x7fff9080cf06
rflags 0x206
cs     0x7
fs     0x0
gs     0x0
exit status 2

go env:

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/lingchax/.go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/1x/d4dgqvms23bgmjpyshv4j6580000gn/T/go-build873055974=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
yanyiwu commented 8 years ago

open /Users/lingchax/.go/src/github.com/yanyiwu/gojieba/dict/jieba.dict.utf8 failed 你看一些这个文件是否存在?

douglarek commented 8 years ago

@yanyiwu 貌似不支持 Go 1.5 之后的 vendor ?

douglarek commented 8 years ago

/Users/lingchax/.go/src/github.com/yanyiwu/gojieba/dict/jieba.dict.utf8 不存在,但是 /Users/lingchax/.go/src/hello/vendor/github.com/yanyiwu/gojieba/dict/jieba.dict.utf8 存在

yanyiwu commented 8 years ago

@douglarek 最新版本 v0.17.1 里面已经修复这个问题。

douglarek commented 8 years ago

@yanyiwu It works, thanks