コード例 #1
0
ファイル: lattice.go プロジェクト: mkitawaki/mecab-go
// SetSentence is a method to set sentence
func (l *Lattice) SetSentence(input string) {
	i := C.CString(input)
	l.memorize.Cache("SetSentence", i)
	// defer C.free(unsafe.Pointer(i))
	C.mecab_lattice_set_sentence(l.toMecabLatticeT(), i)

}
コード例 #2
0
ファイル: mecab.go プロジェクト: hasenbanck/gokumo
// Parses a sentence using mecab
func mecabParser(q chan mecabRequest) {
	model := C.mecab_model_new2(C.CString(""))
	if model == nil {
		log.Panicln("Can't create a mecab model")
	}
	defer C.mecab_model_destroy(model)

	mecab := C.mecab_model_new_tagger(model)
	if mecab == nil {
		log.Panicln("Can't create a mecab tagger")
	}
	defer C.mecab_destroy(mecab)

	lattice := C.mecab_model_new_lattice(model)
	if lattice == nil {
		log.Panicln("Can't create a mecab lattice")
	}
	defer C.mecab_lattice_destroy(lattice)

	for {
		req := <-q

		res := make([]mecabResult, 0)
		C.mecab_lattice_set_sentence(lattice, C.CString(req.Sentence))
		C.mecab_parse_lattice(mecab, lattice)

		lines := strings.Split(C.GoString(C.mecab_lattice_tostr(lattice)), "\n")
		for _, l := range lines {
			if strings.Index(l, "EOS") != 0 {
				if len(l) > 1 {
					res = append(res, split(l))
				}
			}
		}

		req.Result <- res
	}
}