public KiwiBuilder(string modelPath, int numThreads = 0, Option options = Option.LoadDefaultDict | Option.IntegrateAllomorph) { inst = KiwiCAPI.kiwi_builder_init(new Utf8String(modelPath).IntPtr, numThreads, (int)options); if (inst == IntPtr.Zero) { throw new KiwiException(Marshal.PtrToStringAnsi(KiwiCAPI.kiwi_error())); } }
public Kiwi Build() { KiwiHandle ret = KiwiCAPI.kiwi_builder_build(inst); if (ret == IntPtr.Zero) { throw new KiwiException(Marshal.PtrToStringAnsi(KiwiCAPI.kiwi_error())); } return(new Kiwi(ret)); }
public int LoadDictionary(string dictPath) { int ret = KiwiCAPI.kiwi_builder_load_dict(inst, new Utf8String(dictPath).IntPtr); if (ret < 0) { throw new KiwiException(Marshal.PtrToStringAnsi(KiwiCAPI.kiwi_error())); } return(ret); }
public int AddWord(string word, string pos, float score) { int ret = KiwiCAPI.kiwi_builder_add_word(inst, new Utf8String(word).IntPtr, new Utf8String(pos).IntPtr, score); if (ret < 0) { throw new KiwiException(Marshal.PtrToStringAnsi(KiwiCAPI.kiwi_error())); } return(ret); }
public Result[] Analyze(string text, int topN = 1, Match matchOptions = Match.All) { KiwiResHandle res = KiwiCAPI.kiwi_analyze_w(inst, new Utf16String(text).IntPtr, topN, (int)matchOptions); if (inst == IntPtr.Zero) { throw new KiwiException(Marshal.PtrToStringAnsi(KiwiCAPI.kiwi_error())); } Result[] ret = KiwiCAPI.ToResult(res); KiwiCAPI.kiwi_res_close(res); return(ret); }
public void AnalyzeMulti(Reader reader, Receiver receiver, int topN = 1, Match matchOptions = Match.All) { GCHandle handle = GCHandle.Alloc(this); this.reader = reader; this.receiver = receiver; readItem = null; int ret = KiwiCAPI.kiwi_analyze_mw(inst, readerInst, receiverInst, (IntPtr)handle, topN, (int)matchOptions); handle.Free(); if (ret < 0) { throw new KiwiException(Marshal.PtrToStringAnsi(KiwiCAPI.kiwi_error())); } }
public ExtractedWord[] ExtractAddWords(Reader reader, int minCnt = 5, int maxWordLen = 10, float minScore = 0.1f, float posThreshold = -3) { GCHandle handle = GCHandle.Alloc(this); this.reader = reader; readItem = null; KiwiWsHandle ret = KiwiCAPI.kiwi_builder_extract_add_words_w(inst, readerInst, (IntPtr)handle, minCnt, maxWordLen, minScore, posThreshold); handle.Free(); if (inst == IntPtr.Zero) { throw new KiwiException(Marshal.PtrToStringAnsi(KiwiCAPI.kiwi_error())); } ExtractedWord[] words = KiwiCAPI.ToExtractedWord(ret); KiwiCAPI.kiwi_ws_close(ret); return(words); }