Compare commits

...

1 Commits

Author SHA1 Message Date
Ahmed Salah Tawfik Ibrahim 8a6537fd35 Compatible with social model 2.0.0 2024-02-01 17:54:51 +01:00
3 changed files with 42 additions and 32 deletions

11
pom.xml
View File

@ -72,9 +72,16 @@
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<!--needs to be provided -->
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library</artifactId>
<groupId>org.gcube.social-networking</groupId>
<artifactId>social-service-model</artifactId>
<version>[1.2.0-SNAPSHOT, 2.0.0)</version>
</dependency>
<dependency>
<groupId>org.gcube.social-networking</groupId>
<artifactId>social-service-client</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0)</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -12,10 +12,9 @@ import java.util.Set;
import org.apache.commons.codec.binary.Base64;
import org.gcube.common.portal.PortalContext;
import org.gcube.portal.databook.client.GCubeSocialNetworking;
import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
import org.gcube.portal.databook.server.DatabookStore;
import org.gcube.portal.databook.shared.Feed;
import org.gcube.social_networking.social_networking_client_library.LibClient;
import org.gcube.social_networking.socialnetworking.model.client.GCubeSocialNetworking;
import org.gcube.social_networking.socialnetworking.model.shared.Post;
import org.gcube.portlets.user.topics.client.TopicService;
import org.gcube.portlets.user.topics.shared.HashTagOccAndWeight;
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 NORMALIZED_SCORE_FACTOR = 0.6;
private DatabookStore store;
private LibClient libClient;
private GroupManager gm;
private UserManager um;
@ -51,7 +50,11 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
* connect to cassandra at startup
*/
public void init() {
store = new DBCassandraAstyanaxImpl();
try {
libClient = new LibClient();
} catch (Exception e) {
throw new RuntimeException(e);
}
gm = new LiferayGroupManager();
um = new LiferayUserManager();
}
@ -59,9 +62,9 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
/**
* close connection to cassandra at shutdown
*/
public void destroy() {
/*public void destroy() {
store.closeConnection();
}
}*/
/**
@ -107,7 +110,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
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
for (String hashtag : hashtagsAndOccurrenceInScope.keySet()) {
@ -136,7 +139,7 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
else {
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
@ -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
* 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 hashtagsInVres (present if vreid is null)
* @param window size
@ -210,24 +213,24 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
// create the weight for each entry as:
// 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()){
// first part of the weight
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
if(hashtagsInVres == null){
try{
mostRecentFeedForHashtag = store.getVREFeedsByHashtag(vreId, entry.getKey());
mostRecentPostForHashtag = libClient.getVREPostsByHashtagLib(vreId, entry.getKey());
}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
weights.put(entry.getKey(), 0.0);
@ -240,41 +243,41 @@ public class TopicServiceImpl extends RemoteServiceServlet implements TopicServi
List<String> vres = hashtagsInVres.get(entry.getKey());
// init list
mostRecentFeedForHashtag = new ArrayList<Feed>();
mostRecentPostForHashtag = new ArrayList<Post>();
List<Feed> feedsForVre;
List<Post> postsForVre;
for (String vre : vres) {
try{
feedsForVre = store.getVREFeedsByHashtag(vre, entry.getKey());
postsForVre = libClient.getVREPostsByHashtagLib(vre, entry.getKey());
}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;
}
// add to the list
mostRecentFeedForHashtag.addAll(feedsForVre);
mostRecentPostForHashtag.addAll(postsForVre);
}
// check if there is at least a feed or it is empty
if(mostRecentFeedForHashtag.isEmpty()){
// check if there is at least a post or it is empty
if(mostRecentPostForHashtag.isEmpty()){
// put a weight of zero for this hashtag
weights.put(entry.getKey(), 0.0);
continue;
}
}
// retrieve the most recent one among these feeds
Collections.sort(mostRecentFeedForHashtag, Collections.reverseOrder());
// retrieve the most recent one among these posts
Collections.sort(mostRecentPostForHashtag, Collections.reverseOrder());
// get month of the last recent feed for this hashtag
Calendar monstRecentFeedForHashTagTime = Calendar.getInstance();
monstRecentFeedForHashTagTime.setTimeInMillis(mostRecentFeedForHashtag.get(0).getTime().getTime());
// get month of the last recent post for this hashtag
Calendar monstRecentPostForHashTagTime = Calendar.getInstance();
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);
double freshness = 1.0 - (double)(value) / (double)(windowSize);
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
weight += FRESHNESS_FACTOR * freshness;

View File

@ -9,7 +9,7 @@
<inherits name="com.github.gwtbootstrap.Bootstrap" />
<!-- Other module inherits -->
<inherits name='org.gcube.portal.databook.GCubeSocialNetworking' />
<inherits name='org.gcube.social_networking.socialnetworking.model.GCubeSocialNetworking' />
<entry-point class='org.gcube.portlets.user.topics.client.TopTopics' />
<!-- Specify the paths for translatable code -->