CALL { OPTIONAL MATCH (u:User)-[:TWEETED_ORIGINAL]->(t:Tweet) WITH datetime(t.created_at).hour ashour, count(*) as tweets, 0as retweets RETURNhour, sum(tweets) as tweets, sum(retweets) as retweets ORDERBYhourASC
UNIONALL
OPTIONAL MATCH (u:User)-[:RETWEETED]->(t:Tweet) WITH datetime(t.created_at).hour ashour, 0as tweets, count(*) as retweets RETURNhour, sum(tweets) as tweets, sum(retweets) as retweets ORDERBYhourASC } WITHhour, sum(tweets) as tweets, sum(retweets) as retweets RETURNhour, tweets, retweets ORDERBYhourASC
MATCH (u:User)-[:TWEETED_ORIGINAL|RETWEETED|REPLIED|QUOTED]->(t:Tweet) WITH u, SUM(t.reply_count) AS total_replies RETURN u.userid as UserID, u.username AS Username, total_replies as Total_Replies ORDERBY total_replies DESC LIMIT1
MATCH (t:Tweet)-[:HAS_HASHTAG]->(h:Hashtag) WITH h.hashtag AS main_hashtag, collect(DISTINCT t.tweet_id) AS main_tweet_ids ORDERBYsize(main_tweet_ids) DESCLIMIT1 MATCH (t:Tweet)-[:HAS_HASHTAG]->(h:Hashtag) WHERE h.hashtag <> main_hashtag AND t.tweet_id IN main_tweet_ids WITH h.hashtag AS co_hashtag, count(DISTINCT t.tweet_id) AS co_occurrences, main_hashtag ORDERBY co_occurrences DESCLIMIT20 RETURN main_hashtag, co_hashtag, co_occurrences
pagerank_query = """ CALL gds.pageRank.stream('pageRankGraph') YIELD nodeId, score WITH nodeId, score ORDER BY score DESC MATCH (u:User) WHERE id(u) = nodeId WITH u.username AS username, MAX(score) AS max_score RETURN DISTINCT username, max_score """
session.run(create_graph_query) result = session.run(pagerank_query) display(pd.DataFrame(result.data()))
MATCH (u:User)-[:TWEETED_ORIGINAL]->(t:Tweet)-[:HAS_HASHTAG]->(h:Hashtag) WITH h, count(DISTINCT h) AS hashtag_count ORDER BY hashtag_count DESC LIMIT 5 WITH collect(h) AS top_hashtags MATCH (u:User)-[:TWEETED_ORIGINAL]->(t:Tweet)-[:HAS_HASHTAG]->(h:Hashtag) WHERE h IN top_hashtags AND datetime(t.created_at) >= datetime('2022-01-01T00:00:00.000Z') AND datetime(t.created_at) < datetime('2023-01-01T00:00:00.000Z') WITH u, count(DISTINCT t) AS tweet_count ORDER BY tweet_count DESC LIMIT 10 RETURN u.username, tweet_count
MATCH (u:User)-[:TWEETED_ORIGINAL]->(t:Tweet) WITH u, count(t) as numTweets, date(datetime(t.created_at)) as tweetDate WITH u, numTweets, min(tweetDate) as minTweetDate, max(tweetDate) as maxTweetDate WITH u, numTweets, duration.between(minTweetDate, maxTweetDate).days + 1 as numDays WITH u, numTweets toFloat(numDays) as tweetsPerDay WITH u, min(tweetsPerDay) as minTweetsPerDay CALL { MATCH (u:User)-[:TWEETED_ORIGINAL]->(t:Tweet) WITH u, count(t) as numTweets, date(datetime(t.created_at)) as tweetDate WITH u, numTweets, min(tweetDate) as minTweetDate, max(tweetDate) as maxTweetDate WITH u, numTweets, duration.between(minTweetDate, maxTweetDate).days + 1 as numDays WITH u, numTweets / toFloat(numDays) as tweetsPerDay WHERE numTweets > 1 WITH avg(tweetsPerDay) as totalAvgTweetsPerDay RETURN totalAvgTweetsPerDay } with minTweetsPerDay, totalAvgTweetsPerDay, u.username as username WHERE minTweetsPerDay > totalAvgTweetsPerDay RETURN username, minTweetsPerDay ORDER BY minTweetsPerDay DESC