Example #1
0
// Destroy is a method to delete Tagger object
// This method calles "delete tagger". In some environment, e.g., MS-Windows, an object allocated inside a DLL must be deleted in the same DLL too.
func (t *Tagger) Destroy() {
	t.mutex.Lock()
	defer t.mutex.Unlock()
	if t.isAlive {
		C.mecab_destroy(t.toMecabT())
		t.memorize.Clear()
		t.isAlive = false
	}
}
Example #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
	}
}
Example #3
0
// Clean up the tagger
func (t *Tagger) Destroy() {
	C.mecab_destroy(t.tagger)
}