Exemple #1
0
        public FormTweets(Core core, IEnumerable <DbTweet> tweetSet, DbTopic about, int selection, String relatedTo)
        {
            InitializeComponent();

            this.Core      = core;
            this.About     = about;
            this.Selection = selection;
            this.RelatedTo = relatedTo;
            this.TweetSet  = tweetSet;

            ShowTweets();
        }
Exemple #2
0
        public IEnumerable <DbTweet> GetTopicTermIntersectionTweets(DbTopic t, String term)
        {
            try
            {
                IEnumerable <DbTweet> tws = from DbTweet tw in db
                                            where tw.About.Contains(t.Id) && tw.Terms.Contains(term)
                                            select tw;
                return(tws);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine("GetTopicTermIntersection: " + e.Message);
            }

            return(null);
        }
Exemple #3
0
        public Image GetTopicImage(int size, DbTopic t)
        {
            Image im = null;

            if (size == 0)
            {
                if (File.Exists(t.Id + "_0"))
                {
                    im = Image.FromFile(t.Id + "_0");
                }
                if (im == null)
                {
                    im = Image.FromStream(Tweetinvi.User.GetProfileImageStream(Tweetinvi.User.GetUserFromScreenName(t.Alias[1]), Tweetinvi.Core.Enum.ImageSize.mini));
                    im.Save(t.Id + "_0");
                }
                return(im);
            }
            else if (size == 1)
            {
                if (File.Exists(t.Id + "_1"))
                {
                    im = Image.FromFile(t.Id + "_1");
                }
                if (im == null)
                {
                    im = Image.FromStream(Tweetinvi.User.GetProfileImageStream(Tweetinvi.User.GetUserFromScreenName(t.Alias[1]), Tweetinvi.Core.Enum.ImageSize.normal));
                    im.Save(t.Id + "_1");
                }
                return(im);
            }
            else
            {
                if (File.Exists(t.Id + "_2"))
                {
                    im = Image.FromFile(t.Id + "_2");
                }
                if (im == null)
                {
                    im = Image.FromStream(Tweetinvi.User.GetProfileImageStream(Tweetinvi.User.GetUserFromScreenName(t.Alias[1]), Tweetinvi.Core.Enum.ImageSize.bigger));
                    im.Save(t.Id + "_2");
                }
                return(im);
            }
        }
Exemple #4
0
        public AnalysisResults GetTopicTermIntersectionAnalysis(DbTopic t, String term, bool detailed)
        {
            IEnumerable <DbTweet> tws = GetTopicTermIntersectionTweets(t, term);

            if (tws != null)
            {
                if (detailed)
                {
                    return(TA.AnalyzeTweetSet(tws, false));
                }
                else
                {
                    return(TA.AnalyzeTweetSet(tws, true));
                }
            }
            else
            {
                return(null);
            }
        }
Exemple #5
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++;
        }
Exemple #6
0
        public void ListenTo(DbTopic t)
        {
            Action<ITweet> act = (arg) =>
            {
                if (cantTweets >= maxCantTweets)
                {
                    myStream.StopStream();

                    return;
                }

                else Console.Out.Write(t.Id + " ");

                if (arg.Language != Tweetinvi.Core.Enum.Language.Spanish)
                {
                    //Console.Out.WriteLine("!!! No español: " + arg.Text);
                    return;
                }

                IEnumerable<DbTweet> existente = from DbTweet tw in db
                                                 where tw.Id == arg.Id
                                                 select tw;

                // Para modificar un tweet ya almacenado (ej. cuando ya mencionaba a otro tópico) en vez de crear otro distinto.
                DbTweet n;
                if (existente != null && existente.Count() == 0)
                {
                    n = new DbTweet(arg.Id, arg.Text, arg.CreatedBy.UserIdentifier.ScreenName, arg.CreatedAt, DateTime.Now, arg.RetweetCount);
                }
                else
                {
                    n = existente.First();
                }

                if (arg.Coordinates != null)
                {
                    Console.Out.WriteLine("> En: " + arg.Coordinates.Latitude + ", " + arg.Coordinates.Longitude);
                    n.Coord = new Tuple<float, float>((float)arg.Coordinates.Latitude, (float)arg.Coordinates.Longitude);
                }
                else if (arg.Place != null)
                {
                    Console.Out.WriteLine("> En: " + arg.Place.FullName);
                    n.Coord = new Tuple<float, float>((float)arg.Place.BoundingBox.Coordinates[0].Latitude, (float)arg.Place.BoundingBox.Coordinates[0].Longitude);
                    Console.Out.WriteLine("> O sea: " + n.Coord.Item1 +", "+n.Coord.Item2);
                }

                Console.Out.Write(n.PosValue + "/" + n.NegValue + " ");

                // Evito topics duplicados si ya están en la base de datos.
                IEnumerable<DbTopic> res = from DbTopic x in db
                                           where x.Id == t.Id
                                           select x;
                DbTopic dbt;
                if (res==null || res.Count() == 0) dbt = t;
                else dbt = (DbTopic)res.First();

                // Saltear tweet en caso de que mencione una palabra prohibida para un tópico dado (e.g. "alejandro" en "sanz")
                bool ignore = false;
                foreach (String excep in dbt.Except)
                    if (arg.Text.IndexOf(excep, 0, StringComparison.CurrentCultureIgnoreCase) != -1)
                        ignore = true;

                if (ignore)
                {
                    Console.Out.WriteLine("\n\nIgnorando: " + arg.Text + "\n\n");
                }
                else
                {
                    if(!dbt.TweetsAbout.Contains(n.Id))
                        dbt.TweetsAbout.Add(n.Id);

                    n.About.Add(t.Id);

                    db.Store(n);
                    db.Store(dbt);

                    if (existente.Count() > 0)
                        TA.ProcessTweet(n);

                    cantTweets++;
                }
            };

            foreach (String a in t.Alias)
            {
                myStream.AddTrack(a, act);
            }
        }
