private string GetExternalPage(Post post) { WebClient client = new WebClient(); string htmlCode = client.DownloadString(post.Url); return htmlCode; }
private bool IsLinkOrImage(Post post) { if(post.IsSelf) return false; return true; }
internal static string ToJson(Post post) { return JsonConvert.SerializeObject(post, Formatting.Indented); }
/// <summary> /// /// </summary> /// <param name="session"></param> /// <param name="post"></param> /// <see cref="https://github.com/reddit/reddit/wiki/API"/> public static void Submit(Session session, Post post, PostKind kind) { if (string.IsNullOrEmpty((kind == PostKind.Link ? post.Url : post.SelfText))) throw new Exception("No link or self text added to the new post"); if (string.IsNullOrEmpty(post.SubReddit)) throw new Exception("No subreddit set"); if (string.IsNullOrEmpty(post.Title)) throw new Exception("No title provided"); var request = new Request { Url = "http://www.reddit.com/api/submit", Method = "POST", Cookie = session.Cookie, Content = "uh=" + session.ModHash + "&kind=" + (kind == PostKind.Link ? "link" : "self") + "&url=" + (kind == PostKind.Link ? post.Url : post.SelfText) + "&sr=" + post.SubReddit + "&title=" + post.Title + "&r=" + post.SubReddit + "&renderstyle=html" }; var json = string.Empty; if (request.Execute(out json) != System.Net.HttpStatusCode.OK) throw new Exception(json); var o = JObject.Parse(json); // Capcha // o["jquery"][10][3].ToString() // Error Message // o["jquery"][12][3].ToString() }
private void TestEmgu(Post post) { int K = 10; //int trainSampleCount = 100; int trainSampleCount = this.vectorTable[0].Length - 1; int trainSampleColumns = this.vectorTable.Length - 2; //subtract two columns for the post id and IsImage int scalingRatio = 10; #region Generate the traning data and classes Matrix<float> trainData = new Matrix<float>(trainSampleColumns, trainSampleCount); Matrix<float> trainClasses = new Matrix<float>(trainSampleColumns, 1); Image<Bgr, Byte> img = new Image<Bgr, byte>(trainSampleCount, trainSampleCount); Matrix<float> sample = new Matrix<float>(1, trainSampleCount); for (int y = 1; y < this.vectorTable[0].Length - 1; y++) { for (int x = 2; x < this.vectorTable.Length - 1; x++) { trainData.Data.SetValue(Int32.Parse(this.vectorTable[x][y]) * scalingRatio, x - 2, y - 1); } } Matrix<float> trainData1 = trainData.GetRows(0, trainSampleColumns >> 1, 1); //trainData1.SetRandNormal(new MCvScalar(200), new MCvScalar(50)); Matrix<float> trainData2 = trainData.GetRows(trainSampleColumns >> 1, trainSampleColumns, 1); //trainData2.SetRandNormal(new MCvScalar(300), new MCvScalar(50)); Matrix<float> trainClasses1 = trainClasses.GetRows(0, trainSampleCount >> 1, 1); trainClasses1.SetValue(1); Matrix<float> trainClasses2 = trainClasses.GetRows(trainSampleCount >> 1, trainSampleCount, 1); trainClasses2.SetValue(2); #endregion Matrix<float> results, neighborResponses; results = new Matrix<float>(sample.Rows, 1); neighborResponses = new Matrix<float>(sample.Rows, K); //dist = new Matrix<float>(sample.Rows, K); KNearest knn = new KNearest(trainData, trainClasses, null, false, K); for (int i = 0; i < img.Height; i++) { for (int j = 0; j < img.Width; j++) { sample.Data[0, 0] = j; sample.Data[0, 1] = i; //Matrix<float> nearestNeighbors = new Matrix<float>(K* sample.Rows, sample.Cols); // estimates the response and get the neighbors' labels float response = knn.FindNearest(sample, K, results, null, neighborResponses, null); int accuracy = 0; // compute the number of neighbors representing the majority for (int k = 0; k < K; k++) { if (neighborResponses.Data[0, k] == response) accuracy++; } // highlight the pixel depending on the accuracy (or confidence) img[i, j] = response == 1 ? (accuracy > 5 ? new Bgr(90, 0, 0) : new Bgr(90, 60, 0)) : (accuracy > 5 ? new Bgr(0, 90, 0) : new Bgr(60, 90, 0)); } } // display the original training samples for (int i = 0; i < (trainSampleCount >> 1); i++) { PointF p1 = new PointF(trainData1[i, 0], trainData1[i, 1]); img.Draw(new CircleF(p1, 2.0f), new Bgr(255, 100, 100), -1); PointF p2 = new PointF(trainData2[i, 0], trainData2[i, 1]); img.Draw(new CircleF(p2, 2.0f), new Bgr(100, 255, 100), -1); } double poolSize = 2, threshold = 0.5, du; du = Utilities.PrecisionUsingCosineSimilarity(WordCountTable, post, poolSize, threshold); PointF newpoint = new PointF((float)du, (float)du); img.Draw(new CircleF(newpoint, 2.0f), new Bgr(255, 0, 0), -1); //Emgu.CV.UI.ImageViewer.Show(img); //Emgu.CV.UI.ImageViewer imgviewer = new Emgu.CV.UI.ImageViewer(img); //imgviewer.Show(); this.imageBox1.DisplayedImage = img; //this.VisImg = new Emgu.CV.UI.ImageViewer(img); }
private void CompareNewPost(Post post) { List<Post> postList = new List<Post>(); postList.Add(post); string[][] wordCountTable = Utilities.GenerateCountVectorTable(postList); }