public User(User newUser) { this.ID = newUser.ID; this.followeeList = new HashSet<long>(followeeList); this.publishedTweets = deepCloneHashSetTweet(newUser.publishedTweets); this.retweets = deepCloneHashSetTweet(newUser.retweets); this.quotes = deepCloneHashSetTweet(newUser.quotes); this.favorites = deepCloneHashSetTweet(newUser.favorites); this.updateLikedTweets(); }
/***************************** Primary Methods *********************************/ // 'Followee' list of 'userID' public HashSet<long> getFolloweeList(User user) { HashSet<long> followeeList = new HashSet<long>(); using (SQLiteCommand cmd = new SQLiteCommand(conn)) { cmd.CommandText = "SELECT target FROM follow WHERE source = " + user.ID; using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { long followeeID = reader.GetInt64(0); followeeList.Add(followeeID); } } } return followeeList; }
/***************************** Core Methods *********************************/ // Similarity Measure: 'Ego user' to 'Followee' public double jaccardSimilarity(User otherUser) { // A: user liked tweets, B: other user liked tweets HashSet<Tweet> A = new HashSet<Tweet>(this.likedTweets); // Shallow Copy HashSet<Tweet> B = new HashSet<Tweet>(otherUser.getLikedTweets()); // Shallow Copy double cardinalityA, cardinalityB, intersection = 0; cardinalityA = (double)A.Count; cardinalityB = (double)B.Count; // Intersection A.IntersectWith(B); intersection = (double)A.Count; // Jaccard Similarity double similarScore = (intersection / (cardinalityA + cardinalityB - intersection)); return similarScore; }
// Tweet list 'retweeted' by 'user' public HashSet<Tweet> getRetweetList(User user) { HashSet<Tweet> retweetList = new HashSet<Tweet>(); using (SQLiteCommand cmd = new SQLiteCommand(conn)) { cmd.CommandText = "SELECT tweet.id, tweet.author, tweet.isMention FROM retweet, tweet WHERE retweet.user = "******" and retweet.tweet = tweet.id"; using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { long tweetID = reader.GetInt64(0); long author = reader.GetInt64(1); bool isMention = false; if (reader.GetBoolean(2) == true) isMention = true; retweetList.Add(new Tweet(tweetID, author, isMention)); } } } return retweetList; }
// Tweet list 'published' by 'user' public HashSet<Tweet> getPublishedTweets(User user) { HashSet<Tweet> publishedTweetList = new HashSet<Tweet>(); using (SQLiteCommand cmd = new SQLiteCommand(conn)) { cmd.CommandText = "SELECT id, author, isMention FROM tweet WHERE author = " + user.ID; using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { long tweetID = reader.GetInt64(0); long author = reader.GetInt64(1); bool isMention = false; if (reader.GetBoolean(2) == true) isMention = true; publishedTweetList.Add(new Tweet(tweetID, author, isMention)); } } } return publishedTweetList; }
// Total mention count between 'user1' & 'user2' public long getMentionCount(User user1, User user2) { Int64 mentionCount = 0; // 'Int64' == 'long' using (SQLiteCommand cmd = new SQLiteCommand(conn)) { cmd.CommandText = "SELECT COUNT(*) FROM mention WHERE source = " + user1.ID + " AND target = " + user2.ID; mentionCount += (Int64)cmd.ExecuteScalar(); cmd.CommandText = "SELECT COUNT(*) FROM mention WHERE source = " + user2.ID + " AND target = " + user1.ID; mentionCount += (Int64)cmd.ExecuteScalar(); } return mentionCount; }
public bool isFriend(User otherUser) { return (this.followeeList.Contains(otherUser.ID) && otherUser.followeeList.Contains(this.ID)); }
public bool isFollow(User otherUser) { return this.followeeList.Contains(otherUser.ID); }