Exemple #7
0
        public void InitListen()
        {
            cantTweets = 0;

            Console.Out.WriteLine("Tweets test");
            TwitterCredentials.SetCredentials("4460502861-Q1jsfXwbNoQAqPGqZVOF0oQFiOg4mODzgodyzK1", "VPD8QHpv4hBWVt5GHh98HxXrfql0lHzmU5BjxhWM7wkET", "2iNRWcj8m046oF8L70TF7CmI5", "ASLWbyUZboUCBrfKDDKXpA43fhLln5B9vy7TlXb4l6F6YLDkYO");

            myStream = Tweetinvi.Stream.CreateFilteredStream();

            DbTopic cfk = new DbTopic(dbName, "CFK", new List<String>() { "cristina kirchner", "@cfkargentina", "cfk" }, null, Domain_nacion);
            ListenTo(cfk);

            // A presidente / vice
            DbTopic sci = new DbTopic(dbName, "Sci", new List<String>() { "scioli", "@danielscioli", "daniel scioli" }, null, Domain_nacion);
            ListenTo(sci);
            DbTopic mac = new DbTopic(dbName, "Mac", new List<String>() { "macri", "@mauriciomacri", "mauricio macri" }, new List<String>() { "jorge" }, Domain_nacion);
            ListenTo(mac);
            DbTopic snz = new DbTopic(dbName, "Sanz", new List<String>() { "sanz", "@sanzernesto", "ernesto sanz" }, new List<String>() { "alejandro" }, Domain_nacion);
            ListenTo(snz);
            DbTopic car = new DbTopic(dbName, "Carr", new List<String>() { "carrió", "@elisacarrio", "carrio", "lilita", "elisa carrio", "elisa carrió" }, null, Domain_nacion);
            ListenTo(car);
            DbTopic mas = new DbTopic(dbName, "Mas", new List<String>() { "massa", "@sergiomassa", "sergio massa" }, null, Domain_nacion);
            ListenTo(mas);
            DbTopic dls = new DbTopic(dbName, "DlS", new List<String>() { "de la sota", "@delasotaok", "manuel de la sota" }, null, Domain_nacion);
            ListenTo(dls);
            DbTopic stol = new DbTopic(dbName, "Stol", new List<String>() { "stolbizer", "@stolbizer", "margarita stolbizer" }, null, Domain_nacion);
            ListenTo(stol);
            DbTopic alt = new DbTopic(dbName, "Alt", new List<String>() { "altamira", "@altamirajorge", "jorge altamira" }, null, Domain_nacion);
            ListenTo(alt);
            DbTopic dca = new DbTopic(dbName, "dCñ", new List<String>() { "del caño", "@nicolasdelcano", "nicolás del caño", "nicolas del caño" }, null, Domain_nacion);
            ListenTo(dca);

            // A gobernador de Buenos Aires / vice
            DbTopic afz = new DbTopic(dbName, "AFz", new List<String>() { "anibal", "@fernandezanibal", "aníbal", "aníbal fernández", "anibal fernandez" }, null, Domain_provincia);
            ListenTo(afz);
            DbTopic jDz = new DbTopic(dbName, "Mas", new List<String>() { "julian dominguez", "@dominguezjul", "julián domínguez" }, null, Domain_provincia);
            ListenTo(jDz);
            DbTopic vid = new DbTopic(dbName, "Vid", new List<String>() { "maria eugenia vidal", "@mariuvidal", "maría eugenia vidal" }, null, Domain_provincia);
            ListenTo(vid);
            DbTopic chi = new DbTopic(dbName, "Chi", new List<String>() { "christian castillo", "@chipicastillo" }, null, Domain_provincia);
            ListenTo(chi);
            DbTopic pit = new DbTopic(dbName, "Pit", new List<String>() { "pitrola", "@nestorpitrola", "nestor pitrola", }, null, Domain_provincia);
            ListenTo(pit);
            DbTopic lin = new DbTopic(dbName, "Lin", new List<String>() { "jaime linares", "@linaresjaime" }, null, Domain_provincia);
            ListenTo(lin);
            DbTopic sol = new DbTopic(dbName, "Sol", new List<String>() { "felipe solá", "@felipe_sola", "felipe sola", }, null, Domain_provincia);
            ListenTo(sol);
            // Agregar apodos, que presupongan neg?

            myStream.StreamStopped += (sender, args) =>
                {
                    Console.Out.Write("(Stream stopped) ");
                };
        }
