public JsonResult ReponseCaro(String Question) { try { AskCaro_QuestionnaireAspirateur.StackOverflowAspirateur main = new AskCaro_QuestionnaireAspirateur.StackOverflowAspirateur(); var target = Question; var text = AskCaro_Web_MVC.Tools.WordsAnalyzer.StringWords2Remove(target); var targetHS = text.Split(' ').ToHashSet(); var closeNeighbors = from h in _dbContext.Questions.AsEnumerable() // bring into memory // query continued below as linq-to-objects //let score = (0.15 * LevenshteinDistance.Calculate(text, h.Tag) + 0.35 * LevenshteinDistance.Calculate(text.ToLower(), h.Tag.ToLower())) / Math.Max(text.Length, h.Tag.Length) let lD = Tools.Class1.LevenshteinDistance(target, h.Tag) let length = Math.Max(h.Tag.Length, target.Length) let score = 1.0 - (double)lD / length where score > 0.25 select new { h, score }; var listttt = closeNeighbors.OrderByDescending(x => x.score).First(); return(Json(new { Answer = listttt.h.HtmlAnswers, LinkHref = listttt.h.LinkHref })); } catch (Exception ex) { return(Json(new { Answer = "Sorry i can help for this question. I am trying to learning more to give a perfect answer in future" })); } }
public ActionResult Index22() { AskCaro_QuestionnaireAspirateur.StackOverflowAspirateur main = new AskCaro_QuestionnaireAspirateur.StackOverflowAspirateur(); var target = "Is there a best practice and recommended alternative to Session variables in MVC"; var text = AskCaro_Web_MVC.Tools.WordsAnalyzer.StringWords2Remove(target); var targetHS = text.Split(' ').ToHashSet(); var closeNeighbors = from h in _dbContext.Questions.AsEnumerable() // bring into memory // query continued below as linq-to-objects let score = (0.15 * LevenshteinDistance.Calculate(text, h.Tag) + 0.35 * LevenshteinDistance.Calculate(text.ToLower(), h.Tag.ToLower())) / Math.Max(text.Length, h.Tag.Length) //let lD = Tools.Class1.LevenshteinDistance(target, h.Tag) //let length = Math.Max(h.Tag.Length, target.Length) //let score = 1.0 - (double)lD / length where score > 0.25 select new { h, score }; var listttt = closeNeighbors.OrderByDescending(x => x.score).Take(10).ToList(); return(View()); }
public IActionResult Index() { AskCaro_QuestionnaireAspirateur.StackOverflowAspirateur main = new AskCaro_QuestionnaireAspirateur.StackOverflowAspirateur(); string countt = main.GetLastPageNumbers(); int count = int.Parse(countt); int simillar = 4736; for (int i = 317; i < count; i++) { var item = main.Start(i); foreach (var x in item) { List <QuestionModel> questionModels = new List <QuestionModel>(); QuestionModel questionModel = new QuestionModel(); questionModel.Title = x.title; questionModel.Similar = simillar; questionModel.LinkHref = x.hreflink; questionModel.TextDescription = main.GetDescrip(x.hreflink); questionModel.HtmlDescription = main.GetDescripHtml(x.hreflink); questionModel.Answers = new List <AnswerModel>(); foreach (var answers in main.GetBestanswers(x.hreflink)) { AnswerModel AnswerModel = new AnswerModel(); AnswerModel.Htmldescription = answers.Htmldescription; AnswerModel.Textdescription = answers.Textdescription; AnswerModel.voteCount = answers.voteCount; questionModel.Answers.Add(AnswerModel); } int maxZ = 0; if (questionModel.Answers.Count > 0) { maxZ = questionModel.Answers.Max(obj => obj.voteCount); questionModel.HtmlAnswers = questionModel.Answers.Where(obj => obj.voteCount == maxZ).FirstOrDefault().Htmldescription; } questionModels.Add(questionModel); //AskCaro_QuestionnaireAspirateur.GoogleAspirateur googleAspirateur = new AskCaro_QuestionnaireAspirateur.GoogleAspirateur(); //var listgoogle = googleAspirateur.Start(x.title, x.hreflink, "stackoverflow.com"); //foreach (var google in listgoogle) //{ // QuestionModel questionModelSimilar = new QuestionModel(); // questionModelSimilar.Title = google.Title; // questionModelSimilar.Similar = simillar; // questionModelSimilar.LinkHref = google.hreflink; // questionModelSimilar.TextDescription = main.GetDescrip(google.hreflink); // questionModelSimilar.HtmlDescription = main.GetDescrip(google.hreflink); // questionModelSimilar.HtmlAnswers = questionModel.HtmlAnswers; // questionModels.Add(questionModelSimilar); //} simillar++; //if (simillar % 40 == 0) //{ // System.Threading.Thread.Sleep(10000); //} _dbContext.Questions.AddRange(questionModels); var result = _dbContext.SaveChanges(); System.Threading.Thread.Sleep(1000); } } return(View()); }
public ActionResult run(string tag) { AskCaro_QuestionnaireAspirateur.StackOverflowAspirateur main = new AskCaro_QuestionnaireAspirateur.StackOverflowAspirateur(); string countt = main.GetLastPageNumbers(tag); int count = int.Parse(countt); int simillar = 0; for (int i = 0; i < count; i++) { var item = main.Start(i, tag); foreach (var x in item) { List <QuestionModel> questionModels = new List <QuestionModel>(); QuestionModel questionModel = new QuestionModel(); questionModel.Title = x.title; var checkDb = _dbContext.Questions.Where(y => y.Title == x.title).FirstOrDefault(); if (checkDb == null) { questionModel.Similar = simillar; questionModel.LinkHref = x.hreflink; questionModel.TextDescription = main.GetDescrip(x.hreflink); questionModel.HtmlDescription = main.GetDescripHtml(x.hreflink); var html = AskCaro_Web_MVC.Tools.WordsAnalyzer.RemoveTag(questionModel.HtmlDescription, "<code", "</code>"); html = AskCaro_Web_MVC.Tools.WordsAnalyzer.RemoveTag(html, "(", ")"); string InnerText = main.GetInnerText(html).Replace("\r", "").Replace("\n", ""); questionModel.Tag = AskCaro_Web_MVC.Tools.WordsAnalyzer.StringWords2Remove(x.title).Replace("-", " ") + " " + AskCaro_Web_MVC.Tools.WordsAnalyzer.StringWords2Remove(InnerText); questionModel.Answers = new List <AnswerModel>(); foreach (var answers in main.GetBestanswers(x.hreflink)) { AnswerModel AnswerModel = new AnswerModel(); AnswerModel.Htmldescription = answers.Htmldescription; AnswerModel.Textdescription = answers.Textdescription; AnswerModel.voteCount = answers.voteCount; questionModel.Answers.Add(AnswerModel); } int maxZ = 0; if (questionModel.Answers.Count > 0) { maxZ = questionModel.Answers.Max(obj => obj.voteCount); questionModel.HtmlAnswers = questionModel.Answers.Where(obj => obj.voteCount == maxZ).FirstOrDefault().Htmldescription; } _dbContext.Questions.Add(questionModel); var result = _dbContext.SaveChanges(); AskCaro_QuestionnaireAspirateur.GoogleAspirateur googleAspirateur = new AskCaro_QuestionnaireAspirateur.GoogleAspirateur(); var listgoogle = googleAspirateur.Start(x.title, x.hreflink, "stackoverflow.com"); foreach (var google in listgoogle) { if (google.Title != questionModel.Title) { QuestionModel questionModelSimilar = new QuestionModel(); questionModelSimilar.Title = google.Title; questionModelSimilar.Similar = simillar; questionModelSimilar.LinkHref = google.hreflink; questionModelSimilar.TextDescription = main.GetDescrip(google.hreflink); questionModelSimilar.HtmlDescription = main.GetDescrip(google.hreflink); var htmlgoogle = AskCaro_Web_MVC.Tools.WordsAnalyzer.RemoveTag(questionModelSimilar.HtmlDescription, "<code", "</code>"); htmlgoogle = AskCaro_Web_MVC.Tools.WordsAnalyzer.RemoveTag(htmlgoogle, "(", ")"); string InnerTextgoogle = main.GetInnerText(htmlgoogle).Replace("\r", "").Replace("\n", ""); questionModel.Tag = AskCaro_Web_MVC.Tools.WordsAnalyzer.StringWords2Remove(google.Title).Replace("-", " ") + " " + AskCaro_Web_MVC.Tools.WordsAnalyzer.StringWords2Remove(InnerTextgoogle); questionModelSimilar.HtmlAnswers = questionModel.HtmlAnswers; questionModels.Add(questionModelSimilar); } } simillar++; if (simillar % 40 == 0) { System.Threading.Thread.Sleep(10000); } System.Threading.Thread.Sleep(1000); } } } return(View()); }