コード例 #1
0
 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()));
     }
 }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        public static bool LoadDll(string path = null)
        {
            if (dllHandle != IntPtr.Zero)
            {
                return(true);
            }

            if (path == null)
            {
                path = GetDefaultPath();
            }
            return((dllHandle = KiwiCAPI.LoadDll(path)) != IntPtr.Zero);
        }
コード例 #7
0
        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()));
            }
        }
コード例 #8
0
        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);
        }
コード例 #9
0
 public static string Version()
 {
     return(Marshal.PtrToStringAnsi(KiwiCAPI.kiwi_version()));
 }