Example #1
0
 private static void ParseTextFile(string fname, TSChineseDictionary dict)
 {
     using (var reader = new StreamReader(fname, Encoding.UTF8))
     {
         int    lineCount = 0;
         string s         = reader.ReadLine();
         while (s != null)
         {
             if (!s.StartsWith(';'))
             {
                 string[] words = s.Split('=', ',');
                 if (words.Length >= 2)
                 {
                     dict.Add(words[0], words[1]);
                 }
             }
             lineCount++;
             if (lineCount % 100 == 0)
             {
                 Console.Write(".");
             }
             s = reader.ReadLine();
         }
     }
 }
Example #2
0
        public void ConvertToSimplifiedChinese()
        {
            var myDict = new TSChineseDictionary(Log.Logger);

            myDict.Add("擴充方法=擴展方法;extension method")
            .Add("預設=默認=default")
            .Add("建構函式=構造函數")
            .Add("類別名稱=類名")
            .Add("類別=類;class");

            string input          = "Convert() 是一個擴充方法,它所擴充的類別名稱是 Foo。Foo 類別有提供預設建構函式。";
            string expectedResult = "Convert() 是一个扩展方法,它所扩充的类名是 Foo。Foo 类有提供默认构造函数。";
            var    converter      = new TSChineseConverter();
            string result         = converter.ToSimplifiedChinese(input, myDict);

            Assert.AreEqual(result, expectedResult);
        }
Example #3
0
        private static void ParseTongWenJsonFile(string fname, TSChineseDictionary dict)
        {
            var content      = File.ReadAllText(fname, Encoding.UTF8);
            var tongWenTable = JsonConvert.DeserializeObject <TongWenPhraseTable>(content);
            int lastProgress = -1;

            dict.Add(tongWenTable.Map,
                     (sender, args) =>
            {
                if (lastProgress != args.ProgressPercentage)
                {
                    lastProgress = args.ProgressPercentage;
                    if (lastProgress % 10 == 0)
                    {
                        Console.WriteLine($"{lastProgress}%");
                    }
                    else
                    {
                        Console.Write(".");
                    }
                }
            });
        }