|
|
@ -12,10 +12,9 @@ import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
import org.gcube.portal.databook.client.GCubeSocialNetworking;
|
|
|
|
import org.gcube.social_networking.social_networking_client_library.LibClient;
|
|
|
|
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.client.GCubeSocialNetworking;
|
|
|
|
import org.gcube.portal.databook.server.DatabookStore;
|
|
|
|
import org.gcube.social_networking.socialnetworking.model.shared.Post;
|
|
|
|
import org.gcube.portal.databook.shared.Feed;
|
|
|
|
|
|
|
|
import org.gcube.portlets.user.topics.client.TopicService;
|
|
|
|
import org.gcube.portlets.user.topics.client.TopicService;
|
|
|
|
import org.gcube.portlets.user.topics.shared.HashTagOccAndWeight;
|
|
|
|
import org.gcube.portlets.user.topics.shared.HashTagOccAndWeight;
|
|
|
|
import org.gcube.portlets.user.topics.shared.HashtagsWrapper;
|
|
|
|
import org.gcube.portlets.user.topics.shared.HashtagsWrapper;
|
|
|
@ -43,7 +42,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
|
|
|
private static final double FRESHNESS_FACTOR = 0.4;
|
|
|
|
private static final double FRESHNESS_FACTOR = 0.4;
|
|
|
|
private static final double NORMALIZED_SCORE_FACTOR = 0.6;
|
|
|
|
private static final double NORMALIZED_SCORE_FACTOR = 0.6;
|
|
|
|
|
|
|
|
|
|
|
|
private DatabookStore store;
|
|
|
|
private LibClient libClient;
|
|
|
|
private GroupManager gm;
|
|
|
|
private GroupManager gm;
|
|
|
|
private UserManager um;
|
|
|
|
private UserManager um;
|
|
|
|
|
|
|
|
|
|
|
@ -51,7 +50,11 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
|
|
|
* connect to cassandra at startup
|
|
|
|
* connect to cassandra at startup
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void init() {
|
|
|
|
public void init() {
|
|
|
|
store = new DBCassandraAstyanaxImpl();
|
|
|
|
try {
|
|
|
|
|
|
|
|
libClient = new LibClient();
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
gm = new LiferayGroupManager();
|
|
|
|
gm = new LiferayGroupManager();
|
|
|
|
um = new LiferayUserManager();
|
|
|
|
um = new LiferayUserManager();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -59,9 +62,9 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* close connection to cassandra at shutdown
|
|
|
|
* close connection to cassandra at shutdown
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void destroy() {
|
|
|
|
/*public void destroy() {
|
|
|
|
store.closeConnection();
|
|
|
|
store.closeConnection();
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -107,7 +110,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
|
|
|
|
|
|
|
|
|
|
|
for (String context : contexts) {
|
|
|
|
for (String context : contexts) {
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Integer> hashtagsAndOccurrenceInScope = store.getVREHashtagsWithOccurrenceFilteredByTime(context, referenceTime.getTimeInMillis());
|
|
|
|
Map<String, Integer> hashtagsAndOccurrenceInScope = libClient.getVREHashtagsWithOccurrenceFilteredByTimeLib(context, referenceTime.getTimeInMillis());
|
|
|
|
|
|
|
|
|
|
|
|
// merge the values if needed
|
|
|
|
// merge the values if needed
|
|
|
|
for (String hashtag : hashtagsAndOccurrenceInScope.keySet()) {
|
|
|
|
for (String hashtag : hashtagsAndOccurrenceInScope.keySet()) {
|
|
|
@ -136,7 +139,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
|
|
logger.debug("****** retrieving hashtags for scope " + currentScope);
|
|
|
|
logger.debug("****** retrieving hashtags for scope " + currentScope);
|
|
|
|
hashtagsAndOccurrences = store.getVREHashtagsWithOccurrenceFilteredByTime(currentScope, referenceTime.getTimeInMillis());
|
|
|
|
hashtagsAndOccurrences = libClient.getVREHashtagsWithOccurrenceFilteredByTimeLib(currentScope, referenceTime.getTimeInMillis());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// now we need to evaluate score for each element
|
|
|
|
// now we need to evaluate score for each element
|
|
|
@ -173,7 +176,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Evaluate the weight for each element as w = 0.6 * s + 0.4 * f
|
|
|
|
* Evaluate the weight for each element as w = 0.6 * s + 0.4 * f
|
|
|
|
* where s is the score: a normalized value given by counter_i / counter_max
|
|
|
|
* where s is the score: a normalized value given by counter_i / counter_max
|
|
|
|
* f is the freshness: evaluated taking into account the most recent feed containing that hashtag into the window w (that is, the period taken into account)
|
|
|
|
* f is the freshness: evaluated taking into account the most recent post containing that hashtag into the window w (that is, the period taken into account)
|
|
|
|
* @param hashtags
|
|
|
|
* @param hashtags
|
|
|
|
* @param hashtagsInVres (present if vreid is null)
|
|
|
|
* @param hashtagsInVres (present if vreid is null)
|
|
|
|
* @param window size
|
|
|
|
* @param window size
|
|
|
@ -210,24 +213,24 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
|
|
|
|
|
|
|
|
|
|
|
// create the weight for each entry as:
|
|
|
|
// create the weight for each entry as:
|
|
|
|
// w = NORMALIZED_SCORE_FACTOR * normalized_score + FRESHNESS_FACTOR * freshness
|
|
|
|
// w = NORMALIZED_SCORE_FACTOR * normalized_score + FRESHNESS_FACTOR * freshness
|
|
|
|
// freshness is evaluated as (window_size - latest_feed_for_hashtag_in_window_month)/window_size
|
|
|
|
// freshness is evaluated as (window_size - latest_post_for_hashtag_in_window_month)/window_size
|
|
|
|
for(Entry<String, Integer> entry : hashtags.entrySet()){
|
|
|
|
for(Entry<String, Integer> entry : hashtags.entrySet()){
|
|
|
|
|
|
|
|
|
|
|
|
// first part of the weight
|
|
|
|
// first part of the weight
|
|
|
|
double weight = NORMALIZED_SCORE_FACTOR * normalized.get(entry.getKey());
|
|
|
|
double weight = NORMALIZED_SCORE_FACTOR * normalized.get(entry.getKey());
|
|
|
|
|
|
|
|
|
|
|
|
List<Feed> mostRecentFeedForHashtag = null;
|
|
|
|
List<Post> mostRecentPostForHashtag = null;
|
|
|
|
|
|
|
|
|
|
|
|
// we are in the simplest case.. the hashtag belongs (or the request comes) from a single vre
|
|
|
|
// we are in the simplest case.. the hashtag belongs (or the request comes) from a single vre
|
|
|
|
if(hashtagsInVres == null){
|
|
|
|
if(hashtagsInVres == null){
|
|
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
try{
|
|
|
|
|
|
|
|
|
|
|
|
mostRecentFeedForHashtag = store.getVREFeedsByHashtag(vreId, entry.getKey());
|
|
|
|
mostRecentPostForHashtag = libClient.getVREPostsByHashtagLib(vreId, entry.getKey());
|
|
|
|
|
|
|
|
|
|
|
|
}catch(Exception e){
|
|
|
|
}catch(Exception e){
|
|
|
|
|
|
|
|
|
|
|
|
logger.error("Unable to retrieve the most recent feeds for hashtag " + entry.getKey() + " in " + vreId);
|
|
|
|
logger.error("Unable to retrieve the most recent posts for hashtag " + entry.getKey() + " in " + vreId);
|
|
|
|
|
|
|
|
|
|
|
|
// put a weight of zero for this hashtag
|
|
|
|
// put a weight of zero for this hashtag
|
|
|
|
weights.put(entry.getKey(), 0.0);
|
|
|
|
weights.put(entry.getKey(), 0.0);
|
|
|
@ -240,41 +243,41 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
|
|
|
|
List<String> vres = hashtagsInVres.get(entry.getKey());
|
|
|
|
List<String> vres = hashtagsInVres.get(entry.getKey());
|
|
|
|
|
|
|
|
|
|
|
|
// init list
|
|
|
|
// init list
|
|
|
|
mostRecentFeedForHashtag = new ArrayList<Feed>();
|
|
|
|
mostRecentPostForHashtag = new ArrayList<Post>();
|
|
|
|
|
|
|
|
|
|
|
|
List<Feed> feedsForVre;
|
|
|
|
List<Post> postsForVre;
|
|
|
|
for (String vre : vres) {
|
|
|
|
for (String vre : vres) {
|
|
|
|
try{
|
|
|
|
try{
|
|
|
|
feedsForVre = store.getVREFeedsByHashtag(vre, entry.getKey());
|
|
|
|
postsForVre = libClient.getVREPostsByHashtagLib(vre, entry.getKey());
|
|
|
|
}catch(Exception e){
|
|
|
|
}catch(Exception e){
|
|
|
|
logger.error("Unable to retrieve the most recent feeds for hashtag " + entry.getKey() + " in " + vreId);
|
|
|
|
logger.error("Unable to retrieve the most recent posts for hashtag " + entry.getKey() + " in " + vreId);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// add to the list
|
|
|
|
// add to the list
|
|
|
|
mostRecentFeedForHashtag.addAll(feedsForVre);
|
|
|
|
mostRecentPostForHashtag.addAll(postsForVre);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// check if there is at least a feed or it is empty
|
|
|
|
// check if there is at least a post or it is empty
|
|
|
|
if(mostRecentFeedForHashtag.isEmpty()){
|
|
|
|
if(mostRecentPostForHashtag.isEmpty()){
|
|
|
|
// put a weight of zero for this hashtag
|
|
|
|
// put a weight of zero for this hashtag
|
|
|
|
weights.put(entry.getKey(), 0.0);
|
|
|
|
weights.put(entry.getKey(), 0.0);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// retrieve the most recent one among these feeds
|
|
|
|
// retrieve the most recent one among these posts
|
|
|
|
Collections.sort(mostRecentFeedForHashtag, Collections.reverseOrder());
|
|
|
|
Collections.sort(mostRecentPostForHashtag, Collections.reverseOrder());
|
|
|
|
|
|
|
|
|
|
|
|
// get month of the last recent feed for this hashtag
|
|
|
|
// get month of the last recent post for this hashtag
|
|
|
|
Calendar monstRecentFeedForHashTagTime = Calendar.getInstance();
|
|
|
|
Calendar monstRecentPostForHashTagTime = Calendar.getInstance();
|
|
|
|
monstRecentFeedForHashTagTime.setTimeInMillis(mostRecentFeedForHashtag.get(0).getTime().getTime());
|
|
|
|
monstRecentPostForHashTagTime.setTimeInMillis(mostRecentPostForHashtag.get(0).getTime().getTime());
|
|
|
|
|
|
|
|
|
|
|
|
int sub = currentMonth - monstRecentFeedForHashTagTime.get(Calendar.MONTH);
|
|
|
|
int sub = currentMonth - monstRecentPostForHashTagTime.get(Calendar.MONTH);
|
|
|
|
int value = sub >= 0? sub : 12 - Math.abs(sub);
|
|
|
|
int value = sub >= 0? sub : 12 - Math.abs(sub);
|
|
|
|
double freshness = 1.0 - (double)(value) / (double)(windowSize);
|
|
|
|
double freshness = 1.0 - (double)(value) / (double)(windowSize);
|
|
|
|
logger.debug("freshness is " + freshness + " for hashtag " + entry.getKey() +
|
|
|
|
logger.debug("freshness is " + freshness + " for hashtag " + entry.getKey() +
|
|
|
|
" because the last feed has month " + monstRecentFeedForHashTagTime.get(Calendar.MONTH));
|
|
|
|
" because the last post has month " + monstRecentPostForHashTagTime.get(Calendar.MONTH));
|
|
|
|
|
|
|
|
|
|
|
|
// update the weight
|
|
|
|
// update the weight
|
|
|
|
weight += FRESHNESS_FACTOR * freshness;
|
|
|
|
weight += FRESHNESS_FACTOR * freshness;
|
|
|
|