コード例 #1
0
        /// <summary>
        /// 搜索问题
        /// </summary>
        /// <param name="kingQuestion">问题</param>
        /// <returns></returns>
        public virtual BestOption Search(KingQuestion kingQuestion)
        {
            // 从badidu找出原始结论
            var quiz         = this.ClearNot(kingQuestion.data.quiz, out bool clearNot);
            var sourceAnswer = this.SearchSourceAnswers(quiz, trys: 1);

            if (sourceAnswer == null || sourceAnswer.Length == 0)
            {
                return(this.Next.Search(kingQuestion));
            }

            // 各个选项和结论的匹配次数
            var opts    = kingQuestion.data.options;
            var options = opts.Select((opt, i) => new
            {
                Index  = i,
                Option = opt,
                Score  = this.GetMatchScore(sourceAnswer, opt)
            }).ToArray();

            var best = clearNot ?
                       options.OrderBy(item => item.Score).FirstOrDefault() :
                       options.OrderByDescending(item => item.Score).FirstOrDefault();

            // 两个相同的结果,表示没有答案
            const int digits = 5;

            if (options.Any(item => item != best && Math.Round(item.Score, digits) == Math.Round(best.Score, digits)))
            {
                return(this.Next.Search(kingQuestion));
            }

            return(new BestOption
            {
                Index = best.Index,
                Option = best.Option
            });
        }
コード例 #2
0
 public override BestOption Search(KingQuestion kingQuestion)
 {
     return(null);
 }