示例#1
0
 // Construye un bloque a partir de los últimos 5 minutos
 public DbTimeBlock(DateTime start, TimeSpan length, AnalysisResults globalAR, Dictionary<DbTopic, AnalysisResults> topicAR)
 {
     this.Start = start;
     this.Length = length;
     this.GlobalAR = globalAR;
     this.TopicAR = topicAR;
     this.Used = false;
 }
示例#2
0
        // Construye bloques medianos o grandes, basados en bloques chicos o medianos respectivamente.
        public void BuildTimeBlockFromBlocks(TimeSpan length)
        {
            TimeSpan childBlocksLength = TimeSpan.FromSeconds(0);
            if (length == TS_medium)
                childBlocksLength = TS_short;
            else if (length == TS_long)
                childBlocksLength = TS_medium;

            IEnumerable<DbTimeBlock> ch = from DbTimeBlock t in db
                                         where t.Length == childBlocksLength && t.Used == false
                                         orderby t.Start descending
                                         select t;
            int cant = ch.Count();
            AnalysisResults GlobalAR = new AnalysisResults();
            Dictionary<DbTopic, AnalysisResults> TopicAR = new Dictionary<DbTopic, AnalysisResults>();
            foreach (DbTopic t in db.Query<DbTopic>())
                TopicAR.Add(t, new AnalysisResults());

            if (cant > this.TimeBlockConsolidationThreshold)
            {
                foreach (DbTimeBlock cht in ch)
                {
                    GlobalAR.Popularity += cht.GlobalAR.Popularity;
                    GlobalAR.PosVal += cht.GlobalAR.PosVal;
                    GlobalAR.NegVal += cht.GlobalAR.NegVal;
                    GlobalAR.Ambiguity += cht.GlobalAR.Ambiguity;

                    // Para poder comparar las palabras importantes de un subbloque con otro, ya que cada uno fue calculado con tfidf distintos.
                    double normalizationFactor = 0;
                    foreach(KeyValuePair<string,double> kv in cht.GlobalAR.relevantList)
                        normalizationFactor += kv.Value;

                    foreach(KeyValuePair<string,double> kv in cht.GlobalAR.relevantList)
                        if(GlobalAR.RelevantTerms.ContainsKey(kv.Key))
                            GlobalAR.RelevantTerms[kv.Key] += kv.Value/normalizationFactor;
                        else
                            GlobalAR.RelevantTerms[kv.Key] = kv.Value/normalizationFactor;

                    // ídem a lo anterior, para cada topic
                    foreach (KeyValuePair<DbTopic, AnalysisResults> tar in cht.TopicAR)
                    {
                        TopicAR[tar.Key].Popularity += tar.Value.Popularity;
                        TopicAR[tar.Key].PosVal += tar.Value.PosVal;
                        TopicAR[tar.Key].NegVal += tar.Value.NegVal;
                        TopicAR[tar.Key].Ambiguity += tar.Value.Ambiguity;

                        normalizationFactor = 0;
                        foreach(KeyValuePair<string,double> kv in cht.TopicAR[tar.Key].relevantList)
                            normalizationFactor += kv.Value;

                        foreach(KeyValuePair<string,double> kv in cht.TopicAR[tar.Key].relevantList)
                            if(TopicAR[tar.Key].RelevantTerms.ContainsKey(kv.Key))
                                TopicAR[tar.Key].RelevantTerms[kv.Key] += kv.Value/normalizationFactor;
                            else
                                TopicAR[tar.Key].RelevantTerms[kv.Key] = kv.Value / normalizationFactor;
                    }

                    cht.Used = true;
                    db.Store(cht);
                }

                GlobalAR.Ambiguity /= cant;
                GlobalAR.DictionaryToList();

                foreach (DbTopic t in db.Query<DbTopic>())
                {
                    TopicAR[t].Ambiguity /= cant;
                    TopicAR[t].DictionaryToList();
                }

                DbTimeBlock toAdd = new DbTimeBlock(DateTime.Now.Add(-length), length, GlobalAR, TopicAR);
                db.Store(toAdd);

                Console.Out.WriteLine("\n\n[ CONSTRUIDO TIME BLOCK (desde otros bloques), tamaño: " + length +"+ ]\n");

            }
        }
