Exemplo n.º 1
0
        public void SetTweets(StreamReader Tweets)
        {
            Tweets.DiscardBufferedData();
            Tweets.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
            string line;

            while ((line = Tweets.ReadLine()) != null)
            {
                string[] splitstring = line.Split();
                int      ID          = Convert.ToInt32(splitstring.First());
                //If this is true it is a retweet
                if (splitstring[2].Length > 1 && splitstring[2].Substring(0, 2) == "RT")
                {
                    //if this is true there does not exist a retweet from that user
                    if (ReTweet.Where(x => x.ID == ID).Count() == 0)
                    {
                        ReTweet.Add(new ReTweets(ID, 1));
                    }
                    //there does exist a retweet from user
                    else
                    {
                        ReTweets u = ReTweet.Where(x => x.ID == ID).FirstOrDefault();
                        u.ReTweet++;
                    }
                }
                //string post = string.Join(" ", splitstring.Reverse().Take(splitstring.Count() - 2).Reverse().ToArray());
                //if(post.Contains(@"@"))
                //{
                //    //if this is true there does not exist a retweet from that user
                //    if (Post.Where(x => x.ID == ID).Count() == 0)
                //    {
                //        Post.Add(new Post(ID, 1));
                //    }
                //    //there does exist a retweet from user
                //    else
                //    {
                //        Post p = Post.Where(x => x.ID == ID).FirstOrDefault();
                //        p.post++;
                //    }
                //}
            }
        }
Exemplo n.º 2
0
 public TrainingData(ScreenNameLength screenNameLen, DescriptionLength desLength, LongevityDays days, LongevityHours hours, LongevityMinSec minutes, LongevityMinSec seconds,
                     Follow following, Follow followers, Ratio ratio1, Tweets totalTweets, TweetsPerDay tweetsPDay, AverageLinks aveLinks, AverageLinks aveUniqueLinks, AverageUsername aveUsername,
                     AverageUsername aveUniqueUsername, ChangeRate changeRt, ReTweets reTweet, /*Tags tag,*/ int label)
 {
     screenNameLength  = screenNameLen;
     descriptionLength = desLength;
     Days                  = days;
     Hours                 = hours;
     Minutes               = minutes;
     Seconds               = seconds;
     Following             = following;
     Followers             = followers;
     ratio                 = ratio1;
     TotalTweets           = totalTweets;
     tweetsPerDay          = tweetsPDay;
     averageLinks          = aveLinks;
     AverageUniqueLinks    = aveUniqueLinks;
     averageUsername       = aveUsername;
     AverageUniqueUsername = aveUniqueUsername;
     changeRate            = changeRt;
     ReTweet               = reTweet;
     //Tag = tag;
     Label = label;
 }
