Пример #1
0
 public static string Translate(string source)
 {
     if (string.IsNullOrEmpty(source))
     {
         return(source);
     }
     mutex.WaitOne();
     try
     {
         byte[] inp  = MecabEncoding.GetBytes(source);
         IntPtr outp = mecab_sparse_tostr(mecab, inp);
         string result;
         if (outp != IntPtr.Zero)
         {
             result = MecabEncoding.GetString(PInvokeFunc.ByteArrayFromPtr(outp));
         }
         else
         {
             result = null;
         }
         return(result);
     }
     finally
     {
         mutex.ReleaseMutex();
     }
 }
Пример #2
0
        public static string Translate(string source)
        {
            if (source == null)
            {
                return(source);
            }
            bool haveLetters = false;

            foreach (char ch in source)
            {
                if (char.IsLetter(ch))
                {
                    haveLetters = true;
                    break;
                }
            }
            if (!haveLetters)
            {
                return(source);
            }
            //long before = DateTime.Now.Ticks;
            mutex.WaitOne();
            try
            {
                IntPtr outp;
                IntPtr tmp;
                uint   size;
                byte[] inp = Encoding932.GetBytes(source);
                TranslatePair(inp, out outp, out tmp, out size);
                string result;
                if (outp != IntPtr.Zero)
                {
                    result = Encoding932.GetString(PInvokeFunc.ByteArrayFromPtr(outp));
                    FreeAtlasData(outp, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                }
                else
                {
                    result = null;
                }
                if (tmp != IntPtr.Zero)
                {
                    /*if (result != null)
                     * {
                     *  string s = Encoding932.GetString(PInvokeFunc.ByteArrayFromPtr(tmp));
                     *  result += " [" + s + "]";
                     * }*/
                    FreeAtlasData(tmp, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                }
                return(result);
            }
            finally
            {
                mutex.ReleaseMutex();
                //Form1.Debug(((double)(DateTime.Now.Ticks - before) / 10000000).ToString());
            }
        }