Exemple #8
0
        public IEnumerable<DbTweet> GetTweetsInTimeInterval(DateTime start, DateTime end, DbTopic about)
        {
            IEnumerable<DbTweet> toRet = null;

            if (about == null)
            {
                toRet = from DbTweet tw in db
                        where (start.CompareTo(tw.Added) <= 0 && tw.Added.CompareTo(end) < 0)
                        select tw;
            }
            else
            {
                toRet = from DbTweet tw in db
                        where (start.CompareTo(tw.Added) <= 0 && tw.Added.CompareTo(end) < 0 && tw.About.Contains(about.Id))
                        select tw;
            }

            return toRet;
        }
Exemple #9
0
        public IEnumerable<DbTweet> GetTopicTermIntersectionTweets(DbTopic t, String term)
        {
            try
            {
                IEnumerable<DbTweet> tws = from DbTweet tw in db
                                           where tw.About.Contains(t.Id) && tw.Terms.Contains(term)
                                           select tw;
                return tws;
            }
            catch (Exception e)
            {
                Console.Out.WriteLine("GetTopicTermIntersection: " + e.Message);
            }

            return null;
        }
Exemple #10
0
        public AnalysisResults GetTopicTermIntersectionAnalysis(DbTopic t, String term, bool detailed)
        {
            IEnumerable<DbTweet> tws = GetTopicTermIntersectionTweets(t, term);

            if (tws != null)
                if (detailed) return TA.AnalyzeTweetSet(tws, false);
                else return TA.AnalyzeTweetSet(tws, true);
            else
                return null;
        }
Exemple #11
0
        public Image GetTopicImage(int size, DbTopic t)
        {
            Image im = null;

            if (size == 0)
            {
                if(File.Exists(t.Id+"_0"))
                    im = Image.FromFile(t.Id+"_0");
                if (im == null)
                {
                    im = Image.FromStream(Tweetinvi.User.GetProfileImageStream(Tweetinvi.User.GetUserFromScreenName(t.Alias[1]), Tweetinvi.Core.Enum.ImageSize.mini));
                    im.Save(t.Id + "_0");
                }
                return im;
            }
            else if (size == 1)
            {
                if (File.Exists(t.Id + "_1"))
                    im = Image.FromFile(t.Id + "_1");
                if (im == null)
                {
                    im = Image.FromStream(Tweetinvi.User.GetProfileImageStream(Tweetinvi.User.GetUserFromScreenName(t.Alias[1]), Tweetinvi.Core.Enum.ImageSize.normal));
                    im.Save(t.Id + "_1");
                }
                return im;
            }
            else
            {
                if (File.Exists(t.Id + "_2"))
                    im = Image.FromFile(t.Id + "_2");
                if (im == null)
                {
                    im = Image.FromStream(Tweetinvi.User.GetProfileImageStream(Tweetinvi.User.GetUserFromScreenName(t.Alias[1]), Tweetinvi.Core.Enum.ImageSize.bigger));
                    im.Save(t.Id + "_2");
                }
                return im;
            }
        }
        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++;
        }