Exemplo n.º 3
0
        public void SetValidateData(StreamReader train, StreamReader test, StreamReader train_ID, StreamReader test_ID, Random rSeed)
        {
            train.DiscardBufferedData();
            train.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
            train_ID.DiscardBufferedData();
            train_ID.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
            string entry;
            string ids;

            while ((entry = train.ReadLine()) != null && (ids = train_ID.ReadLine()) != null)
            {
                int      Sign;
                double[] Vector      = new double[17];
                string[] splitstring = entry.Split();
                if (splitstring.First().First() == '1')
                {
                    Sign = 1;
                }
                else
                {
                    Sign = 0;
                }
                foreach (var item in splitstring)
                {
                    if (item.Contains(":"))
                    {
                        string[] s = item.Split(':');
                        Vector[Convert.ToInt32(s[0]) - 1] = Convert.ToDouble(s[1]);
                    }
                }
                ReTweets v = ReTweet.Where(t => t.ID == Convert.ToInt32(ids)).FirstOrDefault();
                if (v != null)
                {
                    Vector[16] = v.ReTweet;
                }
                //Post p = Post.Where(t => t.ID == Convert.ToInt32(ids)).FirstOrDefault();
                //if (p != null)
                //{
                //    Vector[17] = p.post;
                //}
                Cross_Validate_Data.Add(new Entry(Sign, Vector));
            }
            test.DiscardBufferedData();
            test.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
            test_ID.DiscardBufferedData();
            test_ID.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
            string entry2;
            string ids2;

            while ((entry2 = test.ReadLine()) != null && (ids2 = test_ID.ReadLine()) != null)
            {
                int      Sign;
                double[] Vector      = new double[17];
                string[] splitstring = entry2.Split();
                if (splitstring.First().First() == '1')
                {
                    Sign = 1;
                }
                else
                {
                    Sign = 0;
                }
                foreach (var item in splitstring)
                {
                    if (item.Contains(":"))
                    {
                        string[] s = item.Split(':');
                        Vector[Convert.ToInt32(s[0]) - 1] = Convert.ToDouble(s[1]);
                    }
                }
                ReTweets v = ReTweet.Where(t => t.ID == Convert.ToInt32(ids2)).FirstOrDefault();
                if (v != null)
                {
                    Vector[16] = v.ReTweet;
                }
                //Post p = Post.Where(t => t.ID == Convert.ToInt32(ids2)).FirstOrDefault();
                //if (p != null)
                //{
                //    Vector[17] = p.post;
                //}
                Cross_Validate_Data.Add(new Entry(Sign, Vector));
            }
            Cross_Validate_Data = Cross_Validate_Data.OrderBy(i => rSeed.Next()).ToList();
            Cross_Validate_Data = Cross_Validate_Data.OrderBy(i => rSeed.Next()).ToList();
            Cross_Validate_Data = Cross_Validate_Data.OrderBy(i => rSeed.Next()).ToList();
            Cross_Validate_Data = Cross_Validate_Data.OrderBy(i => rSeed.Next()).ToList();
            Cross_Validate_Data = Cross_Validate_Data.OrderBy(i => rSeed.Next()).ToList();
            Cross_Validate_Data = Cross_Validate_Data.OrderBy(i => rSeed.Next()).ToList();
            int seperator = Convert.ToInt32(Math.Floor(Convert.ToDecimal(Cross_Validate_Data.Count) / 5M));

            Cross_1 = Cross_Validate_Data.GetRange(0, seperator);
            Cross_2 = Cross_Validate_Data.GetRange(seperator, seperator);
            Cross_3 = Cross_Validate_Data.GetRange(2 * seperator, seperator);
            Cross_4 = Cross_Validate_Data.GetRange(3 * seperator, seperator);
            Cross_5 = Cross_Validate_Data.GetRange(4 * seperator, Cross_Validate_Data.Count - (4 * seperator));


            //var maxx = Cross_Validate_Data.Select(x => x.Vector[15]).ToList().OrderBy(m => m);
            //var max1 = Cross_Validate_Data.Select(x => x.Vector[15]).ToList().OrderByDescending(m => m);
            //var max2 = Cross_Validate_Data.Select(x => x.Vector[14]).ToList().OrderBy(m => m);
            //var max3 = Cross_Validate_Data.Select(x => x.Vector[14]).ToList().OrderByDescending(m => m);
            //var max4 = Cross_Validate_Data.Select(x => x.Vector[13]).ToList().OrderBy(m => m);
            //var max5 = Cross_Validate_Data.Select(x => x.Vector[13]).ToList().OrderByDescending(m => m);
            //var max6 = Cross_Validate_Data.Select(x => x.Vector[12]).ToList().OrderBy(m => m);
            //var max7 = Cross_Validate_Data.Select(x => x.Vector[12]).ToList().OrderByDescending(m => m);
            //var max8 = Cross_Validate_Data.Select(x => x.Vector[11]).ToList().OrderBy(m => m);
            //var max9 = Cross_Validate_Data.Select(x => x.Vector[11]).ToList().OrderByDescending(m => m);
            //var max10 = Cross_Validate_Data.Select(x => x.Vector[10]).ToList().OrderBy(m => m);
            //var max11 = Cross_Validate_Data.Select(x => x.Vector[10]).ToList().OrderByDescending(m => m);
            //var max12 = Cross_Validate_Data.Select(x => x.Vector[9]).ToList().OrderBy(m => m);
            //var max13 = Cross_Validate_Data.Select(x => x.Vector[9]).ToList().OrderByDescending(m => m);
            //var max14 = Cross_Validate_Data.Select(x => x.Vector[8]).ToList().OrderBy(m => m);
            //var max15 = Cross_Validate_Data.Select(x => x.Vector[8]).ToList().OrderByDescending(m => m);
            //var max16 = Cross_Validate_Data.Select(x => x.Vector[7]).ToList().OrderBy(m => m);
            //var max17 = Cross_Validate_Data.Select(x => x.Vector[7]).ToList().OrderByDescending(m => m);
            //var max18 = Cross_Validate_Data.Select(x => x.Vector[6]).ToList().OrderBy(m => m);
            //var max19 = Cross_Validate_Data.Select(x => x.Vector[6]).ToList().OrderByDescending(m => m);
            //var max20 = Cross_Validate_Data.Select(x => x.Vector[5]).ToList().OrderBy(m => m);
            //var max21 = Cross_Validate_Data.Select(x => x.Vector[5]).ToList().OrderByDescending(m => m);
            //var max22 = Cross_Validate_Data.Select(x => x.Vector[4]).ToList().OrderBy(m => m);
            //var max23 = Cross_Validate_Data.Select(x => x.Vector[4]).ToList().OrderByDescending(m => m);
            //var max111 = Cross_Validate_Data.Select(x => x.Vector[3]).ToList().OrderBy(m => m);
            //var max1111 = Cross_Validate_Data.Select(x => x.Vector[3]).ToList().OrderByDescending(m => m);
            //var max1112 = Cross_Validate_Data.Select(x => x.Vector[2]).ToList().OrderBy(m => m);
            //var max1235 = Cross_Validate_Data.Select(x => x.Vector[2]).ToList().OrderByDescending(m => m);
            //var max567 = Cross_Validate_Data.Select(x => x.Vector[1]).ToList().OrderBy(m => m);
            //var max1789 = Cross_Validate_Data.Select(x => x.Vector[1]).ToList().OrderByDescending(m => m);
            //var max09 = Cross_Validate_Data.Select(x => x.Vector[0]).ToList().OrderBy(m => m);
            //var max189 = Cross_Validate_Data.Select(x => x.Vector[0]).ToList().OrderByDescending(m => m);
        }
