private void InitializePanel(GenerateWordCloudArgs args) { this.cloudControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.cloudControl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.cloudControl.Font = new Font(args.Font, 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))); this.cloudControl.LayoutType = Gma.CodeCloud.Controls.LayoutType.Spiral; this.cloudControl.Location = new System.Drawing.Point(12, 151); this.cloudControl.MaxFontSize = (int)args.MaxFontSize; this.cloudControl.MinFontSize = (int)args.MinFontSize; this.cloudControl.Name = "cloudControl"; this.cloudControl.Palette = GetColorPalette(args.Palette).ToArray(); this.cloudControl.TabIndex = 3; this.cloudControl.WeightedWords = null; this.cloudControl.BackColor = Color.FromName(args.BackgroundColor); this.cloudControl.Width = (int)args.Width; this.cloudControl.Height = (int)args.Height; }
public GenerateWordCloudResponse GenerateWordCloud(GenerateWordCloudArgs args) { InitializePanel(args); if (Uri.IsWellFormedUriString(args.Text, UriKind.Absolute)) { args.Text = this.GetTextFromUrl(args.Text); } IEnumerable <string> customWordsToExclude = this.GetCustomWordsFromString(args.WordsToExclude); IBlacklist blacklist = ComponentFactory.CreateBlacklist(args.ExcludeCommonWords); IBlacklist customBlacklist = new CommonBlacklist(customWordsToExclude); IEnumerable <string> terms = ComponentFactory.CreateExtractor(args.Text); IWordStemmer stemmer = ComponentFactory.CreateWordStemmer(args.ExcludeCommonWords); IEnumerable <IWord> words = terms .Filter(blacklist) .Filter(customBlacklist) .CountOccurences(); cloudControl.WeightedWords = words .GroupByStem(stemmer) .SortByOccurences() .Cast <IWord>(); string imageUrl = string.Empty; imageUrl = UploadToImgurAndGetUrl(imageUrl); GenerateWordCloudResponse response = new GenerateWordCloudResponse { ImgurUrl = imageUrl }; return(response); }
public HttpResponseMessage Post([FromBody] GenerateWordCloudArgs args) { HttpResponseMessage httpResponse; try { if (args == null) { httpResponse = Request.CreateResponse(HttpStatusCode.BadRequest, "Input arguments are null. Please check your request"); } else { HttpRequest httpRequest = HttpContext.Current.Request; var response = this.wordCloudGenerator.GenerateWordCloud(args); httpResponse = Request.CreateResponse(HttpStatusCode.OK, response); } } catch { httpResponse = Request.CreateResponse(HttpStatusCode.InternalServerError, "Something went wrong. Please check your inputs and retry after sometime"); } return(httpResponse); }