예제 #1
0
        /**
         * Return dict loader.
         */
        public DictLoaderInterface GetLoader()
        {
            if (this.loader == null)
            {
                string dataDir = Environment.CurrentDirectory + "/data/";

                string loaderName = this.loaderName;
                this.loader = (DictLoaderInterface)Activator.CreateInstance(Type.GetType(loaderName), dataDir);
            }

            return(this.loader);
        }
예제 #2
0
        /**
         * Convert Chinese Surname to pinyin.
         */
        protected string ConvertSurname(string str, DictLoaderInterface dictLoader)
        {
            dictLoader.MapSurname(delegate(Dictionary <string, string> dictionary)
            {
                foreach (string key in dictionary.Keys)
                {
                    if (str.IndexOf(key) == 0)
                    {
                        str = dictionary[key] + str.Substring(key.Length);
                        break;
                    }
                }
            });

            return(str);
        }
예제 #3
0
        /**
         * Convert Chinese to pinyin
         */
        protected string Romanize(string str, bool isName = false)
        {
            str = this.Prepare(str);

            DictLoaderInterface dictLoader = this.GetLoader();

            if (isName)
            {
                str = this.ConvertSurname(str, dictLoader);
            }

            dictLoader.Map(delegate(Dictionary <string, string> dictionary)
            {
                foreach (string key in dictionary.Keys)
                {
                    str = str.Replace(key, dictionary[key]);
                }
            });

            return(str);
        }
예제 #4
0
 /**
  * Loader setter.
  */
 public Pinyin SetLoader(DictLoaderInterface loader)
 {
     this.loader = loader;
     return(this);
 }