Esempio n. 1
0
        /// <summary>
        /// Configure Kakasi
        /// </summary>
        public void ConfigureKakasi()
        {
            /* IMPORTANT:
             *  The native libkakasi.dll library will look for these 2 dictionary files:
             *
             *  itaijidict
             *  kanwadict
             *
             *  When running as a web application, the search path used by the library will be the same as the
             *  running host process (e.g: iisexpress.exe, w3wp.exe) and not the path of the running web application.
             *
             *  If it can't find any one of these file, the library will exit the running process, which is far from ideal.
             *
             *  It's possible to set 2 environment variables that the native library will use instead of the executing path.
             *
             *  KANWADICTPATH for the full path to the dictionary file: kanwadict
             *  ITAIJIDICTPATH for the full path to the dictionary file: itaijidict
             *
             *  Make sure these variables are set in the running host process otherwise it won't work and any call to
             *  the native library will kill the running process.
             */

            // Get the bin folder of the current app domain
            var applicationBinPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin");

            // Init library using
            KakasiLib.Init(applicationBinPath);

            // Set params to get Furigana
            // NOTE: Use EUC-JP encoding as the wrapper will encode/decode using it
            KakasiLib.SetParams(new[] { "kakasi", "-ieuc", "-f", "-JH", "-w" });
        }
        public string Get()
        {
            // Set source sentence
            var value = @"この森は昼でも薄暗く、気味が悪いので、村人は誰も近づかないのでした。";

            // Get furigana
            var result = KakasiLib.DoKakasi(value);

            // Return
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Main entry point
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Initialize library
            KakasiLib.Init();

            // Set params to get Furigana
            // NOTE: Use EUC-JP encoding as the wrapper will encode/decode using it
            KakasiLib.SetParams(new[] { "kakasi", "-ieuc", "-f", "-JH", "-w" });

            // Get furigana from this book: アンブラとパン先生 by 伊藤 綾子
            // http://itunes.apple.com/us/book/id1144287620

            // Set source sentence
            var value1 = @"この森は昼でも薄暗く、気味が悪いので、村人は誰も近づかないのでした。";

            // Get furigana
            var resultValue1 = KakasiLib.DoKakasi(value1);

            // Expected result
            // この 森[もり] は 昼[ひる] でも 薄暗く[うすぐらく] 、 気味[きみ] が 悪い[わるい] ので 、 村人[むらびと] は 誰も[だれも] 近づ[ちかづ] かないのでした 。
            Debug.Assert(resultValue1 == @"この 森[もり] は 昼[ひる] でも 薄暗く[うすぐらく] 、 気味[きみ] が 悪い[わるい] ので 、 村人[むらびと] は 誰も[だれも] 近づ[ちかづ] かないのでした 。");

            // Get furigana from this book: プカプカ島の謎 by 伊藤 綾子
            // http://itunes.apple.com/us/book/id1146306209

            // Set source sentence
            var value2 = @"この島の住人を紹介しましょう";

            // Get furigana
            var resultValue2 = KakasiLib.DoKakasi(value2);

            // Expected result
            // この 島[しま] の 住人[じゅうにん] を 紹介[しょうかい] しましょう
            Debug.Assert(resultValue2 == @"この 島[しま] の 住人[じゅうにん] を 紹介[しょうかい] しましょう");

            // Dispose of library
            KakasiLib.Dispose();
        }