예제 #1
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");
        }
예제 #2
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);
            }
        }
예제 #3
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");
        }