// Create a new stemmer, ready for use with the specified language func NewStemmer(language string) (*Stemmer, error) { clang := C.CString(strings.ToLower(language)) defer C.free(unsafe.Pointer(clang)) cchar := C.CString("UTF_8") defer C.free(unsafe.Pointer(cchar)) tmp := C.sb_stemmer_new(clang, cchar) if tmp == nil { return nil, fmt.Errorf("Unable to create stemmer, please ensure you are using a valid language") } stemmer := &Stemmer{ stemmer: tmp, lock: new(sync.Mutex), } return stemmer, nil }
// New creates a new stemmer for lang func New(lang string) (*Stemmer, error) { clang := C.CString(lang) defer C.free(unsafe.Pointer(clang)) stmr := &Stemmer{ lang, C.sb_stemmer_new(clang, nil), } if stmr.stmr == nil { return nil, fmt.Errorf("can't create stemmer for lang %s", lang) } runtime.SetFinalizer(stmr, free) return stmr, nil }
// Creates new word stemmer with specified algorithm and encoding identifiers. If it is successfully created, it // must be closed as it needs to free native Snowball resources. // // NOTE: Check libstemmer/modules.txt for allowed names of algorithms and encodings. func NewWordStemmer(algorithm string, encoding string) (*WordStemmer, error) { ws := new(WordStemmer) algStr := C.CString(algorithm) encStr := C.CString(encoding) defer C.free(unsafe.Pointer(algStr)) defer C.free(unsafe.Pointer(encStr)) ws.stemmer = C.sb_stemmer_new(algStr, encStr) if nil == ws.stemmer { return nil, fmt.Errorf("Cannot create word stemmer with algorithm: '%s' and encoding: '%s'", algorithm, encoding) } ws.algorithm = algorithm ws.encoding = encoding return ws, nil }