mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 03:48:37 +08:00
5ea2454fdf
fix: #35800 --------- Signed-off-by: longjiquan <jiquan.long@zilliz.com>
41 lines
739 B
Go
41 lines
739 B
Go
package ctokenizer
|
|
|
|
/*
|
|
#cgo pkg-config: milvus_core
|
|
#include <stdlib.h> // free
|
|
#include "segcore/token_stream_c.h"
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"unsafe"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/tokenizerapi"
|
|
)
|
|
|
|
var _ tokenizerapi.TokenStream = (*CTokenStream)(nil)
|
|
|
|
type CTokenStream struct {
|
|
ptr C.CTokenStream
|
|
}
|
|
|
|
func NewCTokenStream(ptr C.CTokenStream) *CTokenStream {
|
|
return &CTokenStream{
|
|
ptr: ptr,
|
|
}
|
|
}
|
|
|
|
func (impl *CTokenStream) Advance() bool {
|
|
return bool(C.token_stream_advance(impl.ptr))
|
|
}
|
|
|
|
func (impl *CTokenStream) Token() string {
|
|
token := C.token_stream_get_token(impl.ptr)
|
|
defer C.free_token(unsafe.Pointer(token))
|
|
return C.GoString(token)
|
|
}
|
|
|
|
func (impl *CTokenStream) Destroy() {
|
|
C.free_token_stream(impl.ptr)
|
|
}
|