コード例 #1
0
        private void CloudControlClick(object sender, EventArgs e)
        {
            LayoutItem itemUnderMouse;
            Point      mousePositionRelativeToControl = cloud.PointToClient(new Point(MousePosition.X, MousePosition.Y));

            if (!cloud.TryGetItemAtLocation(mousePositionRelativeToControl, out itemUnderMouse))
            {
                return;
            }

            String w = itemUnderMouse.Word.Text;
            IEnumerable <DbTweet> tweetSet = core.GetTopicTermIntersectionTweets(ActiveTopic, w);

            FormTweets tweetsWindow = new FormTweets(core, tweetSet, ActiveTopic, FormTweets.SelectionWordRelated, w);

            tweetsWindow.Show();
        }
コード例 #2
0
        private void UpdateTable()
        {
            if (sortByCol == 2)
            {
                resList.Sort((pair1, pair2) => { return(-pair1.Value.Popularity.CompareTo(pair2.Value.Popularity)); });                // Pop desc
            }
            if (sortByCol == 3)
            {
                resList.Sort((pair1, pair2) => { return(-pair1.Value.PosVal.CompareTo(pair2.Value.PosVal)); });                // Pop desc
            }
            if (sortByCol == 4)
            {
                resList.Sort((pair1, pair2) => { return(-pair1.Value.NegVal.CompareTo(pair2.Value.NegVal)); });                // Pop desc
            }
            if (sortByCol == 5)
            {
                resList.Sort((pair1, pair2) => { return(-pair1.Value.Ambiguity.CompareTo(pair2.Value.Ambiguity)); });                // Pop desc
            }
            tableLayoutPanel1.Controls.Clear();
            tableLayoutPanel1.RowCount = 0;

            tableLayoutPanel1.Controls.Add(new Label()
            {
                Text = "Nombre", Width = 200
            }, 1, 0);

            Button bPop = new Button()
            {
                Text = "Pop.", Width = 200
            };

            bPop.Click += (sender, args) =>
            {
                sortByCol = 2;
                UpdateTable();
                UpdateChart();
            };
            tableLayoutPanel1.Controls.Add(bPop, 2, 0);

            Button bPos = new Button()
            {
                Text = "+", Width = 200
            };

            bPos.Click += (sender, args) =>
            {
                sortByCol = 3;
                UpdateTable();
                UpdateChart();
            };
            tableLayoutPanel1.Controls.Add(bPos, 3, 0);

            Button bNeg = new Button()
            {
                Text = "-", Width = 200
            };

            bNeg.Click += (sender, args) =>
            {
                sortByCol = 4;
                UpdateTable();
                UpdateChart();
            };
            tableLayoutPanel1.Controls.Add(bNeg, 4, 0);

            Button bAmb = new Button()
            {
                Text = "Ambig.", Width = 200
            };

            bAmb.Click += (sender, args) =>
            {
                sortByCol = 5;
                UpdateTable();
                UpdateChart();
            };
            tableLayoutPanel1.Controls.Add(bAmb, 5, 0);

            int row = 1;

            foreach (var item in resList)
            {
                PictureBox bDominio = new PictureBox();
                bDominio.Image  = Image.FromFile("Dom" + item.Key.Domain + ".png");
                bDominio.Size   = new Size(20, 20);
                bDominio.Anchor = AnchorStyles.None;
                tableLayoutPanel1.Controls.Add(bDominio, 0, row);



                Button bName = new Button()
                {
                    Text = item.Key.Alias[1], Width = 200
                };
                bName.Click += (sender, args) => {
                    buildingCloud = true;
                    ActiveTopic   = item.Key;
                    cloud.Enabled = false;
                    cloudWorker.Dispose();
                    cloudWorker         = new BackgroundWorker();
                    cloudWorker.DoWork += (e, a) =>
                    {
                        try
                        {
                            List <Gma.CodeCloud.Controls.TextAnalyses.Processing.IWord> iwords = new List <Gma.CodeCloud.Controls.TextAnalyses.Processing.IWord>();

                            int cantCloudWords = 0;

                            // Tomo las palabras relevantes de un tópico porque al armar la tabla sólo había pedido un análisis simple.
                            List <KeyValuePair <string, double> > relevantList = core.GetTopicTermIntersectionAnalysis(item.Key, "", true).relevantList;
                            foreach (var i in relevantList)
                            {
                                if (cantCloudWords > 30)
                                {
                                    break;
                                }

                                // Si la palabra es el topic de la nube, la saltea.
                                bool cont = false;
                                foreach (String al in item.Key.Alias)
                                {
                                    if (al.Contains(i.Key))
                                    {
                                        cont = true;
                                    }
                                }
                                if (cont)
                                {
                                    continue;
                                }

                                AnalysisResults intersection = core.GetTopicTermIntersectionAnalysis(item.Key, i.Key, false);
                                int             neg;
                                if (intersection == null)
                                {
                                    neg = 0;
                                }
                                else
                                {
                                    neg = intersection.NegVal;
                                }
                                int pos;
                                if (intersection == null)
                                {
                                    pos = 0;
                                }
                                else
                                {
                                    pos = intersection.PosVal;
                                }

                                double rr = (double)(neg - pos) / (neg + pos + 1); int r = (int)(rr * 100) + 127;
                                double gg = (double)(pos - neg) / (neg + pos + 1); int g = (int)(gg * 100) + 127;
                                int    b;
                                if (neg == 0 && pos == 0)
                                {
                                    b = 150;
                                }
                                else
                                {
                                    b = 50;
                                }

                                Color c = Color.FromArgb(255, r, g, b);

                                iwords.Add(new Gma.CodeCloud.Controls.TextAnalyses.Processing.Word(i.Key, (int)i.Value, c));
                                cantCloudWords++;
                            }
                            if (iwords.Count > 0)
                            {
                                this.cloud.WeightedWords = iwords;
                            }
                        }
                        catch (Exception ee)
                        {
                            Console.Out.WriteLine("No se pudo crear nube de palabras. Probablemente no sean suficientes.");
                        }

                        pictureBox1.Image = core.GetTopicImage(2, item.Key);
                    };
                    cloudWorker.RunWorkerCompleted += (e, a) => {
                        cloud.Update();
                        cloud.Enabled = true;
                        buildingCloud = false;
                    };
                    cloudWorker.RunWorkerAsync();
                };
                tableLayoutPanel1.Controls.Add(bName, 1, row);

                Button bTopicPop = new Button()
                {
                    Text = "" + item.Value.Popularity
                };
                bTopicPop.Click += (a, e) =>
                {
                    IEnumerable <DbTweet> tweetSet = core.GetTopicTermIntersectionTweets(item.Key, "");   // Funciona intersección con nada

                    FormTweets tweetsWindow = new FormTweets(core, tweetSet, item.Key, FormTweets.SelectionFav, null);
                    tweetsWindow.Show();
                };
                tableLayoutPanel1.Controls.Add(bTopicPop, 2, row);

                Button bTopicPos = new Button()
                {
                    Text = "" + item.Value.PosVal
                };
                bTopicPos.Click += (a, e) =>
                {
                    IEnumerable <DbTweet> tweetSet = core.GetTopicTermIntersectionTweets(item.Key, "");

                    FormTweets tweetsWindow = new FormTweets(core, tweetSet, item.Key, FormTweets.SelectionPos, null);
                    tweetsWindow.Show();
                };
                tableLayoutPanel1.Controls.Add(bTopicPos, 3, row);

                Button bTopicNeg = new Button()
                {
                    Text = "" + item.Value.NegVal
                };
                bTopicNeg.Click += (a, e) =>
                {
                    IEnumerable <DbTweet> tweetSet = core.GetTopicTermIntersectionTweets(item.Key, "");

                    FormTweets tweetsWindow = new FormTweets(core, tweetSet, item.Key, FormTweets.SelectionNeg, null);
                    tweetsWindow.Show();
                };
                tableLayoutPanel1.Controls.Add(bTopicNeg, 4, row);

                Button bTopicAmb = new Button()
                {
                    Text = "" + (int)(item.Value.Ambiguity * 100) + "%"
                };
                bTopicAmb.Click += (a, e) =>
                {
                    IEnumerable <DbTweet> tweetSet = core.GetTopicTermIntersectionTweets(item.Key, "");

                    FormTweets tweetsWindow = new FormTweets(core, tweetSet, item.Key, FormTweets.SelectionAmb, null);
                    tweetsWindow.Show();
                };
                tableLayoutPanel1.Controls.Add(bTopicAmb, 5, row);

                row++;
            }

            tableLayoutPanel1.AutoSize = true;
            tableLayoutPanel1.Update();

            //graphTime++;
        }