public IActionResult QuestionEdit(long id) { QuestionEditParam model = new QuestionEditParam(); var _model = SemEvalRepository.GetQuestionByIdAsync(id).Result; model.QBody = _model.QBody; model.QSubject = _model.QSubject; model.QuestionId = _model.QuestionId; using (TextHelper textHelper = new TextHelper()) { model.QSubjectClean = textHelper.CleanReview(_model.QSubject); model.QBodyClean = textHelper.CleanReview(_model.QBody); } return(View(model)); }
public static void ImportJsonToDB() { int[] forums = new int[] { 115, 116 }; int[] blockTopic = new int[] { 3298910, 1503527, 1662425, 3666349 }; ISemEvalRepository rep = new SemEvalRepository(); List <string> filePaths = new List <string>(); foreach (var forum in forums) { string path1 = Path.Combine(@"E:\", $"{forum}.zip"); Stopwatch stopWatch = new Stopwatch(); using (FileStream fs = new FileStream(path1, FileMode.Open)) using (ZipArchive zip = new ZipArchive(fs)) { if (zip.Entries.Count > 0) { for (int i = 0; i < zip.Entries.Count; i++) { stopWatch.Reset(); stopWatch.Start(); using (StreamReader sr = new StreamReader(zip.Entries[i].Open())) { string readText = sr.ReadToEnd(); Topic topic = new Topic(); if (string.IsNullOrEmpty(readText)) { continue; } try { topic = JsonConvert.DeserializeObject <Topic>(readText); } catch (Exception) { continue; } if (blockTopic.Contains(topic.TopicId)) { continue; } if (!usersDic.ContainsKey(topic.NickName)) { long userid = uc++; usersDic.Add(topic.NickName, userid); usersIdDic.Add(userid, topic.NickName); } Question q = new Question() { QuestionId = qc++, QID = topic.TopicId.ToString(), QSubject = topic.Question, QBody = topic.Description, QCATEGORY = forum.ToString(), QDATE = topic.CreateDatetime, QGOLD_YN = "Not Applicable", QTYPE = "General", QUsername = topic.NickName, QUSERID = usersDic[topic.NickName] }; List <Comment> _comments = new List <Comment>(); using (var textHelper = new TextHelper()) { foreach (var message in topic.Messages) { if (string.IsNullOrEmpty(message.Name) || string.IsNullOrEmpty(message.Text)) { continue; } if (message.MessageId == null) { continue; } if (!usersDic.ContainsKey(message.Name)) { long userid = uc++; usersDic.Add(message.Name, userid); usersIdDic.Add(userid, message.Name); } string cleanText = textHelper.CleanReview(message.TextClean); Comment cm = new Comment() { CommentId = message.MessageId, CID = message.MessageId.ToString(), CBody = message.Text, CBodyClean = cleanText, CUsername = message.Name, CUSERID = usersDic[message.Name], CGOLD = "", CGOLD_YN = "", CSubject = "", ReplayCommentId = message.ReplayId, QuestionId = q.QuestionId }; int[] _persianDate = message.Date.Split('/').Select(x => Convert.ToInt32(x)).ToArray(); if (_persianDate.Length == 3) { PersianCalendar pc = new PersianCalendar(); DateTime dt = new DateTime(_persianDate[0], _persianDate[1], _persianDate[2], 0, 0, 0, pc); cm.CDate = dt; } if (!textHelper.RemoveSingleEmoji(cm.CBodyClean)) { _comments.Add(cm); } } } var _cms = _comments.GroupBy(x => x.CommentId).Select(x => x.First()).ToList(); var _cms1 = _cms.GroupBy(x => x.CBodyClean).Select(x => x.First()).ToList(); comments.AddRange(_cms1); questions.Add(q); //if (comments.Count() > 10000) //{ // rep.AddQuestions(questions); // Thread.Sleep(2 * 1000); // var cms_1 = comments.GroupBy(x => x.CommentId).Select(x => x.First()).ToList(); // rep.AddComments(cms_1); // questions.Clear(); // comments.Clear(); // _comments.Clear(); // _cms.Clear(); // Console.Write("|"); //} } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; string elapsedTime = ts.Milliseconds.ToString(); //Thread.Sleep(500); //Console.Write($"\rRunTime {elapsedTime} "); } } } } if (questions.Count > 1) { rep.AddQuestions(questions); } //Thread.Sleep(2 * 1000); if (comments.Count > 1) { var cms = comments.GroupBy(x => x.CommentId).Select(x => x.First()).ToList(); rep.AddComments(cms); } int aaaaa = 55; }