This is an old revision of the document!
A kind of W2As are social networks applications like Twitter and Facebook. Nowadays, these applications are widely used, thereby, the analysis the flow of information is an interesting research topic. This flow of information is analyzed trough messages sent and retrieved between users of these applications. This analysis is complex because it is necessary to reason about the distributed computations of a social networks application. Next, we present the analysis of popularity of a tweet in Twitter.
The analysis of popularity of user tweets is a novel topic in Twitter. This analysis allows a user to know the popularity of every tweet published by him, which is measured by the number of retweets4 that its followers do of his tweet. For example, Figure shows above four Tweeter users: Toti, Peter, Kuky, and Paul. Toti follows Peter and Peter follows Paul; Kuky follows nobody and vice versa. On the one hand, the figure also shows that Paul publishes a tweet and Peter receives this tweet and retweets it. On the other hand, the figure also shows that Kuky publishes a tweet and nobody receives it. Based on the popularity measurement, the popularity of the Paul’s tweet is one and the Kuky’s tweet is zero. Although Kuky and Paul would have published the same tweet (the same string), the popularity of Kuky is zero because the Kuky’s tweet does not cause any retweet. Commonly, this kind of analysis is carried out through dynamic graphs. Sadly, this analysis is not at real-time and is complex when social networks contains a big amount of users. An alternative way is the use of the vector clock algorithm1). We use WeCa to analyze the popularity of every tweets of every user when the midnight event happens.
Toggle between the code and example
The popularity of a post is carried out by the following sequence:
var popularity = causalSeq(callPublish, repeatUntil(callRepublication, event("midnight")))
This sequence matches and counts all republications of a post until the midnight event happens. The republications that are considered must be caused by a received post, ie a user that republishes a post received. This sequence begins the matching process when the callPublish pointcut matches:
var callPublish = call(publish).and(function(jp, env){ return env.bind("idT", jp.args[0]).bind("tweet", jp.args[1]).bind("counter", 0); });
This pointcut matches the call of the publish function and returns an environment that contains the id of the post, the post, and a counter initialized to zero. This counter is used to count the republications of the post. Whenever callPublish matches, the callRepublication pointcut could match several times to continue the matching of the sequence:
var callRepublication = function (jp, env){ return jp.isCustom("republication") && getPost(jp) == env.post ? env.bind("counter", env.counter + 1) : false; };
This pointcut matches an event of republication2) in which the post of republication is the same of the post of publication. If this pointcut matches, it returns an environment that contains the counter incremented by one. This pointcut matches republications until the midnight event happens, meaning that the sequence matches.
A user commonly publishes several posts, then it is necessary to have several sequences that matches, ie. one sequence by every different post. For example, if a user publishes the post m1 twice and m2 once, we only need a sequence for m1 and a sequence for m2 to analyze the popularity of all posts of the user. To achieve this goal, it is necessary to spawn a sequence by every different post. OTM allows developers to customize the spawning semantics of a Trace-based Mechanism using a plain JavaScript function:
var newPosts = function(steps, index, env, jp){ var currentEnvs = this.getCurrentEnvs(index); return !currentEnvs.some(function(currentEnv){ //returns true if some condition is not satisfied return currentEnv.post == env.post; }); };
Finally, the definition and deployment of the tm that analyzes the popularity of posts is:
var tm = { kind: AFTER, seqExp: causalSeq(callPublish, repeatUntil(callRepublication, event("midnight"))), advice: function(jp, env){ addCounterToPublication(env.id, env.counter); }, spawn: newPosts }; deploy(tm);
