Esempio n. 1
0
// Destroy is a method to delete lattice object
func (l *Lattice) Destroy() {
	l.mutex.Lock()
	defer l.mutex.Unlock()
	if l.isAlive {
		C.mecab_lattice_destroy(l.toMecabLatticeT())
		l.memorize.Clear()
		l.isAlive = false
	}
}
Esempio n. 2
0
// 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
	}
}
Esempio n. 3
0
func (l Lattice) Destroy() {
	C.mecab_lattice_destroy(l.lattice)
}