Example #1
0
        public void TestGuessFollowsGraphEmpty()
        {
            Dictionary <string, HashSet <string> > followsGraph =
                SocialNetwork.GuessFollowsGraph(new List <Tweet>());

            Assert.IsTrue(followsGraph.Count == 0, "expected empty graph");
        }
Example #2
0
        public void TestInfluencersEmpty()
        {
            Dictionary <string, HashSet <string> > followsGraph =
                new Dictionary <string, HashSet <string> >();

            List <string> influencers = SocialNetwork.Influencers(followsGraph);

            Assert.IsTrue(influencers.Count == 0, "expected empty list");
        }
Example #3
0
        public void TestGuessFollowsGraph()
        {
            DateTime     dt1   = DateTime.Parse("2016-02-17T10:00:00Z");
            DateTime     dt2   = DateTime.Parse("2016-02-17T10:00:03Z");
            DateTime     dt3   = DateTime.Parse("2016-02-17T10:00:06Z");
            Tweet        t1    = new Tweet(1, "alyssa", "is it .@bbitdiddle who talks about rivest so much?", dt1);
            Tweet        t2    = new Tweet(2, "bbitdiddle", "@alyssa talks for minimum 30 minutes @Ellen #hype", dt2);
            Tweet        t3    = new Tweet(3, "bibimbop", "I agree that @alyssa talks for minimum 30 minutes @Ellen #NoHype", dt3);
            List <Tweet> listt = new List <Tweet>()
            {
                t1, t2, t3
            };
            Dictionary <string, HashSet <string> > followsGraph = SocialNetwork.GuessFollowsGraph(listt);

            Assert.IsTrue(followsGraph["alyssa"].Count == 1, "Expected 1");
            Assert.IsTrue(followsGraph["bbitdiddle"].Count == 2, "Expected 2");
            Assert.IsTrue(followsGraph["bibimbop"].Count == 2, "Expected 2");
            HashSet <string> hash1 = new HashSet <string>();

            hash1.Add("bbitdiddle");
            HashSet <string> hash2 = new HashSet <string>();

            hash2.Add("alyssa");
            hash2.Add("ellen");
            HashSet <string> hash3 = new HashSet <string>();

            hash3.Add("alyssa");
            hash3.Add("ellen");
            Dictionary <string, HashSet <string> > followsGraphCheck = new Dictionary <string, HashSet <string> >();

            followsGraphCheck.Add("alyssa", hash1);
            followsGraphCheck.Add("bbitdiddle", hash2);
            followsGraphCheck.Add("bibimbop", hash3);
            Assert.IsFalse(followsGraph.Count == 0, "expected non-empty graph");
            Assert.AreEqual(3, followsGraph.Count, "expected 3 items in followsGraph");
            Assert.IsTrue(followsGraph.ContainsKey("alyssa"), "Expected key in graph");
            Assert.IsTrue(followsGraph.ContainsKey("bbitdiddle"), "Expected key in graph");
            Assert.IsTrue(followsGraph.ContainsKey("bibimbop"), "Expected key in graph");
            Assert.IsTrue(followsGraph["alyssa"].Count == 1, "Expected key in graph");
            Assert.IsTrue(followsGraph["bbitdiddle"].Count == 2, "Expected key in graph");
            Assert.IsTrue(followsGraph["bibimbop"].Count == 2, "Expected key in graph");
        }
Example #4
0
        //
        // Main method of the program. Fetches a sample of tweets and prints some
        // facts about it.
        //
        public static void Main()
        {
            List <Tweet> tweets;

            try
            {
                tweets = TweetReader.ReadTweetsFromWeb(SAMPLE_SERVER);
            }
            catch (Exception e)
            {
                throw new Exception("Cannot read tweets", e);
            }

            // display some characteristics about the tweets
            Console.WriteLine("fetched " + tweets.Count + " tweets");

            HashSet <string> mentionedUsers = Extract.GetMentionedUsers(tweets);

            Console.WriteLine("covers " + mentionedUsers.Count + " Twitter users");

            Timespan span = Extract.GetTimespan(tweets);

            Console.WriteLine("ranging from " + span.start + " to " + span.end);

            // infer the follows graph
            Dictionary <string, HashSet <string> > followsGraph =
                SocialNetwork.GuessFollowsGraph(tweets);

            Console.WriteLine("follows graph has " + followsGraph.Count + " nodes");

            // print the top-N influencers
            int           count       = 10;
            List <string> influencers = SocialNetwork.Influencers(followsGraph);

            foreach (string username in
                     influencers.GetRange(0, Math.Min(count, influencers.Count)))
            {
                Console.WriteLine(username);
            }
        }
Example #5
0
        public void TestInfluencers()
        {
            DateTime     dt1   = DateTime.Parse("2016-02-17T10:00:00Z");
            DateTime     dt2   = DateTime.Parse("2016-02-17T10:00:03Z");
            DateTime     dt3   = DateTime.Parse("2016-02-17T10:00:06Z");
            DateTime     dt4   = DateTime.Parse("2016-02-17T10:00:05Z");
            Tweet        t1    = new Tweet(1, "ivan", "i follow @pavan", dt1);
            Tweet        t2    = new Tweet(2, "bappe", "I personally follow both .@pavan and @ivan", dt2);
            Tweet        t3    = new Tweet(3, "pavan", "I will always have a special place for @ivan ", dt3);
            Tweet        t4    = new Tweet(4, "hanan", "I will always have a special place for @iVAn and of course @bappe ", dt4);
            List <Tweet> listt = new List <Tweet>()
            {
                t1, t2, t3, t4
            };
            Dictionary <string, HashSet <string> > followsGraph = SocialNetwork.GuessFollowsGraph(listt);
            List <string> influencers = SocialNetwork.Influencers(followsGraph);

            Assert.IsTrue(influencers[0] == "ivan", "ranked followers");
            Assert.IsTrue(influencers[1] == "pavan", "ranked followers");
            Assert.IsTrue(influencers[2] == "bappe", "ranked followers");
            Assert.IsFalse(influencers.Count == 0, "expected non-empty list");
        }