Exemplo n.º 4
0
        public void SetData(StreamReader reader, StreamReader id_1, StreamReader reader_2 = null, StreamReader id_2 = null)
        {
            reader.DiscardBufferedData();
            reader.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
            id_1.DiscardBufferedData();
            id_1.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
            string line;
            string ids;

            while ((line = reader.ReadLine()) != null && (ids = id_1.ReadLine()) != null)
            {
                int      Sign;
                double[] Vector      = new double[17];
                string[] splitstring = line.Split();
                if (splitstring.First().First() == '1')
                {
                    Sign = 1;
                }
                else
                {
                    Sign = 0;
                }
                foreach (var item in splitstring)
                {
                    if (item.Contains(":"))
                    {
                        string[] s = item.Split(':');
                        Vector[Convert.ToInt32(s[0]) - 1] = Convert.ToDouble(s[1]);
                    }
                }
                ReTweets v = ReTweet.Where(t => t.ID == Convert.ToInt32(ids)).FirstOrDefault();
                if (v != null)
                {
                    Vector[16] = v.ReTweet;
                }
                //Post p = Post.Where(t => t.ID == Convert.ToInt32(ids)).FirstOrDefault();
                //if (p != null)
                //{
                //    Vector[17] = p.post;
                //}
                data_1.Add(new Entry(Sign, Vector));
            }
            if (reader_2 != null)
            {
                reader_2.DiscardBufferedData();
                reader_2.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
                id_2.DiscardBufferedData();
                id_2.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
                string line2;
                string ids2;
                while ((line2 = reader_2.ReadLine()) != null && (ids2 = id_2.ReadLine()) != null)
                {
                    int      Sign;
                    double[] Vector      = new double[17];
                    string[] splitstring = line2.Split();
                    if (splitstring.First().First() == '1')
                    {
                        Sign = 1;
                    }
                    else
                    {
                        Sign = 0;
                    }
                    foreach (var item in splitstring)
                    {
                        if (item.Contains(":"))
                        {
                            string[] s = item.Split(':');
                            Vector[Convert.ToInt32(s[0]) - 1] = Convert.ToDouble(s[1]);
                        }
                    }
                    ReTweets v = ReTweet.Where(t => t.ID == Convert.ToInt32(ids2)).FirstOrDefault();
                    if (v != null)
                    {
                        Vector[16] = v.ReTweet;
                    }
                    //Post p = Post.Where(t => t.ID == Convert.ToInt32(ids2)).FirstOrDefault();
                    //if (p != null)
                    //{
                    //    Vector[17] = p.post;
                    //}
                    data_2.Add(new Entry(Sign, Vector));
                }
            }
        }