コード例 #1
0
        public virtual Distribute <char> GetDistribute(Condition condition)
        {
            var dtb = GetDistribute(condition.Chars);

            if (condition.Pinyin != null)
            {
                dtb = dtb.Where(c => PinyinDict.GetPinyins(c).Contains(condition.Pinyin));
            }
            return(dtb);
        }
コード例 #2
0
        public void TestData(TextReader reader, TextWriter resultWriter = null, string format = "chinese_only")
        {
            resultWriter?.WriteLine("----- Inputer Test Report -----");
            for (int i = 0; i < Inputers.Length; ++i)
            {
                resultWriter?.WriteLine($"No.{i}: {Inputers[i].Name}");
            }
            resultWriter?.WriteLine("-------------------------------");

            string chinese;
            IEnumerable <string> pinyins;

            for (int i = 0; reader.Peek() != -1; ++i)
            {
                if (format == "pinyin_chinese")
                {
                    pinyins = reader.ReadLine().Trim().ToLower().Split(' ');
                    chinese = reader.ReadLine().Trim();
                }
                else if (format == "chinese_only")
                {
                    chinese = reader.ReadLine().Trim();
                    if (chinese == "")
                    {
                        continue;
                    }
                    pinyins = chinese.Select(c => PinyinDict.GetPinyins(c).FirstOrDefault())
                              .Where(s => s != null);
                }
                else
                {
                    throw new ArgumentException(nameof(format));
                }
                var cmps = new SentenseCompareMultiple(chinese);
                foreach (var inputer in Inputers)
                {
                    var compare = TestSentense(inputer, chinese, pinyins);
                    Results[inputer].Count(compare);
                    cmps.Add(inputer, compare);
                }
                resultWriter?.WriteLine(cmps);

                if (PrintToConsoleAfter != 0 && i % PrintToConsoleAfter == 0)
                {
                    Console.WriteLine($"Test Count = {i}");
                }
            }
            resultWriter?.WriteLine("Results:");
            for (int i = 0; i < Inputers.Length; ++i)
            {
                resultWriter?.WriteLine($"{i}: {Results[Inputers[i]]}");
            }
        }
コード例 #3
0
        public override Distribute <char> GetDistribute(Condition condition)
        {
            var list = new List <Distribute <char> >();

            for (int n = 0; n < 6; ++n)
            {
                var dtb = dict.GetOrDefault(condition.Chars.LastSubString(n, ' '));
                if (condition.Pinyin != null)
                {
                    dtb = dtb.Where(c => PinyinDict.GetPinyins(c).Contains(condition.Pinyin));
                }
//				if (dtb.IsEmpty)
//					break;
                list.Add(dtb);
            }
            //Console.WriteLine($"{condition} {list.Count-1}");
            return(MixDistributeStrategy(list));
        }