/** * 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); }
/** * 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); }
/** * 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); }
/** * Loader setter. */ public Pinyin SetLoader(DictLoaderInterface loader) { this.loader = loader; return(this); }