示例#1
0
        //public static SmartHackDbContext _context;

        public static async Task ExecuteAsync(SmartHackDbContext _context)
        {
            var companies = await _context.Companies.Include(x => x.Newses).ToListAsync();

            foreach (var company in companies)
            {
                var news = company.Newses.OrderByDescending(x => x.Time).FirstOrDefault();
                if (news != null)
                {
                    var newsType = ClassifierLearner.Clasify(news.Content);
                    AppNaiveBayes.learnNaiveBayes(company.Percent, newsType, company.Id);
                }
                var result  = AppNaiveBayes.getNaiveBayesResult("Positive", companies.FirstOrDefault().Id);
                var result2 = result;
            }
        }
        public static string getNaiveBayesResult(string newsType, Guid companyId)
        {
            try
            {
                int[] info = codebook.Translate(new string[] { "NewsType", "CompanyId" }, new string[] { newsType.ToString(), companyId.ToString() });
                //int[] info = codebook.Transform(new string[] { newsType, companyId.ToString() });
                if (naiveBayes == null)
                {
                    instance = AppNaiveBayes.Instance;
                }

                if (naiveBayes != null)
                {
                    int    c      = naiveBayes.Decide(info);
                    string result = codebook.Translate("Percent", c);
                    return(result);
                }
                return("-1");
            }
            catch (Exception e)
            {
                return("-1");
            }
        }