Exemple #13
0
        public void ListenTo(DbTopic t)
        {
            Action <ITweet> act = (arg) =>
            {
                if (cantTweets >= maxCantTweets)
                {
                    myStream.StopStream();

                    return;
                }

                else
                {
                    Console.Out.Write(t.Id + " ");
                }

                if (arg.Language != Tweetinvi.Core.Enum.Language.Spanish)
                {
                    //Console.Out.WriteLine("!!! No español: " + arg.Text);
                    return;
                }

                IEnumerable <DbTweet> existente = from DbTweet tw in db
                                                  where tw.Id == arg.Id
                                                  select tw;

                // Para modificar un tweet ya almacenado (ej. cuando ya mencionaba a otro tópico) en vez de crear otro distinto.
                DbTweet n;
                if (existente != null && existente.Count() == 0)
                {
                    n = new DbTweet(arg.Id, arg.Text, arg.CreatedBy.UserIdentifier.ScreenName, arg.CreatedAt, DateTime.Now, arg.RetweetCount);
                }
                else
                {
                    n = existente.First();
                }

                if (arg.Coordinates != null)
                {
                    Console.Out.WriteLine("> En: " + arg.Coordinates.Latitude + ", " + arg.Coordinates.Longitude);
                    n.Coord = new Tuple <float, float>((float)arg.Coordinates.Latitude, (float)arg.Coordinates.Longitude);
                }
                else if (arg.Place != null)
                {
                    Console.Out.WriteLine("> En: " + arg.Place.FullName);
                    n.Coord = new Tuple <float, float>((float)arg.Place.BoundingBox.Coordinates[0].Latitude, (float)arg.Place.BoundingBox.Coordinates[0].Longitude);
                    Console.Out.WriteLine("> O sea: " + n.Coord.Item1 + ", " + n.Coord.Item2);
                }

                Console.Out.Write(n.PosValue + "/" + n.NegValue + " ");


                // Evito topics duplicados si ya están en la base de datos.
                IEnumerable <DbTopic> res = from DbTopic x in db
                                            where x.Id == t.Id
                                            select x;
                DbTopic dbt;
                if (res == null || res.Count() == 0)
                {
                    dbt = t;
                }
                else
                {
                    dbt = (DbTopic)res.First();
                }

                // Saltear tweet en caso de que mencione una palabra prohibida para un tópico dado (e.g. "alejandro" en "sanz")
                bool ignore = false;
                foreach (String excep in dbt.Except)
                {
                    if (arg.Text.IndexOf(excep, 0, StringComparison.CurrentCultureIgnoreCase) != -1)
                    {
                        ignore = true;
                    }
                }

                if (ignore)
                {
                    Console.Out.WriteLine("\n\nIgnorando: " + arg.Text + "\n\n");
                }
                else
                {
                    if (!dbt.TweetsAbout.Contains(n.Id))
                    {
                        dbt.TweetsAbout.Add(n.Id);
                    }

                    n.About.Add(t.Id);

                    db.Store(n);
                    db.Store(dbt);

                    if (existente.Count() > 0)
                    {
                        TA.ProcessTweet(n);
                    }

                    cantTweets++;
                }
            };

            foreach (String a in t.Alias)
            {
                myStream.AddTrack(a, act);
            }
        }
