public static string GetFeatureVector(ContentCrawlResult contentInfo, UserInfo userInfo) { StringBuilder sb = new StringBuilder(); sb.Append("1:").Append(contentInfo.Sentiment).Append(" "); //sentiment sb.Append("2:").Append(contentInfo.HasImg ? "1" : "0").Append(" "); //HasImg ? "1" : "0" sb.Append("3:").Append(contentInfo.HasUrl ? "1" : "0").Append(" "); //HasUrl ? "1" : "0" sb.Append("4:").Append(userInfo.FanNum).Append(" "); //fans sb.Append("5:").Append(userInfo.WeiboNum).Append(" "); //weibo sb.Append("6:").Append(userInfo.Credit).Append(" "); //credit sb.Append("7:").Append(GetProvinceId(userInfo.Location)).Append(" "); //userLoc sb.Append("8:").Append(userInfo.Level).Append(" "); //level sb.Append("9:").Append(userInfo.IsVerified ? "1" : "0").Append(" "); //verified sb.Append("10:").Append(contentInfo.CommentEval).Append(" "); //comval return sb.ToString(); }
public static void GetServiceInfo(string url, out ContentCrawlResult contentInfo, out UserInfo userInfo) { string[] temp = url.Split('/'); ContentCrawlServiceClient contentClient = new ContentCrawlServiceClient(); UserInfoServiceClient infoClient = new UserInfoServiceClient(); var contentTask = Task.Factory.StartNew<ContentCrawlResult>(() => { return contentClient.GetContentCrawlResult(temp[3] + '|' + temp[4]); }); var userTask = Task.Factory.StartNew<UserInfo>(() => { return infoClient.GetUserInfo(temp[3]); }); contentInfo = contentTask.Result;//contentClient.GetContentCrawlResult(temp[3] + '|' + temp[4]); userInfo = userTask.Result; //infoClient.GetUserInfo(temp[3]); }
public void ProcessRequest(HttpContext context) { var url = context.Request["url"]; context.Response.ContentType = "text/plain"; UserInfo uinfo = new UserInfo(); ContentCrawlResult cinfo = new ContentCrawlResult(); ServiceHelper.GetServiceInfo(url, out cinfo, out uinfo); var vec = ServiceHelper.GetFeatureVector(cinfo, uinfo); SVM.InputData(vec); var result = SVM.Predict(); //var result = 1; var data = String.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}|{13}|{14}|{15}|{16}|{17}", uinfo.Uid, uinfo.Uid, uinfo.Sex, uinfo.Level, uinfo.IsVerified, uinfo.Credit, uinfo.FollowNum, uinfo.FanNum, uinfo.WeiboNum, uinfo.NickName, uinfo.Location, uinfo.Intro, cinfo.Content, cinfo.CommentEval, cinfo.HasImg, cinfo.Sentiment, cinfo.HasUrl, result == 1 ? "Rumor!" : "Truth!"); context.Response.Write(data); }
public ContentCrawlResult GetContentCrawlResult(string _data) { var data = _data.Split('|'); string weiboUrl = "http://weibo.com/" + data[0] + "/" + data[1]; WeiBoManager.commentList.Clear(); var contentThread = new Thread(() => { contentCrawlerList[0].Run(weiboUrl); }); contentThread.Start(); Thread[] commentThreadList = new Thread[commentCrawlerList.Count]; int i = 0; foreach (WeiBoCommentCrawler c in commentCrawlerList) { Thread t = new Thread(c.Run); commentThreadList[i++] = t; t.Start(); } contentThread.Join(); foreach (Thread t in commentThreadList) t.Join(); ContentCrawlResult result = new ContentCrawlResult(); result.Sentiment = WeiBoManager.CalcSent(); result.CommentEval = WeiBoManager.CalcComment(); result.HasImg = WeiBoManager.HasImg; result.HasUrl = WeiBoManager.HasUrl; result.Content = WeiBoManager.GetContent(); Console.WriteLine("Finished!"); return result; }