Esempio n. 1
0
        private static void InstanceServices()
        {
            if (_dataBaseLogServices == null)
            {
                _dataBaseLogServices = new DataBaseLogServices();
            }

            if (_fileLogServices == null)
            {
                _fileLogServices = new FileLogServices();
            }

            if (_consoleLogServices == null)
            {
                _consoleLogServices = new ConsoleLogServices();
            }
        }
Esempio n. 2
0
        public void InitializeResource()
        {
            try
            {
                var resourceName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PinyinDb/unicode_to_hanyu_pinyin.txt");

                var table = File.ReadLines(resourceName)
                            .AsParallel()
                            .Select(l => l.Split(' '))
                            .ToDictionary(l => l[0], l => l[1]);
                UnicodeToHanyuPinyinTable = new ConcurrentDictionary <string, string>(table);
            }
            catch (FileNotFoundException ex)
            {
                FileLogServices.WriteLogToFile(ex.Message);
            }
            catch (IOException ex)
            {
                FileLogServices.WriteLogToFile(ex.Message);
            }
        }
Esempio n. 3
0
 private void InitializeResource()
 {
     try
     {
         var         mappingFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pinyindb/pinyin_gwoyeu_mapping.xml");
         XmlDocument doc             = new XmlDocument();
         doc.Load(mappingFileName);
         _pinyinToGwoyeuMappingDoc = doc;
     }
     catch (FileNotFoundException ex)
     {
         FileLogServices.WriteLogToFile(ex.ToString());
     }
     catch (IOException ex)
     {
         FileLogServices.WriteLogToFile(ex.ToString());
     }
     catch (Exception ex)
     {
         FileLogServices.WriteLogToFile(ex.ToString());
     }
 }
Esempio n. 4
0
        public string GetGwoyeuRomatzyh(string hanyuPinyinStr)
        {
            var pinyinString  = Util.ExtractPinyinString(hanyuPinyinStr);
            var toneNumberStr = Util.ExtractToneNumber(hanyuPinyinStr);

            // return value
            var gwoyeuStr = string.Empty;

            try
            {
                // find the node of source Pinyin system
                var xpathQuery1 = "//"
                                  + PinyinRomanizationType.HANYU_PINYIN.TagName
                                  + "[text()='" + pinyinString + "']";

                var pinyinToGwoyeuMappingDoc = _pinyinToGwoyeuMappingDoc;

                var hanyuNode = pinyinToGwoyeuMappingDoc.SelectSingleNode(xpathQuery1);

                if (null != hanyuNode)
                {
                    // find the node of target Pinyin system
                    var xpathQuery2 = "../"
                                      + PinyinRomanizationType.GWOYEU_ROMATZYH.TagName
                                      + tones[int.Parse(toneNumberStr) - 1]
                                      + "/text()";
                    var targetPinyinStrWithoutToneNumber = hanyuNode.SelectSingleNode(xpathQuery2).Value;

                    gwoyeuStr = targetPinyinStrWithoutToneNumber;
                }
            }
            catch (Exception e)
            {
                FileLogServices.WriteLogToFile(e.ToString());
            }

            return(gwoyeuStr);
        }
Esempio n. 5
0
        public string GetRomanizationString(string sourcePinyinStr, PinyinRomanizationType sourcePinyinSystem, PinyinRomanizationType targetPinyinSystem)
        {
            var pinyinString  = Util.ExtractPinyinString(sourcePinyinStr);
            var toneNumberStr = Util.ExtractToneNumber(sourcePinyinStr);

            // return value
            var targetPinyinStr = string.Empty;

            try
            {
                // find the node of source Pinyin system
                var xpathQuery1 = "//" + sourcePinyinSystem.TagName
                                  + "[text()='" + pinyinString + "']";

                var pinyinMappingDoc = _pinyinMappingDoc;

                var hanyuNode = pinyinMappingDoc.SelectSingleNode(xpathQuery1);

                if (null != hanyuNode)
                {
                    // find the node of target Pinyin system
                    var xpathQuery2 = "../" + targetPinyinSystem.TagName
                                      + "/text()";
                    var targetPinyinStrWithoutToneNumber = hanyuNode.SelectSingleNode(xpathQuery2).Value;

                    targetPinyinStr = targetPinyinStrWithoutToneNumber
                                      + toneNumberStr;
                }
            }
            catch (Exception e)
            {
                FileLogServices.WriteLogToFile(e.ToString());
            }

            return(targetPinyinStr);
        }