Exemple #14
0
        public void InitListen()
        {
            cantTweets = 0;

            Console.Out.WriteLine("Tweets test");
            TwitterCredentials.SetCredentials("4460502861-Q1jsfXwbNoQAqPGqZVOF0oQFiOg4mODzgodyzK1", "VPD8QHpv4hBWVt5GHh98HxXrfql0lHzmU5BjxhWM7wkET", "2iNRWcj8m046oF8L70TF7CmI5", "ASLWbyUZboUCBrfKDDKXpA43fhLln5B9vy7TlXb4l6F6YLDkYO");

            myStream = Tweetinvi.Stream.CreateFilteredStream();

            DbTopic cfk = new DbTopic(dbName, "CFK", new List <String>()
            {
                "cristina kirchner", "@cfkargentina", "cfk"
            }, null, Domain_nacion);

            ListenTo(cfk);

            // A presidente / vice
            DbTopic sci = new DbTopic(dbName, "Sci", new List <String>()
            {
                "scioli", "@danielscioli", "daniel scioli"
            }, null, Domain_nacion);

            ListenTo(sci);
            DbTopic mac = new DbTopic(dbName, "Mac", new List <String>()
            {
                "macri", "@mauriciomacri", "mauricio macri"
            }, new List <String>()
            {
                "jorge"
            }, Domain_nacion);

            ListenTo(mac);
            DbTopic snz = new DbTopic(dbName, "Sanz", new List <String>()
            {
                "sanz", "@sanzernesto", "ernesto sanz"
            }, new List <String>()
            {
                "alejandro"
            }, Domain_nacion);

            ListenTo(snz);
            DbTopic car = new DbTopic(dbName, "Carr", new List <String>()
            {
                "carrió", "@elisacarrio", "carrio", "lilita", "elisa carrio", "elisa carrió"
            }, null, Domain_nacion);

            ListenTo(car);
            DbTopic mas = new DbTopic(dbName, "Mas", new List <String>()
            {
                "massa", "@sergiomassa", "sergio massa"
            }, null, Domain_nacion);

            ListenTo(mas);
            DbTopic dls = new DbTopic(dbName, "DlS", new List <String>()
            {
                "de la sota", "@delasotaok", "manuel de la sota"
            }, null, Domain_nacion);

            ListenTo(dls);
            DbTopic stol = new DbTopic(dbName, "Stol", new List <String>()
            {
                "stolbizer", "@stolbizer", "margarita stolbizer"
            }, null, Domain_nacion);

            ListenTo(stol);
            DbTopic alt = new DbTopic(dbName, "Alt", new List <String>()
            {
                "altamira", "@altamirajorge", "jorge altamira"
            }, null, Domain_nacion);

            ListenTo(alt);
            DbTopic dca = new DbTopic(dbName, "dCñ", new List <String>()
            {
                "del caño", "@nicolasdelcano", "nicolás del caño", "nicolas del caño"
            }, null, Domain_nacion);

            ListenTo(dca);


            // A gobernador de Buenos Aires / vice
            DbTopic afz = new DbTopic(dbName, "AFz", new List <String>()
            {
                "anibal", "@fernandezanibal", "aníbal", "aníbal fernández", "anibal fernandez"
            }, null, Domain_provincia);

            ListenTo(afz);
            DbTopic jDz = new DbTopic(dbName, "Mas", new List <String>()
            {
                "julian dominguez", "@dominguezjul", "julián domínguez"
            }, null, Domain_provincia);

            ListenTo(jDz);
            DbTopic vid = new DbTopic(dbName, "Vid", new List <String>()
            {
                "maria eugenia vidal", "@mariuvidal", "maría eugenia vidal"
            }, null, Domain_provincia);

            ListenTo(vid);
            DbTopic chi = new DbTopic(dbName, "Chi", new List <String>()
            {
                "christian castillo", "@chipicastillo"
            }, null, Domain_provincia);

            ListenTo(chi);
            DbTopic pit = new DbTopic(dbName, "Pit", new List <String>()
            {
                "pitrola", "@nestorpitrola", "nestor pitrola",
            }, null, Domain_provincia);

            ListenTo(pit);
            DbTopic lin = new DbTopic(dbName, "Lin", new List <String>()
            {
                "jaime linares", "@linaresjaime"
            }, null, Domain_provincia);

            ListenTo(lin);
            DbTopic sol = new DbTopic(dbName, "Sol", new List <String>()
            {
                "felipe solá", "@felipe_sola", "felipe sola",
            }, null, Domain_provincia);

            ListenTo(sol);
            // Agregar apodos, que presupongan neg?


            myStream.StreamStopped += (sender, args) =>
            {
                Console.Out.Write("(Stream stopped) ");
            };
        }
Exemple #15
0
        public IEnumerable <DbTweet> GetTweetsInTimeInterval(DateTime start, DateTime end, DbTopic about)
        {
            IEnumerable <DbTweet> toRet = null;

            if (about == null)
            {
                toRet = from DbTweet tw in db
                        where (start.CompareTo(tw.Added) <= 0 && tw.Added.CompareTo(end) < 0)
                        select tw;
            }
            else
            {
                toRet = from DbTweet tw in db
                        where (start.CompareTo(tw.Added) <= 0 && tw.Added.CompareTo(end) < 0 && tw.About.Contains(about.Id))
                        select tw;
            }

            return(toRet);
        }