示例#3
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++;
        }
示例#4
0
        // Construye bloques medianos o grandes, basados en bloques chicos o medianos respectivamente.
        public void BuildTimeBlockFromBlocks(TimeSpan length)
        {
            TimeSpan childBlocksLength = TimeSpan.FromSeconds(0);

            if (length == TS_medium)
            {
                childBlocksLength = TS_short;
            }
            else if (length == TS_long)
            {
                childBlocksLength = TS_medium;
            }

            IEnumerable <DbTimeBlock> ch = from DbTimeBlock t in db
                                           where t.Length == childBlocksLength && t.Used == false
                                           orderby t.Start descending
                                           select t;
            int             cant     = ch.Count();
            AnalysisResults GlobalAR = new AnalysisResults();
            Dictionary <DbTopic, AnalysisResults> TopicAR = new Dictionary <DbTopic, AnalysisResults>();

            foreach (DbTopic t in db.Query <DbTopic>())
            {
                TopicAR.Add(t, new AnalysisResults());
            }

            if (cant > this.TimeBlockConsolidationThreshold)
            {
                foreach (DbTimeBlock cht in ch)
                {
                    GlobalAR.Popularity += cht.GlobalAR.Popularity;
                    GlobalAR.PosVal     += cht.GlobalAR.PosVal;
                    GlobalAR.NegVal     += cht.GlobalAR.NegVal;
                    GlobalAR.Ambiguity  += cht.GlobalAR.Ambiguity;

                    // Para poder comparar las palabras importantes de un subbloque con otro, ya que cada uno fue calculado con tfidf distintos.
                    double normalizationFactor = 0;
                    foreach (KeyValuePair <string, double> kv in cht.GlobalAR.relevantList)
                    {
                        normalizationFactor += kv.Value;
                    }

                    foreach (KeyValuePair <string, double> kv in cht.GlobalAR.relevantList)
                    {
                        if (GlobalAR.RelevantTerms.ContainsKey(kv.Key))
                        {
                            GlobalAR.RelevantTerms[kv.Key] += kv.Value / normalizationFactor;
                        }
                        else
                        {
                            GlobalAR.RelevantTerms[kv.Key] = kv.Value / normalizationFactor;
                        }
                    }

                    // ídem a lo anterior, para cada topic
                    foreach (KeyValuePair <DbTopic, AnalysisResults> tar in cht.TopicAR)
                    {
                        TopicAR[tar.Key].Popularity += tar.Value.Popularity;
                        TopicAR[tar.Key].PosVal     += tar.Value.PosVal;
                        TopicAR[tar.Key].NegVal     += tar.Value.NegVal;
                        TopicAR[tar.Key].Ambiguity  += tar.Value.Ambiguity;

                        normalizationFactor = 0;
                        foreach (KeyValuePair <string, double> kv in cht.TopicAR[tar.Key].relevantList)
                        {
                            normalizationFactor += kv.Value;
                        }

                        foreach (KeyValuePair <string, double> kv in cht.TopicAR[tar.Key].relevantList)
                        {
                            if (TopicAR[tar.Key].RelevantTerms.ContainsKey(kv.Key))
                            {
                                TopicAR[tar.Key].RelevantTerms[kv.Key] += kv.Value / normalizationFactor;
                            }
                            else
                            {
                                TopicAR[tar.Key].RelevantTerms[kv.Key] = kv.Value / normalizationFactor;
                            }
                        }
                    }

                    cht.Used = true;
                    db.Store(cht);
                }

                GlobalAR.Ambiguity /= cant;
                GlobalAR.DictionaryToList();

                foreach (DbTopic t in db.Query <DbTopic>())
                {
                    TopicAR[t].Ambiguity /= cant;
                    TopicAR[t].DictionaryToList();
                }

                DbTimeBlock toAdd = new DbTimeBlock(DateTime.Now.Add(-length), length, GlobalAR, TopicAR);
                db.Store(toAdd);

                Console.Out.WriteLine("\n\n[ CONSTRUIDO TIME BLOCK (desde otros bloques), tamaño: " + length + "+ ]\n");
            }
        }