public ActionResult Index() { var cm = db.Comments.ToList(); try { foreach (var item in cm) { try { var sen = db.Sentenses.Where(e => e.CommentId == item.Id).ToList(); if (sen.Count <= 0) { string[] str = item.Comment1.Split('.', '!', '?'); foreach (var s in str) { try { if (s.Trim() != "" && s.Length > 2) { string ids = Public.GetID(); while (db.Sentenses.Where(e => e.Id == ids).Count() > 0) { ids = Public.GetID(); } Sentens se = new Sentens(); se.Id = ids; se.ContentReview = s; se.CommentId = item.Id; db.Sentenses.Add(se); db.SaveChanges(); } } catch { } } } } catch { } } } catch { } return(View()); }
private void SplitComment(string idgc) { var sen2 = db.Sentenses.Where(e => e.Comment.GroupCommentId == idgc).ToList(); if (sen2.Count <= 0) { var cm = db.Comments.Where(e => e.GroupCommentId == idgc).ToList(); //try //{ if (cm.Count > 1) { foreach (var item in cm) { //Tiền xử lý //string[] str = item.Comment1.Split('...'); //try //{ var sen = db.Sentenses.Where(e => e.CommentId == item.Id).ToList(); if (sen.Count <= 0) { // string strtest = "Not too heavy, definately not watery. Not very good at describing it other than it's good."; string[] str = item.Comment1.Split('.', '!', '?'); //string[] str = item.Split('.', '!', '?'); for (int i = 0; i < str.Length; i++) { //try //{ if (str[i].Trim() != "" && str[i].Length > 2) { string str2 = str[i]; int j = i + 1; if (j < str.Length) { while (str[j].Length <= 0) { j++; if (j >= str.Length) { break; } } } //char s = str[j].Trim().ToCharArray()[0]; if (j < str.Length) { try { if (!Char.IsUpper(str[j].Trim().ToCharArray()[0])) { str2 += " " + str[j]; i = j; } } catch { } } string ids = Public.GetID(); while (db.Sentenses.Where(e => e.Id == ids).Count() > 0) { ids = Public.GetID(); } Sentens se = new Sentens(); se.Id = ids; se.ContentReview = str2.Trim(); se.CommentId = item.Id; db.Sentenses.Add(se); db.SaveChanges(); } //} //catch { } } } //} //catch { } } } //} //catch { } } }